comp:userfriendly
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
comp:userfriendly [2009-02-01 1546] – angelegt werner | comp:userfriendly [2009-02-01 1550] (aktuell) – Typos, Link zu Dilbert werner | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== Userfriendly.org Daily Cartoon ====== | ||
+ | Ich mag es, wenn auch mal tagesaktuelle Sachen in einem Wiki auftauchen. Zum Beispiel hatte ich per [[doku> | ||
+ | |||
+ | So habe ich mir denn gedacht, man kann ja mal exemplarisch eine Cartoonseite einbinden. Seite einlesen, URL parsen, im Wiki einbauen, gut is :-) Najagut, Copyright ist zu beachten. Und so wie ich es umgesetzt habe, muss auch in den PHP-Einstellungen beachtet werden, dass die Funktion '' | ||
+ | |||
+ | Hier zeige ich mal den Code, den ich in meinen 4 Wänden benutze -- der also in diesem Wiki nicht aktiv ist, ihr braucht das auf dem [[playground: | ||
+ | |||
+ | <code php> | ||
+ | <?php | ||
+ | /** | ||
+ | * userfriendly plugin: shows the daily cartoon from userfriendly.org | ||
+ | * | ||
+ | /** | ||
+ | * @license | ||
+ | * @author | ||
+ | * @date | ||
+ | */ | ||
+ | |||
+ | if(!defined(' | ||
+ | die(); | ||
+ | if(!defined(' | ||
+ | define(' | ||
+ | require_once(DOKU_PLUGIN . ' | ||
+ | |||
+ | /** | ||
+ | * All DokuWiki plugins to extend the parser/ | ||
+ | * need to inherit from this class | ||
+ | */ | ||
+ | class syntax_plugin_userfriendly extends DokuWiki_Syntax_Plugin { | ||
+ | |||
+ | var $err_sorrynopic = ' | ||
+ | |||
+ | /** | ||
+ | * return some info | ||
+ | */ | ||
+ | function getInfo() | ||
+ | { | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | 'as shown on http:// | ||
+ | ' | ||
+ | ); | ||
+ | } // function getInfo | ||
+ | |||
+ | /** | ||
+ | * What kind of syntax are we? | ||
+ | */ | ||
+ | function getType() | ||
+ | { | ||
+ | return ' | ||
+ | } // function getType | ||
+ | |||
+ | /** | ||
+ | * What kind of plugin are we? | ||
+ | */ | ||
+ | function getPType() | ||
+ | { | ||
+ | return ' | ||
+ | } // function getPType | ||
+ | |||
+ | /** | ||
+ | * Where to sort in? | ||
+ | */ | ||
+ | function getSort() | ||
+ | { | ||
+ | return 200; | ||
+ | } // function getSort | ||
+ | |||
+ | /** | ||
+ | * Connect pattern to lexer | ||
+ | */ | ||
+ | function connectTo($mode) | ||
+ | { | ||
+ | $this-> | ||
+ | | ||
+ | } // function connectTo | ||
+ | |||
+ | /** | ||
+ | * Handle the match | ||
+ | */ | ||
+ | function handle($match, | ||
+ | { | ||
+ | return array(); | ||
+ | } // function handle | ||
+ | |||
+ | /** | ||
+ | * Allow plugin types | ||
+ | */ | ||
+ | function getAllowedTypes() | ||
+ | { | ||
+ | return array(' | ||
+ | } // function getAllowedTypes | ||
+ | |||
+ | /** | ||
+ | * Create output | ||
+ | | ||
+ | (see http:// | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | */ | ||
+ | function render($mode, | ||
+ | { | ||
+ | if ($mode == ' | ||
+ | $pagearr = file(" | ||
+ | if (!is_array($pagearr)) | ||
+ | return -1; | ||
+ | foreach ($pagearr as $line) { | ||
+ | if (substr($line, | ||
+ | $srcpos = strpos($line, | ||
+ | $srclen = strlen($line) - $srcpos - 10; | ||
+ | $picid = substr($line, | ||
+ | $linkstart = '<a href=" | ||
+ | $imgalt | ||
+ | } // if URL in this line | ||
+ | } // foreach ($pagearr as $line) | ||
+ | if ( (strlen($picid) == 0) ) | ||
+ | $renderer-> | ||
+ | // $renderer-> | ||
+ | if (!function_exists(' | ||
+ | require_once(DOKU_INC . ' | ||
+ | $picid | ||
+ | $instruc = p_get_instructions(' | ||
+ | $myinfo | ||
+ | $retval | ||
+ | // echo htmlentities($retval); | ||
+ | $renderer-> | ||
+ | return true; | ||
+ | } // if ($mode == ' | ||
+ | return false; | ||
+ | } // function render | ||
+ | |||
+ | |||
+ | } // class syntax_plugin_userfriendly | ||
+ | |||
+ | //Setup VIM: ex: et ts=4 enc=utf-8 : | ||
+ | </ | ||
+ | |||
+ | So, und wenn ich auf eine Seite den Ausdruck schreibe, den ich in der Funktion '' | ||
+ | |||
+ | Der Code ist noch verbesserungswürdig. So könnte ich zum Parsen der Seite reguläre Ausdrücke benutzen und/oder könnte alles den Funktionen von '' |