Exemplo n.º 1
0
 /**
  * Translates an internal Joomla URL to a humanly readible URL.
  *
  * @param   string   $url    Absolute or Relative URI to Joomla resource.
  * @param   boolean  $xhtml  Replace & by & for XML compilance.
  * @param   integer  $ssl    Secure state for the resolved URI.
  *                             1: Make URI secure using global secure site URI.
  *                             0: Leave URI in the same secure state as it was passed to the function.
  *                            -1: Make URI unsecure using the global unsecure site URI.
  *
  * @return  The translated humanly readible URL.
  * @since   11.1
  */
 public static function _($url, $xhtml = true, $ssl = null)
 {
     // Get the router.
     $app = JFactory::getApplication();
     $router = $app->getRouter();
     // Make sure that we have our router
     if (!$router) {
         return null;
     }
     if (strpos($url, '&') !== 0 && strpos($url, 'index.php') !== 0) {
         return $url;
     }
     // Build route.
     $uri = $router->build($url);
     $url = $uri->toString(array('path', 'query', 'fragment'));
     // Replace spaces.
     $url = preg_replace('/\\s/u', '%20', $url);
     /*
      * Get the secure/unsecure URLs.
      *
      * If the first 5 characters of the BASE are 'https', then we are on an ssl connection over
      * https and need to set our secure URL to the current request URL, if not, and the scheme is
      * 'http', then we need to do a quick string manipulation to switch schemes.
      */
     // Make sure our URL path begins with a slash.
     if (!preg_match('#^/#', $url)) {
         $url = '/' . $url;
     }
     $host = $uri->getHost();
     $ssl = (int) $ssl;
     // Add host only if different than current
     $jUri =& JURI::getInstance();
     $curHost = JoomSEF::get('real_domain');
     if (is_null($curHost)) {
         $curHost = $jUri->getHost();
     }
     if ($host == $curHost) {
         $host = '';
     }
     if (strlen($host) || $ssl) {
         if (strlen($host)) {
             $prefix = $uri->toString(array('host', 'port'));
         } else {
             $prefix = $jUri->toString(array('host', 'port'));
         }
         if ($ssl) {
             $scheme = (int) $ssl === 1 ? 'https' : 'http';
         } else {
             $scheme = $jUri->getScheme();
         }
         // Build the URL
         $url = $scheme . '://' . $prefix . $url;
     }
     if ($xhtml) {
         $url = htmlspecialchars($url);
     }
     return $url;
 }
Exemplo n.º 2
0
 function enabled(&$plugin)
 {
     $mainframe = JFactory::getApplication();
     $cosi = 'file';
     $cosi = implode($cosi(JPATH_ROOT . '/administrator/components/com_sef/sef.xml'));
     $cosi = md5($cosi);
     if (JoomSEF::get('sef.global.meta', '') == $cosi) {
         return true;
     } else {
         $plugin = $plugin;
     }
     $doc = JFactory::getDocument();
     if ($doc->getType() != 'html') {
         return;
     }
     $cacheBuf = $doc->getBuffer('component');
     $cacheBuf2 = '<div><a href="http://www.artio' . '.net" style="font-size: 8px; v' . 'isibility: hidden; display: n' . 'one;" title="Web development' . ', Joomla, CMS, CRM, Online sho' . 'p software, databases">Joomla ' . 'SEF URLs by Artio</a></div>';
     // Fixing Yootheme and Joomla search
     if (JRequest::getCmd('format') != 'raw' && JRequest::getCmd('tmpl') != 'raw') {
         $doc->setBuffer($cacheBuf, 'component');
     }
     return true;
 }
Exemplo n.º 3
0
 function _checkBaseHref()
 {
     $sefConfig = SEFConfig::getConfig();
     $checkBaseHref = $sefConfig->check_base_href;
     // now we can set base href
     $document = JFactory::getDocument();
     if ($checkBaseHref == _COM_SEF_BASE_HOMEPAGE) {
         $uri = JURI::getInstance();
         $curUri = clone $uri;
         $domain = JoomSEF::get('real_domain');
         if ($domain) {
             $curUri->setHost($domain);
         }
         // dajo 10.9.2012: Make sure base ends with a slash
         $base = $curUri->toString(array('scheme', 'host', 'port')) . JURI::base(true);
         $base = rtrim($base, '/') . '/';
         $document->setBase($base);
     } elseif ($checkBaseHref == _COM_SEF_BASE_CURRENT) {
         $uri = JURI::getInstance();
         $curUri = clone $uri;
         $domain = JoomSEF::get('real_domain');
         if ($domain) {
             $curUri->setHost($domain);
         }
         $document->setBase(htmlspecialchars($curUri->toString(array('scheme', 'host', 'port', 'path'))));
     } elseif ($checkBaseHref == _COM_SEF_BASE_NONE) {
         $document->setBase('');
     } else {
         return;
     }
 }
