1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
<?php
require_once('include/menu.php');
function mitem_init(&$a) {
if(! local_user())
return;
if(argc() < 2)
return;
$m = menu_fetch_id(intval(argv(1)),local_user());
if(! $m) {
notice( t('Menu not found.') . EOL);
return '';
}
$a->data['menu'] = $m;
}
function mitem_post(&$a) {
if(! local_user())
return;
if(! $a->data['menu'])
return;
$_REQUEST['mitem_channel_id'] = local_user();
$_REQUEST['menu_id'] = $a->data['menu']['menu_id'];
$_REQUEST['mitem_flags'] = 0;
if($_REQUEST['usezid'])
$_REQUEST['mitem_flags'] |= MENU_ITEM_ZID;
if($_REQUEST['newwin'])
$_REQUEST['mitem_flags'] |= MENU_ITEM_NEWWIN;
// FIXME!!!!
if ((! $_REQUEST['contact_allow'])
&& (! $_REQUEST['group_allow'])
&& (! $_REQUEST['contact_deny'])
&& (! $_REQUEST['group_deny'])) {
$str_group_allow = $channel['channel_allow_gid'];
$str_contact_allow = $channel['channel_allow_cid'];
$str_group_deny = $channel['channel_deny_gid'];
$str_contact_deny = $channel['channel_deny_cid'];
}
else {
// use the posted permissions
$str_group_allow = perms2str($_REQUEST['group_allow']);
$str_contact_allow = perms2str($_REQUEST['contact_allow']);
$str_group_deny = perms2str($_REQUEST['group_deny']);
$str_contact_deny = perms2str($_REQUEST['contact_deny']);
}
$mitem_id = ((argc() > 2) ? intval(argv(2)) : 0);
if($mitem_id) {
$_REQUEST['mitem_id'] = $mitem_id;
$r = menu_edit_item($_REQUEST['menu_id'],local_user(),$_REQUEST);
if($r) {
info( t('Menu element updated.') . EOL);
goaway(z_root() . '/mitem/' . $_REQUEST['menu_id']);
}
else
notice( t('Unable to update menu element.') . EOL);
}
else {
$r = menu_add_item($_REQUEST['menu_id'],local_user(),$_REQUEST);
if($r) {
info( t('Menu element added.') . EOL);
goaway(z_root() . '/mitem/' . $_REQUEST['menu_id']);
}
else
notice( t('Unable to add menu element.') . EOL);
}
}
function mitem_content(&$a) {
if(! local_user()) {
notice( t('Permission denied.') . EOL);
return '';
}
if(argc() < 2 || (! $a->data['menu'])) {
notice( t('Not found.') . EOL);
return '';
}
$a->set_widget('design',design_tools());
$m = menu_fetch($a->data['menu']['menu_name'],local_user(), get_observer_hash());
$a->set_widget('menu_preview',menu_render($m));
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']),
local_user()
);
if($r) {
$o = replace_macros(get_markup_template('mitemlist.tpl'),array(
'$title' => t('Manage Menu Elements'),
'$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(argv(2) === 'new') {
$o = replace_macros(get_markup_template('mitemedit.tpl'), array(
'$header' => t('New Menu Element'),
'$menu_id' => $a->data['menu']['menu_id'],
'$mitem_desc' => array('mitem_desc', t('Link text'), '', '','*'),
'$mitem_link' => array('mitem_link', t('URL of link'), '', '', '*'),
'$usezid' => array('usezid', t('Use Red magic-auth if available'), true, ''),
'$newwin' => array('newwin', t('Open link in new window'), false,''),
// permissions go here
'$mitem_order' => array('mitem_order', t('Order in list'),'0',t('Higher numbers will sink to bottom of listing')),
'$submit' => t('Create')
));
return $o;
}
elseif(intval(argv(2))) {
$m = q("select * from menu_item where mitem_id = %d and mitem_channel_id = %d limit 1",
intval(argv(2)),
intval(local_user())
);
if(! $m) {
notice( t('Menu item not found.') . EOL);
goaway(z_root() . '/menu');
}
$mitem = $m[0];
if(argc() == 4 && argv(3) == 'drop') {
$r = menu_del_item($mitem['mitem_menu_id'], local_user(),intval(argv(2)));
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']);
}
else {
// edit menu item
$o = replace_macros(get_markup_template('mitemedit.tpl'), array(
'$header' => t('Edit Menu Element'),
'$menu_id' => $a->data['menu']['menu_id'],
'$mitem_id' => intval(argv(2)),
'$mitem_desc' => array('mitem_desc', t('Link text'), $mitem['mitem_desc'], '','*'),
'$mitem_link' => array('mitem_link', t('URL of link'), $mitem['mitem_link'], '', '*'),
'$usezid' => array('usezid', t('Use Red magic-auth if available'), (($mitem['mitem_flags'] & MENU_ITEM_ZID) ? 1 : 0), ''),
'$newwin' => array('newwin', t('Open link in new window'), (($mitem['mitem_flags'] & MENU_ITEM_NEWWIN) ? 1 : 0),''),
// permissions go here
'$mitem_order' => array('mitem_order', t('Order in list'),$mitem['mitem_order'],t('Higher numbers will sink to bottom of listing')),
'$submit' => t('Modify')
));
return $o;
}
}
}
}
|