Skip to content

Commit

Permalink
Fix home controller
Browse files Browse the repository at this point in the history
  • Loading branch information
810 committed May 26, 2018
1 parent e3a2504 commit 532c91c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
@@ -1,12 +1,12 @@
<?php
/**
* Kunena Component
* @package Kunena.Site
* @subpackage Controller.Application
* @package Kunena.Site
* @subpackage Controller.Application
*
* @copyright Copyright (C) 2008 - 2018 Kunena Team. All rights reserved.
* @license https://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link https://www.kunena.org
* @copyright (C) 2008 - 2018 Kunena Team. All rights reserved.
* @license https://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link https://www.kunena.org
**/
defined('_JEXEC') or die;

Expand Down Expand Up @@ -68,7 +68,7 @@ public function execute()
$default = clone $home;
}

$default->query['view'] = 'category';
$default->query['view'] = 'category';
$default->query['layout'] = 'list';
}
}
Expand Down Expand Up @@ -115,8 +115,8 @@ public function execute()
* Get default menu item to be shown up.
*
* @param \Joomla\CMS\Menu\SiteMenu $menu Joomla menu.
* @param object $active Active menu item.
* @param array $visited Already visited menu items.
* @param object $active Active menu item.
* @param array $visited Already visited menu items.
*
* @return object|null
* @throws Exception
Expand All @@ -127,7 +127,7 @@ protected function getDefaultMenuItem(\Joomla\CMS\Menu\SiteMenu $menu, $active,
if (empty($active->query['defaultmenu']) || $active->id == $active->query['defaultmenu'])
{
// There is no highlighted menu item!
return;
return null;
}

$item = $menu->getItem($active->query['defaultmenu']);
Expand All @@ -137,27 +137,27 @@ protected function getDefaultMenuItem(\Joomla\CMS\Menu\SiteMenu $menu, $active,
// Menu item points to nowhere, abort!
KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_NOT_EXISTS'), 'menu');

return;
return null;
}
elseif (isset($visited[$item->id]))
{
// Menu loop detected, abort!
KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_LOOP'), 'menu');

return;
return null;
}
elseif (empty($item->component) || $item->component != 'com_kunena' || !isset($item->query['view']))
{
// Menu item doesn't point to Kunena, abort!
KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_NOT_KUNENA'), 'menu');

return;
return null;
}
elseif ($item->query['view'] == 'home')
{
// Menu item is pointing to another Home Page, try to find default menu item from there.
$visited[$item->id] = 1;
$item = $this->getDefaultMenuItem($menu, $item->query['defaultmenu'], $visited);
$item = $this->getDefaultMenuItem($menu, $item->query['defaultmenu'], $visited);
}

return $item;
Expand Down
32 changes: 17 additions & 15 deletions src/components/com_kunena/controllers/home.php
Expand Up @@ -2,15 +2,17 @@
/**
* Kunena Component
*
* @package Kunena.Site
* @subpackage Controllers
* @package Kunena.Site
* @subpackage Controllers
*
* @copyright Copyright (C) 2008 - 2018 Kunena Team. All rights reserved.
* @license https://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link https://www.kunena.org
* @copyright (C) 2008 - 2018 Kunena Team. All rights reserved.
* @license https://www.gnu.org/copyleft/gpl.html GNU/GPL
* @link https://www.kunena.org
**/
defined('_JEXEC') or die();

use Joomla\CMS\Factory;

/**
* Kunena Home Controller
*
Expand Down Expand Up @@ -40,8 +42,8 @@ public function display($cachable = false, $urlparams = false)

if (!$home)
{
$this->app->input->get('view', 'category');
$this->app->input->get('layout', 'list');
Factory::getApplication()->input->get('view', 'category');
Factory::getApplication()->input->get('layout', 'list');
}
else
{
Expand Down Expand Up @@ -76,11 +78,11 @@ public function display($cachable = false, $urlparams = false)
// Add query variables from shown menu item
foreach ($default->query as $var => $value)
{
$this->app->input->get($var, $value);
Factory::getApplication()->input->get($var, $value);
}

// Remove query variables coming from the home menu item
$this->app->input->get('defaultmenu', null);
Factory::getApplication()->input->get('defaultmenu', null);

// Set active menu item to point the real page
$menu->setActive($default->id);
Expand All @@ -98,8 +100,8 @@ public function display($cachable = false, $urlparams = false)
}

/**
* @param $menu
* @param $active
* @param $menu
* @param $active
* @param array $visited visited
*
* @return null
Expand All @@ -111,7 +113,7 @@ protected function _getDefaultMenuItem($menu, $active, $visited = array())
if (empty($active->query ['defaultmenu']) || $active->id == $active->query ['defaultmenu'])
{
// There is no highlighted menu item
return;
return null;
}

$item = $menu->getItem($active->query ['defaultmenu']);
Expand All @@ -121,21 +123,21 @@ protected function _getDefaultMenuItem($menu, $active, $visited = array())
// Menu item points to nowhere, abort
KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_NOT_EXISTS'), 'menu');

return;
return null;
}
elseif (isset($visited[$item->id]))
{
// Menu loop detected, abort
KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_LOOP'), 'menu');

return;
return null;
}
elseif (empty($item->component) || $item->component != 'com_kunena' || !isset($item->query ['view']))
{
// Menu item doesn't point to Kunena, abort
KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_MENU_NOT_KUNENA'), 'menu');

return;
return null;
}
elseif ($item->query ['view'] == 'home')
{
Expand Down

0 comments on commit 532c91c

Please sign in to comment.