DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:admin_plugin_skeleton

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
devel:admin_plugin_skeleton [2015-10-07 20:44] Klap-indevel:admin_plugin_skeleton [2023-09-01 22:43] (current) Klap-in
Line 28: Line 28:
 <code php admin.php> <code php admin.php>
 <?php <?php
 +
 +use dokuwiki\Extension\AdminPlugin;
 +
 /** /**
  * Plugin Skeleton: Displays "Hello World!"  * Plugin Skeleton: Displays "Hello World!"
Line 40: Line 43:
  * need to inherit from this class  * need to inherit from this class
  */  */
-class admin_plugin_skeleton extends DokuWiki_Admin_Plugin {+class admin_plugin_skeleton extends AdminPlugin {
  
-    var $output = 'world';+    private $output = 'world';
      
     /**     /**
      * handle user request      * handle user request
      */      */
-    function handle() { +    public function handle() { 
-     +        global $INPUT; 
-      if (!isset($_REQUEST['cmd'])) return;   // first time - nothing to do+         
 +        if (!$INPUT->has('cmd')) return; // first time - nothing to do
  
-      $this->output = 'invalid'; +        $this->output = 'invalid'; 
-      if (!checkSecurityToken()) return; +       
-      if (!is_array($_REQUEST['cmd'])) return;+        if (!checkSecurityToken()) return; 
 +        if (!is_array($INPUT->param('cmd')) return;
              
-      // verify valid values +        // verify valid values 
-      switch (key($_REQUEST['cmd'])) { +        $cmd = $INPUT->arr('cmd'); 
-        case 'hello' : $this->output = 'again'; break; +        switch (key($cmd)) { 
-        case 'goodbye' : $this->output = 'goodbye'; break; +            case 'hello' 
-      }      +                $this->output = 'again';  
 +                break; 
 +            case 'goodbye':  
 +                $this->output = 'goodbye';  
 +                break; 
 +        }      
     }     }
    
Line 65: Line 75:
      * output appropriate html      * output appropriate html
      */      */
-    function html() { +    public function html() { 
-      ptln('<p>'.htmlspecialchars($this->getLang($this->output)).'</p>');+        echo '<p>' . htmlspecialchars($this->getLang($this->output)) . '</p>';
              
-      ptln('<form action="'.wl($ID).'" method="post">');+        echo '<form action="' . wl($ID) . '" method="post">';
              
-      // output hidden values to ensure dokuwiki will return back to this plugin +        //set hidden values to ensure DokuWiki will return back to this plugin 
-      ptln( <input type="hidden" name="do"   value="admin" />')+        echo  <input type="hidden" name="do" value="admin" />'; 
-      ptln( <input type="hidden" name="page" value="'.$this->getPluginName().'" />')+        echo  <input type="hidden" name="page" value="'  
-      formSecurityToken();+                . $this->getPluginName() . '" />'; 
 +        formSecurityToken();
  
-      ptln( <input type="submit" name="cmd[hello]"  value="'.$this->getLang('btn_hello').'" />')+        echo  <input type="submit" name="cmd[hello]" value="'  
-      ptln( <input type="submit" name="cmd[goodbye]"  value="'.$this->getLang('btn_goodbye').'" />')+                . $this->getLang('btn_hello') . '" />'; 
-      ptln('</form>');+        echo  <input type="submit" name="cmd[goodbye]" value="'  
 +                . $this->getLang('btn_goodbye') . '" />'; 
 +        echo '</form>';
     }     }
    
Line 100: Line 113:
 $lang['menu'] = 'Admin Skeleton...';  $lang['menu'] = 'Admin Skeleton...'; 
  
-$lang['btn_hello'   = 'hello'; +$lang['btn_hello'] = 'hello'; 
-$lang['btn_goodbye' = 'goodbye';+$lang['btn_goodbye'] = 'goodbye';
  
-$lang['world'       = 'Hello, world!'; +$lang['world'] = 'Hello, world!'; 
-$lang['again'       = 'Hello again!'; +$lang['again'] = 'Hello again!'; 
-$lang['goodbye'     = 'Goodbye.'; +$lang['goodbye'] = 'Goodbye.'; 
-$lang['invalid'     = 'invalid input detected!';+$lang['invalid'] = 'invalid input detected!';
 </code> </code>
  
devel/admin_plugin_skeleton.1444243496.txt.gz · Last modified: 2015-10-07 20:44 by Klap-in

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki