streams/mod/menu.php

160 lines
4.2 KiB
PHP
Raw Normal View History

2013-08-12 10:10:34 +00:00
<?php
require_once('include/menu.php');
require_once('include/identity.php');
2013-08-12 10:10:34 +00:00
function menu_init(&$a) {
if (array_key_exists('sys', $_REQUEST) && $_REQUEST['sys'] && is_site_admin()) {
$sys = get_sys_channel();
if ($sys && intval($sys['channel_id'])) {
$a->is_sys = true;
}
}
}
2013-08-12 10:10:34 +00:00
function menu_post(&$a) {
2015-01-29 04:56:04 +00:00
$uid = local_channel();
if(array_key_exists('sys', $_REQUEST) && $_REQUEST['sys'] && is_site_admin()) {
$sys = get_sys_channel();
$uid = intval($sys['channel_id']);
$a->is_sys = true;
}
if(! $uid)
2013-08-12 10:10:34 +00:00
return;
$_REQUEST['menu_channel_id'] = $uid;
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
$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 . (($a->is_sys) ? '?f=&sys=1' : ''));
}
else
notice( t('Unable to update menu.'). EOL);
}
else {
$r = menu_create($_REQUEST);
if($r) {
//info( t('Menu created.') . EOL);
goaway(z_root() . '/mitem/' . $r . (($a->is_sys) ? '?f=&sys=1' : ''));
}
else
notice( t('Unable to create menu.'). EOL);
2013-08-12 10:10:34 +00:00
}
2013-08-12 10:10:34 +00:00
}
function menu_content(&$a) {
2015-01-29 04:56:04 +00:00
$uid = local_channel();
if ($a->is_sys && is_site_admin()) {
$sys = get_sys_channel();
$uid = intval($sys['channel_id']);
}
if(! $uid) {
2013-08-12 10:10:34 +00:00
notice( t('Permission denied.') . EOL);
return '';
}
if(argc() == 1) {
2013-08-12 10:10:34 +00:00
// list menus
$x = menu_list($uid);
2014-11-10 01:39:54 +00:00
if($x) {
for($y = 0; $y < count($x); $y ++) {
2015-05-28 04:09:21 +00:00
$m = menu_fetch($x[$y]['menu_name'],$uid,get_observer_hash());
if($m)
$x[$y]['element'] = '[element]' . base64url_encode(json_encode(menu_element($m))) . '[/element]';
2014-11-10 01:39:54 +00:00
$x[$y]['bookmark'] = (($x[$y]['menu_flags'] & MENU_BOOKMARK) ? true : false);
}
}
$create = replace_macros(get_markup_template('menuedit.tpl'), array(
'$menu_name' => array('menu_name', t('Menu Name'), '', t('Unique name (not visible on webpage) - required'), '*'),
'$menu_desc' => array('menu_desc', t('Menu Title'), '', t('Visible on webpage - leave empty for no title'), ''),
'$menu_bookmark' => array('menu_bookmark', t('Allow Bookmarks'), 0 , t('Menu may be used to store saved bookmarks'), array(t('No'), t('Yes'))),
'$submit' => t('Submit and proceed'),
'$sys' => $a->is_sys,
'$display' => 'none'
));
2014-11-10 01:39:54 +00:00
$o = replace_macros(get_markup_template('menulist.tpl'),array(
'$title' => t('Menus'),
'$create' => $create,
2014-11-10 01:39:54 +00:00
'$menus' => $x,
'$nametitle' => t('Menu Name'),
'$desctitle' => t('Menu Title'),
2014-11-10 01:39:54 +00:00
'$edit' => t('Edit'),
'$drop' => t('Drop'),
2015-05-29 09:07:57 +00:00
'$created' => t('Created'),
'$edited' => t('Edited'),
2014-11-10 01:39:54 +00:00
'$new' => t('New'),
'$bmark' => t('Bookmarks allowed'),
'$hintnew' => t('Create'),
2014-11-10 01:39:54 +00:00
'$hintdrop' => t('Delete this menu'),
'$hintcontent' => t('Edit menu contents'),
'$hintedit' => t('Edit this menu'),
'$sys' => $a->is_sys
2014-11-10 01:39:54 +00:00
));
2013-08-13 08:24:02 +00:00
return $o;
2013-08-12 10:10:34 +00:00
}
if(argc() > 1) {
if(intval(argv(1))) {
2013-08-12 10:10:34 +00:00
if(argc() == 3 && argv(2) == 'drop') {
$r = menu_delete_id(intval(argv(1)),$uid);
if(!$r)
2013-08-12 10:10:34 +00:00
notice( t('Menu could not be deleted.'). EOL);
goaway(z_root() . '/menu' . (($a->is_sys) ? '?f=&sys=1' : ''));
2013-08-12 10:10:34 +00:00
}
$m = menu_fetch_id(intval(argv(1)),$uid);
if(! $m) {
notice( t('Menu not found.') . EOL);
return '';
2013-08-12 10:10:34 +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'), ''),
'$menu_bookmark' => array('menu_bookmark', t('Allow bookmarks'), (($m['menu_flags'] & MENU_BOOKMARK) ? 1 : 0), t('Menu may be used to store saved bookmarks'), array(t('No'), t('Yes'))),
'$menu_system' => (($m['menu_flags'] & MENU_SYSTEM) ? 1 : 0),
'$submit' => t('Submit and proceed')
));
return $o;
2013-08-12 10:10:34 +00:00
}
else {
notice( t('Not found.') . EOL);
return;
}
2013-08-12 10:10:34 +00:00
}
}