]> git.mxchange.org Git - friendica.git/blob - mod/noscrape.php
FR update to the strings THX Perig
[friendica.git] / mod / noscrape.php
1 <?php
2
3 function noscrape_init(&$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'])
19                 killme();
20
21         $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
22         $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
23         $keywords = explode(',', $keywords);
24
25         $json_info = array(
26                 'fn' => $a->profile['name'],
27                 'addr' => $a->profile['addr'],
28                 'key' => $a->profile['pubkey'],
29                 'homepage' => $a->get_baseurl()."/profile/{$which}",
30                 'comm' => (x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY),
31                 'photo' => $a->profile['photo'],
32                 'tags' => $keywords
33         );
34
35         if(is_array($a->profile) AND !$a->profile['hide-friends']) {
36                 $r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
37                         intval($a->profile['uid']));
38                 if(count($r))
39                         $json_info["updated"] =  date("c", strtotime($r[0]['updated']));
40
41                 $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
42                                 AND `network` IN ('%s', '%s', '%s', '')",
43                         intval($a->profile['uid']),
44                         dbesc(NETWORK_DFRN),
45                         dbesc(NETWORK_DIASPORA),
46                         dbesc(NETWORK_OSTATUS)
47                 );
48                 if(count($r))
49                         $json_info["contacts"] = intval($r[0]['total']);
50         }
51
52         //These are optional fields.
53         $profile_fields = array('pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about');
54         foreach($profile_fields as $field)
55                 if(!empty($a->profile[$field])) $json_info["$field"] = $a->profile[$field];
56
57         $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
58         foreach($dfrn_pages as $dfrn)
59                 $json_info["dfrn-{$dfrn}"] = $a->get_baseurl()."/dfrn_{$dfrn}/{$which}";
60
61         //Output all the JSON!
62         header('Content-type: application/json; charset=utf-8');
63         echo json_encode($json_info);
64         exit;
65
66 }