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.

310 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
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
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. require_once('include/Contact.php');
  3. function contacts_init(&$a) {
  4. require_once('include/group.php');
  5. $a->page['aside'] .= group_side();
  6. if($a->config['register_policy'] != REGISTER_CLOSED)
  7. $a->page['aside'] .= '<div class="side-invite-link-wrapper" id="side-invite-link-wrapper" ><a href="invite" class="side-invite-link" id="side-invite-link">' . t("Invite Friends") . '</a></div>';
  8. $tpl = load_view_file('view/follow.tpl');
  9. $a->page['aside'] .= replace_macros($tpl,array(
  10. '$label' => t('Connect/Follow [profile address]'),
  11. '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
  12. '$follow' => t('Follow')
  13. ));
  14. }
  15. function contacts_post(&$a) {
  16. if(! local_user())
  17. return;
  18. $contact_id = intval($a->argv[1]);
  19. if(! $contact_id)
  20. return;
  21. $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  22. intval($contact_id),
  23. intval(local_user())
  24. );
  25. if(! count($orig_record)) {
  26. notice( t('Could not access contact record.') . EOL);
  27. goaway($a->get_baseurl() . '/contacts');
  28. return; // NOTREACHED
  29. }
  30. $profile_id = intval($_POST['profile-assign']);
  31. if($profile_id) {
  32. $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  33. intval($profile_id),
  34. intval(local_user())
  35. );
  36. if(! count($r)) {
  37. notice( t('Could not locate selected profile.') . EOL);
  38. return;
  39. }
  40. }
  41. $priority = intval($_POST['priority']);
  42. if($priority == (-1))
  43. if($priority > 5 || $priority < 0)
  44. $priority = 0;
  45. $rating = intval($_POST['reputation']);
  46. if($rating > 5 || $rating < 0)
  47. $rating = 0;
  48. $reason = notags(trim($_POST['reason']));
  49. $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s'
  50. WHERE `id` = %d AND `uid` = %d LIMIT 1",
  51. intval($profile_id),
  52. intval($priority),
  53. intval($rating),
  54. dbesc($reason),
  55. intval($contact_id),
  56. intval(local_user())
  57. );
  58. if($r)
  59. notice( t('Contact updated.') . EOL);
  60. else
  61. notice( t('Failed to update contact record.') . EOL);
  62. return;
  63. }
  64. function contacts_content(&$a) {
  65. $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
  66. if(! local_user()) {
  67. notice( t('Permission denied.') . EOL);
  68. return;
  69. }
  70. if($a->argc == 3) {
  71. $contact_id = intval($a->argv[1]);
  72. if(! $contact_id)
  73. return;
  74. $cmd = $a->argv[2];
  75. $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  76. intval($contact_id),
  77. intval(local_user())
  78. );
  79. if(! count($orig_record)) {
  80. notice( t('Could not access contact record.') . EOL);
  81. goaway($a->get_baseurl() . '/contacts');
  82. return; // NOTREACHED
  83. }
  84. if($cmd === 'block') {
  85. $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
  86. $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
  87. intval($blocked),
  88. intval($contact_id),
  89. intval(local_user())
  90. );
  91. if($r) {
  92. notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
  93. }
  94. goaway($a->get_baseurl() . '/contacts/' . $contact_id);
  95. return; // NOTREACHED
  96. }
  97. if($cmd === 'ignore') {
  98. $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
  99. $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
  100. intval($readonly),
  101. intval($contact_id),
  102. intval(local_user())
  103. );
  104. if($r) {
  105. notice( t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL );
  106. }
  107. goaway($a->get_baseurl() . '/contacts/' . $contact_id);
  108. return; // NOTREACHED
  109. }
  110. if($cmd === 'drop') {
  111. contact_remove($contact_id);
  112. notice( t('Contact has been removed.') . EOL );
  113. goaway($a->get_baseurl() . '/contacts');
  114. return; // NOTREACHED
  115. }
  116. }
  117. if(($a->argc == 2) && intval($a->argv[1])) {
  118. $contact_id = intval($a->argv[1]);
  119. $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
  120. intval(local_user()),
  121. intval($contact_id)
  122. );
  123. if(! count($r)) {
  124. notice( t('Contact not found.') . EOL);
  125. return;
  126. }
  127. $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
  128. require_once('view/contact_selectors.php');
  129. $tpl = load_view_file("view/contact_edit.tpl");
  130. switch($r[0]['rel']) {
  131. case REL_BUD:
  132. $dir_icon = 'images/lrarrow.gif';
  133. $alt_text = t('Mutual Friendship');
  134. break;
  135. case REL_VIP;
  136. $dir_icon = 'images/larrow.gif';
  137. $alt_text = t('is a fan of yours');
  138. break;
  139. case REL_FAN;
  140. $dir_icon = 'images/rarrow.gif';
  141. $alt_text = t('you are a fan of');
  142. break;
  143. default:
  144. break;
  145. }
  146. if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
  147. $url = "redir/{$r[0]['id']}";
  148. $sparkle = ' class="sparkle" ';
  149. }
  150. else {
  151. $url = $r[0]['url'];
  152. $sparkle = '';
  153. }
  154. $o .= replace_macros($tpl,array(
  155. '$poll_interval' => contact_poll_interval($r[0]['priority']),
  156. '$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00')
  157. ? t('Never')
  158. : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A')),
  159. '$profile_select' => contact_profile_assign($r[0]['profile-id']),
  160. '$contact_id' => $r[0]['id'],
  161. '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
  162. '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
  163. '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
  164. '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
  165. '$rating' => contact_reputation($r[0]['rating']),
  166. '$reason' => $r[0]['reason'],
  167. '$groups' => '', // group_selector(),
  168. '$photo' => $r[0]['photo'],
  169. '$name' => $r[0]['name'],
  170. '$dir_icon' => $dir_icon,
  171. '$alt_text' => $alt_text,
  172. '$sparkle' => $sparkle,
  173. '$url' => $url
  174. ));
  175. return $o;
  176. }
  177. if(($a->argc == 2) && ($a->argv[1] === 'all'))
  178. $sql_extra = '';
  179. else
  180. $sql_extra = " AND `blocked` = 0 ";
  181. $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
  182. $tpl = load_view_file("view/contacts-top.tpl");
  183. $o .= replace_macros($tpl,array(
  184. '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
  185. '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
  186. '$search' => $search,
  187. '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
  188. '$submit' => t('Find'),
  189. '$cmd' => $a->cmd
  190. ));
  191. if($search)
  192. $search = dbesc($search.'*');
  193. $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
  194. $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
  195. $r = q("SELECT COUNT(*) AS `total` FROM `contact`
  196. WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
  197. intval($_SESSION['uid']));
  198. if(count($r))
  199. $a->set_pager_total($r[0]['total']);
  200. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
  201. intval($_SESSION['uid']),
  202. intval($a->pager['start']),
  203. intval($a->pager['itemspage'])
  204. );
  205. if(count($r)) {
  206. $tpl = load_view_file("view/contact_template.tpl");
  207. foreach($r as $rr) {
  208. if($rr['self'])
  209. continue;
  210. switch($rr['rel']) {
  211. case REL_BUD:
  212. $dir_icon = 'images/lrarrow.gif';
  213. $alt_text = t('Mutual Friendship');
  214. break;
  215. case REL_VIP;
  216. $dir_icon = 'images/larrow.gif';
  217. $alt_text = t('is a fan of yours');
  218. break;
  219. case REL_FAN;
  220. $dir_icon = 'images/rarrow.gif';
  221. $alt_text = t('you are a fan of');
  222. break;
  223. default:
  224. break;
  225. }
  226. if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
  227. $url = "redir/{$rr['id']}";
  228. $sparkle = ' class="sparkle" ';
  229. }
  230. else {
  231. $url = $rr['url'];
  232. $sparkle = '';
  233. }
  234. $o .= replace_macros($tpl, array(
  235. '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
  236. '$edit_hover' => t('Edit contact'),
  237. '$id' => $rr['id'],
  238. '$alt_text' => $alt_text,
  239. '$dir_icon' => $dir_icon,
  240. '$thumb' => $rr['thumb'],
  241. '$name' => $rr['name'],
  242. '$sparkle' => $sparkle,
  243. '$url' => $url
  244. ));
  245. }
  246. $o .= '<div id="contact-edit-end"></div>';
  247. }
  248. $o .= paginate($a);
  249. return $o;
  250. }