]> git.mxchange.org Git - friendica.git/blob - src/Module/Profile/Status.php
Remove pager parameter from conversation()
[friendica.git] / src / Module / Profile / Status.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Module\Profile;
23
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Widget;
27 use Friendica\Core\ACL;
28 use Friendica\Core\Session;
29 use Friendica\Database\DBA;
30 use Friendica\DI;
31 use Friendica\Model\Item;
32 use Friendica\Model\Profile as ProfileModel;
33 use Friendica\Model\User;
34 use Friendica\Module\BaseProfile;
35 use Friendica\Module\Security\Login;
36 use Friendica\Util\DateTimeFormat;
37 use Friendica\Util\Security;
38 use Friendica\Util\Strings;
39 use Friendica\Util\XML;
40
41 class Status extends BaseProfile
42 {
43         public static function content(array $parameters = [])
44         {
45                 $args = DI::args();
46
47                 $a = DI::app();
48
49                 ProfileModel::load($a, $parameters['nickname']);
50
51                 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
52                         DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
53                 }
54
55                 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['username']) . '"/>' . "\n";
56                 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['username']) . '"/>' . "\n";
57                 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['username']) . '"/>' . "\n";
58                 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['username']) . '"/>' . "\n";
59
60                 $category = $datequery = $datequery2 = '';
61
62                 $dtFormat = DI::dtFormat();
63
64                 if ($args->getArgc() > 3) {
65                         for ($x = 3; $x < $args->getArgc(); $x++) {
66                                 if ($dtFormat->isYearMonthDay($args->get($x))) {
67                                         if ($datequery) {
68                                                 $datequery2 = Strings::escapeHtml($args->get($x));
69                                         } else {
70                                                 $datequery = Strings::escapeHtml($args->get($x));
71                                         }
72                                 } else {
73                                         $category = $args->get($x);
74                                 }
75                         }
76                 }
77
78                 if (empty($category)) {
79                         $category = $_GET['category'] ?? '';
80                 }
81
82                 $hashtags = $_GET['tag'] ?? '';
83
84                 if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['uid'])) {
85                         return Login::form();
86                 }
87
88                 $o = '';
89
90                 if ($a->profile['uid'] == local_user()) {
91                         Nav::setSelected('home');
92                 }
93
94                 $remote_contact = Session::getRemoteContactID($a->profile['uid']);
95                 $is_owner = local_user() == $a->profile['uid'];
96                 $last_updated_key = "profile:" . $a->profile['uid'] . ":" . local_user() . ":" . $remote_contact;
97
98                 if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
99                         notice(DI::l10n()->t('Access to this profile has been restricted.') . EOL);
100                         return '';
101                 }
102
103                 $o .= self::getTabsHTML($a, 'status', $is_owner, $a->profile['nickname']);
104
105                 $o .= Widget::commonFriendsVisitor($a->profile['uid']);
106
107                 $commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
108                 $commvisitor = $commpage && $remote_contact;
109
110                 DI::page()['aside'] .= Widget::postedByYear(DI::baseUrl() . '/profile/' . $a->profile['nickname'] . '/status', $a->profile['profile_uid'] ?? 0, true);
111                 DI::page()['aside'] .= Widget::categories(DI::baseUrl() . '/profile/' . $a->profile['nickname'] . '/status', XML::escape($category));
112                 DI::page()['aside'] .= Widget::tagCloud();
113
114                 if (Security::canWriteToUserWall($a->profile['uid'])) {
115                         $x = [
116                                 'is_owner' => $is_owner,
117                                 'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'],
118                                 'default_location' => $is_owner ? $a->user['default-location'] : '',
119                                 'nickname' => $a->profile['nickname'],
120                                 'lockstate' => is_array($a->user)
121                                 && (strlen($a->user['allow_cid'])
122                                         || strlen($a->user['allow_gid'])
123                                         || strlen($a->user['deny_cid'])
124                                         || strlen($a->user['deny_gid'])
125                                 ) ? 'lock' : 'unlock',
126                                 'acl' => $is_owner ? ACL::getFullSelectorHTML(DI::page(), $a->user, true) : '',
127                                 'bang' => '',
128                                 'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
129                                 'profile_uid' => $a->profile['uid'],
130                         ];
131
132                         $o .= status_editor($a, $x);
133                 }
134
135                 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
136                 $sql_extra = Item::getPermissionsSQLByUserId($a->profile['uid']);
137                 $sql_extra2 = '';
138
139                 $last_updated_array = Session::get('last_updated', []);
140
141                 $sql_post_table = "";
142
143                 if (!empty($category)) {
144                         $sql_post_table = sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
145                                 DBA::escape(Strings::protectSprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($a->profile['uid']));
146                 }
147
148                 if (!empty($hashtags)) {
149                         $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
150                                 DBA::escape(Strings::protectSprintf($hashtags)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval($a->profile['uid']));
151                 }
152
153                 if (!empty($datequery)) {
154                         $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
155                 }
156                 if (!empty($datequery2)) {
157                         $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
158                 }
159
160                 // Does the profile page belong to a forum?
161                 // If not then we can improve the performance with an additional condition
162                 $condition = ['uid' => $a->profile['uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]];
163                 if (!DBA::exists('user', $condition)) {
164                         $sql_extra3 = sprintf(" AND `thread`.`contact-id` = %d ", intval(intval($a->profile['contact_id'])));
165                 } else {
166                         $sql_extra3 = "";
167                 }
168
169                 //  check if we serve a mobile device and get the user settings
170                 //  accordingly
171                 if (DI::mode()->isMobile()) {
172                         $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', 10);
173                 } else {
174                         $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', 20);
175                 }
176
177                 //  now that we have the user settings, see if the theme forces
178                 //  a maximum item number which is lower then the user choice
179                 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
180                         $itemspage_network = $a->force_max_items;
181                 }
182
183                 $pager = new Pager($args->getQueryString(), $itemspage_network);
184
185                 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
186
187                 $items_stmt = DBA::p(
188                         "SELECT `item`.`uri`
189                         FROM `thread`
190                         STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
191                         $sql_post_table
192                         STRAIGHT_JOIN `contact`
193                         ON `contact`.`id` = `thread`.`contact-id`
194                                 AND NOT `contact`.`blocked`
195                                 AND NOT `contact`.`pending`
196                         WHERE `thread`.`uid` = ?
197                                 AND `thread`.`visible`
198                                 AND NOT `thread`.`deleted`
199                                 AND NOT `thread`.`moderated`
200                                 AND `thread`.`wall`
201                                 $sql_extra3
202                                 $sql_extra
203                                 $sql_extra2
204                         ORDER BY `thread`.`received` DESC
205                         $pager_sql",
206                         $a->profile['uid']
207                 );
208
209                 // Set a time stamp for this page. We will make use of it when we
210                 // search for new items (update routine)
211                 $last_updated_array[$last_updated_key] = time();
212                 Session::set('last_updated', $last_updated_array);
213
214                 if ($is_owner && !DI::config()->get('theme', 'hide_eventlist')) {
215                         $o .= ProfileModel::getBirthdays();
216                         $o .= ProfileModel::getEventsReminderHTML();
217                 }
218
219                 if ($is_owner) {
220                         $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
221                         if ($unseen) {
222                                 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
223                         }
224                 }
225
226                 $items = DBA::toArray($items_stmt);
227
228                 if ($pager->getStart() == 0 && !empty($a->profile['uid'])) {
229                         $pinned_items = Item::selectPinned($a->profile['uid'], ['uri', 'pinned']);
230                         $pinned = Item::inArray($pinned_items);
231                         $items = array_merge($items, $pinned);
232                 }
233
234                 $o .= conversation($a, $items, 'profile', false, false, 'pinned_received', $a->profile['uid']);
235
236                 $o .= $pager->renderMinimal(count($items));
237
238                 return $o;
239         }
240 }