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;
12 use Friendica\Model\User;
14 function noscrape_init(App $a)
23 if ((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
24 $which = $a->user['nickname'];
25 $profile = $a->argv[1];
28 Profile::load($a, $which, $profile);
31 'addr' => $a->profile['addr'],
33 'guid' => $a->profile['guid'],
34 'key' => $a->profile['pubkey'],
35 'homepage' => System::baseUrl()."/profile/{$which}",
36 'comm' => ($a->profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY),
37 'account-type' => $a->profile['account-type'],
40 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
41 foreach ($dfrn_pages as $dfrn) {
42 $json_info["dfrn-{$dfrn}"] = System::baseUrl()."/dfrn_{$dfrn}/{$which}";
45 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
46 header('Content-type: application/json; charset=utf-8');
47 $json_info["hide"] = true;
48 echo json_encode($json_info);
52 $keywords = defaults($a->profile, 'pub_keywords', '');
53 $keywords = str_replace(['#',',',' ',',,'], ['',' ',',',','], $keywords);
54 $keywords = explode(',', $keywords);
56 $contactPhoto = DBA::selectFirst('contact', ['photo'], ['self' => true, 'uid' => $a->profile['uid']]);
58 $json_info['fn'] = $a->profile['name'];
59 $json_info['photo'] = $contactPhoto["photo"];
60 $json_info['tags'] = $keywords;
61 $json_info['language'] = $a->profile['language'];
63 if (is_array($a->profile) && !$a->profile['hide-friends']) {
64 /// @todo What should this value tell us?
65 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
66 intval($a->profile['uid']));
67 if (DBA::isResult($r)) {
68 $json_info["updated"] = date("c", strtotime($r[0]['updated']));
71 $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
72 AND `network` IN ('%s', '%s', '%s', '')",
73 intval($a->profile['uid']),
74 DBA::escape(Protocol::DFRN),
75 DBA::escape(Protocol::DIASPORA),
76 DBA::escape(Protocol::OSTATUS)
78 if (DBA::isResult($r)) {
79 $json_info["contacts"] = intval($r[0]['total']);
83 // We display the last activity (post or login), reduced to year and week number
85 $condition = ['uid' => $a->profile['uid'], 'self' => true];
86 $contact = DBA::selectFirst('contact', ['last-item'], $condition);
87 if (DBA::isResult($contact)) {
88 $last_active = strtotime($contact['last-item']);
91 $condition = ['uid' => $a->profile['uid']];
92 $user = DBA::selectFirst('user', ['login_date'], $condition);
93 if (DBA::isResult($user)) {
94 if ($last_active < strtotime($user['login_date'])) {
95 $last_active = strtotime($user['login_date']);
98 $json_info["last-activity"] = date("o-W", $last_active);
100 //These are optional fields.
101 $profile_fields = ['pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about'];
102 foreach ($profile_fields as $field) {
103 if (!empty($a->profile[$field])) {
104 $json_info["$field"] = $a->profile[$field];
108 //Output all the JSON!
109 header('Content-type: application/json; charset=utf-8');
110 echo json_encode($json_info);