3 namespace Friendica\Module;
\r
5 use Friendica\BaseModule;
\r
6 use Friendica\Content\Nav;
\r
7 use Friendica\Content\Pager;
\r
8 use Friendica\Content\Widget;
\r
9 use Friendica\Core\ACL;
\r
10 use Friendica\Core\Config;
\r
11 use Friendica\Core\Hook;
\r
12 use Friendica\Core\L10n;
\r
13 use Friendica\Core\PConfig;
\r
14 use Friendica\Core\System;
\r
15 use Friendica\Database\DBA;
\r
16 use Friendica\Model\Contact as ContactModel;
\r
17 use Friendica\Model\Group;
\r
18 use Friendica\Model\Item;
\r
19 use Friendica\Model\Profile AS ProfileModel;
\r
20 use Friendica\Model\User;
\r
21 use Friendica\Protocol\ActivityPub;
\r
22 use Friendica\Protocol\DFRN;
\r
23 use Friendica\Util\DateTimeFormat;
\r
24 use Friendica\Util\Security;
\r
25 use Friendica\Util\Strings;
\r
26 use Friendica\Util\XML;
\r
28 require_once 'boot.php';
\r
30 class Profile extends BaseModule
\r
32 public static $which = '';
\r
33 public static $profile = 0;
\r
35 public static function init()
\r
37 $a = self::getApp();
\r
40 System::httpExit(400);
\r
43 self::$which = filter_var($a->argv[1], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);
\r
45 if (local_user() && $a->argc > 2 && $a->argv[2] === 'view') {
\r
46 self::$which = $a->user['nickname'];
\r
47 self::$profile = filter_var($a->argv[1], FILTER_SANITIZE_NUMBER_INT);
\r
49 DFRN::autoRedir($a, self::$which);
\r
53 public static function rawContent()
\r
55 if (ActivityPub::isRequest()) {
\r
56 $user = DBA::selectFirst('user', ['uid'], ['nickname' => self::$which]);
\r
58 if (DBA::isResult($user)) {
\r
59 $data = ActivityPub\Transmitter::getProfile($user['uid']);
\r
62 if (!empty($data)) {
\r
63 System::jsonExit($data, 'application/activity+json');
\r
64 } elseif (DBA::exists('userd', ['username' => self::$which])) {
\r
65 // Known deleted user
\r
67 '@context' => ActivityPub::CONTEXT,
\r
68 'id' => self::getApp()->getBaseUrl() . '/profile/' . self::$which,
\r
69 'type' => 'Tombstone',
\r
70 'published' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
\r
71 'updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
\r
72 'deleted' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
\r
75 System::jsonError(410, $data);
\r
77 // Any other case (unknown, blocked, unverified, expired, no profile, no self contact)
\r
78 System::jsonError(404, $data);
\r
83 public static function content($update = 0)
\r
85 $a = self::getApp();
\r
88 ProfileModel::load($a, self::$which, self::$profile);
\r
90 $blocked = !local_user() && !remote_user() && Config::get('system', 'block_public');
\r
91 $userblock = !local_user() && !remote_user() && $a->profile['hidewall'];
\r
93 if (!empty($a->profile['page-flags']) && $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) {
\r
94 $a->page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
\r
97 if (!empty($a->profile['openidserver'])) {
\r
98 $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\n";
\r
101 if (!empty($a->profile['openid'])) {
\r
102 $delegate = strstr($a->profile['openid'], '://') ? $a->profile['openid'] : 'https://' . $a->profile['openid'];
\r
103 $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\n";
\r
107 if (!$blocked && !$userblock) {
\r
108 $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], defaults($a->profile, 'pub_keywords', ''));
\r
109 if (strlen($keywords)) {
\r
110 $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\n";
\r
114 $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . ($a->profile['net-publish'] ? 'true' : 'false') . '" />' . "\n";
\r
115 $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/dfrn_poll/' . self::$which . '" title="DFRN: ' . L10n::t('%s\'s timeline', $a->profile['username']) . '"/>' . "\n";
\r
116 $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/" title="' . L10n::t('%s\'s posts', $a->profile['username']) . '"/>' . "\n";
\r
117 $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/comments" title="' . L10n::t('%s\'s comments', $a->profile['username']) . '"/>' . "\n";
\r
118 $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . System::baseUrl() . '/feed/' . self::$which . '/activity" title="' . L10n::t('%s\'s timeline', $a->profile['username']) . '"/>' . "\n";
\r
119 $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->getHostName() . ($a->getURLPath() ? '/' . $a->getURLPath() : ''));
\r
120 $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . System::baseUrl() . '/xrd/?uri=' . $uri . '" />' . "\n";
\r
121 header('Link: <' . System::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
\r
123 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
\r
124 foreach ($dfrn_pages as $dfrn) {
\r
125 $a->page['htmlhead'] .= '<link rel="dfrn-' . $dfrn . '" href="' . System::baseUrl() . '/dfrn_' . $dfrn . '/' . self::$which . '" />' . "\n";
\r
127 $a->page['htmlhead'] .= '<link rel="dfrn-poco" href="' . System::baseUrl() . '/poco/' . self::$which . '" />' . "\n";
\r
130 $category = $datequery = $datequery2 = '';
\r
132 if ($a->argc > 2) {
\r
133 for ($x = 2; $x < $a->argc; $x ++) {
\r
134 if (is_a_date_arg($a->argv[$x])) {
\r
136 $datequery2 = Strings::escapeHtml($a->argv[$x]);
\r
138 $datequery = Strings::escapeHtml($a->argv[$x]);
\r
141 $category = $a->argv[$x];
\r
146 if (empty($category)) {
\r
147 $category = defaults($_GET, 'category', '');
\r
150 $hashtags = defaults($_GET, 'tag', '');
\r
152 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
\r
153 return Login::form();
\r
157 $remote_cid = null;
\r
162 // Ensure we've got a profile owner if updating.
\r
163 $a->profile['profile_uid'] = $update;
\r
164 } elseif ($a->profile['profile_uid'] == local_user()) {
\r
165 Nav::setSelected('home');
\r
168 $remote_contact = ContactModel::isFollower(remote_user(), $a->profile['profile_uid']);
\r
169 $is_owner = local_user() == $a->profile['profile_uid'];
\r
170 $last_updated_key = "profile:" . $a->profile['profile_uid'] . ":" . local_user() . ":" . remote_user();
\r
172 if ($remote_contact) {
\r
173 $cdata = ContactModel::getPublicAndUserContacID(remote_user(), $a->profile['profile_uid']);
\r
174 if (!empty($cdata['user'])) {
\r
175 $groups = Group::getIdsByContactId($cdata['user']);
\r
176 $remote_cid = $cdata['user'];
\r
180 if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
\r
181 notice(L10n::t('Access to this profile has been restricted.') . EOL);
\r
187 if (!empty($_GET['tab'])) {
\r
188 $tab = Strings::escapeTags(trim($_GET['tab']));
\r
191 $o .= ProfileModel::getTabs($a, $is_owner, $a->profile['nickname']);
\r
193 if ($tab === 'profile') {
\r
194 $o .= ProfileModel::getAdvanced($a);
\r
195 Hook::callAll('profile_advanced', $o);
\r
199 $o .= Widget::commonFriendsVisitor($a->profile['profile_uid']);
\r
201 $commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
\r
202 $commvisitor = $commpage && $remote_contact;
\r
204 $a->page['aside'] .= posted_date_widget(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], $a->profile['profile_uid'], true);
\r
205 $a->page['aside'] .= Widget::categories(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], (!empty($category) ? XML::escape($category) : ''));
\r
206 $a->page['aside'] .= Widget::tagCloud();
\r
208 if (Security::canWriteToUserWall($a->profile['profile_uid'])) {
\r
210 'is_owner' => $is_owner,
\r
211 'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'],
\r
212 'default_location' => $is_owner ? $a->user['default-location'] : '',
\r
213 'nickname' => $a->profile['nickname'],
\r
214 'lockstate' => is_array($a->user)
\r
215 && (strlen($a->user['allow_cid'])
\r
216 || strlen($a->user['allow_gid'])
\r
217 || strlen($a->user['deny_cid'])
\r
218 || strlen($a->user['deny_gid'])
\r
219 ) ? 'lock' : 'unlock',
\r
220 'acl' => $is_owner ? ACL::getFullSelectorHTML($a->user, true) : '',
\r
222 'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
\r
223 'profile_uid' => $a->profile['profile_uid'],
\r
226 $o .= status_editor($a, $x);
\r
230 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
\r
231 $sql_extra = Item::getPermissionsSQLByUserId($a->profile['profile_uid'], $remote_contact, $groups, $remote_cid);
\r
235 $last_updated = (defaults($_SESSION['last_updated'], $last_updated_key, 0));
\r
237 // If the page user is the owner of the page we should query for unseen
\r
238 // items. Otherwise use a timestamp of the last succesful update request.
\r
239 if ($is_owner || !$last_updated) {
\r
240 $sql_extra4 = " AND `item`.`unseen`";
\r
242 $gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);
\r
243 $sql_extra4 = " AND `item`.`received` > '" . $gmupdate . "'";
\r
246 $items_stmt = DBA::p(
\r
247 "SELECT DISTINCT(`parent-uri`) AS `uri`, `item`.`created`
\r
249 INNER JOIN `contact`
\r
250 ON `contact`.`id` = `item`.`contact-id`
\r
251 AND NOT `contact`.`blocked`
\r
252 AND NOT `contact`.`pending`
\r
253 WHERE `item`.`uid` = ?
\r
254 AND `item`.`visible`
\r
255 AND (NOT `item`.`deleted` OR `item`.`gravity` = ?)
\r
256 AND NOT `item`.`moderated`
\r
260 ORDER BY `item`.`created` DESC",
\r
261 $a->profile['profile_uid'],
\r
265 if (!DBA::isResult($items_stmt)) {
\r
269 $pager = new Pager($a->query_string);
\r
271 $sql_post_table = "";
\r
273 if (!empty($category)) {
\r
274 $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` ",
\r
275 DBA::escape(Strings::protectSprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($a->profile['profile_uid']));
\r
278 if (!empty($hashtags)) {
\r
279 $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` ",
\r
280 DBA::escape(Strings::protectSprintf($hashtags)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval($a->profile['profile_uid']));
\r
283 if (!empty($datequery)) {
\r
284 $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
\r
286 if (!empty($datequery2)) {
\r
287 $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
\r
290 // Does the profile page belong to a forum?
\r
291 // If not then we can improve the performance with an additional condition
\r
292 $condition = ['uid' => $a->profile['profile_uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]];
\r
293 if (!DBA::exists('user', $condition)) {
\r
294 $sql_extra3 = sprintf(" AND `thread`.`contact-id` = %d ", intval(intval($a->profile['contact_id'])));
\r
299 // check if we serve a mobile device and get the user settings
\r
301 if ($a->is_mobile) {
\r
302 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 10);
\r
304 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 20);
\r
307 // now that we have the user settings, see if the theme forces
\r
308 // a maximum item number which is lower then the user choice
\r
309 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
\r
310 $itemspage_network = $a->force_max_items;
\r
313 $pager = new Pager($a->query_string, $itemspage_network);
\r
315 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
\r
317 $items_stmt = DBA::p(
\r
318 "SELECT `item`.`uri`
\r
320 STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
\r
322 STRAIGHT_JOIN `contact`
\r
323 ON `contact`.`id` = `thread`.`contact-id`
\r
324 AND NOT `contact`.`blocked`
\r
325 AND NOT `contact`.`pending`
\r
326 WHERE `thread`.`uid` = ?
\r
327 AND `thread`.`visible`
\r
328 AND NOT `thread`.`deleted`
\r
329 AND NOT `thread`.`moderated`
\r
330 AND `thread`.`wall`
\r
334 ORDER BY `thread`.`created` DESC
\r
336 $a->profile['profile_uid']
\r
340 // Set a time stamp for this page. We will make use of it when we
\r
341 // search for new items (update routine)
\r
342 $_SESSION['last_updated'][$last_updated_key] = time();
\r
344 if ($is_owner && !$update && !Config::get('theme', 'hide_eventlist')) {
\r
345 $o .= ProfileModel::getBirthdays();
\r
346 $o .= ProfileModel::getEventsReminderHTML();
\r
350 $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
\r
352 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
\r
356 $items = DBA::toArray($items_stmt);
\r
358 $o .= conversation($a, $items, $pager, 'profile', $update, false, 'created', $a->profile['profile_uid']);
\r
361 $o .= $pager->renderMinimal(count($items));
\r