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