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.

194 lines
5.2 KiB

9 years ago
9 years ago
  1. <?php
  2. require_once('include/Scrape.php');
  3. require_once('include/follow.php');
  4. require_once('include/Contact.php');
  5. require_once('include/contact_selectors.php');
  6. function follow_content(App $a) {
  7. if (! local_user()) {
  8. notice( t('Permission denied.') . EOL);
  9. goaway($_SESSION['return_url']);
  10. // NOTREACHED
  11. }
  12. $uid = local_user();
  13. $url = notags(trim($_REQUEST['url']));
  14. $submit = t('Submit Request');
  15. // There is a current issue. It seems as if you can't start following a Friendica that is following you
  16. // With Diaspora this works - but Friendica is special, it seems ...
  17. $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND
  18. (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
  19. `network` != '%s' LIMIT 1",
  20. intval(local_user()), dbesc(CONTACT_IS_FOLLOWER), dbesc(NETWORK_DFRN), dbesc(normalise_link($url)),
  21. dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET));
  22. if ($r) {
  23. notice(t('You already added this contact.').EOL);
  24. $submit = "";
  25. //goaway($_SESSION['return_url']);
  26. // NOTREACHED
  27. }
  28. $ret = probe_url($url);
  29. if (($ret["network"] == NETWORK_DIASPORA) AND !get_config('system','diaspora_enabled')) {
  30. notice( t("Diaspora support isn't enabled. Contact can't be added.") . EOL);
  31. $submit = "";
  32. //goaway($_SESSION['return_url']);
  33. // NOTREACHED
  34. }
  35. if (($ret["network"] == NETWORK_OSTATUS) AND get_config('system','ostatus_disabled')) {
  36. notice( t("OStatus support is disabled. Contact can't be added.") . EOL);
  37. $submit = "";
  38. //goaway($_SESSION['return_url']);
  39. // NOTREACHED
  40. }
  41. if ($ret["network"] == NETWORK_PHANTOM) {
  42. notice( t("The network type couldn't be detected. Contact can't be added.") . EOL);
  43. $submit = "";
  44. //goaway($_SESSION['return_url']);
  45. // NOTREACHED
  46. }
  47. if ($ret["network"] == NETWORK_MAIL) {
  48. $ret["url"] = $ret["addr"];
  49. }
  50. if ($ret['network'] === NETWORK_DFRN) {
  51. $request = $ret["request"];
  52. $tpl = get_markup_template('dfrn_request.tpl');
  53. } else {
  54. $request = App::get_baseurl()."/follow";
  55. $tpl = get_markup_template('auto_request.tpl');
  56. }
  57. $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
  58. if (!$r) {
  59. notice( t('Permission denied.') . EOL);
  60. goaway($_SESSION['return_url']);
  61. // NOTREACHED
  62. }
  63. $myaddr = $r[0]["url"];
  64. $gcontact_id = 0;
  65. // Makes the connection request for friendica contacts easier
  66. $_SESSION["fastlane"] = $ret["url"];
  67. $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
  68. normalise_link($ret["url"]));
  69. if (!$r) {
  70. $r = array(array("location" => "", "about" => "", "keywords" => ""));
  71. } else {
  72. $gcontact_id = $r[0]["id"];
  73. }
  74. if ($ret['network'] === NETWORK_DIASPORA) {
  75. $r[0]["location"] = "";
  76. $r[0]["about"] = "";
  77. }
  78. $header = $ret["name"];
  79. if ($ret["addr"] != "") {
  80. $header .= " <".$ret["addr"].">";
  81. }
  82. //$header .= " (".network_to_name($ret['network'], $ret['url']).")";
  83. $header = t("Connect/Follow");
  84. $o = replace_macros($tpl,array(
  85. '$header' => htmlentities($header),
  86. //'$photo' => proxy_url($ret["photo"], false, PROXY_SIZE_SMALL),
  87. '$desc' => "",
  88. '$pls_answer' => t('Please answer the following:'),
  89. '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$ret["name"]), false, '', array(t('No'), t('Yes'))),
  90. '$add_note' => t('Add a personal note:'),
  91. '$page_desc' => "",
  92. '$friendica' => "",
  93. '$statusnet' => "",
  94. '$diaspora' => "",
  95. '$diasnote' => "",
  96. '$your_address' => t('Your Identity Address:'),
  97. '$invite_desc' => "",
  98. '$emailnet' => "",
  99. '$submit' => $submit,
  100. '$cancel' => t('Cancel'),
  101. '$nickname' => "",
  102. '$name' => $ret["name"],
  103. '$url' => $ret["url"],
  104. '$zrl' => zrl($ret["url"]),
  105. '$url_label' => t("Profile URL"),
  106. '$myaddr' => $myaddr,
  107. '$request' => $request,
  108. /*'$location' => bbcode($r[0]["location"]),
  109. '$location_label' => t("Location:"),
  110. '$about' => bbcode($r[0]["about"], false, false),
  111. '$about_label' => t("About:"), */
  112. '$keywords' => $r[0]["keywords"],
  113. '$keywords_label' => t("Tags:")
  114. ));
  115. $a->page['aside'] = "";
  116. profile_load($a, "", 0, get_contact_details_by_url($ret["url"]));
  117. if ($gcontact_id <> 0) {
  118. $o .= replace_macros(get_markup_template('section_title.tpl'),
  119. array('$title' => t('Status Messages and Posts')
  120. ));
  121. // Show last public posts
  122. $o .= posts_from_contact_url($a, $ret["url"]);
  123. }
  124. return $o;
  125. }
  126. function follow_post(App $a) {
  127. if (! local_user()) {
  128. notice( t('Permission denied.') . EOL);
  129. goaway($_SESSION['return_url']);
  130. // NOTREACHED
  131. }
  132. if ($_REQUEST['cancel']) {
  133. goaway($_SESSION['return_url']);
  134. }
  135. $uid = local_user();
  136. $url = notags(trim($_REQUEST['url']));
  137. $return_url = $_SESSION['return_url'];
  138. // Makes the connection request for friendica contacts easier
  139. // This is just a precaution if maybe this page is called somewhere directly via POST
  140. $_SESSION["fastlane"] = $url;
  141. $result = new_contact($uid,$url,true);
  142. if ($result['success'] == false) {
  143. if ($result['message']) {
  144. notice($result['message']);
  145. }
  146. goaway($return_url);
  147. } elseif ($result['cid']) {
  148. goaway(App::get_baseurl().'/contacts/'.$result['cid']);
  149. }
  150. info( t('Contact added').EOL);
  151. if (strstr($return_url,'contacts')) {
  152. goaway(App::get_baseurl().'/contacts/'.$contact_id);
  153. }
  154. goaway($return_url);
  155. // NOTREACHED
  156. }