Skip to content

Commit

Permalink
Refactoring helper of mod_languages
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackwar committed Feb 2, 2015
1 parent 4d285b4 commit 5f24089
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions modules/mod_languages/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ abstract class ModLanguagesHelper
*/
public static function getList(&$params)
{
$user = JFactory::getUser();
$lang = JFactory::getLanguage();
$app = JFactory::getApplication();
$menu = $app->getMenu();
$user = JFactory::getUser();
$lang = JFactory::getLanguage();
$languages = JLanguageHelper::getLanguages();
$app = JFactory::getApplication();
$menu = $app->getMenu();

// Get menu home items
$homes = array();
$homes['*'] = $menu->getDefault('*');

foreach ($menu->getMenu() as $item)
foreach ($languages as $item)
{
if ($item->home)
if ($menu->getDefault($item->lang_code))
{
$homes[$item->language] = $item;
$homes[$item->lang_code] = $menu->getDefault($item->lang_code);
}
}

Expand All @@ -59,20 +61,16 @@ public static function getList(&$params)
}

// Load component associations
$option = $app->input->get('option');
$eName = JString::ucfirst(JString::str_ireplace('com_', '', $option));
$cName = JString::ucfirst($eName . 'HelperAssociation');
JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php'));
$class = str_replace('com_', '', $app->input->get('option')) . 'HelperAssociation';
JLoader::register($class, JPATH_COMPONENT_SITE . '/helpers/association.php');

if (class_exists($cName) && is_callable(array($cName, 'getAssociations')))
if (class_exists($class) && is_callable(array($class, 'getAssociations')))
{
$cassociations = call_user_func(array($cName, 'getAssociations'));
$cassociations = call_user_func(array($class, 'getAssociations'));
}
}

$levels = $user->getAuthorisedViewLevels();
$languages = JLanguageHelper::getLanguages();
$activeLanguage = JFactory::getLanguage()->getTag();

// Filter allowed languages
foreach ($languages as $i => &$language)
Expand Down Expand Up @@ -105,31 +103,19 @@ public static function getList(&$params)
elseif (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code]))
{
$itemid = $associations[$language->lang_code];

if ($app->get('sef') == '1')
{
$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
}
else
{
$language->link = 'index.php?lang=' . $language->sef . '&Itemid=' . $itemid;
}
$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
}
else
{
if ($language->lang_code == $activeLanguage)
if (isset($language->active))
{
$language->link = JUri::current();
}
elseif ($app->get('sef') == '1')
else
{
$itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
$language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
}
else
{
$language->link = 'index.php?lang=' . $language->sef;
}
}
}
else
Expand Down

0 comments on commit 5f24089

Please sign in to comment.