<?php
/**
 * -----------------------------------------------------------------------------------------
 * This file provides a skeleton to create a new {@link http://b2evolution.net/ b2evolution}
 * plugin quickly.
 * See also:
 *  - {@link http://manual.b2evolution.net/CreatingPlugin}
 *  - {@link http://doc.b2evolution.net/stable/plugins/Plugin.html}
 * (Delete this first paragraph, of course)
 * -----------------------------------------------------------------------------------------
 *
 * This file implements the FreePHP plugin for {@link http://b2evolution.net/}.
 *
 * @copyright (c)2008 BigSoft Limited - {@link http://www.bigsoft.co.uk/}.
 *
 * @license GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
 *
 * @package plugins
 *
 * @author David Newcomb
 *
 */
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );


/**
 * FreePHP Plugin
 *
 * Like Free HTML but runs the PHP
 *
 * @package plugins
 */
class freephp_plugin extends Plugin
{
    
/**
     * Variables below MUST be overriden by plugin implementations,
     * either in the subclass declaration or in the subclass constructor.
     */
    
var $name 'Free PHP';
    
/**
     * Code, if this is a renderer or pingback plugin.
     */
    
var $code 'freephp';
    var 
$priority 50;
    var 
$version '0.1-dev';
    var 
$author 'http://www.bigsoft.co.uk/';
    var 
$help_url 'http://www.bigsoft.co.uk/projects/b2evolution_plugin_freephp/';
    var 
$group 'widget';

    var 
$apply_rendering 'never';


    
/**
     * Init
     *
     * This gets called after a plugin has been registered/instantiated.
     */
    
function PluginInit( & $params )
    {
        
$this->short_desc $this->T_('Free PHP. Like Free HTML but executing PHP.');
        
$this->long_desc $this->T_('Free PHP. Like Free HTML but with PHP. Be careful what you add!');
    }


    
/**
     * Define settings that the plugin uses/provides.
     */
    
function get_widget_param_definitions$params )
    {
        
$r = array(
                
'freephp_contents' => array(
                    
'label' => T_('PHP source code'),
                    
'note' => T_('PHP source code to be executed'),
                    
'type' => 'textarea',
                    
'rows' => 10,
                    
'cols' => 60,
                    
'defaultvalue' => ''
                
),
            );
        return 
$r;
    }

    
/**
     * Event handler: SkinTag (widget)
     *
     * @param array Associative array of parameters.
     * @return boolean did we display?
     */
    
function SkinTag$params )
    {
        global 
$generating_static$Plugins;

        if( ! empty(
$generating_static) || $Plugins->trigger_event_first_true('CacheIsCollectingContent') )
        { 
// We're not generating static pages nor is a caching plugin collecting the content, so we can display this block
            
return false;
        }

        echo 
$params['block_start'];

        echo eval(
$params['freephp_contents']);

        echo 
$params['block_end'];

        return 
true;
    }


}
?>