Пример #1
0
function shCheckRedirect($dest, $incomingUrl)
{
    $sefConfig =& shRouter::shGetConfig();
    if (!empty($dest) && $dest != $incomingUrl) {
        // redirect to alias
        if ($dest == sh404SEF_HOMEPAGE_CODE) {
            if (!empty($sefConfig->shForcedHomePage)) {
                $dest = shFinalizeURL($sefConfig->shForcedHomePage);
            } else {
                $dest = shFinalizeURL($GLOBALS['shConfigLiveSite']);
            }
        } else {
            $shUri = new JURI($dest);
            $shOriginalUri = clone $shUri;
            $dest = shSefRelToAbs($dest, '', $shUri, $shOriginalUri) . $shUri->toString(array('query'));
        }
        if ($dest != $incomingUrl) {
            _log('Redirecting to ' . $dest . ' from alias ' . $incomingUrl);
            shRedirect($dest);
        }
    }
}
Пример #2
0
 protected function _do404(&$uri)
 {
     if (self::$requestParsed) {
         return array();
     }
     // get config objects
     $pageInfo =& Sh404sefFactory::getPageInfo();
     $sefConfig = Sh404sefFactory::getConfig();
     // store the status
     $pageInfo->httpStatus = 404;
     // request path
     $reqPath = $uri->getPath();
     // optionnally log the 404 details
     if ($sefConfig->shLog404Errors && !empty($reqPath)) {
         try {
             $record = Sh404sefHelperDb::selectObject('#__sh404sef_urls', '*', array('oldurl' => $reqPath));
             if (!empty($record)) {
                 // we have, so update counter
                 Sh404sefHelperDb::queryQuote('update ?? set cpt=(cpt+1) where ?? = ?', array('#__sh404sef_urls', 'oldurl'), array($reqPath));
             } else {
                 // record the 404
                 Sh404sefHelperDb::insert('#__sh404sef_urls', array('cpt' => 1, 'rank' => 0, 'oldurl' => $reqPath, 'newurl' => '', 'dateadd' => Sh404sefHelperDate::getUTCNow('Y-m-d')));
             }
             // add more details about 404 into security log file
             if ($sefConfig->shSecEnableSecurity && $sefConfig->shSecLogAttacks) {
                 $sep = "\t";
                 $logData = date('Y-m-d') . $sep . date('H:i:s') . $sep . 'Page not found (404)' . $sep . $_SERVER['REMOTE_ADDR'] . $sep;
                 $logData .= getHostByAddr($_SERVER['REMOTE_ADDR']) . $sep;
                 $userAgent = empty($_SERVER['HTTP_USER_AGENT']) ? 'No user agent' : $_SERVER['HTTP_USER_AGENT'];
                 $logData .= $userAgent . $sep . $_SERVER['REQUEST_METHOD'] . $sep . $_SERVER['REQUEST_URI'];
                 $logData .= empty($_SERVER['HTTP_REFERER']) ? "\n" : $sep . $_SERVER['HTTP_REFERER'] . "\n";
                 shLogToSecFile($logData);
             }
         } catch (Sh404sefExceptionDefault $e) {
             _log(__METHOD__ . '/' . __LINE__ . '/' . __CLASS__ . ': Database error: ' . $e->getMessage());
         }
     }
     // display the error page
     $vars['option'] = 'com_content';
     $vars['view'] = 'article';
     // use provided Itemid
     if (empty($sefConfig->shPageNotFoundItemid)) {
         $shHomePage = JFactory::getApplication()->getMenu()->getDefault();
         $vars['Itemid'] = empty($shHomePage) ? null : $shHomePage->id;
     } else {
         $vars['Itemid'] = $sefConfig->shPageNotFoundItemid;
     }
     // user picked our default 404 error page, read its id from DB
     if ($sefConfig->page404 == '0') {
         try {
             $requestedlanguageTag = JFactory::getLanguage()->getTag();
             $languageTag = JRequest::getString(JUtility::getHash('language'), null, 'cookie');
             if (!empty($languageTag)) {
                 $vars['lang'] = $languageTag;
             }
             $ids = Sh404sefHelperDb::queryQuoteOnly('select ?? from ?? where ?? = ? and ?? in ( ?, ?) order by ?? desc', array('id', '#__content', 'title', 'language', 'language'), array('__404__', $languageTag, '*'))->eLoadResultArray();
             $id = empty($ids[0]) ? null : $ids[0];
         } catch (Sh404sefExceptionDefault $e) {
             _log(__METHOD__ . '/' . __LINE__ . '/' . __CLASS__ . ': Database error: ' . $e->getMessage());
         }
         if (empty($id)) {
             JError::raiseError(404, JText::_('Component Not Found') . ' (' . $pageInfo->getDefaultLiveSite() . '/' . $uri->getPath() . ')');
         }
     } else {
         $id = $sefConfig->page404;
     }
     $vars['id'] = $id;
     $uri = new JURI($pageInfo->getDefaultLiveSite() . '/index.php?' . 'option=com_content&view=article&id=' . $id . (empty($vars['Itemid']) ? '' : '&Itemid=' . $vars['Itemid']) . (empty($vars['lang']) ? '' : '&lang=' . shGetIsoCodeFromName($vars['lang'])));
     $tmpl = str_replace('.php', '', $sefConfig->error404SubTemplate);
     if (!empty($tmpl)) {
         $vars['tmpl'] = $tmpl;
     }
     // and prepare the item for display
     $menus =& JFactory::getApplication()->getMenu();
     $menuItem = $menus->getItem($vars['Itemid']);
     if (!empty($menuItem)) {
         $menus->setActive($vars['Itemid']);
     } else {
         $menuItem = $menus->getDefault();
     }
     if (!empty($menuItem->params)) {
         $disableParams = array('show_title', 'show_category', 'show_author', 'show_create_date', 'show_modify_date', 'show_publish_date', 'show_vote', 'show_readmore', 'show_icons', 'show_hits', 'show_feed_link', 'show_page_heading');
         foreach ($disableParams as $p) {
             $menuItem->params->set($p, 0);
         }
         //set a custom page title
         $menuItem->params->set('page_title', htmlspecialchars($uri->get('_uri')));
     }
     // set the menu query array, J! will use that for breadcrumb
     $menuItem->query = $vars;
     // throw 404 http return code, and prepare for page display
     if (!headers_sent()) {
         JResponse::setHeader('status', '404 NOT FOUND');
         // custom error page, faster than loading Joomla 404 page. Not recommended though, why not show
         // your site ?
         if (is_readable(sh404SEF_FRONT_ABS_PATH . '404-Not-Found.tpl.html')) {
             $errorPage = file_get_contents(sh404SEF_FRONT_ABS_PATH . '404-Not-Found.tpl.html');
             if ($errorPage !== false) {
                 $errorPage = str_replace('%sh404SEF_404_URL%', ' (' . $pageInfo->getDefaultLiveSite() . '/' . $uri->getPath() . ')', $errorPage);
                 $errorPage = str_replace('%sh404SEF_404_SITE_URL%', $pageInfo->getDefaultLiveSite(), $errorPage);
                 $errorPage = str_replace('%sh404SEF_404_SITE_NAME%', JFactory::getApplication()->getCfg('sitename'), $errorPage);
                 echo $errorPage;
                 die;
             }
         }
     } else {
         _log('Headers already sent before getting control on 404 page - message displayed');
         $shUri = new JUri();
         $shOriginalUri = new JURI();
         $url = shSefRelToAbs($pageInfo->getDefaultLiveSite() . "/index.php?" . $_SERVER['QUERY_STRING'], '', $shUri, $shOriginalUri);
         JError::RaiseError(500, "<br />SH404SEF : headers were already sent when I got control!<br />This is not necessarily a sh404sef error. It may have been caused by any of your extensions or even Joomla itself. If there is no error message above this one, providing more details, then you may look inside the error log file of your web server for an indication of what may be breaking things up.<br />URL=" . $url . '<br />');
     }
     return $vars;
 }
