Skip to content

Commit

Permalink
Revert "Revert "[K6.1] Merge changes from K6.0""
Browse files Browse the repository at this point in the history
This reverts commit 3059f28.
  • Loading branch information
xillibit committed Jul 7, 2022
1 parent 3059f28 commit 9765fe9
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 46 deletions.
143 changes: 127 additions & 16 deletions src/admin/src/Controller/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\Session\Session;
use Joomla\String\StringHelper;
use Joomla\Utilities\ArrayHelper;
use Kunena\Forum\Libraries\Controller\KunenaController;
use Kunena\Forum\Libraries\Exception\KunenaException;
use Kunena\Forum\Libraries\Factory\KunenaFactory;
use Kunena\Forum\Libraries\Forum\Category\KunenaCategory;
Expand All @@ -31,7 +33,7 @@
*
* @since Kunena 6.0
*/
class CategoryController extends FormController
class CategoryController extends KunenaController
{
/**
* @var string
Expand Down Expand Up @@ -261,20 +263,6 @@ protected function internalSave()
return $category;
}

/**
* Escapes a value for output in a view script.
*
* @param string $var The output to escape.
*
* @return string The escaped value.
*
* @since Kunena 6.0
*/
protected function escape(string $var): string
{
return htmlspecialchars($var, ENT_COMPAT);
}

/**
* Apply
*
Expand Down Expand Up @@ -391,8 +379,131 @@ public function save2newcategory(): void
*/
public function checkin()
{
// TODO : need to implement the logic to checkin teh category
// TODO : need to implement the logic to checkin the category

$this->setRedirect(KunenaRoute::_($this->baseurl, false));
}

/**
* Publish category item
*
* @return void
*
* @throws null
* @throws Exception
* @since Kunena 2.0.0-BETA2
*/
public function publish(): void
{
$cid = $this->app->input->get('cid', [], 'array');
$cid = ArrayHelper::toInteger($cid);

$this->setVariable($cid, 'published', 1);
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
}

/**
* Unpublish category item
*
* @return void
*
* @throws null
* @throws Exception
* @since Kunena 2.0.0-BETA2
*/
public function unpublish(): void
{
$cid = $this->app->input->get('cid', [], 'array');
$cid = ArrayHelper::toInteger($cid);

$this->setVariable($cid, 'published', 0);
$this->setRedirect(KunenaRoute::_($this->baseurl, false));
}

/**
* Set variable
*
* @param array $cid id
* @param string $variable variable
* @param string $value value
*
* @return void
*
* @throws null
* @throws Exception
* @since Kunena 3.0
*/
protected function setVariable(array $cid, string $variable, string $value): void
{
KunenaFactory::loadLanguage('com_kunena', 'admin');

if (!Session::checkToken('post'))
{
$this->app->enqueueMessage(Text::_('COM_KUNENA_ERROR_TOKEN'), 'error');

return;
}

if (empty($cid))
{
$this->app->enqueueMessage(Text::_('COM_KUNENA_A_NO_CATEGORIES_SELECTED'), 'notice');

return;
}

$count = 0;
$name = null;

$categories = KunenaCategoryHelper::getCategories($cid);

foreach ($categories as $category)
{
if ($category->get($variable) == $value)
{
continue;
}

if (!$category->isAuthorised('admin'))
{
$this->app->enqueueMessage(
Text::sprintf('COM_KUNENA_A_CATEGORY_NO_ADMIN', $this->escape($category->name)),
'notice'
);
}
elseif (!$category->isCheckedOut($this->me->userid))
{
$category->set($variable, $value);

if ($category->save())
{
$count++;
$name = $category->name;
}
else
{
$this->app->enqueueMessage(
Text::sprintf('COM_KUNENA_A_CATEGORY_SAVE_FAILED', $category->id, $this->escape($category->getError())),
'error'
);
}
}
else
{
$this->app->enqueueMessage(
Text::sprintf('COM_KUNENA_A_CATEGORY_X_CHECKED_OUT', $this->escape($category->name)),
'notice'
);
}
}

if ($count == 1 && $name)
{
$this->app->enqueueMessage(Text::sprintf('COM_KUNENA_A_CATEGORY_SAVED', $this->escape($name)), 'success');
}

if ($count > 1)
{
$this->app->enqueueMessage(Text::sprintf('COM_KUNENA_A_CATEGORIES_SAVED', $count), 'success');
}
}
}
4 changes: 2 additions & 2 deletions src/admin/tmpl/categories/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class="select-filter filter form-control"
$canEditOwn = $canEdit;
$canChange = $canEdit && $canCheckin;
?>
<tr class="row<?php echo $i % 2; ?>" data-draggable-group="<?php echo $item->id; ?>">
<tr class="row<?php echo $i % 2; ?>" data-draggable-group="<?php echo $item->parentid; ?>" data-item-id="<?php echo $item->id ?>">
<td class="text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->name); ?>
</td>
Expand All @@ -269,7 +269,7 @@ class="select-filter filter form-control"
<?php endif; ?>
</td>
<td class="center">
<?php echo HTMLHelper::_('jgrid.published', $item->published, $i, '', 'cb'); ?>
<?php echo HTMLHelper::_('jgrid.published', $item->published, $i, 'category.'); ?>
</td>
<td class="center">
<?php if (!$this->filter->Item || ($this->filter->Item != $item->id && $item->parentid))
Expand Down
1 change: 0 additions & 1 deletion src/pkg_kunena.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<filename type="component" id="com_kunena">com_kunena_v@kunenaversion@.zip</filename>
<filename type="plugin" group="finder" id="kunena">plg_finder_kunena_v@kunenaversion@.zip</filename>
<filename type="plugin" group="kunena" id="finder">plg_kunena_finder_v@kunenaversion@.zip</filename>
<filename type="plugin" group="kunena" id="altauserpoints">plg_kunena_altauserpoints_v@kunenaversion@.zip</filename>
<filename type="plugin" group="kunena" id="community">plg_kunena_community_v@kunenaversion@.zip</filename>
<filename type="plugin" group="kunena" id="comprofiler">plg_kunena_comprofiler_v@kunenaversion@.zip</filename>
<filename type="plugin" group="kunena" id="easysocial">plg_kunena_easysocial_v@kunenaversion@.zip</filename>
Expand Down
40 changes: 25 additions & 15 deletions src/plugins/plg_finder_kunena/kunena.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@

