function menu_post(&$a) { if (!local_user()) { return; } $_REQUEST['menu_channel_id'] = local_user(); if ($_REQUEST['menu_bookmark']) { $_REQUEST['menu_flags'] |= MENU_BOOKMARK; } if ($_REQUEST['menu_system']) { $_REQUEST['menu_flags'] |= MENU_SYSTEM; } $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); if ($r) { info(t('Menu created.') . EOL); goaway(z_root() . '/mitem/' . $r); } else { notice(t('Unable to create menu.') . EOL); } } }
function menu_post(&$a) { $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) { return; } $_REQUEST['menu_channel_id'] = $uid; if ($_REQUEST['menu_bookmark']) { $_REQUEST['menu_flags'] |= MENU_BOOKMARK; } if ($_REQUEST['menu_system']) { $_REQUEST['menu_flags'] |= MENU_SYSTEM; } $menu_id = argc() > 1 ? intval(argv(1)) : 0; if ($menu_id) { $_REQUEST['menu_id'] = intval(argv(1)); $r = menu_edit($_REQUEST); if ($r) { menu_sync_packet($uid, get_observer_hash(), $menu_id); //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) { menu_sync_packet($uid, get_observer_hash(), $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); } } }
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); } } } } } }