Example #1
0
 /**
  * Parses the route.
  *
  * @param KCommandContext $context Command chain context
  *
  * @return bool
  */
 protected function _actionRoute(KCommandContext $context)
 {
     //route the application
     $url = clone KRequest::url();
     $this->_application->getRouter()->parse($url);
     JRequest::set($url->query, 'get', false);
     // trigger the onAfterRoute events
     $this->_application->triggerEvent('onAfterRoute');
     $url->query = KRequest::get('get', 'raw');
     //globally set ItemId
     global $Itemid;
     $Itemid = KRequest::get('get.Itemid', 'int', 0);
     //set the request
     $this->getRequest()->append($url->query);
     $component = substr($this->_request->option, 4);
     $this->setComponent($component);
 }
Example #2
0
 /**
  * Return a reference to the JRouter object.
  *
  * @param   string    $name        The name of the application.
  * @param   array     $options     An optional associative array of configuration settings.
  *
  * @return  JRouter
  * @since   1.5
  */
 public static function getRouter($name = null, array $options = array())
 {
     $config = JFactory::getConfig();
     $options['mode'] = $config->get('sef');
     $router = parent::getRouter('site', $options);
     return $router;
 }
Example #3
0
 /**
  * Return a reference to the JRouter object.
  *
  * @access	public
  * @return	JRouter.
  * @since	1.5
  */
 function &getRouter()
 {
     $router =& parent::getRouter('administrator');
     return $router;
 }
 /**
  * Return a reference to the JRouter object.
  *
  * @return	JRouter
  * @since	1.5
  */
 public static function getRouter($name = null, array $options = array())
 {
     $router = parent::getRouter('administrator');
     return $router;
 }
Example #5
0
 /**
  * Returns the application JRouter object.
  *
  * @param   string  $name     The name of the application.
  * @param   array   $options  An optional associative array of configuration settings.
  * @return  JRouter  A JRouter object
  */
 public static function getRouter($name = null, array $options = array())
 {
     //die('getRouter() invalid in API application context');
     /*
     if(!isset($name)) {
     	$name = $this->_name;
     }
     
     jimport( 'joomla.application.router' );
     $router =& JRouter::getInstance($name, $options);
     if (JError::isError($router)) {
     	$null = null;
     	return $null;
     }
     return $router;
     */
     $config = JFactory::getConfig();
     $options['mode'] = $config->getValue('config.sef');
     $router = parent::getRouter('api', $options);
     return $router;
 }