use Joomla\CMS\Factory;
use Joomla\CMS\Log\Log;
use Joomla\CMS\User\User;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\Component\Finder\Administrator\Indexer\Adapter;
use Joomla\Component\Finder\Administrator\Indexer\Indexer;
use Joomla\Component\Finder\Administrator\Indexer\Result;
use Joomla\Component\Finder\Administrator\Indexer\Helper;
use Kunena\Forum\Libraries\Error\KunenaError;
use Kunena\Forum\Libraries\Forum\KunenaForum;
use Kunena\Forum\Libraries\Forum\Category\KunenaCategoryHelper;
use Kunena\Forum\Libraries\Forum\Message\KunenaMessageHelper;
use Kunena\Forum\Libraries\Html\KunenaParser;
use Kunena\Forum\Libraries\Route\KunenaRoute;
use Kunena\Forum\Libraries\Tables\TableKunenaCategories;
use Kunena\Forum\Libraries\Tables\TableKunenaMessages;
use Kunena\Forum\Libraries\Tables\TableKunenaTopics;
use Kunena\Forum\Libraries\Forum\Message\KunenaMessage;
use Joomla\CMS\Access\Access;
use Joomla\Database\QueryInterface;

/**
* Finder adapter for com_kunena.
Expand Down Expand Up @@ -353,7 +360,7 @@ protected function setup()
return false;
}

Forum::setup();
KunenaForum::setup();

return true;
}
Expand Down Expand Up @@ -404,7 +411,7 @@ protected function getItem($id)
{
Log::add('FinderIndexerAdapter::getItem', Log::INFO);

$message = \Kunena\Forum\Libraries\Forum\Message\Helper::get($id);
$message = KunenaMessageHelper::get($id);

// Convert the item to a result object.
$item = $this->createIndexerResult($message);
Expand Down Expand Up @@ -450,15 +457,15 @@ protected function getItems($offset, $limit, $sql = null)
}

// Convert the items to result objects.
$messages = \Kunena\Forum\Libraries\Forum\Message\Helper::getMessages($ids, 'none');
$messages = KunenaMessageHelper::getMessages($ids, 'none');
$items = [];

foreach ($messages as &$message)
{
$items[] = $this->createIndexerResult($message);
}

\Kunena\Forum\Libraries\Forum\Message\Helper::cleanup();
KunenaMessageHelper::cleanup();
KunenaRoute::cleanup();

return $items;
Expand All @@ -485,11 +492,10 @@ protected function createIndexerResult($message)
// Build the necessary url, route, path and alias information.
$item->url = $this->getUrl($message->id, $this->extension, $this->layout);
$item->route = $item->url . '&Itemid=' . KunenaRoute::getItemId($item->url);
$item->path = Helper::getContentPath($item->url);
$item->alias = KunenaRoute::stringURLSafe($message->subject);

// Set body context.
$item->body = \Kunena\Forum\Libraries\Html\Parser::stripBBCode($message->message);
$item->body = KunenaParser::stripBBCode($message->message);
$item->summary = $item->body;

// Set other information.
Expand Down Expand Up @@ -526,7 +532,7 @@ protected function createIndexerResult($message)
*/
protected function getUrl($id, $extension, $view)
{
$item = \Kunena\Forum\Libraries\Forum\Message\Helper::get($id);
$item = KunenaMessageHelper::get($id);

return "index.php?option=com_kunena&view={$view}&catid={$item->catid}&id={$item->thread}&mesid={$item->id}";
}
Expand Down Expand Up @@ -579,7 +585,7 @@ protected function getMessagesByCategory($cat_id)
$query->where('c.id = ' . $db->quote($cat_id));
$db->setQuery($query);
$ids = $db->loadColumn();
$messages[$cat_id] = \Kunena\Forum\Libraries\Forum\Message\Helper::getMessages($ids);
$messages[$cat_id] = KunenaMessageHelper::getMessages($ids);
}

