Advertisement
Guest User

Untitled

a guest
Dec 20th, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.99 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @package plg_jlnodubles
  4.  * @author Arkadiy (a.sedelnikov@gmail.com), Vadim Kunicin (vadim@joomline.ru), Sher ZA (irina@hekima.ru).
  5.  * @version 1.1
  6.  * @copyright (C) 2014 by JoomLine (http://www.joomline.net)
  7.  * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
  8.  *
  9.  */
  10. defined('_JEXEC') or die;
  11. use Joomla\Registry\Registry;
  12. require_once JPATH_ROOT . '/components/com_content/helpers/route.php';
  13.  
  14. function myUrlEncode($string) {
  15.     $entities = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D');
  16.     $replacements = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]");
  17.     return str_replace($entities, $replacements, urlencode($string));
  18. }
  19.  
  20. class JLNodoubles_com_content_helper extends JLNodoublesHelper
  21. {
  22.  
  23.     function __construct($params)
  24.     {
  25.         parent::__construct($params);
  26.     }
  27.    
  28.  
  29.     public function go($allGet){
  30.         $original_link = '';
  31.         $app = JFactory::getApplication();
  32.         $uri = JUri::getInstance();
  33.         $homealias = $this->params->get('homealias', 'home');
  34.         $currentLink = $uri->toString(array('path', 'query'));
  35.         // die(print_r($allGet));
  36.  
  37.         switch ($allGet['view'])
  38.         {
  39.             case 'article':
  40.                 $db = JFactory::getDbo();
  41.                 $query = $db->getQuery(true);
  42.                 $query->select('`id`, `alias`, `catid`, `language`')
  43.                     ->from('#__content')
  44.                     ->where('`id` = '.(int)$allGet['id']);
  45.                 $item = $db->setQuery($query,0,1)->loadObject();
  46.  
  47.                 if(is_null($item))
  48.                 {
  49.                     return true;
  50.                 }
  51.  
  52.                 $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
  53.                 $original_link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language), false);
  54.  
  55.                 if (!$original_link)
  56.                 {
  57.                     return true;
  58.                 }
  59.  
  60.                 if (strpos($original_link, 'component/content/article') !== false && !empty($homealias))
  61.                 {
  62.                     $original_link = str_replace('component/content/article', $homealias, $original_link);
  63.                 }
  64.  
  65.                 $symb = "?";
  66.  
  67.                 if ($app->input->getInt('start') > 0)
  68.                 {
  69.                     $original_link .= $symb . "start=" . $app->input->getInt('start');
  70.                     $symb = "&";
  71.                 }
  72.  
  73.                 if ($app->input->getInt('showall') > 0)
  74.                 {
  75.                     $original_link .= $symb . "showall=" . $app->input->getInt('showall');
  76.                 }
  77.                 break;
  78.  
  79.             case 'frontpage':
  80.             case 'featured':
  81.                 $link = 'index.php?option=com_content&view=' . $allGet['view'];
  82.                 if ($app->input->getInt('start') > 0)
  83.                 {
  84.                     $link .= '&start=' . $app->input->getInt('start');
  85.                 }
  86.                 $original_link = JRoute::_($link);
  87.                 break;
  88.  
  89.             case 'category':
  90.                 $original_link = JRoute::_(ContentHelperRoute::getCategoryRoute($allGet['id']), false);
  91.  
  92.                 $start = $app->input->getInt('start', 0);
  93.                 if ($start > 0)
  94.                 {
  95.                     $params = $app->getParams();
  96.                     $menuParams = new Registry;
  97.  
  98.                     if ($menu = $app->getMenu()->getActive())
  99.                     {
  100.                         $menuParams->loadString($menu->params);
  101.                     }
  102.  
  103.                     $mergedParams = clone $menuParams;
  104.                     $mergedParams->merge($params);
  105.                     $itemid = $app->input->get('id', 0, 'int') . ':' . $app->input->get('Itemid', 0, 'int');
  106.  
  107.                     if (($app->input->get('layout') == 'blog') || $params->get('layout_type') == 'blog')
  108.                     {
  109.                         $limit = $params->get('num_leading_articles') + $params->get('num_intro_articles');
  110.                     }
  111.                     else
  112.                     {
  113.                         $limit = $app->getUserStateFromRequest('com_content.category.list.' . $itemid . '.limit', 'limit', $params->get('display_num'), 'uint');
  114.                     }
  115.  
  116.                     if($start % $limit != 0)
  117.                     {
  118.                         $start = intval($start / $limit) * $limit;
  119.                     }
  120.                     $original_link .= "?start=" . $start;
  121.                 }
  122.                 break;
  123.             case 'form':
  124.                 return true;
  125.                 break;
  126.             default:
  127.                 return false;
  128.                 break;
  129.         }
  130.  
  131.        
  132.        
  133.         if ($original_link && (myurlencode($original_link) != $currentLink))
  134.         {
  135.             $this->shRedirect($original_link);
  136.         }
  137.         return true;
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement