4 function group_select($selname,$selclass,$preselected = false,$size = 4) {
10 $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
12 $r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC",
17 $arr = array('group' => $r, 'entry' => $o);
19 // e.g. 'network_pre_group_deny', 'profile_pre_group_allow'
21 call_hooks($a->module . '_pre_' . $selname, $arr);
25 if((is_array($preselected)) && in_array($rr['id'], $preselected))
26 $selected = " selected=\"selected\" ";
29 $trimmed = mb_substr($rr['name'],0,12);
31 $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}\" >$trimmed</option>\r\n";
35 $o .= "</select>\r\n";
37 call_hooks($a->module . '_post_' . $selname, $o);
44 function contact_selector($selname, $selclass, $preselected = false, $options) {
54 if(is_array($options)) {
55 if(x($options,'size'))
56 $size = $options['size'];
58 if(x($options,'mutual_friends'))
60 if(x($options,'single'))
62 if(x($options,'multiple'))
64 if(x($options,'exclude'))
65 $exclude = $options['exclude'];
67 if(x($options,'networks')) {
68 switch($options['networks']) {
70 $networks = array('dfrn');
73 if(is_array($a->user) && $a->user['prvnets'])
74 $networks = array('dfrn','mail','dspr');
76 $networks = array('dfrn','face','mail', 'dspr');
79 if(is_array($a->user) && $a->user['prvnets'])
80 $networks = array('dfrn','mail','dspr');
82 $networks = array('dfrn','face','mail','dspr','stat');
90 $x = array('options' => $options, 'size' => $size, 'single' => $single, 'mutual' => $mutual, 'exclude' => $exclude, 'networks' => $networks);
92 call_hooks('contact_select_options', $x);
99 $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
102 if(intval($x['exclude']))
103 $sql_extra .= sprintf(" AND `id` != %d ", intval($x['exclude']));
105 if(is_array($x['networks']) && count($x['networks'])) {
106 for($y = 0; $y < count($x['networks']) ; $y ++)
107 $x['networks'][$y] = "'" . dbesc($x['networks'][$y]) . "'";
108 $str_nets = implode(',',$x['networks']);
109 $sql_extra .= " AND `network` IN ( $str_nets ) ";
113 $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"" . $x['size'] . "\" >\r\n";
115 $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"" . $x['size'] . "$\" >\r\n";
117 $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
118 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
120 ORDER BY `name` ASC ",
125 $arr = array('contact' => $r, 'entry' => $o);
127 // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
129 call_hooks($a->module . '_pre_' . $selname, $arr);
133 if((is_array($preselected)) && in_array($rr['id'], $preselected))
134 $selected = " selected=\"selected\" ";
138 $trimmed = mb_substr($rr['name'],0,20);
140 $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
145 $o .= "</select>\r\n";
147 call_hooks($a->module . '_post_' . $selname, $o);
154 function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false) {
160 // When used for private messages, we limit correspondence to mutual DFRN/Friendika friends and the selector
161 // to one recipient. By default our selector allows multiple selects amongst all contacts.
165 if($privmail || $celeb) {
166 $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
170 $sql_extra .= " AND `network` IN ( 'dfrn', 'dspr' ) ";
172 elseif($privatenet) {
173 $sql_extra .= " AND `network` IN ( 'dfrn', 'mail', 'face', 'dspr' ) ";
179 $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" >\r\n";
181 $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
183 $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
184 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
186 ORDER BY `name` ASC ",
191 $arr = array('contact' => $r, 'entry' => $o);
193 // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
195 call_hooks($a->module . '_pre_' . $selname, $arr);
199 if((is_array($preselected)) && in_array($rr['id'], $preselected))
200 $selected = " selected=\"selected\" ";
204 $trimmed = mb_substr($rr['name'],0,20);
206 $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
211 $o .= "</select>\r\n";
213 call_hooks($a->module . '_post_' . $selname, $o);
219 function fixacl(&$item) {
220 $item = intval(str_replace(array('<','>'),array('',''),$item));
223 function populate_acl($user = null,$celeb = false) {
225 $allow_cid = $allow_gid = $deny_cid = $deny_gid = false;
227 if(is_array($user)) {
228 $allow_cid = ((strlen($user['allow_cid']))
229 ? explode('><', $user['allow_cid']) : array() );
230 $allow_gid = ((strlen($user['allow_gid']))
231 ? explode('><', $user['allow_gid']) : array() );
232 $deny_cid = ((strlen($user['deny_cid']))
233 ? explode('><', $user['deny_cid']) : array() );
234 $deny_gid = ((strlen($user['deny_gid']))
235 ? explode('><', $user['deny_gid']) : array() );
236 array_walk($allow_cid,'fixacl');
237 array_walk($allow_gid,'fixacl');
238 array_walk($deny_cid,'fixacl');
239 array_walk($deny_gid,'fixacl');
243 $o .= '<div id="acl-wrapper">';
244 $o .= '<div id="acl-permit-outer-wrapper">';
245 $o .= '<div id="acl-permit-text">' . t('Visible To:') . '</div><div id="jot-public">' . t('everybody') . '</div>';
246 $o .= '<div id="acl-permit-text-end"></div>';
247 $o .= '<div id="acl-permit-wrapper">';
248 $o .= '<div id="group_allow_wrapper">';
249 $o .= '<label id="acl-allow-group-label" for="group_allow" >' . t('Groups') . '</label>';
250 $o .= group_select('group_allow','group_allow',$allow_gid);
252 $o .= '<div id="contact_allow_wrapper">';
253 $o .= '<label id="acl-allow-contact-label" for="contact_allow" >' . t('Contacts') . '</label>';
254 $o .= contact_select('contact_allow','contact_allow',$allow_cid,4,false,$celeb,true);
256 $o .= '</div>' . "\r\n";
257 $o .= '<div id="acl-allow-end"></div>' . "\r\n";
259 $o .= '<div id="acl-deny-outer-wrapper">';
260 $o .= '<div id="acl-deny-text">' . t('Except For:') . '</div>';
261 $o .= '<div id="acl-deny-text-end"></div>';
262 $o .= '<div id="acl-deny-wrapper">';
263 $o .= '<div id="group_deny_wrapper" >';
264 $o .= '<label id="acl-deny-group-label" for="group_deny" >' . t('Groups') . '</label>';
265 $o .= group_select('group_deny','group_deny', $deny_gid);
267 $o .= '<div id="contact_deny_wrapper" >';
268 $o .= '<label id="acl-deny-contact-label" for="contact_deny" >' . t('Contacts') . '</label>';
269 $o .= contact_select('contact_deny','contact_deny', $deny_cid,4,false, $celeb,true);
271 $o .= '</div>' . "\r\n";
272 $o .= '<div id="acl-deny-end"></div>' . "\r\n";
274 $o .= '</div>' . "\r\n";
275 $o .= '<div id="acl-wrapper-end"></div>' . "\r\n";*/
277 $tpl = get_markup_template("acl_selector.tpl");
278 $o = replace_macros($tpl, array(
279 '$showall'=> t("Visible to everybody"),
280 '$show' => t("show"),
281 '$hide' => t("don't show"),
282 '$allowcid' => json_encode($allow_cid),
283 '$allowgid' => json_encode($allow_gid),
284 '$denycid' => json_encode($deny_cid),
285 '$denygid' => json_encode($deny_gid),