]> git.mxchange.org Git - friendica.git/blob - mod/display.php
"firewall" setting - block all public pages from the public if configured to do so
[friendica.git] / mod / display.php
1 <?php
2
3
4 function display_content(&$a) {
5
6         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
7                 notice( t('Public access denied.') . EOL);
8                 return;
9         }
10
11         require_once("include/bbcode.php");
12         require_once('include/security.php');
13         require_once('include/conversation.php');
14
15
16         $o = '<div id="live-display"></div>' . "\r\n";
17
18         $nick = (($a->argc > 1) ? $a->argv[1] : '');
19         profile_load($a,$nick);
20
21         $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
22
23         if(! $item_id) {
24                 $a->error = 404;
25                 notice( t('Item not found.') . EOL);
26                 return;
27         }
28
29
30
31         $groups = array();
32
33         $contact = null;
34         $remote_contact = false;
35
36         if(remote_user()) {
37                 $contact_id = $_SESSION['visitor_id'];
38                 $groups = init_groups_visitor($contact_id);
39                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
40                         intval($contact_id),
41                         intval($a->profile['uid'])
42                 );
43                 if(count($r)) {
44                         $contact = $r[0];
45                         $remote_contact = true;
46                 }
47         }
48
49         if(! $remote_contact) {
50                 if(local_user()) {
51                         $contact_id = $_SESSION['cid'];
52                         $contact = $a->contact;
53                 }
54         }
55
56         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
57                 intval($a->profile['uid'])
58         );
59         if(count($r))
60                 $a->page_contact = $r[0];
61
62         $sql_extra = "
63                 AND `allow_cid` = '' 
64                 AND `allow_gid` = '' 
65                 AND `deny_cid`  = '' 
66                 AND `deny_gid`  = '' 
67         ";
68
69
70         // Profile owner - everything is visible
71
72         if(local_user() && (local_user() == $a->profile['uid'])) {
73                 $sql_extra = '';                
74         }
75
76         // authenticated visitor - here lie dragons
77         // If $remotecontact is true, we know that not only is this a remotely authenticated
78         // person, but that it is *our* contact, which is important in multi-user mode.
79
80         elseif($remote_contact) {
81                 $gs = '<<>>'; // should be impossible to match
82                 if(count($groups)) {
83                         foreach($groups as $g)
84                                 $gs .= '|<' . intval($g) . '>';
85                 } 
86                 $sql_extra = sprintf(
87                         " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) 
88                           AND ( `deny_cid`  = '' OR  NOT `deny_cid` REGEXP '<%d>' ) 
89                           AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
90                           AND ( `deny_gid`  = '' OR  NOT `deny_gid` REGEXP '%s') ",
91
92                         intval($_SESSION['visitor_id']),
93                         intval($_SESSION['visitor_id']),
94                         dbesc($gs),
95                         dbesc($gs)
96                 );
97         }
98
99         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
100                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
101                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
102                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
103                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
104                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
105                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
106                 AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s' ))
107                 $sql_extra
108                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
109                 intval($a->profile['uid']),
110                 dbesc($item_id),
111                 dbesc($item_id)
112         );
113
114
115         if(count($r)) {
116
117                 if((local_user()) && (local_user() == $a->profile['uid'])) {
118                         q("UPDATE `item` SET `unseen` = 0 
119                                 WHERE `parent` = %d AND `unseen` = 1",
120                                 intval($r[0]['parent'])
121                         );
122                 }
123
124
125                 $o .= conversation($a,$r,'display', false);
126
127         }
128         else {
129                 $r = q("SELECT `id` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
130                         dbesc($item_id),
131                         dbesc($item_id)
132                 );
133                 if(count($r)) {
134                         if($r[0]['deleted']) {
135                                 notice( t('Item has been removed.') . EOL );
136                         }
137                         else {  
138                                 notice( t('Permission denied.') . EOL ); 
139                         }
140                 }
141                 else {
142                         notice( t('Item not found.') . EOL );
143                 }
144
145         }
146
147         $o .= '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';
148
149         return $o;
150 }
151