forked from turnermm/dwedit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
executable file
·95 lines (82 loc) · 2.91 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
87
88
89
90
91
92
93
94
95
<?php
/**
* Action adding DW Edit button to page tools (useful with fckedit)
*
* @author Anonymous
* @author Kamil Demecki <[email protected]>
* @author Myron Turner <[email protected]>
* @author Davor Turkalj <[email protected]>
*/
if (!defined('DOKU_INC'))
{
die();
}
class action_plugin_dwedit extends DokuWiki_Action_Plugin
{
var $ckgedit_loaded = false;
var $helper;
function __construct() {
$list = plugin_list('helper');
if(in_array('ckgedit',$list)) {
$this->ckgedit_loaded=true;
$this->helper = plugin_load('helper', 'ckgedit');
}
else if(in_array('ckgdoku',$list)) {
$this->ckgedit_loaded=true;
$this->helper = plugin_load('helper', 'ckgdoku');
}
}
function register(Doku_Event_Handler $controller)
{
$controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'dwedit_action_link',array('page_tools'));
$controller->register_hook('TEMPLATE_DWEDITLINK_DISPLAY', 'BEFORE', $this, 'dwedit_action_link', array('user'));
}
function dwedit_action_link(&$event, $param)
{
global $ACT, $ID, $REV, $INFO, $INPUT;
/* do I need to insert button ? */
if (!$this->ckgedit_loaded || $event->data['view'] != 'main' || $ACT != 'show')
{
return;
}
$mode = $INPUT->str('mode', 'fckg');
if($mode == 'dwiki') return;
/* check excluded namespaces */
$dwedit_ns = $this->helper->getConf('dwedit_ns');
if($dwedit_ns) {
$ns_choices = explode(',',$dwedit_ns);
foreach($ns_choices as $ns) {
$ns = trim($ns);
if(preg_match("/$ns/",$_REQUEST['id'])) return;
}
}
/* insert button at second position */
$params = array('do' => 'edit');
if($REV) {
$params['rev'] = $REV;
}
$params['mode'] = 'dwiki';
$params['fck_preview_mode'] = 'nil';
$name = $this->helper->getLang('btn_dw_edit');
if ($INFO['perm'] > AUTH_READ) {
$title = 'Clasic DokuWiki Editor';
$name = 'DokuWiki Editor';
$edclass = 'dwedit';
}
else {
$title = 'Clasic DokuWiki View';
$name = 'DokuWiki View';
$edclass = 'dwview';
}
$link = '<a href="' . wl($ID, $params) . '" class="action ' . $edclass . '" rel="nofollow" title="' . $title . '"><span>' . $name . '</span></a>';
if($param[0] == 'page_tools') {
$link = '<li class = "dwedit">' . $link .'</li>';
}
else {
$link = '<span class = "dwedit">' . $link .'</span>';
}
$event->data['items'] = array_slice($event->data['items'], 0, 1, true) +
array('dwedit' => $link) + array_slice($event->data['items'], 1, NULL, true);
}
}
?>