]> git.mxchange.org Git - friendica.git/blob - mod/display.php
2125e169631ab38eb6d2096747a8a4da9a7433d9
[friendica.git] / mod / display.php
1 <?php
2
3
4 function display_content(&$a) {
5
6         require_once('mod/profile.php');
7         profile_init($a);
8
9         $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
10
11         if(! $item_id) {
12                 $a->error = 404;
13                 notice( t('Item not found.') . EOL);
14                 return;
15         }
16
17         require_once("include/bbcode.php");
18         require_once('include/security.php');
19
20
21         $groups = array();
22
23         $tab = 'posts';
24
25
26         $contact = null;
27         $remote_contact = false;
28
29         if(remote_user()) {
30                 $contact_id = $_SESSION['visitor_id'];
31                 $groups = init_groups_visitor($contact_id);
32                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
33                         intval($contact_id),
34                         intval($a->profile['uid'])
35                 );
36                 if(count($r)) {
37                         $contact = $r[0];
38                         $remote_contact = true;
39                 }
40         }
41
42         if(! $remote_contact) {
43                 if(local_user()) {
44                         $contact_id = $_SESSION['cid'];
45                         $contact = $a->contact;
46                 }
47         }
48
49
50         $sql_extra = "
51                 AND `allow_cid` = '' 
52                 AND `allow_gid` = '' 
53                 AND `deny_cid`  = '' 
54                 AND `deny_gid`  = '' 
55         ";
56
57
58         // Profile owner - everything is visible
59
60         if(local_user() && (get_uid() == $a->profile['uid'])) {
61                 $sql_extra = '';                
62         }
63
64         // authenticated visitor - here lie dragons
65         // If $remotecontact is true, we know that not only is this a remotely authenticated
66         // person, but that it is *our* contact, which is important in multi-user mode.
67
68         elseif($remote_contact) {
69                 $gs = '<<>>'; // should be impossible to match
70                 if(count($groups)) {
71                         foreach($groups as $g)
72                                 $gs .= '|<' . intval($g) . '>';
73                 } 
74                 $sql_extra = sprintf(
75                         " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) 
76                           AND ( `deny_cid`  = '' OR  NOT `deny_cid` REGEXP '<%d>' ) 
77                           AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
78                           AND ( `deny_gid`  = '' OR NOT `deny_gid` REGEXP '%s') ",
79
80                         intval($_SESSION['visitor_id']),
81                         intval($_SESSION['visitor_id']),
82                         dbesc($gs),
83                         dbesc($gs)
84                 );
85         }
86
87         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
88                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, 
89                 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`, 
90                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
91                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
92                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
93                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
94                 AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE `id` = %d )
95                 $sql_extra
96                 ORDER BY `parent` DESC, `id` ASC ",
97                 intval($a->profile['uid']),
98                 intval($item_id)
99         );
100
101
102         $cmnt_tpl = file_get_contents('view/comment_item.tpl');
103
104         $tpl = file_get_contents('view/wall_item.tpl');
105
106         $return_url = $_SESSION['return_url'] = $a->cmd;
107
108         if(count($r)) {
109                 foreach($r as $item) {
110                         $comment = '';
111                         $template = $tpl;
112                         
113                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
114                         
115
116                         if(can_write_wall($a,$a->profile['uid'])) {
117                                 if($item['last-child']) {
118                                         $comment = replace_macros($cmnt_tpl,array(
119                                                 '$return_path' => $_SESSION['return_url'],
120                                                 '$type' => 'wall-comment',
121                                                 '$id' => $item['item_id'],
122                                                 '$parent' => $item['parent'],
123                                                 '$profile_uid' =>  $a->profile['uid'],
124                                                 '$mylink' => $contact['url'],
125                                                 '$mytitle' => t('Me'),
126                                                 '$myphoto' => $contact['thumb'],
127                                                 '$ww' => ''
128                                         ));
129                                 }
130                         }
131
132
133                         $profile_url = $item['url'];
134
135
136                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
137
138
139                         // Top-level wall post not written by the wall owner (wall-to-wall)
140                         // First figure out who owns it. 
141
142                         if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
143                                 
144                                 if($item['type'] == 'wall') {
145                                         // I do. Put me on the left of the wall-to-wall notice.
146                                         $owner_url = $a->contact['url'];
147                                         $owner_photo = $a->contact['thumb'];
148                                         $owner_name = $a->contact['name'];
149                                         $template = $wallwall;
150                                         $commentww = 'ww';      
151                                 }
152                                 if($item['type'] == 'remote' && ($item['owner-link'] != $item['author-link'])) {
153                                         // Could be anybody. 
154                                         $owner_url = $item['owner-link'];
155                                         $owner_photo = $item['owner-avatar'];
156                                         $owner_name = $item['owner-name'];
157                                         $template = $wallwall;
158                                         $commentww = 'ww';
159                                         // If it is our contact, use a friendly redirect link
160                                         if(($item['owner-link'] == $item['url']) && ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH))
161                                                 $owner_url = $redirect_url;
162                                                 $owner_url = $redirect_url;
163
164                                 }
165                         }
166
167
168
169
170                         $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
171                         $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
172                         $profile_link = $profile_url;
173
174                         $drop = '';
175
176                         if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == get_uid()))
177                                 $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id']));
178
179
180                         $o .= replace_macros($template,array(
181                                 '$id' => $item['item_id'],
182                                 '$profile_url' => $profile_link,
183                                 '$name' => $profile_name,
184                                 '$thumb' => $profile_avatar,
185                                 '$title' => $item['title'],
186                                 '$body' => bbcode($item['body']),
187                                 '$ago' => relative_date($item['created']),
188                                 '$location' => (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : ''),
189                                 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
190                                 '$drop' => $drop,
191                                 '$comment' => $comment
192                         ));
193                         
194                 }
195         }
196
197         return $o;
198 }