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));
60 if($privmail || $privatenet) {
61 $sql_extra .= " AND `network` IN ( 'dfrn' ) ";
65 $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" >\r\n";
67 $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
69 $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
70 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
72 ORDER BY `name` ASC ",
77 $arr = array('contact' => $r, 'entry' => $o);
79 // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
81 call_hooks($a->module . '_pre_' . $selname, $arr);
87 if((is_array($preselected)) && in_array($rr['id'], $preselected))
88 $selected = " selected=\"selected\" ";
92 $trimmed = mb_substr($rr['name'],0,22);
94 $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
99 $o .= "</select>\r\n";
101 call_hooks($a->module . '_post_' . $selname, $o);
106 function fixacl(&$item) {
107 $item = intval(str_replace(array('<','>'),array('',''),$item));
110 function populate_acl($user = null,$celeb = false) {
112 $allow_cid = $allow_gid = $deny_cid = $deny_gid = false;
114 if(is_array($user)) {
115 $allow_cid = ((strlen($user['allow_cid']))
116 ? explode('><', $user['allow_cid']) : array() );
117 $allow_gid = ((strlen($user['allow_gid']))
118 ? explode('><', $user['allow_gid']) : array() );
119 $deny_cid = ((strlen($user['deny_cid']))
120 ? explode('><', $user['deny_cid']) : array() );
121 $deny_gid = ((strlen($user['deny_gid']))
122 ? explode('><', $user['deny_gid']) : array() );
123 array_walk($allow_cid,'fixacl');
124 array_walk($allow_gid,'fixacl');
125 array_walk($deny_cid,'fixacl');
126 array_walk($deny_gid,'fixacl');
130 $o .= '<div id="acl-wrapper">';
131 $o .= '<div id="acl-permit-outer-wrapper">';
132 $o .= '<div id="acl-permit-text">' . t('Visible To:') . '</div>';
133 $o .= '<div id="acl-permit-text-end"></div>';
134 $o .= '<div id="acl-permit-wrapper">';
135 $o .= '<div id="group_allow_wrapper">';
136 $o .= '<label id="acl-allow-group-label" for="group_allow" >' . t('Groups') . '</label>';
137 $o .= group_select('group_allow','group_allow',$allow_gid);
139 $o .= '<div id="contact_allow_wrapper">';
140 $o .= '<label id="acl-allow-contact-label" for="contact_allow" >' . t('Contacts') . '</label>';
141 $o .= contact_select('contact_allow','contact_allow',$allow_cid,4,false,$celeb,true);
143 $o .= '</div>' . "\r\n";
144 $o .= '<div id="acl-allow-end"></div>' . "\r\n";
146 $o .= '<div id="acl-deny-outer-wrapper">';
147 $o .= '<div id="acl-deny-text">' . t('Except For:') . '</div>';
148 $o .= '<div id="acl-deny-text-end"></div>';
149 $o .= '<div id="acl-deny-wrapper">';
150 $o .= '<div id="group_deny_wrapper" >';
151 $o .= '<label id="acl-deny-group-label" for="group_deny" >' . t('Groups') . '</label>';
152 $o .= group_select('group_deny','group_deny', $deny_gid);
154 $o .= '<div id="contact_deny_wrapper" >';
155 $o .= '<label id="acl-deny-contact-label" for="contact_deny" >' . t('Contacts') . '</label>';
156 $o .= contact_select('contact_deny','contact_deny', $deny_cid,4,false, $celeb,true);
158 $o .= '</div>' . "\r\n";
159 $o .= '<div id="acl-deny-end"></div>' . "\r\n";
161 $o .= '</div>' . "\r\n";
162 $o .= '<div id="acl-wrapper-end"></div>' . "\r\n";