]> git.mxchange.org Git - friendica.git/blob - mod/noscrape.php
Merge pull request #1338 from annando/1501-global-contacts
[friendica.git] / mod / noscrape.php
1 <?php
2
3 function noscrape_init(&$a) {
4
5         if(get_config('system','disable_noscrape'))
6                 killme();
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'])
22                 killme();
23
24         $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
25         $keywords = str_replace(array('#',',',' ',',,'),array('',' ',',',','),$keywords);
26         $keywords = explode(',', $keywords);
27
28         $json_info = array(
29                 'fn' => $a->profile['name'],
30                 'key' => $a->profile['pubkey'],
31                 'homepage' => $a->get_baseurl()."/profile/{$which}",
32                 'comm' => (x($a->profile,'page-flags')) && ($a->profile['page-flags'] == PAGE_COMMUNITY),
33                 'photo' => $a->profile['photo'],
34                 'tags' => $keywords
35         );
36
37         //These are optional fields.
38         $profile_fields = array('pdesc', 'locality', 'region', 'postal-code', 'country-name', 'gender', 'marital', 'about');
39         foreach($profile_fields as $field)
40                 if(!empty($a->profile[$field])) $json_info["$field"] = $a->profile[$field];
41
42         $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
43         foreach($dfrn_pages as $dfrn)
44                 $json_info["dfrn-{$dfrn}"] = $a->get_baseurl()."/dfrn_{$dfrn}/{$which}";
45
46         //Output all the JSON!
47         header('Content-type: application/json; charset=utf-8');
48         echo json_encode($json_info);
49         exit;
50
51 }