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.

235 lines
6.3 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
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
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
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
  1. <?php
  2. function validate_members(&$item) {
  3. $item = intval($item);
  4. }
  5. function group_init(&$a) {
  6. if(local_user()) {
  7. require_once('include/group.php');
  8. $a->page['aside'] = group_side('contacts','group',false,(($a->argc > 1) ? intval($a->argv[1]) : 0));
  9. }
  10. }
  11. function group_post(&$a) {
  12. if(! local_user()) {
  13. notice( t('Permission denied.') . EOL);
  14. return;
  15. }
  16. if(($a->argc == 2) && ($a->argv[1] === 'new')) {
  17. check_form_security_token_redirectOnErr('/group/new', 'group_edit');
  18. $name = notags(trim($_POST['groupname']));
  19. $r = group_add(local_user(),$name);
  20. if($r) {
  21. info( t('Group created.') . EOL );
  22. $r = group_byname(local_user(),$name);
  23. if($r)
  24. goaway($a->get_baseurl() . '/group/' . $r);
  25. }
  26. else
  27. notice( t('Could not create group.') . EOL );
  28. goaway($a->get_baseurl() . '/group');
  29. return; // NOTREACHED
  30. }
  31. if(($a->argc == 2) && (intval($a->argv[1]))) {
  32. check_form_security_token_redirectOnErr('/group', 'group_edit');
  33. $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  34. intval($a->argv[1]),
  35. intval(local_user())
  36. );
  37. if(! count($r)) {
  38. notice( t('Group not found.') . EOL );
  39. goaway($a->get_baseurl() . '/contacts');
  40. return; // NOTREACHED
  41. }
  42. $group = $r[0];
  43. $groupname = notags(trim($_POST['groupname']));
  44. if((strlen($groupname)) && ($groupname != $group['name'])) {
  45. $r = q("UPDATE `group` SET `name` = '%s' WHERE `uid` = %d AND `id` = %d",
  46. dbesc($groupname),
  47. intval(local_user()),
  48. intval($group['id'])
  49. );
  50. if($r)
  51. info( t('Group name changed.') . EOL );
  52. }
  53. $a->page['aside'] = group_side();
  54. }
  55. return;
  56. }
  57. function group_content(&$a) {
  58. $change = false;
  59. if(! local_user()) {
  60. notice( t('Permission denied') . EOL);
  61. return;
  62. }
  63. // Switch to text mode interface if we have more than 'n' contacts or group members
  64. $switchtotext = get_pconfig(local_user(),'system','groupedit_image_limit');
  65. if($switchtotext === false)
  66. $switchtotext = get_config('system','groupedit_image_limit');
  67. if($switchtotext === false)
  68. $switchtotext = 400;
  69. $tpl = get_markup_template('group_edit.tpl');
  70. $context = array(
  71. '$submit' => t('Save Group'),
  72. );
  73. if(($a->argc == 2) && ($a->argv[1] === 'new')) {
  74. return replace_macros($tpl, $context + array(
  75. '$title' => t('Create a group of contacts/friends.'),
  76. '$gname' => array('groupname',t('Group Name: '), '', ''),
  77. '$gid' => 'new',
  78. '$form_security_token' => get_form_security_token("group_edit"),
  79. ));
  80. }
  81. if(($a->argc == 3) && ($a->argv[1] === 'drop')) {
  82. check_form_security_token_redirectOnErr('/group', 'group_drop', 't');
  83. if(intval($a->argv[2])) {
  84. $r = q("SELECT `name` FROM `group` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  85. intval($a->argv[2]),
  86. intval(local_user())
  87. );
  88. if(count($r))
  89. $result = group_rmv(local_user(),$r[0]['name']);
  90. if($result)
  91. info( t('Group removed.') . EOL);
  92. else
  93. notice( t('Unable to remove group.') . EOL);
  94. }
  95. goaway($a->get_baseurl() . '/group');
  96. // NOTREACHED
  97. }
  98. if(($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
  99. check_form_security_token_ForbiddenOnErr('group_member_change', 't');
  100. $r = q("SELECT `id` FROM `contact` WHERE `id` = %d AND `uid` = %d and `self` = 0 and `blocked` = 0 AND `pending` = 0 LIMIT 1",
  101. intval($a->argv[2]),
  102. intval(local_user())
  103. );
  104. if(count($r))
  105. $change = intval($a->argv[2]);
  106. }
  107. if(($a->argc > 1) && (intval($a->argv[1]))) {
  108. require_once('include/acl_selectors.php');
  109. $r = q("SELECT * FROM `group` WHERE `id` = %d AND `uid` = %d AND `deleted` = 0 LIMIT 1",
  110. intval($a->argv[1]),
  111. intval(local_user())
  112. );
  113. if(! count($r)) {
  114. notice( t('Group not found.') . EOL );
  115. goaway($a->get_baseurl() . '/contacts');
  116. }
  117. $group = $r[0];
  118. $members = group_get_members($group['id']);
  119. $preselected = array();
  120. if(count($members)) {
  121. foreach($members as $member)
  122. $preselected[] = $member['id'];
  123. }
  124. if($change) {
  125. if(in_array($change,$preselected)) {
  126. group_rmv_member(local_user(),$group['name'],$change);
  127. }
  128. else {
  129. group_add_member(local_user(),$group['name'],$change);
  130. }
  131. $members = group_get_members($group['id']);
  132. $preselected = array();
  133. if(count($members)) {
  134. foreach($members as $member)
  135. $preselected[] = $member['id'];
  136. }
  137. }
  138. $drop_tpl = get_markup_template('group_drop.tpl');
  139. $drop_txt = replace_macros($drop_tpl, array(
  140. '$id' => $group['id'],
  141. '$delete' => t('Delete'),
  142. '$form_security_token' => get_form_security_token("group_drop"),
  143. ));
  144. $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
  145. $context = $context + array(
  146. '$title' => t('Group Editor'),
  147. '$gname' => array('groupname',t('Group Name: '),$group['name'], ''),
  148. '$gid' => $group['id'],
  149. '$drop' => $drop_txt,
  150. '$form_security_token' => get_form_security_token('group_edit'),
  151. );
  152. }
  153. if(! isset($group))
  154. return;
  155. $groupeditor = array(
  156. 'label_members' => t('Members'),
  157. 'members' => array(),
  158. 'label_contacts' => t('All Contacts'),
  159. 'contacts' => array(),
  160. );
  161. $sec_token = addslashes(get_form_security_token('group_member_change'));
  162. $textmode = (($switchtotext && (count($members) > $switchtotext)) ? true : false);
  163. foreach($members as $member) {
  164. if($member['url']) {
  165. $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;';
  166. $groupeditor['members'][] = micropro($member,true,'mpgroup', $textmode);
  167. }
  168. else
  169. group_rmv_member(local_user(),$group['name'],$member['id']);
  170. }
  171. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `blocked` = 0 and `pending` = 0 and `self` = 0 ORDER BY `name` ASC",
  172. intval(local_user())
  173. );
  174. if(count($r)) {
  175. $textmode = (($switchtotext && (count($r) > $switchtotext)) ? true : false);
  176. foreach($r as $member) {
  177. if(! in_array($member['id'],$preselected)) {
  178. $member['click'] = 'groupChangeMember(' . $group['id'] . ',' . $member['id'] . ',\'' . $sec_token . '\'); return true;';
  179. $groupeditor['contacts'][] = micropro($member,true,'mpall', $textmode);
  180. }
  181. }
  182. }
  183. $context['$groupeditor'] = $groupeditor;
  184. $context['$desc'] = t('Click on a contact to add or remove.');
  185. if($change) {
  186. $tpl = get_markup_template('groupeditor.tpl');
  187. echo replace_macros($tpl, $context);
  188. killme();
  189. }
  190. return replace_macros($tpl, $context);
  191. }