Пример #3
0
 /**
  * Returns the sh404SEF SEF url for a give non-sef url,
  * creating it on the fly if not already in the database
  *
  * @param string $nonSefUrl non-sef url, starting with index.php?...
  * @param boolean $fullyQualified if true, return a fully qualified url, including protocol and host
  * @param boolean $xhtml
  * @param  $ssl
  */
 public static function getSefFromNonSef($nonSefUrl, $fullyQualified = true, $xhtml = false, $ssl = null)
 {
     if (!defined('SH404SEF_IS_RUNNING')) {
         return false;
     }
     $pageInfo = Sh404sefFactory::getPageInfo();
     if (empty($nonSefUrl)) {
         return $pageInfo->getDefaultFrontLiveSite();
     }
     $newUri = new JURI($nonSefUrl);
     $originalUri = clone $newUri;
     $route = shSefRelToAbs($nonSefUrl, $shLanguageParam = '', $newUri, $originalUri);
     $route = ltrim(str_replace($pageInfo->getDefaultFrontLiveSite(), '', $route), '/');
     $route = $route == '/' ? '' : $route;
     // find path
     $nonSefVars = $newUri->getQuery($asArray = true);
     if (strpos($route, '?') !== false && !empty($nonSefVars)) {
         $parts = explode('?', $route);
         // there are some query vars, just use the path
         $path = $parts[0];
     } else {
         $path = $route;
     }
     $newUri->setPath($path);
     if ($fullyQualified || (int) $ssl === 1) {
         // remove protocol, host, etc, only keep relative-to-site part
         $liveSite = $pageInfo->getDefaultFrontLiveSite();
         if ((int) $ssl === 1 && substr($liveSite, 0, 7) == 'http://') {
             $liveSite = str_replace('http://', 'https://', $liveSite);
         }
         $sefUrl = $liveSite . '/' . $newUri->toString();
     } else {
         $sefUrl = '/' . $newUri->toString(array('path', 'query', 'fragment'));
     }
     if ($xhtml) {
         $sefUrl = htmlspecialchars($sefUrl);
     }
     return $sefUrl;
 }
