Beispiel #1
0
	/**
	 * @param JUri $uri
	 * @param bool $object
	 *
	 * @return JUri|string
	 */
	public static function normalize($uri = null, $object = false)
	{
		if (self::$adminApp)
		{
			// Use default routing in administration
			return $object ? $uri : 'index.php?' . $uri->getQuery ();
		}

		KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;

		$uri = self::prepare($uri);

		if (!$uri)
		{
			return false;
		}

		if (!$uri->getVar('Itemid'))
		{
			self::setItemID ( $uri );
		}

		$result = $object ? $uri : 'index.php?' . $uri->getQuery ();
		KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__CLASS__.'::'.__FUNCTION__.'()') : null;

		return $result;
	}
Beispiel #2
0
 /**
  * Constructor for the class.
  *
  * @param   string   $title      The title of the node
  * @param   string   $link       The node link
  * @param   string   $class      The CSS class for the node
  * @param   boolean  $active     True if node is active, false otherwise
  * @param   string   $target     The link target
  * @param   string   $titleicon  The title icon for the node
  */
 public function __construct($title, $link = null, $class = null, $active = false, $target = null, $titleicon = null)
 {
     $this->title = $titleicon ? $title . $titleicon : $title;
     $this->link = JFilterOutput::ampReplace($link);
     $this->class = $class;
     $this->active = $active;
     $this->id = null;
     if (!empty($link) && $link !== '#') {
         $uri = new JUri($link);
         $params = $uri->getQuery(true);
         $parts = array();
         foreach ($params as $value) {
             $parts[] = str_replace(array('.', '_'), '-', $value);
         }
         $this->id = implode('-', $parts);
     }
     $this->target = $target;
 }
 /**
  * @param JRouter $router
  * @param JUri $uri
  */
 function buildRule(&$router, &$uri)
 {
     $MobileJoomla_Device =& MobileJoomla::getDevice();
     if ($MobileJoomla_Device['markup'] != $MobileJoomla_Device['default_markup']) {
         switch ($uri->getVar('format')) {
             case 'feed':
             case 'json':
             case 'xml':
                 return;
         }
         switch ($uri->getVar('type')) {
             case 'rss':
             case 'atom':
                 return;
         }
         if ((is_a($router, 'shRouter') || class_exists('Sh404sefClassRouter')) && $uri->getVar('Itemid') && count($uri->getQuery(true)) == 2) {
             $itemid = $uri->getVar('Itemid');
             $app = JFactory::getApplication();
             $menu = $app->getMenu();
             $item = $menu->getItem($itemid);
             $uri->setQuery($item->query);
             $uri->setVar('Itemid', $itemid);
             $uri->setVar('device', $MobileJoomla_Device['markup']);
         } else {
             $uri->setVar('device', $MobileJoomla_Device['markup']);
         }
     }
 }
 /**
  * Test the getQuery method.
  *
  * @return  void
  *
  * @since   11.1
  * @covers  JUri::getQuery
  */
 public function testGetQuery()
 {
     $this->object->parse('http://*****:*****@www.example.com:80/path/file.html?var=value#fragment');
     $this->assertThat($this->object->getQuery(), $this->equalTo('var=value'));
     $this->assertThat($this->object->getQuery(true), $this->equalTo(array('var' => 'value')));
 }
Beispiel #5
0
 /**
  * Process the build uri query data based on custom defined rules
  *
  * @param   JUri  $uri  The URI
  *
  * @return  void
  */
 protected function _processBuildRules($uri)
 {
     // Make sure any menu vars are used if no others are specified
     if ($this->_mode != JROUTER_MODE_SEF && $uri->getVar('Itemid') && count($uri->getQuery(true)) == 2) {
         $app = JApplication::getInstance('site');
         $menu = $app->getMenu();
         // Get the active menu item
         $itemid = $uri->getVar('Itemid');
         $item = $menu->getItem($itemid);
         if ($item) {
             $uri->setQuery($item->query);
         }
         $uri->setVar('Itemid', $itemid);
     }
     // Process the attached build rules
     parent::_processBuildRules($uri);
     // Get the path data
     $route = $uri->getPath();
     if ($this->_mode == JROUTER_MODE_SEF && $route) {
         if ($limitstart = $uri->getVar('limitstart')) {
             $uri->setVar('start', (int) $limitstart);
             $uri->delVar('limitstart');
         }
     }
     $uri->setPath($route);
 }
