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