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.

128 lines
3.3 KiB

11 years ago
  1. <?php
  2. require_once('include/Contact.php');
  3. require_once('include/contact_selectors.php');
  4. function viewcontacts_init(App $a) {
  5. if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
  6. return;
  7. }
  8. nav_set_selected('home');
  9. if($a->argc > 1) {
  10. $nick = $a->argv[1];
  11. $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
  12. dbesc($nick)
  13. );
  14. if (! dbm::is_result($r)) {
  15. return;
  16. }
  17. $a->data['user'] = $r[0];
  18. $a->profile_uid = $r[0]['uid'];
  19. $is_owner = (local_user() && (local_user() == $a->profile_uid));
  20. profile_load($a,$a->argv[1]);
  21. }
  22. }
  23. function viewcontacts_content(App $a) {
  24. require_once("mod/proxy.php");
  25. if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
  26. notice( t('Public access denied.') . EOL);
  27. return;
  28. }
  29. $o = "";
  30. // tabs
  31. $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']);
  32. if(((! count($a->profile)) || ($a->profile['hide-friends']))) {
  33. notice( t('Permission denied.') . EOL);
  34. return $o;
  35. }
  36. $r = q("SELECT COUNT(*) AS `total` FROM `contact`
  37. WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
  38. AND NOT `hidden` AND NOT `archive`
  39. AND `network` IN ('%s', '%s', '%s')",
  40. intval($a->profile['uid']),
  41. dbesc(NETWORK_DFRN),
  42. dbesc(NETWORK_DIASPORA),
  43. dbesc(NETWORK_OSTATUS)
  44. );
  45. if (dbm::is_result($r))
  46. $a->set_pager_total($r[0]['total']);
  47. $r = q("SELECT * FROM `contact`
  48. WHERE `uid` = %d AND NOT `blocked` AND NOT `pending`
  49. AND NOT `hidden` AND NOT `archive`
  50. AND `network` IN ('%s', '%s', '%s')
  51. ORDER BY `name` ASC LIMIT %d, %d",
  52. intval($a->profile['uid']),
  53. dbesc(NETWORK_DFRN),
  54. dbesc(NETWORK_DIASPORA),
  55. dbesc(NETWORK_OSTATUS),
  56. intval($a->pager['start']),
  57. intval($a->pager['itemspage'])
  58. );
  59. if (!dbm::is_result($r)) {
  60. info(t('No contacts.').EOL);
  61. return $o;
  62. }
  63. $contacts = array();
  64. foreach ($r as $rr) {
  65. /// @TODO This triggers an E_NOTICE if 'self' is not there
  66. if ($rr['self']) {
  67. continue;
  68. }
  69. $url = $rr['url'];
  70. // route DFRN profiles through the redirect
  71. $is_owner = ((local_user() && ($a->profile['profile_uid'] == local_user())) ? true : false);
  72. if($is_owner && ($rr['network'] === NETWORK_DFRN) && ($rr['rel']))
  73. $url = 'redir/' . $rr['id'];
  74. else
  75. $url = zrl($url);
  76. $contact_details = get_contact_details_by_url($rr['url'], $a->profile['uid'], $rr);
  77. $contacts[] = array(
  78. 'id' => $rr['id'],
  79. 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'), $contact_details['name'], $rr['url']),
  80. 'photo_menu' => contact_photo_menu($rr),
  81. 'thumb' => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
  82. 'name' => htmlentities(substr($contact_details['name'],0,20)),
  83. 'username' => htmlentities($contact_details['name']),
  84. 'details' => $contact_details['location'],
  85. 'tags' => $contact_details['keywords'],
  86. 'about' => $contact_details['about'],
  87. 'account_type' => account_type($contact_details),
  88. 'url' => $url,
  89. 'sparkle' => '',
  90. 'itemurl' => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
  91. 'network' => network_to_name($rr['network'], $rr['url']),
  92. );
  93. }
  94. $tpl = get_markup_template("viewcontact_template.tpl");
  95. $o .= replace_macros($tpl, array(
  96. '$title' => t('Contacts'),
  97. '$contacts' => $contacts,
  98. '$paginate' => paginate($a),
  99. ));
  100. return $o;
  101. }