]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Profile/Status.php
Move missing POST part of Profile\Photos from mod/photos
[friendica.git] / src / Module / Profile / Status.php
index c2d691f1cf1e63139704b53e364bbeed784f8a7f..0a4a17e462e1b3deb9d0145235834105be2ef50c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -26,9 +26,9 @@ use Friendica\Content\Pager;
 use Friendica\Content\Widget;
 use Friendica\Core\ACL;
 use Friendica\Core\Protocol;
-use Friendica\Core\Session;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Model\Post\Category;
@@ -46,13 +46,13 @@ use Friendica\Util\XML;
 
 class Status extends BaseProfile
 {
-       public static function content(array $parameters = [])
+       protected function content(array $request = []): string
        {
                $args = DI::args();
 
                $a = DI::app();
 
-               $profile = ProfileModel::load($a, $parameters['nickname']);
+               $profile = ProfileModel::load($a, $this->parameters['nickname']);
 
                if (empty($profile)) {
                        throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
@@ -62,10 +62,10 @@ class Status extends BaseProfile
                        DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
                }
 
-               DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/dfrn_poll/' . $parameters['nickname'] . '" title="DFRN: ' . DI::l10n()->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
-               DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/" title="' . DI::l10n()->t('%s\'s posts', $profile['name']) . '"/>' . "\n";
-               DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/comments" title="' . DI::l10n()->t('%s\'s comments', $profile['name']) . '"/>' . "\n";
-               DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
+               DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/dfrn_poll/' . $this->parameters['nickname'] . '" title="DFRN: ' . DI::l10n()->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
+               DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $this->parameters['nickname'] . '/" title="' . DI::l10n()->t('%s\'s posts', $profile['name']) . '"/>' . "\n";
+               DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $this->parameters['nickname'] . '/comments" title="' . DI::l10n()->t('%s\'s comments', $profile['name']) . '"/>' . "\n";
+               DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $this->parameters['nickname'] . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $profile['name']) . '"/>' . "\n";
 
                $category = $datequery = $datequery2 = '';
 
@@ -91,26 +91,25 @@ class Status extends BaseProfile
 
                $hashtags = $_GET['tag'] ?? '';
 
