2013-08-12 10:10:34 +00:00
< ? php
require_once ( 'include/menu.php' );
function menu_post ( & $a ) {
if ( ! local_user ())
return ;
2013-08-14 01:10:03 +00:00
$_REQUEST [ 'menu_channel_id' ] = local_user ();
2014-02-03 00:49:09 +00:00
if ( $_REQUEST [ 'menu_bookmark' ])
2014-02-05 11:44:46 +00:00
$_REQUEST [ 'menu_flags' ] |= MENU_BOOKMARK ;
if ( $_REQUEST [ 'menu_system' ])
$_REQUEST [ 'menu_flags' ] |= MENU_SYSTEM ;
2013-08-12 10:10:34 +00:00
2013-08-14 01:10:03 +00:00
$menu_id = (( argc () > 1 ) ? intval ( argv ( 1 )) : 0 );
if ( $menu_id ) {
$_REQUEST [ 'menu_id' ] = intval ( argv ( 1 ));
$r = menu_edit ( $_REQUEST );
if ( $r ) {
info ( t ( 'Menu updated.' ) . EOL );
goaway ( z_root () . '/mitem/' . $menu_id );
}
else
notice ( t ( 'Unable to update menu.' ) . EOL );
}
else {
$r = menu_create ( $_REQUEST );
2013-08-14 03:57:03 +00:00
if ( $r ) {
2013-08-14 01:10:03 +00:00
info ( t ( 'Menu created.' ) . EOL );
goaway ( z_root () . '/mitem/' . $r );
}
else
notice ( t ( 'Unable to create menu.' ) . EOL );
2013-08-12 10:10:34 +00:00
2013-08-14 01:10:03 +00:00
}
2013-08-12 10:10:34 +00:00
}
function menu_content ( & $a ) {
if ( ! local_user ()) {
notice ( t ( 'Permission denied.' ) . EOL );
return '' ;
}
2013-12-19 10:16:14 +00:00
// $a->set_widget('design',design_tools());
2013-09-04 02:55:26 +00:00
2013-08-12 10:10:34 +00:00
if ( argc () == 1 ) {
// list menus
2013-08-13 08:24:02 +00:00
$x = menu_list ( local_user ());
2013-08-15 04:24:40 +00:00
2013-08-13 08:24:02 +00:00
$o = replace_macros ( get_markup_template ( 'menulist.tpl' ), array (
'$title' => t ( 'Manage Menus' ),
'$menus' => $x ,
'$edit' => t ( 'Edit' ),
'$drop' => t ( 'Drop' ),
'$new' => t ( 'New' ),
'$hintnew' => t ( 'Create a new menu' ),
'$hintdrop' => t ( 'Delete this menu' ),
2013-08-14 01:10:03 +00:00
'$hintcontent' => t ( 'Edit menu contents' ),
2013-08-13 08:24:02 +00:00
'$hintedit' => t ( 'Edit this menu' )
));
2013-08-15 04:24:40 +00:00
2013-08-13 08:24:02 +00:00
return $o ;
2013-08-12 10:10:34 +00:00
}
if ( argc () > 1 ) {
2013-08-14 01:10:03 +00:00
if ( argv ( 1 ) === 'new' ) {
$o = replace_macros ( get_markup_template ( 'menuedit.tpl' ), array (
'$header' => t ( 'New Menu' ),
'$menu_name' => array ( 'menu_name' , t ( 'Menu name' ), '' , t ( 'Must be unique, only seen by you' ), '*' ),
'$menu_desc' => array ( 'menu_desc' , t ( 'Menu title' ), '' , t ( 'Menu title as seen by others' ), '' ),
2014-02-03 00:51:11 +00:00
'$menu_bookmark' => array ( 'menu_bookmark' , t ( 'Allow bookmarks' ), 0 , t ( 'Menu may be used to store saved bookmarks' ), '' ),
2013-08-14 01:10:03 +00:00
'$submit' => t ( 'Create' )
));
return $o ;
2013-08-12 10:10:34 +00:00
}
elseif ( intval ( argv ( 1 ))) {
2013-08-14 01:10:03 +00:00
$m = menu_fetch_id ( intval ( argv ( 1 )), local_user ());
if ( ! $m ) {
notice ( t ( 'Menu not found.' ) . EOL );
return '' ;
}
2013-08-12 10:10:34 +00:00
if ( argc () == 3 && argv ( 2 ) == 'drop' ) {
$r = menu_delete_id ( intval ( argv ( 1 )), local_user ());
if ( $r )
info ( t ( 'Menu deleted.' ) . EOL );
else
notice ( t ( 'Menu could not be deleted.' ) . EOL );
goaway ( z_root () . '/menu' );
}
else {
2013-08-14 01:10:03 +00:00
$o = replace_macros ( get_markup_template ( 'menuedit.tpl' ), array (
'$header' => t ( 'Edit Menu' ),
'$menu_id' => intval ( argv ( 1 )),
'$hintedit' => t ( 'Add or remove entries to this menu' ),
'$editcontents' => t ( 'Edit menu contents' ),
'$menu_name' => array ( 'menu_name' , t ( 'Menu name' ), $m [ 'menu_name' ], t ( 'Must be unique, only seen by you' ), '*' ),
'$menu_desc' => array ( 'menu_desc' , t ( 'Menu title' ), $m [ 'menu_desc' ], t ( 'Menu title as seen by others' ), '' ),
2014-02-03 00:51:11 +00:00
'$menu_bookmark' => array ( 'menu_bookmark' , t ( 'Allow bookmarks' ), (( $m [ 'menu_flags' ] & MENU_BOOKMARK ) ? 1 : 0 ), t ( 'Menu may be used to store saved bookmarks' ), '' ),
2014-02-05 11:44:46 +00:00
'$menu_system' => (( $m [ 'menu_flags' ] & MENU_SYSTEM ) ? 1 : 0 ),
2013-08-14 01:10:03 +00:00
'$submit' => t ( 'Modify' )
));
return $o ;
2013-08-12 10:10:34 +00:00
}
}
2013-08-14 01:10:03 +00:00
else {
notice ( t ( 'Not found.' ) . EOL );
return ;
}
2013-08-12 10:10:34 +00:00
}
}