<?php
/**
 * @version		$Id: example.php 10094 2008-03-02 04:35:10Z instance $
 * @package		Joomla
 * @subpackage	Content
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * See COPYRIGHT.php for copyright notices and details.
 */

// Check to ensure this file is included in Joomla!
defined( '_JEXEC' ) or die( 'Restricted access' );

class plgContentReadMoreLink extends JPlugin
{


	function plgContentReadMoreLink( &$subject, $params )
	{

		parent::__construct( $subject, $params );
	}


	function onBeforeDisplayContent( &$article, &$params, $limitstart )
	{
		global $mainframe;
 		
		if (!empty($article->fulltext)) {
		
  		if ($_GET['view']!='article') {
  		
  		 // Get the article URL from $article->readmorelink not is a good idea
       // Jooma 1.5 don't generate value for readmore_link for some situations
       // like the frontpage
       // Thanks to Goran Stetic for discover this bug.       
	     
       //$route=$article->readmore_link;
       	     
       $route=JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catslug, $article->sectionid));             
       $link="<a href=\"$route\" class=\"readmorelink\">";
  		  		
  		 $article->text=str_ireplace('{readmorelink}', $link, $article->text);
  		 $article->text=str_ireplace('{/readmorelink}', '</a>', $article->text);
  		}
  		else {
  		 $article->text=preg_replace('#{readmorelink}(.*?){/readmorelink}#s', '', $article->text);
  		 $article->text=str_ireplace('{readmorelink}', '', $article->text);
  		 $article->text=str_ireplace('{/readmorelink}', '', $article->text);
      }
  	   				
  	}
  	
  					
	}
	
}
