1<?php
2
3if(!defined('DOKU_INC')) die();
4
5class action_plugin_publish_recent extends DokuWiki_Action_Plugin {
6
7    /**
8     * @var helper_plugin_publish
9     */
10    private $hlp;
11
12    function __construct() {
13        $this->hlp = plugin_load('helper','publish');
14    }
15
16    function register(Doku_Event_Handler $controller) {
17        $controller->register_hook('HTML_RECENTFORM_OUTPUT', 'BEFORE', $this, 'handle_recent', array());
18    }
19
20    function handle_recent(Doku_Event &$event, $param) {
21        if (!$this->hlp->isActive()) {
22            return;
23        }
24
25        $render = $event->data->_content;
26
27        $parent = null;
28        foreach ($render as $id => $element) {
29
30            if ($this->isParentTag($element)) {
31                $parent = $id;
32                continue;
33            }
34
35            if ($parent === null) {
36                continue;
37            }
38
39            $id = $this->getPageId($element);
40            if (!$id) {
41                continue;
42            }
43
44            if ($this->hlp->isCurrentRevisionApproved($id)) {
45                $event->data->_content[$parent]['class'] .= ' approved_revision';
46            } else {
47                $event->data->_content[$parent]['class'] .= ' unapproved_revision';
48            }
49            $parent = null;
50        }
51        return true;
52    }
53
54    function isParentTag($tag) {
55        if (!isset($tag['_elem']) || $tag['_elem'] !== 'opentag') {
56            return false;
57        }
58
59        if (!isset($tag['_tag']) || $tag['_tag'] !== 'div') {
60            return false;
61        }
62
63        return (isset($tag['class']) && $tag['class'] === 'li');
64    }
65
66    function getPageId($tag) {
67        if (!is_string($tag)) {
68            return false;
69        }
70
71        $match = array();
72        if (!preg_match('/<a href=".*" class="wikilink1" title="(.*)">.*/i', $tag, $match)) {
73            return false;
74        }
75
76        return $match[1];
77    }
78
79}
80