]> git.mxchange.org Git - friendica.git/blob - mod/noscrape.php
Remove unused global cache constants
[friendica.git] / mod / noscrape.php
1 <?php
2 /**
3  * @file mod/noscrape.php
4  */
5 use Friendica\App;
6 use Friendica\Core\System;
7 use Friendica\Database\DBM;
8 use Friendica\Model\Profile;
9
10 function noscrape_init(App $a)
11 {
12         if ($a->argc > 1) {
13                 $which = $a->argv[1];
14         } else {
15                 killme();
16         }
17
18         $profile = 0;
19         if ((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
20                 $which = $a->user['nickname'];
21                 $profile = $a->argv[1];
22         }
23
24         Profile::load($a, $which, $profile);
25
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);
30                 exit;
31         }
32
33         $keywords = ((x($a->profile, 'pub_keywords')) ? $a->profile['pub_keywords'] : '');
34         $keywords = str_replace(['#',',',' ',',,'], ['',' ',',',','], $keywords);
35         $keywords = explode(',', $keywords);
36
37         $contactPhoto = dba::selectFirst('contact', ['photo'], ['self' => true, 'uid' => $a->profile['uid']]);
38
39         $json_info = [
40                 'fn'       => $a->profile['name'],
41                 'addr'     => $a->profile['addr'],
42                 'nick'     => $which,
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"],
48                 'tags'     => $keywords
49         ];
50
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']));
57                 }
58
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']),
62                         dbesc(NETWORK_DFRN),
63                         dbesc(NETWORK_DIASPORA),
64                         dbesc(NETWORK_OSTATUS)
65                 );
66                 if (DBM::is_result($r)) {
67                         $json_info["contacts"] = intval($r[0]['total']);
68                 }
69         }
70
71         // We display the last activity (post or login), reduced to year and week number
72         $last_active = 0;
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']);
77         }
78
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']);
84                 }
85         }
86         $json_info["last-activity"] = date("o-W", $last_active);
87
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];
93                 }
94         }
95
96         $dfrn_pages = ['request', 'confirm', 'notify', 'poll'];
97         foreach ($dfrn_pages as $dfrn) {
98                 $json_info["dfrn-{$dfrn}"] = System::baseUrl()."/dfrn_{$dfrn}/{$which}";
99         }
100
101         //Output all the JSON!
102         header('Content-type: application/json; charset=utf-8');
103         echo json_encode($json_info);
104         exit;
105 }