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.
 
 
 
 
 
 

876 lines
26 KiB

  1. <?php
  2. require_once('include/Contact.php');
  3. require_once('include/socgraph.php');
  4. require_once('include/contact_selectors.php');
  5. require_once('include/Scrape.php');
  6. require_once('mod/proxy.php');
  7. require_once('include/Photo.php');
  8. function contacts_init(&$a) {
  9. if(! local_user())
  10. return;
  11. $contact_id = 0;
  12. if(($a->argc == 2) && intval($a->argv[1])) {
  13. $contact_id = intval($a->argv[1]);
  14. $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
  15. intval(local_user()),
  16. intval($contact_id)
  17. );
  18. if(! count($r)) {
  19. $contact_id = 0;
  20. }
  21. }
  22. require_once('include/group.php');
  23. require_once('include/contact_widgets.php');
  24. if ($_GET['nets'] == "all")
  25. $_GET['nets'] = "";
  26. if(! x($a->page,'aside'))
  27. $a->page['aside'] = '';
  28. if($contact_id) {
  29. $a->data['contact'] = $r[0];
  30. $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
  31. '$name' => htmlentities($a->data['contact']['name']),
  32. '$photo' => $a->data['contact']['photo'],
  33. '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? $a->get_baseurl()."/redir/".$a->data['contact']['id'] : $a->data['contact']['url']
  34. ));
  35. $finpeople_widget = '';
  36. $follow_widget = '';
  37. $networks_widget = '';
  38. }
  39. else {
  40. $vcard_widget = '';
  41. $networks_widget .= networks_widget('contacts',$_GET['nets']);
  42. if (isset($_GET['add']))
  43. $follow_widget = follow_widget($_GET['add']);
  44. else
  45. $follow_widget = follow_widget();
  46. $findpeople_widget .= findpeople_widget();
  47. }
  48. $groups_widget .= group_side('contacts','group','full',0,$contact_id);
  49. $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
  50. '$vcard_widget' => $vcard_widget,
  51. '$findpeople_widget' => $findpeople_widget,
  52. '$follow_widget' => $follow_widget,
  53. '$groups_widget' => $groups_widget,
  54. '$networks_widget' => $networks_widget
  55. ));
  56. $base = $a->get_baseurl();
  57. $tpl = get_markup_template("contacts-head.tpl");
  58. $a->page['htmlhead'] .= replace_macros($tpl,array(
  59. '$baseurl' => $a->get_baseurl(true),
  60. '$base' => $base
  61. ));
  62. $tpl = get_markup_template("contacts-end.tpl");
  63. $a->page['end'] .= replace_macros($tpl,array(
  64. '$baseurl' => $a->get_baseurl(true),
  65. '$base' => $base
  66. ));
  67. }
  68. function contacts_batch_actions(&$a){
  69. $contacts_id = $_POST['contact_batch'];
  70. if (!is_array($contacts_id)) return;
  71. $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
  72. implode(",", $contacts_id),
  73. intval(local_user())
  74. );
  75. $count_actions=0;
  76. foreach($orig_records as $orig_record) {
  77. $contact_id = $orig_record['id'];
  78. if (x($_POST, 'contacts_batch_update')) {
  79. _contact_update($contact_id);
  80. $count_actions++;
  81. }
  82. if (x($_POST, 'contacts_batch_block')) {
  83. $r = _contact_block($contact_id, $orig_record);
  84. if ($r) $count_actions++;
  85. }
  86. if (x($_POST, 'contacts_batch_ignore')) {
  87. $r = _contact_ignore($contact_id, $orig_record);
  88. if ($r) $count_actions++;
  89. }
  90. if (x($_POST, 'contacts_batch_archive')) {
  91. $r = _contact_archive($contact_id, $orig_record);
  92. if ($r) $count_actions++;
  93. }
  94. if (x($_POST, 'contacts_batch_drop')) {
  95. _contact_drop($contact_id, $orig_record);
  96. $count_actions++;
  97. }
  98. }
  99. if ($count_actions>0) {
  100. info ( sprintf( tt("%d contact edited.", "%d contacts edited", $count_actions), $count_actions) );
  101. }
  102. if(x($_SESSION,'return_url'))
  103. goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
  104. else
  105. goaway($a->get_baseurl(true) . '/contacts');
  106. }
  107. function contacts_post(&$a) {
  108. if(! local_user())
  109. return;
  110. if ($a->argv[1]==="batch") {
  111. contacts_batch_actions($a);
  112. return;
  113. }
  114. $contact_id = intval($a->argv[1]);
  115. if(! $contact_id)
  116. return;
  117. $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  118. intval($contact_id),
  119. intval(local_user())
  120. );
  121. if(! count($orig_record)) {
  122. notice( t('Could not access contact record.') . EOL);
  123. goaway($a->get_baseurl(true) . '/contacts');
  124. return; // NOTREACHED
  125. }
  126. call_hooks('contact_edit_post', $_POST);
  127. $profile_id = intval($_POST['profile-assign']);
  128. if($profile_id) {
  129. $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  130. intval($profile_id),
  131. intval(local_user())
  132. );
  133. if(! count($r)) {
  134. notice( t('Could not locate selected profile.') . EOL);
  135. return;
  136. }
  137. }
  138. $hidden = intval($_POST['hidden']);
  139. $notify = intval($_POST['notify']);
  140. $fetch_further_information = intval($_POST['fetch_further_information']);
  141. $ffi_keyword_blacklist = fix_mce_lf(escape_tags(trim($_POST['ffi_keyword_blacklist'])));
  142. $priority = intval($_POST['poll']);
  143. if($priority > 5 || $priority < 0)
  144. $priority = 0;
  145. $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
  146. $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
  147. `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
  148. `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
  149. intval($profile_id),
  150. intval($priority),
  151. dbesc($info),
  152. intval($hidden),
  153. intval($notify),
  154. intval($fetch_further_information),
  155. dbesc($ffi_keyword_blacklist),
  156. intval($contact_id),
  157. intval(local_user())
  158. );
  159. if($r)
  160. info( t('Contact updated.') . EOL);
  161. else
  162. notice( t('Failed to update contact record.') . EOL);
  163. $r = q("select * from contact where id = %d and uid = %d limit 1",
  164. intval($contact_id),
  165. intval(local_user())
  166. );
  167. if($r && count($r))
  168. $a->data['contact'] = $r[0];
  169. return;
  170. }
  171. /*contact actions*/
  172. function _contact_update($contact_id) {
  173. $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
  174. if (!$r)
  175. return;
  176. $uid = $r[0]["uid"];
  177. if ($uid != local_user())
  178. return;
  179. if ($r[0]["network"] == NETWORK_OSTATUS) {
  180. $result = new_contact($uid, $r[0]["url"], false);
  181. if ($result['success'])
  182. $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
  183. intval($contact_id));
  184. } else
  185. // pull feed and consume it, which should subscribe to the hub.
  186. proc_run('php',"include/onepoll.php","$contact_id", "force");
  187. }
  188. function _contact_update_profile($contact_id) {
  189. $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
  190. if (!$r)
  191. return;
  192. $uid = $r[0]["uid"];
  193. if ($uid != local_user())
  194. return;
  195. $data = probe_url($r[0]["url"]);
  196. // "Feed" or "Unknown" is mostly a sign of communication problems
  197. if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
  198. return;
  199. $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
  200. "poco", "network", "alias");
  201. $update = array();
  202. if ($data["network"] == NETWORK_OSTATUS) {
  203. $result = new_contact($uid, $data["url"], false);
  204. if ($result['success'])
  205. $update["subhub"] = true;
  206. }
  207. foreach($updatefields AS $field)
  208. if (isset($data[$field]) AND ($data[$field] != ""))
  209. $update[$field] = $data[$field];
  210. $update["nurl"] = normalise_link($data["url"]);
  211. $query = "";
  212. if (isset($data["priority"]) AND ($data["priority"] != 0))
  213. $query = "`priority` = ".intval($data["priority"]);
  214. foreach($update AS $key => $value) {
  215. if ($query != "")
  216. $query .= ", ";
  217. $query .= "`".$key."` = '".dbesc($value)."'";
  218. }
  219. if ($query == "")
  220. return;
  221. $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
  222. intval($contact_id),
  223. intval(local_user())
  224. );
  225. $photos = import_profile_photo($data['photo'], local_user(), $contact_id);
  226. $r = q("UPDATE `contact` SET `photo` = '%s',
  227. `thumb` = '%s',
  228. `micro` = '%s',
  229. `name-date` = '%s',
  230. `uri-date` = '%s',
  231. `avatar-date` = '%s'
  232. WHERE `id` = %d",
  233. dbesc($photos[0]),
  234. dbesc($photos[1]),
  235. dbesc($photos[2]),
  236. dbesc(datetime_convert()),
  237. dbesc(datetime_convert()),
  238. dbesc(datetime_convert()),
  239. intval($contact_id)
  240. );
  241. }
  242. function _contact_block($contact_id, $orig_record) {
  243. $blocked = (($orig_record['blocked']) ? 0 : 1);
  244. $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
  245. intval($blocked),
  246. intval($contact_id),
  247. intval(local_user())
  248. );
  249. return $r;
  250. }
  251. function _contact_ignore($contact_id, $orig_record) {
  252. $readonly = (($orig_record['readonly']) ? 0 : 1);
  253. $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
  254. intval($readonly),
  255. intval($contact_id),
  256. intval(local_user())
  257. );
  258. return $r;
  259. }
  260. function _contact_archive($contact_id, $orig_record) {
  261. $archived = (($orig_record['archive']) ? 0 : 1);
  262. $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
  263. intval($archived),
  264. intval($contact_id),
  265. intval(local_user())
  266. );
  267. if ($archived) {
  268. q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
  269. }
  270. return $r;
  271. }
  272. function _contact_drop($contact_id, $orig_record) {
  273. require_once('include/Contact.php');
  274. $a = get_app();
  275. terminate_friendship($a->user,$a->contact,$orig_record);
  276. contact_remove($orig_record['id']);
  277. }
  278. function contacts_content(&$a) {
  279. $sort_type = 0;
  280. $o = '';
  281. nav_set_selected('contacts');
  282. if(! local_user()) {
  283. notice( t('Permission denied.') . EOL);
  284. return;
  285. }
  286. if($a->argc == 3) {
  287. $contact_id = intval($a->argv[1]);
  288. if(! $contact_id)
  289. return;
  290. $cmd = $a->argv[2];
  291. $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
  292. intval($contact_id),
  293. intval(local_user())
  294. );
  295. if(! count($orig_record)) {
  296. notice( t('Could not access contact record.') . EOL);
  297. goaway($a->get_baseurl(true) . '/contacts');
  298. return; // NOTREACHED
  299. }
  300. if($cmd === 'update') {
  301. _contact_update($contact_id);
  302. goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
  303. // NOTREACHED
  304. }
  305. if($cmd === 'updateprofile') {
  306. _contact_update_profile($contact_id);
  307. goaway($a->get_baseurl(true) . '/crepair/' . $contact_id);
  308. // NOTREACHED
  309. }
  310. if($cmd === 'block') {
  311. $r = _contact_block($contact_id, $orig_record[0]);
  312. if($r) {
  313. $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
  314. info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
  315. }
  316. goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
  317. return; // NOTREACHED
  318. }
  319. if($cmd === 'ignore') {
  320. $r = _contact_ignore($contact_id, $orig_record[0]);
  321. if($r) {
  322. $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
  323. info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
  324. }
  325. goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
  326. return; // NOTREACHED
  327. }
  328. if($cmd === 'archive') {
  329. $r = _contact_archive($contact_id, $orig_record[0]);
  330. if($r) {
  331. $archived = (($orig_record[0]['archive']) ? 0 : 1);
  332. info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
  333. }
  334. goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
  335. return; // NOTREACHED
  336. }
  337. if($cmd === 'drop') {
  338. // Check if we should do HTML-based delete confirmation
  339. if($_REQUEST['confirm']) {
  340. // <form> can't take arguments in its "action" parameter
  341. // so add any arguments as hidden inputs
  342. $query = explode_querystring($a->query_string);
  343. $inputs = array();
  344. foreach($query['args'] as $arg) {
  345. if(strpos($arg, 'confirm=') === false) {
  346. $arg_parts = explode('=', $arg);
  347. $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
  348. }
  349. }
  350. $a->page['aside'] = '';
  351. return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
  352. '$contact' => _contact_detail_for_template($orig_record[0]),
  353. '$method' => 'get',
  354. '$message' => t('Do you really want to delete this contact?'),
  355. '$extra_inputs' => $inputs,
  356. '$confirm' => t('Yes'),
  357. '$confirm_url' => $query['base'],
  358. '$confirm_name' => 'confirmed',
  359. '$cancel' => t('Cancel'),
  360. ));
  361. }
  362. // Now check how the user responded to the confirmation query
  363. if($_REQUEST['canceled']) {
  364. if(x($_SESSION,'return_url'))
  365. goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
  366. else
  367. goaway($a->get_baseurl(true) . '/contacts');
  368. }
  369. _contact_drop($contact_id, $orig_record[0]);
  370. info( t('Contact has been removed.') . EOL );
  371. if(x($_SESSION,'return_url'))
  372. goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
  373. else
  374. goaway($a->get_baseurl(true) . '/contacts');
  375. return; // NOTREACHED
  376. }
  377. }
  378. $_SESSION['return_url'] = $a->query_string;
  379. if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
  380. $contact_id = $a->data['contact']['id'];
  381. $contact = $a->data['contact'];
  382. $editselect = 'none';
  383. if( feature_enabled(local_user(),'richtext') )
  384. $editselect = 'exact';
  385. $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
  386. '$baseurl' => $a->get_baseurl(true),
  387. '$editselect' => $editselect,
  388. ));
  389. $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
  390. '$baseurl' => $a->get_baseurl(true),
  391. '$editselect' => $editselect,
  392. ));
  393. require_once('include/contact_selectors.php');
  394. $tpl = get_markup_template("contact_edit.tpl");
  395. switch($contact['rel']) {
  396. case CONTACT_IS_FRIEND:
  397. $dir_icon = 'images/lrarrow.gif';
  398. $relation_text = t('You are mutual friends with %s');
  399. break;
  400. case CONTACT_IS_FOLLOWER;
  401. $dir_icon = 'images/larrow.gif';
  402. $relation_text = t('You are sharing with %s');
  403. break;
  404. case CONTACT_IS_SHARING;
  405. $dir_icon = 'images/rarrow.gif';
  406. $relation_text = t('%s is sharing with you');
  407. break;
  408. default:
  409. break;
  410. }
  411. if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
  412. $relation_text = "";
  413. $relation_text = sprintf($relation_text,htmlentities($contact['name']));
  414. if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
  415. $url = "redir/{$contact['id']}";
  416. $sparkle = ' class="sparkle" ';
  417. }
  418. else {
  419. $url = $contact['url'];
  420. $sparkle = '';
  421. }
  422. $insecure = t('Private communications are not available for this contact.');
  423. $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
  424. ? t('Never')
  425. : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
  426. if($contact['last-update'] !== '0000-00-00 00:00:00')
  427. $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
  428. $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
  429. $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
  430. $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
  431. $common = count_common_friends(local_user(),$contact['id']);
  432. $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
  433. $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
  434. $x = count_all_friends(local_user(), $contact['id']);
  435. $all_friends = (($x) ? t('View all contacts') : '');
  436. // tabs
  437. $tabs = array(
  438. array(
  439. 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
  440. 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
  441. 'sel' => '',
  442. 'title' => t('Toggle Blocked status'),
  443. 'id' => 'toggle-block-tab',
  444. 'accesskey' => 'b',
  445. ),
  446. array(
  447. 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
  448. 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
  449. 'sel' => '',
  450. 'title' => t('Toggle Ignored status'),
  451. 'id' => 'toggle-ignore-tab',
  452. 'accesskey' => 'i',
  453. ),
  454. array(
  455. 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
  456. 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
  457. 'sel' => '',
  458. 'title' => t('Toggle Archive status'),
  459. 'id' => 'toggle-archive-tab',
  460. 'accesskey' => 'v',
  461. ),
  462. array(
  463. 'label' => t('Repair'),
  464. 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
  465. 'sel' => '',
  466. 'title' => t('Advanced Contact Settings'),
  467. 'id' => 'repair-tab',
  468. 'accesskey' => 'r',
  469. )
  470. );
  471. $tab_tpl = get_markup_template('common_tabs.tpl');
  472. $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
  473. $lost_contact = (($contact['archive'] && $contact['term-date'] != '0000-00-00 00:00:00' && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
  474. if ($contact['network'] == NETWORK_FEED)
  475. $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
  476. array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
  477. if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
  478. $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
  479. if ($contact['network'] == NETWORK_DFRN)
  480. $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
  481. if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
  482. ($contact['rel'] == CONTACT_IS_FOLLOWER))
  483. $follow = $a->get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
  484. $o .= replace_macros($tpl, array(
  485. '$header' => t('Contact Editor'),
  486. '$tab_str' => $tab_str,
  487. '$submit' => t('Submit'),
  488. '$lbl_vis1' => t('Profile Visibility'),
  489. '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
  490. '$lbl_info1' => t('Contact Information / Notes'),
  491. '$infedit' => t('Edit contact notes'),
  492. '$common_text' => $common_text,
  493. '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
  494. '$all_friends' => $all_friends,
  495. '$relation_text' => $relation_text,
  496. '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
  497. '$blockunblock' => t('Block/Unblock contact'),
  498. '$ignorecont' => t('Ignore contact'),
  499. '$lblcrepair' => t("Repair URL settings"),
  500. '$lblrecent' => t('View conversations'),
  501. '$lblsuggest' => $lblsuggest,
  502. '$delete' => t('Delete contact'),
  503. '$nettype' => $nettype,
  504. '$poll_interval' => $poll_interval,
  505. '$poll_enabled' => $poll_enabled,
  506. '$lastupdtext' => t('Last update:'),
  507. '$lost_contact' => $lost_contact,
  508. '$updpub' => t('Update public posts'),
  509. '$last_update' => $last_update,
  510. '$udnow' => t('Update now'),
  511. '$follow' => $follow,
  512. '$follow_text' => t("Connect/Follow"),
  513. '$profile_select' => $profile_select,
  514. '$contact_id' => $contact['id'],
  515. '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
  516. '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
  517. '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
  518. '$info' => $contact['info'],
  519. '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
  520. '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
  521. '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
  522. '$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')),
  523. '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
  524. '$fetch_further_information' => $fetch_further_information,
  525. '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
  526. '$ffi_keyword_blacklist' => array('ffi_keyword_blacklist', t('Blacklisted keywords'), $contact['ffi_keyword_blacklist'], t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')),
  527. '$photo' => $contact['photo'],
  528. '$name' => htmlentities($contact['name']),
  529. '$dir_icon' => $dir_icon,
  530. '$alt_text' => $alt_text,
  531. '$sparkle' => $sparkle,
  532. '$url' => $url,
  533. '$profileurllabel' => t('Profile URL'),
  534. '$profileurl' => $contact['url'],
  535. ));
  536. $arr = array('contact' => $contact,'output' => $o);
  537. call_hooks('contact_edit', $arr);
  538. return $arr['output'];
  539. }
  540. $blocked = false;
  541. $hidden = false;
  542. $ignored = false;
  543. $all = false;
  544. if(($a->argc == 2) && ($a->argv[1] === 'all')) {
  545. $sql_extra = '';
  546. $all = true;
  547. }
  548. elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
  549. $sql_extra = " AND `blocked` = 1 ";
  550. $blocked = true;
  551. }
  552. elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
  553. $sql_extra = " AND `hidden` = 1 ";
  554. $hidden = true;
  555. }
  556. elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
  557. $sql_extra = " AND `readonly` = 1 ";
  558. $ignored = true;
  559. }
  560. elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
  561. $sql_extra = " AND `archive` = 1 ";
  562. $archived = true;
  563. }
  564. else
  565. $sql_extra = " AND `blocked` = 0 ";
  566. $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
  567. $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
  568. $tabs = array(
  569. array(
  570. 'label' => t('Suggestions'),
  571. 'url' => $a->get_baseurl(true) . '/suggest',
  572. 'sel' => '',
  573. 'title' => t('Suggest potential friends'),
  574. 'id' => 'suggestions-tab',
  575. 'accesskey' => 'g',
  576. ),
  577. array(
  578. 'label' => t('All Contacts'),
  579. 'url' => $a->get_baseurl(true) . '/contacts/all',
  580. 'sel' => ($all) ? 'active' : '',
  581. 'title' => t('Show all contacts'),
  582. 'id' => 'showall-tab',
  583. 'accesskey' => 'l',
  584. ),
  585. array(
  586. 'label' => t('Unblocked'),
  587. 'url' => $a->get_baseurl(true) . '/contacts',
  588. 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
  589. 'title' => t('Only show unblocked contacts'),
  590. 'id' => 'showunblocked-tab',
  591. 'accesskey' => 'o',
  592. ),
  593. array(
  594. 'label' => t('Blocked'),
  595. 'url' => $a->get_baseurl(true) . '/contacts/blocked',
  596. 'sel' => ($blocked) ? 'active' : '',
  597. 'title' => t('Only show blocked contacts'),
  598. 'id' => 'showblocked-tab',
  599. 'accesskey' => 'b',
  600. ),
  601. array(
  602. 'label' => t('Ignored'),
  603. 'url' => $a->get_baseurl(true) . '/contacts/ignored',
  604. 'sel' => ($ignored) ? 'active' : '',
  605. 'title' => t('Only show ignored contacts'),
  606. 'id' => 'showignored-tab',
  607. 'accesskey' => 'i',
  608. ),
  609. array(
  610. 'label' => t('Archived'),
  611. 'url' => $a->get_baseurl(true) . '/contacts/archived',
  612. 'sel' => ($archived) ? 'active' : '',
  613. 'title' => t('Only show archived contacts'),
  614. 'id' => 'showarchived-tab',
  615. 'accesskey' => 'y',
  616. ),
  617. array(
  618. 'label' => t('Hidden'),
  619. 'url' => $a->get_baseurl(true) . '/contacts/hidden',
  620. 'sel' => ($hidden) ? 'active' : '',
  621. 'title' => t('Only show hidden contacts'),
  622. 'id' => 'showhidden-tab',
  623. 'accesskey' => 'h',
  624. ),
  625. );
  626. $tab_tpl = get_markup_template('common_tabs.tpl');
  627. $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
  628. $searching = false;
  629. if($search) {
  630. $search_hdr = $search;
  631. $search_txt = dbesc(protect_sprintf(preg_quote($search)));
  632. $searching = true;
  633. }
  634. $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
  635. if($nets)
  636. $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
  637. $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
  638. $r = q("SELECT COUNT(*) AS `total` FROM `contact`
  639. WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
  640. intval($_SESSION['uid']));
  641. if(count($r)) {
  642. $a->set_pager_total($r[0]['total']);
  643. $total = $r[0]['total'];
  644. }
  645. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
  646. intval($_SESSION['uid']),
  647. intval($a->pager['start']),
  648. intval($a->pager['itemspage'])
  649. );
  650. $contacts = array();
  651. if(count($r)) {
  652. foreach($r as $rr) {
  653. $contacts[] = _contact_detail_for_template($rr);
  654. }
  655. }
  656. $tpl = get_markup_template("contacts-template.tpl");
  657. $o .= replace_macros($tpl, array(
  658. '$baseurl' => $a->get_baseurl(),
  659. '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
  660. '$tabs' => $t,
  661. '$total' => $total,
  662. '$search' => $search_hdr,
  663. '$desc' => t('Search your contacts'),
  664. '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
  665. '$submit' => t('Find'),
  666. '$cmd' => $a->cmd,
  667. '$contacts' => $contacts,
  668. '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
  669. 'multiselect' => 1,
  670. '$batch_actions' => array(
  671. 'contacts_batch_update' => t('Update'),
  672. 'contacts_batch_block' => t('Block')."/".t("Unblock"),
  673. "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
  674. "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
  675. "contacts_batch_drop" => t('Delete'),
  676. ),
  677. '$paginate' => paginate($a),
  678. ));
  679. return $o;
  680. }
  681. function _contact_detail_for_template($rr){
  682. switch($rr['rel']) {
  683. case CONTACT_IS_FRIEND:
  684. $dir_icon = 'images/lrarrow.gif';
  685. $alt_text = t('Mutual Friendship');
  686. break;
  687. case CONTACT_IS_FOLLOWER;
  688. $dir_icon = 'images/larrow.gif';
  689. $alt_text = t('is a fan of yours');
  690. break;
  691. case CONTACT_IS_SHARING;
  692. $dir_icon = 'images/rarrow.gif';
  693. $alt_text = t('you are a fan of');
  694. break;
  695. default:
  696. break;
  697. }
  698. if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
  699. $url = "redir/{$rr['id']}";
  700. $sparkle = ' class="sparkle" ';
  701. }
  702. else {
  703. $url = $rr['url'];
  704. $sparkle = '';
  705. }
  706. return array(
  707. 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
  708. 'edit_hover' => t('Edit contact'),
  709. 'photo_menu' => contact_photo_menu($rr),
  710. 'id' => $rr['id'],
  711. 'alt_text' => $alt_text,
  712. 'dir_icon' => $dir_icon,
  713. 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
  714. 'name' => htmlentities($rr['name']),
  715. 'username' => htmlentities($rr['name']),
  716. 'sparkle' => $sparkle,
  717. 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
  718. 'url' => $url,
  719. 'network' => network_to_name($rr['network'], $rr['url']),
  720. );
  721. }