public function __get($name) { switch ($name) { case 'searchEnginesAgents': case 'trackingVars': $remoteConfig = Sh404sefHelperUpdates::getRemoteConfig(false); $prop = '_' . $name; $value = empty($remoteConfig->config[$name]) ? $this->{$prop} : $remoteConfig->config[$name]; return $value; break; case 'windowSizes': case 'modalTitleSizes': case 'metaDataSpecs': $remoteConfig = Sh404sefHelperUpdates::getRemoteConfig(false); $remotes = empty($remoteConfig->config[$name]) ? array() : $remoteConfig->config[$name]; $prop = '_' . $name; $value = array_merge($this->{$prop}, $remotes); return $value; break; default: $prop = '_' . $name; return $this->{$prop}; break; } }
/** * Fix Joomsef manifest files, to force upgrade method * */ protected function _fixManifest() { jimport('joomla.filesystem.file'); // fix original file $source = $this->parent->getPath('source'); $path = $source . DS . $this->_getElement() . '.xml'; $fileContent = JFile::read($path); if (!empty($fileContent)) { $fileContent = str_replace('type="sef_ext"', 'type="sef_ext" method="upgrade"', $fileContent); $defaults = array(); $remoteConfig = Sh404sefHelperUpdates::getRemoteConfig($forced = false); $remotes = empty($remoteConfig->config['joomsef_prefixes']) ? array() : $remoteConfig->config['joomsef_prefixes']; $prefixes = array_unique(array_merge($defaults, $remotes)); foreach ($prefixes as $prefix) { $fileContent = preg_replace('/function\\s*' . preg_quote($prefix) . '\\s*\\(\\s*\\)\\s*\\{/isU', 'function ' . $prefix . '() { return;', $fileContent); } // generic replace $defaultReplaces = array(); $remoteReplaces = empty($remoteConfig->config['joomsef_prefixes']) ? array() : $remoteConfig->config['joomsef_prefixes']; $replaces = array_unique(array_merge($defaultReplaces, $remoteReplaces)); foreach ($replaces as $replace) { $fileContent = preg_replace('/' . $replace['source'] . '/sU', $replace['target'], $fileContent); } // group="seo" is of no use for us, so leave it behind $written = JFile::write($path, $fileContent); } // fix in memory object, by killing it, thus prompting recreation $manifest =& $this->parent->getManifest(); $manifest = null; $manifest =& $this->parent->getManifest(); $this->manifest =& $manifest->document; }
private function _prepareControlPanelData() { $sefConfig =& shRouter::shGetConfig(); $this->assign('sefConfig', $sefConfig); // update information $versionsInfo = Sh404sefHelperUpdates::getUpdatesInfos(); $this->assign('updates', $versionsInfo); // url databases stats $database =& JFactory::getDBO(); $sql = 'SELECT count(*) FROM #__redirection WHERE '; $database->setQuery($sql . "`dateadd` > '0000-00-00' and `newurl` = '' "); // 404 $Count404 = $database->loadResult(); $database->setQuery($sql . "`dateadd` > '0000-00-00' and `newurl` != '' "); // custom $customCount = $database->loadResult(); $database->setQuery($sql . "`dateadd` = '0000-00-00'"); // regular $sefCount = $database->loadResult(); // calculate security stats $default = empty($sefConfig->shSecLastUpdated) ? '- -' : '0'; $this->assign('sefCount', $sefCount); $this->assign('Count404', $Count404); $this->assign('customCount', $customCount); }
/** * Checks whether a request is coming from mobile device * * @return boolean true if current page request is from a known mobile device */ public static function isMobileRequest() { static $isMobile = null; static $defaultRecords = array(array('start' => 0, 'stop' => 0, 'string' => '/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile|o2|opera m(ob|in)i|palm( os)?|p(ixi|re)\\/|plucker|pocket|psp|smartphone|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce; (iemobile|ppc)|xiino/i'), array('start' => 0, 'stop' => 4, 'string' => '/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|e\\-|e\\/|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\\-|2|g)|yas\\-|your|zeto|zte\\-/i')); if (is_null($isMobile)) { jimport('joomla.environment.browser'); $browser =& JBrowser::getInstance(); $isMobile = $browser->get('_mobile'); $userAgent = $browser->get('_lowerAgent'); // detection code adapted from http://detectmobilebrowser.com/ $remoteConfig = Sh404sefHelperUpdates::getRemoteConfig($forced = false); $remotesRecords = empty($remoteConfig->config['mobiledetectionstrings']) ? array() : $remoteConfig->config['mobiledetectionstrings']; $records = empty($remotes) ? $defaultRecords : $remotesRecords; foreach ($records as $record) { $isMobile = $isMobile || (empty($record['stop']) ? preg_match($record['string'], substr($userAgent, $record['start'])) : preg_match($record['string'], substr($userAgent, $record['start'], $record['stop']))); } } return $isMobile; }
/** * Fix Acesef manifest files, so that their * parameters can be displayed in a regular * plugin screen * */ protected function _fixManifest() { jimport('joomla.filesystem.file'); // fix original files $source = $this->parent->getPath('source'); $path = $source . DS . $this->_getElement() . '.xml'; $fileContent = JFile::read($path); if (!empty($fileContent)) { $fileContent = str_replace('group="sef"', '', $fileContent); $fileContent = str_replace('group="url"', '', $fileContent); // group="seo" is of no use for us, so leave it behind $written = JFile::write($path, $fileContent); } $path = $source . DS . $this->_getElement() . '.php'; $fileContent = JFile::read($path); if (!empty($fileContent)) { $defaults = array('_check', '_sh_is_clever', '_viva_acesef', '_i_love_acesef', '_sh_loves_acesef', '_need_acesef', '_a_b_c_acesef'); $remoteConfig = Sh404sefHelperUpdates::getRemoteConfig($forced = false); $remotes = empty($remoteConfig->config['ace_prefixes']) ? array() : $remoteConfig->config['ace_prefixes']; $prefixes = array_unique(array_merge($defaults, $remotes)); foreach ($prefixes as $prefix) { $fileContent = preg_replace('/function\\s*' . preg_quote($prefix) . '\\s*\\(\\s*\\)\\s*\\{/isU', 'function ' . $prefix . '() { return;', $fileContent); } // generic replace $defaultReplaces = array(array('source' => 'die;', 'target' => '')); $remoteReplaces = empty($remoteConfig->config['ace_replaces']) ? array() : $remoteConfig->config['ace_replaces']; $replaces = array_unique(array_merge($defaultReplaces, $remoteReplaces)); foreach ($replaces as $replace) { $fileContent = preg_replace('/' . $replace['source'] . '/sU', $replace['target'], $fileContent); } // write back manifest file $written = JFile::write($path, $fileContent); } // fix in memory object, by killing it, thus prompting recreation $manifest =& $this->parent->getManifest(); $manifest = null; $manifest =& $this->parent->getManifest(); $this->manifest =& $manifest->document; }
function shIsSearchEngine() { // return true if user agant is a search engine static $isSearchEngine = null; static $searchEnginesAgents = array('B-l-i-t-z-B-O-T', 'Baiduspider', 'BlitzBot', 'btbot', 'DiamondBot', 'Exabot', 'FAST Enterprise Crawler', 'FAST-WebCrawler/', 'g2Crawler', 'genieBot', 'Gigabot', 'Girafabot', 'Googlebot', 'ia_archiver', 'ichiro', 'Mediapartners-Google', 'Mnogosearch', 'msnbot', 'MSRBOT', 'Nusearch Spider', 'SearchSight', 'Seekbot', 'sogou spider', 'Speedy Spider', 'Ask Jeeves/Teoma', 'VoilaBot', 'Yahoo!', 'Slurp', 'YahooSeeker', 'YandexBot'); //return true; if (!is_null($isSearchEngine)) { return $isSearchEngine; } else { $isSearchEngine = false; $useragent = empty($_SERVER['HTTP_USER_AGENT']) ? '' : strtolower($_SERVER['HTTP_USER_AGENT']); if (!empty($useragent)) { $remoteConfig = Sh404sefHelperUpdates::getRemoteConfig($forced = false); $remotes = empty($remoteConfig->config['searchenginesagents']) ? array() : $remoteConfig->config['searchenginesagents']; $agents = array_unique(array_merge($searchEnginesAgents, $remotes)); foreach ($agents as $agent) { if (strpos($useragent, strtolower($agent)) !== false) { $isSearchEngine = true; return true; } } } return $isSearchEngine; } }
public function _doCheck() { // if not set to auto check and not forced to do so // when user click on "check updates" button // we don't actually try to get updates info $sefConfig =& Sh404sefFactory::getConfig(); // prepare a default response object $response = new stdClass(); $response->status = true; $response->statusMessage = JText::_('COM_SH404SEF_CLICK_TO_CHECK_UPDATES'); $response->current = 0; $response->note = ''; $response->changelogLink = ''; $response->minVersionToUpgrade = 0; $response->maxVersionToUpgrade = 0; $response->shouldUpdate = false; $response->excludes = array(); // check if allowed to auto check, w/o user clicking on button if (!$sefConfig->autoCheckNewVersion && empty(self::$_forced['updates'])) { return $response; } // get an http client require_once JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_sh404sef' . DS . 'lib' . DS . 'Zend' . DS . 'Http' . DS . 'Client.php'; $hClient = new Sh_Zend_Http_Client(); $hClient->setConfig(array('maxredirects' => 0, 'timeout' => 10)); // find where to call ... $remoteConfig = Sh404sefHelperUpdates::getRemoteConfig($forced = false); // hardcoded default update server $defaultServers = array(array('url' => self::$_endPoint . '/' . self::$_updateFile)); // try to read from remote, central, configuration file $remoteServers = empty($remoteConfig->config['updateservers']) ? array() : $remoteConfig->config['updateservers']; // merge default and remote $servers = array_merge($remoteServers, $defaultServers); // check for urls in both defaults and remote $serverList = array(); foreach ($servers as $server) { $serverList[] = $server['url']; } $serverList = array_unique($serverList); // now iterate over server list, until we find one that responds foreach ($serverList as $server) { $response->status = true; // actually place a call to find about available updates try { $hClient->setUri($server); } catch (Exception $e) { // move to next update server in list $response->status = false; continue; } // request file content $adapters = array('Sh_Zend_Http_Client_Adapter_Curl', 'Sh_Zend_Http_Client_Adapter_Socket'); $rawResponse = null; foreach ($adapters as $adapter) { try { $hClient->setAdapter($adapter); $rawResponse = $hClient->request(); break; } catch (Exception $e) { // need that to be Exception, so as to catche Sh_Zend_Exceptions.. as well // we failed, let's try another method } } // (un)set flag if we have a response if (empty($rawResponse)) { $response->status = false; $msg = 'unknown code'; $response->statusMessage = JText::sprintf('COM_SH404SEF_COULD_NOT_CHECK_FOR_NEW_VERSION', $msg); } else { if (!is_object($rawResponse) || $rawResponse->isError()) { $response->status = false; $msg = method_exists($rawResponse, 'getStatus') ? $rawResponse->getStatus() : 'unknown code'; $response->statusMessage = JText::sprintf('COM_SH404SEF_COULD_NOT_CHECK_FOR_NEW_VERSION', $msg); } else { // communication was fine, check the file type $type = $rawResponse->getHeader('Content-type'); if (strtolower($type) != 'text/xml' && strtolower($type) != 'application/xml') { $response->status = false; $response->statusMessage = JText::sprintf('COM_SH404SEF_COULD_NOT_CHECK_FOR_NEW_VERSION', $rawResponse->getStatus()); } } } // if there was a valid response, break out of // loop over available update servers if ($response->status) { break; } } // if we were not able to contact any update server // return this if (!$response->status) { return $response; } // get an xml object and parse the response $xml =& JFactory::getXMLparser('Simple'); $xml->loadString($rawResponse->getBody()); // into our response object // first version of version check used an xml file that could only hold one // version data set. So we only iterate over the "update" group if it exists if (empty($xml->document->update)) { $response = self::_readUpdateInformation($xml->document, $response); } else { foreach ($xml->document->update as $updateRecord) { $product = $updateRecord->product[0]->data(); // only use if this update record is for us if ($product == self::$_product) { $response = self::_readUpdateInformation($updateRecord, $response); // find if user should update $response = Sh404sefHelperUpdates::_updateRequired($response); // if found an update, break out if ($response->shouldUpdate) { break; } } } } // check if this is a valid information file return $response; }
* @version $Id: mod_sh404sef_cpicon.php 2112 2011-10-24 17:49:42Z silianacom-svn $ */ // no direct access defined('_JEXEC') or die('Restricted access'); // Access check. if (!JFactory::getUser()->authorise('core.manage', 'com_sh404sef')) { return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); } // define path to sh404SEF front and backend dirs require_once JPATH_ROOT . DS . 'administrator' . DS . 'components' . DS . 'com_sh404sef' . DS . 'defines.php'; if (defined('sh404SEF_AUTOLOADER_LOADED')) { $lang =& JFactory::getLanguage(); $app =& JFactory::getApplication(); $document =& JFactory::getDocument(); // is an update available? $versionsInfo = Sh404sefHelperUpdates::getUpdatesInfos(); $updateText = $versionsInfo->shouldUpdate ? '<br /><font color="red">' . JText::_('COM_SH404SEF_UPDATE_REQUIRED') . '</font>' : '<br /><font color="green">' . JText::_('COM_SH404SEF_UPDATE_NOT_REQUIRED') . '</font>'; } else { $updateText = ''; } ?> <div id="cpanel" > <div class="icon-wrapper"> <div class="icon"> <a href="index.php?option=com_sh404sef"><img src="components/com_sh404sef/assets/images/icon-48-analytics.png" title="sh404sef & Analytics" alt="sh404sef & Analytics" /><span>sh404sef & Analytics<?php echo $updateText; ?> </span> </a>
public static function extractTrackingVarsFromNonSef($url, &$existingVars, $keepThem = false) { $remoteConfig = Sh404sefHelperUpdates::getRemoteConfig($forced = false); // hardcoded default tracking vars $defaultTrackingVars = array('utm_source', 'utm_medium', 'utm_term', 'utm_content', 'utm_campaign'); // try to read from remote, central, configuration file $remoteTrackingVars = empty($remoteConfig->config['trackingvars']) ? array() : $remoteConfig->config['trackingvars']; foreach ($remoteTrackingVars as $var) { // collect existing value, if any $value = shGetURLVar($url, $var, null); if (!is_null($value)) { // store extracted value into passed array $existingVars[$var] = $value; } // still remove var from url if (!$keepThem) { $url = shCleanUpVar($url, $var); } } return $url; }
function shIsSearchEngine() { // return true if user agant is a search engine static $isSearchEngine = null; //return true; if (!is_null($isSearchEngine)) { return $isSearchEngine; } else { $isSearchEngine = false; $useragent = empty($_SERVER['HTTP_USER_AGENT']) ? '' : strtolower($_SERVER['HTTP_USER_AGENT']); if (!empty($useragent)) { $remoteConfig = Sh404sefHelperUpdates::getRemoteConfig($forced = false); $remotes = empty($remoteConfig->config['searchenginesagents']) ? array() : $remoteConfig->config['searchenginesagents']; $agents = array_unique(array_merge(Sh404sefFactory::getPConfig()->searchEnginesAgents, $remotes)); foreach ($agents as $agent) { if (strpos($useragent, strtolower($agent)) !== false) { $isSearchEngine = true; return true; } } } return $isSearchEngine; } }
private function _prepareControlPanelData() { $sefConfig = Sh404sefFactory::getConfig(); $this->assign('sefConfig', $sefConfig); // update information $versionsInfo = Sh404sefHelperUpdates::getUpdatesInfos(); $this->assign('updates', $versionsInfo); // url databases stats $database = ShlDbHelper::getDb(); try { $sql = 'SELECT count(*) FROM #__sh404sef_urls WHERE '; $database->setQuery($sql . "`dateadd` > '0000-00-00' and `newurl` = '' "); // 404 $count404 = $database->shlLoadResult(); $database->setQuery($sql . "`dateadd` > '0000-00-00' and `newurl` != '' "); // custom $customCount = $database->shlLoadResult(); $database->setQuery($sql . "`dateadd` = '0000-00-00'"); // regular $sefCount = $database->shlLoadResult(); // calculate security stats $default = empty($sefConfig->shSecLastUpdated) ? '- -' : '0'; } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $sefCount = 0; $count404 = 0; $customCount = 0; } $this->assign('sefCount', $sefCount); $this->assign('Count404', $count404); $this->assign('customCount', $customCount); }
protected function _getAppKey() { static $_key = null; if (is_null($_key)) { $remoteConfig = Sh404sefHelperUpdates::getRemoteConfig($forced = false); $keys = empty($remoteConfig->config['google_analytics_api_keys']) ? $this->_appKeys : $remoteConfig->config['google_analytics_api_keys']; $_key = $keys[mt_rand(0, count($keys) - 1)]; } return $_key; }
private function _doUpdates($tpl) { // get configuration object $sefConfig =& Sh404sefFactory::getConfig(); // push it into to the view $this->assignRef('sefConfig', $sefConfig); // do we force reading updates from server ? $forced = JRequest::getInt('forced', 0); $versionsInfo = Sh404sefHelperUpdates::getUpdatesInfos(!empty($forced)); // push security stats into view $this->assign('updates', $versionsInfo); // push any message $error = $this->getError(); if (empty($error)) { $noMsg = JRequest::getInt('noMsg', 0); if (empty($noMsg)) { $this->assign('message', JText::_('COM_SH404SEF_ELEMENT_SAVED')); } } parent::display($tpl); }
public function _doCheck() { // if not set to auto check and not forced to do so // when user click on "check updates" button // we don't actually try to get updates info $sefConfig =& shRouter::shGetConfig(); // prepare a default response object $response = new stdClass(); $response->status = true; $response->statusMessage = JText16::_('COM_SH404SEF_CLICK_TO_CHECK_UPDATES'); $response->current = 0; $response->note = ''; $response->changelogLink = ''; $response->minVersionToUpgrade = 0; $response->maxVersionToUpgrade = 0; $response->shouldUpdate = false; $response->excludes = array(); // check if allowed to auto check, w/o user clicking on button if (!$sefConfig->autoCheckNewVersion && !self::$_forced) { return $response; } // get an http client require_once JPATH_COMPONENT . DS . 'lib' . DS . 'Zend' . DS . 'Http' . DS . 'Client.php'; $hClient = new Zend_Http_Client(); // set params $hClient->setUri(self::$_endPoint . '/' . self::$_product); $hClient->setConfig(array('maxredirects' => 0, 'timeout' => 10)); // request file content $adapters = array('Zend_Http_Client_Adapter_Curl', 'Zend_Http_Client_Adapter_Socket'); $rawResponse = null; foreach ($adapters as $adapter) { try { $hClient->setAdapter($adapter); $rawResponse = $hClient->request(); break; } catch (Exception $e) { // need that to be Exception, so as to catche Zend_Exceptions.. as well // we failed, let's try another method } } // return if error if (!is_object($rawResponse) || $rawResponse->isError()) { $response->status = false; $msg = method_exists($rawResponse, 'getStatus') ? $rawResponse->getStatus() : 'unknown code'; $response->statusMessage = JText16::sprintf('COM_SH404SEF_COULD_NOT_CHECK_FOR_NEW_VERSION', $msg); return $response; } // check the file $type = $rawResponse->getHeader('Content-type'); if (strtolower($type) != 'text/xml' && strtolower($type) != 'application/xml') { $response->status = false; $response->statusMessage = JText16::sprintf('COM_SH404SEF_COULD_NOT_CHECK_FOR_NEW_VERSION', $rawResponse->getStatus()); return $response; } // should be OK then $response->status = true; // get an xml object and parse the response $xml =& JFactory::getXMLparser('Simple'); $xml->loadString($rawResponse->getBody()); // into our response object $response->current = $xml->document->current[0]->data(); $response->note = $xml->document->note[0]->data(); $response->changelogLink = $xml->document->changelogLink[0]->data(); $response->downloadLink = $xml->document->downloadLink[0]->data(); $response->minVersionToUpgrade = $xml->document->minVersionToUpgrade[0]->data(); $response->maxVersionToUpgrade = $xml->document->maxVersionToUpgrade[0]->data(); $rawExcludes = $xml->document->exclude; $response->excludes = array(); if (!empty($rawExcludes)) { foreach ($rawExcludes as $exclude) { $response->excludes[] = $exclude->data(); } } // find if user should update $response = Sh404sefHelperUpdates::_updateRequired($response); // check if this is a valid information file return $response; }