1<?php 2/* 3 * DokuWiki wolframalpha plugin 4 * 2011 Zahno Silvan 5 * Usage: 6 * 7 * {{wolfram>widget_id}} 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the LGNU Lesser General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * LGNU Lesser General Public License for more details. 18 * 19 * You should have received a copy of the LGNU Lesser General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 */ 23 24 25if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 26if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 27require_once(DOKU_PLUGIN.'syntax.php'); 28 29/** 30 * All DokuWiki plugins to extend the parser/rendering mechanism 31 * need to inherit from this class 32 */ 33class syntax_plugin_wolfram extends DokuWiki_Syntax_Plugin { 34 35 /** 36 * return some info 37 */ 38 function getInfo(){ 39 return array( 40 'author' => 'Zahno Silvan', 41 'email' => 'zaswiki@gmail.com', 42 'date' => '2011-10-22', 43 'name' => 'Wolfram Alpha Plugin', 44 'desc' => 'Add Wolfram Alpha Widgets to your Wikipage', 45 'url' => 'http://zawiki.zapto.org/doku.php/tschinz:dw_wolfram', 46 ); 47 } 48 49 /** 50 * What kind of syntax are we? 51 */ 52 function getType(){ 53 return 'substition'; 54 } 55 56 /** 57 * Where to sort in? 58 */ 59 function getSort(){ 60 return 299; 61 } 62 63 64 /** 65 * Connect pattern to lexer 66 */ 67 function connectTo($mode) { 68 $this->Lexer->addSpecialPattern('\{\{wolfram>.*?\}\}',$mode,'plugin_wolfram'); 69 } 70 71 /** 72 * Handle the match 73 */ 74 function handle($match, $state, $pos, &$handler){ 75 switch ($state) { 76 case DOKU_LEXER_ENTER : 77 break; 78 case DOKU_LEXER_MATCHED : 79 break; 80 case DOKU_LEXER_UNMATCHED : 81 break; 82 case DOKU_LEXER_EXIT : 83 break; 84 case DOKU_LEXER_SPECIAL : 85 return $match; 86 break; 87 } 88 return array(); 89 } 90 91 /** 92 * Create output 93 */ 94 function render($mode, &$renderer, $data) { 95 if($mode == 'xhtml'){ 96 // strip {{wolfram> from start 97 $data = substr($data,10); 98 // strip }} from end 99 $data = substr($data,0,-2); 100 $pluginid = $data; 101 102 if (empty($pluginid)) 103 { 104 $renderer->doc .= 'No plugin id value given'; 105 return true; 106 } 107 108 109 $renderer->doc .= '<script type="text/javascript" id="WolframAlphaScript'.$pluginid.'" src="http://www.wolframalpha.com/widget/widget.jsp?id='.$pluginid.'"></script>'; 110 111 return true; 112 } 113 return false; 114 } 115} 116