示例#1
0
 public function create(&$uri)
 {
     $title = array();
     $vars = $uri->getQuery(true);
     $this->_createNonSefVars($uri);
     // Set menu title
     $title[] = JoomSEF::_getMenuTitle($uri->getVar('option'), $uri->getVar('task'), $uri->getVar('Itemid'));
     if (isset($vars['view'])) {
         switch ($vars['view']) {
             case 'tag':
                 if (isset($vars['id'])) {
                     $tag = $this->getTag($vars['id']);
                     if (is_null($tag)) {
                         JoomSefLogger::Log('Tag with ID ' . $vars['id'] . ' not set.', $this, 'com_tags');
                         return $uri;
                     }
                     $title[] = $tag;
                 }
                 break;
             default:
                 $title[] = $vars['view'];
                 break;
         }
     }
     $newUri = $uri;
     if (count($title) > 0) {
         $newUri = JoomSEF::_sefGetLocation($uri, $title, null, null, null, $uri->getVar('lang'), $this->nonSefVars, null, null, null, true);
     }
     return $newUri;
 }
 function create(&$uri)
 {
     $vars = $uri->getQuery(true);
     extract($vars);
     $this->params =& SEFTools::getExtParams('com_search');
     $newUri = $uri;
     if (!(isset($task) ? @$task : null)) {
         $title[] = JoomSEF::_getMenuTitle($option, isset($task) ? $task : null);
         if (isset($searchword) && $this->params->get('nonsefphrase', '1') != '1') {
             $title[] = $searchword;
         }
         if (count($title) > 0) {
             $this->_createNonSefVars($uri);
             if (!isset($searchword) || $this->params->get('nonsefphrase', '1') != '1') {
                 // Generate meta tags
                 $desc = array();
                 if (isset($searchword)) {
                     $desc[] = $searchword;
                 }
                 if (isset($searchphrase)) {
                     $desc[] = $searchphrase;
                 }
                 $this->metadesc = implode(', ', $desc);
                 unset($desc);
             }
             $metatags = $this->getMetaTags();
             $newUri = JoomSEF::_sefGetLocation($uri, $title, null, null, null, @$vars['lang'], $this->nonSefVars, null, $metatags);
         }
     }
     return $newUri;
 }
 function create(&$uri)
 {
     $vars = $uri->getQuery(true);
     extract($vars);
     // Don't SEF URLs with "return" variable
     if (!empty($return)) {
         return $uri;
     }
     $title = array();
     $title[] = JoomSEF::_getMenuTitle(@$option, null, @$Itemid);
     if (isset($task)) {
         if ($task == 'register') {
             $title[] = JText::_('Register');
             unset($task);
         }
         /*if($task=='activate') {
           	$title[]=$vars['activation'];
           }*/
     }
     if (!empty($view)) {
         $title[] = JText::_($view);
     }
     if (!empty($layout)) {
         $title[] = JText::_($layout);
     }
     $newUri = $uri;
     if (count($title) > 0) {
         $this->_createNonSefVars($uri);
         $newUri = JoomSEF::_sefGetLocation($uri, $title, @$task, null, null, @$lang, $this->nonSefVars);
     }
     return $newUri;
 }
 function create(&$uri)
 {
     $vars = $uri->getQuery(true);
     extract($vars);
     $title = array();
     $title[] = JoomSEF::_getMenuTitle(@$option, null, @$Itemid);
     $newUri = $uri;
     if (count($title) > 0) {
         $newUri = JoomSEF::_sefGetLocation($uri, $title, null, null, null, @$lang);
     }
     return $newUri;
 }
 function create(&$uri)
 {
     $sefConfig =& SEFConfig::getConfig();
     $database =& JFactory::getDBO();
     $this->params =& SEFTools::getExtParams('com_weblinks');
     // JF translate extension.
     $jfTranslate = $sefConfig->translateNames ? ', `id`' : '';
     $vars = $uri->getQuery(true);
     extract($vars);
     $title = array();
     $title[] = JoomSEF::_getMenuTitle($option, @$this_task);
     if (@$view == 'category') {
         $title[] = $this->getCategoryTitle($id, SEFTools::UseAlias($this->params, 'category_alias'));
     } elseif (empty($this_task) && @$view == 'weblink') {
         if (isset($catid)) {
             if ($this->params->get('show_category', '1')) {
                 $title[] = $this->getCategoryTitle($catid, SEFTools::UseAlias($this->params, 'category_alias'));
             }
         }
         if (!empty($id)) {
             $field = 'title';
             if (SEFTools::UseAlias($this->params, 'weblink_alias')) {
                 $field = 'alias';
             }
             $id = intval($id);
             $database->setQuery("SELECT `{$field}` AS `title` {$jfTranslate} FROM `#__weblinks` WHERE `id` = '{$id}'");
             $row = $database->loadObject();
             if (is_null($row)) {
                 JoomSefLogger::Log("Weblink with ID {$id} could not be found.", $this, 'com_weblinks');
             } elseif (!empty($row->title)) {
                 $name = $row->title;
                 if ($this->params->get('weblink_id', '0')) {
                     $name = $id . '-' . $name;
                 }
                 $title[] = $name;
             }
         } else {
             $title[] = JText::_('Submit');
         }
     }
     if (isset($task) && $task == 'new') {
         $title[] = 'new' . $sefConfig->suffix;
     }
     $newUri = $uri;
     if (count($title) > 0) {
         // Generate meta tags
         $metatags = $this->getMetaTags();
         $priority = $this->getPriority($uri);
         $sitemap = $this->getSitemapParams($uri);
         $newUri = JoomSEF::_sefGetLocation($uri, $title, null, null, null, @$vars['lang'], null, null, $metatags, $priority, false, null, $sitemap);
     }
     return $newUri;
 }
 function create(&$uri)
 {
     $vars = $uri->getQuery(true);
     extract($vars);
     $title = array();
     $profile_name = $this->getAiContactSafeProfileName($pf);
     if (strlen(trim($profile_name)) > 0) {
         $title[] = $profile_name;
     } else {
         $title[] = JoomSEF::_getMenuTitle(@$option, null, @$Itemid);
     }
     $newUri = $uri;
     if (count($title) > 0) {
         $newUri = JoomSEF::_sefGetLocation($uri, $title, null, null, null, @$lang);
     }
     return $newUri;
 }
 function create(&$uri)
 {
     $sefConfig =& SEFConfig::getConfig();
     $params = SEFTools::GetExtParams('com_content');
     $vars = $uri->getQuery(true);
     extract($vars);
     // Set title.
     $title = array();
     $title[] = JoomSEF::_getMenuTitle(@$option, @$task, @$Itemid);
     if (!empty($tmpl)) {
         $title[] = $tmpl;
     }
     $newUri = $uri;
     if (count($title) > 0) {
         $this->_createNonSefVars($uri);
         $newUri = JoomSEF::_sefGetLocation($uri, $title, null, null, null, @$lang, null, $this->ignoreVars);
     }
     return $newUri;
 }
 function create(&$uri)
 {
     $sefConfig =& SEFConfig::getConfig();
     $this->params =& SEFTools::getExtParams('com_banners');
     $vars = $uri->getQuery(true);
     extract($vars);
     //$title[] = 'banners';
     //$title[] = '/';
     //$title[] = $task.$bid.$sefConfig->suffix;
     $title[] = JoomSEF::_getMenuTitle(@$option, @$task, @$Itemid);
     switch (@$task) {
         case 'click':
             $title[] = $this->GetBannerName($bid);
             unset($task);
             break;
     }
     $newUri = $uri;
     if (count($title) > 0) {
         $newUri = JoomSEF::_sefGetLocation($uri, $title, @$task, null, null, @$vars['lang']);
     }
     return $newUri;
 }