Example #6
0
 function loadMenu($menuname = 'mainmenu')
 {
     $list = array();
     $db = JFactory::getDbo();
     $acl = JFactory::getACL();
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     $menu = $app->getMenu();
     $aid = max($user->getAuthorisedViewLevels());
     //find active element or set default
     $active = $menu->getActive() ? $menu->getActive() : $menu->getDefault();
     $this->open = $active->tree;
     $rows = $menu->getItems('menutype', $menuname);
     if (!count($rows)) {
         return;
     }
     $children = array();
     $this->items = array();
     foreach ($rows as $index => $v) {
         if (isset($v->title)) {
             $v->name = $v->title;
         }
         if (isset($v->parent_id)) {
             $v->parent = $v->parent_id;
         }
         $v->name = str_replace('&', '&', str_replace('&amp', '&', $v->name));
         if ($v->access <= $aid) {
             $ptr = $v->parent;
             $list = @$children[$ptr] ? $children[$ptr] : array();
             $v->gkparams = new JObject();
             $v->gkparams = $gkparams = new JObject(json_decode($v->params));
             if ($gkparams) {
                 foreach (get_object_vars($gkparams) as $gk_name => $gk_value) {
                     if (preg_match('/gk_(.+)/', $gk_name, $matches)) {
                         if (is_array($gk_value)) {
                             $gk_value = implode(',', $gk_value);
                         }
                         $v->gkparams->set($matches[1], $gk_value);
                     }
                 }
             }
             // set cols to 1
             if ($v->gkparams->get('group')) {
                 $v->gkparams->set('cols', 1);
             }
             if ($v->gkparams->get('subcontent') == 'pos') {
                 $modules = $this->loadModules($v->gkparams);
                 if ($modules && count($modules) > 0) {
                     $v->content = "";
                     $total = count($modules);
                     $cols = min($v->gkparams->get('cols'), $total);
                     for ($col = 0; $col < $cols; $col++) {
                         $pos = $col == 0 ? 'first' : ($col == $cols - 1 ? 'last' : '');
                         if ($cols > 1) {
                             $v->content .= $this->beginSubMenuModules($v->id, 1, $pos, $col, true);
                         }
                         $i = $col;
                         while ($i < $total) {
                             $mod = $modules[$i];
                             $i += $cols;
                             $mod_params = new JObject(json_decode($mod->params));
                             $v->content .= "<jdoc:include type=\"modules\" name=\"{$mod->position}\" style=\"" . $v->gkparams->get('style', 'none') . "\" />";
                         }
                         if ($cols > 1) {
                             $v->content .= $this->endSubMenuModules($v->id, 1, true);
                         }
                     }
                     $v->cols = $cols;
                     $v->content = trim($v->content);
                     $this->items[$v->id] = $v;
                 }
             }
             // friendly links
             $v->flink = $v->link;
             switch ($v->type) {
                 case 'separator':
                     continue;
                 case 'url':
                     if (strpos($v->link, 'index.php?') === 0 && strpos($v->link, 'Itemid=') === false) {
                         $v->flink = $v->link . '&Itemid=' . $v->id;
                     }
                     break;
                 case 'alias':
                     $v->flink = 'index.php?Itemid=' . $v->gkparams->get('aliasoptions');
                     break;
                 default:
                     $router = JApplication::getRouter();
                     $router->getMode() == JROUTER_MODE_SEF ? $v->flink = 'index.php?Itemid=' . $v->id : ($v->flink .= '&Itemid=' . $v->id);
                     break;
             }
             $v->url = $v->flink = JRoute::_($v->flink);
             if ($v->home == 1) {
                 $v->url = JURI::base();
             }
             // class suffix
             if (!isset($v->clssfx)) {
                 $v->clssfx = $v->gkparams->get('pageclass_sfx', '');
                 if ($v->gkparams->get('cols')) {
                     $v->cols = $v->gkparams->get('cols');
                     $v->col = array();
                     for ($i = 0; $i < $v->cols; $i++) {
                         if ($v->gkparams->get("col{$i}")) {
                             $v->col[$i] = $v->gkparams->get("col{$i}");
                         }
                     }
                 }
             }
             $v->_idx = count($list);
             array_push($list, $v);
             $children[$ptr] = $list;
             $this->items[$v->id] = $v;
         }
     }
     $this->children = $children;
     foreach ($this->items as $v) {
         if (($v->gkparams->get('subcontent') || $v->gkparams->get('modpos')) && !isset($this->children[$v->id]) && (!isset($v->content) || !$v->content)) {
             $this->remove_item($this->items[$v->id]);
             unset($this->items[$v->id]);
         }
     }
 }
