-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.php
86 lines (63 loc) · 2.07 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
// must be run within Dokuwiki
use dokuwiki\plugin\stale\StaleMenuItem;
if (!defined('DOKU_INC')) die();
require_once(__DIR__ . '/Menuitem.php');
/**
* Class action_plugin_move_rewrite
*/
class action_plugin_stale extends DokuWiki_Action_Plugin
{
/**
* Register event handlers.
*
* @param Doku_Event_Handler $controller The plugin controller
*/
public function register(Doku_Event_Handler $controller)
{
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call');
/**
* Add a icon in the page tools menu
* https://www.dokuwiki.org/devel:event:menu_items_assembly
*/
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'add_menu_item');
}
/**
* Render a subtree
*
* @param Doku_Event $event
* @param $params
*/
public function handle_ajax_call(Doku_Event $event, $params)
{
if ($event->data != 'plugin_stale') return;
$event->preventDefault();
$event->stopPropagation();
/** @var helper_plugin_stale $stale */
$stale = plugin_load('helper', 'stale');
if ($stale->canTouch() !== true) {
http_status(403);
$message = "You don't have the right to touch";
} else {
$message = $stale->stale();
http_status(200);
}
$jsonArray = array("message" => $message);
header('Content-Type: application/json');
echo json_encode($jsonArray);
}
public function add_menu_item(Doku_Event $event, $param)
{
/**
* The `view` property defines the menu that is currently built
* https://www.dokuwiki.org/devel:menus
* If this is not the page menu, return
*/
if ($event->data['view'] != 'site') return;
/** @var helper_plugin_stale $stale */
$stale = plugin_load('helper', 'stale');
if ($stale->canTouch()===true){
array_splice($event->data['items'], -1, 0, array(new StaleMenuItem()));
}
}
}