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.

142 lines
3.9 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_PHANTOM) {
  27. notice( t("The network type couldn't be detected. Contact can't be added.") . EOL);
  28. goaway($_SESSION['return_url']);
  29. // NOTREACHED
  30. }
  31. if ($ret["network"] == NETWORK_MAIL)
  32. $ret["url"] = $ret["addr"];
  33. if($ret['network'] === NETWORK_DFRN) {
  34. $request = $ret["request"];
  35. $tpl = get_markup_template('dfrn_request.tpl');
  36. } else {
  37. $request = $a->get_baseurl()."/follow";
  38. $tpl = get_markup_template('auto_request.tpl');
  39. }
  40. $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
  41. if (!$r) {
  42. notice( t('Permission denied.') . EOL);
  43. goaway($_SESSION['return_url']);
  44. // NOTREACHED
  45. }
  46. $myaddr = $r[0]["url"];
  47. // Makes the connection request for friendica contacts easier
  48. $_SESSION["fastlane"] = $ret["url"];
  49. $r = q("SELECT `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
  50. normalise_link($ret["url"]));
  51. $header = $ret["name"];
  52. if ($ret["addr"] != "")
  53. $header .= " <".$ret["addr"].">";
  54. $header .= " (".network_to_name($ret['network']).")";
  55. $o = replace_macros($tpl,array(
  56. '$header' => htmlentities($header),
  57. '$photo' => $ret["photo"],
  58. '$desc' => "",
  59. '$pls_answer' => t('Please answer the following:'),
  60. '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'),t('Yes'))),
  61. '$add_note' => t('Add a personal note:'),
  62. '$page_desc' => "",
  63. '$friendica' => "",
  64. '$statusnet' => "",
  65. '$diaspora' => "",
  66. '$diasnote' => "",
  67. '$your_address' => t('Your Identity Address:'),
  68. '$invite_desc' => "",
  69. '$emailnet' => "",
  70. '$submit' => t('Submit Request'),
  71. '$cancel' => t('Cancel'),
  72. '$nickname' => "",
  73. '$name' => $ret["name"],
  74. '$url' => $ret["url"],
  75. '$url_label' => t("Profile URL"),
  76. '$myaddr' => $myaddr,
  77. '$request' => $request,
  78. '$location' => bbcode($r[0]["location"]),
  79. '$location_label' => t("Location:"),
  80. '$about' => bbcode($r[0]["about"]),
  81. '$about_label' => t("About:"),
  82. '$keywords' => bbcode($r[0]["keywords"]),
  83. '$keywords_label' => t("Tags:")
  84. ));
  85. return $o;
  86. }
  87. function follow_post(&$a) {
  88. if(! local_user()) {
  89. notice( t('Permission denied.') . EOL);
  90. goaway($_SESSION['return_url']);
  91. // NOTREACHED
  92. }
  93. if ($_REQUEST['cancel'])
  94. goaway($_SESSION['return_url']);
  95. $uid = local_user();
  96. $url = notags(trim($_REQUEST['url']));
  97. $return_url = $_SESSION['return_url'];
  98. // Makes the connection request for friendica contacts easier
  99. // This is just a precaution if maybe this page is called somewhere directly via POST
  100. $_SESSION["fastlane"] = $url;
  101. $result = new_contact($uid,$url,true);
  102. if($result['success'] == false) {
  103. if($result['message'])
  104. notice($result['message']);
  105. goaway($return_url);
  106. } elseif ($result['cid'])
  107. goaway($a->get_baseurl().'/contacts/'.$result['cid']);
  108. info( t('Contact added').EOL);
  109. if(strstr($return_url,'contacts'))
  110. goaway($a->get_baseurl().'/contacts/'.$contact_id);
  111. goaway($return_url);
  112. // NOTREACHED
  113. }