1<?php
2/**
3 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
4 * @author     Jonas Fourquier <jonas@tuxfamily.org>
5 */
6
7if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
8if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
9require_once(DOKU_PLUGIN.'syntax.php');
10
11
12class syntax_plugin_page4release extends DokuWiki_Syntax_Plugin {
13
14    function getType(){
15        return 'substition';
16    }
17    function getPType() {
18        return 'block';
19    }
20
21    function getInfo(){
22        return confToHash(dirname(__FILE__).'/info.txt');
23    }
24
25    function getSort(){
26        return 305;
27    }
28
29    function connectTo($mode) {
30        global $ID;
31        p_set_metadata($ID, array('page4release'=>False), False, True);
32        $this->Lexer->addSpecialPattern('\{\{for .*?\}\}',$mode,'plugin_page4release');
33        $this->Lexer->addSpecialPattern('\{\{pour .*?\}\}',$mode,'plugin_page4release');
34    }
35
36    function handle($match, $state, $pos, &$handler) {
37        if (substr($match,2,3) == 'for')
38            return trim(substr($match,6,-2));
39        elseif (substr($match,2,4) == 'pour')
40            return trim(substr($match,6,-2));
41    }
42
43    function render($mode, &$renderer, $data) {
44        global $conf,$ACT, $ID;
45        if($mode == 'xhtml') {
46            $INFO = pageinfo();
47            $release = $data;
48            $linkOtherReleases = array();
49            $page4release = unserialize(io_readFile($conf['indexdir'].'/page4release.idx', false));
50            $filename = array_pop(explode(':',$ID));
51            if (isset($page4release[$filename])) {
52                foreach ($page4release[$filename] as $otherId=>$otherRelease) {
53                    if ($otherId != $ID)
54                        $linkOtherReleases[] = '<a class="wikilink1" href="'.wl($otherId).'">'.$otherRelease.'</a>';
55                }
56            }
57            $doc = '<div class="page4release">';
58            if ($release)
59                $doc .= $this->getLang('pageFor').' <span class="active_page4release">'.$release.'</span>. ';
60            if (!empty($linkOtherReleases))
61                $doc .= $this->getLang('pageForOther').join(', ',$linkOtherReleases);
62            $doc .= '</div>';
63            $renderer->doc .= $doc;
64            return true;
65        } elseif ($mode == 'metadata' && $ACT != 'preview' && !$REV) {
66            p_set_metadata($ID, array('page4release'=>$data), False, True);
67            return true;
68        }
69        return false;
70    }
71}
72?>
73