1<?php 2// must be run within Dokuwiki 3if(!defined('DOKU_INC')) die(); 4 5if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 6require_once(DOKU_PLUGIN.'syntax.php'); 7 8/** 9 * All DokuWiki plugins to extend the parser/rendering mechanism 10 * need to inherit from this class 11 */ 12class syntax_plugin_tablemath extends DokuWiki_Syntax_Plugin { 13 14 /** 15 * return some info 16 */ 17 function getInfo() { 18 return array( 19 'author' => 'James GuanFeng Lin', 20 'email' => 'guanfenglin@gmail.com', 21 'date' => '2009-08-24', 22 'name' => 'Table Math Plugin', 23 'desc' => 'Enables calculated columns in built in table syntax', 24 'url' => 'https://www.dokuwiki.org/plugin:tablemath', 25 ); 26 } 27 28 function getType() { return 'substition'; } 29 function getSort() { return 1213; } 30 31 /** 32 * Connect pattern to lexer 33 */ 34 function connectTo($mode) { 35 $this->Lexer->addSpecialPattern("~~=[a-zA-Z0-9_]*\([0-9,:]*\)~~", $mode, 'plugin_tablemath'); 36 } 37 38 /** 39 * Handle the match 40 */ 41 function handle($match, $state, $pos, &$handler) { 42 global $ID, $ACT, $INFO; 43 $match = str_replace('~~', '', $match); 44 $match = str_replace('=', '', $match); 45 $tmp = explode('(', $match); 46 if (count($tmp)>1) 47 { 48 $tmp[1] = str_replace(')', '', $tmp[1]); 49 return array('method'=>$tmp[0],'set'=>$tmp[1], 'divid'=>'tm'.rand()); 50 } 51 return array(); 52 } 53 54 function render($mode, &$renderer, $data) { 55 global $INFO, $ID, $conf; 56 if($mode == 'xhtml'){ 57 // get discussion meta file name 58 $renderer->doc .= '<html><div id="'.$data['divid'].'"><script type="text/javascript" defer="defer">tablemath("'.$data['divid'].'","'.$data['method'].'","'.$data['set'].'");</script></div></html>'; 59 return true; 60 } 61 return false; 62 } 63 64}