3 namespace Friendica\Module\Profile;
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;
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;
22 require_once 'boot.php';
24 class Status extends BaseModule
26 public static function content(array $parameters = [])
32 ProfileModel::load($a, $parameters['nickname']);
34 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
35 DI::page()['htmlhead'] .= '<meta content="noindex, noarchive" name="robots" />' . "\n";
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";
43 $category = $datequery = $datequery2 = '';
45 $dtFormat = DI::dtFormat();
47 if ($args->getArgc() > 2) {
48 for ($x = 2; $x < $args->getArgc(); $x++) {
49 if ($dtFormat->isYearMonth($args->get($x))) {
51 $datequery2 = Strings::escapeHtml($args->get($x));
53 $datequery = Strings::escapeHtml($args->get($x));
56 $category = $args->get($x);
61 if (empty($category)) {
62 $category = $_GET['category'] ?? '';
65 $hashtags = $_GET['tag'] ?? '';
67 if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile['profile_uid'])) {
73 if ($a->profile['profile_uid'] == local_user()) {
74 Nav::setSelected('home');
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;
81 if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
82 notice(DI::l10n()->t('Access to this profile has been restricted.') . EOL);
86 $o .= ProfileModel::getTabs($a, 'status', $is_owner, $a->profile['nickname']);
88 $o .= Widget::commonFriendsVisitor($a->profile['profile_uid']);
90 $commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
91 $commvisitor = $commpage && $remote_contact;
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();
97 if (Security::canWriteToUserWall($a->profile['profile_uid'])) {
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) : '',
111 'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
112 'profile_uid' => $a->profile['profile_uid'],
115 $o .= status_editor($a, $x);
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']);
122 $last_updated_array = Session::get('last_updated', []);
124 $sql_post_table = "";
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']));
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']));
136 if (!empty($datequery)) {
137 $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
139 if (!empty($datequery2)) {
140 $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
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'])));
152 // check if we serve a mobile device and get the user settings
154 if (DI::mode()->isMobile()) {
155 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', 10);
157 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network', 20);
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;
166 $pager = new Pager($args->getQueryString(), $itemspage_network);
168 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
170 $items_stmt = DBA::p(
173 STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
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`
187 ORDER BY `thread`.`received` DESC
189 $a->profile['profile_uid']
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);
197 if ($is_owner && !DI::config()->get('theme', 'hide_eventlist')) {
198 $o .= ProfileModel::getBirthdays();
199 $o .= ProfileModel::getEventsReminderHTML();
203 $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
205 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
209 $items = DBA::toArray($items_stmt);
211 $o .= conversation($a, $items, $pager, 'profile', false, false, 'received', $a->profile['profile_uid']);
213 $o .= $pager->renderMinimal(count($items));