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);
45 function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false) {
51 // When used for private messages, we limit correspondence to mutual friends and the selector
52 // to one recipient. By default our selector allows multiple selects amongst all contacts.
56 if($privmail || $celeb) {
57 $sql_extra .= sprintf(" AND `rel` = %d ", intval(REL_BUD));
61 $sql_extra .= " AND `network` IN ( 'dfrn' ) ";
64 $sql_extra .= " AND `network` IN ( 'dfrn', 'mail' ) ";
68 $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" >\r\n";
70 $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
72 $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
73 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
75 ORDER BY `name` ASC ",
80 $arr = array('contact' => $r, 'entry' => $o);
82 // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
84 call_hooks($a->module . '_pre_' . $selname, $arr);
90 if((is_array($preselected)) && in_array($rr['id'], $preselected))
91 $selected = " selected=\"selected\" ";
95 $trimmed = mb_substr($rr['name'],0,22);
97 $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
102 $o .= "</select>\r\n";
104 call_hooks($a->module . '_post_' . $selname, $o);
109 function fixacl(&$item) {
110 $item = intval(str_replace(array('<','>'),array('',''),$item));
113 function populate_acl($user = null,$celeb = false) {
115 $allow_cid = $allow_gid = $deny_cid = $deny_gid = false;
117 if(is_array($user)) {
118 $allow_cid = ((strlen($user['allow_cid']))
119 ? explode('><', $user['allow_cid']) : array() );
120 $allow_gid = ((strlen($user['allow_gid']))
121 ? explode('><', $user['allow_gid']) : array() );
122 $deny_cid = ((strlen($user['deny_cid']))
123 ? explode('><', $user['deny_cid']) : array() );
124 $deny_gid = ((strlen($user['deny_gid']))
125 ? explode('><', $user['deny_gid']) : array() );
126 array_walk($allow_cid,'fixacl');
127 array_walk($allow_gid,'fixacl');
128 array_walk($deny_cid,'fixacl');
129 array_walk($deny_gid,'fixacl');
133 $o .= '<div id="acl-wrapper">';
134 $o .= '<div id="acl-permit-outer-wrapper">';
135 $o .= '<div id="acl-permit-text">' . t('Visible To:') . '</div>';
136 $o .= '<div id="acl-permit-text-end"></div>';
137 $o .= '<div id="acl-permit-wrapper">';
138 $o .= '<div id="group_allow_wrapper">';
139 $o .= '<label id="acl-allow-group-label" for="group_allow" >' . t('Groups') . '</label>';
140 $o .= group_select('group_allow','group_allow',$allow_gid);
142 $o .= '<div id="contact_allow_wrapper">';
143 $o .= '<label id="acl-allow-contact-label" for="contact_allow" >' . t('Contacts') . '</label>';
144 $o .= contact_select('contact_allow','contact_allow',$allow_cid,4,false,$celeb,true);
146 $o .= '</div>' . "\r\n";
147 $o .= '<div id="acl-allow-end"></div>' . "\r\n";
149 $o .= '<div id="acl-deny-outer-wrapper">';
150 $o .= '<div id="acl-deny-text">' . t('Except For:') . '</div>';
151 $o .= '<div id="acl-deny-text-end"></div>';
152 $o .= '<div id="acl-deny-wrapper">';
153 $o .= '<div id="group_deny_wrapper" >';
154 $o .= '<label id="acl-deny-group-label" for="group_deny" >' . t('Groups') . '</label>';
155 $o .= group_select('group_deny','group_deny', $deny_gid);
157 $o .= '<div id="contact_deny_wrapper" >';
158 $o .= '<label id="acl-deny-contact-label" for="contact_deny" >' . t('Contacts') . '</label>';
159 $o .= contact_select('contact_deny','contact_deny', $deny_cid,4,false, $celeb,true);
161 $o .= '</div>' . "\r\n";
162 $o .= '<div id="acl-deny-end"></div>' . "\r\n";
164 $o .= '</div>' . "\r\n";
165 $o .= '<div id="acl-wrapper-end"></div>' . "\r\n";