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.

126 lines
3.7 KiB

10 years ago
10 years ago
  1. <?php
  2. require_once('include/Scrape.php');
  3. require_once('include/follow.php');
  4. require_once('include/contact_selectors.php');
  5. function follow_content(&$a) {
  6. if(! local_user()) {
  7. notice( t('Permission denied.') . EOL);
  8. goaway($_SESSION['return_url']);
  9. // NOTREACHED
  10. }
  11. $uid = local_user();
  12. $url = notags(trim($_REQUEST['url']));
  13. // There is a current issue. It seems as if you can't start following a Friendica that is following you
  14. // With Diaspora this works - but Friendica is special, it seems ...
  15. $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
  16. (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
  17. `network` != '%s' LIMIT 1",
  18. intval(local_user()), dbesc(CONTACT_IS_FOLLOWER), dbesc(NETWORK_DFRN), dbesc(normalise_link($url)),
  19. dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
  20. if ($r) {
  21. notice(t('You already added this contact.').EOL);
  22. goaway($_SESSION['return_url']);
  23. // NOTREACHED
  24. }
  25. $ret = probe_url($url);
  26. if ($ret["network"] == NETWORK_MAIL)
  27. $ret["url"] = $ret["addr"];
  28. if($ret['network'] === NETWORK_DFRN) {
  29. $request = $ret["request"];
  30. $tpl = get_markup_template('dfrn_request.tpl');
  31. } else {
  32. $request = $a->get_baseurl()."/follow";
  33. $tpl = get_markup_template('auto_request.tpl');
  34. }
  35. $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
  36. if (!$r) {
  37. notice( t('Permission denied.') . EOL);
  38. goaway($_SESSION['return_url']);
  39. // NOTREACHED
  40. }
  41. $myaddr = $r[0]["url"];
  42. // Makes the connection request for friendica contacts easier
  43. $_SESSION["fastlane"] = $ret["url"];
  44. $header = $ret["name"];
  45. if ($ret["addr"] != "")
  46. $header .= " <".$ret["addr"].">";
  47. $header .= " (".network_to_name($ret['network']).")";
  48. $o = replace_macros($tpl,array(
  49. '$header' => htmlentities($header),
  50. '$photo' => $ret["photo"],
  51. '$desc' => "",
  52. '$pls_answer' => t('Please answer the following:'),
  53. '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'),t('Yes'))),
  54. '$add_note' => t('Add a personal note:'),
  55. '$page_desc' => "",
  56. '$friendica' => "",
  57. '$statusnet' => "",
  58. '$diaspora' => "",
  59. '$diasnote' => "",
  60. '$your_address' => t('Your Identity Address:'),
  61. '$invite_desc' => "",
  62. '$emailnet' => "",
  63. '$submit' => t('Submit Request'),
  64. '$cancel' => t('Cancel'),
  65. '$nickname' => "",
  66. '$name' => $ret["name"],
  67. '$url' => $ret["url"],
  68. '$myaddr' => $myaddr,
  69. '$request' => $request
  70. ));
  71. return $o;
  72. }
  73. function follow_post(&$a) {
  74. if(! local_user()) {
  75. notice( t('Permission denied.') . EOL);
  76. goaway($_SESSION['return_url']);
  77. // NOTREACHED
  78. }
  79. if ($_REQUEST['cancel'])
  80. goaway($_SESSION['return_url']);
  81. $uid = local_user();
  82. $url = notags(trim($_REQUEST['url']));
  83. $return_url = $_SESSION['return_url'];
  84. // Makes the connection request for friendica contacts easier
  85. // This is just a precaution if maybe this page is called somewhere directly via POST
  86. $_SESSION["fastlane"] = $url;
  87. $result = new_contact($uid,$url,true);
  88. if($result['success'] == false) {
  89. if($result['message'])
  90. notice($result['message']);
  91. goaway($return_url);
  92. } elseif ($result['cid'])
  93. goaway($a->get_baseurl().'/contacts/'.$result['cid']);
  94. info( t('Contact added').EOL);
  95. if(strstr($return_url,'contacts'))
  96. goaway($a->get_baseurl().'/contacts/'.$contact_id);
  97. goaway($return_url);
  98. // NOTREACHED
  99. }