1<?php 2/** 3 * Action adding DW Edit button to page tools (useful with fckedit) 4 * 5 * @author Myron Turner <turnermm02@shaw.ca> 6 * @author Davor Turkalj <turki.bsc@gmail.com> 7 */ 8 9if (!defined('DOKU_INC')) 10{ 11 die(); 12} 13 14class action_plugin_dwedit extends DokuWiki_Action_Plugin 15{ 16 var $ckgedit_loaded = false; 17 var $helper; 18 function __construct() { 19 /* is either ckgdoku or ckgedit enabled and if so get a reference to the helper */ 20 $list = plugin_list('helper'); 21 if(in_array('ckgedit',$list)) { 22 $this->ckgedit_loaded=true; 23 $this->helper = plugin_load('helper', 'ckgedit'); 24 } 25 else if(in_array('ckgdoku',$list)) { 26 $this->ckgedit_loaded=true; 27 $this->helper = plugin_load('helper', 'ckgdoku'); 28 } 29 } 30 31 function register(Doku_Event_Handler $controller) 32 { 33 $controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addsvgbutton', array()); 34 /* discontinued/deprecdated hooks */ 35 $controller->register_hook('TEMPLATE_PAGETOOLS_DISPLAY', 'BEFORE', $this, 'dwedit_action_link',array('page_tools')); 36 $controller->register_hook('TEMPLATE_DWEDITLINK_DISPLAY', 'BEFORE', $this, 'dwedit_action_link', array('user')); 37 38} 39 40 41 public function addsvgbutton(Doku_Event $event) { 42 /* if this is not a page OR ckgedit/ckgedoku is not active -> return */ 43 if($event->data['view'] != 'page' || !$this->ckgedit_loaded) return; 44 if(method_exists($this->helper,'dw_edit_displayed') && $this->helper->dw_edit_displayed()) return; 45 $btn = $this->helper->getLang('btn_dw_edit'); // get the button's name from the currently enabled ckg_ plugin 46 if(!$btn) $btn = 'DW Edit'; 47 array_splice($event->data['items'], -1, 0, [new \dokuwiki\plugin\dwedit\MenuItem($btn)]); 48 } 49 50 function dwedit_action_link(&$event, $param) 51 { 52 global $ACT, $ID, $REV, $INFO, $INPUT, $USERINFO,$conf; 53 54 /* do I need to insert button ? */ 55 if (!$this->ckgedit_loaded || $event->data['view'] != 'main' || $ACT != 'show') 56 { 57 return; 58 } 59 60 if(!isset($USERINFO) && strpos($conf['disableactions'], 'source') !== false) return; 61 $mode = $INPUT->str('mode', 'fckg'); 62 if($mode == 'dwiki') return; 63 64 /* check excluded namespaces */ 65 $dwedit_ns = $this->helper->getConf('dwedit_ns'); 66 if($dwedit_ns) { 67 $ns_choices = explode(',',$dwedit_ns); 68 foreach($ns_choices as $ns) { 69 $ns = trim($ns); 70 if(preg_match("/$ns/",$_REQUEST['id'])) return; 71 } 72 } 73 74 /* insert button at second position */ 75 $params = array('do' => 'edit'); 76 if($REV) { 77 $params['rev'] = $REV; 78 } 79 $params['mode'] = 'dwiki'; 80 $params['fck_preview_mode'] = 'nil'; 81 82 $name = $this->helper->getLang('btn_dw_edit'); 83 84 if ($INFO['perm'] > AUTH_READ) { 85 $title = $name; 86 $name =$name; 87 $edclass = 'dwedit'; 88 } 89 else { 90 $title = $name; 91 $name = 'DokuWiki View'; 92 $edclass = 'dwview'; 93 } 94 $link = '<a href="' . wl($ID, $params) . '" class="action ' . $edclass . '" rel="nofollow" title="' . $title . '"><span>' . $name . '</span></a>'; 95 96 if($param[0] == 'page_tools') { 97 $link = '<li class = "dwedit">' . $link .'</li>'; 98 } 99 else { 100 $link = '<span class = "dwedit">' . $link .'</span>'; 101 } 102 103 $event->data['items'] = array_slice($event->data['items'], 0, 1, true) + 104 array('dwedit' => $link) + array_slice($event->data['items'], 1, NULL, true); 105 106 107 } 108} 109?> 110