예제 #1
0
 /**
  *
  * Get details of the "Uncategorized" category for a given extension,
  * storing the result in a cache variable
  *
  * @param string $extension full name of extension, ie "com_content"
  */
 public static function getSh404sefContentCat()
 {
     // if not already in cache
     if (is_null(self::$_sh404sefContentCat)) {
         try {
             // read details from database
             self::$_sh404sefContentCat = Sh404sefHelperDb::selectObject('#__categories', '*', array('parent_id' => 1, 'extension' => 'com_content', 'path' => 'sh404sef-custom-content', 'level' => 1));
         } catch (Sh404sefExceptionDefault $e) {
             self::$_sh404sefContentCat = null;
         }
     }
     return self::$_sh404sefContentCat;
 }
예제 #2
0
 /**
  * Fetch a non-sef url directly from database
  *
  * @param string $sefUrl the sefurl we are searching a non sef for
  * @param string $nonSefUrl will be set to non sef url found
  * @return integer code, either none found, or the url pair type: custom or automatic
  */
 public function getNonSefUrlFromDatabase(&$sefUrl, &$nonSefUrl)
 {
     try {
         $result = Sh404sefHelperDb::selectObject($this->_getTableName(), array('oldurl', 'newurl', 'dateadd'), array('oldurl' => $sefUrl), array(), $orderBy = array('rank'));
     } catch (Sh404sefExceptionDefault $e) {
         return sh404SEF_URLTYPE_NONE;
     }
     if (empty($result->newurl)) {
         // no match, that's a 404 for us
         return sh404SEF_URLTYPE_404;
     }
     // found it
     $nonSefUrl = $result->newurl;
     // also adjust sefurl, as the one we have found in db might have a different case from original
     $sefUrl = $result->oldurl;
     // return code: either custom or automatic url
     return $result->dateadd == '0000-00-00' ? sh404SEF_URLTYPE_AUTO : sh404SEF_URLTYPE_CUSTOM;
 }
예제 #3
0
 public function getArticle($id)
 {
     // sanitize input
     $id = intval($id);
     if (empty($id)) {
         throw new Sh404sefExceptionDefault('Invalid article id passed to ' . __METHOD__ . ' in ' . __CLASS__, 500);
     }
     // already cached ?
     if (empty(self::$_articles[$id])) {
         // read details about the article
         $article = Sh404sefHelperDb::selectObject('#__content', array('id', 'title', 'alias', 'catid', 'language'), array('id' => $id));
         // if not found, that's bad
         if (empty($article)) {
             throw new Sh404sefExceptionDefault('Non existing article id (' . $id . ') passed to ' . __METHOD__ . ' in ' . __CLASS__, 500);
         }
         // store our cached record
         self::$_articles[$id][$article->language] = $article;
     }
     return self::$_articles[$id];
 }
예제 #4
0
 function shGetCustomMetaData($nonSef)
 {
     static $_tags;
     if (is_null($_tags)) {
         $_tags = new Sh404sefTableMetas(JFactory::getDbo());
         // now read manually setup tags
         try {
             $data = Sh404sefHelperDb::selectObject('#__sh404sef_metas', '*', array('newurl' => $nonSef));
         } catch (Sh404sefExceptionDefault $e) {
         }
         if (!empty($data)) {
             $_tags->bind($data);
         }
     }
     return $_tags;
 }
예제 #5
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;
 }
예제 #6
0
$catid = isset($catid) ? $catid : null;
// optional prefix
$shWeblinksName = shGetComponentPrefix($option);
if (!empty($shWeblinksName) && $shWeblinksName != '/') {
    $title[] = $shWeblinksName;
}
// joomla content models
$slugsModel = Sh404sefModelSlugs::getInstance();
$menuItemTitle = getMenuTitle(null, $view, isset($Itemid) ? $Itemid : null, '', $shLangName);
$uncategorizedPath = $sefConfig->slugForUncategorizedWeblinks == shSEFConfig::COM_SH404SEF_UNCATEGORIZED_EMPTY ? '' : $menuItemTitle;
$slugsArray = array();
if ($task == 'weblink.go') {
    // jumping to link target
    if (!empty($id)) {
        try {
            $weblinkDetails = Sh404sefHelperDb::selectObject('#__weblinks', array('id', 'title', 'catid'), array('id' => $id));
            $slugsArray[] = $weblinkDetails->title;
        } catch (Sh404sefExceptionDefault $e) {
            $weblinksDetails = null;
        }
        if (!empty($weblinkDetails->catid)) {
            try {
                $title = $slugsModel->getCategorySlugArray('com_weblinks', $weblinkDetails->catid, $sefConfig->includeWeblinksCat, $sefConfig->useWeblinksCatAlias, $insertId = false, $uncategorizedPath, $shLangName);
            } catch (Sh404sefExceptionDefault $e) {
            }
            $title[] = '/';
        }
    } else {
        $dosef = false;
    }
    if (!empty($slugsArray)) {