]> git.mxchange.org Git - friendica.git/blob - mod/noscrape.php
113ad8746266ac0ebbc466e00bec45bde59cfe8a
[friendica.git] / mod / noscrape.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\System;
5
6 function noscrape_init(App $a) {
7
8         if($a->argc > 1)
9                 $which = $a->argv[1];
10         else
11                 killme();
12
13         $profile = 0;
14         if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
15                 $which = $a->user['nickname'];
16                 $profile = $a->argv[1];
17         }
18
19         profile_load($a,$which,$profile);
20
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);
25                 exit;
26         }
27
28         $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
29         $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
30         $keywords = explode(',', $keywords);
31
32         $r = q("SELECT `photo` FROM `contact` WHERE `self` AND `uid` = %d",
33                 intval($a->profile['uid']));
34
35         $json_info = array(
36                 'fn'       => $a->profile['name'],
37                 'addr'     => $a->profile['addr'],
38                 'nick'     => $which,
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"],
44                 'tags'     => $keywords
45         );
46
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']));
53                 }
54
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']),
58                         dbesc(NETWORK_DFRN),
59                         dbesc(NETWORK_DIASPORA),
60                         dbesc(NETWORK_OSTATUS)
61                 );
62                 if (dbm::is_result($r)) {
63                         $json_info["contacts"] = intval($r[0]['total']);
64                 }
65         }
66
67         // We display the last activity (post or login), reduced to year and week number
68         $last_active = 0;
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']);
73         }
74
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']);
80                 }
81         }
82         $json_info["last-activity"] = date("o-W", $last_active);
83
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];
89                 }
90         }
91
92         $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
93         foreach ($dfrn_pages as $dfrn) {
94                 $json_info["dfrn-{$dfrn}"] = System::baseUrl()."/dfrn_{$dfrn}/{$which}";
95         }
96
97         //Output all the JSON!
98         header('Content-type: application/json; charset=utf-8');
99         echo json_encode($json_info);
100         exit;
101
102 }