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