function shSefRelToAbs($string, $shLanguageParam, &$uri, &$originalUri) {

  global $_SEF_SPACE, $shGETVars, $shRebuildNonSef;

  _log('Entering shSefRelToAbs with '.$string.' | Lang = '.$shLanguageParam);

  $mainframe = JFactory::getApplication();

  $pageInfo = & Sh404sefFactory::getPageInfo();
  $sefConfig = & Sh404sefFactory::getConfig();
  _log('HomeLinks = ', $pageInfo->homeLinks);

  // if superadmin, display non-sef URL, for testing/setting up purposes
  if (sh404SEF_NON_SEF_IF_SUPERADMIN) {
    $user = JFactory::getUser();
    if ($user->usertype == 'Super Administrator' ) {
      _log('Returning non-sef because superadmin said so.');
      return 'index.php';
    }
  }
  // return unmodified anchors
  if (JString::substr( $string, 0, 1) == '#') {
    // V 1.2.4.t
    return $string;
  }
  // Quick fix for shared SSL server : if https, switch to non sef
  $id = shGetURLVar($string, 'Itemid', JRequest::getInt( 'Itemid'));
  $secure = 'yes' == shGetMenuItemSsl( $id);
  if ($secure && $sefConfig->shForceNonSefIfHttps ) {
    _log('Returning shSefRelToAbs : Forced non sef if https');
    return shFinalizeURL($string);
  }

  $database =& JFactory::getDBO();

  $shOrigString = $string;
  $shMosMsg = shGetMosMsg($string); // V x 01/09/2007 22:45:52
  $string = shCleanUpMosMsg($string);// V x 01/09/2007 22:45:52

  // V x : removed shJoomfish module. Now we set $mosConfi_lang here
  $shOrigLang = $pageInfo->shMosConfig_locale; // save current language
  $shLanguage = shGetURLLang( $string);  // target language in URl is always first choice
  // second choice is param
  if(empty( $shLanguage)) {
    $shLanguage = !empty($shLanguageParam) ? $shLanguageParam : $shLanguage;
  }
  // third choice is to read from menu, based on Itemid
  if(empty( $shLanguage) && !empty( $id)) {
    $shLanguage = shGetMenuItemLanguage($id);
  }
  if (empty($shLanguage)) {
    $shLanguage = !empty($shLanguageParam) ? $shLanguageParam : $pageInfo->shMosConfig_locale;
  }

  // V 1.3.1 protect against those drop down lists
  if (strpos( $string, 'this.options[selectedIndex].value') !== false) {
    $string .= '&lang='.shGetIsoCodeFromName($shLanguage);
    return $string;
  }
  $pageInfo->shMosConfig_locale = $shLanguage;
  _log('Language used : '.$shLanguage);

  // V 1.2.4.t workaround for old links like option=compName instead of option=com_compName
  if ( strpos(strtolower($string), 'option=login') === false && strpos(strtolower($string), 'option=logout') === false &&
  strpos(strtolower($string), 'option=&') === false && JString::substr(strtolower($string), -7) != 'option='
  && strpos(strtolower($string), 'option=cookiecheck') === false
  && strpos(strtolower($string), 'option=') !== false && strpos(strtolower($string), 'option=com_') === false) {
    $string = str_replace('option=', 'option=com_', $string);
  }
  // V 1.2.4.j string to be appended to URL, but not saved to DB
  $shAppendString = '';
  $shRebuildNonSef = array();
  $shComponentType = '';  // V w initialize var to avoid notices

  if ($pageInfo->homeLink) {
    // now check URL against our homepage, so as to always return / if homepage
    $v1 = JString::ltrim(str_replace($pageInfo->getDefaultLiveSite(), '', $string), '/');
    // V 1.2.4.m : remove anchor if any
    $v2 = explode( '#', $v1);
    $v1 = $v2[0];
    $shAnchor = isset($v2[1]) ? '#'.$v2[1] : '';
    $shSepString = (JString::substr($v1, -9) == 'index.php' || strpos( $v1, '?') === false) ? '?':'&';
    $shLangString = 'lang='.shGetIsoCodeFromName($shLanguage);
    if (!strpos($v1,'lang=')) {
      $v1 .= $shSepString . $shLangString;
    }
    $v1 = str_replace('&', '&', shSortURL($v1));
    // V 1.2.4.t check also without pagination info
    if (strpos( $v1, 'limitstart=0') !== false) {
      // the page has limitstart=0
      $stringNoPag = shCleanUpPag($v1);  // remove paging info to be sure this is not homepage
    } else {
      $stringNoPag = null;
    }
    if ($v1 == $pageInfo->homeLink
    || $v1 == $pageInfo->allLangHomeLink
    || $v1 == 'index.php?'.$shLangString
    || $stringNoPag == $pageInfo->homeLink
    || $stringNoPag == $pageInfo->allLangHomeLink
    )  {
      $shTemp = $v1 == $pageInfo->homeLink || shIsDefaultLang($shLanguage) ? '' : shGetIsoCodeFromName($shLanguage) . '/';

      if (!empty($sefConfig->shForcedHomePage)) {
        // V 1.2.4.t
        $shTmp = $shTemp.$shAnchor;
        $ret = shFinalizeURL($sefConfig->shForcedHomePage.(empty($shTmp) ? '' : '/'.$shTmp));
        if (empty($uri))  // if no URI, append remaining vars directly to the string
        $ret .= $shAppendString;
        else
        shRebuildVars( $shAppendString, $uri);
        $pageInfo->shMosConfig_locale = $shOrigLang;
        _log('Returning shSefRelToAbs 1 with '.$ret);
        return $ret;
      } else {
        $shRewriteBit = shIsDefaultLang($shLanguage)? '/': $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode];
        $ret = shFinalizeURL($pageInfo->getDefaultLiveSite().$shRewriteBit.$shTemp.$shAnchor);
        if (empty($uri))  // if no URI, append remaining vars directly to the string
        $ret .= $shAppendString;
        else
        shRebuildVars( $shAppendString, $uri);
        $pageInfo->shMosConfig_locale = $shOrigLang;
        _log('Returning shSefRelToAbs 2 with '.$ret);
        return $ret;
      }
    }
  }

  $newstring = str_replace($pageInfo->getDefaultLiveSite().'/', '', $string);

  $letsGo = JString::substr($newstring,0,9) == 'index.php'
  && (strpos( $newstring, 'this.options[selectedIndex\].value' ) === false);
  $letsGoSsl = false;
  if ($letsGo || $letsGoSsl)
  {
    // Replace & character variations.
    $string = str_replace(array('&', '&'), array('&', '&'), $letsGo ? $newstring : $newStringSsl);
    $newstring = $string; // V 1.2.4.q
    $shSaveString = $string;
    // warning : must add &lang=xx (only if it does not exists already), so as to be able to recognize the SefURL in the db if it's there
    if (!strpos($string,'lang=')) {
      $shSepString = JString::substr($string, -9) == 'index.php' ? '?':'&';
      $anchorTable = explode('#', $string); // V 1.2.4.m remove anchor before adding language
      $string = $anchorTable[0];
      $string .= $shSepString.'lang='.shGetIsoCodeFromName($shLanguage)
      .(!empty($anchorTable[1])? '#'.$anchorTable[1]:''); // V 1.2.4.m then stitch back anchor
    }
    $URI = new sh_Net_URL($string);
    // V 1.2.4.l need to save unsorted URL
    if (count($URI->querystring) > 0) {
      // Import new vars here.
      $option = null;
      $task = null;
      //$sid = null;  V 1.2.4.s
      // sort GET parameters to avoid some issues when same URL is produced with options not
      // in the same order, ie index.php?option=com_virtuemart&category_id=3&Itemid=2&lang=fr
      // Vs index.php?category_id=3&option=com_virtuemart&Itemid=2&lang=fr
      ksort($URI->querystring);  // sort URL array
      $string = shSortUrl($string);
      // now we are ready to extract vars
      $shGETVars = $URI->querystring;
      extract($URI->querystring, EXTR_REFS);
    }

    if (empty($option)) {
      // V 1.2.4.r protect against empty $option : we won't know what to do
      $pageInfo->shMosConfig_locale = $shOrigLang;
      _log('Returning shSefRelToAbs 3 with '.$shOrigString);
      return $shOrigString;
    }

    // get plugin associated with the extension
    $extPlugin = & Sh404sefFactory::getExtensionPlugin( $option);

    // get component type
    $shComponentType = $extPlugin->getComponentType();
    $shOption = str_replace('com_', '', $option);

    //list of extension we always skip
    $alwaysSkip = array( 'jce', 'akeeba');
    if( in_array($shOption, $alwaysSkip)) {
      $shComponentType = Sh404sefClassBaseextplugin::TYPE_SKIP;
    }

    // V 1.2.4.s : fallback to to JoomlaSEF if no extension available
    // V 1.2.4.t : this is too early ; it prevents manual custom redirect to be checked agains the requested non-sef URL
    _log('Component type = '.$shComponentType);
    // is there a named anchor attached to $string? If so, strip it off, we'll put it back later.
    if ($URI->anchor)
    $string = str_replace('#'.$URI->anchor, '', $string);  // V 1.2.4.m
    // shumisha special homepage processing (in other than default language)
    if  ((shIsAnyHomePage($string)) || ($string == 'index.php')  // 10/08/2007 18:13:43
    ){
      $sefstring = '';
      $urlType = shGetSefURLFromCacheOrDB($string, $sefstring);
      // still use it so we need it both ways
      if (($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) && empty($showall) && (!empty($limit) || (!isset($limit) && !empty($limitstart))) ) {
        $urlType = shGetSefURLFromCacheOrDB(shCleanUpPag($string), $sefstring); // V 1.2.4.t check also without page info
        //to be able to add pagination on custom
        //redirection or multi-page homepage
        if ($urlType != sh404SEF_URLTYPE_NONE && $urlType != sh404SEF_URLTYPE_404) {
          $sefstring = shAddPaginationInfo( @$limit, @$limitstart, @showall,1, $string, $sefstring, null);
          // a special case : com_content  does not calculate pagination right
          // for frontpage and blog, they include links shown at the bottom in the calculation of number of items
          // For instance, with joomla sample data, the frontpage has only 5 articles
          // but the view sets $limit to 9 !!!
          if (($option == 'com_content' && isset($layout) && $layout == 'blog')
          || ($option == 'com_content' && isset( $view) && $view == 'frontpage' )) {
            $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true);
            $string = shSetURLVar( $string, 'limit', $listLimit);
            $string = shSortUrl($string);
          }

          // that's a new URL, so let's add it to DB and cache
          shAddSefUrlToDBAndCache( $string, $sefstring, 0, $urlType);  // created url must be of same type as original
        }
        if ($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) {
          require_once(sh404SEF_FRONT_ABS_PATH.'sef_ext.php');
          $sef_ext = new sef_404();
          // Rewrite the URL now.
          // a special case : com_content  does not calculate pagination right
          // for frontpage and blog, they include links shown at the bottom in the calculation of number of items
          // For instance, with joomla sample data, the frontpage has only 5 articles
          // but the view sets $limit to 9 !!!
          if (($option == 'com_content' && isset($layout) && $layout == 'blog')
          || ($option == 'com_content' && isset( $view) && $view == 'frontpage' )) {
            $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true);
            $string = shSetURLVar( $string, 'limit', $listLimit);
            $string = shSortUrl($string);
            //$URI->addQueryString( 'limit', $listLimit);
          }
          $urlVars = is_array($URI->querystring) ? array_map('urldecode', $URI->querystring): $URI->querystring;
          $sefstring = $sef_ext->create($string, $urlVars, $shAppendString, $shLanguage, $shOrigString, $originalUri); // V 1.2.4.s added original string
        }
      } else if (($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404)) {
        // not found but no $limit or $limitstart
        $sefstring = shGetIsoCodeFromName($shLanguage).'/';
        shAddSefUrlToDBAndCache( $string, $sefstring, 0, sh404SEF_URLTYPE_AUTO); // create it
      }
      // V 1.2.4.j : added $shAppendString to pass non sef parameters. For use with parameters that won't be stored in DB
      $ret = $pageInfo->getDefaultLiveSite().(empty( $sefstring) ? '' : $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode].$sefstring);

      $ret = shFinalizeURL($ret);
      if (empty($uri))  // if no URI, append remaining vars directly to the string
      $ret .= $shAppendString;
      else
      shRebuildVars( $shAppendString, $uri);
      $pageInfo->shMosConfig_locale = $shOrigLang;
      _log('Returning shSefRelToAbs 4 with '.$ret);
      return $ret;
    }

    if (isset($option) && !($option=='com_content' && @$task == 'edit') && (strtolower($option) != 'com_sh404sef')) {
      // V x 29/08/2007 23:19:48
      // check also that option = com_content, otherwise, breaks some comp
      switch ($shComponentType) {
        case Sh404sefClassBaseextplugin::TYPE_SKIP : {
          $sefstring = $shSaveString;  // V 1.2.4.q : restore untouched URL, except anchor which will be added later
          // J! 1.6 kill all query vars
          $shGETVars = array();
          $uri->setQuery( array());
          break;
        }

        case Sh404sefClassBaseextplugin::TYPE_SIMPLE:

          // check for custom urls
          $sefstring = '';
          $urlType = shGetSefURLFromCacheOrDB($string, $sefstring);
          // if no custom found, then build default url
          if ($urlType != sh404SEF_URLTYPE_CUSTOM) {
            // if not found then fall back to Joomla! SEF
            if (isset($URI)) {
              unset($URI);
            }
            $sefstring = 'component/';
            $URI = new sh_Net_URL(shSortUrl($shSaveString)); // can't remove yet, anchor is use later down
            $jUri = new JUri(shSortUrl($shSaveString));
            $uriVars = $jUri->getQuery( $asArray = true);
            if (count($uriVars) > 0) {
              foreach($uriVars as $key => $value) {
                if( is_array($value) ) {
                  foreach($value as $k=>$v) {
                    // fix for arrays, thanks doorknob
                    $sefstring .= $key.'[' . $k. '],'. $v . '/';
                  }
                } else {
                  $sefstring .= $key.','.$value . '/';
                }
              }
              $sefstring = str_replace( 'option,', '', $sefstring );
            }
          }
          break;

        default: {
          $sefstring='';
          // base case:
          $urlType = shGetSefURLFromCacheOrDB($string, $sefstring);

          // first special case. User may have customized paginated urls
          // this will be picked up by the line above, except if we're talking about
          // a category or section blog layout, where Joomla does not uses the correct
          // value for limit
          if (($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) && empty( $showall) && (!empty($limit) || (!isset($limit) && !empty($limitstart)))) {
            if (($option == 'com_content' && isset($layout) && $layout == 'blog')
            || ($option == 'com_content' && isset( $view) && $view == 'frontpage' )) {
              $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true);
              $tmpString = shSetURLVar( $string, 'limit', $listLimit);
              $tmpString = shSortUrl($tmpString);
              $urlType = shGetSefURLFromCacheOrDB($tmpString, $sefstring);
              if ($urlType != sh404SEF_URLTYPE_NONE && $urlType != sh404SEF_URLTYPE_404) {
                // we found a match with pagination info!
                $string = $tmpString;
              }
            }
          }

          // now let's try again without any pagination at all
          if (($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) && empty( $showall) && (!empty($limit) || (!isset($limit) && !empty($limitstart)))) {
            $urlType = shGetSefURLFromCacheOrDB(shCleanUpPag($string), $sefstring); // search without pagination info
            if ($urlType != sh404SEF_URLTYPE_NONE && $urlType != sh404SEF_URLTYPE_404) {
              $sefstring = shAddPaginationInfo( @$limit, @$limitstart, @showall, 1, $string, $sefstring, null);
              // a special case : com_content  does not calculate pagination right
              // for frontpage and blog, they include links shown at the bottom in the calculation of number of items
              // For instance, with joomla sample data, the frontpage has only 5 articles
              // but the view sets $limit to 9 !!!
              if (($option == 'com_content' && isset($layout) && $layout == 'blog')
              || ($option == 'com_content' && isset( $view) && $view == 'frontpage' )) {
                $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true);
                $string = shSetURLVar( $string, 'limit', $listLimit);
                $string = shSortUrl($string);
              }

              // that's a new URL, so let's add it to DB and cache
              _log('Created url based on non paginated base url:' . $string);
              shAddSefUrlToDBAndCache( $string, $sefstring, 0, $urlType);
            }
          }

          if ($urlType == sh404SEF_URLTYPE_NONE) {
            // If component has its own sef_ext plug-in included.
            $shDoNotOverride = in_array( $shOption, $sefConfig->shDoNotOverrideOwnSef);
            if (shFileExists(sh404SEF_ABS_PATH.'components/'.$option.'/sef_ext.php')
            && ($shDoNotOverride                   // and param said do not override
            || (!$shDoNotOverride              // or param said override, but we don't have a plugin either in sh404SEF dir or component sef_ext dir
            && (!shFileExists(sh404SEF_ABS_PATH
            .'components/com_sh404sef/sef_ext/'.$option.'.php')
            &&
            !shFileExists(sh404SEF_ABS_PATH
            .'components/'.$option.'/sef_ext/'.$option.'.php') )
            ))) {
              // Load the plug-in file. V 1.2.4.s changed require_once to include
              include_once(sh404SEF_ABS_PATH.'components/'.$option.'/sef_ext.php');
              $_SEF_SPACE = $sefConfig->replacement;
              $comp_name = str_replace('com_', '', $option);
              $className = 'sef_' . $comp_name;
              $sef_ext = new $className;
              // V x : added default string in params
              if (empty($sefConfig->defaultComponentStringList[$comp_name]))
              $title[] = getMenuTitle($option, null, isset($Itemid) ? @$Itemid : null, null, $shLanguage); // V 1.2.4.x
              else $title[] = $sefConfig->defaultComponentStringList[$comp_name];
              // V 1.2.4.r : clean up URL BEFORE sending it to sef_ext files, to have control on what they do
              // remove lang information, we'll put it back ourselves later
              //$shString = preg_replace( '/(&|\?)lang=[a-zA-Z]{2,3}/iU' ,'', $string);
              // V 1.2.4.t use original non-sef string. Some sef_ext files relies on order of params, which may
              // have been changed by sh404SEF
              $shString = preg_replace( '/(&|\?)lang=[a-zA-Z]{2,3}/iU' ,'', $shSaveString);
              $finalstrip = explode("|", $sefConfig->stripthese);
              $shString = str_replace('&', '&', $shString);
              _log('Sending to own sef_ext.php plugin : '.$shString);
              $sefstring = $sef_ext->create($shString);
              _log('Created by sef_ext.php plugin : '.$sefstring);
              $sefstring = str_replace("%10", "%2F", $sefstring);
              $sefstring = str_replace("%11", $sefConfig->replacement, $sefstring);
              $sefstring = rawurldecode($sefstring);
              if ($sefstring == $string) {
                if (!empty($shMosMsg)) // V x 01/09/2007 22:48:01
                $string .= '?'.$shMosMsg;
                $ret = shFinalizeURL($string);
                $pageInfo->shMosConfig_locale = $shOrigLang;
                _log('Returning shSefRelToAbs 5 with '.$ret);
                return $ret;
              } else {
                // V 1.2.4.p : sef_ext extensions for opensef/SefAdvance do not always replace '
                $sefstring = str_replace( '\'', $sefConfig->replacement, $sefstring);
                // some ext. seem to html_special_chars URL ?
                $sefstring = str_replace( ''', $sefConfig->replacement, $sefstring); // V w 27/08/2007 13:23:56
                $sefstring = str_replace(' ', $_SEF_SPACE, $sefstring);
                $sefstring = str_replace(' ', '',
                (shInsertIsoCodeInUrl($option, $shLanguage) ?   // V 1.2.4.q
                shGetIsoCodeFromName($shLanguage).'/' : '')
                .titleToLocation($title[0]).'/'.$sefstring.(($sefstring != '') ? $sefConfig->suffix : ''));
                if (!empty($sefConfig->suffix))
                $sefstring = str_replace('/'.$sefConfig->suffix, $sefConfig->suffix, $sefstring);

                //$finalstrip = explode("|", $sefConfig->stripthese);
                $sefstring = str_replace($finalstrip, $sefConfig->replacement, $sefstring);
                $sefstring = str_replace($sefConfig->replacement.$sefConfig->replacement.$sefConfig->replacement,
                $sefConfig->replacement, $sefstring);
                $sefstring = str_replace($sefConfig->replacement.$sefConfig->replacement,
                $sefConfig->replacement, $sefstring);
                $suffixthere = 0;
                if (!empty($sefConfig->suffix) && strpos($sefstring, $sefConfig->suffix ) !== false)  // V 1.2.4.s
                $suffixthere = strlen($sefConfig->suffix);
                $takethese = str_replace("|", "", $sefConfig->friendlytrim);
                $sefstring = JString::trim(JString::substr($sefstring,0,strlen($sefstring)-$suffixthere), $takethese);
                $sefstring .= $suffixthere == 0 ? '': $sefConfig->suffix;  // version u 26/08/2007 17:27:16
                // V 1.2.4.m store it in DB so as to be able to use sef_ext plugins really !
                $string = str_replace('&', '&', $string);
                // V 1.2.4.r without mod_rewrite
                $shSefString = shAdjustToRewriteMode($sefstring);
                // V 1.2.4.p check for various URL for same content
                $dburl = ''; // V 1.2.4.t prevent notice error
                $urlType = sh404SEF_URLTYPE_NONE;
                if ($sefConfig->shUseURLCache)
                $urlType = Sh404sefHelperCache::getNonSefUrlFromCache($shSefString, $dburl);
                $newMaxRank = 0; // V 1.2.4.s
                $shDuplicate = false;
                if ($sefConfig->shRecordDuplicates || $urlType == sh404SEF_URLTYPE_NONE) {
                  // V 1.2.4.q + V 1.2.4.s+t
                  $sql = "SELECT newurl, rank, dateadd FROM #__sh404sef_urls WHERE oldurl = "
                  .$database->Quote($shSefString)." ORDER BY rank ASC";
                  $database->setQuery($sql);
                  $dbUrlList = $database->loadObjectList();
                  if (count($dbUrlList) > 0) {
                    $dburl = $dbUrlList[0]->newurl;
                    $newMaxRank = $dbUrlList[count($dbUrlList)-1]->rank+1;
                    $urlType = $dbUrlList[0]->dateadd == '0000-00-00' ? sh404SEF_URLTYPE_AUTO : sh404SEF_URLTYPE_CUSTOM;
                  }
                }
                if ($urlType != sh404SEF_URLTYPE_NONE && ($dburl != $string)) $shDuplicate = true;
                $urlType = $urlType == sh404SEF_URLTYPE_NONE ? sh404SEF_URLTYPE_AUTO : $urlType;
                _log('Adding from sef_ext to DB : '.$shSefString.' | rank = '.($shDuplicate?$newMaxRank:0) );
                shAddSefUrlToDBAndCache( $string, $shSefString, ($shDuplicate?$newMaxRank:0), $urlType);
              }
            }
            // Component has no own sef extension.
            else {
              $string = JString::trim($string, "&?");

              // V 1.2.4.q a trial in better handling homepage articles
              // disabled in J! 1.6. Becomes too complex with multi-language
              // TODO: remove guessItemidOnHomepage setting
              if (false && shIsCurrentPageHome() && ($option == 'com_content')    // com_content component on homepage
              && (isset($task)) && ($task == 'view')
              && $sefConfig->guessItemidOnHomepage) {
                $string = preg_replace( '/(&|\?)Itemid=[^&]*/i', '', $string);  // we remove Itemid, as com_content plugin
                $Itemid = null;                                     // will hopefully do a better job at finding the right one
                unset($URI->querystring['Itemid']);
                unset($shGETVars['Itemid']);
              }

              require_once(sh404SEF_FRONT_ABS_PATH.'sef_ext.php');
              $sef_ext = new sef_404();
              // Rewrite the URL now. // V 1.2.4.s added original string
              // a special case : com_content  does not calculate pagination right
              // for frontpage and blog, they include links shown at the bottom in the calculation of number of items
              // For instance, with joomla sample data, the frontpage has only 5 articles
              // but the view sets $limit to 9 !!!
              if (($option == 'com_content' && isset($layout) && $layout == 'blog')
              || ($option == 'com_content' && isset( $view) && $view == 'frontpage' )) {
                $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true);
                $string = shSetURLVar( $string, 'limit', $listLimit);
                $string = shSortUrl($string);
                //$URI->addQueryString( 'limit', $listLimit);
              }
              $sefstring = $sef_ext->create($string, $URI->querystring, $shAppendString, $shLanguage, $shOrigString, $originalUri);
              _log('Created sef url from default plugin: '.$sefstring);
            }
          }
        }
      } // end of cache check shumisha
      if (isset($sef_ext)) unset($sef_ext);

      // if string has not been modified, then we have decided for a non-sef
      if($string == $sefstring) {
        // J! 1.6 kill all query vars
        $shGETVars = array();
        $uri->setQuery( array());
      } else {
        // include rewrite mode bit
        $shRewriteBit = $shComponentType == Sh404sefClassBaseextplugin::TYPE_SKIP ? '/': $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode];
        if (strpos($sefstring,'index.php') === 0 ) $shRewriteBit = '/';  // V 1.2.4.t bug #119
        $string =  $pageInfo->getDefaultLiveSite().$shRewriteBit.JString::ltrim( $sefstring, '/') . (($URI->anchor)?"#".$URI->anchor:'');
      }
    }
    else {  // V x 03/09/2007 13:47:37 editing content
      $shComponentType = Sh404sefClassBaseextplugin::TYPE_SKIP;  // will prevent turning & into &
      _log('shSefrelfToAbs: option not set, skipping');
    }
    $ret = $string;
    // $ret = str_replace('itemid', 'Itemid', $ret); // V 1.2.4.t bug #125
    _log('(1) Setting shSefRelToAbs return string as: ' . $ret);
  }
  if (!isset($ret)) {
    $ret = $string;
    _log('(2) Setting shSefRelToAbs return string as: ' . $ret);
  }
  $ret = ($shComponentType == Sh404sefClassBaseextplugin::TYPE_DEFAULT) ? shFinalizeURL($ret) : $ret;  // V w 27/08/2007 13:21:28
  _log('(3) shSefRelToAbs return string after shFinalize: ' . $ret);
  if (empty($uri) || $shComponentType == Sh404sefClassBaseextplugin::TYPE_SKIP) {
    // we don't have a uri : we must be doing a redirect from non-sef to sef or similar
    $ret .= $shAppendString;  // append directly to url
    _log('(4) shSefRelToAbs return string after appendString: ' . $ret);
  } else {
    if ( empty( $sefstring) || (!empty( $sefstring) && strpos( $sefstring, 'index.php') !== 0 )) {
      shRebuildVars( $shAppendString, $uri);  // instead, add to uri. Joomla will put everything together. Only do this if we have a sef url, and not if we have a non-sef
      _log('(5) shSefRelToAbs no sefstring, adding rebuild vars : ' . $shAppendString);
    }
  }
  $pageInfo->shMosConfig_locale = $shOrigLang;
  _log( 'shSefRelToAbs: finally returning: ' . $ret);
  return $ret;
}
 /**
  * Generate a URI based on current URL.
  *
  * @param JUri $url
  *
  * @return string
  */
 private function getCurrentURI(JUri $url)
 {
     $uri = $url->getPath();
     if ($url->getQuery()) {
         $uri .= "?" . $url->getQuery();
     }
     return $uri;
 }
 /**
  * Method to get a JPagination object for the data set.
  *
  * @return  JPagination  A JPagination object for the data set.
  */
 public function getPagination()
 {
     if ($this->getState('list.limit', 20) == 0) {
         return;
     }
     $pagination = parent::getPagination();
     $pagination->prefix = 'slicomments';
     $url = ContentHelperRoute::getArticleRoute($this->getState('article.slug'), $this->getState('article.catid'));
     $uri = new JUri($url);
     $query = $uri->getQuery(true);
     foreach ($query as $key => $value) {
         $pagination->setAdditionalUrlParam($key, $value);
     }
     return $pagination;
 }
 /**
  * Captures the onJHarvestRetrieve event, retrieving records via the configured
  * OpenSearch results.
  *
  * @param  JObject  $harvest  The harvest information.
  */
 public function onJHarvestRetrieve($harvest)
 {
     if ($harvest->get('params')->get('discovery.type') != 'opensearch') {
         return;
     }
     $templateUrl = $harvest->get('params')->get('discovery.url');
     $http = JHttpFactory::getHttp();
     $parameters = array("{startIndex?}" => 0, "{startPage?}" => 0, "{count?}" => 100, "{language}" => urlencode(JFactory::getLanguage()->getName()), "{inputEncoding}" => "UTF-8", "{outputEncoding}" => "UTF-8");
     $dom = new DomDocument();
     $count = 0;
     // the number of records to retrieve.
     do {
         $url = new JUri($templateUrl);
         $queries = $url->getQuery(true);
         foreach ($queries as $keyq => $valueq) {
             if (array_key_exists($valueq, $parameters)) {
                 $queries[$keyq] = $parameters[$valueq];
             }
         }
         $url->setQuery($queries);
         $response = $http->get($url);
         if ((int) $response->code === 200) {
             $reader = new XMLReader();
             $reader->xml($response->body);
             while ($reader->read()) {
                 if ($reader->nodeType == XmlReader::ELEMENT) {
                     if ($reader->localName == 'entry') {
                         $entry = simplexml_import_dom($dom->importNode($reader->expand(), true));
                         $this->cache($harvest, $entry);
                     }
                     if ($reader->localName == 'item') {
                         $entry = simplexml_import_dom($dom->importNode($reader->expand(), true));
                         $this->cache($harvest, $entry);
                     }
                     if ($reader->localName == 'totalResults') {
                         $totalResults = simplexml_import_dom($dom->importNode($reader->expand(), true));
                         if (!$count) {
                             $count = (int) $totalResults;
                         }
                     }
                 }
             }
         }
         $parameters['{startIndex?}'] += $parameters['{count?}'];
         $parameters['{startPage?}'] += 1;
     } while ($parameters['{startIndex?}'] < $count);
 }