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