Пример #4
0
 function _buildSefRoute(&$uri)
 {
     $sefConfig =& shRouter::shGetConfig();
     $shPageInfo =& shRouter::shPageInfo();
     $menu =& shRouter::shGetMenu();
     // keep a copy of  Joomla original URI, which has article names in it (ie: 43:article-title)
     $originalUri = clone $uri;
     shNormalizeNonSefUri($uri, $menu);
     shNormalizeNonSefUri($originalUri, $menu, $removeSlugs = false);
     // do our job!
     $query = $uri->getQuery(false);
     $route = shSefRelToAbs('index.php?' . $query, null, $uri, $originalUri);
     $route = ltrim(str_replace($GLOBALS['shConfigLiveSite'], '', $route), '/');
     $route = $shPageInfo->base . ($route == '/' ? '' : $route);
     // find path
     if (strpos($route, '?') !== false) {
         $parts = explode('?', $route);
         if ($sefConfig->shRewriteMode == 2) {
             // '/index.php?/'
             // need to extract the first part of the query, which is actually the path
             // and store it as the path
             $tmpParts = explode('/index.php?/', $route);
             $tmpPath = '';
             if (isset($tmpParts[1])) {
                 // there is somethings after the /index.php?/
                 if (strpos($tmpParts[1], '?') !== false) {
                     // but this can also have parameters, so only get the path
                     $tmpPathParts = explode('?', $tmpParts[1]);
                     $tmpPath = $tmpPathParts[0];
                 } else {
                     $tmpPath = $tmpParts[1];
                 }
             }
             $path = $tmpParts[0] . '/index.php?/' . $tmpPath;
         } else {
             // there are some query vars, just use the path
             $path = $parts[0];
         }
     } else {
         $path = $route;
     }
     $uri->setPath($path);
 }
