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.

175 lines
4.8 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
  1. <?php
  2. require_once('Scrape.php');
  3. function follow_post(&$a) {
  4. if(! local_user()) {
  5. notice( t('Permission denied.') . EOL);
  6. goaway($_SESSION['return_url']);
  7. // NOTREACHED
  8. }
  9. $url = $orig_url = notags(trim($_POST['url']));
  10. // remove ajax junk, e.g. Twitter
  11. $url = str_replace('/#!/','/',$url);
  12. if(! allowed_url($url)) {
  13. notice( t('Disallowed profile URL.') . EOL);
  14. goaway($_SESSION['return_url']);
  15. // NOTREACHED
  16. }
  17. $ret = probe_url($url);
  18. if($ret['network'] === NETWORK_DFRN) {
  19. if(strlen($a->path))
  20. $myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']);
  21. else
  22. $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname());
  23. goaway($ret['request'] . "&addr=$myaddr");
  24. // NOTREACHED
  25. }
  26. // do we have enough information?
  27. if(! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) {
  28. notice( t('The profile address specified does not provide adequate information.') . EOL);
  29. if(! x($ret,'poll'))
  30. notice( t('No compatible communication protocols or feeds were discovered.') . EOL);
  31. if(! x($ret,'name'))
  32. notice( t('An author or name was not found.') . EOL);
  33. if(! x($ret,'url'))
  34. notice( t('No browser URL could be matched to this address.') . EOL);
  35. if(strpos($url,'@') !== false)
  36. notice('Unable to match @-style Identity Address with a known protocol or email contact');
  37. goaway($_SESSION['return_url']);
  38. }
  39. if(! $ret['notify']) {
  40. notice( t('Limited profile. This person will be unable to receive direct/personal notifications from you.') . EOL);
  41. }
  42. $writeable = ((($ret['network'] === NETWORK_OSTATUS) && ($ret['notify'])) ? 1 : 0);
  43. if($ret['network'] === NETWORK_MAIL) {
  44. $writeable = 1;
  45. }
  46. // check if we already have a contact
  47. // the poll url is more reliable than the profile url, as we may have
  48. // indirect links or webfinger links
  49. $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `poll` = '%s' LIMIT 1",
  50. intval(local_user()),
  51. dbesc($ret['poll'])
  52. );
  53. if(count($r)) {
  54. // update contact
  55. if($r[0]['rel'] == REL_VIP) {
  56. q("UPDATE `contact` SET `rel` = %d , `readonly` = 0 WHERE `id` = %d AND `uid` = %d LIMIT 1",
  57. intval(REL_BUD),
  58. intval($r[0]['id']),
  59. intval(local_user())
  60. );
  61. }
  62. }
  63. else {
  64. // create contact record
  65. $r = q("INSERT INTO `contact` ( `uid`, `created`, `url`, `addr`, `alias`, `notify`, `poll`, `name`, `nick`, `photo`, `network`, `rel`, `priority`,
  66. `writable`, `blocked`, `readonly`, `pending` )
  67. VALUES ( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, 0, 0, 0 ) ",
  68. intval(local_user()),
  69. dbesc(datetime_convert()),
  70. dbesc($ret['url']),
  71. dbesc($ret['addr']),
  72. dbesc($ret['alias']),
  73. dbesc($ret['notify']),
  74. dbesc($ret['poll']),
  75. dbesc($ret['name']),
  76. dbesc($ret['nick']),
  77. dbesc($ret['photo']),
  78. dbesc($ret['network']),
  79. intval(($ret['network'] === NETWORK_MAIL) ? REL_BUD : REL_FAN),
  80. intval($ret['priority']),
  81. intval($writeable)
  82. );
  83. }
  84. $r = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
  85. dbesc($ret['url']),
  86. intval(local_user())
  87. );
  88. if(! count($r)) {
  89. notice( t('Unable to retrieve contact information.') . EOL);
  90. goaway($_SESSION['return_url']);
  91. // NOTREACHED
  92. }
  93. $contact = $r[0];
  94. $contact_id = $r[0]['id'];
  95. require_once("Photo.php");
  96. $photos = import_profile_photo($ret['photo'],local_user(),$contact_id);
  97. $r = q("UPDATE `contact` SET `photo` = '%s',
  98. `thumb` = '%s',
  99. `micro` = '%s',
  100. `name-date` = '%s',
  101. `uri-date` = '%s',
  102. `avatar-date` = '%s'
  103. WHERE `id` = %d LIMIT 1
  104. ",
  105. dbesc($photos[0]),
  106. dbesc($photos[1]),
  107. dbesc($photos[2]),
  108. dbesc(datetime_convert()),
  109. dbesc(datetime_convert()),
  110. dbesc(datetime_convert()),
  111. intval($contact_id)
  112. );
  113. // pull feed and consume it, which should subscribe to the hub.
  114. proc_run('php',"include/poller.php","$contact_id");
  115. // create a follow slap
  116. $tpl = get_markup_template('follow_slap.tpl');
  117. $slap = replace_macros($tpl, array(
  118. '$name' => $a->user['username'],
  119. '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
  120. '$photo' => $a->contact['photo'],
  121. '$thumb' => $a->contact['thumb'],
  122. '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
  123. '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':follow:' . random_string(),
  124. '$title' => '',
  125. '$type' => 'text',
  126. '$content' => t('following'),
  127. '$nick' => $a->user['nickname'],
  128. '$verb' => ACTIVITY_FOLLOW,
  129. '$ostat_follow' => ''
  130. ));
  131. $r = q("SELECT `contact`.*, `user`.* FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
  132. WHERE `user`.`uid` = %d AND `contact`.`self` = 1 LIMIT 1",
  133. intval(local_user())
  134. );
  135. if((count($r)) && (x($contact,'notify')) && (strlen($contact['notify']))) {
  136. require_once('include/salmon.php');
  137. slapper($r[0],$contact['notify'],$slap);
  138. }
  139. goaway($_SESSION['return_url']);
  140. // NOTREACHED
  141. }