3 * @file mod/noscrape.php
6 use Friendica\Core\System;
7 use Friendica\Database\DBM;
9 function noscrape_init(App $a)
18 if ((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
19 $which = $a->user['nickname'];
20 $profile = $a->argv[1];
23 Profile::load($a, $which, $profile);
25 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
26 header('Content-type: application/json; charset=utf-8');
27 $json_info = array("hide" => true);
28 echo json_encode($json_info);
32 $keywords = ((x($a->profile, 'pub_keywords')) ? $a->profile['pub_keywords'] : '');
33 $keywords = str_replace(array('#',',',' ',',,'), array('',' ',',',','), $keywords);
34 $keywords = explode(',', $keywords);
36 $r = dba::selectFirst('contact', ['photo'], ['self' => true, 'uid' => $a->profile['uid']]);
39 'fn' => $a->profile['name'],
40 'addr' => $a->profile['addr'],
42 'guid' => $a->profile['guid'],
43 'key' => $a->profile['pubkey'],
44 'homepage' => System::baseUrl()."/profile/{$which}",
45 'comm' => (x($a->profile, 'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY),
46 'photo' => $r["photo"],
50 if (is_array($a->profile) && !$a->profile['hide-friends']) {
51 /// @todo What should this value tell us?
52 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
53 intval($a->profile['uid']));
54 if (DBM::is_result($r)) {
55 $json_info["updated"] = date("c", strtotime($r[0]['updated']));
58 $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
59 AND `network` IN ('%s', '%s', '%s', '')",
60 intval($a->profile['uid']),
62 dbesc(NETWORK_DIASPORA),
63 dbesc(NETWORK_OSTATUS)
65 if (DBM::is_result($r)) {
66 $json_info["contacts"] = intval($r[0]['total']);
70 // We display the last activity (post or login), reduced to year and week number
72 $condition = ['uid' => $a->profile['uid'], 'self' => true];
73 $contact = dba::selectFirst('contact', ['last-item'], $condition);
74 if (DBM::is_result($contact)) {
75 $last_active = strtotime($contact['last-item']);
78 $condition = ['uid' => $a->profile['uid']];
79 $user = dba::selectFirst('user', ['login_date'], $condition);
80 if (DBM::is_result($user)) {
81 if ($last_active < strtotime($user['login_date'])) {
82 $last_active = strtotime($user['login_date']);
85 $json_info["last-activity"] = date("o-W", $last_active);
87 //These are optional fields.
88 $profile_fields = array('pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about');
89 foreach ($profile_fields as $field) {
90 if (!empty($a->profile[$field])) {
91 $json_info["$field"] = $a->profile[$field];
95 $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
96 foreach ($dfrn_pages as $dfrn) {
97 $json_info["dfrn-{$dfrn}"] = System::baseUrl()."/dfrn_{$dfrn}/{$which}";
100 //Output all the JSON!
101 header('Content-type: application/json; charset=utf-8');
102 echo json_encode($json_info);