-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathaction.php
60 lines (53 loc) · 1.63 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
<?php
use dokuwiki\Extension\ActionPlugin;
use dokuwiki\Extension\EventHandler;
use dokuwiki\Extension\Event;
/**
* Removes entries from repository database when removed from page
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
*/
/**
* Register actions for event hooks
*/
class action_plugin_pluginrepo extends ActionPlugin
{
/**
* Registers a callback function for a given event
*
* @param EventHandler $controller
*/
public function register(EventHandler $controller)
{
$controller->register_hook('IO_WIKIPAGE_WRITE', 'BEFORE', $this, 'cleanOldEntry');
}
/**
* Handles the page write event and removes the database info
* when the plugin or template code is no longer in the source
*
* @param Event $event event object
*/
public function cleanOldEntry(Event $event)
{
global $ID;
$data = $event->data;
// addSpecialPattern: ----+ *plugin *-+\n.*?\n----+
$haspluginentry = preg_match('/----+ *plugin *-+/', $data[0][1]);
// addSpecialPattern: ----+ *template *-+\n.*?\n----+
$hastemplateentry = preg_match('/----+ *template *-+/', $data[0][1]);
if ($haspluginentry || $hastemplateentry) {
return; // plugin seems still to be there
}
/** @var helper_plugin_pluginrepo_repository $hlp */
$hlp = $this->loadHelper('pluginrepo_repository');
if (!$hlp) {
return;
}
if (curNS($ID) == 'plugin') {
$id = noNS($ID);
} else {
$id = curNS($ID) . ':' . noNS($ID);
}
$hlp->deletePlugin($id);
}
}