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;
 }