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