====== Daily Cartoon ====== I want the daily cartoon of userfriendly.org show up on one of my wiki pages. Since it has another URL every day, I try to do it via a syntax plugin. Unfortunately, everything works fine on preview, but the page is garbled after saving :-( You can reproduce this when you save the code in a file named ''syntax.php'' in the ''lib/plugins/userfriendly'' directory of your DokuWiki installation. Then, place ''{~userfriendly~}'' in the page text (I have it on a separate line with one blank line above and one underneath) and see... Here's the code, maybe you can give [[w.flamme@web.de|me]] some hints what I am doing wrong. * @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 { /** * 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://wiki.splitbrain.org/doku.php?id=plugin: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 300; } // 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 /** * Create output @param $mode current mode of DokuWiki (see http://wiki.splitbrain.org/plugin:tutorial) @param $renderer DokuWiki's rendering object @param $data the data between '\' tags (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 $imgalt constant expression for the alt attribute of the img tag @var $myPrep the text prepared to output @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 .= "

{$linkstart}This was *YOUR* link here.

\n"; $myPrep = '

' . '' . $imgalt .
                      '

'. "\n"; // debug line $renderer->doc .= "\n

" . htmlentities($myPrep) . '

'; // the next line causes the strange behaviour // $renderer->doc .= "\n" . $myPrep; return true; } // if ($mode == 'xhtml') return false; } // function render } // class syntax_plugin_userfriendly //Setup VIM: ex: et ts=4 enc=utf-8 :