-               if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($profile['uid'])) {
+               if (DI::config()->get('system', 'block_public') && !DI::userSession()->getLocalUserId() && !DI::userSession()->getRemoteContactID($profile['uid'])) {
                        return Login::form();
                }
 
                $o = '';
 
-               if ($profile['uid'] == local_user()) {
+               if ($profile['uid'] == DI::userSession()->getLocalUserId()) {
                        Nav::setSelected('home');
                }
 
-               $remote_contact = Session::getRemoteContactID($profile['uid']);
-               $is_owner = local_user() == $profile['uid'];
-               $last_updated_key = "profile:" . $profile['uid'] . ":" . local_user() . ":" . $remote_contact;
+               $remote_contact = DI::userSession()->getRemoteContactID($profile['uid']);
+               $is_owner = DI::userSession()->getLocalUserId() == $profile['uid'];
+               $last_updated_key = "profile:" . $profile['uid'] . ":" . DI::userSession()->getLocalUserId() . ":" . $remote_contact;
 
-               if (!empty($profile['hidewall']) && !$is_owner && !$remote_contact) {
-                       notice(DI::l10n()->t('Access to this profile has been restricted.'));
-                       return '';
+               if (!empty($profile['hidewall']) && !DI::userSession()->isAuthenticated()) {
+                       $this->baseUrl->redirect('profile/' . $profile['nickname'] . '/restricted');
                }
 
-               $o .= self::getTabsHTML($a, 'status', $is_owner, $profile['nickname'], $profile['hide-friends']);
+               $o .= self::getTabsHTML('status', $is_owner, $profile['nickname'], $profile['hide-friends']);
 
                $o .= Widget::commonFriendsVisitor($profile['uid'], $profile['nickname']);
 
@@ -118,7 +117,7 @@ class Status extends BaseProfile
                $commvisitor = $commpage && $remote_contact;
 
                DI::page()['aside'] .= Widget::postedByYear(DI::baseUrl() . '/profile/' . $profile['nickname'] . '/status', $profile['profile_uid'] ?? 0, true);
-               DI::page()['aside'] .= Widget::categories(DI::baseUrl() . '/profile/' . $profile['nickname'] . '/status', XML::escape($category));
+               DI::page()['aside'] .= Widget::categories($profile['uid'], DI::baseUrl() . '/profile/' . $profile['nickname'] . '/status', $category);
                DI::page()['aside'] .= Widget::tagCloud($profile['uid']);
 
                if (Security::canWriteToUserWall($profile['uid'])) {
@@ -138,7 +137,7 @@ class Status extends BaseProfile
                // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
                $condition = Item::getPermissionsConditionArrayByUserId($profile['uid']);
 
-               $last_updated_array = Session::get('last_updated', []);
+               $last_updated_array = DI::session()->get('last_updated', []);
 
                if (!empty($category)) {
                        $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `category-view` WHERE `name` = ? AND `type` = ? AND `uid` = ?)",
@@ -159,25 +158,23 @@ class Status extends BaseProfile
 
                // Does the profile page belong to a forum?
                // If not then we can improve the performance with an additional condition
-               $condition2 = ['uid' => $profile['uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]];
+               $condition2 = ['uid' => $profile['uid'], 'account-type' => User::ACCOUNT_TYPE_COMMUNITY];
                if (!DBA::exists('user', $condition2)) {
                        $condition = DBA::mergeConditions($condition, ['contact-id' => $profile['id']]);
                }
 
                if (DI::mode()->isMobile()) {
-                       $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
+                       $itemspage_network = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
                                DI::config()->get('system', 'itemspage_network_mobile'));
                } else {
-                       $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
+                       $itemspage_network = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
                                DI::config()->get('system', 'itemspage_network'));
                }
 
                $condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
                        (`gravity` = ? AND `vid` = ? AND `origin`
-                       AND EXISTS(SELECT `uri-id` FROM `post` WHERE `gravity` = ? AND `network` IN (?, ?, ?, ?)
-                               AND `uri-id` = `post-user-view`.`thr-parent-id`)))",
-                       GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), GRAVITY_PARENT,
-                       Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::OSTATUS]);
+                       AND `thr-parent-id` IN (SELECT `uri-id` FROM `post` WHERE `gravity` = ? AND `network` IN (?, ?))))",
+                       Item::GRAVITY_PARENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Item::GRAVITY_PARENT, Protocol::ACTIVITYPUB, Protocol::DFRN]);
 
                $condition = DBA::mergeConditions($condition, ['uid' => $profile['uid'], 'network' => Protocol::FEDERATED,
                        'visible' => true, 'deleted' => false]);
@@ -190,7 +187,7 @@ class Status extends BaseProfile
                // Set a time stamp for this page. We will make use of it when we
                // search for new items (update routine)
                $last_updated_array[$last_updated_key] = time();
-               Session::set('last_updated', $last_updated_array);
+               DI::session()->set('last_updated', $last_updated_array);
 
                if ($is_owner && !DI::config()->get('theme', 'hide_eventlist')) {
                        $o .= ProfileModel::getBirthdays();
@@ -198,29 +195,17 @@ class Status extends BaseProfile
                }
 
                if ($is_owner) {
-                       $unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
+                       $unseen = Post::exists(['wall' => true, 'unseen' => true, 'uid' => DI::userSession()->getLocalUserId()]);
                        if ($unseen) {
-                               Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
+                               Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => DI::userSession()->getLocalUserId()]);
                        }
                }
 
                $items = Post::toArray($items_stmt);
 
                if ($pager->getStart() == 0 && !empty($profile['uid'])) {
-                       $condition = ['private' => [Item::PUBLIC, Item::UNLISTED]];
-                       $remote_user = Session::getRemoteContactID($profile['uid']);
-                       if (!empty($remote_user)) {
-                               $permissionSets = DI::permissionSet()->selectByContactId($remote_user, $profile['uid']);
-                               if (!empty($permissionSets)) {
-                                       $condition = ['psid' => array_merge($permissionSets->column('id'),
-                                                       [DI::permissionSet()->selectPublic($profile['uid'])->id])];
-                               }
-                       } elseif ($profile['uid'] == local_user()) {
-                               $condition = [];
-                       }
-       
-                       $pinned_items = Post::selectPinned($profile['uid'], ['uri-id', 'pinned'], $condition);
-                       $pinned = Post::toArray($pinned_items);
+                       $pcid = Contact::getPublicIdByUserId($profile['uid']);
+                       $pinned = Post\Collection::selectToArrayForContact($pcid, Post\Collection::FEATURED);
                        $items = array_merge($items, $pinned);
                }