4 use Friendica\Core\System;
6 function noscrape_init(App $a) {
14 if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
15 $which = $a->user['nickname'];
16 $profile = $a->argv[1];
19 profile_load($a,$which,$profile);
21 if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
22 header('Content-type: application/json; charset=utf-8');
23 $json_info = array("hide" => true);
24 echo json_encode($json_info);
28 $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
29 $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
30 $keywords = explode(',', $keywords);
32 $r = q("SELECT `photo` FROM `contact` WHERE `self` AND `uid` = %d",
33 intval($a->profile['uid']));
36 'fn' => $a->profile['name'],
37 'addr' => $a->profile['addr'],
39 'guid' => $a->profile['guid'],
40 'key' => $a->profile['pubkey'],
41 'homepage' => System::baseUrl()."/profile/{$which}",
42 'comm' => (x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY),
43 'photo' => $r[0]["photo"],
47 if (is_array($a->profile) && !$a->profile['hide-friends']) {
48 /// @todo What should this value tell us?
49 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
50 intval($a->profile['uid']));
51 if (dbm::is_result($r)) {
52 $json_info["updated"] = date("c", strtotime($r[0]['updated']));
55 $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
56 AND `network` IN ('%s', '%s', '%s', '')",
57 intval($a->profile['uid']),
59 dbesc(NETWORK_DIASPORA),
60 dbesc(NETWORK_OSTATUS)
62 if (dbm::is_result($r)) {
63 $json_info["contacts"] = intval($r[0]['total']);
67 // We display the last activity (post or login), reduced to year and week number
69 $condition = array('uid' => $a->profile['uid'], 'self' => true);
70 $contact = dba::select('contact', array('last-item'), $condition, array('limit' => 1));
71 if (dbm::is_result($contact)) {
72 $last_active = strtotime($contact['last-item']);
75 $condition = array('uid' => $a->profile['uid']);
76 $user = dba::select('user', array('login_date'), $condition, array('limit' => 1));
77 if (dbm::is_result($user)) {
78 if ($last_active < strtotime($user['login_date'])) {
79 $last_active = strtotime($user['login_date']);
82 $json_info["last-activity"] = date("o-W", $last_active);
84 //These are optional fields.
85 $profile_fields = array('pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about');
86 foreach ($profile_fields as $field) {
87 if (!empty($a->profile[$field])) {
88 $json_info["$field"] = $a->profile[$field];
92 $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
93 foreach ($dfrn_pages as $dfrn) {
94 $json_info["dfrn-{$dfrn}"] = System::baseUrl()."/dfrn_{$dfrn}/{$which}";
97 //Output all the JSON!
98 header('Content-type: application/json; charset=utf-8');
99 echo json_encode($json_info);