Revision [20853]

This is an old revision of WikkaMenusAdmin made by EmeraldIsland on 2009-09-17 17:05:18.

 

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.
 

NilsLindenberg did WikkaMenus, a solution to manage users customized menus stored in MySql database. WikkaMenusAdmin is a "downgrade" version which stores menulets introduced with Wikka version 1.2.
Usage
Place in a page {{wikkamenuadmin}}, 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
wikkamenusadmin.php (line 1)
  1. <h3>Menus 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. /*Only admin can create/edit/delete menus*/
  63. if ($this->IsAdmin()) {
  64.  
  65.     switch ($_POST['operation']) {
  66.         case 'Create Menu':
  67.             if (file_exists(MENU_PATH.$_POST['newname'])) {
  68.                 echo $this->Format('<<**Sorry!** --- A menu named "'.$_POST['newname'].'" already exists. --- Please choose another name<<::c::--- --- ');
  69.             } else {
  70.                 WriteMyMenu($_POST["newname"], $_POST["menu"]);
  71.                 echo $this->Format("<<**Thanks!** --- Menu \"".$_POST["newname"]."\" has been created<<::c:: --- ");
  72.             }
  73.         break;
  74.  
  75.         case 'Delete Menu':
  76.             echo $this->Format('<<**Confirmation required**<<::c:: --- Do you really want to delete **'.$_POST['name'].'**? --- --- ');
  77.             $formdelete = '<fieldset><input type="hidden" name="name" value="'.$_POST["name"].'" />'.
  78.                 '<input type="submit" name="operation" value="Confirm Deletion" style="width: 120px" accesskey="s" />'.
  79.                 '<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /></fieldset><p>&nbsp;</p>';
  80.             echo $this->FormOpen('','','post')."\n";
  81.             echo $formdelete."\n";
  82.             echo $this->FormClose()."\n";
  83.         break;
  84.  
  85.         case 'Confirm Deletion':
  86.             DeleteMyMenu($_POST['name']);
  87.             echo $this->Format('<<**Thanks!** --- Menu "'.$_POST['name'].'" has been deleted<<::c:: --- ');
  88.         break;
  89.  
  90.         case 'Rename Menu':
  91.             if (file_exists(MENU_PATH.$_POST["newname"])) {
  92.                 echo $this->Format('<<**Sorry!** --- A menu named "'.$_POST["newname"].'" already exists. --- Please choose another name<<::c:: --- --- ');
  93.             } else {
  94.                 echo $this->Format('<<**Confirmation required**<<::c:: --- Do you really want to rename **'.$_POST["name"].'** as **'.$_POST["newname"].'**? --- --- ');
  95.                 $formrename =  '<fieldset><input type="hidden" name="oldname" value="'.$_POST["name"].'" />'.
  96.                     '<input type="hidden" name="newname" value="'.$_POST["newname"].'" />'.
  97.                     '<input type="submit" name="operation" value="Confirm Rename" style="width: 120px" accesskey="s" />'.
  98.                     '<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /><fieldset><p>&nbsp;</p>';  
  99.                 echo $this->FormOpen('','','post')."\n";
  100.                 echo $formrename."\n";
  101.                 echo $this->FormClose()."\n";
  102.             }
  103.         break;
  104.  
  105.         case 'Confirm Rename':
  106.             rename(MENU_PATH.$_POST['oldname'], MENU_PATH.$_POST['newname']);
  107.             echo $this->Format('<<**Thanks!** --- Menu has been renamed as "'.$_POST["newname"].'"<<::c:: --- --- ');
  108.         break;
  109.  
  110.         case 'Update Menu':
  111.             WriteMyMenu($_POST['name'], $this->TrimMenu($_POST['content']));
  112.             echo $this->Format('<<**Menu configuration stored** --- Thanks for updating "'.$_POST["name"].'"!<<::c:: --- --- ');
  113.         break;
  114.     }
  115.  
  116.     // load stored menus and print menu forms
  117.     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]]""## --- --- --- ');
  118.  
  119.     $allmenus = LoadAllMyMenus();
  120.  
  121.     foreach ($allmenus as $item) {
  122.         $formarray[$item['name']] = '<fieldset>Menu: <strong>'.$item['name'].'</strong><br />'.
  123.             '<input type="hidden" name="name" value="'.$item['name'].'" />'.
  124.             '<textarea name="content" rows="6" cols="120">'.$item['content'].'</textarea><br />'.
  125.             '<input type="submit" name="operation" value="Update Menu" style="width: 120px" accesskey="s" />'.
  126.             '<input type="submit" name="operation" value="Delete Menu" style="width: 120px" /><br />'.
  127.             '<input type="text" name="newname" value="'.$item['name'].'" style="width: 120px" />'.
  128.             '<input type="submit" name="operation" value="Rename Menu" style="width: 120px" /></fieldset><p>&nbsp;</p>';
  129.         print $this->FormOpen('','','post');
  130.         echo $formarray[$item['name']];
  131.         print($this->FormClose());
  132.     }
  133.  
  134.     // "Create menu" form
  135.     $newmenuform = '<fieldset><table><tr>'.
  136.         '<td>Menu name:</td><td><input type="text" name="newname" value="new_menu_name" style="width: 120px" /></td></tr></table>'.
  137.         '<input type="submit" name="operation" value="Create Menu" style="width: 120px" /><br /></fieldset>';
  138.     echo $this->Format('== Create a new menu ==');
  139.     echo $this->FormOpen('','','post')."\n";
  140.     echo $newmenuform;
  141.     echo $this->FormClose()."\n";
  142.    
  143. } else {
  144.     echo '<em>Sorry, only Wikka Administrators can modify the Menu configuration.</em>';
  145. }
  146. ?>


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