<?php
/**
 * PHPImplicitNocache plugin: <php> blocks make pages NOCACHE by default
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     B.J. Black <bj@schmong.org>
 */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_phpimplicitnocache extends DokuWiki_Syntax_Plugin {
 
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'B.J. Black',
            'email'  => 'bj@schmong.org',
            'date'   => '2007-11-26',
            'name'   => 'PHPImplicitNocache Plugin',
            'desc'   => 'PHP blocks in a page make it NOCACHE by default',
            'url'    => 'http://wiki.splitbrain.org/plugin:phpimplicitnocache',
        );
    }
 
    function getType(){ return 'protected'; }
    function getAllowedTypes() { return array('protected'); }   
    function getSort(){ return 179; }
    function connectTo($mode) {
        $this->Lexer->addEntryPattern('<php>(?=.*</php>)',$mode,'plugin_phpimplicitnocache');
        $this->Lexer->addEntryPattern('<PHP>(?=.*</PHP>)',$mode,'plugin_phpimplicitnocache');
    }
    function postConnect() {
        $this->Lexer->addExitPattern('</php>','plugin_phpimplicitnocache');
        $this->Lexer->addExitPattern('</PHP>','plugin_phpimplicitnocache');
    }

    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){
        if( $state == DOKU_LEXER_UNMATCHED ) {
            return array($match);
        }
    }
 
    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {
        $renderer->info['cache'] = false;
        if( $mode == 'xhtml' ) {
            ob_start();
            eval($data[0]);
            $renderer->doc .= ob_get_contents();
            ob_end_clean();
        }
        return true;
    }
}
     
//Setup VIM: ex: et ts=4 enc=utf-8 :