function shCheckRedirect ($dest, $incomingUrl) {

  $sefConfig = & Sh404sefFactory::getConfig();
  if (!empty($dest) && $dest != $incomingUrl) {
    // redirect to alias
    if ($dest == sh404SEF_HOMEPAGE_CODE) {
      if (!empty($sefConfig->shForcedHomePage)) {
        $dest = shFinalizeURL($sefConfig->shForcedHomePage);
      } else {
        $dest = shFinalizeURL(Sh404sefFactory::getPageInfo()->getDefaultLiveSite());
      }
    } else {
      $shUri = new JURI($dest);
      $shOriginalUri = clone( $shUri);
      $dest = shSefRelToAbs($dest, '', $shUri, $shOriginalUri) . $shUri->toString( array('query'));
    }
     
    if ($dest != $incomingUrl) {
      _log('Redirecting to '. $dest .' from alias '.$incomingUrl);
      shRedirect($dest);
    }
  }
}
Пример #6
0
                $tmpl = str_replace('.php', '', $sefConfig->error404SubTemplate);
                if (!empty($tmpl)) {
                    $vars['tmpl'] = $tmpl;
                }
                if (!headers_sent()) {
                    header('HTTP/1.0 404 NOT FOUND');
                    // V x : include error page, faster than loading Joomla 404 page. Not recommended though, why not show
                    // your site ?
                    if (is_readable(sh404SEF_FRONT_ABS_PATH . '404-Not-Found.tpl.html')) {
                        $errorPage = file_get_contents(sh404SEF_FRONT_ABS_PATH . '404-Not-Found.tpl.html');
                        if ($errorPage !== false) {
                            $errorPage = str_replace('%sh404SEF_404_URL%', $vars['mosmsg'], $errorPage);
                            $errorPage = str_replace('%sh404SEF_404_SITE_URL%', $GLOBALS['shConfigLiveSite'], $errorPage);
                            $errorPage = str_replace('%sh404SEF_404_SITE_NAME%', $mainframe->getCfg('sitename'), $errorPage);
                            echo $errorPage;
                            die;
                        }
                    }
                } else {
                    _log('Headers already sent before getting control on 404 page - message displayed');
                    $shUri = null;
                    $shOriginalUri = null;
                    $url = shSefRelToAbs($GLOBALS['shConfigLiveSite'] . "/index.php?" . $_SERVER['QUERY_STRING'], '', $shUri, $shOriginalUri);
                    print_r($path_array);
                    JError::RaiseError(500, "<br />SH404SEF : headers were already sent when I got control!<br />This is not necessarily a sh404sef error. It may have been caused by any of your extensions or even Joomla itself. If there is no error message above this one, providing more details, then you may look inside the error log file of your web server for an indication of what may be breaking things up.<br />URL=" . @$url . '<br />');
                }
            }
        }
        //end bad url
        //
}
Пример #7
0
 protected function _buildSefRoute(&$uri)
 {
     $pageInfo =& Sh404sefFactory::getPageInfo();
     $sefConfig = Sh404sefFactory::getConfig();
     $menu =& JFactory::getApplication()->getMenu();
     // keep a copy of  Joomla original URI, which has article names in it (ie: 43:article-title)
     $originalUri = clone $uri;
     shNormalizeNonSefUri($uri, $menu);
     shNormalizeNonSefUri($originalUri, $menu, $removeSlugs = false);
     // do our job!
     $query = $uri->getQuery(false);
     $route = shSefRelToAbs('index.php?' . $query, null, $uri, $originalUri);
     $route = ltrim(str_replace($pageInfo->getDefaultLiveSite(), '', $route), '/');
     $route = $route == '/' ? '' : $route;
     // find path
     $nonSefVars = $uri->getQuery($asArray = true);
     if (strpos($route, '?') !== false && !empty($nonSefVars)) {
         $parts = explode('?', $route);
         if ($sefConfig->shRewriteMode == 2) {
             // '/index.php?/' - removed from V 3.0+, but code left, as maybe we can put it back later?
             // need to extract the first part of the query, which is actually the path
             // and store it as the path
             $tmpParts = explode('/index.php?/', $route);
             $tmpPath = '';
             if (isset($tmpParts[1])) {
                 // there is somethings after the /index.php?/
                 if (strpos($tmpParts[1], '?') !== false) {
                     // but this can also have parameters, so only get the path
                     $tmpPathParts = explode('?', $tmpParts[1]);
                     $tmpPath = $tmpPathParts[0];
                 } else {
                     $tmpPath = $tmpParts[1];
                 }
             }
             $path = $tmpParts[0] . '/index.php?/' . $tmpPath;
         } else {
             // there are some query vars, just use the path
             $path = $parts[0];
         }
     } else {
         $path = $route;
     }
     $uri->setPath($path);
 }
Пример #8
0
 function _buildSefRoute(&$uri)
 {
     $sefConfig =& shRouter::shGetConfig();
     $shPageInfo =& shRouter::shPageInfo();
     $menu =& shRouter::shGetMenu();
     // keep a copy of  Joomla original URI, which has article names in it (ie: 43:article-title)
     $originalUri = clone $uri;
     shNormalizeNonSefUri($uri, $menu);
     shNormalizeNonSefUri($originalUri, $menu, $removeSlugs = false);
     // do our job!
     $query = $uri->getQuery(false);
     $route = shSefRelToAbs('index.php?' . $query, null, $uri, $originalUri);
     $route = ltrim(str_replace($GLOBALS['shConfigLiveSite'], '', $route), '/');
     $route = $shPageInfo->base . ($route == '/' ? '' : $route);
     // find path
     if (strpos($route, '?') !== false) {
         $parts = explode('?', $route);
         $path = $parts[0];
     } else {
         $path = $route;
     }
     $uri->setPath($path);
 }