* @date 2009-01-17 */ if(!defined('DOKU_INC')) die(); 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_userfriendly extends DokuWiki_Syntax_Plugin { var $err_sorrynopic = 'Sorry, no picture found'; /** * return some info */ function getInfo() { return array( 'author' => 'Werner Flamme', 'email' => 'w.flamme@web.de', 'date' => '2009-01-17', 'name' => 'Userfriendly.org Cartoon Plugin', 'desc' => 'Shows the daily cartoon from userfriendly org ' . 'as shown on http://ars.userfriendly.org/cartoons/?id=', 'url' => 'http://www.wernerflamme.name/doku.php?id=comp:userfriendly' ); } // function getInfo /** * What kind of syntax are we? */ function getType() { return 'substition'; } // function getType /** * What kind of plugin are we? */ function getPType() { return 'block'; } // function getPType /** * Where to sort in? */ function getSort() { return 200; } // function getSort /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addSpecialPattern('{~userfriendly~}', $mode, 'plugin_userfriendly'); } // function connectTo /** * Handle the match */ function handle($match, $state, $pos) { return array(); } // function handle /** * Allow plugin types */ function getAllowedTypes() { return array('substition'); } // function getAllowedTypes /** * Create output @param $mode current mode of DokuWiki (see http://wiki.splitbrain.org/plugin:tutorial) @param $renderer DokuWiki's rendering object @param $data (not looked at) @var $pagearr the starting page of userfriendly.org (as array) @var $line that's what $pagearr consists of @var $srcpos position of the line where SRC= starts @var $srclen length of the URL after SRC= @var $picid the URL of the daily cartoon @var $linkstart constant expression to start the link tag with @var $imgstart constant expression to start the img tag with @return true, if rendering happens, false in all other cases */ function render($mode, &$renderer, $data) { if ($mode == 'xhtml') { $pagearr = file("http://userfriendly.org/"); if (!is_array($pagearr)) return -1; foreach ($pagearr as $line) { if (substr($line, 0, 50) == 'doc .= "

{$this->err_sorrynopic}

"; // $renderer->doc .= "

{$linkstart}Hier wäre *IHR* Bild.

\n"; if (!function_exists('p_get_instructions')) require_once(DOKU_INC . 'inc/parserutils.php'); $picid = substr($picid, 1, -1); $instruc = p_get_instructions('[[http://www.userfriendly.org/|{{' . $picid . '}}]]'); $myinfo = array(); $retval = p_render('xhtml', $instruc, $myinfo); // echo htmlentities($retval); $renderer->doc .= $retval; return true; } // if ($mode == 'xhtml') return false; } // function render } // class syntax_plugin_userfriendly //Setup VIM: ex: et ts=4 enc=utf-8 :