1<?php
2/**
3 * DokuWiki Plugin outdated (Syntax Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Andreas Böhler <dev@aboehler.at>
7 */
8
9
10// must be run within DokuWiki
11if(!defined('DOKU_INC')) die();
12
13
14class syntax_plugin_outdated extends DokuWiki_Syntax_Plugin {
15
16    /**
17     * @var helper_plugin_publish
18     */
19    private $hlp;
20
21    function __construct(){
22        $this->hlp = plugin_load('helper','outdated');
23    }
24
25    function pattern() {
26        return '\{\{outdated>[^}]*\}\}';
27    }
28
29    function getType() {
30        return 'substition';
31    }
32
33    function getSort() {
34        return 150;
35    }
36
37    function PType() {
38        return 'block';
39    }
40
41    function connectTo($mode) {
42        $this->Lexer->addSpecialPattern($this->pattern(),$mode,'plugin_outdated');
43    }
44
45    function handle($match, $state, $pos, Doku_Handler $handler){
46        $options = trim(substr($match,11,-2));
47        $options = explode(',', $options);
48
49        $data = array(
50            'timedelta' => '',
51            'message' => '',
52        );
53
54        foreach($options as $option)
55        {
56            list($key, $val) = explode('=', $option);
57            switch($key) {
58            case 'timedelta':
59                $lastchr = substr($val, -1);
60                $multiplier = 1;
61                switch($lastchr) {
62                case 'd':
63                    $multiplier = 24 * 3600;
64                    break;
65                case 'h':
66                    $multiplier = 3600;
67                    break;
68                case 'y':
69                    $multiplier = 365 * 24 * 3600;
70                    break;
71                }
72                $val = intval(substr($val, 0, -1)) * $multiplier;
73                // fall-through
74            default:
75                $data[$key] = $val;
76            }
77        }
78        return $data;
79    }
80
81    function render($mode, Doku_Renderer $renderer, $data) {
82        global $conf;
83
84        if($mode != 'metadata') {
85            return false;
86        }
87        $renderer->meta['plugin_outdated'] = $data;
88        return true;
89    }
90
91}
92
93
94