3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Profile;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Widget;
27 use Friendica\Core\ACL;
28 use Friendica\Core\Protocol;
29 use Friendica\Core\Session;
30 use Friendica\Database\DBA;
32 use Friendica\Model\Item;
33 use Friendica\Model\Post\Category;
34 use Friendica\Model\Profile as ProfileModel;
35 use Friendica\Model\User;
36 use Friendica\Model\Verb;
37 use Friendica\Module\BaseProfile;
38 use Friendica\Module\Security\Login;
39 use Friendica\Network\HTTPException;
40 use Friendica\Protocol\Activity;
41 use Friendica\Util\DateTimeFormat;
42 use Friendica\Security\Security;
43 use Friendica\Util\Strings;
44 use Friendica\Util\XML;
46 class Status extends BaseProfile
48 public static function content(array $parameters = [])
54 ProfileModel::load($a, $parameters['nickname']);
56 if (empty($a->profile)) {
57 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
60 if (!$a->profile['net-publish']) {
61 DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
64 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', $a->profile['name']) . '"/>' . "\n";
65 DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/" title="' . DI::l10n()->t('%s\'s posts', $a->profile['name']) . '"/>' . "\n";
66 DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/comments" title="' . DI::l10n()->t('%s\'s comments', $a->profile['name']) . '"/>' . "\n";
67 DI::page()['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . DI::baseUrl() . '/feed/' . $parameters['nickname'] . '/activity" title="' . DI::l10n()->t('%s\'s timeline', $a->profile['name']) . '"/>' . "\n";
69 $category = $datequery = $datequery2 = '';
71 $dtFormat = DI::dtFormat();
73 if ($args->getArgc() > 3) {
74 for ($x = 3; $x < $args->getArgc(); $x++) {
75 if ($dtFormat->isYearMonthDay($args->get($x))) {
77 $datequery2 = Strings::escapeHtml($args->get($x));
79 $datequery = Strings::escapeHtml($args->get($x));
82 $category = $args->get($x);
87 if (empty($category)) {
88 $category = $_GET['category'] ?? '';
91 $hashtags = $_GET['tag'] ?? '';
93 if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['uid'])) {
99 if ($a->profile['uid'] == local_user()) {
100 Nav::setSelected('home');
103 $remote_contact = Session::getRemoteContactID($a->profile['uid']);
104 $is_owner = local_user() == $a->profile['uid'];
105 $last_updated_key = "profile:" . $a->profile['uid'] . ":" . local_user() . ":" . $remote_contact;
107 if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
108 notice(DI::l10n()->t('Access to this profile has been restricted.'));
112 $o .= self::getTabsHTML($a, 'status', $is_owner, $a->profile['nickname']);
114 $o .= Widget::commonFriendsVisitor($a->profile['uid'], $a->profile['nickname']);
116 $commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
117 $commvisitor = $commpage && $remote_contact;
119 DI::page()['aside'] .= Widget::postedByYear(DI::baseUrl() . '/profile/' . $a->profile['nickname'] . '/status', $a->profile['profile_uid'] ?? 0, true);
120 DI::page()['aside'] .= Widget::categories(DI::baseUrl() . '/profile/' . $a->profile['nickname'] . '/status', XML::escape($category));
121 DI::page()['aside'] .= Widget::tagCloud();
123 if (Security::canWriteToUserWall($a->profile['uid'])) {
125 'is_owner' => $is_owner,
126 'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'],
127 'default_location' => $is_owner ? $a->user['default-location'] : '',
128 'nickname' => $a->profile['nickname'],
129 'lockstate' => is_array($a->user)
130 && (strlen($a->user['allow_cid'])
131 || strlen($a->user['allow_gid'])
132 || strlen($a->user['deny_cid'])
133 || strlen($a->user['deny_gid'])
134 ) ? 'lock' : 'unlock',
135 'acl' => $is_owner ? ACL::getFullSelectorHTML(DI::page(), $a->user, true) : '',
137 'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
138 'profile_uid' => $a->profile['uid'],
141 $o .= status_editor($a, $x);
144 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
145 $condition = Item::getPermissionsConditionArrayByUserId($a->profile['uid']);
147 $last_updated_array = Session::get('last_updated', []);
149 if (!empty($category)) {
150 $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `category-view` WHERE `name` = ? AND `type` = ? AND `uid` = ?)",
151 $category, Category::CATEGORY, $a->profile['uid']]);
154 if (!empty($hashtags)) {
155 $condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `tag-search-view` WHERE `name` = ? AND `uid` = ?)",
156 $hashtags, $a->profile['uid']]);
159 if (!empty($datequery)) {
160 $condition = DBA::mergeConditions($condition, ["`received` <= ?", DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get())]);
162 if (!empty($datequery2)) {
163 $condition = DBA::mergeConditions($condition, ["`received` >= ?", DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get())]);
166 // Does the profile page belong to a forum?
167 // If not then we can improve the performance with an additional condition
168 $condition2 = ['uid' => $a->profile['uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]];
169 if (!DBA::exists('user', $condition2)) {
170 $condition = DBA::mergeConditions($condition, ['contact-id' => $a->profile['id']]);
173 if (DI::mode()->isMobile()) {
174 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
175 DI::config()->get('system', 'itemspage_network_mobile'));
177 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
178 DI::config()->get('system', 'itemspage_network'));
181 $condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
182 (`gravity` = ? AND `vid` = ? AND `origin` AND `thr-parent-id` IN
183 (SELECT `uri-id` FROM `item` AS `i`
184 WHERE `gravity` = ? AND `network` IN (?, ?, ?, ?) AND `uid` IN (?, ?)
185 AND `i`.`uri-id` = `item`.`thr-parent-id`)))",
186 GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), GRAVITY_PARENT,
187 Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::OSTATUS,
188 0, $a->profile['uid']]);
190 $condition = DBA::mergeConditions($condition, ['uid' => $a->profile['uid'], 'network' => Protocol::FEDERATED,
191 'visible' => true, 'deleted' => false, 'moderated' => false]);
193 $pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
194 $params = ['limit' => [$pager->getStart(), $pager->getItemsPerPage()], 'order' => ['received' => true]];
196 $items_stmt = DBA::select('item', ['uri', 'thr-parent-id', 'gravity', 'author-id'], $condition, $params);
198 // Set a time stamp for this page. We will make use of it when we
199 // search for new items (update routine)
200 $last_updated_array[$last_updated_key] = time();
201 Session::set('last_updated', $last_updated_array);
203 if ($is_owner && !DI::config()->get('theme', 'hide_eventlist')) {
204 $o .= ProfileModel::getBirthdays();
205 $o .= ProfileModel::getEventsReminderHTML();
209 $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
211 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
215 $items = DBA::toArray($items_stmt);
217 if ($pager->getStart() == 0 && !empty($a->profile['uid'])) {
218 $condition = ['private' => [Item::PUBLIC, Item::UNLISTED]];
219 $remote_user = Session::getRemoteContactID($a->profile['uid']);
220 if (!empty($remote_user)) {
221 $permissionSets = DI::permissionSet()->selectByContactId($remote_user, $a->profile['uid']);
222 if (!empty($permissionSets)) {
223 $condition = ['psid' => array_merge($permissionSets->column('id'),
224 [DI::permissionSet()->getIdFromACL($a->profile['uid'], '', '', '', '')])];
226 } elseif ($a->profile['uid'] == local_user()) {
230 $pinned_items = Item::selectPinned($a->profile['uid'], ['uri', 'pinned'], $condition);
231 $pinned = Item::inArray($pinned_items);
232 $items = array_merge($items, $pinned);
235 $o .= conversation($a, $items, 'profile', false, false, 'pinned_received', $a->profile['uid']);
237 $o .= $pager->renderMinimal(count($items));