3 * @file mod/noscrape.php
7 use Friendica\Core\Protocol;
8 use Friendica\Core\System;
9 use Friendica\Database\DBA;
10 use Friendica\Model\Contact;
11 use Friendica\Model\Profile;
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' => System::baseUrl()."/profile/{$which}",
35 'comm' => ($a->profile['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY),
36 'account-type' => $a->profile['account-type'],
39 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
40 header('Content-type: application/json; charset=utf-8');
41 $json_info["hide"] = true;
42 echo json_encode($json_info);
46 $keywords = ((x($a->profile, 'pub_keywords')) ? $a->profile['pub_keywords'] : '');
47 $keywords = str_replace(['#',',',' ',',,'], ['',' ',',',','], $keywords);
48 $keywords = explode(',', $keywords);
50 $contactPhoto = DBA::selectFirst('contact', ['photo'], ['self' => true, 'uid' => $a->profile['uid']]);
52 $json_info['fn'] = $a->profile['name'];
53 $json_info['photo'] = $contactPhoto["photo"];
54 $json_info['tags'] = $keywords;
55 $json_info['language'] = $a->profile['language'];
57 if (is_array($a->profile) && !$a->profile['hide-friends']) {
58 /// @todo What should this value tell us?
59 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
60 intval($a->profile['uid']));
61 if (DBA::isResult($r)) {
62 $json_info["updated"] = date("c", strtotime($r[0]['updated']));
65 $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
66 AND `network` IN ('%s', '%s', '%s', '')",
67 intval($a->profile['uid']),
68 DBA::escape(Protocol::DFRN),
69 DBA::escape(Protocol::DIASPORA),
70 DBA::escape(Protocol::OSTATUS)
72 if (DBA::isResult($r)) {
73 $json_info["contacts"] = intval($r[0]['total']);
77 // We display the last activity (post or login), reduced to year and week number
79 $condition = ['uid' => $a->profile['uid'], 'self' => true];
80 $contact = DBA::selectFirst('contact', ['last-item'], $condition);
81 if (DBA::isResult($contact)) {
82 $last_active = strtotime($contact['last-item']);
85 $condition = ['uid' => $a->profile['uid']];
86 $user = DBA::selectFirst('user', ['login_date'], $condition);
87 if (DBA::isResult($user)) {
88 if ($last_active < strtotime($user['login_date'])) {
89 $last_active = strtotime($user['login_date']);
92 $json_info["last-activity"] = date("o-W", $last_active);
94 //These are optional fields.
95 $profile_fields = ['pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about'];
96 foreach ($profile_fields as $field) {
97 if (!empty($a->profile[$field])) {
98 $json_info["$field"] = $a->profile[$field];
102 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
103 foreach ($dfrn_pages as $dfrn) {
104 $json_info["dfrn-{$dfrn}"] = System::baseUrl()."/dfrn_{$dfrn}/{$which}";
107 //Output all the JSON!
108 header('Content-type: application/json; charset=utf-8');
109 echo json_encode($json_info);