diff options
author | friendica <info@friendica.com> | 2013-08-13 20:57:03 -0700 |
---|---|---|
committer | friendica <info@friendica.com> | 2013-08-13 20:57:03 -0700 |
commit | 9508967c7350e69bf3321aaa63f5527a3e8096f4 (patch) | |
tree | c2b6c78f47cf2c7a1623d4bc528b58cc2d8793fc | |
parent | 680baff73d70769714d806c00cc84c6e65faba0f (diff) | |
download | volse-hubzilla-9508967c7350e69bf3321aaa63f5527a3e8096f4.tar.gz volse-hubzilla-9508967c7350e69bf3321aaa63f5527a3e8096f4.tar.bz2 volse-hubzilla-9508967c7350e69bf3321aaa63f5527a3e8096f4.zip |
menu management is now functional with the exception of acl's (and of course a way to display the menus you create, and probably a bit more input sanity checking)
-rwxr-xr-x | boot.php | 2 | ||||
-rw-r--r-- | include/menu.php | 4 | ||||
-rw-r--r-- | mod/menu.php | 2 | ||||
-rw-r--r-- | mod/mitem.php | 145 | ||||
-rw-r--r-- | view/tpl/menuedit.tpl | 2 | ||||
-rw-r--r-- | view/tpl/menulist.tpl | 2 | ||||
-rw-r--r-- | view/tpl/usermenu.tpl | 2 |
7 files changed, 133 insertions, 26 deletions
@@ -289,7 +289,7 @@ define ( 'ATTACH_FLAG_OS', 0x0002); define ( 'MENU_ITEM_ZID', 0x0001); - +define ( 'MENU_ITEM_NEWWIN', 0x0002); /** diff --git a/include/menu.php b/include/menu.php index cee17c1e9..8d4664385 100644 --- a/include/menu.php +++ b/include/menu.php @@ -29,7 +29,9 @@ function menu_render($menu) { return ''; for($x = 0; $x < count($menu['items']); $x ++) if($menu['items']['mitem_flags'] & MENU_ITEM_ZID) - $menu['items']['link'] = zid($menu['items']['link']); + $menu['items']['mitem_link'] = zid($menu['items']['mitem_link']); + if($menu['items']['mitem_flags'] & MENU_ITEM_NEWWIN) + $menu['items']['newwin'] = '1'; return replace_macros(get_markup_template('usermenu.tpl'),array( '$menu' => $menu['menu'], diff --git a/mod/menu.php b/mod/menu.php index f00bf7a78..910fc389b 100644 --- a/mod/menu.php +++ b/mod/menu.php @@ -22,7 +22,7 @@ function menu_post(&$a) { } else { $r = menu_create($_REQUEST); - if($r) { + if($r) { info( t('Menu created.') . EOL); goaway(z_root() . '/mitem/' . $r); } diff --git a/mod/mitem.php b/mod/mitem.php index b2ccaa341..2b890d5a1 100644 --- a/mod/mitem.php +++ b/mod/mitem.php @@ -1,20 +1,40 @@ <?php +require_once('include/menu.php'); + +function mitem_init(&$a) { + if(! local_user()) + return; + if(argc() < 2) + return; + + $m = menu_fetch_id(intval(argv(1)),local_user()); + if(! $m) { + notice( t('Menu not found.') . EOL); + return ''; + } + $a->data['menu'] = $m; + +} + function mitem_post(&$a) { if(! local_user()) return; - $channel = $a->get_channel(); - $mitem_id = ((argc() > 1) ? intval(argv(1)) : 0); + if(! $a->data['menu']) + return; - $mitem_link = (($_REQUEST['mitem_link']) ? $_REQUEST['menu_link'] : ''); - $mitem_desc = (($_REQUEST['mitem_desc']) ? $_REQUEST['mitem_desc'] : ''); - $mitem_order = (($_REQUEST['mitem_order']) ? intval($_REQUEST['mitem_order']) : 0); - $mitem_id = (($_REQUEST['mitem_id']) ? intval($_REQUEST['mitem_id']) : 0); + $_REQUEST['mitem_channel_id'] = local_user(); + $_REQUEST['menu_id'] = $a->data['menu']['menu_id']; - $mitem_flags = (($_REQUEST['mitem_zid']) ? MENU_ITEM_ZID : 0); + $_REQUEST['mitem_flags'] = 0; + if($_REQUEST['usezid']) + $_REQUEST['mitem_flags'] |= MENU_ITEM_ZID; + if($_REQUEST['newwin']) + $_REQUEST['mitem_flags'] |= MENU_ITEM_NEWWIN; +// FIXME!!!! if ((! $_REQUEST['contact_allow']) && (! $_REQUEST['group_allow']) @@ -35,6 +55,34 @@ function mitem_post(&$a) { $str_contact_deny = perms2str($_REQUEST['contact_deny']); } + + + + $mitem_id = ((argc() > 2) ? intval(argv(2)) : 0); + if($mitem_id) { + $_REQUEST['mitem_id'] = $mitem_id; + $r = menu_edit_item($_REQUEST['menu_id'],local_user(),$_REQUEST); + if($r) { + info( t('Menu element updated.') . EOL); + goaway(z_root() . '/mitem/' . $_REQUEST['menu_id']); + } + else + notice( t('Unable to update menu element.') . EOL); + + } + else { + $r = menu_add_item($_REQUEST['menu_id'],local_user(),$_REQUEST); + if($r) { + info( t('Menu element added.') . EOL); + goaway(z_root() . '/mitem/' . $_REQUEST['menu_id']); + } + else + notice( t('Unable to add menu element.') . EOL); + + } + + + } @@ -45,24 +93,67 @@ function mitem_content(&$a) { return ''; } - - if(argc() == 1) { - // list menus - + if(argc() < 2 || (! $a->data['menu'])) { + notice( t('Not found.') . EOL); + return ''; } - if(argc() > 1) { - if(argv(1) === 'new') { - // new menu + $m = menu_fetch($a->data['menu']['menu_name'],local_user(), get_observer_hash()); + $a->set_widget('menu_preview',menu_render($m)); + + + if(argc() == 2) { + $r = q("select * from menu_item where mitem_menu_id = %d and mitem_channel_id = %d order by mitem_order asc, mitem_desc asc", + intval($a->data['menu']['menu_id']), + local_user() + ); + + if($r) { + $o = replace_macros(get_markup_template('mitemlist.tpl'),array( + '$title' => t('Manage Menu Elements'), + '$menuname' => $a->data['menu']['menu_name'], + '$menudesc' => $a->data['menu']['menu_desc'], + '$edmenu' => t('Edit menu'), + '$menu_id' => $a->data['menu']['menu_id'], + '$mlist' => $r, + '$edit' => t('Edit element'), + '$drop' => t('Drop element'), + '$new' => t('New element'), + '$hintmenu' => t('Edit this menu container'), + '$hintnew' => t('Add menu element'), + '$hintdrop' => t('Delete this menu item'), + '$hintedit' => t('Edit this menu item') + )); + } + + return $o; + + } + if(argc() > 2) { + if(argv(2) === 'new') { + + $o = replace_macros(get_markup_template('mitemedit.tpl'), array( + '$header' => t('New Menu Element'), + '$menu_id' => $a->data['menu']['menu_id'], + '$mitem_desc' => array('mitem_desc', t('Link text'), '', '','*'), + '$mitem_link' => array('mitem_link', t('URL of link'), '', '', '*'), + '$usezid' => array('usezid', t('Use Red magic-auth if available'), true, ''), + '$newwin' => array('newwin', t('Open link in new window'), false,''), +// permissions go here + '$mitem_order' => array('mitem_order', t('Order in list'),'0',t('Higher numbers will sink to bottom of listing')), + '$submit' => t('Create') + )); + return $o; } - elseif(intval(argv(1))) { + + elseif(intval(argv(2))) { $m = q("select * from menu_item where mitem_id = %d and mitem_channel_id = %d limit 1", - intval(argv(1)), + intval(argv(2)), intval(local_user()) ); if(! $m) { @@ -71,19 +162,33 @@ function mitem_content(&$a) { } $mitem = $m[0]; - if(argc() == 3 && argv(2) == 'drop') { - $r = menu_del_item($mitem['mitem_menu_id'], local_user(),intval(argv(1))); + + if(argc() == 4 && argv(3) == 'drop') { + $r = menu_del_item($mitem['mitem_menu_id'], local_user(),intval(argv(2))); if($r) info( t('Menu item deleted.') . EOL); else notice( t('Menu item could not be deleted.'). EOL); - goaway(z_root() . '/menu'); + goaway(z_root() . '/mitem/' . $mitem['mitem_menu_id']); } else { - // edit menu item + // edit menu item + $o = replace_macros(get_markup_template('mitemedit.tpl'), array( + '$header' => t('Edit Menu Element'), + '$menu_id' => $a->data['menu']['menu_id'], + '$mitem_id' => intval(argv(2)), + '$mitem_desc' => array('mitem_desc', t('Link text'), $mitem['mitem_desc'], '','*'), + '$mitem_link' => array('mitem_link', t('URL of link'), $mitem['mitem_link'], '', '*'), + '$usezid' => array('usezid', t('Use Red magic-auth if available'), (($mitem['mitem_flags'] & MENU_ITEM_ZID) ? 1 : 0), ''), + '$newwin' => array('newwin', t('Open link in new window'), (($mitem['mitem_flags'] & MENU_ITEM_NEWWIN) ? 1 : 0),''), +// permissions go here + '$mitem_order' => array('mitem_order', t('Order in list'),$mitem['mitem_order'],t('Higher numbers will sink to bottom of listing')), + '$submit' => t('Modify') + )); + return $o; } } diff --git a/view/tpl/menuedit.tpl b/view/tpl/menuedit.tpl index a46727c55..ea9e775e2 100644 --- a/view/tpl/menuedit.tpl +++ b/view/tpl/menuedit.tpl @@ -2,7 +2,7 @@ <h2>{{$header}}</h2> {{if $menu_id}} -<a href="medit/{{$menu_id}}" title="{{$hintedit}}">{{$editcontents}}</a> +<a href="mitem/{{$menu_id}}" title="{{$hintedit}}">{{$editcontents}}</a> {{/if}} <form id="menuedit" action="menu{{if $menu_id}}/{{$menu_id}}{{/if}}" method="post" > diff --git a/view/tpl/menulist.tpl b/view/tpl/menulist.tpl index 0761322cd..4ee382a27 100644 --- a/view/tpl/menulist.tpl +++ b/view/tpl/menulist.tpl @@ -7,7 +7,7 @@ {{if $menus }} <ul id="menulist"> {{foreach $menus as $m }} -<li><a href="menu/{{$m.menu_id}}" title="{{$hintedit}}">{{$edit}}</a> | <a href="menu/{{$m.menu.id}}/drop" title={{$hintdrop}}>{{$drop}}</a> <a href="medit/{{$m.menu_id}}" title="{{$hintcontent}}">{{$m.menu_name}}</a></li> +<li><a href="menu/{{$m.menu_id}}" title="{{$hintedit}}">{{$edit}}</a> | <a href="menu/{{$m.menu_id}}/drop" title={{$hintdrop}}>{{$drop}}</a> <a href="mitem/{{$m.menu_id}}" title="{{$hintcontent}}">{{$m.menu_name}}</a></li> {{/foreach}} </ul> {{/if}} diff --git a/view/tpl/usermenu.tpl b/view/tpl/usermenu.tpl index 771ae4b2a..3904f4696 100644 --- a/view/tpl/usermenu.tpl +++ b/view/tpl/usermenu.tpl @@ -5,7 +5,7 @@ {{if $items }} <ul class="pmenu-body"> {{foreach $items as $mitem }} -<li class="pmenu-item"><a href="{{$mitem.mitem_link}}">{{$mitem.mitem_desc}}</a></li> +<li class="pmenu-item"><a href="{{$mitem.mitem_link}}" {{if $mitem.newwin}}target="_blank"{{/if}}>{{$mitem.mitem_desc}}</a></li> {{/foreach }} </ul> {{/if}} |