3 * @file mod/noscrape.php
7 use Friendica\Core\Protocol;
8 use Friendica\Database\DBA;
10 use Friendica\Model\Profile;
11 use Friendica\Model\User;
13 function noscrape_init(App $a)
22 if ((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
23 $which = $a->user['nickname'];
24 $profile = $a->argv[1];
27 Profile::load($a, $which, $profile);
30 'addr' => $a->profile['addr'],
32 'guid' => $a->profile['guid'],
33 'key' => $a->profile['pubkey'],
34 'homepage' => DI::baseUrl()."/profile/{$which}",
35 'comm' => ($a->profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY),
36 'account-type' => $a->profile['account-type'],
39 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
40 foreach ($dfrn_pages as $dfrn) {
41 $json_info["dfrn-{$dfrn}"] = DI::baseUrl()."/dfrn_{$dfrn}/{$which}";
44 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
45 header('Content-type: application/json; charset=utf-8');
46 $json_info["hide"] = true;
47 echo json_encode($json_info);
51 $keywords = $a->profile['pub_keywords'] ?? '';
52 $keywords = str_replace(['#',',',' ',',,'], ['',' ',',',','], $keywords);
53 $keywords = explode(',', $keywords);
55 $contactPhoto = DBA::selectFirst('contact', ['photo'], ['self' => true, 'uid' => $a->profile['uid']]);
57 $json_info['fn'] = $a->profile['name'];
58 $json_info['photo'] = $contactPhoto["photo"];
59 $json_info['tags'] = $keywords;
60 $json_info['language'] = $a->profile['language'];
62 if (is_array($a->profile) && !$a->profile['hide-friends']) {
63 /// @todo What should this value tell us?
64 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
65 intval($a->profile['uid']));
66 if (DBA::isResult($r)) {
67 $json_info["updated"] = date("c", strtotime($r[0]['updated']));
70 $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0
71 AND `network` IN ('%s', '%s', '%s', '')",
72 intval($a->profile['uid']),
73 DBA::escape(Protocol::DFRN),
74 DBA::escape(Protocol::DIASPORA),
75 DBA::escape(Protocol::OSTATUS)
77 if (DBA::isResult($r)) {
78 $json_info["contacts"] = intval($r[0]['total']);
82 // We display the last activity (post or login), reduced to year and week number
84 $condition = ['uid' => $a->profile['uid'], 'self' => true];
85 $contact = DBA::selectFirst('contact', ['last-item'], $condition);
86 if (DBA::isResult($contact)) {
87 $last_active = strtotime($contact['last-item']);
90 $condition = ['uid' => $a->profile['uid']];
91 $user = DBA::selectFirst('user', ['login_date'], $condition);
92 if (DBA::isResult($user)) {
93 if ($last_active < strtotime($user['login_date'])) {
94 $last_active = strtotime($user['login_date']);
97 $json_info["last-activity"] = date("o-W", $last_active);
99 //These are optional fields.
100 $profile_fields = ['pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about'];
101 foreach ($profile_fields as $field) {
102 if (!empty($a->profile[$field])) {
103 $json_info["$field"] = $a->profile[$field];
107 //Output all the JSON!
108 header('Content-type: application/json; charset=utf-8');
109 echo json_encode($json_info);