]> git.mxchange.org Git - friendica.git/blob - mod/display.php
more lint
[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() && (local_user() == $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`, `contact`.`rel`,
89                 `contact`.`network`, `contact`.`thumb`, `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` = '%s' OR `uri` = '%s' ))
95                 $sql_extra
96                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
97                 intval($a->profile['uid']),
98                 dbesc($item_id),
99                 dbesc($item_id)
100         );
101
102
103         $cmnt_tpl = load_view_file('view/comment_item.tpl');
104         $like_tpl = load_view_file('view/like.tpl');
105         $tpl = load_view_file('view/wall_item.tpl');
106         $wallwall = load_view_file('view/wallwall_item.tpl');
107
108         $return_url = $_SESSION['return_url'] = $a->cmd;
109
110         $alike = array();
111         $dlike = array();
112
113         if(count($r)) {
114
115                 foreach($r as $item) {
116                         like_puller($a,$item,$alike,'like');
117                         like_puller($a,$item,$dlike,'dislike');
118                 }
119
120                 foreach($r as $item) {
121                         $comment = '';
122                         $template = $tpl;
123                         
124                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
125                         
126                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
127                                 && ($item['id'] != $item['parent']))
128                                 continue;
129
130                         $lock = (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
131                                 || strlen($item['deny_cid']) || strlen($item['deny_gid']))
132                                 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
133                                 : '<div class="wall-item-lock"></div>');
134
135                         if(can_write_wall($a,$a->profile['uid'])) {
136                                 if($item['id'] == $item['parent']) {
137                                         $likebuttons = replace_macros($like_tpl,array('$id' => $item['id']));
138                                 }
139                                 if($item['last-child']) {
140                                         $comment = replace_macros($cmnt_tpl,array(
141                                                 '$return_path' => $_SESSION['return_url'],
142                                                 '$type' => 'wall-comment',
143                                                 '$id' => $item['item_id'],
144                                                 '$parent' => $item['parent'],
145                                                 '$profile_uid' =>  $a->profile['uid'],
146                                                 '$mylink' => $contact['url'],
147                                                 '$mytitle' => t('This is you'),
148                                                 '$myphoto' => $contact['thumb'],
149                                                 '$ww' => ''
150                                         ));
151                                 }
152                         }
153
154
155                         $profile_url = $item['url'];
156                         $sparkle = '';
157
158
159                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
160
161                         if(($item['network'] === 'dfrn') && (! $item['self'] )) {
162                                 $profile_url = $redirect_url;
163                                 $sparkle = ' sparkle';
164                         }
165
166
167                         // Top-level wall post not written by the wall owner (wall-to-wall)
168                         // First figure out who owns it. 
169
170                         $osparkle = '';
171
172                         if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
173                                 
174                                 if($item['type'] === 'wall') {
175                                         // I do. Put me on the left of the wall-to-wall notice.
176                                         $owner_url = $a->contact['url'];
177                                         $owner_photo = $a->contact['thumb'];
178                                         $owner_name = $a->contact['name'];
179                                         $template = $wallwall;
180                                         $commentww = 'ww';      
181                                 }
182                                 if($item['type'] === 'remote' && ($item['owner-link'] != $item['author-link'])) {
183                                         // Could be anybody. 
184                                         $owner_url = $item['owner-link'];
185                                         $owner_photo = $item['owner-avatar'];
186                                         $owner_name = $item['owner-name'];
187                                         $template = $wallwall;
188                                         $commentww = 'ww';
189                                         // If it is our contact, use a friendly redirect link
190                                         if(($item['owner-link'] == $item['url']) && ($item['network'] === 'dfrn')) {
191                                                 $owner_url = $redirect_url;
192                                                 $osparkle = ' sparkle';
193                                         }
194
195
196                                 }
197                         }
198
199                         $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
200                         $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
201                         $profile_link = $profile_url;
202
203                         if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == local_user()))
204                                 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
205                         else 
206                                 $drop = replace_macros(load_view_file('view/wall_fake_drop.tpl'), array('$id' => $item['id']));
207
208                         $like    = (($alike[$item['id']]) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
209                         $dislike = (($dlike[$item['id']]) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
210                         $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
211                         $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
212                         if($coord) {
213                                 if($location)
214                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
215                                 else
216                                         $location = '<span class="smalltext">' . $coord . '</span>';
217                         }
218
219                         $o .= replace_macros($template,array(
220                                 '$id' => $item['item_id'],
221                                 '$profile_url' => $profile_link,
222                                 '$name' => $profile_name,
223                                 '$sparkle' => $sparkle,
224                                 '$osparkle' => $osparkle,
225                                 '$thumb' => $profile_avatar,
226                                 '$title' => $item['title'],
227                                 '$body' => bbcode($item['body']),
228                                 '$ago' => relative_date($item['created']),
229                                 '$lock' => $lock,
230                                 '$location' => $location,
231                                 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
232                                 '$owner_url' => $owner_url,
233                                 '$owner_photo' => $owner_photo,
234                                 '$owner_name' => $owner_name,
235                                 '$drop' => $drop,
236                                 '$vote' => $likebuttons,
237                                 '$like' => $like,
238                                 '$dislike' => $dislike,
239                                 '$comment' => $comment
240                         ));
241
242                 }
243         }
244         else {
245                 $r = q("SELECT `id` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
246                         dbesc($item_id),
247                         dbesc($item_id)
248                 );
249                 if(count($r)) {
250                         if($r[0]['deleted']) {
251                                 notice( t('Item has been removed.') . EOL );
252                         }
253                         else {  
254                                 notice( t('Permission denied.') . EOL ); 
255                         }
256                 }
257                 else {
258                         notice( t('Item not found.') . EOL );
259                 }
260
261         }
262         return $o;
263 }
264