<?php
/**
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Dan Kreiser <dan.kreiser@gmail.com>
 */

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_tline extends DokuWiki_Syntax_Plugin {

    function getInfo() {
        return array(
            'author' => 'Dan Kreiser',
            'email'  => 'dan.kreiser@gmail.com',
            'date'   => '2011-03-01',
            'name'   => 'tline',
            'desc'   => 'Integrate charts with the google charts api',
            'url'    => 'http://www.tux-tips.de/tux-wiki/doku.php?id=start:dokuwiki:plugins',
        );
    }
    /**
     * What kind of syntax are we?
     */
    function getType(){
        return 'substition';
    }

    function getPType(){
        return 'block';
    }

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

    /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
      $this->Lexer->addSpecialPattern('<tline>\n.*?\n</tline>',$mode,'plugin_tline');
    }

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

        // prepare default data
        
		$return=explode("\n",$match);
        return $return;
    }

    /**
     * Create output
     */
    function render($mode, &$R, $data) {
        if($mode != 'xhtml') return false;
	  
	  //$R->doc .= '<img src="'.$url.'&.png" />';
	  $R->doc .='<script src="data/pages/tline/'.$data[1].'.txt" type="text/javascript"></script>';
	  $R->doc .='<div id="tl" class="timeline-default" style="height:'.$data[2].';"></div>';
	  $R->doc .='<a title="tline:'.$data[1].'" class="wikilink1" href="doku.php?id=tline:'.$data[1].'" >Timeline bearbeiten</a>';
  		if ($data[3]=="controls"){
		$R->doc .='<div class="controls" id="controls"></div>';
		}
			return true;

    }
}