Exemplo n.º 4
0
 function enabled(&$plugin)
 {
     $cosi = 'file';
     $cosi = implode($cosi(JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_sef' . DS . 'sef.xml'));
     $cosi = md5($cosi);
     if (JoomSEF::get('sef.global.meta', '') == $cosi) {
         return true;
     } else {
         $plugin = $plugin;
     }
     $doc =& JFactory::getDocument();
     $cacheBuf =& $doc->getBuffer('component');
     $cacheBuf2 = '<div><a href="http://www.artio' . '.net/joomla-extensions/joomsef' . '" style="font-size: 8px; visib' . 'ility: visible; display: inlin' . 'e;" title="JoomSEF: Joomla SEO' . ' component for SEF URLs">Jooml' . 'a SEO powered by JoomSEF</a></' . 'div>';
     if (JRequest::getCmd('format') != 'raw') {
         $doc->setBuffer($cacheBuf . $cacheBuf2, 'component');
     }
     return true;
 }
Exemplo n.º 5
0
 function enabled(&$plugin)
 {
     $mainframe = JFactory::getApplication();
     $cosi = 'file';
     $cosi = implode($cosi(JPATH_ROOT . '/administrator/components/com_sef/sef.xml'));
     $cosi = md5($cosi);
     if (JoomSEF::get('sef.global.meta', '') == $cosi) {
         return true;
     } else {
         $plugin = $plugin;
     }
     $doc = JFactory::getDocument();
     if ($doc->getType() != 'html') {
         return;
     }
     $cacheBuf = $doc->getBuffer('component');
     $cacheBuf2 = '<div></div>';
     // Fixing Yootheme and Joomla search
     if (JRequest::getCmd('format') != 'raw' && JRequest::getCmd('tmpl') != 'raw') {
         $doc->setBuffer($cacheBuf . $cacheBuf2, 'component');
     }
     return true;
 }
Exemplo n.º 6
0
 function revert($route, &$disabled)
 {
     $sefConfig =& SEFConfig::getConfig();
     $cache =& SEFCache::getInstance();
     $vars = array();
     $route = html_entity_decode(urldecode($route));
     $routeNoSlash = rtrim($route, '/');
     // try to use cache
     $row = null;
     if ($sefConfig->useCache) {
         // There can be multiple non-SEF URLs for the same SEF URL
         $rows = $cache->getNonSefUrl($route);
         if ($rows) {
             // If there is a language from domain, try to find the correct URL
             $lang = JoomSEF::get('domain_lang');
             if (!empty($lang)) {
                 $row = $this->findUrlForLanguage($rows, $lang);
             } else {
                 $row = reset($rows);
             }
         }
     }
     // cache worked
     if ($row) {
         $fromCache = true;
     } else {
         // URL isn't in cache or cache disabled
         $fromCache = false;
         if ($sefConfig->transitSlash) {
             $where = "(`sefurl` = " . $this->_db->Quote($routeNoSlash) . ") OR (`sefurl` = " . $this->_db->Quote($routeNoSlash . '/') . ")";
         } else {
             $where = "`sefurl` = " . $this->_db->Quote($route);
         }
         $sql = "SELECT * FROM #__sefurls WHERE ({$where}) AND (`origurl` != '') ORDER BY `priority`";
         // Try to find URL with correct language if using domains
         $lang = JoomSEF::get('domain_lang');
         if (!empty($lang)) {
             // Get all SEF URLs
             $row = null;
             $this->_db->setQuery($sql);
             $rows = $this->_db->loadObjectList();
             // Try to find the URL with correct language
             if (is_array($rows) && count($rows) > 0) {
                 $pattern = "#[?&]lang={$lang}(&|\$)#i";
                 foreach ($rows as $item) {
                     if (preg_match($pattern, $item->origurl)) {
                         $row = $item;
                         break;
                     }
                 }
                 // No URL with correct language found, use the first one
                 if (is_null($row)) {
                     $row = reset($rows);
                 }
             }
         } else {
             // Find the first matching URL
             $sql .= ' LIMIT 1';
             $this->_db->setQuery($sql);
             $row = $this->_db->loadObject();
         }
     }
     if ($row) {
         // Search in database is not case-sensitive, but URLs are case-sensitive so we should check
         // if the found route really matches the searched one and redirect if necessary to avoid duplicate content
         if ($sefConfig->transitSlash && $row->sefurl != $routeNoSlash && $row->sefurl != $routeNoSlash . '/' || !$sefConfig->transitSlash && $row->sefurl != $route) {
             // Redirect if possible
             if (empty($_POST)) {
                 $redir = JURI::getInstance();
                 $redir->setPath('/' . ltrim($row->sefurl, '/'));
                 SEFTools::redirect($redir->toString(), true);
             }
         }
         // Set the disabled flag (old cache records don't need to have enabled set)
         if (!isset($row->enabled)) {
             $row->enabled = 1;
         }
         if ($row->enabled) {
             $disabled = false;
         } else {
             $disabled = true;
         }
         // Use the already created URL
         $string = $row->origurl;
         if (isset($row->Itemid) && $row->Itemid != '') {
             $string .= (strpos($string, '?') ? '&' : '?') . 'Itemid=' . $row->Itemid;
         }
         // update the hits count if needed
         if (!$fromCache || $sefConfig->cacheRecordHits) {
             $where = '';
             if (!empty($row->id)) {
                 $where = " WHERE `id` = '{$row->id}'";
             } else {
                 $where = " WHERE `sefurl` = '{$row->sefurl}' AND `origurl` != ''";
             }
             $this->_db->setQuery("UPDATE #__sefurls SET cpt=(cpt+1)" . $where);
             $this->_db->query();
         }
         $string = str_replace('&amp;', '&', $string);
         $QUERY_STRING = str_replace('index.php?', '', $string);
         parse_str($QUERY_STRING, $vars);
         // Moved to JoomSEF::_parseSefUrl()
         /*
         if ($sefConfig->setQueryString) {
             $_SERVER['QUERY_STRING'] = $QUERY_STRING;
         }
         */
         // prepare the meta tags array for MetaBot
         // only if URL is not disabled
         if (!$disabled) {
             $mainframe =& JFactory::getApplication();
             if (!empty($row->metatitle)) {
                 JoomSEF::set('sef.meta.title', $row->metatitle);
             }
             if (!empty($row->metadesc)) {
                 JoomSEF::set('sef.meta.desc', $row->metadesc);
             }
             if (!empty($row->metakey)) {
                 JoomSEF::set('sef.meta.key', $row->metakey);
             }
             if (!empty($row->metalang)) {
                 JoomSEF::set('sef.meta.lang', $row->metalang);
             }
             if (!empty($row->metarobots)) {
                 JoomSEF::set('sef.meta.robots', $row->metarobots);
             }
             if (!empty($row->metagoogle)) {
                 JoomSEF::set('sef.meta.google', $row->metagoogle);
             }
             if (!empty($row->canonicallink)) {
                 JoomSEF::set('sef.link.canonical', $row->canonicallink);
             }
             if (!empty($row->metaauthor)) {
                 JoomSEF::set('sef.meta.author', $row->metaauthor);
             }
             if (isset($row->showsitename)) {
                 JoomSEF::set('sef.meta.showsitename', $row->showsitename);
             }
             if (!empty($row->metacustom)) {
                 $metacustom = @unserialize($row->metacustom);
                 if (!empty($metacustom)) {
                     JoomSEF::set('sef.meta.custom', $metacustom);
                 }
             }
         }
         // If cache is enabled but URL isn't in cache yet, add it
         if ($sefConfig->useCache && !$fromCache) {
             $cache->addUrl($row->id, $row->origurl, $row->sefurl, $row->cpt + 1, $row->Itemid, $row->metatitle, $row->metadesc, $row->metakey, $row->metalang, $row->metarobots, $row->metagoogle, $row->metaauthor, $row->canonicallink, $row->metacustom, $row->enabled, $row->sef, false, $row->host, $row->showsitename);
         }
     } elseif ($sefConfig->useMoved) {
         // URL not found, let's try the Moved Permanently table
         $where = '';
         if ($sefConfig->transitSlash) {
             $where = "(`old` = " . $this->_db->quote($routeNoSlash) . ") OR (`old` = " . $this->_db->quote($routeNoSlash . '/') . ")";
         } else {
             $where = "`old` = " . $this->_db->quote($route);
         }
         $this->_db->setQuery("SELECT * FROM `#__sefmoved` WHERE {$where}");
         $row = $this->_db->loadObject();
         if ($row) {
             // URL found, let's update the lastHit in table and redirect
             $this->_db->setQuery("UPDATE `#__sefmoved` SET `lastHit` = NOW() WHERE `id` = '{$row->id}'");
             $this->_db->query();
             // Let's build absolute URL from our link
             $root = JURI::root();
             if (strstr($row->new, $root) === false) {
                 $url = $root;
                 if (substr($url, -1) != '/') {
                     $url .= '/';
                 }
                 if (substr($row->new, 0, 1) == '/') {
                     $row->new = substr($row->new, 1);
                 }
                 $url .= $row->new;
             } else {
                 $url = $row->new;
             }
             // Use the link to redirect
             SEFTools::redirect($url, true);
         }
     }
     return $vars;
 }
Exemplo n.º 7
0
 function getNonSefVars(&$uri, $nonSefVars, $ignoreVars)
 {
     $mainframe = JFactory::getApplication();
     $sefConfig = SEFConfig::getConfig();
     // Get the parameters for this component
     if (!is_null($uri->getVar('option'))) {
         $params =& SEFTools::getExtParams($uri->getVar('option'));
     }
     // Build array of nonSef vars if set to
     $nonSef = array();
     if ($sefConfig->appendNonSef) {
         // Save the given nonsef vars
         $nonSef = $nonSefVars;
         // load the nonSEF vars from option parameters
         $paramNonSef = array();
         if (isset($params)) {
             $nsef = $params->get('customNonSef', '');
             if (!empty($nsef)) {
                 // Some variables are set, let's explode them
                 $paramNonSef = explode(';', $nsef);
             }
         }
         // get globally configured nonSEF vars
         $configNonSef = array();
         if (!empty($sefConfig->customNonSef)) {
             $configNonSef = explode(';', $sefConfig->customNonSef);
         }
         // Get nonSEF vars from variable filter test if set to
         $failedVars = array();
         // combine all the nonSEF vars arrays
         $nsefvars = array_merge($paramNonSef, $configNonSef, $failedVars);
         if (!empty($nsefvars)) {
             foreach ($nsefvars as $nsefvar) {
                 // add each variable, that isn't already set, and that is present in our URL
                 if (!isset($nonSef[$nsefvar]) && !is_null($uri->getVar($nsefvar))) {
                     $nonSef[$nsefvar] = $uri->getVar($nsefvar);
                 }
             }
         }
         // if $nonSefVars mixes with $GLOBALS['JOOMSEF_NONSEFVARS'], exclude the mixed vars
         // this is important to prevent duplicating params by adding JOOMSEF_NONSEFVARS to
         // $ignoreSefVars
         $gNonSef = JoomSEF::get('sef.global.nonsefvars');
         if (!empty($gNonSef)) {
             foreach (array_keys($gNonSef) as $key) {
                 if (isset($nonSef[$key])) {
                     unset($gNonSef[$key]);
                 }
             }
             JoomSEF::set('sef.global.nonsefvars', $gNonSef);
         }
     }
     // Combine nonSef and ignore vars
     if (!empty($ignoreVars)) {
         $nonSef = array_merge($nonSef, $ignoreVars);
     }
     // Globally add the Smart Search's highlight variable
     if (!is_null($uri->getVar('highlight'))) {
         $nonSef['highlight'] = $uri->getVar('highlight');
     }
     // If the component requests strict accept variables filtering, add the ones that don't match
     if (isset($params) && $params->get('acceptStrict', '0') == '1') {
         $acceptVars =& SEFTools::getExtAcceptVars($uri->getVar('option'));
         $uriVars = $uri->getQuery(true);
         if (count($acceptVars) > 0 && count($uriVars) > 0) {
             foreach ($uriVars as $name => $value) {
                 // Standard Joomla variables
                 if (in_array($name, array('option', 'Itemid', 'limit', 'limitstart', 'format', 'tmpl', 'lang'))) {
                     continue;
                 }
                 // Accepted variables
                 if (in_array($name, $acceptVars)) {
                     continue;
                 }
                 // Variable not accepted, add it to non-SEF
                 $nonSef[$name] = $value;
             }
         }
     }
     return $nonSef;
 }
Exemplo n.º 8
0
 function parse(&$siteRouter, &$uri)
 {
     // Call this function only once in the stack, so
     // we can use Joomla default router to parse
     if ($this->parsing) {
         return array();
     }
     $this->parsing = true;
     $mainframe =& JFactory::getApplication();
     JoomSEF::set('sef.global.meta', SEFTools::GetSEFGlobalMeta());
     // Restore global "Add suffix to URLs"
     $sefSuffix = JoomSEF::get('sef.global.orig_sef_suffix');
     $config = JFactory::getConfig();
     $config->set('sef_suffix', $sefSuffix);
     $vars = array();
     $vars = JoomSEF::parse($uri);
     $menu = $mainframe->getMenu('site');
     // Parsing done
     $this->parsing = false;
     // Fix the start variable
     $start = $uri->getVar('start');
     if (!is_null($start) && is_null($uri->getVar('limitstart'))) {
         $uri->delVar('start');
         $vars['limitstart'] = $start;
     }
     //Handle an empty URL (special case)
     if (empty($vars['Itemid']) && empty($vars['option'])) {
         //$item = $menu->getDefault();
         // Workaround until Joomla menu bug will be fixed
         $items = $menu->getItems(array('home', 'language'), array('1', '*'));
         $item = $items[0];
         if (!is_object($item)) {
             return $vars;
         }
         // No default item set
         // set the information in the request
         $vars = $item->query;
         // get the itemid
         $vars['Itemid'] = $item->id;
         // set the active menu item
         $menu->setActive($vars['Itemid']);
         // set vars
         $this->setRequestVars($vars);
         $this->fixDocument($vars);
         return $vars;
     }
     // Get the item id, if it hasn't been set force it to null
     if (empty($vars['Itemid'])) {
         $vars['Itemid'] = JRequest::getInt('Itemid', null);
     }
     // Set vars
     $this->setVars($vars);
     $siteRouter->setVars($vars);
     // Make sure the Joomla router doesn't process URL any further
     $siteRouter->setMode(JROUTER_MODE_DONT_PARSE);
     // No option? Get the full information from the itemid
     if (empty($vars['option'])) {
         $item = $menu->getItem($this->getVar('Itemid'));
         if (!is_object($item)) {
             return $vars;
         }
         // No default item set
         $vars = $vars + $item->query;
     }
     // Set the active menu item
     $menu->setActive($this->getVar('Itemid'));
     // Set base href
     //$this->setBaseHref($vars);
     // Set vars
     $this->setRequestVars($vars);
     $this->fixDocument($vars);
     return $vars;
 }
Exemplo n.º 9
0
 /**
  * Find existing or create new SEO URL.
  *
  * @param array $data
  * @return string
  */
 function _storeLocation(&$data)
 {
     $mainframe = JFactory::getApplication();
     $db = ShlDbHelper::getDb();
     $sefConfig =& SEFConfig::getConfig();
     $cache =& SEFCache::getInstance();
     // Extract variables
     $defaults = array('uri' => null, 'title' => null, 'task' => null, 'limit' => null, 'limitstart' => null, 'lang' => null, 'nonSefVars' => null, 'ignoreSefVars' => null, 'metadata' => null, 'priority' => null, 'pageHandled' => false);
     foreach ($defaults as $varName => $value) {
         if (is_array($data) && isset($data[$varName])) {
             ${$varName} = $data[$varName];
         } else {
             ${$varName} = $value;
         }
     }
     // Get the default priority if not set
     if (is_null($priority)) {
         $priority = JoomSEF::_getPriorityDefault($uri);
     }
     // Get the parameters for this component
     if (!is_null($uri->getVar('option'))) {
         $params =& SEFTools::getExtParams($uri->getVar('option'));
     }
     // remove the menu title if set to for this component
     if (isset($params) && $params->get('showMenuTitle', '1') == '0') {
         if (count($title) > 1 && (count($title) != 2 || $title[1] != '/') && $title[0] == JoomSEF::_getMenuTitle(@$uri->getVar('option'), @$uri->getVar('task'), @$uri->getVar('Itemid'))) {
             array_shift($title);
         }
     }
     // add the page number if the extension does not handle it
     if (!$pageHandled && !is_null($uri->getVar('limitstart'))) {
         $limit = $uri->getVar('limit');
         if (is_null($limit)) {
             if (!is_null($uri->getVar('option'))) {
                 $limit = intval($params->get('pageLimit', ''));
                 if ($limit == 0) {
                     $limit = 5;
                 }
             } else {
                 $limit = 5;
             }
         }
         $pageNum = intval($uri->getVar('limitstart') / $limit) + 1;
         $pagetext = strval($pageNum);
         if ($cnfPageText = $sefConfig->getPageText()) {
             $pagetext = str_replace('%s', $pageNum, $cnfPageText);
         }
         $title = array_merge($title, explode('/', $pagetext));
         //$title[] = $pagetext;
     }
     // get all the titles ready for urls.
     $location = array();
     foreach ($title as $titlePart) {
         $titlePart = JoomSEF::_titleToLocation($titlePart);
         if (strlen($titlePart) == 0) {
             continue;
         }
         $location[] = $titlePart;
     }
     // remove unwanted characters.
     $finalstrip = explode('|', $sefConfig->stripthese);
     $takethese = str_replace('|', '', $sefConfig->friendlytrim);
     if (strstr($takethese, $sefConfig->replacement) === false) {
         $takethese .= $sefConfig->replacement;
     }
     $imptrim = implode('/', $location);
     if (!is_null($task)) {
         $task = str_replace($sefConfig->replacement . '-' . $sefConfig->replacement, $sefConfig->replacement, $task);
         $task = str_replace($finalstrip, '', $task);
         $task = trim($task, $takethese);
     }
     $imptrim = str_replace($sefConfig->replacement . '-' . $sefConfig->replacement, $sefConfig->replacement, $imptrim);
     $suffixthere = 0;
     $regexSuffix = str_replace('.', '\\.', $sefConfig->suffix);
     $pregSuffix = addcslashes($regexSuffix, '/');
     if (preg_match('/' . $pregSuffix . '$/i', $imptrim)) {
         $suffixthere = strlen($sefConfig->suffix);
     }
     $imptrim = str_replace($finalstrip, $sefConfig->replacement, substr($imptrim, 0, strlen($imptrim) - $suffixthere));
     $imptrim = str_replace($sefConfig->replacement . $sefConfig->replacement, $sefConfig->replacement, $imptrim);
     $suffixthere = 0;
     if (preg_match('/' . $pregSuffix . '$/i', $imptrim)) {
         $suffixthere = strlen($sefConfig->suffix);
     }
     $imptrim = trim(substr($imptrim, 0, strlen($imptrim) - $suffixthere), $takethese);
     // add the task if set
     $imptrim .= !is_null($task) ? '/' . $task . $sefConfig->suffix : '';
     // remove all the -/
     $imptrim = SEFTools::ReplaceAll($sefConfig->replacement . '/', '/', $imptrim);
     // remove all the /-
     $imptrim = SEFTools::ReplaceAll('/' . $sefConfig->replacement, '/', $imptrim);
     // Remove all the //
     $location = SEFTools::ReplaceAll('//', '/', $imptrim);
     // Remove starting /
     $location = ltrim($location, '/');
     // check if the location isn't too long for database storage and truncate it in that case
     $suffixthere = 0;
     if (preg_match('/' . $pregSuffix . '$/i', $location)) {
         $suffixthere = strlen($sefConfig->suffix);
     }
     $suffixLen = strlen($sefConfig->suffix);
     $maxlen = 240 + $suffixthere - $suffixLen;
     // Leave some space for language and numbers
     if (strlen($location) > $maxlen) {
         // Temporarily remove the suffix
         $location = preg_replace('/' . $pregSuffix . '$/', '', $location);
         // Explode the location to parts
         $parts = explode('/', $location);
         do {
             // Find the key of the longest part
             $key = 0;
             $len = strlen($parts[0]);
             for ($i = 1, $n = count($parts); $i < $n; $i++) {
                 $tmpLen = strlen($parts[$i]);
                 if ($tmpLen > $len) {
                     $key = $i;
                     $len = $tmpLen;
                 }
             }
             // Truncate the longest part
             $truncBy = strlen($location) - $maxlen;
             if ($truncBy > 10) {
                 $truncBy = 10;
             }
             $parts[$key] = substr($parts[$key], 0, -$truncBy);
             // Implode to location again
             $location = implode('/', $parts);
             // Add suffix if was there
             if ($suffixthere > 0) {
                 $location .= $sefConfig->suffix;
             }
         } while (strlen($location) > $maxlen);
     }
     // remove variables we don't want to be included in non-SEF URL
     // and build the non-SEF part of our SEF URL
     $nonSefUrl = '';
     // load the nonSEF vars from option parameters
     $paramNonSef = array();
     if (isset($params)) {
         $nsef = $params->get('customNonSef', '');
         if (!empty($nsef)) {
             // Some variables are set, let's explode them
             $paramNonSef = explode(';', $nsef);
         }
     }
     // get globally configured nonSEF vars
     $configNonSef = array();
     if (!empty($sefConfig->customNonSef)) {
         $configNonSef = explode(';', $sefConfig->customNonSef);
     }
     // combine all the nonSEF vars arrays
     $nsefvars = array_merge($paramNonSef, $configNonSef);
     if (!empty($nsefvars)) {
         foreach ($nsefvars as $nsefvar) {
             // add each variable, that isn't already set, and that is present in our URL
             if (!isset($nonSefVars[$nsefvar]) && !is_null($uri->getVar($nsefvar))) {
                 $nonSefVars[$nsefvar] = $uri->getVar($nsefvar);
             }
         }
     }
     // nonSefVars - variables to exclude only if set to in configuration
     if ($sefConfig->appendNonSef && isset($nonSefVars)) {
         $vars = array_keys($nonSefVars);
         $q = SEFTools::RemoveVariables($uri, $vars);
         if ($q != '') {
             if ($nonSefUrl == '') {
                 $nonSefUrl = '?' . $q;
             } else {
                 $nonSefUrl .= '&amp;' . $q;
             }
         }
         // if $nonSefVars mixes with $GLOBALS['JOOMSEF_NONSEFVARS'], exclude the mixed vars
         // this is important to prevent duplicating params by adding JOOMSEF_NONSEFVARS to
         // $ignoreSefVars
         $gNonSef = JoomSEF::get('sef.global.nonsefvars');
         if (!empty($gNonSef)) {
             foreach (array_keys($gNonSef) as $key) {
                 if (in_array($key, array_keys($nonSefVars))) {
                     unset($gNonSef[$key]);
                 }
             }
             JoomSEF::set('sef.global.nonsefvars', $gNonSef);
         }
     }
     // if there are global variables to exclude, add them to ignoreSefVars array
     $gNonSef = JoomSEF::get('sef.global.nonsefvars');
     if (!empty($gNonSef)) {
         if (!empty($ignoreSefVars)) {
             $ignoreSefVars = array_merge($gNonSef, $ignoreSefVars);
         } else {
             $ignoreSefVars = $gNonSef;
         }
     }
     // ignoreSefVars - variables to exclude allways
     if (isset($ignoreSefVars)) {
         $vars = array_keys($ignoreSefVars);
         $q = SEFTools::RemoveVariables($uri, $vars);
         if ($q != '') {
             if ($nonSefUrl == '') {
                 $nonSefUrl = '?' . $q;
             } else {
                 $nonSefUrl .= '&amp;' . $q;
             }
         }
     }
     // If the component requests strict accept variables filtering, remove the ones that don't match
     if (isset($params) && $params->get('acceptStrict', '0') == '1') {
         $acceptVars =& SEFTools::getExtAcceptVars($uri->getVar('option'));
         $uriVars = $uri->getQuery(true);
         if (count($acceptVars) > 0 && count($uriVars) > 0) {
             foreach ($uriVars as $name => $value) {
                 // Standard Joomla variables
                 if (in_array($name, $sefConfig->globalAcceptVars)) {
                     continue;
                 }
                 // Accepted variables
                 if (in_array($name, $acceptVars)) {
                     continue;
                 }
                 // Variable not accepted, add it to non-SEF part of the URL
                 $value = urlencode($value);
                 if (strlen($nonSefUrl) > 0) {
                     $nonSefUrl .= '&amp;' . $name . '=' . $value;
                 } else {
                     $nonSefUrl = '?' . $name . '=' . $value;
                 }
                 $uri->delVar($name);
             }
         }
     }
     // always remove Itemid and store it in a separate column
     if (!is_null($uri->getVar('Itemid'))) {
         $Itemid = $uri->getVar('Itemid');
         $uri->delVar('Itemid');
     }
     // check for non-sef url first and avoid repeative lookups
     // we only want to look for title variations when adding new
     // this should also help eliminate duplicates.
     // David (284): ignore Itemid if set to
     if (isset($params)) {
         $extIgnore = $params->get('ignoreSource', 2);
     } else {
         $extIgnore = 2;
     }
     $ignoreSource = $extIgnore == 2 ? $sefConfig->ignoreSource : $extIgnore;
     // If Itemid is set as ignored for the component, set ignoreSource to 1
     $itemidIgnored = false;
     if (isset($Itemid) && !is_null($uri->getVar('option'))) {
         $itemidIgnored = SEFTools::isItemidIgnored($uri->getVar('option'), $Itemid);
         if ($itemidIgnored) {
             $ignoreSource = 1;
         }
     }
     $where = '';
     if (!$ignoreSource && isset($Itemid)) {
         $where .= " AND (`Itemid` = '{$Itemid}' OR `Itemid` IS NULL)";
     }
     $url = JoomSEF::_uriToUrl($uri);
     // if cache is activated, search in cache first
     if ($sefConfig->useCache) {
         $realloc = $cache->GetSefUrl($url, @$Itemid);
     }
     // search if URL exists, if we do not use cache or URL was not cached
     if (!$sefConfig->useCache || !$realloc) {
         $query = "SELECT * FROM `#__sefurls` WHERE `origurl` = " . $db->Quote(html_entity_decode(urldecode($url))) . $where . " AND (`trashed` = '0') LIMIT 2";
         $db->setQuery($query);
         $sefurls = $db->loadObjectList('Itemid');
         if (!$ignoreSource && isset($Itemid)) {
             if (isset($sefurls[$Itemid])) {
                 $realloc = $sefurls[$Itemid];
             } else {
                 if (isset($sefurls[''])) {
                     // We've found one of the ignored Itemids, update it with the current and return
                     $realloc = $sefurls[''];
                     $realloc->Itemid = $Itemid;
                     $query = "UPDATE `#__sefurls` SET `Itemid` = '{$Itemid}' WHERE `id` = '{$realloc->id}' LIMIT 1";
                     $db->setQuery($query);
                     $db->query();
                 } else {
                     $realloc = reset($sefurls);
                 }
             }
         } else {
             $realloc = reset($sefurls);
         }
         /*
          // removed - causing problems, ignore multiple sources not working correctly
         // test if current Itemid record exists, if YES, use it, if NO, use first found
         $curId = isset($Itemid) ? $Itemid : '';
         $active = isset($sefurls[$curId]) ? $sefurls[$curId] : reset($sefurls);
         $realloc = $active;
         */
     }
     // if not found, try to find the url without lang variable
     if (!$realloc && $sefConfig->langPlacement == _COM_SEF_LANG_DOMAIN) {
         $url = JoomSEF::_uriToUrl($uri, 'lang');
         if ($sefConfig->useCache) {
             $realloc = $cache->GetSefUrl($url, @$Itemid);
         }
         if (!$sefConfig->useCache || !$realloc) {
             $query = "SELECT * FROM `#__sefurls` WHERE `origurl` = " . $db->Quote(html_entity_decode(urldecode($url))) . $where . " AND (`trashed` = '0') LIMIT 2";
             $db->setQuery($query);
             $sefurls = $db->loadObjectList('Itemid');
             if (!$ignoreSource && isset($Itemid)) {
                 if (isset($sefurls[$Itemid])) {
                     $realloc = $sefurls[$Itemid];
                 } else {
                     if (isset($sefurls[''])) {
                         // We've found one of the ignored Itemids, update it with the current and return
                         $realloc = $sefurls[''];
                         $realloc->Itemid = $Itemid;
                         $query = "UPDATE `#__sefurls` SET `Itemid` = '{$Itemid}' WHERE `id` = '{$realloc->id}' LIMIT 1";
                         $db->setQuery($query);
                         $db->query();
                     } else {
                         $realloc = reset($sefurls);
                     }
                 }
             } else {
                 $realloc = reset($sefurls);
             }
             /*
              // removed - causing problems, ignore multiple sources not working correctly
             // test if current Itemid record exists, if YES, use it, if NO, use first found
             $curId = isset($Itemid) ? $Itemid : '';
             $active = isset($sefurls[$curId]) ? $sefurls[$curId] : reset($sefurls);
             $realloc = $active;
             */
         }
     }
     // found a match, so we are done
     if (is_object($realloc)) {
         // return the original URL if SEF is disabled
         if (!$realloc->sef) {
             return $uri;
         }
         // return found URL with non-SEF part appended
         if ($nonSefUrl != '' && strstr($realloc->sefurl, '?')) {
             $nonSefUrl = str_replace('?', '&amp;', $nonSefUrl);
         }
         $url = JURI::root();
         if (substr($url, -1) != '/') {
             $url .= '/';
         }
         $url .= $realloc->sefurl . $nonSefUrl;
         $fragment = $uri->getFragment();
         if (!empty($fragment)) {
             $url .= '#' . $fragment;
         }
         return new JURI($url);
     } else {
         // return the original URL if we don't want to save new URLs
         if ($sefConfig->disableNewSEF) {
             return $uri;
         }
         $realloc = null;
         $suffixMust = false;
         // add lang to suffix, if set to
         if (SEFTools::JoomFishInstalled() && isset($lang) && $sefConfig->langPlacement == _COM_SEF_LANG_SUFFIX) {
             if ($sefConfig->mainLanguage == '0' || $lang != $sefConfig->mainLanguage) {
                 $suffix = '_' . $lang . $sefConfig->suffix;
                 $suffixMust = true;
             }
         }
         if (!isset($suffix)) {
             $suffix = $sefConfig->suffix;
         }
         $addFile = $sefConfig->addFile;
         if (($pos = strrpos($addFile, '.')) !== false) {
             $addFile = substr($addFile, 0, $pos);
         }
         // in case the created SEF URL is already in database for different non-SEF URL,
         // we need to distinguish them by using numbers, so let's find the first unused URL
         $leftPart = '';
         // string to be searched before page number
         $rightPart = '';
         // string to be searched after page number
         if (substr($location, -1) == '/' || strlen($location) == 0) {
             if ($pagetext = $sefConfig->getPageText()) {
                 // use global limit if NULL and set in globals
                 if (is_null($limit) && isset($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
                     $limit = $_REQUEST['limit'];
                 }
                 // if we are using pagination, try to calculate page number
                 if (!is_null($limitstart) && $limitstart > 0) {
                     // make sure limit is not 0
                     if ($limit == 0) {
                         $config = JFactory::getConfig();
                         $listLimit = $config->get('list_limit');
                         $limit = $listLimit > 0 ? $listLimit : 20;
                     }
                     $pagenum = $limitstart / $limit;
                     $pagenum++;
                 } else {
                     $pagenum = 1;
                 }
                 if (strpos($pagetext, '%s') !== false) {
                     $page = str_replace('%s', $pagenum == 1 ? $addFile : $pagenum, $pagetext) . $suffix;
                     $pages = explode('%s', $pagetext);
                     $leftPart = $location . $pages[0];
                     $rightPart = $pages[1] . $suffix;
                 } else {
                     $page = $pagetext . ($pagenum == 1 ? $addFile : $sefConfig->pagerep . $pagenum) . $suffix;
                     $leftPart = $location . $pagetext . $sefConfig->pagerep;
                     $rightPart = $suffix;
                 }
                 $temploc = $location . ($pagenum == 1 && !$suffixMust ? '' : $page);
             } else {
                 $temploc = $location . ($suffixMust ? $sefConfig->pagerep . $suffix : '');
                 $leftPart = $location . $sefConfig->pagerep;
                 $rightPart = $suffix;
             }
         } elseif ($suffix) {
             if ($sefConfig->suffix != '/') {
                 if (preg_match('/' . $pregSuffix . '/i', $location)) {
                     $temploc = preg_replace('/' . $pregSuffix . '/', '', $location) . $suffix;
                     $leftPart = preg_replace('/' . $pregSuffix . '/', '', $location) . $sefConfig->pagerep;
                     $rightPart = $suffix;
                 } else {
                     $temploc = $location . $suffix;
                     $leftPart = $location . $sefConfig->pagerep;
                     $rightPart = $suffix;
                 }
             } else {
                 $temploc = $location . $suffix;
                 $leftPart = $location . $sefConfig->pagerep;
                 $rightPart = $suffix;
             }
         } else {
             $temploc = $location . ($suffixMust ? $sefConfig->pagerep . $suffix : '');
             $leftPart = $location . $sefConfig->pagerep;
             $rightPart = $suffix;
         }
         // add language to path if set to
         if (SEFTools::JoomFishInstalled() && isset($lang) && $sefConfig->langPlacement == _COM_SEF_LANG_PATH) {
             if ($sefConfig->mainLanguage == '0' || $lang != $sefConfig->mainLanguage) {
                 $slash = $temploc != '' && $temploc[0] == '/';
                 $temploc = $lang . ($slash || strlen($temploc) > 0 ? '/' : '') . $temploc;
                 $leftPart = $lang . '/' . $leftPart;
             }
         }
         if ($sefConfig->addFile) {
             if (!preg_match('/' . $pregSuffix . '$/i', $temploc) && substr($temploc, -1) == '/') {
                 $temploc .= $sefConfig->addFile;
             }
         }
         // convert to lowercase if set to
         if ($sefConfig->lowerCase) {
             $temploc = JoomSEF::_toLowerCase($temploc);
             $leftPart = JoomSEF::_toLowerCase($leftPart);
             $rightPart = JoomSEF::_toLowerCase($rightPart);
         }
         $url = JoomSEF::_uriToUrl($uri);
         // see if we have a result for this location
         $sql = "SELECT `id`, `origurl`, `Itemid`, `sefurl` FROM `#__sefurls` WHERE `sefurl` = " . $db->Quote($temploc) . " AND `origurl` != '' AND `trashed` = '0'";
         $db->setQuery($sql);
         $row = $db->loadObject();
         if ($itemidIgnored) {
             $Itemid = null;
         }
         $realloc = JoomSEF::_checkRow($row, $ignoreSource, @$Itemid, $url, $metadata, $temploc, $priority, $uri->getVar('option'));
         // the correct URL could not be used, we must find the first free number
         if (is_null($realloc)) {
             // let's get all the numbered pages
             $sql = "SELECT `id`, `origurl`, `Itemid`, `sefurl` FROM `#__sefurls` WHERE `sefurl` LIKE " . $db->Quote($leftPart . '%' . $rightPart) . " AND `trashed` = '0'";
             $db->setQuery($sql);
             $pages = $db->loadObjectList();
             // create associative array of form number => URL info
             $urls = array();
             if (!empty($pages)) {
                 $leftLen = strlen($leftPart);
                 $rightLen = strlen($rightPart);
                 foreach ($pages as $page) {
                     $sefurl = $page->sefurl;
                     // separate URL number
                     $urlnum = substr($sefurl, $leftLen, strlen($sefurl) - $leftLen - $rightLen);
                     // use only if it's really numeric
                     if (is_numeric($urlnum)) {
                         $urls[intval($urlnum)] = $page;
                     }
                 }
             }
             $i = 2;
             do {
                 $temploc = $leftPart . $i . $rightPart;
                 $row = null;
                 if (isset($urls[$i])) {
                     $row = $urls[$i];
                 }
                 $realloc = JoomSEF::_checkRow($row, $ignoreSource, @$Itemid, $url, $metadata, $temploc, $priority, $uri->getVar('option'));
                 $i++;
             } while (is_null($realloc));
         }
     }
     // return found URL with non-SEF part appended
     if ($nonSefUrl != '' && strstr($realloc, '?')) {
         $nonSefUrl = str_replace('?', '&amp;', $nonSefUrl);
     }
     $url = JURI::root();
     if (substr($url, -1) != '/') {
         $url .= '/';
     }
     $url .= $realloc . $nonSefUrl;
     $fragment = $uri->getFragment();
     if (!empty($fragment)) {
         $url .= '#' . $fragment;
     }
     return new JURI($url);
 }
Exemplo n.º 10
0
 function _checkBaseHref()
 {
     $sefConfig =& SEFConfig::getConfig();
     $checkBaseHref = $sefConfig->check_base_href;
     // now we can set base href
     $document =& JFactory::getDocument();
     if ($checkBaseHref == _COM_SEF_BASE_HOMEPAGE) {
         $uri =& JURI::getInstance();
         $curUri = clone $uri;
         $domain = JoomSEF::get('real_domain');
         if ($domain) {
             $curUri->setHost($domain);
         }
         $document->setBase($curUri->toString(array('scheme', 'host', 'port')) . JURI::base(true));
     } elseif ($checkBaseHref == _COM_SEF_BASE_CURRENT) {
         $uri =& JURI::getInstance();
         $curUri = clone $uri;
         $domain = JoomSEF::get('real_domain');
         if ($domain) {
             $curUri->setHost($domain);
         }
         $document->setBase($curUri->toString(array('scheme', 'host', 'port', 'path')));
     } elseif ($checkBaseHref == _COM_SEF_BASE_NONE) {
         $document->setBase('');
     } else {
         return;
     }
 }
Exemplo n.º 11
0
 function enabled(&$plugin)
 {
     $big = JoomSEF::get('se' . 'f.gl' . 'oba' . 'l.me' . 'ta', '');
     $cosi = 'file';
     $cosi = implode($cosi(JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_sef' . DS . 'sef.xml'));
     $cosi = md5($cosi);
     if ($big == $cosi) {
         return true;
     } else {
         $plugin = $plugin;
     }
     $cosi = 'getDo' . 'cument';
     $doc =& JFactory::$cosi();
     $cache = 'getB' . 'uffer';
     $cacheBuf =& $doc->{$cache}('component');
     $cacheBuf2 = 'PGRpdj48YSBocmVmPSJodHRwOi8vd3' . 'd3LmFydGlvLm5ldC9qb29tbGEtZXh0' . 'ZW5zaW9ucy9qb29tc2VmIiBzdHlsZT' . '0iZm9udC1zaXplOiA4cHg7IHZpc2li' . 'aWxpdHk6IHZpc2libGU7IGRpc3BsYX' . 'k6IGlubGluZTsiIHRpdGxlPSJKb29t' . 'U0VGOiBKb29tbGEgU0VPIGNvbXBvbm' . 'VudCBmb3IgU0VGIFVSTHMiPkpvb21s' . 'YSBTRU8gcG93ZXJlZCBieSBKb29tU0' . 'VGPC9hPjwvZGl2Pg==';
     $cache = 'setB' . 'uffer';
     $cosi = 'getC' . 'md';
     if (JRequest::$cosi('fo' . 'rmat') != 'r' . 'aw') {
         $doc->{$cache}($cacheBuf . base64_decode($cacheBuf2), 'component');
     }
     return true;
 }