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'];
28 } elseif (local_user() && isset($parameters['profile']) && DI::args()->get(2) == 'view') {
29 // view infos about a known profile (needs a login)
30 $which = $a->user['nickname'];
32 System::jsonError(403, 'Authentication required');
36 Profile::load($a, $which);
39 'addr' => $a->profile['addr'],
41 'guid' => $a->profile['guid'],
42 'key' => $a->profile['pubkey'],
43 'homepage' => DI::baseUrl() . "/profile/{$which}",
44 'comm' => ($a->profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY),
45 'account-type' => $a->profile['account-type'],
48 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
49 foreach ($dfrn_pages as $dfrn) {
50 $json_info["dfrn-{$dfrn}"] = DI::baseUrl() . "/dfrn_{$dfrn}/{$which}";
53 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
54 $json_info['hide'] = true;
55 System::jsonExit($json_info);
58 $keywords = $a->profile['pub_keywords'] ?? '';
59 $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], $keywords);
60 $keywords = explode(',', $keywords);
62 $contactPhoto = DBA::selectFirst('contact', ['photo'], ['self' => true, 'uid' => $a->profile['uid']]);
64 $json_info['fn'] = $a->profile['name'];
65 $json_info['photo'] = $contactPhoto["photo"];
66 $json_info['tags'] = $keywords;
67 $json_info['language'] = $a->profile['language'];
69 if (!($a->profile['hide-friends'] ?? false)) {
71 "SELECT `gcontact`.`updated`
74 WHERE `gcontact`.`nurl` = `contact`.`nurl`
78 intval($a->profile['uid'])
80 if ($gcontact = DBA::fetch($stmt)) {
81 $json_info["updated"] = date("c", strtotime($gcontact['updated']));
85 $json_info['contacts'] = DBA::count('contact',
87 'uid' => $a->profile['uid'],
93 'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]
97 // We display the last activity (post or login), reduced to year and week number
99 $condition = ['uid' => $a->profile['uid'], 'self' => true];
100 $contact = DBA::selectFirst('contact', ['last-item'], $condition);
101 if (DBA::isResult($contact)) {
102 $last_active = strtotime($contact['last-item']);
105 $condition = ['uid' => $a->profile['uid']];
106 $user = DBA::selectFirst('user', ['login_date'], $condition);
107 if (DBA::isResult($user)) {
108 if ($last_active < strtotime($user['login_date'])) {
109 $last_active = strtotime($user['login_date']);
112 $json_info['last-activity'] = date('o-W', $last_active);
114 //These are optional fields.
115 $profile_fields = ['pdesc', 'locality', 'region', 'postal-code', 'country-name'];
116 foreach ($profile_fields as $field) {
117 if (!empty($a->profile[$field])) {
118 $json_info["$field"] = $a->profile[$field];
122 System::jsonExit($json_info);