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