3 namespace Friendica\Module\Profile;
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;
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;
22 class Status extends BaseProfile
24 public static function content(array $parameters = [])
30 ProfileModel::load($a, $parameters['nickname']);
32 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
33 DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
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";
41 $category = $datequery = $datequery2 = '';
43 $dtFormat = DI::dtFormat();
45 if ($args->getArgc() > 3) {
46 for ($x = 3; $x < $args->getArgc(); $x++) {
47 if ($dtFormat->isYearMonth($args->get($x))) {
49 $datequery2 = Strings::escapeHtml($args->get($x));
51 $datequery = Strings::escapeHtml($args->get($x));
54 $category = $args->get($x);
59 if (empty($category)) {
60 $category = $_GET['category'] ?? '';
63 $hashtags = $_GET['tag'] ?? '';
65 if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['uid'])) {
71 if ($a->profile['uid'] == local_user()) {
72 Nav::setSelected('home');
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;
79 if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
80 notice(DI::l10n()->t('Access to this profile has been restricted.') . EOL);
84 $o .= self::getTabsHTML($a, 'status', $is_owner, $a->profile['nickname']);
86 $o .= Widget::commonFriendsVisitor($a->profile['uid']);
88 $commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
89 $commvisitor = $commpage && $remote_contact;
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();
95 if (Security::canWriteToUserWall($a->profile['uid'])) {
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) : '',
109 'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
110 'profile_uid' => $a->profile['uid'],
113 $o .= status_editor($a, $x);
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']);
120 $last_updated_array = Session::get('last_updated', []);
122 $sql_post_table = "";
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']));
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']));
134 if (!empty($datequery)) {
135 $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
137 if (!empty($datequery2)) {
138 $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
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'])));
150 // check if we serve a mobile device and get the user settings
152 if (DI::mode()->isMobile()) {
153 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', 10);
155 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', 20);
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;
164 $pager = new Pager($args->getQueryString(), $itemspage_network);
166 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
168 $items_stmt = DBA::p(
171 STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
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`
185 ORDER BY `thread`.`received` DESC
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);
195 if ($is_owner && !DI::config()->get('theme', 'hide_eventlist')) {
196 $o .= ProfileModel::getBirthdays();
197 $o .= ProfileModel::getEventsReminderHTML();
201 $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
203 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
207 $items = DBA::toArray($items_stmt);
209 $o .= conversation($a, $items, $pager, 'profile', false, false, 'received', $a->profile['uid']);
211 $o .= $pager->renderMinimal(count($items));