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
57 if (DBA::isResult($user)) {
\r
58 $data = ActivityPub\Transmitter::getProfile($user['uid']);
\r
59 System::jsonExit($data, 'application/activity+json');
\r
60 } elseif (DBA::exists('userd', ['username' => self::$which])) {
\r
61 // Known deleted user
\r
62 System::httpExit(410);
\r
65 System::httpExit(404);
\r
70 public static function content($update = 0)
\r
72 $a = self::getApp();
\r
75 ProfileModel::load($a, self::$which, self::$profile);
\r
77 $blocked = !local_user() && !remote_user() && Config::get('system', 'block_public');
\r
78 $userblock = !local_user() && !remote_user() && $a->profile['hidewall'];
\r
80 if (!empty($a->profile['page-flags']) && $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY) {
\r
81 $a->page['htmlhead'] .= '<meta name="friendica.community" content="true" />';
\r
84 if (!empty($a->profile['openidserver'])) {
\r
85 $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\n";
\r
88 if (!empty($a->profile['openid'])) {
\r
89 $delegate = strstr($a->profile['openid'], '://') ? $a->profile['openid'] : 'https://' . $a->profile['openid'];
\r
90 $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\n";
\r
94 if (!$blocked && !$userblock) {
\r
95 $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], defaults($a->profile, 'pub_keywords', ''));
\r
96 if (strlen($keywords)) {
\r
97 $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\n";
\r
101 $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . ($a->profile['net-publish'] ? 'true' : 'false') . '" />' . "\n";
\r
102 $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
103 $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
104 $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
105 $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
106 $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->getHostName() . ($a->getURLPath() ? '/' . $a->getURLPath() : ''));
\r
107 $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . System::baseUrl() . '/xrd/?uri=' . $uri . '" />' . "\n";
\r
108 header('Link: <' . System::baseUrl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
\r
110 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
\r
111 foreach ($dfrn_pages as $dfrn) {
\r
112 $a->page['htmlhead'] .= '<link rel="dfrn-' . $dfrn . '" href="' . System::baseUrl() . '/dfrn_' . $dfrn . '/' . self::$which . '" />' . "\n";
\r
114 $a->page['htmlhead'] .= '<link rel="dfrn-poco" href="' . System::baseUrl() . '/poco/' . self::$which . '" />' . "\n";
\r
117 $category = $datequery = $datequery2 = '';
\r
119 if ($a->argc > 2) {
\r
120 for ($x = 2; $x < $a->argc; $x ++) {
\r
121 if (is_a_date_arg($a->argv[$x])) {
\r
123 $datequery2 = Strings::escapeHtml($a->argv[$x]);
\r
125 $datequery = Strings::escapeHtml($a->argv[$x]);
\r
128 $category = $a->argv[$x];
\r
133 if (empty($category)) {
\r
134 $category = defaults($_GET, 'category', '');
\r
137 $hashtags = defaults($_GET, 'tag', '');
\r
139 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
\r
140 return Login::form();
\r
144 $remote_cid = null;
\r
149 // Ensure we've got a profile owner if updating.
\r
150 $a->profile['profile_uid'] = $update;
\r
151 } elseif ($a->profile['profile_uid'] == local_user()) {
\r
152 Nav::setSelected('home');
\r
155 $remote_contact = ContactModel::isFollower(remote_user(), $a->profile['profile_uid']);
\r
156 $is_owner = local_user() == $a->profile['profile_uid'];
\r
157 $last_updated_key = "profile:" . $a->profile['profile_uid'] . ":" . local_user() . ":" . remote_user();
\r
159 if ($remote_contact) {
\r
160 $cdata = ContactModel::getPublicAndUserContacID(remote_user(), $a->profile['profile_uid']);
\r
161 if (!empty($cdata['user'])) {
\r
162 $groups = Group::getIdsByContactId($cdata['user']);
\r
163 $remote_cid = $cdata['user'];
\r
167 if (!empty($a->profile['hidewall']) && !$is_owner && !$remote_contact) {
\r
168 notice(L10n::t('Access to this profile has been restricted.') . EOL);
\r
174 if (!empty($_GET['tab'])) {
\r
175 $tab = Strings::escapeTags(trim($_GET['tab']));
\r
178 $o .= ProfileModel::getTabs($a, $is_owner, $a->profile['nickname']);
\r
180 if ($tab === 'profile') {
\r
181 $o .= ProfileModel::getAdvanced($a);
\r
182 Hook::callAll('profile_advanced', $o);
\r
186 $o .= Widget::commonFriendsVisitor($a->profile['profile_uid']);
\r
188 $commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
\r
189 $commvisitor = $commpage && $remote_contact;
\r
191 $a->page['aside'] .= posted_date_widget(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], $a->profile['profile_uid'], true);
\r
192 $a->page['aside'] .= Widget::categories(System::baseUrl(true) . '/profile/' . $a->profile['nickname'], (!empty($category) ? XML::escape($category) : ''));
\r
193 $a->page['aside'] .= Widget::tagCloud();
\r
195 if (Security::canWriteToUserWall($a->profile['profile_uid'])) {
\r
197 'is_owner' => $is_owner,
\r
198 'allow_location' => ($is_owner || $commvisitor) && $a->profile['allow_location'],
\r
199 'default_location' => $is_owner ? $a->user['default-location'] : '',
\r
200 'nickname' => $a->profile['nickname'],
\r
201 'lockstate' => is_array($a->user)
\r
202 && (strlen($a->user['allow_cid'])
\r
203 || strlen($a->user['allow_gid'])
\r
204 || strlen($a->user['deny_cid'])
\r
205 || strlen($a->user['deny_gid'])
\r
206 ) ? 'lock' : 'unlock',
\r
207 'acl' => $is_owner ? ACL::getFullSelectorHTML($a->user, true) : '',
\r
209 'visitor' => $is_owner || $commvisitor ? 'block' : 'none',
\r
210 'profile_uid' => $a->profile['profile_uid'],
\r
213 $o .= status_editor($a, $x);
\r
217 // Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
\r
218 $sql_extra = Item::getPermissionsSQLByUserId($a->profile['profile_uid'], $remote_contact, $groups, $remote_cid);
\r
222 $last_updated = (defaults($_SESSION['last_updated'], $last_updated_key, 0));
\r
224 // If the page user is the owner of the page we should query for unseen
\r
225 // items. Otherwise use a timestamp of the last succesful update request.
\r
226 if ($is_owner || !$last_updated) {
\r
227 $sql_extra4 = " AND `item`.`unseen`";
\r
229 $gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);
\r
230 $sql_extra4 = " AND `item`.`received` > '" . $gmupdate . "'";
\r
233 $items_stmt = DBA::p(
\r
234 "SELECT DISTINCT(`parent-uri`) AS `uri`, `item`.`created`
\r
236 INNER JOIN `contact`
\r
237 ON `contact`.`id` = `item`.`contact-id`
\r
238 AND NOT `contact`.`blocked`
\r
239 AND NOT `contact`.`pending`
\r
240 WHERE `item`.`uid` = ?
\r
241 AND `item`.`visible`
\r
242 AND (NOT `item`.`deleted` OR `item`.`gravity` = ?)
\r
243 AND NOT `item`.`moderated`
\r
247 ORDER BY `item`.`created` DESC",
\r
248 $a->profile['profile_uid'],
\r
252 if (!DBA::isResult($items_stmt)) {
\r
256 $pager = new Pager($a->query_string);
\r
258 $sql_post_table = "";
\r
260 if (!empty($category)) {
\r
261 $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
262 DBA::escape(Strings::protectSprintf($category)), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), intval($a->profile['profile_uid']));
\r
265 if (!empty($hashtags)) {
\r
266 $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
267 DBA::escape(Strings::protectSprintf($hashtags)), intval(TERM_OBJ_POST), intval(TERM_HASHTAG), intval($a->profile['profile_uid']));
\r
270 if (!empty($datequery)) {
\r
271 $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
\r
273 if (!empty($datequery2)) {
\r
274 $sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
\r
277 // Does the profile page belong to a forum?
\r
278 // If not then we can improve the performance with an additional condition
\r
279 $condition = ['uid' => $a->profile['profile_uid'], 'page-flags' => [User::PAGE_FLAGS_COMMUNITY, User::PAGE_FLAGS_PRVGROUP]];
\r
280 if (!DBA::exists('user', $condition)) {
\r
281 $sql_extra3 = sprintf(" AND `thread`.`contact-id` = %d ", intval(intval($a->profile['contact_id'])));
\r
286 // check if we serve a mobile device and get the user settings
\r
288 if ($a->is_mobile) {
\r
289 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_mobile_network', 10);
\r
291 $itemspage_network = PConfig::get(local_user(), 'system', 'itemspage_network', 20);
\r
294 // now that we have the user settings, see if the theme forces
\r
295 // a maximum item number which is lower then the user choice
\r
296 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
\r
297 $itemspage_network = $a->force_max_items;
\r
300 $pager = new Pager($a->query_string, $itemspage_network);
\r
302 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
\r
304 $items_stmt = DBA::p(
\r
305 "SELECT `item`.`uri`
\r
307 STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
\r
309 STRAIGHT_JOIN `contact`
\r
310 ON `contact`.`id` = `thread`.`contact-id`
\r
311 AND NOT `contact`.`blocked`
\r
312 AND NOT `contact`.`pending`
\r
313 WHERE `thread`.`uid` = ?
\r
314 AND `thread`.`visible`
\r
315 AND NOT `thread`.`deleted`
\r
316 AND NOT `thread`.`moderated`
\r
317 AND `thread`.`wall`
\r
321 ORDER BY `thread`.`created` DESC
\r
323 $a->profile['profile_uid']
\r
327 // Set a time stamp for this page. We will make use of it when we
\r
328 // search for new items (update routine)
\r
329 $_SESSION['last_updated'][$last_updated_key] = time();
\r
331 if ($is_owner && !$update && !Config::get('theme', 'hide_eventlist')) {
\r
332 $o .= ProfileModel::getBirthdays();
\r
333 $o .= ProfileModel::getEventsReminderHTML();
\r
337 $unseen = Item::exists(['wall' => true, 'unseen' => true, 'uid' => local_user()]);
\r
339 Item::update(['unseen' => false], ['wall' => true, 'unseen' => true, 'uid' => local_user()]);
\r
343 $items = DBA::toArray($items_stmt);
\r
345 $o .= conversation($a, $items, $pager, 'profile', $update, false, 'created', $a->profile['profile_uid']);
\r
348 $o .= $pager->renderMinimal(count($items));
\r