about summary refs log tree commit diff stats
path: root/wiki/lib/plugins/extension/action.php
diff options
context:
space:
mode:
authorahriman <ahriman@falte.red>2018-12-03 19:22:25 -0500
committerahriman <ahriman@falte.red>2018-12-03 19:22:25 -0500
commit0ae8cbf5c0b1a198b963490985b7738392ebcb97 (patch)
treeb2c77ae72c6b717e2b97492065196ac5ffb2d9e2 /wiki/lib/plugins/extension/action.php
parentf57f6cc5a2d159f90168d292437dc4bd8cd7f934 (diff)
downloadsite-0ae8cbf5c0b1a198b963490985b7738392ebcb97.tar.gz
installed dokuwiki, added to navbar, updated news
Diffstat (limited to 'wiki/lib/plugins/extension/action.php')
-rw-r--r--wiki/lib/plugins/extension/action.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/wiki/lib/plugins/extension/action.php b/wiki/lib/plugins/extension/action.php
new file mode 100644
index 0000000..9e48f13
--- /dev/null
+++ b/wiki/lib/plugins/extension/action.php
@@ -0,0 +1,85 @@
+<?php
+/** DokuWiki Plugin extension (Action Component)
+ *
+ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
+ * @author  Andreas Gohr <andi@splitbrain.org>
+ */
+
+// must be run within Dokuwiki
+if(!defined('DOKU_INC')) die();
+
+class action_plugin_extension extends DokuWiki_Action_Plugin {
+
+    /**
+     * Registers a callback function for a given event
+     *
+     * @param Doku_Event_Handler $controller DokuWiki's event controller object
+     * @return void
+     */
+    public function register(Doku_Event_Handler $controller) {
+
+        $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'info');
+
+    }
+
+    /**
+     * Create the detail info for a single plugin
+     *
+     * @param Doku_Event $event
+     * @param            $param
+     */
+    public function info(Doku_Event &$event, $param) {
+        global $USERINFO;
+        global $INPUT;
+
+        if($event->data != 'plugin_extension') return;
+        $event->preventDefault();
+        $event->stopPropagation();
+
+        if(empty($_SERVER['REMOTE_USER']) || !auth_isadmin($_SERVER['REMOTE_USER'], $USERINFO['grps'])) {
+            http_status(403);
+            echo 'Forbidden';
+            exit;
+        }
+
+        $ext = $INPUT->str('ext');
+        if(!$ext) {
+            http_status(400);
+            echo 'no extension given';
+            return;
+        }
+
+        /** @var helper_plugin_extension_extension $extension */
+        $extension = plugin_load('helper', 'extension_extension');
+        $extension->setExtension($ext);
+
+        $act = $INPUT->str('act');
+        switch($act) {
+            case 'enable':
+            case 'disable':
+                $json = new JSON();
+                $extension->$act(); //enables/disables
+
+                $reverse = ($act == 'disable') ? 'enable' : 'disable';
+
+                $return = array(
+                    'state'   => $act.'d', // isn't English wonderful? :-)
+                    'reverse' => $reverse,
+                    'label'   => $extension->getLang('btn_'.$reverse)
+                );
+
+                header('Content-Type: application/json');
+                echo $json->encode($return);
+                break;
+
+            case 'info':
+            default:
+                /** @var helper_plugin_extension_list $list */
+                $list = plugin_load('helper', 'extension_list');
+                header('Content-Type: text/html; charset=utf-8');
+                echo $list->make_info($extension);
+        }
+    }
+
+}
+