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.

140 lines
3.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. /**
  3. * @file mod/unfollow.php
  4. */
  5. use Friendica\App;
  6. use Friendica\Core\System;
  7. use Friendica\Database\DBM;
  8. use Friendica\Model\Contact;
  9. require_once 'include/contact_selectors.php';
  10. function unfollow_post(App $a) {
  11. if (!local_user()) {
  12. notice(t('Permission denied.') . EOL);
  13. goaway($_SESSION['return_url']);
  14. // NOTREACHED
  15. }
  16. if ($_REQUEST['cancel']) {
  17. goaway($_SESSION['return_url']);
  18. }
  19. $uid = local_user();
  20. $url = notags(trim($_REQUEST['url']));
  21. $return_url = $_SESSION['return_url'];
  22. $condition = array("`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
  23. $uid, CONTACT_IS_FRIEND, normalise_link($url),
  24. normalise_link($url), $url, NETWORK_STATUSNET);
  25. $contact = dba::select('contact', array(), $condition, array('limit' => 1));
  26. if (!DBM::is_result($contact)) {
  27. notice(t("Contact wasn't found or can't be unfollowed."));
  28. } else {
  29. if (in_array($contact['network'], array(NETWORK_OSTATUS, NETWORK_DIASPORA))) {
  30. $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
  31. WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
  32. intval($uid)
  33. );
  34. if (DBM::is_result($r)) {
  35. Contact::terminateFriendship($r[0], $contact);
  36. }
  37. }
  38. dba::update('contact', array('rel' => CONTACT_IS_FOLLOWER), array('id' => $contact['id']));
  39. info(t('Contact unfollowed').EOL);
  40. goaway(System::baseUrl().'/contacts/'.$contact['id']);
  41. }
  42. goaway($return_url);
  43. // NOTREACHED
  44. }
  45. function unfollow_content(App $a) {
  46. if (! local_user()) {
  47. notice(t('Permission denied.') . EOL);
  48. goaway($_SESSION['return_url']);
  49. // NOTREACHED
  50. }
  51. $uid = local_user();
  52. $url = notags(trim($_REQUEST['url']));
  53. $submit = t('Submit Request');
  54. $condition = array("`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?",
  55. local_user(), CONTACT_IS_FRIEND, normalise_link($url),
  56. normalise_link($url), $url, NETWORK_STATUSNET);
  57. $contact = dba::select('contact', array('url', 'network', 'addr', 'name'), $condition, array('limit' => 1));
  58. if (!DBM::is_result($contact)) {
  59. notice(t("You aren't a friend of this contact.").EOL);
  60. $submit = "";
  61. // NOTREACHED
  62. }
  63. if (!in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
  64. notice(t("Unfollowing is currently not supported by your network.").EOL);
  65. $submit = "";
  66. // NOTREACHED
  67. }
  68. $request = System::baseUrl()."/unfollow";
  69. $tpl = get_markup_template('auto_request.tpl');
  70. $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
  71. if (!$r) {
  72. notice(t('Permission denied.') . EOL);
  73. goaway($_SESSION['return_url']);
  74. // NOTREACHED
  75. }
  76. $myaddr = $r[0]["url"];
  77. // Makes the connection request for friendica contacts easier
  78. $_SESSION["fastlane"] = $contact["url"];
  79. $header = t("Disconnect/Unfollow");
  80. $o = replace_macros($tpl,array(
  81. '$header' => htmlentities($header),
  82. '$desc' => "",
  83. '$pls_answer' => "",
  84. '$does_know_you' => "",
  85. '$add_note' => "",
  86. '$page_desc' => "",
  87. '$friendica' => "",
  88. '$statusnet' => "",
  89. '$diaspora' => "",
  90. '$diasnote' => "",
  91. '$your_address' => t('Your Identity Address:'),
  92. '$invite_desc' => "",
  93. '$emailnet' => "",
  94. '$submit' => $submit,
  95. '$cancel' => t('Cancel'),
  96. '$nickname' => "",
  97. '$name' => $contact["name"],
  98. '$url' => $contact["url"],
  99. '$zrl' => zrl($contact["url"]),
  100. '$url_label' => t("Profile URL"),
  101. '$myaddr' => $myaddr,
  102. '$request' => $request,
  103. '$keywords' => "",
  104. '$keywords_label' => ""
  105. ));
  106. $a->page['aside'] = "";
  107. profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
  108. $o .= replace_macros(get_markup_template('section_title.tpl'),
  109. array('$title' => t('Status Messages and Posts')
  110. ));
  111. // Show last public posts
  112. $o .= Contact::getPostsFromUrl($contact["url"]);
  113. return $o;
  114. }