function menu_content(&$a) { $uid = local_channel(); if ($a->is_sys && is_site_admin()) { $sys = get_sys_channel(); $uid = intval($sys['channel_id']); } if (!$uid) { notice(t('Permission denied.') . EOL); return ''; } if (argc() == 1) { // list menus $x = menu_list($uid); if ($x) { for ($y = 0; $y < count($x); $y++) { $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]'; } $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')); $o = replace_macros(get_markup_template('menulist.tpl'), array('$title' => t('Menus'), '$create' => $create, '$menus' => $x, '$nametitle' => t('Menu Name'), '$desctitle' => t('Menu Title'), '$edit' => t('Edit'), '$drop' => t('Drop'), '$created' => t('Created'), '$edited' => t('Edited'), '$new' => t('New'), '$bmark' => t('Bookmarks allowed'), '$hintnew' => t('Create'), '$hintdrop' => t('Delete this menu'), '$hintcontent' => t('Edit menu contents'), '$hintedit' => t('Edit this menu'), '$sys' => $a->is_sys)); return $o; } if (argc() > 1) { if (intval(argv(1))) { if (argc() == 3 && argv(2) == 'drop') { menu_sync_packet($uid, get_observer_hash(), intval(argv(1)), true); $r = menu_delete_id(intval(argv(1)), $uid); if (!$r) { notice(t('Menu could not be deleted.') . EOL); } goaway(z_root() . '/menu' . ($a->is_sys ? '?f=&sys=1' : '')); } $m = menu_fetch_id(intval(argv(1)), $uid); if (!$m) { notice(t('Menu not found.') . EOL); return ''; } $o = replace_macros(get_markup_template('menuedit.tpl'), array('$header' => t('Edit Menu'), '$sys' => $a->is_sys, '$menu_id' => intval(argv(1)), '$menu_edit_link' => 'mitem/' . intval(argv(1)) . ($a->is_sys ? '?f=&sys=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; } else { notice(t('Not found.') . EOL); return; } } }
function menu_content(&$a) { $uid = local_channel(); if ($a->is_sys && is_site_admin()) { $sys = get_sys_channel(); $uid = intval($sys['channel_id']); } if (!$uid) { notice(t('Permission denied.') . EOL); return ''; } if (argc() == 1) { // list menus $x = menu_list($uid); if ($x) { for ($y = 0; $y < count($x); $y++) { $x[$y]['bookmark'] = $x[$y]['menu_flags'] & MENU_BOOKMARK ? true : false; } } $o = replace_macros(get_markup_template('menulist.tpl'), array('$title' => t('Manage Menus'), '$menus' => $x, '$edit' => t('Edit'), '$drop' => t('Drop'), '$new' => t('New'), '$bmark' => t('Bookmarks allowed'), '$hintnew' => t('Create a new menu'), '$hintdrop' => t('Delete this menu'), '$hintcontent' => t('Edit menu contents'), '$hintedit' => t('Edit this menu'))); return $o; } if (argc() > 1) { 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'), ''), '$menu_bookmark' => array('menu_bookmark', t('Allow bookmarks'), 0, t('Menu may be used to store saved bookmarks'), ''), '$submit' => t('Create'))); return $o; } elseif (intval(argv(1))) { $m = menu_fetch_id(intval(argv(1)), $uid); if (!$m) { notice(t('Menu not found.') . EOL); return ''; } if (argc() == 3 && argv(2) == 'drop') { $r = menu_delete_id(intval(argv(1)), $uid); if ($r) { info(t('Menu deleted.') . EOL); } else { notice(t('Menu could not be deleted.') . EOL); } goaway(z_root() . '/menu' . ($a->is_sys ? '?f=&sys=1' : '')); } else { $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'), ''), '$menu_system' => $m['menu_flags'] & MENU_SYSTEM ? 1 : 0, '$submit' => t('Modify'))); return $o; } } else { notice(t('Not found.') . EOL); return; } } }
function menu_content(&$a) { if (!local_user()) { notice(t('Permission denied.') . EOL); return ''; } // $a->set_widget('design',design_tools()); if (argc() == 1) { // list menus $x = menu_list(local_user()); $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'), '$hintcontent' => t('Edit menu contents'), '$hintedit' => t('Edit this menu'))); return $o; } if (argc() > 1) { 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'), ''), '$menu_bookmark' => array('menu_bookmark', t('Allow bookmarks'), 0, t('Menu may be used to store saved bookmarks'), ''), '$submit' => t('Create'))); return $o; } elseif (intval(argv(1))) { $m = menu_fetch_id(intval(argv(1)), local_user()); if (!$m) { notice(t('Menu not found.') . EOL); return ''; } 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 { $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'), ''), '$menu_system' => $m['menu_flags'] & MENU_SYSTEM ? 1 : 0, '$submit' => t('Modify'))); return $o; } } else { notice(t('Not found.') . EOL); return; } } }
function menu_delete($menu_name, $uid) { $r = q("select menu_id from menu where menu_name = '%s' and menu_channel_id = %d limit 1", dbesc($menu_name), intval($uid)); if ($r) { return menu_delete_id($r[0]['menu_id'], $uid); } return false; }
function sync_menus($channel, $menus) { if ($channel && $menus) { foreach ($menus as $menu) { $m = array(); $m['menu_channel_id'] = $channel['channel_id']; $m['menu_name'] = $menu['pagetitle']; $m['menu_desc'] = $menu['desc']; if ($menu['created']) { $m['menu_created'] = datetime_convert($menu['created']); } if ($menu['edited']) { $m['menu_edited'] = datetime_convert($menu['edited']); } $m['menu_flags'] = 0; if ($menu['flags']) { if (in_array('bookmark', $menu['flags'])) { $m['menu_flags'] |= MENU_BOOKMARK; } if (in_array('system', $menu['flags'])) { $m['menu_flags'] |= MENU_SYSTEM; } } $editing = false; $r = q("select * from menu where menu_name = '%s' and menu_channel_id = %d limit 1", dbesc($m['menu_name']), intval($channel['channel_id'])); if ($r) { if ($r[0]['menu_edited'] >= $m['menu_edited']) { continue; } if ($menu['menu_deleted']) { menu_delete_id($r[0]['menu_id'], $channel['channel_id']); continue; } $menu_id = $r[0]['menu_id']; $m['menu_id'] = $r[0]['menu_id']; $x = menu_edit($m); if (!$x) { continue; } $editing = true; } if (!$editing) { $menu_id = menu_create($m); } if ($menu_id) { if ($editing) { // don't try syncing - just delete all the entries and start over q("delete from menu_item where mitem_menu_id = %d", intval($menu_id)); } if (is_array($menu['items'])) { foreach ($menu['items'] as $it) { $mitem = array(); $mitem['mitem_link'] = str_replace('[baseurl]', z_root(), $it['link']); $mitem['mitem_desc'] = escape_tags($it['desc']); $mitem['mitem_order'] = intval($it['order']); if (is_array($it['flags'])) { $mitem['mitem_flags'] = 0; if (in_array('zid', $it['flags'])) { $mitem['mitem_flags'] |= MENU_ITEM_ZID; } if (in_array('new-window', $it['flags'])) { $mitem['mitem_flags'] |= MENU_ITEM_NEWWIN; } if (in_array('chatroom', $it['flags'])) { $mitem['mitem_flags'] |= MENU_ITEM_CHATROOM; } } menu_add_item($menu_id, $channel['channel_id'], $mitem); } } } } } }