<?php 
/**
 * @package JTurbo
 * @version 1.5.3
 * @copyright (C) Copyright 2010 CMS Fruit, CMSFruit.com. All rights reserved.
 * @license GNU/GPL http://www.gnu.org/licenses/gpl-3.0.txt

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

if(JRequest::getVar('debug', null, 'get'))
{
    ini_set('display_errors', 'On');
    ini_set('error_reporting', E_ALL);
}

jimport('joomla.plugin.plugin');

class plgSystemJTurbo extends JPlugin
{
    function plgSystemJTurbo( &$subject, $config )
    {
	parent::__construct( $subject, $config );

	jimport('joomla.application.helper');

	$comPath = dirname(JApplicationHelper::getPath('admin', 'com_jturbo'));
	$settingsPath = $comPath.DS.'models'.DS.'settings.php';

	if(file_exists($settingsPath)) require_once $settingsPath;
    }

    function onAfterRender()
    {
	jimport('joomla.application.component.model');
	jimport('joomla.application.helper');
	
	$app =& JFactory::getApplication();
	$comPath = JApplicationHelper::getPath('admin', 'com_jturbo');
	
	if($app->getName() != 'site' || JRequest::getVar('do_not_log', null, 'method') || JRequest::getVar('format', null, 'method') == 'raw' || !$comPath)
	{
	    // Do not continue
	    return false;
	}

	$modelPath = dirname($comPath).DS.'models'.DS.'parser.php';

	//  If the parser object was not found, don't continue
	if(!file_exists($modelPath)) return false;
	
	require_once $modelPath;
	
	$parser =& JModel::getInstance('Parser', 'JTurboModel');
	
	$parser->html = JResponse::getBody();
	
	JResponse::setBody( $parser->parse() );
    }
}