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