return $messages[$cat_id];
Expand Down Expand Up @@ -610,7 +616,7 @@ protected function getMessagesByTopic($topic_id)

foreach ($results as $result)
{
$list[] = new \Kunena\Forum\Libraries\Forum\Message\Message($result);
$list[] = new KunenaMessage($result);
}

$messages[$topic_id] = $list;
Expand All @@ -628,14 +634,18 @@ protected function getMessagesByTopic($topic_id)
*/
protected function getAccessLevel($item)
{
$category = \Kunena\Forum\Libraries\Forum\Category\Helper::get($item);
$user = $this->getApplication()->getIdentity();
$category = KunenaCategoryHelper::get($item);
$user = Factory::getUser(0);

$accesslevels = (array) $user->getAuthorisedViewLevels();
$groups_r = (array) \Joomla\CMS\Access\Access::getGroupsByUser($user->id, true);
$groups = (array) \Joomla\CMS\Access\Access::getGroupsByUser($user->id, false);
// WORKAROUND: Joomla! 2.5.6 bug returning NULL if $userid = 0 and session is corrupted.
if (!($user instanceof User))
{
$user = User::getInstance();
}

$catlist = [];
$accesslevels = (array) $user->getAuthorisedViewLevels();
$groups_r = (array) Access::getGroupsByUser($user->id, true);
$groups = (array) Access::getGroupsByUser($user->id, false);

// Check against Joomla access level
if ($category->accesstype == 'joomla.level')
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/plg_kunena_community/KunenaActivityCommunity.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class KunenaActivityCommunity extends KunenaActivity
public function __construct(object $params)
{
$this->params = $params;

parent::__construct();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/plg_kunena_comprofiler/comprofiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
class plgKunenaComprofiler extends CMSPlugin
{
/**
* @var string CB version 2.7.2 works with Php 8.1 and with Joomla! 4.0/4.1
* @var string CB version 2.7.3 works with Php 8.1 and with Joomla! 4.0/4.1
* @since Kunena 6.0
*/
public $minCBVersion = '2.7.2';
public $minCBVersion = '2.7.3';

/**
* plgKunenaComprofiler constructor.
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/plg_system_kunena/kunena.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function onUserAfterSave($user, bool $isnew, bool $success, ?string $msg)
* @since Kunena 6.0
* @throws \Exception
*/
public function onExtensionBeforeInstall(string $method, string $type, $manifest, int $eid): bool
public function onExtensionBeforeInstall(string $method, string $type, object $manifest, int $eid): bool
{
// We don't want to handle discover install (where there's no manifest provided)
if (!$manifest)
Expand All @@ -176,7 +176,7 @@ public function onExtensionBeforeInstall(string $method, string $type, $manifest
* @throws Exception
* @since Kunena 6.0
*/
public function onExtensionBeforeUpdate($type, string $manifest): bool
public function onExtensionBeforeUpdate($type, object $manifest): bool
{
if ($type != 'component')
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected function before()
{
parent::before();

$params = ComponentHelper::getParams('com_kunena');
$params = $this->app->getParams('com_kunena');
$this->header = $params->get('page_title');
$Itemid = $this->input->getInt('Itemid');

Expand Down
2 changes: 1 addition & 1 deletion src/site/tmpl/topics/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</fields>
<fields name="params">
<fieldset name="basic"
label="COM_KUNENA_ATTRIBS_MAIN_SETTINGS_LABEL">
label="COM_KUNENA_ATTRIBS_MAIN_SETTINGS_LABEL" addfieldprefix="Kunena\Forum\Administrator\Field">
<field name="topics_catselection"
type="radio"
default=""
Expand Down
Loading

0 comments on commit 9765fe9

Please sign in to comment.