1<?php 2/** 3 * Flattr Plugin 4 * 5 * Inserts a flattr button into the current wikipage 6 * 7 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 8 * @author Gina Haeussge <osd@foosel.net> 9 */ 10 11if (!defined('DOKU_INC')) 12 define('DOKU_INC', realpath(dirname(__FILE__) . '/../../') . '/'); 13if (!defined('DOKU_PLUGIN')) 14 define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 15require_once (DOKU_PLUGIN . 'syntax.php'); 16require_once (DOKU_INC . 'inc/template.php'); 17require_once (DOKU_INC . 'inc/pageutils.php'); 18 19class syntax_plugin_flattr extends DokuWiki_Syntax_Plugin { 20 21 function getType() { 22 return 'substition'; 23 } 24 25 function getPType() { 26 return 'block'; 27 } 28 29 function getSort() { 30 return 124; 31 } 32 33 function connectTo($mode) { 34 $this->Lexer->addSpecialPattern('<flattr>.*?</flattr>', $mode, 'plugin_flattr'); 35 $this->Lexer->addSpecialPattern('<flattr\s*/>', $mode, 'plugin_flattr'); 36 } 37 38 function handle($match, $state, $pos, Doku_Handler $handler) { 39 // do not allow the syntax in comments 40 if (isset($_REQUEST['comment'])) 41 return false; 42 43 $params = array(); 44 $match = trim($match); 45 46 //~~ parse the long syntax if given 47 $helper =& plugin_load('helper', 'flattr'); 48 if (substr($match, 0, 8) == '<flattr>') { 49 $lines = explode("\n", substr($match, 8, -9)); 50 if (trim($lines[0]) === '') 51 array_shift($lines); 52 if (trim($lines[-1]) === '') 53 array_pop($lines); 54 55 foreach ($lines as $line) { 56 $line = trim($line); 57 list($name, $value) = explode('=', $line, 2); 58 $name = trim(strtolower($name)); 59 $value = trim($value); 60 if (in_array($name, $helper->validParameters)) 61 $params[$name] = $value; 62 } 63 } 64 65 //~~ validation 66 $helper->validateParameters($params); 67 68 return ($params); 69 } 70 71 /** 72 * Renders the flattr button. Currently only XHTML output is supported. 73 * 74 * @param $mode 75 * @param $renderer 76 * @param $indata 77 * @return unknown_type 78 */ 79 function render($mode, Doku_Renderer $renderer, $data) { 80 global $ID; 81 82 $params = $indata; 83 if ($mode == 'xhtml') { 84 //~~ insert default values for empty parameters 85 $helper =& plugin_load('helper', 'flattr'); 86 $helper->insertMissingParameters($params); 87 88 //~~ render 89 $renderer->doc .= $helper->getEmbedCode($params); 90 return true; 91 } 92 } 93} 94 95//Setup VIM: ex: et ts=4 enc=utf-8 : 96