Exemplo n.º 1
0
 public function onAfterRoute()
 {
     $app = JFactory::getApplication();
     if ($app->getName() != 'site' || self::$noRedirect) {
         return true;
     }
     $option = $app->input->getCmd('option', '');
     $Itemid = $app->input->getInt('Itemid', 0);
     $view = $app->input->getCmd('view', '');
     $id = $app->input->getString('id', 0);
     $task = $app->input->getCmd('task', '');
     $layout = $app->input->getCmd('layout', '');
     $lang = $app->input->getCmd('lang', '');
     $allGet = array('Itemid' => $Itemid, 'option' => $option, 'view' => $view, 'id' => $id, 'task' => $task, 'layout' => $layout, 'lang' => $lang);
     $u = JUri::getInstance();
     $currentLink = $u->toString(array('path'));
     $uir = $_SERVER['REQUEST_URI'];
     $defValue = array(array('var_name' => array('task', 'format', 'no_html', 'tmpl'), 'var_value' => array('save, edit, add, delete, apply', 'nohtml', '1', 'component')), 'com_content' => array('checkbox' => 'on', 'var_name' => array(''), 'var_value' => array('')));
     $componentsvars = $this->params->get('componentsvars', $defValue);
     if (is_object($componentsvars)) {
         $tmp = array();
         foreach ($componentsvars as $k => $val) {
             $tmp[$k] = (array) $val;
         }
         $componentsvars = $tmp;
         unset($tmp);
     }
     if (!isset($componentsvars[$option]["checkbox"])) {
         self::$noRedirect = true;
         return true;
     }
     if (isset($componentsvars[$option])) {
         for ($i = 0; $i < sizeof($componentsvars[$option]["var_name"]); $i++) {
             $var_name = $componentsvars[$option]["var_name"][$i];
             if (trim($componentsvars[$option]["var_value"][$i])) {
                 $var_values = array_map('trim', explode(',', $componentsvars[$option]["var_value"][$i]));
                 foreach ($var_values as $vvalue) {
                     if (isset($allGet[trim($var_name)]) && $allGet[trim($var_name)] == trim($vvalue)) {
                         self::$noRedirect = true;
                         return true;
                     }
                 }
             } else {
                 if (isset($allGet[$var_name])) {
                     self::$noRedirect = true;
                     return true;
                 }
             }
         }
     }
     $helperPath = JPATH_ROOT . '/plugins/system/jlnodoubles/helpers/' . $option . '.php';
     $return = true;
     if (is_file($helperPath) && ($option == 'com_content' || self::$isPro)) {
         require_once $helperPath;
         $class = 'JLNodoubles_' . $option . '_helper';
         if (class_exists($class)) {
             $this->params->set('isPro', self::$isPro);
             $helper = new $class($this->params);
             if (method_exists($helper, 'go')) {
                 $return = $helper->go($allGet);
             }
         }
     }
     if ($option && $return == false) {
         $allGetArr = array();
         foreach ($allGet as $ag_name => $ag_value) {
             if ($ag_name && $ag_value) {
                 $allGetArr[] = $ag_name . '=' . $ag_value;
             }
         }
         if (!$Itemid) {
             $app = JFactory::getApplication();
             $menus = $app->getMenu();
             //$menus = &JApplication::getMenu('site', array());
             $component_menu = $menus->getItems('component', $option);
             $Itemid = $component_menu[0]->id;
             if ($Itemid) {
                 $allGetArr[] = 'Itemid=' . $Itemid;
             }
         }
         $redirectLink = JRoute::_('index.php?' . implode('&', $allGetArr));
         if ($redirectLink != $currentLink) {
             JLNodoublesHelper::getInstance($this->params)->shRedirect($redirectLink);
         }
     }
     return true;
 }