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.
 
 
 
 
 
 

404 lines
12 KiB

  1. <?php
  2. require_once('include/Contact.php');
  3. function contacts_init(&$a) {
  4. require_once('include/group.php');
  5. if(! x($a->page,'aside'))
  6. $a->page['aside'] = '';
  7. $a->page['aside'] .= group_side();
  8. if($a->config['register_policy'] != REGISTER_CLOSED)
  9. $a->page['aside'] .= '<div class="side-link" id="side-invite-link" ><a href="invite" >' . t("Invite Friends") . '</a></div>';
  10. if(strlen(get_config('system','directory_submit_url')))
  11. $a->page['aside'] .= '<div class="side-link" id="side-match-link"><a href="match" >' . t('Find People With Shared Interests') . '</a></div>';
  12. $tpl = load_view_file('view/follow.tpl');
  13. $a->page['aside'] .= replace_macros($tpl,array(
  14. '$label' => t('Connect/Follow'),
  15. '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
  16. '$follow' => t('Follow')
  17. ));
  18. }
  19. function contacts_post(&$a) {
  20. if(! local_user())
  21. return;
  22. $contact_id = intval($a->argv[1]);
  23. if(! $contact_id)
  24. return;
  25. $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  26. intval($contact_id),
  27. intval(local_user())
  28. );
  29. if(! count($orig_record)) {
  30. notice( t('Could not access contact record.') . EOL);
  31. goaway($a->get_baseurl() . '/contacts');
  32. return; // NOTREACHED
  33. }
  34. call_hooks('contact_edit_post', $_POST);
  35. $profile_id = intval($_POST['profile-assign']);
  36. if($profile_id) {
  37. $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  38. intval($profile_id),
  39. intval(local_user())
  40. );
  41. if(! count($r)) {
  42. notice( t('Could not locate selected profile.') . EOL);
  43. return;
  44. }
  45. }
  46. logger('contact_edit ' . print_r($_POST,true));
  47. $priority = intval($_POST['poll']);
  48. if($priority == (-1))
  49. if($priority > 5 || $priority < 0)
  50. $priority = 0;
  51. $rating = intval($_POST['reputation']);
  52. if($rating > 5 || $rating < 0)
  53. $rating = 0;
  54. $reason = notags(trim($_POST['reason']));
  55. $info = escape_tags(trim($_POST['info']));
  56. $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s', `info` = '%s'
  57. WHERE `id` = %d AND `uid` = %d LIMIT 1",
  58. intval($profile_id),
  59. intval($priority),
  60. intval($rating),
  61. dbesc($reason),
  62. dbesc($info),
  63. intval($contact_id),
  64. intval(local_user())
  65. );
  66. if($r)
  67. notice( t('Contact updated.') . EOL);
  68. else
  69. notice( t('Failed to update contact record.') . EOL);
  70. return;
  71. }
  72. function contacts_content(&$a) {
  73. $sort_type = 0;
  74. $o = '';
  75. $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
  76. $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
  77. if(! local_user()) {
  78. notice( t('Permission denied.') . EOL);
  79. return;
  80. }
  81. if($a->argc == 3) {
  82. $contact_id = intval($a->argv[1]);
  83. if(! $contact_id)
  84. return;
  85. $cmd = $a->argv[2];
  86. $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  87. intval($contact_id),
  88. intval(local_user())
  89. );
  90. if(! count($orig_record)) {
  91. notice( t('Could not access contact record.') . EOL);
  92. goaway($a->get_baseurl() . '/contacts');
  93. return; // NOTREACHED
  94. }
  95. if($cmd === 'update') {
  96. // pull feed and consume it, which should subscribe to the hub.
  97. proc_run('php',"include/poller.php","$contact_id");
  98. goaway($a->get_baseurl() . '/contacts/' . $contact_id);
  99. // NOTREACHED
  100. }
  101. if($cmd === 'block') {
  102. $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
  103. $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
  104. intval($blocked),
  105. intval($contact_id),
  106. intval(local_user())
  107. );
  108. if($r) {
  109. //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
  110. notice( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
  111. }
  112. goaway($a->get_baseurl() . '/contacts/' . $contact_id);
  113. return; // NOTREACHED
  114. }
  115. if($cmd === 'ignore') {
  116. $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
  117. $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
  118. intval($readonly),
  119. intval($contact_id),
  120. intval(local_user())
  121. );
  122. if($r) {
  123. notice( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
  124. }
  125. goaway($a->get_baseurl() . '/contacts/' . $contact_id);
  126. return; // NOTREACHED
  127. }
  128. if($cmd === 'drop') {
  129. // create an unfollow slap
  130. if($orig_record[0]['network'] === 'stat') {
  131. $tpl = load_view_file('view/follow_slap.tpl');
  132. $slap = replace_macros($tpl, array(
  133. '$name' => $a->user['username'],
  134. '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
  135. '$photo' => $a->contact['photo'],
  136. '$thumb' => $a->contact['thumb'],
  137. '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
  138. '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
  139. '$title' => '',
  140. '$type' => 'text',
  141. '$content' => t('stopped following'),
  142. '$nick' => $a->user['nickname'],
  143. '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
  144. '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
  145. ));
  146. if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
  147. require_once('include/salmon.php');
  148. slapper($a->user,$orig_record[0]['notify'],$slap);
  149. }
  150. }
  151. if($orig_record[0]['network'] === 'dfrn') {
  152. require_once('include/items.php');
  153. dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
  154. }
  155. contact_remove($contact_id);
  156. notice( t('Contact has been removed.') . EOL );
  157. goaway($a->get_baseurl() . '/contacts');
  158. return; // NOTREACHED
  159. }
  160. }
  161. if(($a->argc == 2) && intval($a->argv[1])) {
  162. $contact_id = intval($a->argv[1]);
  163. $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
  164. intval(local_user()),
  165. intval($contact_id)
  166. );
  167. if(! count($r)) {
  168. notice( t('Contact not found.') . EOL);
  169. return;
  170. }
  171. $tpl = load_view_file('view/contact_head.tpl');
  172. $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
  173. require_once('include/contact_selectors.php');
  174. $tpl = load_view_file("view/contact_edit.tpl");
  175. switch($r[0]['rel']) {
  176. case REL_BUD:
  177. $dir_icon = 'images/lrarrow.gif';
  178. $alt_text = t('Mutual Friendship');
  179. break;
  180. case REL_VIP;
  181. $dir_icon = 'images/larrow.gif';
  182. $alt_text = t('is a fan of yours');
  183. break;
  184. case REL_FAN;
  185. $dir_icon = 'images/rarrow.gif';
  186. $alt_text = t('you are a fan of');
  187. break;
  188. default:
  189. break;
  190. }
  191. if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
  192. $url = "redir/{$r[0]['id']}";
  193. $sparkle = ' class="sparkle" ';
  194. }
  195. else {
  196. $url = $r[0]['url'];
  197. $sparkle = '';
  198. }
  199. $insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" />&nbsp;'
  200. . t('Private communications are not available for this contact.') . '</p></div>';
  201. $last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00')
  202. ? t('Never')
  203. : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
  204. if($r[0]['last-update'] !== '0000-00-00 00:00:00')
  205. $last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
  206. $o .= replace_macros($tpl,array(
  207. '$header' => t('Contact Editor'),
  208. '$submit' => t('Submit'),
  209. '$lbl_vis1' => t('Profile Visibility'),
  210. '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
  211. '$lbl_info1' => t('Contact Information / Notes'),
  212. '$lbl_rep1' => t('Online Reputation'),
  213. '$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'),
  214. '$lbl_rep3' => t('You may help them choose whether or not to interact with this person by providing a <em>reputation</em> to guide them.'),
  215. '$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'),
  216. '$visit' => t('Visit $name\'s profile'),
  217. '$blockunblock' => t('Block/Unblock contact'),
  218. '$ignorecont' => t('Ignore contact'),
  219. '$altcrepair' => t('Repair contact URL settings'),
  220. '$lblcrepair' => t("Repair contact URL settings \x28WARNING: Advanced\x29"),
  221. '$delete' => t('Delete contact'),
  222. '$poll_interval' => contact_poll_interval($r[0]['priority']),
  223. '$lastupdtext' => t('Last updated: '),
  224. '$updpub' => t('Update public posts: '),
  225. '$last_update' => $last_update,
  226. '$udnow' => t('Update now'),
  227. '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
  228. '$contact_id' => $r[0]['id'],
  229. '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
  230. '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
  231. '$insecure' => (($r[0]['network'] !== 'dfrn') ? $insecure : ''),
  232. '$info' => $r[0]['info'],
  233. '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
  234. '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
  235. '$rating' => contact_reputation($r[0]['rating']),
  236. '$reason' => $r[0]['reason'],
  237. '$groups' => '', // group_selector(),
  238. '$photo' => $r[0]['photo'],
  239. '$name' => $r[0]['name'],
  240. '$dir_icon' => $dir_icon,
  241. '$alt_text' => $alt_text,
  242. '$sparkle' => $sparkle,
  243. '$url' => $url
  244. ));
  245. $arr = array('contact' => $r[0],'output' => $o);
  246. call_hooks('contact_edit', $arr);
  247. return $arr['output'];
  248. }
  249. if(($a->argc == 2) && ($a->argv[1] === 'all'))
  250. $sql_extra = '';
  251. else
  252. $sql_extra = " AND `blocked` = 0 ";
  253. $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
  254. $tpl = load_view_file("view/contacts-top.tpl");
  255. $o .= replace_macros($tpl,array(
  256. '$header' => t('Contacts'),
  257. '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
  258. '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
  259. '$search' => $search,
  260. '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
  261. '$submit' => t('Find'),
  262. '$cmd' => $a->cmd
  263. ));
  264. if($search)
  265. $search = dbesc($search.'*');
  266. $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
  267. $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
  268. $r = q("SELECT COUNT(*) AS `total` FROM `contact`
  269. WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
  270. intval($_SESSION['uid']));
  271. if(count($r))
  272. $a->set_pager_total($r[0]['total']);
  273. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
  274. intval($_SESSION['uid']),
  275. intval($a->pager['start']),
  276. intval($a->pager['itemspage'])
  277. );
  278. if(count($r)) {
  279. $tpl = load_view_file("view/contact_template.tpl");
  280. foreach($r as $rr) {
  281. if($rr['self'])
  282. continue;
  283. switch($rr['rel']) {
  284. case REL_BUD:
  285. $dir_icon = 'images/lrarrow.gif';
  286. $alt_text = t('Mutual Friendship');
  287. break;
  288. case REL_VIP;
  289. $dir_icon = 'images/larrow.gif';
  290. $alt_text = t('is a fan of yours');
  291. break;
  292. case REL_FAN;
  293. $dir_icon = 'images/rarrow.gif';
  294. $alt_text = t('you are a fan of');
  295. break;
  296. default:
  297. break;
  298. }
  299. if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
  300. $url = "redir/{$rr['id']}";
  301. $sparkle = ' class="sparkle" ';
  302. }
  303. else {
  304. $url = $rr['url'];
  305. $sparkle = '';
  306. }
  307. $o .= replace_macros($tpl, array(
  308. '$img_hover' => t('Visit $username\'s profile'),
  309. '$edit_hover' => t('Edit contact'),
  310. '$id' => $rr['id'],
  311. '$alt_text' => $alt_text,
  312. '$dir_icon' => $dir_icon,
  313. '$thumb' => $rr['thumb'],
  314. '$name' => substr($rr['name'],0,20),
  315. '$username' => $rr['name'],
  316. '$sparkle' => $sparkle,
  317. '$url' => $url
  318. ));
  319. }
  320. $o .= '<div id="contact-edit-end"></div>';
  321. }
  322. $o .= paginate($a);
  323. return $o;
  324. }