comp:dilbert
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
comp:dilbert [2009-02-02 21:08] – angelegt werner | comp:dilbert [2013-05-24 10:43] (aktuell) – Github-Link werner | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
+ | ====== DokuWiki: Dilbert Daily Cartoon plugin ====== | ||
+ | Ich versuche, den täglichen Cartoon von Dilbert auf eine [[doku> | ||
+ | |||
+ | Harrharr. Auf der [[http:// | ||
+ | |||
+ | OK, also auf ein Neues. Nach einer Anfrage auf der Mailingliste und einer kurzen Einführung in die Benutzung des FeedParsers in DokuWiki (durch Meister Andi Gohr himself :-)) konnte ich den folgenden (bei mir funktionierenden) Code zusammenstoppeln: | ||
+ | |||
+ | <code php lib/ | ||
+ | <?php | ||
+ | /** | ||
+ | * dilbert plugin: shows the daily cartoon from dilbert.com | ||
+ | **/ | ||
+ | /** | ||
+ | * @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_dilbert extends DokuWiki_Syntax_Plugin { | ||
+ | |||
+ | /** | ||
+ | * return some info | ||
+ | * @return array (hash) with some info about the plugin | ||
+ | **/ | ||
+ | function getInfo() | ||
+ | { | ||
+ | return array( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | 'as shown on http:// | ||
+ | ' | ||
+ | ); | ||
+ | } // function getInfo | ||
+ | |||
+ | /** | ||
+ | * What kind of syntax are we? | ||
+ | * @return string containing the syntax type | ||
+ | **/ | ||
+ | function getType() | ||
+ | { | ||
+ | return ' | ||
+ | } // function getType | ||
+ | |||
+ | /** | ||
+ | * What kind of plugin are we? | ||
+ | * @return string containing the kind of the plugin | ||
+ | **/ | ||
+ | function getPType() | ||
+ | { | ||
+ | return ' | ||
+ | } // function getPType | ||
+ | |||
+ | /** | ||
+ | * Where to sort in? | ||
+ | * @return integer number giving the sort sequence number | ||
+ | **/ | ||
+ | function getSort() | ||
+ | { | ||
+ | return 200; | ||
+ | } // function getSort | ||
+ | |||
+ | /** | ||
+ | * Connect pattern to lexer | ||
+ | **/ | ||
+ | function connectTo($mode) | ||
+ | { | ||
+ | $this-> | ||
+ | } // function connectTo | ||
+ | |||
+ | /** | ||
+ | * Handle the match | ||
+ | * @return an empty array ;-) | ||
+ | **/ | ||
+ | function handle($match, | ||
+ | { | ||
+ | return array(); | ||
+ | } // function handle | ||
+ | |||
+ | /** | ||
+ | * Create output | ||
+ | * @param $mode | ||
+ | | ||
+ | * @param $renderer | ||
+ | * @param $data (not looked at) | ||
+ | * @return true, if rendering happens, false in all other cases | ||
+ | **/ | ||
+ | function render($mode, | ||
+ | { | ||
+ | if ($mode == ' | ||
+ | // we need the SimplePie library | ||
+ | require_once(DOKU_INC . ' | ||
+ | // where to look for the feed: | ||
+ | //$url = ' | ||
+ | $url = ' | ||
+ | // create SimplePie feed parsing object | ||
+ | $feed = new FeedParser(); | ||
+ | // next line is mandatory, since feedburner dislikes simplepie | ||
+ | $feed-> | ||
+ | // point feed to URL | ||
+ | $feed-> | ||
+ | // get data | ||
+ | $feed-> | ||
+ | // ...and mangle^Wmanage it :-) | ||
+ | $feed-> | ||
+ | // we only want the cartoon that was published during last 24 hours | ||
+ | $yesterday = time() - (24 * 60 * 60); | ||
+ | // loop at the items in the feed | ||
+ | foreach ($feed-> | ||
+ | // if the item has been published during the last 24 hours... | ||
+ | if ($item-> | ||
+ | $feedDescription = hsc($item-> | ||
+ | $image | ||
+ | $imageurl | ||
+ | $src = $imageurl; | ||
+ | $title | ||
+ | $align | ||
+ | $width | ||
+ | $height | ||
+ | $cache | ||
+ | $renderer-> | ||
+ | } // if ($item-> | ||
+ | } // foreach ($feed-> | ||
+ | return true; | ||
+ | } // if ($mode == ' | ||
+ | return false; | ||
+ | } // function render | ||
+ | | ||
+ | /** | ||
+ | * taken from esteban on http:// | ||
+ | * Last edited by esteban (23 April 2007 03:06:30) | ||
+ | * | ||
+ | * Get an image | ||
+ | * @return (string) content of image tag in the feed | ||
+ | **/ | ||
+ | function _returnImage($text) | ||
+ | { | ||
+ | $text = html_entity_decode($text, | ||
+ | $pattern = "/< | ||
+ | preg_match($pattern, | ||
+ | $text = $matches[0]; | ||
+ | return urldecode($text); | ||
+ | } // function _returnImage | ||
+ | |||
+ | /** | ||
+ | * taken from esteban on http:// | ||
+ | * Last edited by esteban (23 April 2007 03:06:30) | ||
+ | * | ||
+ | * Filter out image url only | ||
+ | * @return (string) URL of the picture | ||
+ | **/ | ||
+ | function _scrapeImage($text) | ||
+ | { | ||
+ | $pattern = '/ | ||
+ | preg_match($pattern, | ||
+ | $link = $link[1]; | ||
+ | return hsc($link); | ||
+ | } // function _scrapeImage | ||
+ | |||
+ | } // class syntax_plugin_dilbert | ||
+ | |||
+ | //Setup VIM: ex: et ts=4 enc=utf-8 : | ||
+ | |||
+ | </ | ||
+ | |||
+ | Das gibt es seit 2013-02-25 auch als Plugin zum direkten Eingeben in den Plugin-Manager von DokuWiki: https:// |