function shFetchPostId($show, $option, $shLangName) { if (empty($show)) { return null; } try { $postId = ShlDbHelper::selectResult('#__myblog_permalinks', 'contentid', array('permalink' => $show)); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } return isset($postId) ? $postId : ''; }
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->currentNonSefUrl, '/'); $nonSefUrl = shSortURL($nonSefUrl); // make sure we have a language $nonSefUrl = shSetURLVar($nonSefUrl, 'lang', $pageInfo->currentLanguageShortTag); // remove tracking vars (Google Analytics) $nonSefUrl = Sh404sefHelperGeneral::stripTrackingVarsFromNonSef($nonSefUrl); // try to get the current shURL, if any $shURL = ShlDbHelper::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->getDefaultFrontLiveSite(), '/') . '/' . $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 (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } } }
public function createPageId($sefUrl, $nonSefUrl) { $shURL = ''; if (!$this->_mustCreatePageid($nonSefUrl)) { return $shURL; } jimport('joomla.utilities.string'); $sefUrl = JString::ltrim($sefUrl, '/'); try { if (!empty($sefUrl)) { // check that we don't already have a shURL for the same SEF url, even if non-sef differ $result = (int) ShlDbHelper::count('#__sh404sef_urls', '*', $this->_db->quoteName('oldurl') . ' = ? and ' . $this->_db->quoteName('newurl') . ' <> ?', array($sefUrl, '')); if (!empty($result) && $result > 1) { // we already have a SEF URL, so we must already have a shURL as well return $shURL; } } // check this nonsef url does not already have a shURL $existingShurl = ShlDbHelper::selectResult('#__sh404sef_pageids', 'pageid', array('newurl' => $nonSefUrl)); // there already is a shurl for the same non-sef if (!empty($existingShurl)) { return $existingShurl; } // if we don't already have a shURL, create the new one $shURL = $this->_buildPageId(); if (!empty($shURL)) { // insert in db ShlDbHelper::insert('#__sh404sef_pageids', array('newurl' => $nonSefUrl, 'pageid' => $shURL, 'type' => Sh404sefHelperGeneral::COM_SH404SEF_URLTYPE_PAGEID, 'hits' => 0)); } } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } // don't need to add the pageid to cache, won't be needed when building up the page, //only when decoding incoming url return $shURL; }
/** * Creates a link to the shLib plugin page * @return string */ public static function getShLibPluginLink($xhtml = true) { try { $pluginId = ShlDbHelper::selectResult('#__extensions', array('extension_id'), array('type' => 'plugin', 'element' => 'shlib', 'folder' => 'system')); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', __CLASS__ . '/' . __METHOD__ . '/' . __LINE__ . ': ' . $e->getMessage()); } $link = ''; $pluginId = (int) $pluginId; if (!empty($pluginId)) { $link = 'index.php?option=com_plugins&task=plugin.edit&extension_id=' . $pluginId; } if ($xhtml) { $link = htmlspecialchars($link); } return $link; }
/** * * @param string $url * @param array $title * @param string $task * @param int $limit * @param int $limitstart * @return sefurl */ public static function sefGetLocation($nonSefUrl, &$title, $task = null, $limit = null, $limitstart = null, $langParam = null, $showall = null, $suppressPagination = false) { try { $shPageInfo =& Sh404sefFactory::getPageInfo(); $sefConfig =& Sh404sefFactory::getConfig(); $lang = empty($langParam) ? $shPageInfo->currentLanguageTag : $langParam; // shumisha : try to avoid duplicate content on multilingual sites by always adding &lang=xx to url (stored in DB). // warning : must add &lang=xx only if it does not exists already if (!strpos($nonSefUrl, 'lang=')) { $shSepString = substr($nonSefUrl, -9) == 'index.php' ? '?' : '&'; $nonSefUrl .= $shSepString . 'lang=' . shGetIsoCodeFromName($lang); } // make sure url is consistent $nonSefUrl = str_replace('&', '&', $nonSefUrl); // detect multipage homepage $shMultiPageHomePageFlag = shIsHomepage($nonSefUrl); // get all the slugs ready for being urls bits $tempSefUrl = array(); foreach ($title as $titlestring) { $decodedTitletring = urldecode($titlestring); $tempSefUrl[] = titleToLocation($decodedTitletring); } // now build the URL $tempSefUrl = implode("/", $tempSefUrl); // remove duplicate / $tempSefUrl = ShlSystem_Strings::pr('/\\/{2,}/u', '/', $tempSefUrl); // and truncate to max length, according to param $tempSefUrl = JString::substr($tempSefUrl, 0, sh404SEF_MAX_SEF_URL_LENGTH); // trim to max length V 1.2.4.t // if URL is empty, and unless this is a paginated home page, or home page in non-default language, stop there if (empty($tempSefUrl)) { if ((!shIsMultilingual() || shIsMultilingual() && shIsDefaultlang($lang)) && !$sefConfig->addFile && !$shMultiPageHomePageFlag) { // return ''; } // if location is empty, and not multilingual site, or multilingual, but this is default language, then there is nothing to add to url } // we have a valid SEF url, built with the data ($title) sent // by plugin. Now we want to check if it's already in the db // and add it if not // first, we search the memory cache for the non-sef url // as it is faster than looking up the db $finalSefUrl = ''; $sefUrlType = Sh404sefHelperCache::getSefUrlFromCache($nonSefUrl, $finalSefUrl); // if non-sef was not found in cache - or found, but it was a 404 last time we saw it - // we should continue and try adding it if ($sefUrlType == sh404SEF_URLTYPE_NONE || $sefUrlType == sh404SEF_URLTYPE_404) { $finalSefUrl = false; // non-sef was not found in cache, let's look up the database if ($sefUrlType == sh404SEF_URLTYPE_NONE) { $finalSefUrl = ShlDbHelper::selectResult('#__sh404sef_urls', 'oldurl', array('newurl' => $nonSefUrl)); } // we found the sef url in database, we're done if (!empty($finalSefUrl)) { return $finalSefUrl; } // the non-sef url is not in memory cache, nor in database // that's a new one, we need to finalize its sef (add pagination and language information) // After finalizing it, we'll also check that sef is not in the db // as it can already be there, associated with another non-sef (ie: a duplicate) // Either way we'll add it in the db, but mark it as a duplicate if needed // add pagination information, unless we were instructed by extension plugin not to // find if we should separate pagination info from sef with a / or not if (!empty($tempSefUrl)) { $shSeparator = JString::substr($tempSefUrl, -1) == '/' ? '' : '/'; } else { $shSeparator = ''; } $finalSefUrl = $suppressPagination ? $tempSefUrl : shAddPaginationInfo($limit, $limitstart, $showall, 1, $nonSefUrl, $tempSefUrl, $shSeparator); // v 1.2.4.t // if home page, we don't record anything, just return "home page" if ($shMultiPageHomePageFlag && '/' . $finalSefUrl == $tempSefUrl && (!shIsMultilingual() || shIsMultilingual() && shIsDefaultLang($lang))) { // but this is default language // this is start page of multipage homepage, return home or forced home if (!empty($sefConfig->shForcedHomePage)) { return str_replace($shPageInfo->getDefaultFrontLiveSite() . '/', '', $sefConfig->shForcedHomePage); } else { return ''; } } // add language information // first, remove languages in non-sef, to see if we're on homepage // as handling is sligthly different for homepage $v1 = shCleanUpLang($nonSefUrl); $v2 = shCleanUpLang($shPageInfo->homeLink); if ($v1 == $v2 || $v1 == 'index.php') { // check if this is homepage if (shIsMultilingual() && !shIsDefaultLang($lang)) { // if homepage in not-default-language, then add language code regardless of user settings // as we otherwise would not be able to switch language on the frontpage $finalSefUrl = shGetIsoCodeFromName($lang) . '/'; } else { $finalSefUrl = ''; } } else { // not on homepage, insert lang code based on user setting $option = shGetURLVar($nonSefUrl, 'option', ''); if (shInsertIsoCodeInUrl($option, $lang)) { // insert language code based on param // pass URL lang info, as may not be current lang $finalSefUrl = shGetIsoCodeFromName($lang) . '/' . $finalSefUrl; // must be forced lang, not default } } // after adding pagination part of SEF, and adding language code // the new SEF url is now complete and we can try adding to it cache and db if ($finalSefUrl != '') { $dburl = null; $dbUrlId = null; $nonSefUrlType = sh404SEF_URLTYPE_NONE; // search the memory cache for this new sef if ($sefConfig->shUseURLCache) { $nonSefUrlType = Sh404sefHelperCache::getNonSefUrlFromCache($finalSefUrl, $dburl); } $newMaxRank = 0; // if the new SEF was not found in memory cache, or if it was found but // we're set to record duplicates, we search for it in the database if ($sefConfig->shRecordDuplicates || $nonSefUrlType == sh404SEF_URLTYPE_NONE) { $dbUrlList = ShlDbHelper::selectObjectList('#__sh404sef_urls', array('id', 'newurl', 'rank', 'dateadd'), array('oldurl' => $finalSefUrl), $aWhereData = array(), $orderBy = array('rank')); if (count($dbUrlList) > 0) { $dburl = $dbUrlList[0]->newurl; $dbUrlId = $dbUrlList[0]->id; if (empty($dburl)) { // V 1.2.4.t url was found in DB, but was a 404 $nonSefUrlType = sh404SEF_URLTYPE_404; } else { $newMaxRank = $dbUrlList[count($dbUrlList) - 1]->rank + 1; $nonSefUrlType = $dbUrlList[0]->dateadd == '0000-00-00' ? sh404SEF_URLTYPE_AUTO : sh404SEF_URLTYPE_CUSTOM; } } } if ($nonSefUrlType != sh404SEF_URLTYPE_NONE && $nonSefUrlType != sh404SEF_URLTYPE_404) { // we found the SEF, one or more times in the db, in records which do have a non-sef attached $isDuplicate = $dburl != $nonSefUrl; // This is a duplicate so we must indert it with incremented rank; if (is_null($dburl) || $isDuplicate && $sefConfig->shRecordDuplicates) { // shAddSefUrlToDBAndCache( $nonSefUrl, $finalSefUrl, ($isDuplicate ? $newMaxRank : 0), $nonSefUrlType); $dateAdd = $nonSefUrlType == sh404SEF_URLTYPE_AUTO ? '0000-00-00' : date("Y-m-d"); ShlDbHelper::insert('#__sh404sef_urls', array('oldurl' => $finalSefUrl, 'newurl' => $nonSefUrl, 'rank' => $isDuplicate ? $newMaxRank : 0, 'dateadd' => $dateAdd)); // store new sef/non-sef pair in memory cache Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, $nonSefUrlType); // create shURL : get a shURL model, and ask url creation $model = ShlMvcModel_Base::getInstance('pageids', 'Sh404sefModel'); $model->createPageId($finalSefUrl, $nonSefUrl); } } else { // we haven't found the non-sef/sef pair, but maybe there is a record for // a 404 with that SEF. If so, we will "upgrade" the 404 record to a // normal non-sef/sef pair $dbUrlId = empty($dbUrlId) ? 0 : intval($dbUrlId); if ($sefConfig->shLog404Errors) { if ($nonSefUrlType == sh404SEF_URLTYPE_404 && !empty($dbUrlId)) { // we already have seen that it is a 404 $id = $dbUrlId; } elseif ($nonSefUrlType == sh404SEF_URLTYPE_404) { $id = ShlDbHelper::selectResult('#__sh404sef_urls', 'id', array('oldurl' => $finalSefUrl, 'newurl' => '')); } else { $id = null; } } else { $id = null; // if we are not logging 404 errors, then no need to check for } // previous hit of this page. if (!empty($id)) { // we found a 404 record matching the SEF url just created. We'll update that record // instead of creating a new one // need to update dateadd to 0, as otherwise this sef/non-sef pair will be seen as custom // this makes all such 404 errors 'disappear' from the 404 log, but no other solution ShlDbHelper::updateIn('#__sh404sef_urls', array('newurl' => $nonSefUrl, 'dateadd' => '0000-00-00'), 'id', array($id)); Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, sh404SEF_URLTYPE_AUTO); } else { // standard case: creation of a totally new sef/non-sef pair ShlDbHelper::insert('#__sh404sef_urls', array('oldurl' => $finalSefUrl, 'newurl' => $nonSefUrl, 'rank' => 0, 'dateadd' => '0000-00-00')); // store new sef/non-sef pair in memory cache Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, sh404SEF_URLTYPE_AUTO); // create shURL : get a shURL model, and ask url creation $model = ShlMvcModel_Base::getInstance('pageids', 'Sh404sefModel'); $model->createPageId($finalSefUrl, $nonSefUrl); } } } } } catch (Exception $e) { $finalSefUrl = ''; ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } return $finalSefUrl; }
$title[] = $shCBName; } $title[] = $sh_LANG[$shLangIso]['_SH404SEF_CB_MANAGE_AVATAR']; shRemoveFromGETVarsList('task'); break; } break; case 'emailuser': if ($sefConfig->shInsertCBName) { $title[] = $shCBName; } $title[] = $sh_LANG[$shLangIso]['_SH404SEF_CB_EMAIL_USER']; // add user name if set to do so / user id is in $uid if ($sefConfig->shCBInsertUserName) { try { $result = ShlDbHelper::selectResult('#__users', array(($sefConfig->shCBUseUserPseudo ? 'user' : '') . 'name'), array('id' => $uid)); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } $title[] = empty($result) ? $sh_LANG[$shLangIso]['_SH404SEF_CB_USER'] . $sefConfig->replacement . $uid : ($sefConfig->shCBInsertUserId ? $uid . $sefConfig->replacement . $result : $result); // if name, put ID only if requested shRemoveFromGETVarsList('uid'); } shRemoveFromGETVarsList('task'); break; case 'teamcredits': if ($sefConfig->shInsertCBName) { $title[] = $shCBName; } $title[] = $sh_LANG[$shLangIso]['_SH404SEF_CB_TEAM_CREDITS']; shRemoveFromGETVarsList('task');
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 = ShlDbHelper::selectResult($this->_tbl, 'id', array('newurl' => $this->newurl)); if (!empty($existingId)) { $this->id = $existingId; } } catch (Exception $e) { } } return true; }
/** * Prepare saving of Error documents configuration options set */ private function _saveErrordocs($errorPagecontent) { // update 404 error page $quoteGPC = get_magic_quotes_gpc(); $shIntroText = empty($_POST) ? '' : ($quoteGPC ? stripslashes($errorPagecontent) : $errorPagecontent); try { // is there already a 404 page article? $id = ShlDbHelper::selectResult('#__content', 'id', array('title' => '__404__', 'catid' => Sh404sefHelperCategories::getSh404sefContentCat()->id, 'language' => '*')); if (!empty($id)) { // yes, update it ShlDbHelper::update('#__content', array('introtext' => $shIntroText, 'modified' => date("Y-m-d H:i:s")), array('id' => $id)); } else { $catid = Sh404sefHelperCategories::getSh404sefContentCat()->id; 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 (Exception $e) { $this->setError($e->getMEssage()); } }
/** * Insert into the content database an uncategorized article * which serves as a basis for the 404 error page * Article title is __404__ * Prior to version 1.5.5, the article displayed for 404 errors * was titled 404. The new name ensures users who customized * will keep their old design in the db. They can either reselect it * from the control panel, or customize as well the new __404__ page * @return unknown_type */ private function _shUpdateErrorPage($pageTitle = '__404__') { // do we already have a __404__ article? try { $catid = $this->_getErrorPageCatId(); // we have cat id, try to read article $id = ShlDbHelper::selectResult('#__content', array('id'), array('catid' => $catid, 'title' => $pageTitle)); // if required page is already there, go away if (!empty($id)) { return; } // maybe there's already an error page in the 'uncategorised' category we were using prior to 3.4 // we can move it to the new category $updated = $this->_changeErrorPageCategory(); if ($updated) { return true; } // find about the default page content $lang = JFactory::getLanguage(); $lang->load('com_sh404sef'); // now we can insert the new page content into the db $status = $this->_insertContent($pageTitle, JText::_('COM_SH404SEF_DEF_404_MSG')); return $status; } catch (Exception $e) { $app = JFactory::getApplication(); $app->enqueueMessage('Error: ' . $e->getMessage()); return false; } }
function shKUTopicName($topicid, $option, $shLangIso, $shLangName) { static $topics = array(); $sefConfig =& Sh404sefFactory::getConfig(); if (empty($topicid) || !$sefConfig->shFbInsertMessageSubject) { return ''; } if (class_exists('KunenaForum')) { // Kunena 2.0 support $topic = KunenaForumTopic::getInstance($topicid); $topicsubject = $topic->subject; } elseif (class_exists('KunenaRouter')) { // Kunena 1.6 support if (empty(KunenaRouter::$msgidcache[$topicid])) { try { KunenaRouter::$msgidcache[$topicid] = ShlDbHelper::selectResult('#__kunena_messages', array('subject', 'id'), array('id' => $topicid)); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } } $topicsubject = KunenaRouter::$msgidcache[$topicid]; } else { // Kunena 1.0 / 1.5 support if (empty($topics[$topicid])) { try { $topicDetails = ShlDbHelper::selectObject('#__fb_messages', array('id', 'subject'), array('id' => $topicid)); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } $topics[$topicid] = empty($topicDetails) ? '' : $topicDetails->subject; } $topicsubject = $topics[$topicid]; } // we have a user name $topicstring = empty($topicsubject) ? 't' . $sefConfig->replacement . $topicid : ($sefConfig->shFbInsertMessageId ? $topicid . $sefConfig->replacement : ''); // if name, put ID only if requested $topicstring = $topicstring . (empty($topicsubject) ? '' : $topicsubject); return $topicstring; }
// Tagged = search_by case 'searchby': if (!empty($cf_id) && !empty($value)) { $title[] = $sh_LANG[$shLangIso]['_MT_SEF_SEARCH']; $title[] = shMTGetCustomFieldById($cf_id); $title[] = $value; shRemoveFromGETVarsList('value'); $title[] = '/'; } break; // View All listing from Owner // View All listing from Owner case 'viewowner': if ($sefConfig->shMTreeInsertUserName) { try { $username = ShlDbHelper::selectResult('#__users', array('name'), array('id' => $user_id, 'block' => 0)); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); } } else { $username = ''; } if (!empty($username)) { $title[] = ($sefConfig->shMTreeInsertUserId ? $user_id . $sefConfig->replacement : '') . $username; $title[] = $sh_LANG[$shLangIso]['_MT_SEF_OWNER']; if (isset($user_id)) { shRemoveFromGETVarsList('user_id'); } } // TODO - Does not append further virtual path if username does not exists. mtree.php // should check if user is not block / exists.