3 namespace Friendica\Module;
5 use Friendica\BaseModule;
6 use Friendica\Core\Protocol;
7 use Friendica\Core\System;
8 use Friendica\Database\DBA;
10 use Friendica\Model\GContact;
11 use Friendica\Model\Profile;
12 use Friendica\Model\User;
15 * Endpoint for getting current user infos
17 * @see GContact::updateFromNoScrape() for usage
19 class NoScrape extends BaseModule
21 public static function rawContent(array $parameters = [])
25 if (isset($parameters['nick'])) {
26 // Get infos about a specific nick (public)
27 $which = $parameters['nick'];
29 } elseif (local_user() && isset($parameters['profile']) && DI::args()->get(2) == 'view') {
30 // view infos about a known profile (needs a login)
31 $which = $a->user['nickname'];
32 $profile = $parameters['profile'];
34 System::jsonError(403, 'Authentication required');
38 Profile::load($a, $which, $profile);
41 'addr' => $a->profile['addr'],
43 'guid' => $a->profile['guid'],
44 'key' => $a->profile['pubkey'],
45 'homepage' => DI::baseUrl() . "/profile/{$which}",
46 'comm' => ($a->profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY),
47 'account-type' => $a->profile['account-type'],
50 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
51 foreach ($dfrn_pages as $dfrn) {
52 $json_info["dfrn-{$dfrn}"] = DI::baseUrl() . "/dfrn_{$dfrn}/{$which}";
55 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
56 $json_info['hide'] = true;
57 System::jsonExit($json_info);
60 $keywords = $a->profile['pub_keywords'] ?? '';
61 $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], $keywords);
62 $keywords = explode(',', $keywords);
64 $contactPhoto = DBA::selectFirst('contact', ['photo'], ['self' => true, 'uid' => $a->profile['uid']]);
66 $json_info['fn'] = $a->profile['name'];
67 $json_info['photo'] = $contactPhoto["photo"];
68 $json_info['tags'] = $keywords;
69 $json_info['language'] = $a->profile['language'];
71 if (!($a->profile['hide-friends'] ?? false)) {
72 /// @todo What should this value tell us?
73 $result = DBA::p("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = ? LIMIT 1", intval($a->profile['uid']));
74 if (DBA::isResult($result)) {
75 $json_info["updated"] = date("c", strtotime($result[0]['updated']));
78 $json_info['contacts'] = DBA::count('contact',
80 'uid' => $a->profile['uid'],
86 'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]
90 // We display the last activity (post or login), reduced to year and week number
92 $condition = ['uid' => $a->profile['uid'], 'self' => true];
93 $contact = DBA::selectFirst('contact', ['last-item'], $condition);
94 if (DBA::isResult($contact)) {
95 $last_active = strtotime($contact['last-item']);
98 $condition = ['uid' => $a->profile['uid']];
99 $user = DBA::selectFirst('user', ['login_date'], $condition);
100 if (DBA::isResult($user)) {
101 if ($last_active < strtotime($user['login_date'])) {
102 $last_active = strtotime($user['login_date']);
105 $json_info['last-activity'] = date('o-W', $last_active);
107 //These are optional fields.
108 $profile_fields = ['pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about'];
109 foreach ($profile_fields as $field) {
110 if (!empty($a->profile[$field])) {
111 $json_info["$field"] = $a->profile[$field];
115 System::jsonExit($json_info);