Example #1
0
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;
        }
    }
}
Example #2
0
function mitem_content(&$a)
{
    $uid = local_channel();
    $channel = $a->get_channel();
    $observer = $a->get_observer();
    $ob_hash = $observer ? $observer['xchan_hash'] : '';
    if ($a->is_sys && is_site_admin()) {
        $sys = get_sys_channel();
        $uid = intval($sys['channel_id']);
        $channel = $sys;
        $ob_hash = $sys['xchan_hash'];
    }
    if (!$uid) {
        notice(t('Permission denied.') . EOL);
        return '';
    }
    if (argc() < 2 || !$a->data['menu']) {
        notice(t('Not found.') . EOL);
        return '';
    }
    $m = menu_fetch($a->data['menu']['menu_name'], $uid, $ob_hash);
    $a->data['menu_item'] = $m;
    $menu_list = menu_list($uid);
    foreach ($menu_list as $menus) {
        if ($menus['menu_name'] != $m['menu']['menu_name']) {
            $menu_names[] = $menus['menu_name'];
        }
    }
    $acl = new AccessList($channel);
    $lockstate = $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid'] ? 'lock' : 'unlock';
    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']), intval($uid));
        if ($_GET['display']) {
            $display = $_GET['display'];
        } else {
            $display = $r ? 'none' : 'block';
        }
        $create = replace_macros(get_markup_template('mitemedit.tpl'), array('$menu_id' => $a->data['menu']['menu_id'], '$permissions' => t('Menu Item Permissions'), '$permdesc' => t("(click to open/close)"), '$aclselect' => populate_acl($acl->get(), false), '$mitem_desc' => array('mitem_desc', t('Link Name'), '', 'Visible name of the link', '*'), '$mitem_link' => array('mitem_link', t('Link or Submenu Target'), '', t('Enter URL of the link or select a menu name to create a submenu'), '*', 'list="menu-names"'), '$usezid' => array('usezid', t('Use magic-auth if available'), true, '', array(t('No'), t('Yes'))), '$newwin' => array('newwin', t('Open link in new window'), false, '', array(t('No'), t('Yes'))), '$mitem_order' => array('mitem_order', t('Order in list'), '0', t('Higher numbers will sink to bottom of listing')), '$submit' => t('Submit and finish'), '$submit_more' => t('Submit and continue'), '$display' => $display, '$lockstate' => $lockstate, '$menu_names' => $menu_names, '$sys' => $a->is_sys));
        $o .= replace_macros(get_markup_template('mitemlist.tpl'), array('$title' => t('Menu:'), '$create' => $create, '$nametitle' => t('Link Name'), '$targettitle' => t('Link Target'), '$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 (intval(argv(2))) {
            $m = q("select * from menu_item where mitem_id = %d and mitem_channel_id = %d limit 1", intval(argv(2)), intval($uid));
            if (!$m) {
                notice(t('Menu item not found.') . EOL);
                goaway(z_root() . '/menu' . ($a->is_sys ? '?f=&sys=1' : ''));
            }
            $mitem = $m[0];
            $lockstate = $mitem['allow_cid'] || $mitem['allow_gid'] || $mitem['deny_cid'] || $mitem['deny_gid'] ? 'lock' : 'unlock';
            if (argc() == 4 && argv(3) == 'drop') {
                menu_sync_packet($uid, get_observer_hash(), $mitem['mitem_menu_id']);
                $r = menu_del_item($mitem['mitem_menu_id'], $uid, intval(argv(2)));
                menu_sync_packet($uid, get_observer_hash(), $mitem['mitem_menu_id']);
                if ($r) {
                    info(t('Menu item deleted.') . EOL);
                } else {
                    notice(t('Menu item could not be deleted.') . EOL);
                }
                goaway(z_root() . '/mitem/' . $mitem['mitem_menu_id'] . ($a->is_sys ? '?f=&sys=1' : ''));
            }
            // edit menu item
            $o = replace_macros(get_markup_template('mitemedit.tpl'), array('$header' => t('Edit Menu Element'), '$menu_id' => $a->data['menu']['menu_id'], '$permissions' => t('Menu Item Permissions'), '$permdesc' => t("(click to open/close)"), '$aclselect' => populate_acl($mitem, false), '$mitem_id' => intval(argv(2)), '$mitem_desc' => array('mitem_desc', t('Link text'), $mitem['mitem_desc'], '', '*'), '$mitem_link' => array('mitem_link', t('Link or Submenu Target'), $mitem['mitem_link'], 'Enter URL of the link or select a menu name to create a submenu', '*', 'list="menu-names"'), '$usezid' => array('usezid', t('Use magic-auth if available'), $mitem['mitem_flags'] & MENU_ITEM_ZID ? 1 : 0, '', array(t('No'), t('Yes'))), '$newwin' => array('newwin', t('Open link in new window'), $mitem['mitem_flags'] & MENU_ITEM_NEWWIN ? 1 : 0, '', array(t('No'), t('Yes'))), '$mitem_order' => array('mitem_order', t('Order in list'), $mitem['mitem_order'], t('Higher numbers will sink to bottom of listing')), '$submit' => t('Submit'), '$lockstate' => $lockstate, '$menu_names' => $menu_names));
            return $o;
        }
    }
}