From 1c26baec466171e6d4d8bbefb5924eb9ba775c63 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 28 Sep 2019 09:59:08 +0000 Subject: [PATCH] remote_user is replaced --- boot.php | 6 ++---- mod/cal.php | 5 +++-- mod/display.php | 7 ++++--- mod/item.php | 4 ++-- mod/photos.php | 17 +++++++++-------- mod/redir.php | 19 +------------------ mod/videos.php | 13 +++++++------ mod/wall_attach.php | 5 +++-- mod/wall_upload.php | 5 +++-- src/Model/Profile.php | 4 ++-- src/Module/Profile.php | 8 ++++---- 11 files changed, 40 insertions(+), 53 deletions(-) diff --git a/boot.php b/boot.php index 3aca931492..6aada42cbe 100644 --- a/boot.php +++ b/boot.php @@ -414,15 +414,13 @@ function public_contact() * * @return int|bool visitor_id or false */ -function remote_user($uid = null) +function remote_user() { if (empty($_SESSION['authenticated'])) { return false; } - if (!is_null($uid)) { - return Session::getRemoteContactID($uid); - } elseif (is_null($uid) && !empty($_SESSION['visitor_id'])) { + if (!empty($_SESSION['visitor_id'])) { return intval($_SESSION['visitor_id']); } diff --git a/mod/cal.php b/mod/cal.php index 158856d21e..7066770703 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -14,6 +14,7 @@ use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\System; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Event; @@ -109,8 +110,8 @@ function cal_content(App $a) $owner_uid = intval($a->data['user']['uid']); $nick = $a->data['user']['nickname']; - if (!empty(remote_user($a->profile['profile_uid']))) { - $contact_id = remote_user($a->profile['profile_uid']); + if (!empty(Session::getRemoteContactID($a->profile['profile_uid']))) { + $contact_id = Session::getRemoteContactID($a->profile['profile_uid']); } if ($contact_id) { diff --git a/mod/display.php b/mod/display.php index 7f77be37ef..874e2e8bf3 100644 --- a/mod/display.php +++ b/mod/display.php @@ -14,6 +14,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\Renderer; use Friendica\Core\System; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Group; @@ -53,7 +54,7 @@ function display_init(App $a) $nick = $a->user["nickname"]; } // Is this item private but could be visible to the remove visitor? - } elseif (remote_user($item['uid'])) { + } elseif (Session::getRemoteContactID($item['uid'])) { $item = Item::selectFirst($fields, ['guid' => $a->argv[1], 'private' => 1]); if (DBA::isResult($item)) { $item_user = $item['uid']; @@ -225,7 +226,7 @@ function display_content(App $a, $update = false, $update_uid = 0) $item_parent = $item["parent"]; $item_parent_uri = $item['parent-uri']; } - } elseif (remote_user($item['uid'])) { + } elseif (Session::getRemoteContactID($item['uid'])) { $item = Item::selectFirst($fields, ['guid' => $a->argv[1], 'private' => 1]); if (DBA::isResult($item)) { $item_id = $item["id"]; @@ -273,7 +274,7 @@ function display_content(App $a, $update = false, $update_uid = 0) if (DBA::isResult($parent)) { $a->profile['uid'] = defaults($a->profile, 'uid', $parent['uid']); $a->profile['profile_uid'] = defaults($a->profile, 'profile_uid', $parent['uid']); - $is_remote_contact = remote_user($a->profile['profile_uid']); + $is_remote_contact = Session::getRemoteContactID($a->profile['profile_uid']); if ($is_remote_contact) { $item_uid = $parent['uid']; } diff --git a/mod/item.php b/mod/item.php index 5ffee86a06..b059f63d1f 100644 --- a/mod/item.php +++ b/mod/item.php @@ -348,8 +348,8 @@ function item_post(App $a) { if (local_user() && ((local_user() == $profile_uid) || $allow_comment)) { $self = true; $author = DBA::selectFirst('contact', [], ['uid' => local_user(), 'self' => true]); - } elseif (!empty(remote_user($profile_uid))) { - $author = DBA::selectFirst('contact', [], ['id' => remote_user($profile_uid)]); + } elseif (!empty(Session::getRemoteContactID($profile_uid))) { + $author = DBA::selectFirst('contact', [], ['id' => Session::getRemoteContactID($profile_uid)]); } if (DBA::isResult($author)) { diff --git a/mod/photos.php b/mod/photos.php index 3bf49f37be..1514458717 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -15,6 +15,7 @@ use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\Core\System; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Group; @@ -84,7 +85,7 @@ function photos_init(App $a) { $ret['albums'] = []; foreach ($albums as $k => $album) { //hide profile photos to others - if (!$is_owner && !remote_user($a->profile_uid) && ($album['album'] == L10n::t('Profile Photos'))) + if (!$is_owner && !Session::getRemoteContactID($a->profile_uid) && ($album['album'] == L10n::t('Profile Photos'))) continue; $entry = [ 'text' => $album['album'], @@ -150,8 +151,8 @@ function photos_post(App $a) if (local_user() && (local_user() == $page_owner_uid)) { $can_post = true; - } elseif ($community_page && !empty(remote_user($page_owner_uid))) { - $contact_id = remote_user($page_owner_uid); + } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) { + $contact_id = Session::getRemoteContactID($page_owner_uid); $can_post = true; $visitor = $contact_id; } @@ -874,8 +875,8 @@ function photos_content(App $a) if (local_user() && (local_user() == $owner_uid)) { $can_post = true; - } elseif ($community_page && !empty(remote_user($owner_uid))) { - $contact_id = remote_user($owner_uid); + } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) { + $contact_id = Session::getRemoteContactID($owner_uid); $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]); if (DBA::isResult($contact)) { @@ -886,8 +887,8 @@ function photos_content(App $a) } // perhaps they're visiting - but not a community page, so they wouldn't have write access - if (!empty(remote_user($owner_uid)) && !$visitor) { - $contact_id = remote_user($owner_uid); + if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) { + $contact_id = Session::getRemoteContactID($owner_uid); $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]); @@ -1563,7 +1564,7 @@ function photos_content(App $a) $twist = false; foreach ($r as $rr) { //hide profile photos to others - if (!$is_owner && !remote_user($owner_uid) && ($rr['album'] == L10n::t('Profile Photos'))) { + if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == L10n::t('Profile Photos'))) { continue; } diff --git a/mod/redir.php b/mod/redir.php index 6b492473a0..5345b1d81b 100644 --- a/mod/redir.php +++ b/mod/redir.php @@ -66,7 +66,7 @@ function redir_init(App $a) { // with the local contact. Otherwise the local user would ask the local contact // for authentification everytime he/she is visiting a profile page of the local // contact. - if (($host == $remotehost) && (remote_user(Session::get('visitor_visiting')) == Session::get('visitor_id'))) { + if (($host == $remotehost) && (Session::getRemoteContactID(Session::get('visitor_visiting')) == Session::get('visitor_id'))) { // Remote user is already authenticated. $target_url = defaults($url, $contact_url); Logger::log($contact['name'] . " is already authenticated. Redirecting to " . $target_url, Logger::DEBUG); @@ -139,23 +139,6 @@ function redir_magic($a, $cid, $url) Logger::info('Got my url', ['visitor' => $visitor]); } - /// @todo Most likely these lines are superfluous. We will remove them in the next version - if (empty($visitor) && remote_user()) { - $contact = DBA::selectFirst('contact', ['url'], ['id' => remote_user()]); - if (!empty($contact['url'])) { - $visitor = $contact['url']; - Logger::info('Got remote user', ['visitor' => $visitor]); - } - } - - if (empty($visitor) && local_user()) { - $contact = DBA::selectFirst('contact', ['url'], ['id' => local_user()]); - if (!empty($contact['url'])) { - $visitor = $contact['url']; - Logger::info('Got local user', ['visitor' => $visitor]); - } - } - $contact = DBA::selectFirst('contact', ['url'], ['id' => $cid]); if (!DBA::isResult($contact)) { Logger::info('Contact not found', ['id' => $cid]); diff --git a/mod/videos.php b/mod/videos.php index 6ff4236a1b..fd40e79c90 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -10,6 +10,7 @@ use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\System; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\Model\Attach; use Friendica\Model\Contact; @@ -22,7 +23,7 @@ use Friendica\Util\Security; function videos_init(App $a) { - if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) { + if (Config::get('system', 'block_public') && !local_user() && !remote_user()) { return; } @@ -110,7 +111,7 @@ function videos_content(App $a) // videos/name/video/xxxxx/edit - if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) { + if (Config::get('system', 'block_public') && !local_user() && !remote_user()) { notice(L10n::t('Public access denied.') . EOL); return; } @@ -150,16 +151,16 @@ function videos_content(App $a) if ((local_user()) && (local_user() == $owner_uid)) { $can_post = true; - } elseif ($community_page && !empty(remote_user($owner_uid))) { - $contact_id = remote_user($owner_uid); + } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) { + $contact_id = Session::getRemoteContactID($owner_uid); $can_post = true; $remote_contact = true; $visitor = $contact_id; } // perhaps they're visiting - but not a community page, so they wouldn't have write access - if (!empty(remote_user($owner_uid)) && !$visitor) { - $contact_id = remote_user($owner_uid); + if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) { + $contact_id = Session::getRemoteContactID($owner_uid); $remote_contact = true; } diff --git a/mod/wall_attach.php b/mod/wall_attach.php index 096439fa74..0324a5581c 100644 --- a/mod/wall_attach.php +++ b/mod/wall_attach.php @@ -6,6 +6,7 @@ use Friendica\App; use Friendica\Core\Config; use Friendica\Core\L10n; +use Friendica\Core\Session; use Friendica\Database\DBA; use Friendica\Model\Attach; use Friendica\Model\User; @@ -45,8 +46,8 @@ function wall_attach_post(App $a) { if (local_user() && (local_user() == $page_owner_uid)) { $can_post = true; - } elseif ($community_page && !empty(remote_user($page_owner_uid))) { - $contact_id = remote_user($page_owner_uid); + } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) { + $contact_id = Session::getRemoteContactID($page_owner_uid); $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($page_owner_uid) diff --git a/mod/wall_upload.php b/mod/wall_upload.php index 0848c05906..1224b6dab0 100644 --- a/mod/wall_upload.php +++ b/mod/wall_upload.php @@ -12,6 +12,7 @@ use Friendica\App; use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\System; +use Friendica\Core\Session; use Friendica\Core\Config; use Friendica\Database\DBA; use Friendica\Model\Contact; @@ -74,8 +75,8 @@ function wall_upload_post(App $a, $desktopmode = true) if ((local_user()) && (local_user() == $page_owner_uid)) { $can_post = true; - } elseif ($community_page && !empty(remote_user($page_owner_uid))) { - $contact_id = remote_user($page_owner_uid); + } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) { + $contact_id = Session::getRemoteContactID($page_owner_uid); $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 1aaa1907ce..bdb69750dc 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -248,8 +248,8 @@ class Profile */ public static function getByNickname($nickname, $uid = 0, $profile_id = 0) { - if (!empty(remote_user($uid))) { - $contact = DBA::selectFirst('contact', ['profile-id'], ['id' => remote_user($uid)]); + if (!empty(Session::getRemoteContactID($uid))) { + $contact = DBA::selectFirst('contact', ['profile-id'], ['id' => Session::getRemoteContactID($uid)]); if (DBA::isResult($contact)) { $profile_id = $contact['profile-id']; } diff --git a/src/Module/Profile.php b/src/Module/Profile.php index d1e76bf01a..cb710b10ba 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -84,8 +84,8 @@ class Profile extends BaseModule $a->page['htmlhead'] .= "\n"; - $blocked = !local_user() && !remote_user($a->profile['profile_uid']) && Config::get('system', 'block_public'); - $userblock = !local_user() && !remote_user($a->profile['profile_uid']) && $a->profile['hidewall']; + $blocked = !local_user() && !Session::getRemoteContactID($a->profile['profile_uid']) && Config::get('system', 'block_public'); + $userblock = !local_user() && !Session::getRemoteContactID($a->profile['profile_uid']) && $a->profile['hidewall']; if (!empty($a->profile['page-flags']) && $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) { $a->page['htmlhead'] .= '' . "\n"; @@ -151,7 +151,7 @@ class Profile extends BaseModule $hashtags = defaults($_GET, 'tag', ''); - if (Config::get('system', 'block_public') && !local_user() && !remote_user($a->profile['profile_uid'])) { + if (Config::get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['profile_uid'])) { return Login::form(); } @@ -164,7 +164,7 @@ class Profile extends BaseModule Nav::setSelected('home'); } - $remote_contact = remote_user($a->profile['profile_uid']); + $remote_contact = Session::getRemoteContactID($a->profile['profile_uid']); $is_owner = local_user() == $a->profile['profile_uid']; $last_updated_key = "profile:" . $a->profile['profile_uid'] . ":" . local_user() . ":" . $remote_contact;