示例#9
0
文件: joomsef.php 项目: 01J/bealtine
 /**
  * Find existing or create new SEO URL.
  *
  * @param array $data
  * @return string
  */
 function _storeLocation(&$data, $check = false, $removeItemid = false)
 {
     $mainframe =& JFactory::getApplication();
     $db =& JFactory::getDBO();
     $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, 'host' => false, 'sitemapParams' => null);
     foreach ($defaults as $varName => $value) {
         if (is_array($data) && isset($data[$varName])) {
             ${$varName} = $data[$varName];
         } else {
             ${$varName} = $value;
         }
     }
     // Original object is stored in origUri
     $origUri = $uri;
     $uri = clone $origUri;
     // 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'), null, @$uri->getVar('Itemid'))) {
             array_shift($title);
         }
     }
     // remove the Itemid if set to
     if ($removeItemid) {
         $uri->delVar('Itemid');
     }
     // 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[] = $pagetext;
     }
     // get all the titles ready for urls.
     $location = array();
     foreach ($title as $titlePart) {
         if (strlen($titlePart) == 0) {
             continue;
         }
         $location[] = JoomSEF::_titleToLocation($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 (eregi($regexSuffix.'$', $imptrim)) {
     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 (eregi($regexSuffix.'$', $imptrim)) {
     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);
     // check if the location isn't too long for database storage and truncate it in that case
     $suffixthere = 0;
     //if (eregi($regexSuffix.'$', $location)) {
     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 = ereg_replace($regexSuffix.'$', '', $location);
         $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
     $realloc = false;
     if ($sefConfig->useCache) {
         if (!$check) {
             $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` = '" . addslashes(html_entity_decode(urldecode($url))) . "'" . $where . ' 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` = '" . addslashes(html_entity_decode(urldecode($url))) . "'" . $where . ' 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) && !$check) {
         // return the original URL if SEF is disabled
         if (!$realloc->sef) {
             return $origUri;
         }
         // return found URL with non-SEF part appended
         if ($nonSefUrl != '' && strstr($realloc->sefurl, '?')) {
             $nonSefUrl = str_replace('?', '&amp;', $nonSefUrl);
         }
         if (!strlen($host)) {
             $root = JFactory::getURI()->getHost();
         } else {
             $root = $host;
         }
         $url = JFactory::getURI()->getScheme() . "://" . $root;
         if (substr($url, -1) != '/') {
             $url .= '/';
         }
         $url .= $realloc->sefurl . $nonSefUrl;
         $fragment = $uri->getFragment();
         if (!empty($fragment)) {
             $url .= '#' . $fragment;
         }
         JoomSefUri::updateUri($origUri, $url);
         return $origUri;
     } else {
         if (!is_object($realloc) || $check) {
             // return the original URL if we don't want to save new URLs
             if ($sefConfig->disableNewSEF) {
                 return $origUri;
             }
             $realloc = null;
             $suffixMust = false;
             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 (eregi($regexSuffix, $location)) {
                     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 ($sefConfig->langEnable && isset($lang) && $sefConfig->langPlacementJoomla == _COM_SEF_LANG_PATH) {
                 if ($sefConfig->alwaysUseLang || $lang != $sefConfig->mainLanguageJoomla) {
                     $slash = $temploc != '' && $temploc[0] == '/';
                     $temploc = $lang . ($slash || strlen($temploc) > 0 ? '/' : '') . $temploc;
                     $leftPart = $lang . '/' . $leftPart;
                 }
             }
             if ($sefConfig->addFile) {
                 //if (!eregi($regexSuffix . '$', $temploc) && substr($temploc, -1) == '/') {
                 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` = '{$temploc}' AND `origurl` != ''";
             $db->setQuery($sql);
             $row = $db->loadObject();
             if ($itemidIgnored) {
                 $Itemid = null;
             }
             $realloc = JoomSEF::_checkRow($row, $ignoreSource, @$Itemid, $url, $metadata, $temploc, $priority, $uri->getVar('option'), $check, $host, $sitemapParams);
             // 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 '{$leftPart}%{$rightPart}'";
                 $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'), false, $host, $sitemapParams);
                     $i++;
                 } while (is_null($realloc));
             }
         }
     }
     // return found URL with non-SEF part appended
     if ($nonSefUrl != '' && strstr($realloc, '?')) {
         $nonSefUrl = str_replace('?', '&amp;', $nonSefUrl);
     }
     if (!strlen($host)) {
         $root = JFactory::getUri()->toString(array('host', 'port'));
     } else {
         $root = $host;
     }
     $url = JFactory::getURI()->getScheme() . "://" . $root . JURI::root(true);
     if (substr($url, -1) != '/') {
         $url .= '/';
     }
     $url .= $realloc . $nonSefUrl;
     $fragment = $uri->getFragment();
     if (!empty($fragment)) {
         $url .= '#' . $fragment;
     }
     JoomSefUri::updateUri($origUri, $url);
     return $origUri;
 }
 function create(&$uri)
 {
     // Extract variables
     $vars = $uri->getQuery(true);
     extract($vars);
     $title = array();
     $this->params = SEFTools::getExtParams('com_contact');
     $title[] = JoomSEF::_getMenuTitle(@$option, @$task, @$Itemid);
     if (isset($view)) {
         switch ($view) {
             case 'contact':
                 $title = array_merge($title, $this->getContactName($id));
                 unset($view);
                 break;
             case 'category':
                 if (isset($catid)) {
                     $title[] = $this->getCategoryTitle($catid);
                 }
                 unset($view);
                 break;
         }
     }
     if (!empty($format) && $format == 'feed') {
         if (!empty($type)) {
             $title[] = $type;
         }
     }
     $newUri = $uri;
     if (count($title) > 0) {
         // Generate meta tags
         $metatags = $this->getMetaTags();
         $priority = $this->getPriority($uri);
         $sitemap = $this->getSitemapParams($uri);
         $newUri = JoomSEF::_sefGetLocation($uri, $title, @$view, null, null, @$lang, null, null, $metatags, $priority, false, null, $sitemap);
     }
     return $newUri;
 }
 function create(&$uri)
 {
     $sefConfig =& SEFConfig::getConfig();
     $mainframe =& JFactory::getApplication();
     $this->params =& SEFTools::GetExtParams('com_content');
     $vars = $uri->getQuery(true);
     extract($vars);
     // Do not SEF URLs with exturl variable
     //if( !empty($exturl) )   return $string;
     // Do not SEF edit urls
     if (isset($task) && $task == 'edit') {
         return $uri;
     }
     // Set title.
     $title = array();
     switch (@$view) {
         case 'new':
         case 'edit':
             /*
             $title[] = getMenuTitle($option, $task, $Itemid, $string);
             $title[] = 'new' . $sefConfig->suffix;
             */
             break;
         case 'archive':
             $title[] = JText::_($view);
             if (!empty($year)) {
                 $title[] = $year;
             }
             if (!empty($month)) {
                 $title[] = $month;
             }
             break;
             /*
             case 'archivecategory':
             case 'archivesection': {
             if (eregi($task.".*id=".$id, $_SERVER['REQUEST_URI'])) break;
             }
             */
         /*
         case 'archivecategory':
         case 'archivesection': {
         if (eregi($task.".*id=".$id, $_SERVER['REQUEST_URI'])) break;
         }
         */
         default:
             if (isset($format)) {
                 if ($format == 'pdf') {
                     // wrong ID
                     if (intval($id) == 0) {
                         return $uri;
                     }
                     // create PDF
                     $title = $this->_getContentTitles(!empty($view) ? $view : 'article', $id);
                     if (count($title) === 0) {
                         $title[] = JoomSEF::_getMenuTitle(@$option, @$task, @$Itemid);
                     }
                     // Add Google News number if set to
                     if (@$view == 'article' && $this->params->get('googlenewsnum', '0') != '0') {
                         $i = count($title) - 1;
                         $title[$i] = $this->GoogleNews($title[$i], $id);
                     }
                     $title[] = JText::_('PDF');
                 } elseif ($format == 'feed') {
                     // Create feed
                     if (@$view != 'frontpage') {
                         // wrong ID
                         if (intval($id) == 0) {
                             return $uri;
                         }
                         $title = $this->_getContentTitles(!empty($view) ? $view : 'article', $id);
                         // Add Google News number if set to
                         if (@$view == 'article' && $this->params->get('googlenewsnum', '0') != '0') {
                             $i = count($title) - 1;
                             $title[$i] = $this->GoogleNews($title[$i], $id);
                         }
                     }
                     if (count($title) === 0 && empty($type)) {
                         $title[] = JoomSEF::_getMenuTitle(@$option, @$task, @$Itemid);
                     }
                     if (!empty($type)) {
                         $title[] = $type;
                     }
                 }
             } else {
                 if (isset($id)) {
                     // wrong ID
                     if (intval($id) == 0) {
                         return $uri;
                     }
                     $title = $this->_getContentTitles(@$view, @$id);
                     if (count($title) === 0) {
                         $title[] = JoomSEF::_getMenuTitle(@$option, @$task, @$Itemid);
                     }
                     // Add Google News number if set to
                     if (@$view == 'article' && $this->params->get('googlenewsnum', '0') != '0') {
                         $i = count($title) - 1;
                         $title[$i] = $this->GoogleNews($title[$i], $id);
                     }
                 } else {
                     $title[] = JoomSEF::_getMenuTitle(@$option, @$task, @$Itemid);
                     //$title[] = JText::_('Submit');
                 }
                 // Layout
                 $addLayout = $this->params->get('add_layout', '2');
                 if (isset($layout) && !empty($layout) && $addLayout != '0') {
                     if ($addLayout == '2') {
                         $defLayout = $this->params->get('def_layout', 'default');
                         if ($layout != $defLayout) {
                             $title[] = $layout;
                         }
                     } else {
                         $title[] = $layout;
                     }
                 }
                 if (isset($limitstart) && (!$sefConfig->appendNonSef || $this->params->get('pagination', '0') == '0')) {
                     $pagetext = null;
                     if (@$view == 'article') {
                         // Multipage article - get the correct page title
                         $page = $limitstart + 1;
                         if ($this->params->get('multipagetitles', '1') == '1') {
                             $pagetext = $this->_getPageTitle($limitstart);
                         }
                     } else {
                         // Is limit set?
                         if (!isset($limit)) {
                             // Try to get limit from menu parameters
                             $menu =& JSite::getMenu();
                             if (!isset($Itemid)) {
                                 // We need to find Itemid first
                                 $active =& $menu->getActive();
                                 $Itemid = $active->id;
                             }
                             $menuParams =& $menu->getParams($Itemid);
                             $leading = $menuParams->get('num_leading_articles', 1);
                             $intro = $menuParams->get('num_intro_articles', 4);
                             $links = $menuParams->get('num_links', 4);
                             if (isset($layout) && $layout == 'blog') {
                                 $limit = $leading + $intro;
                                 // + $links;
                             } else {
                                 $limit = $menuParams->get('display_num', $mainframe->getCfg('list_limit'));
                                 $limit = $mainframe->getUserStateFromRequest('com_content.' . $uri->getVar('layout', 'default') . '.limit', 'limit', $limit, 'int');
                             }
                         }
                         $page = intval($limitstart / $limit) + 1;
                     }
                     if (is_null($pagetext)) {
                         $pagetext = strval($page);
                         if ($cnfPageText = $sefConfig->getPageText()) {
                             $pagetext = str_replace('%s', $page, $cnfPageText);
                         }
                     }
                     $title = array_merge($title, explode('/', $pagetext));
                     //$title[] = $pagetext;
                 }
                 // show all
                 if (isset($showall) && $showall == 1) {
                     $title[] = JText::_('All Pages');
                 }
                 // print article
                 if (isset($print) && $print == 1) {
                     $title[] = JText::_('Print') . (!empty($page) ? '-' . ($page + 1) : '');
                 }
             }
     }
     $newUri = $uri;
     if (count($title) > 0) {
         // Generate meta tags
         $metatags = $this->getMetaTags();
         if (isset($this->metatitle)) {
             $metatags['metatitle'] = $this->metatitle;
         }
         $this->_createNonSefVars($uri);
         $priority = $this->getPriority($uri);
         $sitemap = $this->getSitemapParams($uri);
         $newUri = JoomSEF::_sefGetLocation($uri, $title, null, null, null, @$lang, $this->nonSefVars, null, $metatags, $priority, true, null, $sitemap);
     }
     return $newUri;
 }
示例#12
0
 function create(&$uri)
 {
     $vars = $uri->getQuery(true);
     extract($vars);
     $title = array();
     // Don't SEF if no variables
     if (self::$is20 && is_null($uri->getVar('view'))) {
         return $uri;
     }
     // JF translate extension.
     $sefConfig =& SEFConfig::getConfig();
     $database =& JFactory::getDBO();
     $jfTranslate = $sefConfig->translateNames ? ', `id`' : '';
     // load params
     $this->params = SEFTools::getExtParams('com_kunena');
     $catRewrite = true;
     $msgRewrite = true;
     $usrRewrite = true;
     /*if (isset($view) && ($view == 'category')) {
           $msgRewrite = false;
       }*/
     if ($msgRewrite || $catRewrite) {
         if ($catRewrite && !empty($catid)) {
             $categories = $this->GetCategories($catid);
             if (is_null($categories)) {
                 // Error, don't SEF
                 return $uri;
             }
         }
         if (isset($id)) {
             $msgID = $id;
         } elseif (isset($msg_id)) {
             $msgID = $msg_id;
         } elseif (isset($replyto)) {
             $msgID = $replyto;
         } elseif (isset($pid)) {
             $msgID = $pid;
         } else {
             $msgID = null;
         }
         if ($msgRewrite && !empty($msgID)) {
             if (isset($func) && $func == 'announcement') {
                 $msgTitle = $this->GetAnnouncementTitle($msgID);
             } else {
                 if (self::$is20) {
                     $msgTitle = $this->GetTopicTitle($msgID);
                 } else {
                     $msgTitle = $this->GetMessageTitle($msgID);
                 }
             }
             if (is_null($msgTitle)) {
                 // Error, don't SEF
                 return $uri;
             }
         }
     }
     // Set non-sef vars according to settings
     $this->_createNonSefVars($uri);
     // this needs to follow previous that use do
     if ($this->params->get('doExclude', true)) {
         unset($do);
     }
     // get user ID
     if ($usrRewrite && isset($userid)) {
         if ($this->params->get('userIdInsteadOfLogin', false)) {
             $usrTitle = 'user-' . $userid;
         } else {
             $query = "SELECT `username` FROM `#__users` WHERE `id` = {$userid}";
             $database->setQuery($query);
             $usrTitle = $database->loadResult();
         }
     }
     // use view if func not set
     if (!isset($func) && isset($view)) {
         $func = $view;
         unset($view);
     }
     // if task is not set, use do
     if (empty($task) && isset($func) && $func == 'post' && isset($do)) {
         $task = $do;
         unset($func);
         unset($do);
     }
     if (empty($task) && isset($func)) {
         $task = $func;
         unset($func);
     }
     // First subdir
     if (!empty($option) && !self::$is16) {
         $title[] = JoomSEF::_getMenuTitle($option, @$task, @$Itemid);
     } elseif (self::$is16) {
         $menuTitle = $this->getDefaultForumMenuTitle();
         if (!is_null($menuTitle)) {
             $title[] = $menuTitle;
         }
     }
     // Category
     if (isset($categories) && !empty($categories)) {
         $addCat = $this->params->get('categories', '2');
         if ($addCat == '2') {
             $title = array_merge($title, $categories);
         } else {
             if ($addCat == '1' || empty($msgID)) {
                 $title[] = $categories[count($categories) - 1];
             }
         }
     }
     // Announcement
     if (@$task == 'announcement') {
         $title[] = JText::_('Announcements');
     }
     // Topic
     if (isset($msgTitle) && !empty($msgTitle) && isset($task) && $task != 'showcat') {
         //$title[] = (!isset($do) && !isset($func)) ? $msgTitle.$sefConfig->suffix : $msgTitle;
         $title[] = $msgTitle;
     }
     if (isset($task) && in_array($task, array('search', 'advsearch'))) {
         if ($task == 'advsearch') {
             $title[] = JText::_('Advanced Search');
         } else {
             $title[] = JText::_($task);
         }
         if (isset($limitstart)) {
             unset($limitstart);
         }
         if (isset($limit)) {
             unset($limit);
         }
         unset($task);
     }
     if (isset($task) && $task == 'topics') {
         $title[] = $task;
         unset($task);
     }
     // Cleanout some views
     if (in_array(@$view, array('entrypage', 'category', 'topic', 'home'))) {
         unset($view);
     }
     // Cleanout some funcs
     if (in_array(@$func, array('showcat', 'view', 'announcement', 'entrypage', 'rules', 'category', 'topic', 'home'))) {
         unset($func);
     }
     // Cleanout some tasks
     if (in_array(@$task, array('showcat', 'view', 'announcement', 'entrypage', 'category', 'topic', 'home'))) {
         unset($task);
     }
     // View
     if (isset($view)) {
         $title[] = $view;
     }
     // JSON
     if (isset($task) && $task == 'json') {
         $title[] = $task;
         unset($task);
     }
     // Action
     if (isset($action)) {
         $title[] = $action;
         unset($action);
     }
     // User
     if (@$task == 'user') {
         if (empty($Itemid)) {
             $title[] = 'user';
         } else {
             $app = JFactory::getApplication();
             $menu = $app->getMenu('site');
             $item = $menu->getItem($Itemid);
             if (!is_object($item) || !isset($item->query['view']) || $item->query['view'] != 'user') {
                 $title[] = 'user';
             } else {
                 $title[] = 'profile';
             }
         }
         $task = null;
     }
     if (isset($usrTitle) && !empty($usrTitle)) {
         if (@$task == 'fbprofile') {
             $title[] = 'users';
             $task = null;
         } elseif (@$task == 'profile') {
             $title[] = 'profile';
             $task = null;
         } elseif (@$task == 'showprf') {
             $task = null;
         }
         $title[] = $usrTitle;
     }
     // Misc
     if (@$task == 'misc' && !empty($Itemid)) {
         // Use correct menu title
         $title[] = JoomSEF::_getMenuTitle(null, null, $Itemid);
         $task = null;
     }
     // Layout
     if (isset($layout)) {
         switch ($layout) {
             case 'reply':
                 if (isset($quote) && $quote) {
                     $layout = 'quote';
                 }
                 $title[] = $layout;
                 break;
             case 'list':
                 if ($uri->getVar('view') == 'category') {
                     $layout = 'index';
                     $title[] = $layout;
                 } else {
                     if ($uri->getVar('view') == 'user') {
                         $title[] = $layout;
                     }
                 }
                 break;
             case 'default':
                 // Don't add
                 break;
             default:
                 $title[] = $layout;
                 break;
         }
         unset($layout);
     }
     // Gallery
     if (isset($gallery)) {
         $title[] = $gallery;
     }
     // Func and do
     if (isset($do) || isset($func)) {
         if (isset($func)) {
             if ($func == 'search') {
                 $oper[] = 'do';
             }
             $oper[] = $func;
         }
         if (isset($do)) {
             $oper[] = $do;
         }
         $title[] = join('-', $oper) . $sefConfig->suffix;
     }
     // Fix some task texts
     if (isset($task)) {
         $task = str_replace(array('listcat', 'userlist'), array('categories', 'users'), $task);
     }
     // Mode
     if (isset($mode) && $mode == 'noreplies') {
         $title[] = $mode;
     }
     // Feeds
     if (isset($format)) {
         switch ($format) {
             case 'feed':
                 if (!isset($type)) {
                     $type = 'rss';
                 }
                 $title[] = $type;
                 break;
             case 'raw':
                 $title[] = $format;
                 break;
         }
     }
     // Page number
     if (isset($limitstart)) {
         // Limit should be set due to beforeCreate function, but to be sure
         if (!isset($limit)) {
             if (in_array($uri->getVar('view'), array('category', 'topics')) && isset(self::$kunenaConfig->threads_per_page)) {
                 $limit = self::$kunenaConfig->threads_per_page;
             } elseif ($uri->getVar('view') == 'user') {
                 $limit = self::$kunenaConfig->userlist_rows;
             } else {
                 $limit = self::$kunenaConfig->messages_per_page;
             }
         }
         $pageNum = intval($limitstart / $limit) + 1;
         $pagetext = strval($pageNum);
         if ($cnfPageText = $sefConfig->getPageText()) {
             $pagetext = str_replace('%s', $pageNum, $cnfPageText);
         }
         $title = array_merge($title, explode('/', $pagetext));
         //$title[] = $pagetext;
     }
     // Selection
     if (!empty($sel)) {
         if (isset($task) && $task == 'latest') {
             $num = $sel >= 24 ? $sel / 24 : $sel;
             $title[] = $task . '-' . $num;
             unset($task);
         } else {
             $title[] = $sel;
         }
     }
     if (isset($page) && $page > 1) {
         $pagetext = strval($page);
         if ($cnfPageText = $sefConfig->getPageText()) {
             $pagetext = str_replace('%s', $page, $cnfPageText);
         }
         $title[] = $pagetext;
     }
     // Task
     if (isset($task)) {
         $title[] = $task;
         unset($task);
     }
     $newUri = $uri;
     if (count($title) > 0) {
         $newUri = JoomSEF::_sefGetLocation($uri, $title, null, @$limit, @$limitstart, @$lang, $this->nonSefVars, $this->ignoreVars, null, null, true);
     }
     return $newUri;
 }
示例#13
0
 function create(&$uri)
 {
     $vars = $uri->getQuery(true);
     $title = array();
     if ($this->params->get('showMenuTitle', '1') == '1') {
         $title[] = JoomSEF::_getMenuTitle($uri->getVar('option'), null, $uri->getVar('Itemid'));
     } else {
         $title[] = substr($uri->getVar('option'), 4);
     }
     $noAdd = array('option', 'lang', 'Itemid');
     foreach ($vars as $name => $value) {
         if (in_array($name, $noAdd)) {
             continue;
         }
         $this->_addValue($title, $value);
     }
     $newUri = $uri;
     if (count($title) > 0) {
         $newUri = JoomSEF::_sefGetLocation($uri, $title, null, null, null, $uri->getVar('lang'));
     }
     return $newUri;
 }