3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module;
24 use Friendica\BaseModule;
25 use Friendica\Core\Protocol;
26 use Friendica\Core\System;
27 use Friendica\Database\DBA;
29 use Friendica\Model\Contact;
30 use Friendica\Model\Profile;
31 use Friendica\Model\User;
34 * Endpoint for getting current user infos
36 * @see Contact::updateFromNoScrape() for usage
38 class NoScrape extends BaseModule
40 public static function rawContent(array $parameters = [])
44 if (isset($parameters['nick'])) {
45 // Get infos about a specific nick (public)
46 $which = $parameters['nick'];
47 } elseif (local_user() && isset($parameters['profile']) && DI::args()->get(2) == 'view') {
48 // view infos about a known profile (needs a login)
49 $which = $a->user['nickname'];
51 System::jsonError(403, 'Authentication required');
54 $profile = Profile::getByNickname($which);
56 if (empty($profile['uid'])) {
57 System::jsonError(404, 'Profile not found');
61 'addr' => $profile['addr'],
63 'guid' => $profile['guid'],
64 'key' => $profile['upubkey'],
65 'homepage' => DI::baseUrl() . "/profile/{$which}",
66 'comm' => ($profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY),
67 'account-type' => $profile['account-type'],
70 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
71 foreach ($dfrn_pages as $dfrn) {
72 $json_info["dfrn-{$dfrn}"] = DI::baseUrl() . "/dfrn_{$dfrn}/{$which}";
75 if (!$profile['net-publish']) {
76 $json_info['hide'] = true;
77 System::jsonExit($json_info);
80 $keywords = $profile['pub_keywords'] ?? '';
81 $keywords = str_replace(['#', ',', ' ', ',,'], ['', ' ', ',', ','], $keywords);
82 $keywords = explode(',', $keywords);
84 $json_info['fn'] = $profile['name'];
85 $json_info['photo'] = Contact::getAvatarUrlForUrl($profile['url'], $profile['uid']);
86 $json_info['tags'] = $keywords;
87 $json_info['language'] = $profile['language'];
89 if (!empty($profile['last-item'])) {
90 $json_info['updated'] = date("c", strtotime($profile['last-item']));
93 if (!($profile['hide-friends'] ?? false)) {
94 $json_info['contacts'] = DBA::count('contact',
96 'uid' => $profile['uid'],
102 'network' => [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]
106 // We display the last activity (post or login), reduced to year and week number
108 $condition = ['uid' => $profile['uid'], 'self' => true];
109 $contact = DBA::selectFirst('contact', ['last-item'], $condition);
110 if (DBA::isResult($contact)) {
111 $last_active = strtotime($contact['last-item']);
114 $condition = ['uid' => $profile['uid']];
115 $user = DBA::selectFirst('user', ['login_date'], $condition);
116 if (DBA::isResult($user)) {
117 if ($last_active < strtotime($user['login_date'])) {
118 $last_active = strtotime($user['login_date']);
121 $json_info['last-activity'] = date('o-W', $last_active);
123 //These are optional fields.
124 $profile_fields = ['about', 'locality', 'region', 'postal-code', 'country-name'];
125 foreach ($profile_fields as $field) {
126 if (!empty($profile[$field])) {
127 $json_info["$field"] = $profile[$field];
131 System::jsonExit($json_info);