<?php
/**
* @version $Id: plgContentBookMarks.php 1.5
* @copyright Joe Guo
* @license GNU/GPLv2,
* @author Joe Guo - http://www.ctoptravel.com
*/
defined( '_JEXEC' ) or  die('Restricted access');
jimport( 'joomla.event.plugin' );


class plgContentSearchTag extends JPlugin
{
	function plgContentSearchTag( &$subject, $params )
		{
		   parent::__construct( $subject, $params );	
		}	
	
	//function onPrepareContent( &$article, &$params )
	function onContentPrepare($context, &$article, &$params, $page=0 )
	
	{	
	  if ((JRequest :: getVar('view')) == 'article'){
        
		  $links = '';
		  $keys = explode( ',', $article->metakey );
		  foreach ($keys as $key) {
		  $key = trim( $key );
        if($key==''){
            continue;
        }
		  if ($key) { 
		       $searchphrase=$this->param('searchphrase');
		       if(!$searchphrase){
                $searchphrase='all';		       
		       }
				 $link="index.php?option=com_search&areas[]=content&searchphrase=".$searchphrase."&searchword=";
				 $link.=urlencode($key);
				 $link=JRoute::_($link);
				 $links.="<a href='".$link."'>".$key."</a>&nbsp;&nbsp;"; 
		  }
		}
		if ($links!=""){
		  $cssStyle=$this->param('cssStyle');
		  if($cssStyle){
		     $article->text.="<div class='".$cssStyle."'>Теги: ". $links ."</div>";
		  }else{
		     $align=$this->param('align');
		     $alignStyle="";
		     if($align!='none'){
		       $alignStyle=" align='".$align."'";
		     }
		     $article->text.="<div ".$alignStyle." style='background-color:#efefef; margin-bottom: 20px;'>Теги: ". $links ."</div>";
		  }
		}
     
    }//end if JRequest
	  return true;
	}
	
	function param($name){
      static $plugin,$pluginParams;
      if (!isset( $plugin )){ 
 	 	  $plugin =& JPluginHelper::getPlugin('content', 'SearchTag');
   	  $pluginParams = new JParameter( $plugin->params );
   	}
   	return $pluginParams->get($name);
 }
	
}
?>