Example #7
0
	public static function getList(&$params)
	{
		$lang = JFactory::getLanguage();
		$languages	= JLanguageHelper::getLanguages();
		$app		= JFactory::getApplication();

        //use to remove default language code in url
        $lang_codes 	= JLanguageHelper::getLanguages('lang_code');
        $default_lang = JComponentHelper::getParams('com_languages')->get('site', 'en-GB');
        $default_sef 	= $lang_codes[$default_lang]->sef;

        $sefToolsEnabled = modFaLangHelper::sefToolEnabled();


        $menu = $app->getMenu();
        $active = $menu->getActive();
        $uri = JURI::getInstance();


        // Get menu home items
        $homes = array();

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


        if (FALANG_J30) {
            //since 3.2
            if (version_compare(JVERSION, '3.2', 'ge')) {
                $assoc =  JLanguageAssociations::isEnabled();
            } else {
                $assoc = isset($app->item_associations) ? (boolean) $app->item_associations : false;
            }
        } else {
            $assoc = (boolean) $app->get('menu_associations', true);
        }


		if ($assoc) {
			if ($active) {
				$associations = MenusHelper::getAssociations($active->id);
			}
		}
   		foreach($languages as $i => &$language) {
			// Do not display language without frontend UI
			if (!JLanguage::exists($language->lang_code)) {
				unset($languages[$i]);
			}
            if (FALANG_J30) {
                $language_filter = JLanguageMultilang::isEnabled();
            } else {
                $language_filter = $app->getLanguageFilter();
            }



            //set language active before language filter use for sh404 notice
            $language->active =  $language->lang_code == $lang->getTag();

            //since v1.4 change in 1.5 , ex rsform preview don't have active
            if (isset($active)){
                $language->display = ($active->language == '*' || $language->active)?true:false;
            } else {
                $language->display = true;
            }


            if ($language_filter) {
                if (isset($associations[$language->lang_code]) && $menu->getItem($associations[$language->lang_code])) {
                    $language->display = true;
                    $itemid = $associations[$language->lang_code];
                    if ($app->getCfg('sef')=='1') {
                        $language->link = JRoute::_('index.php?lang='.$language->sef.'&Itemid='.$itemid);
                    }
                    else {
                        $language->link = 'index.php?lang='.$language->sef.'&Itemid='.$itemid;
                    }
                }
                else {
                    //sef case
                    if ($app->getCfg('sef')=='1') {

                        //sefToolsEnabled
                        if ($sefToolsEnabled) {
                            $itemid = isset($homes[$language->lang_code]) ? $homes[$language->lang_code]->id : $homes['*']->id;
                            $language->link = JRoute::_('index.php?lang='.$language->sef.'&Itemid='.$itemid);
                            continue;
                        }


                         //$uri->setVar('lang',$language->sef);
                         $router = JApplication::getRouter();
                         $tmpuri = clone($uri);

                         $router->parse($tmpuri);

                         $vars = $router->getVars();
                         //workaround to fix index language
                         $vars['lang'] = $language->sef;

                        //case of category article
                        if (!empty($vars['view']) && $vars['view'] == 'article' && !empty($vars['option']) && $vars['option'] == 'com_content') {

                            if (FALANG_J30){
                                JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel');
                                $model = JModelLegacy::getInstance('Article', 'ContentModel', array('ignore_request'=>true));
                                $appParams = JFactory::getApplication()->getParams();
                            } else {
                                JModel::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel');
                                $model =& JModel::getInstance('Article', 'ContentModel', array('ignore_request'=>true));
                                $appParams = JFactory::getApplication()->getParams();
                            }


                            $model->setState('params', $appParams);

                            //in sef some link have this url
                            //index.php/component/content/article?id=39
                            //id is not in vars but in $tmpuri
                            if (empty($vars['id'])) {
                                $tmpid = $tmpuri->getVar('id');
                                if (!empty($tmpid)) {
                                    $vars['id'] = $tmpuri->getVar('id');
                                } else {
                                    continue;
                                }
                            }

                            $item = $model->getItem($vars['id']);

                            //get alias of content item without the id , so i don't have the translation
                            $db = JFactory::getDbo();
                            $query = $db->getQuery(true);
                            $query->select('alias')->from('#__content')->where('id = ' . (int) $item->id);
                            $db->setQuery($query);
                            $alias = $db->loadResult();

                            $vars['id'] = $item->id.':'.$alias;
                            $vars['catid'] =$item->catid.':'.$item->category_alias;
                        }

                        //new version 1.5
                        //case for k2 item alias write twice
                        if (isset($vars['option']) && $vars['option'] == 'com_k2'){
                            if ($vars['task'] == $vars['id']){
                                unset($vars['id']);
                            }
                        }
                        $url = 'index.php?'.JURI::buildQuery($vars);
                        $language->link = JRoute::_($url);

                        //TODO check performance 3 queries by languages -1
                        /**
                         * Replace the slug from the language switch with correctly translated slug.
                         * $language->lang_code language de la boucle (icone lien)
                         * $lang->getTag() => language en cours sur le site
                         * $default_lang langue par default du site
                         */
                        if($lang->getTag() != $language->lang_code && !empty($vars['Itemid']))
                        {
                            $fManager = FalangManager::getInstance();
                            $id_lang = $fManager->getLanguageID($language->lang_code);
                            $db = JFactory::getDbo();
                            // get translated path if exist
                            $query = $db->getQuery(true);
                            $query->select('fc.value')
                                ->from('#__falang_content fc')
                                ->where('fc.reference_id = '.(int)$vars['Itemid'])
                                ->where('fc.language_id = '.(int) $id_lang )
                                ->where('fc.reference_field = \'path\'')
                                ->where('fc.reference_table = \'menu\'');
                            $db->setQuery($query);
                            $translatedPath = $db->loadResult();

                            // $translatedPath not exist if not translated or site default language
                            // don't pass id to the query , so no translation given by falang
                            $query = $db->getQuery(true);
                            $query->select('m.path')
                                ->from('#__menu m')
                                ->where('m.id = '.(int)$vars['Itemid']);
                            $db->setQuery($query);
                            $originalPath = $db->loadResult();

                            $pathInUse = null;
                            //si on est sur une page traduite on doit récupérer la traduction du path en cours
                            if ($default_lang != $lang->getTag() ) {
                                $id_lang = $fManager->getLanguageID($lang->getTag());
                                // get translated path if exist
                                $query = $db->getQuery(true);
                                $query->select('fc.value')
                                    ->from('#__falang_content fc')
                                    ->where('fc.reference_id = '.(int)$vars['Itemid'])
                                    ->where('fc.language_id = '.(int) $id_lang )
                                    ->where('fc.reference_field = \'path\'')
                                    ->where('fc.reference_table = \'menu\'');
                                $db->setQuery($query);
                                $pathInUse = $db->loadResult();

                            }

                            if (!isset($translatedPath)) {
                                $translatedPath = $originalPath;
                            }

                            // not exist if not translated or site default language
                            if (!isset($pathInUse)) {
                                $pathInUse = $originalPath ;
                            }

                            //make replacement in the url

                            //si language de boucle et language site
                            if($language->lang_code == $default_lang) {
                                if (isset($pathInUse) && isset($originalPath)){
                                    $language->link = str_replace($pathInUse, $originalPath, $language->link);
                                }
                            } else {
                                if (isset($pathInUse) && isset($translatedPath)){
                                    $language->link = str_replace($pathInUse, $translatedPath, $language->link);
                                }
                            }

                        }
                    }
                    //default case
             else {
                        //we can't remove default language in the link
                        $uri->setVar('lang',$language->sef);
                        $language->link = 'index.php?'.$uri->getQuery();
                    }
                }
            }
            else {
                $language->link = 'index.php';
            }

		}
		return $languages;
	}
