Hi
Thanks for your reply
the problem is with RSSEO System Plugin,
the code below is the rsseo.php plugin:
<?php
/**
* @version 1.0.0
* @package RSSEO! 1.0.0
* @copyright (C) 2009 www.rsjoomla.com
* @license GPL, http://www.gnu.org/licenses/gpl-2.0.html
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
/**
* RSSeo system plugin
*/
class plgSystemRsseo extends JPlugin
{
/**
* Constructor
*
* For php4 compatability we must not use the __constructor as a constructor for plugins
* because func_get_args ( void ) returns a copy of all passed arguments NOT references.
* This causes problems with cross-referencing necessary for the observer design pattern.
*
* @access protected
* @param object $subject The object to observe
* @param array $config An array that holds the plugin configuration
* @since 1.0
*/
function plgSystemRsseo( &$subject, $config )
{
parent::__construct( $subject, $config);
// load plugin parameters
$this->_plugin = & JPluginHelper::getPlugin('system', 'rsseo');
$this->_params = new JParameter($this->_plugin->params);
}
/**
* Do something onAfterInitialise
*/
function onAfterInitialise()
{
$db = JFactory::getDBO();
$app =& JFactory::getApplication();
$document =& JFactory::getDocument();
$u =& JURI::getInstance('SERVER');
$config = new JConfig();
$sef = $config->sef;
if($app->getName() == 'site')
{
$genabled = $this->_params->get('enable','0');
$type = $this->_params->get( 'type','google-site-verification');
$gcontent = $this->_params->get( 'content' );
if($genabled == 1)
{
$document->setMetaData($type, $gcontent);
}
$yenabled = $this->_params->get('enabley','0');
$ycontent = $this->_params->get( 'contenty' );
if($yenabled == 1)
{
$document->setMetaData('y_key', $ycontent);
}
$benabled = $this->_params->get('enableb','0');
$bcontent = $this->_params->get( 'contentb' );
if($benabled == 1)
{
$document->setMetaData('msvalidate.01', $bcontent);
}
//get the current url of the page
if($sef == 0)
$curl = $u->getScheme().'://'.$u->getHost().JRequest::getURI();
else $curl = JURI::current();
//load the redirects
$db->setQuery("SELECT * FROM #__rsseo_redirects WHERE published = 1 ");
$redirects = $db->loadObjectList();
//redirect method
foreach($redirects as $redirect)
{
if($this->_getRoute($redirect->RedirectFrom) == $curl )
{
if($redirect->RedirectType == 301)
{
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$this->_getRoute($redirect->RedirectTo));
exit;
} else if ($redirect->RedirectType == 302)
{
header("Location: ".$this->_getRoute($redirect->RedirectTo));
exit;
}
}
}
}
//canonicalization
$enablecan = $this->_params->get('enablecan','0');
$host = $this->_params->get('domain','');
$host = str_replace(array('http://','https://'),'',$host);
if($enablecan == 1 && trim($host) != '')
{
if(@$_SERVER['HTTP_HOST'] == $host || @$_SERVER['SERVER_NAME'] == $host) {
return true;
}
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
$url = $protocol . $host . $_SERVER['REQUEST_URI'];
header("HTTP/1.1 301 Moved Permanently");
header('Location: '. $url);
exit();
}
}
/**
* Do something onAfterDispatch
*/
function onAfterDispatch()
{
$app =& JFactory::getApplication();
$db = JFactory::getDBO();
$doc =& JFactory::getDocument();
$u =& JURI::getInstance('SERVER');
$config = new JConfig();
$sef = $config->sef;
if($app->getName() == 'site')
{
$base = JURI::base();
//see if the auto-crawler option is enabled
$db->setQuery("SELECT ConfigValue FROM #__rsseo_config WHERE ConfigName = 'crawler.enable.auto'");
$enable = $db->loadResult();
if($enable == 1)
{
//get the ignored links
$db->setQuery("SELECT ConfigValue FROM #__rsseo_config WHERE ConfigName = 'crawler.ignore'");
$ignored = $db->loadResult();
$ignored = str_replace("\r",'',$ignored);
$ignored = explode("\n",$ignored);
//get the links of the page requested
if($sef == 0)
{
$curl = $u->getScheme().'://'.$u->getHost().JRequest::getURI();
$linkToCheck = str_replace(array($base,'&'),array('','&'),$curl);
} else
{
//$curl = JURI::current();
$curl = $u->getScheme().'://'.$u->getHost().JRequest::getURI();
$linkToCheck = str_replace(array($base,'&'),array('','&'),$curl);
}
//see if the current page is already crawled
$db->setQuery("SELECT IdPage FROM #__rsseo_pages WHERE PageURL = '".$linkToCheck."'");
$result = $db->loadResult();
//if the page hasn`t been crawled , we crawl it
if(empty($result) && !$this->_is_ignored($linkToCheck, $ignored))
{
$db->setQuery("INSERT INTO #__rsseo_pages SET PageURL = '".$db->getEscaped($linkToCheck)."', PageTitle ='".$db->getEscaped($doc->getTitle())."', PageKeywords ='".$db->getEscaped($doc->getMetaData('keywords'))."', PageDescription = '".$db->getEscaped($doc->getDescription())."', PageSitemap=0, PageCrawled=0, PageLevel = 127");
$db->query();
}
}
//get the current link of the page
if($sef == 1)
{
$db->setQuery("SELECT `published` FROM `#__plugins` WHERE `element` = 'jfrouter' AND `folder` = 'system' ");
$JRouterEnable = $db->loadResult();
// joomfish hack
if(file_exists(JPATH_SITE.DS.'plugins'.DS.'system'.DS.'jfrouter.php') && $JRouterEnable)
{
if($u->getPath()=='/')
$u->setPath('/');
else
$u->setPath("/".JRequest::getVar('lang','en','get')."/".$u->getPath());
$u->delVar("lang");
}
$host = $u->getScheme().'://'.$u->getHost().JRequest::getURI();
$host = str_replace($base,'',$host);
} else
{
$host = $u->getScheme().'://'.$u->getHost().JRequest::getURI();
$host = str_replace($base,'',$host);
$ampHost = str_replace('&','&',$host);
$db->setQuery("SELECT PageURL FROM #__rsseo_pages WHERE PageURL = '".$ampHost."' AND published = 1 LIMIT 1");
$result = $db->loadResult();
if(strpos($result,".php?") === FALSE) $sef_in_db = 1; else $sef_in_db = 0;
if(strpos($host,".php?") === FALSE) $sef_url = 1; else $sef_url = 0;
if($sef_url == 0 && $sef_in_db == 1)
{
$app = &JFactory::getApplication();
$router = &$app->getRouter();
$router->setMode(JROUTER_MODE_SEF);
$root = JURI::root(true);
$host = JRoute::_($host);
$host = str_replace($root,'',$host);
$router->setMode(JROUTER_MODE_RAW);
}
}
if (substr($host, 0, 1) == '/')
$host = substr($host, 1, strlen($host));
//load the page details
$db->setQuery("SELECT IdPage, PageModified, PageTitle , PageKeywords , PageDescription, PageCrawled , PageLevel FROM #__rsseo_pages WHERE PageURL = '".str_replace('&','&',$host)."' AND published = 1 LIMIT 1");
$page = $db->loadObject();
//set the new Title , MetaKeywords , and the Description
if(!empty($page) && (($page->PageCrawled == 1 || $page->PageLevel == 0) || $page->PageModified == 1 ))
{
if(!($page->PageLevel == 0 && $page->PageTitle == null))
{
$doc->setTitle(html_entity_decode($page->PageTitle));
$doc->setMetaData('title',html_entity_decode($page->PageTitle));
$doc->setMetaData('keywords',html_entity_decode($page->PageKeywords));
$doc->setDescription(html_entity_decode($page->PageDescription));
}
}
}
$this->rsseofunction();
}
/**
* Keywords Replacement and Redirect function
*/
function rsseofunction()
{
$app =& JFactory::getApplication();
$db = JFactory::getDBO();
$doc = JFactory::getDocument();
$u =& JURI::getInstance('SERVER');
$config = new JConfig();
$sef = $config->sef;
if($app->getName() == 'site')
{
//get the body of the component
$body = $doc->getBuffer();
$body = !isset($body['component']['']) ? $body : $body['component'][''] ;
$db->setQuery("SELECT ConfigValue FROM #__rsseo_config WHERE ConfigName = 'component.heading'");
$componentHeading = $db->loadResult();
$db->setQuery("SELECT ConfigValue FROM #__rsseo_config WHERE ConfigName = 'content.heading'");
$contentHeading = $db->loadResult();
$CompStartElement = '<'.$componentHeading.'>';
$CompEndElement = '</'.$componentHeading.'>';
$ContStartElement = '<'.$contentHeading.'>';
$ContEndElement = '</'.$contentHeading.'>';
//search for the contentheading and componentheading class
preg_match_all('#<div class="contentheading">(.*?)<\/div>#is', $body, $content);
preg_match_all('#<div class="componentheading">(.*?)<\/div>#is', $body, $component);
$contentCounter = count($content[0]);
$componentCounter = count($component[0]);
//replace the contentheading class
if($contentHeading != '0')
for($i=0;$i<$contentCounter;$i++)
{
$body = str_replace($content[0][$i],$ContStartElement.$content[1][$i].$ContEndElement,$body);
}
//replace the componentheading classa
if($componentHeading != '0')
for($i=0;$i<$componentCounter;$i++)
{
$body = str_replace($component[0][$i],$CompStartElement.$component[1][$i].$CompEndElement,$body);
}
//is the keyword replacement on
$db->setQuery("SELECT ConfigValue FROM #__rsseo_config WHERE ConfigName = 'enable.keyword.replace'");
$enableKeywords = $db->loadResult();
//replace the keywords
if($enableKeywords == 1)
{
//get all the keywords
$db->setQuery("SELECT Keyword , KeywordBold ,KeywordUnderline , KeywordLink FROM #__rsseo_keywords ORDER BY CHAR_LENGTH(Keyword) DESC");
$keywords = $db->loadObjectList();
if(!empty($keywords))
{
//get all the links in the body
preg_match_all('#<a href=\"(.*?)\">(.*?)<\/a>#i', $body, $links);
foreach($links[0] as $i => $link)
{
$body = str_replace($link,'{rsseo '.$i.'}', $body);
}
//replacement of the keywords
foreach($keywords as $keyword)
if(strpos($body, $keyword->Keyword) !== FALSE)
{
$body = $this->keywordReplace($body, $keyword->Keyword, $this->_setOptions($keyword->Keyword,$keyword->KeywordBold,$keyword->KeywordUnderline,$keyword->KeywordLink));
preg_match_all('#<a href=\"(.*?)\">(.*?)<\/a>#i', $body, $links2[$keyword->Keyword]);
if(!empty($links2))
foreach($links2[$keyword->Keyword][0] as $i => $link)
{
$body = str_replace($link,'{rsseo '.md5($keyword->Keyword).' '.$i.'}', $body);
}
}
foreach ($links[0] as $i => $link)
{
$body = str_replace('{rsseo '.$i.'}', $link, $body);
}
foreach ($keywords as $keyword)
if (!empty($links2[$keyword->Keyword][0]))
foreach ($links2[$keyword->Keyword][0] as $i => $link)
$body = str_replace('{rsseo '.md5($keyword->Keyword).' '.$i.'}', $link, $body);
}
}
$doc->setBuffer($body,'component');
}
}
//function for Routing the url
function _getRoute($url)
{
$config = new JConfig();
$sef = $config->sef;
$u =& JURI::getInstance('SERVER');
$host = $u->getScheme().'://'.$u->getHost();
if(strpos($url,".php?") === FALSE) $sef_url = 1; else $sef_url = 0;
if($sef == 1 && $sef_url == 1)
return JURI::root().$url;
else if ($sef == 1 && $sef_url == 0)
return $host.JRoute::_($url);
else if ($sef == 0 && $sef_url == 0)
return JURI::root().$url;
else if ($sef == 0 && $sef_url == 1)
return JURI::root().$url;
}
function _is_ignored($url, $pattern_array)
{
$return = false;
if (is_array($pattern_array))
foreach ($pattern_array as $pattern)
{
$pattern = str_replace('&', '&', $pattern);
$pattern = $this->_transform_string($pattern);
preg_match_all($pattern, $url, $matches);
if (count($matches[0]) > 0)
$return = true;
}
return $return;
}
function _transform_string($string)
{
$string = preg_quote($string, '/');
$string = str_replace(preg_quote('{*}', '/'), '(.*)', $string);
$pattern = '#\\\{(\\\\\?){1,}\\\}#';
preg_match_all($pattern, $string, $matches);
if (count($matches[0]) > 0)
foreach ($matches[0] as $match)
{
$count = count(explode('\?', $match)) - 1;
$string = str_replace($match, '(.){'.$count.'}', $string);
}
return '#'.$string.'#';
}
//add custom tags to the keyword
function _setOptions($text,$bold = '0',$underline = '0',$link = '')
{
if($bold == '1')
{
$startB = '<strong>';
$endB = '</strong>';
} elseif($bold == '2')
{
$startB = '<b>';
$endB = '</b>';
} elseif($bold == '0')
{
$startB = '';
$endB = '';
}
if ($underline == '1')
{
$startU = '<u>';
$endU = '</u>';
} elseif ($underline)
{
$startU = '';
$endU = '';
} else {
$startU = '';
$endU = '';
}
if($link != '' && strpos($link,'http://') !== FALSE)
{
return $startB.$startU.'<a href="'.$link.'" target="_blank">'.$text.'</a>'.$endU.$endB;
} elseif ($link =='' || strpos($link,'http://') === FALSE)
{
return $startB.$startU.$text.$endU.$endB;
}
}
//function to replace the keywords
function keywordReplace($bodyText, $searchTerm, $replaceWith)
{
$db = JFactory::getDBO();
$newText = '';
$i = -1;
$lcSearchTerm = strtolower($searchTerm);
$lcBodyText = strtolower($bodyText);
$db->setQuery("SELECT ConfigValue FROM #__rsseo_config WHERE ConfigName = 'approved.chars'");
$chars = $db->loadResult();
while (strlen($bodyText) > 0) {
//Get index of search term
$i = $this->_indexOf($lcBodyText, $lcSearchTerm, $i+1);
if ($i < 0) {
$newText .= $bodyText;
$bodyText = '';
} else {
// skip anything inside an HTML tag
if (($this->_lastIndexOf($bodyText,">",$i) >= $this->_lastIndexOf($bodyText,"<",$i)))
{
// skip anything inside a <script> or <style> block
if (($this->_lastIndexOf($lcBodyText,"/script>",$i) >= $this->_lastIndexOf($lcBodyText,"<script",$i)) && ($this->_lastIndexOf($lcBodyText,"/style>",$i) >= $this->_lastIndexOf($lcBodyText,"<style",$i)) && ($this->_lastIndexOf($lcBodyText,"/button>",$i) >= $this->_lastIndexOf($lcBodyText,"<button",$i)) && ($this->_lastIndexOf($lcBodyText,"/textarea>",$i) >= $this->_lastIndexOf($lcBodyText,"<textarea",$i)) && ($this->_lastIndexOf($lcBodyText,"/select>",$i) >= $this->_lastIndexOf($lcBodyText,"<select",$i)) && ($this->_lastIndexOf($lcBodyText,"/a>",$i) >= $this->_lastIndexOf($lcBodyText,"<a",$i)) )
{
$word = substr($bodyText, $i - 1, strlen($searchTerm) + 2);
$firstChar = substr($word, 0, 1);
$lastChar = substr($word, -1);
if( (strpos($chars,$firstChar) !== FALSE) && (strpos($chars,$lastChar) !== FALSE))
{
$newText .= substr($bodyText, 0, $i) . $replaceWith;
$bodyText = substr($bodyText, $i+strlen($searchTerm));
$lcBodyText = strtolower($bodyText);
$i = -1;
}
}
}
}
}
return $newText;
}
function _indexOf($text, $search, $i)
{
$return = strpos($text, $search, $i);
if ($return === false)
$return = -1;
return $return;
}
function _lastIndexOf($text, $search, $i)
{
$length = strlen($text);
$i = ($i > 0)?($length - $i):abs($i);
$pos = strpos(strrev($text), strrev($search), $i);
return ($pos === false)? -1 : ( $length - $pos - strlen($search) );
}
}
How can i optimize this code with joomgallery or reverse,
how can i change joomgallery route.php to work with this plug in sir
Thank you in advance