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