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 $which = DI::args()->get(1);
28 if ((local_user()) && (DI::args()->get(2) === 'view')) {
29 $which = $a->user['nickname'];
30 $profile = DI::args()->get(1);
33 Profile::load($a, $which, $profile);
36 'addr' => $a->profile['addr'],
38 'guid' => $a->profile['guid'],
39 'key' => $a->profile['pubkey'],
40 'homepage' => DI::baseUrl() . "/profile/{$which}",
41 'comm' => ($a->profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY),
42 'account-type' => $a->profile['account-type'],
45 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
46 foreach ($dfrn_pages as $dfrn) {
47 $json_info["dfrn-{$dfrn}"] = DI::baseUrl() . "/dfrn_{$dfrn}/{$which}";
50 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
51 $json_info['hide'] = true;
52 System::jsonExit($json_info);
55 $keywords = $a->profile['pub_keywords'] ?? '';
56 $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], $keywords);
57 $keywords = explode(',', $keywords);
59 $contactPhoto = DBA::selectFirst('contact', ['photo'], ['self' => true, 'uid' => $a->profile['uid']]);
61 $json_info['fn'] = $a->profile['name'];
62 $json_info['photo'] = $contactPhoto["photo"];
63 $json_info['tags'] = $keywords;
64 $json_info['language'] = $a->profile['language'];
66 if (!($a->profile['hide-friends'] ?? false)) {
67 /// @todo What should this value tell us?
68 $result = DBA::p("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1", $a->profile['uid']);
69 if (DBA::isResult($result)) {
70 $json_info["updated"] = date("c", strtotime($result[0]['updated']));
73 $json_info['contacts'] = DBA::count('contact',
75 'uid' => $a->profile['uid'],
81 'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]
85 // We display the last activity (post or login), reduced to year and week number
87 $condition = ['uid' => $a->profile['uid'], 'self' => true];
88 $contact = DBA::selectFirst('contact', ['last-item'], $condition);
89 if (DBA::isResult($contact)) {
90 $last_active = strtotime($contact['last-item']);
93 $condition = ['uid' => $a->profile['uid']];
94 $user = DBA::selectFirst('user', ['login_date'], $condition);
95 if (DBA::isResult($user)) {
96 if ($last_active < strtotime($user['login_date'])) {
97 $last_active = strtotime($user['login_date']);
100 $json_info['last-activity'] = date('o-W', $last_active);
102 //These are optional fields.
103 $profile_fields = ['pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about'];
104 foreach ($profile_fields as $field) {
105 if (!empty($a->profile[$field])) {
106 $json_info["$field"] = $a->profile[$field];
110 System::jsonExit($json_info);