Wiki source for WikkaMenusAdmin


Show raw source

=====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.
::c::
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==
%%(php;1)<h3>Menu Configuration</h3>
<br />
<?php
/* My Menu Configuration Interface
* http:\\emerald-island.eu
* 20090917
* version 1.0
*/
/*Change the path below if needed */
if(!defined('MENU_PATH')) define('MENU_PATH', 'config/');

function WriteMyMenu($file, $content) {
if (!preg_match('/.*inc/', $file))
$file = $file.'.inc';
$menu_file = fopen(MENU_PATH.$file, 'w+');
fwrite($menu_file, $content);
fclose($menu_file);
}

function ReadMyMenu($file) {
$source = fopen(MENU_PATH.$file, 'r');
$size = filesize(MENU_PATH.$file);
$menu_content = '';
if ($size)
$menu_content = fread($source, $size);
else
$menu_content = '';
fclose($source);
return $menu_content;
}

function DeleteMyMenu($filename) {
if (file_exists(MENU_PATH.$filename)) {
if (is_file(MENU_PATH.$filename)) {
unlink(MENU_PATH.$filename);
}
}
}

function LoadAllMyMenus() {

if (is_dir(MENU_PATH)) {

$handle = opendir(MENU_PATH);
$menulist = array();

while (false !== ($file = readdir($handle))) {
$menu = array();
if (preg_match('/.*inc/', $file)) {
$menu['name'] .= $file;
$menu['content'] .= ReadMyMenu($file);
$menulist[] = $menu;
unset($menu);
}
}
return $menulist;
} else {
return FALSE;
}
}

function TrimMenu($list) {
foreach (explode("\n", $list) as $line) {
$line = trim($line);
$trimmed_list .= $line."\n";
}
return $trimmed_list;
}

/*Only admin can create/edit/delete menus*/
if ($this->IsAdmin()) {

switch ($_POST['operation']) {
case 'Create Menu':
if (file_exists(MENU_PATH.$_POST['newname'])) {
echo $this->Format('<<**Sorry!** --- A menu named "'.$_POST['newname'].'" already exists. --- Please choose another name<<::c::--- --- ');
} else {
WriteMyMenu($_POST["newname"], $_POST["menu"]);
echo $this->Format("<<**Thanks!** --- Menu \"".$_POST["newname"]."\" has been created<<::c:: --- ");
}
break;

case 'Delete Menu':
echo $this->Format('<<**Confirmation required**<<::c:: --- Do you really want to delete **'.$_POST['name'].'**? --- --- ');
$formdelete = '<fieldset><input type="hidden" name="name" value="'.$_POST["name"].'" />'.
'<input type="submit" name="operation" value="Confirm Deletion" style="width: 120px" accesskey="s" />'.
'<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /></fieldset><p> </p>';
echo $this->FormOpen('','','post')."\n";
echo $formdelete."\n";
echo $this->FormClose()."\n";
break;

case 'Confirm Deletion':
DeleteMyMenu($_POST['name']);
echo $this->Format('<<**Thanks!** --- Menu "'.$_POST['name'].'" has been deleted<<::c:: --- ');
break;

case 'Rename Menu':
if (file_exists(MENU_PATH.$_POST["newname"])) {
echo $this->Format('<<**Sorry!** --- A menu named "'.$_POST["newname"].'" already exists. --- Please choose another name<<::c:: --- --- ');
} else {
echo $this->Format('<<**Confirmation required**<<::c:: --- Do you really want to rename **'.$_POST["name"].'** as **'.$_POST["newname"].'**? --- --- ');
$formrename = '<fieldset><input type="hidden" name="oldname" value="'.$_POST["name"].'" />'.
'<input type="hidden" name="newname" value="'.$_POST["newname"].'" />'.
'<input type="submit" name="operation" value="Confirm Rename" style="width: 120px" accesskey="s" />'.
'<input type="button" value="Cancel" onClick="history.back();" style="width: 120px" /><fieldset><p> </p>';
echo $this->FormOpen('','','post')."\n";
echo $formrename."\n";
echo $this->FormClose()."\n";
}
break;

case 'Confirm Rename':
rename(MENU_PATH.$_POST['oldname'], MENU_PATH.$_POST['newname']);
echo $this->Format('<<**Thanks!** --- Menu has been renamed as "'.$_POST["newname"].'"<<::c:: --- --- ');
break;

case 'Update Menu':
WriteMyMenu($_POST['name'], TrimMenu($_POST['content']));
echo $this->Format('<<**Menu configuration stored** --- Thanks for updating "'.$_POST["name"].'"!<<::c:: --- --- ');
break;
}

// load stored menus and print menu forms
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]]""## --- --- --- ');

$allmenus = LoadAllMyMenus();

foreach ($allmenus as $item) {
$formarray[$item['name']] = '<fieldset>Menu: <strong>'.$item['name'].'</strong><br />'.
'<input type="hidden" name="name" value="'.$item['name'].'" />'.
'<textarea name="content" rows="6" cols="120">'.$item['content'].'</textarea><br />'.
'<input type="submit" name="operation" value="Update Menu" style="width: 120px" accesskey="s" />'.
'<input type="submit" name="operation" value="Delete Menu" style="width: 120px" /><br />'.
'<input type="text" name="newname" value="'.$item['name'].'" style="width: 120px" />'.
'<input type="submit" name="operation" value="Rename Menu" style="width: 120px" /></fieldset><p> </p>';
print $this->FormOpen('','','post');
echo $formarray[$item['name']];
print($this->FormClose());
}

// "Create menu" form
$newmenuform = '<fieldset><table><tr>'.
'<td>Menu name:</td><td><input type="text" name="newname" value="new_menu_name" style="width: 120px" /></td></tr></table>'.
'<input type="submit" name="operation" value="Create Menu" style="width: 120px" /><br /></fieldset>';
echo $this->Format('== Create a new menu ==');
echo $this->FormOpen('','','post')."\n";
echo $newmenuform;
echo $this->FormClose()."\n";

} else {
echo '<em>Sorry, only Wikka Administrators can modify the Menu configuration.</em>';
}
?>
%%
That's all !
----
CategoryUserContributions - CategoryDevelopmentActions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki