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