]> git.mxchange.org Git - friendica.git/blob - mod/noscrape.php
Merge branch 'develop' into 1703-worker-splitting
[friendica.git] / mod / noscrape.php
1 <?php
2
3 function noscrape_init(App $a) {
4
5         if ($a->argc > 1) {
6                 $which = $a->argv[1];
7         } else {
8                 killme();
9         }
10
11         $profile = 0;
12         if ((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
13                 $which = $a->user['nickname'];
14                 $profile = $a->argv[1];
15         }
16
17         profile_load($a,$which,$profile);
18
19         if (!$a->profile['net-publish'] OR $a->profile['hidewall']) {
20                 header('Content-type: application/json; charset=utf-8');
21                 $json_info = array("hide" => true);
22                 echo json_encode($json_info);
23                 exit;
24         }
25
26         $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
27         $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
28         $keywords = explode(',', $keywords);
29
30         $r = q("SELECT `photo` FROM `contact` WHERE `self` AND `uid` = %d",
31                 intval($a->profile['uid']));
32
33         $json_info = array(
34                 'fn'       => $a->profile['name'],
35                 'addr'     => $a->profile['addr'],
36                 'nick'     => $which,
37                 'key'      => $a->profile['pubkey'],
38                 'homepage' => App::get_baseurl()."/profile/{$which}",
39                 'comm'     => (x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY),
40                 'photo'    => $r[0]["photo"],
41                 'tags'     => $keywords
42         );
43
44         if (is_array($a->profile) AND !$a->profile['hide-friends']) {
45                 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
46                         intval($a->profile['uid']));
47                 if (dbm::is_result($r)) {
48                         $json_info["updated"] =  date("c", strtotime($r[0]['updated']));
49                 }
50
51                 $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
52                                 AND `network` IN ('%s', '%s', '%s', '')",
53                         intval($a->profile['uid']),
54                         dbesc(NETWORK_DFRN),
55                         dbesc(NETWORK_DIASPORA),
56                         dbesc(NETWORK_OSTATUS)
57                 );
58                 if (dbm::is_result($r)) {
59                         $json_info["contacts"] = intval($r[0]['total']);
60                 }
61         }
62
63         //These are optional fields.
64         $profile_fields = array('pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about');
65         foreach ($profile_fields as $field) {
66                 if (!empty($a->profile[$field])) {
67                         $json_info["$field"] = $a->profile[$field];
68                 }
69         }
70
71         $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
72         foreach ($dfrn_pages as $dfrn) {
73                 $json_info["dfrn-{$dfrn}"] = App::get_baseurl()."/dfrn_{$dfrn}/{$which}";
74         }
75
76         //Output all the JSON!
77         header('Content-type: application/json; charset=utf-8');
78         echo json_encode($json_info);
79         exit;
80
81 }