3 * @file mod/noscrape.php
6 use Friendica\Core\System;
7 use Friendica\Database\DBM;
8 use Friendica\Model\Profile;
10 function noscrape_init(App $a)
19 if ((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
20 $which = $a->user['nickname'];
21 $profile = $a->argv[1];
24 Profile::load($a, $which, $profile);
27 'addr' => $a->profile['addr'],
29 'guid' => $a->profile['guid'],
30 'key' => $a->profile['pubkey'],
31 'homepage' => System::baseUrl()."/profile/{$which}",
32 'comm' => ($a->profile['account-type'] == ACCOUNT_TYPE_COMMUNITY),
35 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
36 header('Content-type: application/json; charset=utf-8');
37 $json_info["hide"] = true;
38 echo json_encode($json_info);
42 $keywords = ((x($a->profile, 'pub_keywords')) ? $a->profile['pub_keywords'] : '');
43 $keywords = str_replace(['#',',',' ',',,'], ['',' ',',',','], $keywords);
44 $keywords = explode(',', $keywords);
46 $contactPhoto = dba::selectFirst('contact', ['photo'], ['self' => true, 'uid' => $a->profile['uid']]);
48 $json_info['fn'] = $a->profile['name'];
49 $json_info['photo'] = $contactPhoto["photo"];
50 $json_info['tags'] = $keywords;
52 if (is_array($a->profile) && !$a->profile['hide-friends']) {
53 /// @todo What should this value tell us?
54 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
55 intval($a->profile['uid']));
56 if (DBM::is_result($r)) {
57 $json_info["updated"] = date("c", strtotime($r[0]['updated']));
60 $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
61 AND `network` IN ('%s', '%s', '%s', '')",
62 intval($a->profile['uid']),
64 dbesc(NETWORK_DIASPORA),
65 dbesc(NETWORK_OSTATUS)
67 if (DBM::is_result($r)) {
68 $json_info["contacts"] = intval($r[0]['total']);
72 // We display the last activity (post or login), reduced to year and week number
74 $condition = ['uid' => $a->profile['uid'], 'self' => true];
75 $contact = dba::selectFirst('contact', ['last-item'], $condition);
76 if (DBM::is_result($contact)) {
77 $last_active = strtotime($contact['last-item']);
80 $condition = ['uid' => $a->profile['uid']];
81 $user = dba::selectFirst('user', ['login_date'], $condition);
82 if (DBM::is_result($user)) {
83 if ($last_active < strtotime($user['login_date'])) {
84 $last_active = strtotime($user['login_date']);
87 $json_info["last-activity"] = date("o-W", $last_active);
89 //These are optional fields.
90 $profile_fields = ['pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about'];
91 foreach ($profile_fields as $field) {
92 if (!empty($a->profile[$field])) {
93 $json_info["$field"] = $a->profile[$field];
97 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
98 foreach ($dfrn_pages as $dfrn) {
99 $json_info["dfrn-{$dfrn}"] = System::baseUrl()."/dfrn_{$dfrn}/{$which}";
102 //Output all the JSON!
103 header('Content-type: application/json; charset=utf-8');
104 echo json_encode($json_info);