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