-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.php
86 lines (75 loc) · 2.2 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* DokuWiki Plugin starred (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <andi@splitbrain.org>
*/
/**
* Class action_plugin_starred
*/
class action_plugin_starred extends DokuWiki_Action_Plugin
{
/** @var helper_plugin_starred */
protected $helper;
/**
* action_plugin_starred constructor.
*/
public function __construct()
{
$this->helper = plugin_load('helper', 'starred');
}
/** @inheritdoc */
public function register(Doku_Event_Handler $controller)
{
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_unknown');
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action_act_preprocess');
}
/**
* Handle the ajax call
*
* @param Doku_Event $event AJAX_CALL_UNKNOWN
* @param $param
*/
public function handle_ajax_call_unknown(Doku_Event $event, $param)
{
if ($event->data != 'startoggle') return;
global $ID;
global $INPUT;
$ID = cleanID($INPUT->str('id'));
$this->helper->toggleStar();
$this->tpl_starred(true);
$event->preventDefault();
$event->stopPropagation();
}
/**
* Handle the non-ajax call
*
* @param Doku_Event $event ACTION_ACT_PREPROCESS
* @param $param
*/
public function handle_action_act_preprocess(Doku_Event $event, $param)
{
if (substr(act_clean($event->data), 0, 10) != 'startoggle') return;
$id = substr($event->data, 11);
$this->helper->toggleStar(null, $id);
$event->data = 'show';
}
/**
* Print the current star state for the current page
* @param bool $inneronly TBD
* @param bool $print Should the HTML be printed or returned?
* @return bool|string
*/
public function tpl_starred($inneronly = false, $print = true)
{
global $ID;
global $INPUT;
if (!$INPUT->server->has('REMOTE_USER')) return false;
$star_html = $this->helper->starHtml($ID, $ID, $inneronly, true);
if ($print) {
echo $star_html;
}
return $star_html;
}
}