1<?php 2/** 3 * 4 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 5 * @author Dan Kreiser <dan.kreiser@gmail.com> 6 */ 7 8if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 10require_once(DOKU_PLUGIN.'syntax.php'); 11 12 13/** 14 * All DokuWiki plugins to extend the parser/rendering mechanism 15 * need to inherit from this class 16 */ 17class syntax_plugin_googlechart extends DokuWiki_Syntax_Plugin { 18 19 function getInfo() { 20 return array( 21 'author' => 'Dan Kreiser', 22 'email' => 'dan.kreiser@gmail.com', 23 'date' => '2011-03-01', 24 'name' => 'googlecharts', 25 'desc' => 'Integrate charts with the google charts api', 26 'url' => 'http://www.tux-tips.de/tux-wiki/doku.php?id=start:dokuwiki:plugins', 27 ); 28 } 29 /** 30 * What kind of syntax are we? 31 */ 32 function getType(){ 33 return 'substition'; 34 } 35 36 function getPType(){ 37 return 'block'; 38 } 39 40 /** 41 * Where to sort in? 42 */ 43 function getSort(){ 44 return 160; 45 } 46 47 /** 48 * Connect pattern to lexer 49 */ 50 function connectTo($mode) { 51 $this->Lexer->addSpecialPattern('<googlechart>\n.*?\n</googlechart>',$mode,'plugin_googlechart'); 52 } 53 54 /** 55 * Handle the match 56 */ 57 function handle($match, $state, $pos, &$handler){ 58 59 // prepare default data 60 61 $return=explode("\n",$match); 62 return $return; 63 } 64 65 /** 66 * Create output 67 */ 68 function render($mode, &$R, $data) { 69 if($mode != 'xhtml') return false; 70 71 $url = 'http://chart.apis.google.com/chart?'; 72 $index=0; 73 foreach ( $data as $line ) { 74 if($index==0 OR $line=='</googlechart>' ){} 75 else {$url .= $line.'&';} 76 $index++; 77 } 78 $R->doc .= '<img src="'.$url.'&.png" />'; 79 return true; 80 } 81} 82