7 * @package acl_selectors
9 function group_select($selname,$selclass,$preselected = false,$size = 4) {
15 $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
17 $r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC",
22 $arr = array('group' => $r, 'entry' => $o);
24 // e.g. 'network_pre_group_deny', 'profile_pre_group_allow'
26 call_hooks($a->module . '_pre_' . $selname, $arr);
30 if((is_array($preselected)) && in_array($rr['id'], $preselected))
31 $selected = " selected=\"selected\" ";
34 $trimmed = mb_substr($rr['name'],0,12);
36 $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}\" >$trimmed</option>\r\n";
40 $o .= "</select>\r\n";
42 call_hooks($a->module . '_post_' . $selname, $o);
49 function contact_selector($selname, $selclass, $preselected = false, $options) {
59 if(is_array($options)) {
60 if(x($options,'size'))
61 $size = $options['size'];
63 if(x($options,'mutual_friends'))
65 if(x($options,'single'))
67 if(x($options,'multiple'))
69 if(x($options,'exclude'))
70 $exclude = $options['exclude'];
72 if(x($options,'networks')) {
73 switch($options['networks']) {
75 $networks = array('dfrn');
78 if(is_array($a->user) && $a->user['prvnets'])
79 $networks = array('dfrn','mail','dspr');
81 $networks = array('dfrn','face','mail', 'dspr');
84 if(is_array($a->user) && $a->user['prvnets'])
85 $networks = array('dfrn','mail','dspr');
87 $networks = array('dfrn','face','mail','dspr','stat');
95 $x = array('options' => $options, 'size' => $size, 'single' => $single, 'mutual' => $mutual, 'exclude' => $exclude, 'networks' => $networks);
97 call_hooks('contact_select_options', $x);
104 $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
107 if(intval($x['exclude']))
108 $sql_extra .= sprintf(" AND `id` != %d ", intval($x['exclude']));
110 if(is_array($x['networks']) && count($x['networks'])) {
111 for($y = 0; $y < count($x['networks']) ; $y ++)
112 $x['networks'][$y] = "'" . dbesc($x['networks'][$y]) . "'";
113 $str_nets = implode(',',$x['networks']);
114 $sql_extra .= " AND `network` IN ( $str_nets ) ";
117 $tabindex = (x($options, 'tabindex') ? "tabindex=\"" . $options["tabindex"] . "\"" : "");
120 $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"" . $x['size'] . "\" $tabindex >\r\n";
122 $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"" . $x['size'] . "$\" $tabindex >\r\n";
124 $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
125 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
127 ORDER BY `name` ASC ",
132 $arr = array('contact' => $r, 'entry' => $o);
134 // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
136 call_hooks($a->module . '_pre_' . $selname, $arr);
140 if((is_array($preselected)) && in_array($rr['id'], $preselected))
141 $selected = " selected=\"selected\" ";
145 $trimmed = mb_substr($rr['name'],0,20);
147 $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
152 $o .= "</select>\r\n";
154 call_hooks($a->module . '_post_' . $selname, $o);
161 function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false, $tabindex = null) {
167 // When used for private messages, we limit correspondence to mutual DFRN/Friendica friends and the selector
168 // to one recipient. By default our selector allows multiple selects amongst all contacts.
172 if($privmail || $celeb) {
173 $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
177 $sql_extra .= " AND `network` IN ( 'dfrn', 'dspr' ) ";
179 elseif($privatenet) {
180 $sql_extra .= " AND `network` IN ( 'dfrn', 'mail', 'face', 'dspr' ) ";
183 $tabindex = ($tabindex > 0 ? "tabindex=\"$tabindex\"" : "");
186 $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" $tabindex >\r\n";
188 $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" $tabindex >\r\n";
190 $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
191 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
193 ORDER BY `name` ASC ",
198 $arr = array('contact' => $r, 'entry' => $o);
200 // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
202 call_hooks($a->module . '_pre_' . $selname, $arr);
206 if((is_array($preselected)) && in_array($rr['id'], $preselected))
207 $selected = " selected=\"selected\" ";
211 $trimmed = mb_substr($rr['name'],0,20);
213 $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
218 $o .= "</select>\r\n";
220 call_hooks($a->module . '_post_' . $selname, $o);
226 function fixacl(&$item) {
227 $item = intval(str_replace(array('<','>'),array('',''),$item));
230 function populate_acl($user = null,$celeb = false) {
232 $allow_cid = $allow_gid = $deny_cid = $deny_gid = false;
234 if(is_array($user)) {
235 $allow_cid = ((strlen($user['allow_cid']))
236 ? explode('><', $user['allow_cid']) : array() );
237 $allow_gid = ((strlen($user['allow_gid']))
238 ? explode('><', $user['allow_gid']) : array() );
239 $deny_cid = ((strlen($user['deny_cid']))
240 ? explode('><', $user['deny_cid']) : array() );
241 $deny_gid = ((strlen($user['deny_gid']))
242 ? explode('><', $user['deny_gid']) : array() );
243 array_walk($allow_cid,'fixacl');
244 array_walk($allow_gid,'fixacl');
245 array_walk($deny_cid,'fixacl');
246 array_walk($deny_gid,'fixacl');
250 $o .= '<div id="acl-wrapper">';
251 $o .= '<div id="acl-permit-outer-wrapper">';
252 $o .= '<div id="acl-permit-text">' . t('Visible To:') . '</div><div id="jot-public">' . t('everybody') . '</div>';
253 $o .= '<div id="acl-permit-text-end"></div>';
254 $o .= '<div id="acl-permit-wrapper">';
255 $o .= '<div id="group_allow_wrapper">';
256 $o .= '<label id="acl-allow-group-label" for="group_allow" >' . t('Groups') . '</label>';
257 $o .= group_select('group_allow','group_allow',$allow_gid);
259 $o .= '<div id="contact_allow_wrapper">';
260 $o .= '<label id="acl-allow-contact-label" for="contact_allow" >' . t('Contacts') . '</label>';
261 $o .= contact_select('contact_allow','contact_allow',$allow_cid,4,false,$celeb,true);
263 $o .= '</div>' . "\r\n";
264 $o .= '<div id="acl-allow-end"></div>' . "\r\n";
266 $o .= '<div id="acl-deny-outer-wrapper">';
267 $o .= '<div id="acl-deny-text">' . t('Except For:') . '</div>';
268 $o .= '<div id="acl-deny-text-end"></div>';
269 $o .= '<div id="acl-deny-wrapper">';
270 $o .= '<div id="group_deny_wrapper" >';
271 $o .= '<label id="acl-deny-group-label" for="group_deny" >' . t('Groups') . '</label>';
272 $o .= group_select('group_deny','group_deny', $deny_gid);
274 $o .= '<div id="contact_deny_wrapper" >';
275 $o .= '<label id="acl-deny-contact-label" for="contact_deny" >' . t('Contacts') . '</label>';
276 $o .= contact_select('contact_deny','contact_deny', $deny_cid,4,false, $celeb,true);
278 $o .= '</div>' . "\r\n";
279 $o .= '<div id="acl-deny-end"></div>' . "\r\n";
281 $o .= '</div>' . "\r\n";
282 $o .= '<div id="acl-wrapper-end"></div>' . "\r\n";*/
284 $tpl = get_markup_template("acl_selector.tpl");
285 $o = replace_macros($tpl, array(
286 '$showall'=> t("Visible to everybody"),
287 '$show' => t("show"),
288 '$hide' => t("don't show"),
289 '$allowcid' => json_encode($allow_cid),
290 '$allowgid' => json_encode($allow_gid),
291 '$denycid' => json_encode($deny_cid),
292 '$denygid' => json_encode($deny_gid),