aboutsummaryrefslogtreecommitdiffstats
path: root/include/menu.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/menu.php')
-rw-r--r--include/menu.php88
1 files changed, 34 insertions, 54 deletions
diff --git a/include/menu.php b/include/menu.php
index 515f47758..813d7bcdb 100644
--- a/include/menu.php
+++ b/include/menu.php
@@ -1,6 +1,7 @@
<?php /** @file */
require_once('include/security.php');
+require_once('include/bbcode.php');
function menu_fetch($name,$uid,$observer_xchan) {
@@ -23,37 +24,17 @@ function menu_fetch($name,$uid,$observer_xchan) {
return null;
}
-function bookmarks_menu_fetch($uid,$observer_xchan,$flags = MENU_BOOKMARK) {
-
- $sel_option = (($flags) ? ' and menu_flags = ' . intval($menu_flags) . ' ' : '');
-
- $sql_options = permissions_sql($uid);
-
- $r = q("select * from menu where menu_channel_id = %d $sel_option limit 1",
- intval($uid)
- );
- if($r) {
- $x = q("select * from menu_item where mitem_menu_id = %d and mitem_channel_id = %d
- $sql_options
- order by mitem_order asc, mitem_desc asc",
- intval($r[0]['menu_id']),
- intval($uid)
- );
- return array('menu' => $r[0], 'items' => $x );
- }
-
- return null;
-}
-
-
function menu_render($menu) {
if(! $menu)
return '';
- for($x = 0; $x < count($menu['items']); $x ++)
- if($menu['items']['mitem_flags'] & MENU_ITEM_ZID)
- $menu['items']['mitem_link'] = zid($menu['items']['mitem_link']);
- if($menu['items']['mitem_flags'] & MENU_ITEM_NEWWIN)
- $menu['items']['newwin'] = '1';
+
+ for($x = 0; $x < count($menu['items']); $x ++) {
+ if($menu['items'][$x]['mitem_flags'] & MENU_ITEM_ZID)
+ $menu['items'][$x]['mitem_link'] = zid($menu['items'][$x]['mitem_link']);
+ if($menu['items'][$x]['mitem_flags'] & MENU_ITEM_NEWWIN)
+ $menu['items'][$x]['newwin'] = '1';
+ $menu['items'][$x]['mitem_desc'] = bbcode($menu['items'][$x]['mitem_desc']);
+ }
return replace_macros(get_markup_template('usermenu.tpl'),array(
'$menu' => $menu['menu'],
@@ -95,10 +76,9 @@ function menu_create($arr) {
$menu_channel_id = intval($arr['menu_channel_id']);
- $r = q("select * from menu where menu_name = '%s' and menu_channel_id = %d and menu_flags = %d limit 1",
+ $r = q("select * from menu where menu_name = '%s' and menu_channel_id = %d limit 1",
dbesc($menu_name),
- intval($menu_channel_id),
- intval($menu_flags)
+ intval($menu_channel_id)
);
if($r)
@@ -124,8 +104,19 @@ function menu_create($arr) {
}
-function menu_list($channel_id) {
- $r = q("select * from menu where menu_channel_id = %d order by menu_name",
+/**
+ * If $flags is present, check that all the bits in $flags are set
+ * so that MENU_SYSTEM|MENU_BOOKMARK will return entries with both
+ * bits set. We will use this to find system generated bookmarks.
+ */
+
+function menu_list($channel_id, $name = '', $flags = 0) {
+
+ $sel_options = '';
+ $sel_options .= (($name) ? " and menu_name = '" . protect_sprintf(dbesc($name)) . "' " : '');
+ $sel_options .= (($flags) ? " and menu_flags = " . intval($flags) . " " : '');
+
+ $r = q("select * from menu where menu_channel_id = %d $sel_options order by menu_name",
intval($channel_id)
);
return $r;
@@ -153,9 +144,8 @@ function menu_edit($arr) {
$menu_channel_id = intval($arr['menu_channel_id']);
- $r = q("select menu_id from menu where menu_name = '%s' and menu_flags = %d and menu_channel_id = %d limit 1",
+ $r = q("select menu_id from menu where menu_name = '%s' and menu_channel_id = %d limit 1",
dbesc($menu_name),
- intval($menu_flags),
intval($menu_channel_id)
);
if(($r) && ($r[0]['menu_id'] != $menu_id)) {
@@ -173,22 +163,11 @@ function menu_edit($arr) {
return false;
}
-
- $r = q("select * from menu where menu_name = '%s' and menu_channel_id = %d and menu_desc = '%s' and menu_flags = %d limit 1",
- dbesc($menu_name),
- intval($menu_channel_id),
- dbesc($menu_desc),
- intval($menu_flags)
- );
-
- if($r)
- return false;
-
-
- return q("update menu set menu_name = '%s', menu_desc = '%s',
+ return q("update menu set menu_name = '%s', menu_desc = '%s', menu_flags = %d
where menu_id = %d and menu_channel_id = %d limit 1",
dbesc($menu_name),
dbesc($menu_desc),
+ intval($menu_flags),
intval($menu_id),
intval($menu_channel_id)
);
@@ -236,7 +215,8 @@ function menu_add_item($menu_id, $uid, $arr) {
$channel = get_app()->get_channel();
}
- if ((! $arr['contact_allow'])
+ if (($channel)
+ && (! $arr['contact_allow'])
&& (! $arr['group_allow'])
&& (! $arr['contact_deny'])
&& (! $arr['group_deny'])) {
@@ -255,11 +235,11 @@ function menu_add_item($menu_id, $uid, $arr) {
$str_contact_deny = perms2str($arr['contact_deny']);
}
-
- $allow_cid = perms2str($arr['allow_cid']);
- $allow_gid = perms2str($arr['allow_gid']);
- $deny_cid = perms2str($arr['deny_cid']);
- $deny_gid = perms2str($arr['deny_gid']);
+// unused
+// $allow_cid = perms2str($arr['allow_cid']);
+// $allow_gid = perms2str($arr['allow_gid']);
+// $deny_cid = perms2str($arr['deny_cid']);
+// $deny_gid = perms2str($arr['deny_gid']);
$r = q("insert into menu_item ( mitem_link, mitem_desc, mitem_flags, allow_cid, allow_gid, deny_cid, deny_gid, mitem_channel_id, mitem_menu_id, mitem_order ) values ( '%s', '%s', %d, '%s', '%s', '%s', '%s', %d, %d, %d ) ",
dbesc($mitem_link),