1<?php
2/**
3 * lastcomp Plugin: Compare the timestamps of the last modification of two pages
4 *
5 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Hans-Jürgen Schümmer
7 *             adapted from "modcomp Plugin" by Dennis Ploeger
8
9 * Syntax:
10 * ~~LASTCOMP|<page1>~~
11 * or
12 * ~~LASTCOMP|<page1>|<page2>~~
13
14 * Examples:
15 * ~~LASTCOMP|ktg00:m0000068.004.v01~~
16 *            compares the current wiki page with the page 'ktg00:m0000068.004.v01'
17 * ~~LASTCOMP|ktg00:m0000068.004.v01|playground:playground~~
18 *            compares the wiki page 'ktg00:m0000068.004.v01' with the page 'playground:playground'
19 *
20 * Additionally required for the box output:
21 * wrap plugin
22**/
23
24
25if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
26if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
27require_once(DOKU_PLUGIN.'syntax.php');
28
29/**
30 * All DokuWiki plugins to extend the parser/rendering mechanism
31 * need to inherit from this class
32 */
33class syntax_plugin_lastcomp extends DokuWiki_Syntax_Plugin {
34    /**
35     * What kind of syntax are we?
36     */
37    function getType(){
38        return 'substition';
39    }
40    /**
41     * What about paragraphs?
42     */
43    function getPType(){
44        return 'normal';
45    }
46    /**
47     * Where to sort in?
48     */
49    function getSort(){
50        return 160;
51    }
52    /**
53     * Connect pattern to lexer
54     */
55    function connectTo($mode) {
56        $this->Lexer->addSpecialPattern('~~LASTCOMP[^~]*~~',$mode,'plugin_lastcomp');
57    }
58    /**
59     * Handle the match
60     */
61
62	function handle($match, $state, $pos, Doku_Handler $handler){
63
64		global $ID, $INFO, $conf;
65
66		$basis = DOKU_URL . "doku.php?id=";
67
68		// erste Seite auslesen
69		$match = str_replace("~~lastcomp", '', $match);
70		$match = str_replace("~~", '', $match);
71		$typ = explode('|',$match);
72
73		$verz1 = $typ[1];
74		if (!empty($typ[2])) {
75			$verz2 = $typ[2];
76		} else {
77			$verz2 = $ID;
78		}
79
80
81		$id_save = $ID;
82		$ID = $verz1;
83		$tmp_info = pageinfo();
84		$mod1 = $tmp_info['lastmod'];
85		$ID = $id_save;
86
87		$id_save = $ID;
88		$ID = $verz2;
89		$tmp_info = pageinfo();
90		$mod2 = $tmp_info['lastmod'];
91		$ID = $id_save;
92
93
94		$titel1 = substr($verz1,strrpos($verz1,":")+1);
95		$titel2 = substr($verz2,strrpos($verz2,":")+1);
96
97		$link1 = "<a href = $basis.$verz1 title=$titel1>$titel1</a>";
98		$link2 = "<a href = $basis.$verz2 title=$titel2>$titel2</a>";
99
100		$datum1 = strftime($conf['dformat'], $mod1);
101		$datum2 = strftime($conf['dformat'], $mod2);
102
103		$txt1 = $this->getLang('txt1');
104		$txt2 = $this->getLang('txt2');
105		$txt3 = $this->getLang('txt3');
106
107		if ($mod1 > $mod2) {
108			$mod = "<div class='wrap_alert wrap_right';>";
109			$mod .= $txt1 . "<br>'" . $link1 . "' (". $datum1 . ")<br>" . $txt2 . "<br>'" . $link2 . "' (" . $datum2 . ")<br>" . $txt3;
110			$mod .= "</div>";
111		} else {
112			$mod = "<div class='wrap_info wrap_right';>";
113			$mod .= $txt1 . "<br>'" . $link2 . "' (". $datum2 . ")<br>" . $txt2 . "<br>'" . $link1 . "' (". $datum1 . ")";
114			$mod .= "</div>";
115		}
116
117		return $mod;
118	}
119
120    /**
121     * Create output
122     */
123	function render($mode, Doku_Renderer $renderer, $data) {
124		if($mode == 'xhtml'){
125			$renderer->doc .= $data;
126			return true;
127		}
128		return false;
129	}
130
131}
132
133?>
134