/** * * Set the currently selected database instance, will be used * for subsequent operations of this helper class, until * another one is selected * * @param string $name name of database instance to select * @throws CliExceptionDefault */ public static function selectDb($name = 'default') { if (empty($name) || empty(self::$_instances[$name])) { throw new Sh404sefExceptionDefault('Trying to select a database that has not been set: ' . $name); } self::$_selected = $name; }
/** * Save a list of meta data as entered by user in backend to the database * * @param string $metaData an array of meta key/meta value from user. Also include nonsef url * @return boolean true on success */ public function save($metaDatas) { $this->_db =& JFactory::getDBO(); $row =& JTable::getInstance($this->_defaultTable, 'Sh404sefTable'); // only save if there is actually some metas data // at least on new records $metas = ''; foreach ($metaDatas as $key => $value) { if ($key != 'meta_id' && (substr($key, 0, 4) == 'meta' || substr($key, 0, 3) == 'fb_' || substr($key, 0, 3) == 'og_' || $key == 'canonical')) { $metas .= $value; } } // if there is no meta data entered, don't save if (!empty($metas) && $metas == SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT . SH404SEF_OPTION_VALUE_USE_DEFAULT) { if (!empty($metaDatas['id'])) { // there is an existing record, meta data was cleared by user, we can delete the record altogether try { Sh404sefHelperDb::delete('#__sh404sef_metas', array('id' => $metaDatas['id'])); return true; } catch (Sh404sefExceptionDefault $e) { $this->setError($e->getMessage()); return false; } } // in any case, don't save anything return true; } $status = true; // load pre-existing values if (!empty($metaDatas['id'])) { $status = $row->load($metaDatas['id']); } // attach incoming data to table object $status = $status && $row->bind($metaDatas); // add language code if missing, except on home page if ($status && $row->newurl != sh404SEF_HOMEPAGE_CODE && !preg_match('/(&|\\?)lang=[a-zA-Z]{2,3}/iU', $row->newurl)) { // no lang string, let's add default $shTemp = explode('-', shGetDefaultLang()); $shLangTemp = $shTemp[0] ? $shTemp[0] : 'en'; $row->newurl .= '&lang=' . $shLangTemp; } // sort url params, except on home page if ($status && $row->newurl != sh404SEF_HOMEPAGE_CODE) { $row->newurl = shSortUrl($row->newurl); } // pre-save checks $status = $status && $row->check(); // save the changes $status = $status && $row->store(); // store error message if (!$status) { $error = $row->getError(); $this->setError($error); } // return true if no error $errors = $this->getError(); return empty($errors); }
/** * Delete a list of aliases from their ids, * passed as params * * @param array of integer $ids the list of aliases id to delete * @return boolean true if success */ public function deleteByIds($ids = array()) { if (empty($ids)) { return false; } try { Sh404sefHelperDb::deleteIn($this->_getTableName(), 'id', $ids, Sh404sefHelperDb::INTEGER); } catch (Sh404sefExceptionDefault $e) { $this->setError('Internal database error # ' . $e->getMessage()); return false; } return true; }
/** * * 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; }
/** * Purge urls from database (and cache) * either all automatic, or according to current * sef url list page select options as stored in * in session * @param unknown_type $type */ public function purge($type = 'auto') { // make sure we use latest user state $this->_updateContextData(); // call the appropriate sub-method to get the db query $methodName = '_getPurgeQuery' . ucfirst($type); if (is_callable(array($this, $methodName))) { $deleteQuery = $this->{$methodName}(); } else { $this->setError('Invalid method call _purge' . $type); return; } // then run the query $this->_db->setQuery($deleteQuery); $this->_db->query(); // store error $error = $this->_db->getErrorNum(); if (!empty($error)) { $this->setError('Internal database error # ' . $error); } // delete from cache : we delete the whole cache anyway, except for 404 pages // which are not in the cache if ($type != '404') { Sh404sefHelperCache::purge(); } // reset limit and limitstart variables, to avoid // issue when displaying again results $this->_setState('limitstart', 0); $this->_setState('limit', 0); // reprocess custom urls, checking there is still at least one per group // of identical SEF url with a rank = 0 // as the "main" url for this group was possibly deleted during the purge $query = 'select ?? from (select * from ?? where ?? <> ? order by ?? asc) as tmp_table group by ??'; $nameQuoted = array('id', '#__sh404sef_urls', 'dateadd', 'rank', 'oldurl'); $quoted = array('0000-00-00'); try { // select custom with lowest rank $customs = Sh404sefHelperDb::queryQuoteOnly($query, $nameQuoted, $quoted)->eLoadResultArray(); // make sure there is at least one of those with rank = 0 if (!empty($customs)) { Sh404sefHelperDb::updateIn('#__sh404sef_urls', array('rank' => 0), 'id', $customs); } } catch (Sh404sefExceptionDefault $e) { $this->setError('Internal database error # ' . $e->getMessage()); } }
/** * Load components * * @access public * @param array exclude an array of component to exclude from result * @return array */ public static function getComponentsList($exclude = array()) { static $components = null; if (is_null($components)) { $db =& JFactory::getDBO(); // exclude some and ourselves $exclude = array_merge(array('com_sh404sef', 'com_joomfish', 'com_falang', 'com_joomsef', 'com_acesef', 'com_admin', 'com_cache', 'com_categories', 'com_checkin', 'com_cpanel', 'com_installer', 'com_languages', 'com_media', 'com_menus', 'com_messages', 'com_modules', 'com_plugins', 'com_templates', 'com_config', 'com_redirect', 'com_users'), $exclude); $where = $db->nameQuote('type') . ' = ? and ' . $db->nameQuote('enabled') . ' = ? and ' . $db->nameQuote('element') . ' <> ? ' . ' and ' . $db->nameQuote('element') . ' not in (' . Sh404sefHelperDb::arrayToQuotedList($exclude) . ')'; $whereData = array('component', 1, ''); try { $components = Sh404sefHelperDb::selectObjectList('#__extensions', array('*'), $where, $whereData, $orderBy = array('name'), $offset = 0, $lines = 0, $key = 'element'); } catch (Sh404sefExceptionDefault $e) { JError::raiseWarning('SOME_ERROR_CODE', "Error loading Components: " . $e->getMessage()); return false; } } return $components; }
/** * 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; }
public static function updateShurls() { $pageInfo =& Sh404sefFactory::getPageInfo(); $sefConfig =& Sh404sefFactory::getConfig(); $pageInfo->shURL = empty($pageInfo->shURL) ? '' : $pageInfo->shURL; if ($sefConfig->enablePageId && !$sefConfig->stopCreatingShurls) { try { jimport('joomla.utilities.string'); $nonSefUrl = JString::ltrim($pageInfo->shCurrentPageNonSef, '/'); $nonSefUrl = shSortURL($nonSefUrl); // make sure we have a language $nonSefUrl = shSetURLVar($nonSefUrl, 'lang', $pageInfo->shMosConfig_shortcode); // remove tracking vars (Google Analytics) $nonSefUrl = Sh404sefHelperGeneral::stripTrackingVarsFromNonSef($nonSefUrl); // try to get the current shURL, if any $shURL = Sh404sefHelperDb::selectResult('#__sh404sef_pageids', array('pageid'), array('newurl' => $nonSefUrl)); // if none, we may have to create one if (empty($shURL)) { $shURL = self::_createShurl($nonSefUrl); } // insert in head and header, if not empty if (!empty($shURL)) { $fullShURL = JString::ltrim($pageInfo->getDefaultLiveSite(), '/') . '/' . $shURL; $document =& JFactory::getDocument(); if ($sefConfig->insertShortlinkTag) { $document->addHeadLink($fullShURL, 'shortlink'); // also add header, especially for HEAD requests JResponse::setHeader('Link', '<' . $fullShURL . '>; rel=shortlink', true); } if ($sefConfig->insertRevCanTag) { $document->addHeadLink($fullShURL, 'canonical', 'rev', array('type' => 'text/html')); } if ($sefConfig->insertAltShorterTag) { $document->addHeadLink($fullShURL, 'alternate shorter'); } // store for reuse $pageInfo->shURL = $shURL; } } catch (Sh404sefExceptionDefault $e) { } } }
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]; }
/** * Main shurl creation. shurl is first created by encoding the next * id in the shurl table, using an 18 characters subset of the alphabet * plus a few digits. These have been selected to avoid risks of * characters confusion. * * There is no check a * */ private function _buildPageId() { $shURL = ''; $nextId = $this->_getNextDBId('#__sh404sef_pageids'); if ($nextId !== false) { $nextId = base_convert(18 + $nextId, 10, 18); for ($c = 0; $c < strlen($nextId); ++$c) { $char = base_convert($nextId[$c], 18, 10); $shURL .= self::$_regular[$char]; } } // now check if this shurl is not an existing // SEF or alias. If so, use the alternate char set // to create a new shurl, and try again. // using alternate char set (instead of simply increasing nextId) // makes sure that next time we try to create a shurl (for next URL) // we won't try something we've already used, making the number of attempts // for each shurl creation grows each time there is a collision try { $attempts = 0; $maxAttempts = 8; // don't need to check for collisions with existing shurls // as we use the next insert id, and code that using a unique char set //however, if we need to modify the shurl because it collides with // an existing SEF url or an alias, we will do so using the alternate // character set, so the new shurl don't risk collision with a regular // shurl but it may then collide with another, previously modified shurl // and so we need to check for shurl collisions when this happens $doneShurl = true; // however, need to check for collisions with regular sef urls and aliases $doneSef = false; $doneAlias = false; // and for bad language $doneClean = false; // prepare user set bad language/exclusion list $sefConfig =& shRouter::shGetConfig(); $sefConfig->shurlBlackList = JString::trim($sefConfig->shurlBlackList); if (empty($sefConfig->shurlBlackList)) { $blackList = array(); } else { if (strpos($sefConfig->shurlBlackList, '|') !== false) { $blackList = explode('|', $sefConfig->shurlBlackList); } else { $blackList = array($sefConfig->shurlBlackList); } } $doneBlackList = false; do { // clean word check: this is an internal bad words list if (!$doneClean) { if (in_array($shURL, self::$_badWords)) { // bad language $attempts++; // build a new shurl, by changing a character // with one from the alternate set $shURL = $this->_getModifiedShurl($shURL); // invalidate shurl and alias check flag, to check again with this new shurl $doneShurl = false; $doneAlias = false; $doneSef = false; $doneBlackList = false; } else { $doneClean = true; } } // user word black list if (!$doneBlackList) { if (in_array($shURL, $blackList)) { // bad language $attempts++; // build a new shurl, by changing a character // with one from the alternate set $shURL = $this->_getModifiedShurl($shURL); // invalidate shurl and alias check flag, to check again with this new shurl $doneShurl = false; $doneAlias = false; $doneSef = false; $doneClean = false; } else { $doneBlackList = true; } } // regular SEF url collision check if (!$doneSef) { $isSEF = (int) Sh404sefHelperDb::count('#__redirection', '*', $this->_db->nameQuote('oldurl') . ' = ? and ' . $this->_db->nameQuote('newurl') . ' <> ?', array($shURL, '')); if (!empty($isSEF)) { // there is already a SEF url like that $attempts++; // build a new shurl, by changing a character // with one from the alternate set $shURL = $this->_getModifiedShurl($shURL); // invalidate shurl and alias check flag, to check again with this new shurl $doneShurl = false; $doneAlias = false; $doneClean = false; $doneBlackList = false; } else { $doneSef = true; } } // previous shurl check if (!$doneShurl) { $isShurl = (int) Sh404sefHelperDb::count('#__sh404sef_pageids', '*', array('pageid' => $shURL, 'type' => Sh404sefHelperGeneral::COM_SH404SEF_URLTYPE_PAGEID)); if (!empty($isShurl)) { // there is already a shurl like that $attempts++; // build a new shurl, by changing a character // with one from the alternate set $shURL = $this->_getModifiedShurl($shURL); // invalidate regular sef and alias check flag, to check again with this new shurl $doneSef = false; $doneAlias = false; $doneClean = false; $doneBlackList = false; } else { $doneShurl = true; } } // alias collision check if (!$doneAlias) { $isAlias = (int) Sh404sefHelperDb::count('#__sh404sef_aliases', '*', array('alias' => $shURL, 'type' => Sh404sefHelperGeneral::COM_SH404SEF_URLTYPE_ALIAS)); if (!empty($isAlias)) { // there is already an alias like that $attempts++; // build a new shurl, by changing a character // with one from the alternate set $shURL = $this->_getModifiedShurl($shURL); // invalidate regular sef and shurl check flag, to check again with this new shurl $doneSef = false; $doneShurl = false; $doneClean = false; $doneBlackList = false; } else { $doneAlias = true; } } } while ((!$doneSef || !$doneAlias || !$doneShurl || !$doneClean || !$doneBlackList) && $attempts < $maxAttempts); } catch (Sh404sefExceptionDefault $e) { } return $shURL; }
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; }
public function getAliasesCount($which = 'auto') { switch (strtolower($which)) { // we want to read all automatic urls (include duplicates) case 'auto': try { $numberOfUrls = Sh404sefHelperDb::count($this->_getTableName(), '*', array('type' => Sh404sefHelperGeneral::COM_SH404SEF_URLTYPE_ALIAS)); } catch (Sh404sefExceptionDefault $e) { $numberofUrls = 0; } break; // we want to read urls as per current selection input fields // ie : component, language, custom, ... // we want to read urls as per current selection input fields // ie : component, language, custom, ... case 'selected': $numberOfUrls = $this->getTotal(); break; default: $numberOfUrls = 0; break; } return intval($numberOfUrls); }
public function check() { //initialize $this->newurl = JString::trim($this->newurl); $this->metadesc = JString::trim($this->metadesc); $this->metakey = JString::trim($this->metakey); $this->metatitle = JString::trim($this->metatitle); $this->metalang = JString::trim($this->metalang); $this->metarobots = JString::trim($this->metarobots); $this->canonical = JString::trim($this->canonical); // Open graph data $this->og_site_name = JString::trim($this->og_site_name); $this->fb_admin_ids = JString::trim($this->fb_admin_ids); $this->og_latitude = JString::trim($this->og_latitude); $this->og_longitude = JString::trim($this->og_longitude); $this->og_street_address = JString::trim($this->og_street_address); $this->og_locality = JString::trim($this->og_locality); $this->og_postal_code = JString::trim($this->og_postal_code); $this->og_region = JString::trim($this->og_region); $this->og_country_name = JString::trim($this->og_country_name); $this->og_email = JString::trim($this->og_email); $this->og_phone_number = JString::trim($this->og_phone_number); $this->og_fax_number = JString::trim($this->og_fax_number); if ($this->newurl == '/') { $this->newurl = sh404SEF_HOMEPAGE_CODE; } // check for valid URLs if ($this->newurl == '') { $this->setError(JText::_('COM_SH404SEF_EMPTYURL')); return false; } if (JString::substr($this->newurl, 0, 9) != 'index.php') { $this->setError(JText::_('COM_SH404SEF_BADURL')); return false; } // check for existing record, even if id is empty. This may happen // in some circumstances, when saving data from popup, ajaxified, dialog boxes if (empty($this->id)) { try { $existingId = Sh404sefHelperDb::selectResult($this->_tbl, 'id', array('newurl' => $this->newurl)); if (!empty($existingId)) { $this->id = $existingId; } } catch (Sh404sefExceptionDefault $e) { } } return true; }
$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)) {
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; }
/** * Delete a list of urls from their ids, * passed as params * Also delete all duplicates * * @param array of integer $ids the list of url id to delete * @return boolean true if success */ public function deleteByIdsWithDuplicates($ids = array()) { if (empty($ids)) { return true; } // build a list of ids to read $whereIds = Sh404sefHelperDb::arrayToIntValList($ids); // read urls and their duplicates $query = 'select r2.id' . ' from `#__redirection` as r1' . ' join `#__redirection` as r2' . ' on r1.`oldurl` = r2.`oldurl`' . ' where r1.' . $this->_db->nameQuote('id') . ' in (' . $whereIds . ')'; // perform query $this->_db->setQuery($query); $urlsIds = $this->_db->loadResultArray(); // now delete urls from db and cache $rows = $this->_getNonSefUrls($urlsIds); if (!empty($rows)) { Sh404sefHelperCache::removeURLFromCache($rows); } // finally, we can simply delete from db by ids try { sh404sefHelperDb::deleteIn('#__redirection', 'id', $urlsIds); } catch (Sh404sefExceptionDefault $e) { $this->setError('Internal database error # ' . $e->getMessage()); } return true; }
/** * Make the url with id = $cid the main url * in case of duplicates. Also set the previous * main url as secondary, swapping their rank * * @param integer $cid */ public function makeMainUrl($cid) { // get this url record $newMain = $this->getById($cid); $error = $this->getError(); if (!empty($error)) { return; } // is this already the main url ? if ($newMain->rank == 0) { return; } // now get the current main url $options = array('rank' => 0, 'oldurl' => $newMain->oldurl); $previousMains = $this->getByAttr($options); try { // if we got it, do the swapping if (!empty($previousMains)) { foreach ($previousMains as $previousMain) { Sh404sefHelperDb::update($this->_getTableName(), array('rank' => $newMain->rank), array('id' => $previousMain->id)); // another thing we have to do is attach any meta data to the new // main url, so that they keep showing. Meta data are attached to // a NON-sef url, which has the benefit of keeping the attachement // whenever sef url creations are modified and sef urls recreated // but require a bit more work in that case Sh404sefHelperDb::update('#__sh404sef_metas', array('newurl' => $newMain->newurl), array('newurl' => $previousMain->newurl)); } } // finally make it the main url Sh404sefHelperDb::update($this->_getTableName(), array('rank' => 0), array('id' => $newMain->id)); } catch (Sh404sefExceptionDefault $e) { $this->setError('Internal database error # ' . $e->getMessage()); } }
/** * Prepare saving of Error documents configuration options set */ private function _saveErrordocs() { // update 404 error page $quoteGPC = get_magic_quotes_gpc(); $shIntroText = empty($_POST) ? '' : ($quoteGPC ? stripslashes($_POST['introtext']) : $_POST['introtext']); try { // is there already a 404 page article? $id = Sh404sefHelperDb::selectResult('#__content', 'id', array('title' => '__404__', 'language' => '*')); if (!empty($id)) { // yes, update it Sh404sefHelperDb::update('#__content', array('introtext' => $shIntroText, 'modified' => date("Y-m-d H:i:s")), array('id' => $id)); } else { $catid = Sh404sefHelperCategories::getSh404sefContentCat(); if (empty($catid)) { $this->setError(JText::_('COM_SH404SEF_CANNOT_SAVE_404_NO_UNCAT')); return; } $contentTable = JTable::getInstance('content'); $content = array('title' => '__404__', 'alias' => '__404__', 'title_alias' => '__404__', 'introtext' => $shIntroText, 'state' => 1, 'catid' => $catid, 'attribs' => '{"menu_image":"-1","show_title":"0","show_section":"0","show_category":"0","show_vote":"0","show_author":"0","show_create_date":"0","show_modify_date":"0","show_pdf_icon":"0","show_print_icon":"0","show_email_icon":"0","pageclass_sfx":""', 'language' => '*'); $saved = $contentTable->save($content); if (!$saved) { $this->setError($contentTable->getError()); } } } catch (Sh404sefExceptionDefault $e) { $this->setError($e->getMEssage()); } // prevent from being added later on to $sefConfig unset($_POST['introtext']); }
/** * Save params, then delete plugin, for all plugins * in a given group * * @param $group the group to be deleted * @return none */ private function _shSaveDeletePluginGroup($group) { $unsafe = array('authentication', 'content', 'editors', 'editors-xtd', 'search', 'system', 'xmlrpc'); if (in_array($group, $unsafe)) { // safety net : we don't want to delete the whole system or content folder return false; } // read list of plugins from db $db =& JFactory::getDBO(); // read plugin param from db try { $pluginList = Sh404sefHelperDb::selectAssocList('#__extensions', array('*'), array('type' => 'plugin', 'folder' => $group)); if (empty($pluginList)) { return true; } // for each plugin foreach ($pluginList as $plugin) { // remove plugin db id unset($plugin['id']); // write everything on disk $this->_shWriteExtensionConfig($plugin['folder'] . '.' . $plugin['element'], array('shConfig' => $plugin)); // now remove plugin details from db Sh404sefHelperDb::delete('#__extensions', array('type' => 'plugin', 'element' => $plugin['element'], 'folder' => $plugin['folder'])); } } catch (Sh404sefExceptionDefault $e) { echo $e->getMessage() . '<br />'; } // now delete the files for the whole group if (JFolder::exists(JPATH_ROOT . DS . 'plugins' . DS . $group)) { JFolder::delete(JPATH_ROOT . DS . 'plugins' . DS . $group); } }