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