From e480da788e7d44f0704441f8879c5ff93d98eaf0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 30 Aug 2018 08:27:31 -0400 Subject: [PATCH 1/7] Fix unfollow for sharing-only contacts - Add removal when unfollowing sharing-only contacts --- mod/unfollow.php | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/mod/unfollow.php b/mod/unfollow.php index 5c00726e2..594217124 100644 --- a/mod/unfollow.php +++ b/mod/unfollow.php @@ -27,29 +27,37 @@ function unfollow_post(App $a) $url = notags(trim($_REQUEST['url'])); $return_url = $_SESSION['return_url']; - $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", - $uid, Contact::FRIEND, normalise_link($url), + $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", + $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url), normalise_link($url), $url, Protocol::STATUSNET]; $contact = DBA::selectFirst('contact', [], $condition); if (!DBA::isResult($contact)) { notice(L10n::t("Contact wasn't found or can't be unfollowed.")); - } else { - if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) { - $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` - WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1", - intval($uid) - ); - if (DBA::isResult($r)) { - Contact::terminateFriendship($r[0], $contact); - } - } - DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]); - - info(L10n::t('Contact unfollowed').EOL); - goaway(System::baseUrl().'/contacts/'.$contact['id']); + goaway($return_url); } - goaway($return_url); + + if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) { + $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` + WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1", + intval($uid) + ); + if (DBA::isResult($r)) { + Contact::terminateFriendship($r[0], $contact); + } + } + + // Sharing-only contacts get deleted as there no relationship any more + if ($contact['rel'] == Contact::SHARING) { + Contact::remove($contact['id']); + $return_path = 'contacts'; + } else { + DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]); + $return_path = 'contacts/' . $contact['id']; + } + + info(L10n::t('Contact unfollowed')); + goaway($return_path); // NOTREACHED } @@ -66,8 +74,8 @@ function unfollow_content(App $a) $submit = L10n::t('Submit Request'); - $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", - local_user(), Contact::FRIEND, normalise_link($url), + $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", + local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url), normalise_link($url), $url, Protocol::STATUSNET]; $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition); From b81eaec88576dbbfa5f447df18a36a1866d19a1d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 30 Aug 2018 08:52:15 -0400 Subject: [PATCH 2/7] Enable unfollowing contacts from all networks (but Statusnet) --- mod/contacts.php | 2 +- mod/unfollow.php | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/mod/contacts.php b/mod/contacts.php index 4e8769717..38896a611 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -595,7 +595,7 @@ function contacts_content(App $a, $update = 0) /// @todo Only show the following link with DFRN when the remote version supports it $follow = ''; $follow_text = ''; - if (in_array($contact['network'], [Protocol::DIASPORA, Protocol::OSTATUS, Protocol::DFRN])) { + if ($contact['network'] != Protocol::STATUSNET) { if (in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) { $follow = System::baseUrl(true) . "/unfollow?url=" . urlencode($contact["url"]); $follow_text = L10n::t("Disconnect/Unfollow"); diff --git a/mod/unfollow.php b/mod/unfollow.php index 594217124..4bc64e4fc 100644 --- a/mod/unfollow.php +++ b/mod/unfollow.php @@ -28,13 +28,20 @@ function unfollow_post(App $a) $return_url = $_SESSION['return_url']; $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", - $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url), - normalise_link($url), $url, Protocol::STATUSNET]; + $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url), + normalise_link($url), $url]; $contact = DBA::selectFirst('contact', [], $condition); if (!DBA::isResult($contact)) { - notice(L10n::t("Contact wasn't found or can't be unfollowed.")); + notice(L10n::t("You aren't following this contact.")); goaway($return_url); + // NOTREACHED + } + + if ($contact['network'] == Protocol::STATUSNET) { + notice(L10n::t('Unfollowing is currently not supported by your network.')); + goaway($return_url); + // NOTREACHED } if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) { @@ -74,21 +81,21 @@ function unfollow_content(App $a) $submit = L10n::t('Submit Request'); - $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", - local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url), - normalise_link($url), $url, Protocol::STATUSNET]; + $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)", + local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url), + normalise_link($url), $url]; $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition); if (!DBA::isResult($contact)) { - notice(L10n::t("You aren't a friend of this contact.").EOL); - $submit = ""; + notice(L10n::t("You aren't following this contact.")); + goaway('contacts'); // NOTREACHED } - if (!in_array($contact['network'], [Protocol::DIASPORA, Protocol::OSTATUS, Protocol::DFRN])) { - notice(L10n::t("Unfollowing is currently not supported by your network.").EOL); - $submit = ""; + if ($contact['network'] == Protocol::STATUSNET) { + notice(L10n::t('Unfollowing is currently not supported by your network.')); + goaway('contacts/' . $contact['id']); // NOTREACHED } From 55c676d8b0074bf534049cd54dd1eae646a6c590 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 30 Aug 2018 08:54:12 -0400 Subject: [PATCH 3/7] Source cleaning mod/unfollow.php - Normalize quotes - Remove unneeded EOL - Use DBA method where tasteful --- mod/unfollow.php | 89 +++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/mod/unfollow.php b/mod/unfollow.php index 4bc64e4fc..f82796a6b 100644 --- a/mod/unfollow.php +++ b/mod/unfollow.php @@ -11,21 +11,22 @@ use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Profile; -function unfollow_post(App $a) +function unfollow_post() { + $return_url = $_SESSION['return_url']; + if (!local_user()) { - notice(L10n::t('Permission denied.') . EOL); - goaway($_SESSION['return_url']); + notice(L10n::t('Permission denied.')); + goaway($return_url); // NOTREACHED } if ($_REQUEST['cancel']) { - goaway($_SESSION['return_url']); + goaway($return_url); } $uid = local_user(); - $url = notags(trim($_REQUEST['url'])); - $return_url = $_SESSION['return_url']; + $url = notags(trim(defaults($_REQUEST, 'url', ''))); $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url), @@ -70,8 +71,8 @@ function unfollow_post(App $a) function unfollow_content(App $a) { - if (! local_user()) { - notice(L10n::t('Permission denied.') . EOL); + if (!local_user()) { + notice(L10n::t('Permission denied.')); goaway($_SESSION['return_url']); // NOTREACHED } @@ -79,8 +80,6 @@ function unfollow_content(App $a) $uid = local_user(); $url = notags(trim($_REQUEST['url'])); - $submit = L10n::t('Submit Request'); - $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)", local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url), normalise_link($url), $url]; @@ -99,58 +98,56 @@ function unfollow_content(App $a) // NOTREACHED } - $request = System::baseUrl()."/unfollow"; + $request = System::baseUrl() . '/unfollow'; $tpl = get_markup_template('auto_request.tpl'); - $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid)); + $self = DBA::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]); - if (!$r) { - notice(L10n::t('Permission denied.') . EOL); + if (!DBA::isResult($self)) { + notice(L10n::t('Permission denied.')); goaway($_SESSION['return_url']); // NOTREACHED } - $myaddr = $r[0]["url"]; - // Makes the connection request for friendica contacts easier - $_SESSION["fastlane"] = $contact["url"]; + $_SESSION['fastlane'] = $contact['url']; - $header = L10n::t("Disconnect/Unfollow"); + $header = L10n::t('Disconnect/Unfollow'); - $o = replace_macros($tpl, [ - '$header' => htmlentities($header), - '$desc' => "", - '$pls_answer' => "", - '$does_know_you' => "", - '$add_note' => "", - '$page_desc' => "", - '$friendica' => "", - '$statusnet' => "", - '$diaspora' => "", - '$diasnote' => "", - '$your_address' => L10n::t('Your Identity Address:'), - '$invite_desc' => "", - '$emailnet' => "", - '$submit' => $submit, - '$cancel' => L10n::t('Cancel'), - '$nickname' => "", - '$name' => $contact["name"], - '$url' => $contact["url"], - '$zrl' => Contact::magicLink($contact["url"]), - '$url_label' => L10n::t("Profile URL"), - '$myaddr' => $myaddr, - '$request' => $request, - '$keywords' => "", - '$keywords_label' => "" + $o = replace_macros($tpl, [ + '$header' => htmlentities($header), + '$desc' => '', + '$pls_answer' => '', + '$does_know_you' => '', + '$add_note' => '', + '$page_desc' => '', + '$friendica' => '', + '$statusnet' => '', + '$diaspora' => '', + '$diasnote' => '', + '$your_address' => L10n::t('Your Identity Address:'), + '$invite_desc' => '', + '$emailnet' => '', + '$submit' => L10n::t('Submit Request'), + '$cancel' => L10n::t('Cancel'), + '$nickname' => '', + '$name' => $contact['name'], + '$url' => $contact['url'], + '$zrl' => Contact::magicLink($contact['url']), + '$url_label' => L10n::t('Profile URL'), + '$myaddr' => $self['url'], + '$request' => $request, + '$keywords' => '', + '$keywords_label'=> '' ]); - $a->page['aside'] = ""; - Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"])); + $a->page['aside'] = ''; + Profile::load($a, '', 0, Contact::getDetailsByURL($contact['url'])); $o .= replace_macros(get_markup_template('section_title.tpl'), ['$title' => L10n::t('Status Messages and Posts')]); // Show last public posts - $o .= Contact::getPostsFromUrl($contact["url"]); + $o .= Contact::getPostsFromUrl($contact['url']); return $o; } From 804cfa03200456116db0c96b7f2ae6e3b7bdbfd8 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 30 Aug 2018 17:47:48 -0400 Subject: [PATCH 4/7] Reorganize Protocol constants - Add ActivityPub protocol constant - Add Protocol::NATIVE_SUPPORT - Sort/group constant names --- src/Core/Protocol.php | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/Core/Protocol.php b/src/Core/Protocol.php index 4467bf002..9e96b7db2 100644 --- a/src/Core/Protocol.php +++ b/src/Core/Protocol.php @@ -13,27 +13,33 @@ use Friendica\Util\Network; */ class Protocol { - const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations - const DIASPORA = 'dspr'; // Diaspora - const DIASPORA2 = 'dspc'; // Diaspora connector - const STATUSNET = 'stac'; // Statusnet connector - const OSTATUS = 'stat'; // GNU-social, Pleroma, Mastodon, other OStatus implementations - const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol - const MAIL = 'mail'; // IMAP/POP - const XMPP = 'xmpp'; // XMPP - Currently unsupported + // Native support + const ACTIVITYPUB = 'apub'; // ActivityPub + const DFRN = 'dfrn'; // Friendica, Mistpark, other DFRN implementations + const DIASPORA = 'dspr'; // Diaspora + const FEED = 'feed'; // RSS/Atom feeds with no known "post/notify" protocol + const MAIL = 'mail'; // IMAP/POP + const OSTATUS = 'stat'; // GNU-social, Pleroma, Mastodon, other OStatus implementations - const FACEBOOK = 'face'; // Facebook API - const LINKEDIN = 'lnkd'; // LinkedIn - const MYSPACE = 'mysp'; // MySpace - Currently unsupported - const GPLUS = 'goog'; // Google+ - const PUMPIO = 'pump'; // pump.io - const TWITTER = 'twit'; // Twitter + const NATIVE_SUPPORT = [self::DFRN, self::DIASPORA, self::OSTATUS, self::FEED, self::MAIL, self::ACTIVITYPUB]; + + // Supported through a connector const APPNET = 'apdn'; // app.net - Dead protocol + const DIASPORA2 = 'dspc'; // Diaspora connector + const FACEBOOK = 'face'; // Facebook API + const GPLUS = 'goog'; // Google+ + const LINKEDIN = 'lnkd'; // LinkedIn + const PUMPIO = 'pump'; // pump.io + const STATUSNET = 'stac'; // Statusnet connector + const TWITTER = 'twit'; // Twitter - const NEWS = 'nntp'; // Network News Transfer Protocol - Currently unsupported - const ICALENDAR = 'ical'; // iCalendar - Currently unsupported - const PNUT = 'pnut'; // pnut.io - Currently unsupported - const ZOT = 'zot!'; // Zot! - Currently unsupported + // Currently unsupported + const ICALENDAR = 'ical'; // iCalendar + const MYSPACE = 'mysp'; // MySpace + const NEWS = 'nntp'; // Network News Transfer Protocol + const PNUT = 'pnut'; // pnut.io + const XMPP = 'xmpp'; // XMPP + const ZOT = 'zot!'; // Zot! const PHANTOM = 'unkn'; // Place holder From 92c4ca091193e571d76a9db7b2d4078e2b3dc473 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 30 Aug 2018 17:53:23 -0400 Subject: [PATCH 5/7] Prevent unfollowing contacts from networks not supported natively --- mod/unfollow.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mod/unfollow.php b/mod/unfollow.php index f82796a6b..30aca5688 100644 --- a/mod/unfollow.php +++ b/mod/unfollow.php @@ -39,20 +39,18 @@ function unfollow_post() // NOTREACHED } - if ($contact['network'] == Protocol::STATUSNET) { + if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) { notice(L10n::t('Unfollowing is currently not supported by your network.')); goaway($return_url); // NOTREACHED } - if (in_array($contact['network'], [Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) { - $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` - WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1", - intval($uid) - ); - if (DBA::isResult($r)) { - Contact::terminateFriendship($r[0], $contact); - } + $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` + WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1", + intval($uid) + ); + if (DBA::isResult($r)) { + Contact::terminateFriendship($r[0], $contact); } // Sharing-only contacts get deleted as there no relationship any more @@ -92,7 +90,7 @@ function unfollow_content(App $a) // NOTREACHED } - if ($contact['network'] == Protocol::STATUSNET) { + if (!in_array($contact['network'], Protocol::NATIVE_SUPPORT)) { notice(L10n::t('Unfollowing is currently not supported by your network.')); goaway('contacts/' . $contact['id']); // NOTREACHED From e25c579c76b0721b06c477f82356cc2e824ce53a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 30 Aug 2018 21:03:57 -0400 Subject: [PATCH 6/7] Add Protocol::NATIVE_SUPPORT constant usage to mod/contacts --- mod/contacts.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mod/contacts.php b/mod/contacts.php index 38896a611..227a48b96 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -595,17 +595,12 @@ function contacts_content(App $a, $update = 0) /// @todo Only show the following link with DFRN when the remote version supports it $follow = ''; $follow_text = ''; - if ($contact['network'] != Protocol::STATUSNET) { - if (in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) { + if (in_array($contact['rel'], [Contact::FRIEND, Contact::SHARING])) { + if (in_array($contact['network'], Protocol::NATIVE_SUPPORT)) { $follow = System::baseUrl(true) . "/unfollow?url=" . urlencode($contact["url"]); $follow_text = L10n::t("Disconnect/Unfollow"); - } else { - $follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]); - $follow_text = L10n::t("Connect/Follow"); } - } - - if ($contact['uid'] == 0) { + } else { $follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]); $follow_text = L10n::t("Connect/Follow"); } From 76b40cf05ec201811aedb22df0217bd027ebcbd1 Mon Sep 17 00:00:00 2001 From: Benjamin Lorteau Date: Fri, 31 Aug 2018 11:22:51 -0400 Subject: [PATCH 7/7] Use User::getOwnerDataById in mod/unfollow --- mod/unfollow.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mod/unfollow.php b/mod/unfollow.php index 30aca5688..0af16ec67 100644 --- a/mod/unfollow.php +++ b/mod/unfollow.php @@ -10,6 +10,7 @@ use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Profile; +use Friendica\Model\User; function unfollow_post() { @@ -45,12 +46,9 @@ function unfollow_post() // NOTREACHED } - $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` - WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1", - intval($uid) - ); - if (DBA::isResult($r)) { - Contact::terminateFriendship($r[0], $contact); + $owner = User::getOwnerDataById($uid); + if ($owner) { + Contact::terminateFriendship($owner, $contact); } // Sharing-only contacts get deleted as there no relationship any more