<?php
/**
 * Embed an guestbook
 * 
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Gerry Weißbach <gerry.w@gammaproduction.de>
 */

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');

require_once(dirname(__FILE__).'/'.'basic.class.php');   // settings classes specific to these settings

class syntax_plugin_guestbook extends DokuWiki_Syntax_Plugin {
    /**
     * return some info
     */
    function getInfo(){
        return array(
            'author' => 'Gerry Wei&szlig;bach',
            'email'  => 'gerry.w@gammaproduction.de',
            'date'   => '2006-01-28',
            'name'   => 'guestbook Plugin',
            'desc'   => 'Shows up a guestbook, editable from adminarea 
            			Syntax: {{guestbook}}',
            'url'    => 'http://wiki.gammaproduction.de/dokuwiki/plugins/guestbook',
        );
    }

    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'disabled'; //substition';
    }
   
    /**
     * What about paragraphs?
     */
    function getPType(){
        return 'block'; //container';
    }

    /**
     * Where to sort in?
     */ 
    function getSort(){
        return 301;
    }


    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
        $this->Lexer->addSpecialPattern('\{\{guestbook\}\}',$mode, 'plugin_guestbook');
    }


    /**
     * Handle the match
     */
    function handle($match, $state, $pos, &$handler){

			return 1;
    }

    /**
     * Create output
     */
    function render($mode, &$renderer, $data) {

       	$renderer->info['cache'] = FALSE;
        if($mode == 'xhtml'){
						$guestbook = new guestbook();

		      	$renderer->doc .= '<div id="guestbook">';

						if (!empty($_POST['newEntry']))
						{
							$renderer->doc .= $guestbook->newEntry($this);
						}
		    		if(!empty($_POST['createEntry']))
							$renderer->doc .= $guestbook->form($this, intval($_POST['guestEdit']));
						else
						{
            	$renderer->doc .= $guestbook->html($this);
            }

					  $renderer->doc .= '</div>';

            return true;
        }
        return false;
    }
    
}

//Setup VIM: ex: et ts=4 enc=utf-8 :
