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