Example #8
0
 function loadMenu($menuname = 'mainmenu')
 {
     $list = array();
     $db = JFactory::getDbo();
     $acl = JFactory::getACL();
     $user = JFactory::getUser();
     $app = JFactory::getApplication();
     $menu = $app->getMenu();
     $aid = $user->get('aid');
     //find active element or set default
     $active = $menu->getActive() ? $menu->getActive() : $menu->getDefault();
     $this->open = $active->tree;
     $this->open = $this->open[count($this->open) - 1];
     $rows = $menu->getItems('menutype', $menuname);
     if (!count($rows)) {
         return;
     }
     $children = array();
     $this->items = array();
     foreach ($rows as $index => $v) {
         if (isset($v->title)) {
             $v->name = $v->title;
         }
         if (isset($v->parent_id)) {
             $v->parent = $v->parent_id;
         }
         $v->name = str_replace('&', '&amp;', str_replace('&amp', '&', $v->name));
         if ($v->access >= $aid) {
             $ptr = $v->parent;
             $list = @$children[$ptr] ? $children[$ptr] : array();
             // friendly links
             $v->flink = $v->link;
             switch ($v->type) {
                 case 'separator':
                     continue;
                 case 'url':
                     if (strpos($v->link, 'index.php?') === 0 && strpos($v->link, 'Itemid=') === false) {
                         $v->flink = $v->link . '&Itemid=' . $v->id;
                     }
                     break;
                 case 'alias':
                     $v->flink = 'index.php?Itemid=' . $v->params->get('aliasoptions');
                     break;
                 default:
                     $router = JApplication::getRouter();
                     if ($router->getMode() == JROUTER_MODE_SEF) {
                         $v->flink = 'index.php?Itemid=' . $v->id;
                     } else {
                         $v->flink .= '&Itemid=' . $v->id;
                     }
                     break;
             }
             $v->url = $v->flink = JRoute::_($v->flink);
             if ($v->home == 1) {
                 $v->url = JURI::base();
             }
             $v->_idx = count($list);
             array_push($list, $v);
             $children[$ptr] = $list;
             $this->items[$v->id] = $v;
         }
     }
     $this->children = $children;
 }
Example #9
0
	/**
	 * Return a reference to the JRouter object.
	 *
	 * @access	public
	 * @return	JRouter.
	 * @since	1.5
	 */
	function &getRouter()
	{
		$config =& JFactory::getConfig();
		$options['mode'] = $config->getValue('config.sef');
		$router =& parent::getRouter('site', $options);
		return $router;
	}
 /**
  * Return a reference to the JRouter object.
  *
  * @access	public
  * @return	JRouter.
  * @since	1.5
  */
 function &getRouter()
 {
     $options['mode'] = $this->getCfg('sef');
     $router =& parent::getRouter('forum', $options);
     return $router;
 }