1<?php
2/**
3 * Plugin Now: Inserts a timestamp.
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Carlo Perassi <carlo@perassi.org>
7 */
8
9// based on http://wiki.splitbrain.org/plugin:tutorial
10
11// must be run within Dokuwiki
12if (!defined('DOKU_INC')) die();
13
14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
15require_once(DOKU_PLUGIN . 'syntax.php');
16
17/**
18 * All DokuWiki plugins to extend the parser/rendering mechanism
19 * need to inherit from this class
20 */
21class syntax_plugin_dil extends DokuWiki_Syntax_Plugin {
22    function getInfo() {
23        return array(
24        'author'  => 'Carlo Perassi',
25        'email'   => 'carlo@perassi.org',
26        'date'    => '2009-02-09',
27        'name'    => 'dil Plugin',
28        'desc'    => 'It displays the Daily Dilbert. It uses the DilbertDailyStrip RSS feed. - 0.7',
29        'url'     => 'http://perassi.org/2007/07/28/a-dilbert-plugin-for-dokuwiki/'
30        );
31    }
32
33    private function _listhd() {
34        require_once(DOKU_INC . 'inc/HTTPClient.php');
35
36        $url = 'http://feedproxy.google.com/DilbertDailyStrip';
37
38        $ch = new DokuHTTPClient();
39        $piece = $ch->get($url);
40
41        $xml = simplexml_load_string($piece);
42
43        $pre  = 'http://dilbert.com/dyn/str_strip/';
44        $post = '.gif';
45        $a = explode($pre,  (string)$xml->channel->item->description);
46        $b = explode($post, $a[1]);
47
48        $feed_contents .= '<a href="' . $url . '/">' .
49        '<img src="' . $pre . $b[0] . $post . '" alt="DIL"/></a>' .
50        '<a href="http://perassi.org/2007/07/28/a-dilbert-plugin-for-dokuwiki/">dkdil</a>' . "\n";
51
52        return $feed_contents;
53    }
54
55    function connectTo($mode) {
56        $this->Lexer->addSpecialPattern('\[DIL\]', $mode, 'plugin_dil');
57    }
58
59    function getType() { return 'substition'; }
60
61    function getSort() { return 667; }
62
63    function handle($match, $state, $pos, &$handler) {
64        return array($match, $state, $pos);
65    }
66
67    function render($mode, &$renderer, $data) {
68
69        if ($mode == 'xhtml') {
70            $renderer->doc .= $this->_listhd();
71            return true;
72        }
73        return false;
74    }
75}
76