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);
26 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
27 header('Content-type: application/json; charset=utf-8');
28 $json_info = ["hide" => true];
29 echo json_encode($json_info);
33 $keywords = ((x($a->profile, 'pub_keywords')) ? $a->profile['pub_keywords'] : '');
34 $keywords = str_replace(['#',',',' ',',,'], ['',' ',',',','], $keywords);
35 $keywords = explode(',', $keywords);
37 $contactPhoto = dba::selectFirst('contact', ['photo'], ['self' => true, 'uid' => $a->profile['uid']]);
40 'fn' => $a->profile['name'],
41 'addr' => $a->profile['addr'],
43 'guid' => $a->profile['guid'],
44 'key' => $a->profile['pubkey'],
45 'homepage' => System::baseUrl()."/profile/{$which}",
46 'comm' => (x($a->profile, 'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY),
47 'photo' => $contactPhoto["photo"],
51 if (is_array($a->profile) && !$a->profile['hide-friends']) {
52 /// @todo What should this value tell us?
53 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
54 intval($a->profile['uid']));
55 if (DBM::is_result($r)) {
56 $json_info["updated"] = date("c", strtotime($r[0]['updated']));
59 $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
60 AND `network` IN ('%s', '%s', '%s', '')",
61 intval($a->profile['uid']),
63 dbesc(NETWORK_DIASPORA),
64 dbesc(NETWORK_OSTATUS)
66 if (DBM::is_result($r)) {
67 $json_info["contacts"] = intval($r[0]['total']);
71 // We display the last activity (post or login), reduced to year and week number
73 $condition = ['uid' => $a->profile['uid'], 'self' => true];
74 $contact = dba::selectFirst('contact', ['last-item'], $condition);
75 if (DBM::is_result($contact)) {
76 $last_active = strtotime($contact['last-item']);
79 $condition = ['uid' => $a->profile['uid']];
80 $user = dba::selectFirst('user', ['login_date'], $condition);
81 if (DBM::is_result($user)) {
82 if ($last_active < strtotime($user['login_date'])) {
83 $last_active = strtotime($user['login_date']);
86 $json_info["last-activity"] = date("o-W", $last_active);
88 //These are optional fields.
89 $profile_fields = ['pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about'];
90 foreach ($profile_fields as $field) {
91 if (!empty($a->profile[$field])) {
92 $json_info["$field"] = $a->profile[$field];
96 $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
97 foreach ($dfrn_pages as $dfrn) {
98 $json_info["dfrn-{$dfrn}"] = System::baseUrl()."/dfrn_{$dfrn}/{$which}";
101 //Output all the JSON!
102 header('Content-type: application/json; charset=utf-8');
103 echo json_encode($json_info);