WikkaMenusAdmin Action

See also :
Documentation : WikkaMenusAdminInfo
Other: WikkaMenus
Works with :
Wikka 1.2

This is the development page for the WikkaMenusAdmin action for Wikka version > 1.2.
 

DarTar did WikkaMenus, a solution to manage users customized menus stored in MySql database. WikkaMenusAdmin is a "downgraded" version which manages menulets files introduced with Wikka version 1.2.
Usage
Place in a page {{wikkamenusadmin}}, you can also apply ACLs restriction (despite this action is made for admin user only).
Installation
- Save the code block below as /plugins/actions/wikkamenusadmin.php
- Give it the same file permissions as the other php files in that directory
- Customized menulets directory if needed
Code
  1. <h3>Menu Configuration</h3>
  2. <br />
  3. <?php
  4. /* My Menu Configuration Interface
  5.  * http:\\emerald-island.eu
  6.  * 20090917
  7.  * version 1.0
  8.  */
  9. /*Change the path below if needed */
  10. if(!defined('MENU_PATH')) define('MENU_PATH', 'config/');
  11.  
  12. function WriteMyMenu($file, $content) {
  13.     if (!preg_match('/.*inc/', $file))
  14.         $file = $file.'.inc';
  15.     $menu_file = fopen(MENU_PATH.$file, 'w+');
  16.     fwrite($menu_file, $content);
  17.     fclose($menu_file);
  18. }
  19.  
  20. function ReadMyMenu($file) {
  21.     $source = fopen(MENU_PATH.$file, 'r');
  22.     $size = filesize(MENU_PATH.$file);
  23.     $menu_content = '';
  24.     if ($size)
  25.         $menu_content = fread($source, $size);
  26.     else
  27.         $menu_content = '';
  28.     fclose($source);
  29.     return $menu_content;
  30. }
  31.  
  32. function DeleteMyMenu($filename) {
  33.     if (file_exists(MENU_PATH.$filename)) {
  34.         if (is_file(MENU_PATH.$filename)) {
  35.             unlink(MENU_PATH.$filename);
  36.         }
  37.     }
  38. }
  39.  
  40. function LoadAllMyMenus() {
  41.  
  42.     if (is_dir(MENU_PATH)) {
  43.    
  44.         $handle = opendir(MENU_PATH);
  45.         $menulist = array();
  46.  
  47.         while (false !== ($file = readdir($handle))) {
  48.             $menu = array();
  49.             if (preg_match('/.*inc/', $file)) {
  50.                 $menu['name'] .= $file;
  51.                 $menu['content'] .= ReadMyMenu($file);
  52.                 $menulist[] = $menu;
  53.                 unset($menu);
  54.             }
  55.         }
  56.         return $menulist;
  57.     } else {
  58.         return FALSE;
  59.     }
  60. }
  61.  
  62. function TrimMenu($list) {
  63.     foreach (explode("\n", $list) as $line) {
  64.         $line = trim($line);
  65.         $trimmed_list .= $line."\n";
  66.     }
  67.     return $trimmed_list;
  68. }
  69.  
  70. /*Only admin can create/edit/delete menus*/
  71. if ($this->IsAdmin()) {
  72.  
  73.     switch ($_POST['operation']) {
  74.         case 'Create Menu':
  75.             if (file_exists(MENU_PATH.$_POST['newname'])) {
  76.                 echo $this->Format('<<**Sorry!** --- A menu named "'.$_POST['newname'].'" already exists. --- Please choose another name<<::c::--- --- ');
  77.             } else {
  78.                 WriteMyMenu($_POST["newname"], $_POST["menu"]);
  79.                 echo $this->Format("<<**Thanks!** --- Menu \"".$_POST["newname"]."\" has been created<<::c:: --- ");
  80.             }
  81.         break;
  82.  
  83.         case 'Delete Menu':
  84.             echo $this->Format('<<**Confirmation required**<<::c:: --- Do you really want to delete **'.$_POST['name'].'**? --- --- ');
  85.             $formdelete = '<fieldset><input type="hidden" name="name" value="'.$_POST["name"].'" />'.
  86.                 '<input type="submit" name="operation" value="Confirm Deletion" style="width: 120px" accesskey="s" />'.
  87.                 '<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /></fieldset><p>&nbsp;</p>';
  88.             echo $this->FormOpen('','','post')."\n";
  89.             echo $formdelete."\n";
  90.             echo $this->FormClose()."\n";
  91.         break;
  92.  
  93.         case 'Confirm Deletion':
  94.             DeleteMyMenu($_POST['name']);
  95.             echo $this->Format('<<**Thanks!** --- Menu "'.$_POST['name'].'" has been deleted<<::c:: --- ');
  96.         break;
  97.  
  98.         case 'Rename Menu':
  99.             if (file_exists(MENU_PATH.$_POST["newname"])) {
  100.                 echo $this->Format('<<**Sorry!** --- A menu named "'.$_POST["newname"].'" already exists. --- Please choose another name<<::c:: --- --- ');
  101.             } else {
  102.                 echo $this->Format('<<**Confirmation required**<<::c:: --- Do you really want to rename **'.$_POST["name"].'** as **'.$_POST["newname"].'**? --- --- ');
  103.                 $formrename =  '<fieldset><input type="hidden" name="oldname" value="'.$_POST["name"].'" />'.
  104.                     '<input type="hidden" name="newname" value="'.$_POST["newname"].'" />'.
  105.                     '<input type="submit" name="operation" value="Confirm Rename" style="width: 120px" accesskey="s" />'.
  106.                     '<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /><fieldset><p>&nbsp;</p>';  
  107.                 echo $this->FormOpen('','','post')."\n";
  108.                 echo $formrename."\n";
  109.                 echo $this->FormClose()."\n";
  110.             }
  111.         break;
  112.  
  113.         case 'Confirm Rename':
  114.             rename(MENU_PATH.$_POST['oldname'], MENU_PATH.$_POST['newname']);
  115.             echo $this->Format('<<**Thanks!** --- Menu has been renamed as "'.$_POST["newname"].'"<<::c:: --- --- ');
  116.         break;
  117.  
  118.         case 'Update Menu':
  119.             WriteMyMenu($_POST['name'], TrimMenu($_POST['content']));
  120.             echo $this->Format('<<**Menu configuration stored** --- Thanks for updating "'.$_POST["name"].'"!<<::c:: --- --- ');
  121.         break;
  122.     }
  123.  
  124.     // load stored menus and print menu forms
  125.     echo $this->Format('Please enter menu items on separate lines. --- You can either use //""CamelCase"" links// like ##""PageIndex""## --- or //forced links// like: ##""[[http://www.mydomain.com | External Link]]""## --- --- --- ');
  126.  
  127.     $allmenus = LoadAllMyMenus();
  128.  
  129.     foreach ($allmenus as $item) {
  130.         $formarray[$item['name']] = '<fieldset>Menu: <strong>'.$item['name'].'</strong><br />'.
  131.             '<input type="hidden" name="name" value="'.$item['name'].'" />'.
  132.             '<textarea name="content" rows="6" cols="120">'.$item['content'].'</textarea><br />'.
  133.             '<input type="submit" name="operation" value="Update Menu" style="width: 120px" accesskey="s" />'.
  134.             '<input type="submit" name="operation" value="Delete Menu" style="width: 120px" /><br />'.
  135.             '<input type="text" name="newname" value="'.$item['name'].'" style="width: 120px" />'.
  136.             '<input type="submit" name="operation" value="Rename Menu" style="width: 120px" /></fieldset><p>&nbsp;</p>';
  137.         print $this->FormOpen('','','post');
  138.         echo $formarray[$item['name']];
  139.         print($this->FormClose());
  140.     }
  141.  
  142.     // "Create menu" form
  143.     $newmenuform = '<fieldset><table><tr>'.
  144.         '<td>Menu name:</td><td><input type="text" name="newname" value="new_menu_name" style="width: 120px" /></td></tr></table>'.
  145.         '<input type="submit" name="operation" value="Create Menu" style="width: 120px" /><br /></fieldset>';
  146.     echo $this->Format('== Create a new menu ==');
  147.     echo $this->FormOpen('','','post')."\n";
  148.     echo $newmenuform;
  149.     echo $this->FormClose()."\n";
  150.    
  151. } else {
  152.     echo '<em>Sorry, only Wikka Administrators can modify the Menu configuration.</em>';
  153. }
  154. ?>

That's all !

CategoryUserContributions - CategoryDevelopmentActions
There is one comment on this page. [Display comment]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki