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