Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
8.1 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. <?php
  2. function group_select($selname,$selclass,$preselected = false,$size = 4) {
  3. $a = get_app();
  4. $o = '';
  5. $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
  6. $r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC",
  7. intval(local_user())
  8. );
  9. $arr = array('group' => $r, 'entry' => $o);
  10. // e.g. 'network_pre_group_deny', 'profile_pre_group_allow'
  11. call_hooks($a->module . '_pre_' . $selname, $arr);
  12. if(count($r)) {
  13. foreach($r as $rr) {
  14. if((is_array($preselected)) && in_array($rr['id'], $preselected))
  15. $selected = " selected=\"selected\" ";
  16. else
  17. $selected = '';
  18. $trimmed = mb_substr($rr['name'],0,12);
  19. $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}\" >$trimmed</option>\r\n";
  20. }
  21. }
  22. $o .= "</select>\r\n";
  23. call_hooks($a->module . '_post_' . $selname, $o);
  24. return $o;
  25. }
  26. function contact_selector($selname, $selclass, $preselected = false, $options) {
  27. $a = get_app();
  28. $mutual = false;
  29. $networks = null;
  30. $single = false;
  31. $exclude = false;
  32. $size = 4;
  33. if(is_array($options)) {
  34. if(x($options,'size'))
  35. $size = $options['size'];
  36. if(x($options,'mutual_friends'))
  37. $mutual = true;
  38. if(x($options,'single'))
  39. $single = true;
  40. if(x($options,'multiple'))
  41. $single = false;
  42. if(x($options,'exclude'))
  43. $exclude = $options['exclude'];
  44. if(x($options,'networks')) {
  45. switch($options['networks']) {
  46. case 'DFRN_ONLY':
  47. $networks = array('dfrn');
  48. break;
  49. case 'PRIVATE':
  50. if(is_array($a->user) && $a->user['prvnets'])
  51. $networks = array('dfrn','mail','dspr');
  52. else
  53. $networks = array('dfrn','face','mail', 'dspr');
  54. break;
  55. case 'TWO_WAY':
  56. if(is_array($a->user) && $a->user['prvnets'])
  57. $networks = array('dfrn','mail','dspr');
  58. else
  59. $networks = array('dfrn','face','mail','dspr','stat');
  60. break;
  61. default:
  62. break;
  63. }
  64. }
  65. }
  66. $x = array('options' => $options, 'size' => $size, 'single' => $single, 'mutual' => $mutual, 'exclude' => $exclude, 'networks' => $networks);
  67. call_hooks('contact_select_options', $x);
  68. $o = '';
  69. $sql_extra = '';
  70. if($x['mutual']) {
  71. $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
  72. }
  73. if(intval($x['exclude']))
  74. $sql_extra .= sprintf(" AND `id` != %d ", intval($x['exclude']));
  75. if(is_array($x['networks']) && count($x['networks'])) {
  76. for($y = 0; $y < count($x['networks']) ; $y ++)
  77. $x['networks'][$y] = "'" . dbesc($x['networks'][$y]) . "'";
  78. $str_nets = implode(',',$x['networks']);
  79. $sql_extra .= " AND `network` IN ( $str_nets ) ";
  80. }
  81. if($x['single'])
  82. $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"" . $x['size'] . "\" >\r\n";
  83. else
  84. $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"" . $x['size'] . "$\" >\r\n";
  85. $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
  86. WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
  87. $sql_extra
  88. ORDER BY `name` ASC ",
  89. intval(local_user())
  90. );
  91. $arr = array('contact' => $r, 'entry' => $o);
  92. // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
  93. call_hooks($a->module . '_pre_' . $selname, $arr);
  94. if(count($r)) {
  95. foreach($r as $rr) {
  96. if((is_array($preselected)) && in_array($rr['id'], $preselected))
  97. $selected = " selected=\"selected\" ";
  98. else
  99. $selected = '';
  100. $trimmed = mb_substr($rr['name'],0,20);
  101. $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
  102. }
  103. }
  104. $o .= "</select>\r\n";
  105. call_hooks($a->module . '_post_' . $selname, $o);
  106. return $o;
  107. }
  108. function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false) {
  109. $a = get_app();
  110. $o = '';
  111. // When used for private messages, we limit correspondence to mutual DFRN/Friendika friends and the selector
  112. // to one recipient. By default our selector allows multiple selects amongst all contacts.
  113. $sql_extra = '';
  114. if($privmail || $celeb) {
  115. $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
  116. }
  117. if($privmail) {
  118. $sql_extra .= " AND `network` IN ( 'dfrn' ) ";
  119. }
  120. elseif($privatenet) {
  121. $sql_extra .= " AND `network` IN ( 'dfrn', 'mail', 'face', 'dspr' ) ";
  122. }
  123. if($privmail)
  124. $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" >\r\n";
  125. else
  126. $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
  127. $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
  128. WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
  129. $sql_extra
  130. ORDER BY `name` ASC ",
  131. intval(local_user())
  132. );
  133. $arr = array('contact' => $r, 'entry' => $o);
  134. // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
  135. call_hooks($a->module . '_pre_' . $selname, $arr);
  136. if(count($r)) {
  137. foreach($r as $rr) {
  138. if((is_array($preselected)) && in_array($rr['id'], $preselected))
  139. $selected = " selected=\"selected\" ";
  140. else
  141. $selected = '';
  142. $trimmed = mb_substr($rr['name'],0,20);
  143. $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
  144. }
  145. }
  146. $o .= "</select>\r\n";
  147. call_hooks($a->module . '_post_' . $selname, $o);
  148. return $o;
  149. }
  150. function fixacl(&$item) {
  151. $item = intval(str_replace(array('<','>'),array('',''),$item));
  152. }
  153. function populate_acl($user = null,$celeb = false) {
  154. $allow_cid = $allow_gid = $deny_cid = $deny_gid = false;
  155. if(is_array($user)) {
  156. $allow_cid = ((strlen($user['allow_cid']))
  157. ? explode('><', $user['allow_cid']) : array() );
  158. $allow_gid = ((strlen($user['allow_gid']))
  159. ? explode('><', $user['allow_gid']) : array() );
  160. $deny_cid = ((strlen($user['deny_cid']))
  161. ? explode('><', $user['deny_cid']) : array() );
  162. $deny_gid = ((strlen($user['deny_gid']))
  163. ? explode('><', $user['deny_gid']) : array() );
  164. array_walk($allow_cid,'fixacl');
  165. array_walk($allow_gid,'fixacl');
  166. array_walk($deny_cid,'fixacl');
  167. array_walk($deny_gid,'fixacl');
  168. }
  169. /*$o = '';
  170. $o .= '<div id="acl-wrapper">';
  171. $o .= '<div id="acl-permit-outer-wrapper">';
  172. $o .= '<div id="acl-permit-text">' . t('Visible To:') . '</div><div id="jot-public">' . t('everybody') . '</div>';
  173. $o .= '<div id="acl-permit-text-end"></div>';
  174. $o .= '<div id="acl-permit-wrapper">';
  175. $o .= '<div id="group_allow_wrapper">';
  176. $o .= '<label id="acl-allow-group-label" for="group_allow" >' . t('Groups') . '</label>';
  177. $o .= group_select('group_allow','group_allow',$allow_gid);
  178. $o .= '</div>';
  179. $o .= '<div id="contact_allow_wrapper">';
  180. $o .= '<label id="acl-allow-contact-label" for="contact_allow" >' . t('Contacts') . '</label>';
  181. $o .= contact_select('contact_allow','contact_allow',$allow_cid,4,false,$celeb,true);
  182. $o .= '</div>';
  183. $o .= '</div>' . "\r\n";
  184. $o .= '<div id="acl-allow-end"></div>' . "\r\n";
  185. $o .= '</div>';
  186. $o .= '<div id="acl-deny-outer-wrapper">';
  187. $o .= '<div id="acl-deny-text">' . t('Except For:') . '</div>';
  188. $o .= '<div id="acl-deny-text-end"></div>';
  189. $o .= '<div id="acl-deny-wrapper">';
  190. $o .= '<div id="group_deny_wrapper" >';
  191. $o .= '<label id="acl-deny-group-label" for="group_deny" >' . t('Groups') . '</label>';
  192. $o .= group_select('group_deny','group_deny', $deny_gid);
  193. $o .= '</div>';
  194. $o .= '<div id="contact_deny_wrapper" >';
  195. $o .= '<label id="acl-deny-contact-label" for="contact_deny" >' . t('Contacts') . '</label>';
  196. $o .= contact_select('contact_deny','contact_deny', $deny_cid,4,false, $celeb,true);
  197. $o .= '</div>';
  198. $o .= '</div>' . "\r\n";
  199. $o .= '<div id="acl-deny-end"></div>' . "\r\n";
  200. $o .= '</div>';
  201. $o .= '</div>' . "\r\n";
  202. $o .= '<div id="acl-wrapper-end"></div>' . "\r\n";*/
  203. $tpl = get_markup_template("acl_selector.tpl");
  204. $o = replace_macros($tpl, array(
  205. '$showall'=> t("Visible to everybody"),
  206. '$show' => t("show"),
  207. '$hide' => t("don't show"),
  208. '$allowcid' => json_encode($allow_cid),
  209. '$allowgid' => json_encode($allow_gid),
  210. '$denycid' => json_encode($deny_cid),
  211. '$denygid' => json_encode($deny_gid),
  212. ));
  213. return $o;
  214. }