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
Next revision
Previous revision
Last revisionBoth sides next revision
devel:admin_plugin_skeleton [2008-08-09 19:59] chidevel:admin_plugin_skeleton [2015-10-07 20:44] Klap-in
Line 1: Line 1:
-====== Admin Plugin Skeleton ======+====== Admin Plugin Example ======
  
-This skeleton has a little more meat than the one list on the admin plugins page. In particular it shows a bare bones form with hidden controls to generate values to return to the plugin and all displayed text is retrieved from the localised language file. +This Hello World example show an admin plugin. In particular it shows a bare bones form with hidden controls to generate values to return to the plugin and all displayed text is retrieved from the localized language file. 
  
-Two files are shown here +Three files are needed 
-  * [[#admin.php]] +  * [[#plugin.info.txt]], contain metadata about the plugin, see [[plugin info]] for more details. 
-  * [[#lang.php]]+  * [[#admin.php]], the actual plugin code called when entering from the [[:admin window]]. 
 +  * [[#lang/en/lang.php]], an English language file with [[localization|localized]] strings used for this plugin. 
 + 
 +===== plugin.info.txt ===== 
 + 
 +''lib/plugins/skeleton/plugin.info.txt'' 
 + 
 +<code - plugin.info.txt> 
 +base   skeleton 
 +author me 
 +email  me@somesite.com 
 +date   20yy-mm-dd 
 +name   Hello World Plugin 
 +desc   Demonstration plugin 
 +url    https://www.dokuwiki.org/plugin:skeleton 
 +</code>
  
 ===== admin.php ===== ===== admin.php =====
Line 11: Line 26:
 ''lib/plugins/skeleton/admin.php'' ''lib/plugins/skeleton/admin.php''
  
-<code php>+<code php admin.php>
 <?php <?php
 /** /**
Line 20: Line 35:
  */  */
  
-if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 
-if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 
-require_once(DOKU_PLUGIN.'admin.php'); 
    
 /** /**
Line 31: Line 43:
  
     var $output = 'world';     var $output = 'world';
-  +  
-    /** +
-     * return some info +
-     */ +
-    function getInfo(){ +
-      return array( +
-        'author' => 'me', +
-        'email'  => 'me@somesite.com', +
-        'date'   => '20yy-mm-dd', +
-        'name'   => 'admin plugin skeleton', +
-        'desc'   => 'demonstration skeleton', +
-        'url'    => 'http://www.dokuwiki.org/plugin:adminskeleton', +
-      ); +
-    } +
-  +
-    /** +
-     * return sort order for position in admin menu +
-     */ +
-    function getMenuSort() { +
-      return 999; +
-    } +
-     +
-    /** +
-      return a menu prompt for the admin menu +
-      NOT REQUIRED - its better to place $lang['menu'] string in localised string file +
-      only use this function when you need to vary the string returned +
-     */ +
-//    function getMenuText() { +
-//      return 'a menu prompt'; +
-//    } +
- +
     /**     /**
      * handle user request      * handle user request
Line 70: Line 52:
  
       $this->output = 'invalid';       $this->output = 'invalid';
 +      if (!checkSecurityToken()) return;
       if (!is_array($_REQUEST['cmd'])) return;       if (!is_array($_REQUEST['cmd'])) return;
              
Line 91: Line 73:
       ptln('  <input type="hidden" name="do"   value="admin" />');       ptln('  <input type="hidden" name="do"   value="admin" />');
       ptln('  <input type="hidden" name="page" value="'.$this->getPluginName().'" />');       ptln('  <input type="hidden" name="page" value="'.$this->getPluginName().'" />');
-      +      formSecurityToken(); 
       ptln('  <input type="submit" name="cmd[hello]"  value="'.$this->getLang('btn_hello').'" />');       ptln('  <input type="submit" name="cmd[hello]"  value="'.$this->getLang('btn_hello').'" />');
       ptln('  <input type="submit" name="cmd[goodbye]"  value="'.$this->getLang('btn_goodbye').'" />');       ptln('  <input type="submit" name="cmd[goodbye]"  value="'.$this->getLang('btn_goodbye').'" />');
Line 100: Line 83:
 </code> </code>
  
-===== lang.php =====+===== lang/en/lang.php =====
  
-lib/plugins/skeleton/lang/en/lang.php+''lib/plugins/skeleton/lang/en/lang.php''
  
-<code php>+<code php lang.php>
 <?php <?php
 /** /**
- english language file+ English language file
  *  *
  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
  * @author     Christopher Smith <chris@jalakai.co.uk>  * @author     Christopher Smith <chris@jalakai.co.uk>
  */  */
- 
-// settings must be present and set appropriately for the language 
-$lang['encoding'  = 'utf-8'; 
-$lang['direction' = 'ltr'; 
  
 // for admin plugins, the menu prompt to be displayed in the admin menu // for admin plugins, the menu prompt to be displayed in the admin menu
Line 121: Line 100:
 $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.txt · Last modified: 2023-09-01 22:43 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