<?php

    // -- plugin manager stuff
	include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
    // -- for the public side action
	include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
    include_once( PLOG_CLASS_PATH."class/view/errorview.class.php" );
    // -- for the admin side action
    include_once( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
    include_once( PLOG_CLASS_PATH."class/view/admin/adminerrorview.class.php" );
    
    // -------------------
    //
    // very simple example of an action that is registered by the plugin
    //
    // -------------------
    class PluginHelloWorldAdminAction extends AdminAction
    {
        function PluginHelloWorldAdminAction( $actionInfo, $request ) 
        {
            $this->AdminAction( $actionInfo, $request );
        }
        
        function perform()
        {
            $this->_view = new AdminErrorView( $this->_blogInfo );
            $this->_view->setMessage( "I am the PluginHelloWorldAction and I am quitting the whole thing from the admin interface :)" );
            $this->setCommonData();
        }
    }

    // -------------------
    //
    // very simple example of an *admin* action that is registered by the plugin
    //
    // -------------------    
    class PluginHelloWorldAction extends BlogAction
    {
        function PluginHelloWorldAction( $actionInfo, $request ) 
        {
            $this->BlogAction( $actionInfo, $request );
        }
        
        function perform()
        {
            $this->_view = new ErrorView( $this->_blogInfo );
            $this->_view->setValue( "message", "I am the PluginHelloWorldAction and I am quitting the whole thing :)" );
            $this->setCommonData();
        }
    }
    
    // -------------------
    //
    // very simple example of an filter for the pipeline that is registered by the plugin
    //
    // -------------------
    class PluginHelloWorldTestFilter extends PipelineFilter
    {
        function PluginHelloWorldTestFilter( $pipelineRequest ) 
        {
            $this->PipelineFilter( $pipelineRequest );
        }
        
        //
        // like any other filter, we have to implement the filter() method and do whatever we would
        // like to do there, as a filter
        //
        function filter()
        {
            // check for a certain parameter in the url
            $pipelineRequest = $this->getPipelineRequest();
            $httpRequest = $pipelineRequest->getHttpRequest();
            if( $httpRequest->getValue( "block" ) == "me" ) {
                // if available, cancel the whole thing just to show what kind of things can
                // be done here...
                $result = new PipelineResult( false, 1, "You triggered the easter egg!!" );
            }
            else
                $result = new PipelineResult( true );
                
            return $result;
        }
    }
	
    /**
     * Implementation of a very simple plugin file.
     */
    class PluginHelloWorld extends PluginBase 
    {

    	function PluginHelloWorld()
        {
        	$this->PluginBase();

            $this->desc    = "This is a very simple plugin to show how to develop custom plugins";
            $this->author  = "The LifeType team";
            $this->id      = "helloworld";
			$this->locales = Array();
            
            // register a sample action for the public side        
            $this->registerBlogAction( "test", "PluginHelloWorldAction" );
            // register a simple action for the admin side and add a link to it
            $this->registerAdminAction( "testAdmin", "PluginHelloWorldAdminAction" );
            $this->addMenuEntry( "/menu/Manage/manageLinks", "testAction", "admin.php?op=testAdmin", "PluginHelloWorld Sample Action" );
            // and register a sample pipeline filter
            $this->registerFilter( "PluginHelloWorldTestFilter" );
			
			// register an event
			$this->registerNotification( EVENT_POST_LOADED, "MyTestEventPlugin" );
        }
		
		function process( $eventType, $params )
		{			
			// return the content as it came, as the caller class probably expected us to do
			// something with it...
			return $params;
		}		
        
        function sayHello()
        {
        	return( "Hello, world!" );
        }
    }
?>