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.

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