]> git.mxchange.org Git - friendica.git/blob - mod/display.php
Merge branch 'erikl-master'
[friendica.git] / mod / display.php
1 <?php
2
3
4 function display_content(&$a) {
5
6         $o = '<div id="live-display"></div>' . "\r\n";
7
8         $nick = (($a->argc > 1) ? $a->argv[1] : '');
9         profile_load($a,$nick);
10
11         $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
12
13         if(! $item_id) {
14                 $a->error = 404;
15                 notice( t('Item not found.') . EOL);
16                 return;
17         }
18
19         require_once("include/bbcode.php");
20         require_once('include/security.php');
21
22
23         $groups = array();
24
25         $tab = 'posts';
26
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
52         $sql_extra = "
53                 AND `allow_cid` = '' 
54                 AND `allow_gid` = '' 
55                 AND `deny_cid`  = '' 
56                 AND `deny_gid`  = '' 
57         ";
58
59
60         // Profile owner - everything is visible
61
62         if(local_user() && (local_user() == $a->profile['uid'])) {
63                 $sql_extra = '';                
64         }
65
66         // authenticated visitor - here lie dragons
67         // If $remotecontact is true, we know that not only is this a remotely authenticated
68         // person, but that it is *our* contact, which is important in multi-user mode.
69
70         elseif($remote_contact) {
71                 $gs = '<<>>'; // should be impossible to match
72                 if(count($groups)) {
73                         foreach($groups as $g)
74                                 $gs .= '|<' . intval($g) . '>';
75                 } 
76                 $sql_extra = sprintf(
77                         " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' ) 
78                           AND ( `deny_cid`  = '' OR  NOT `deny_cid` REGEXP '<%d>' ) 
79                           AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
80                           AND ( `deny_gid`  = '' OR  NOT `deny_gid` REGEXP '%s') ",
81
82                         intval($_SESSION['visitor_id']),
83                         intval($_SESSION['visitor_id']),
84                         dbesc($gs),
85                         dbesc($gs)
86                 );
87         }
88
89         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
90                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
91                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, 
92                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
93                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
94                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
95                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
96                 AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s' ))
97                 $sql_extra
98                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
99                 intval($a->profile['uid']),
100                 dbesc($item_id),
101                 dbesc($item_id)
102         );
103
104
105
106         $cmnt_tpl = load_view_file('view/comment_item.tpl');
107         $like_tpl = load_view_file('view/like_noshare.tpl');
108         $tpl = load_view_file('view/wall_item.tpl');
109         $wallwall = load_view_file('view/wallwall_item.tpl');
110
111         $return_url = $_SESSION['return_url'] = $a->cmd;
112
113         $alike = array();
114         $dlike = array();
115
116         if(count($r)) {
117
118                 if((local_user()) && (local_user() == $a->profile['uid'])) {
119                         q("UPDATE `item` SET `unseen` = 0 
120                                 WHERE `parent` = %d AND `unseen` = 1",
121                                 intval($r[0]['parent'])
122                         );
123                 }
124
125                 foreach($r as $item) {
126                         like_puller($a,$item,$alike,'like');
127                         like_puller($a,$item,$dlike,'dislike');
128                 }
129
130                 $author_contacts = extract_item_authors($r,$a->profile['uid']);
131
132                 foreach($r as $item) {
133
134                         $template = $tpl;
135
136                         $comment     = '';
137                         $owner_url   = '';
138                         $owner_photo = '';
139                         $owner_name  = '';
140                         
141                         $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
142                         
143                         if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) 
144                                 && ($item['id'] != $item['parent']))
145                                 continue;
146
147                         $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) 
148                                 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
149                                 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
150                                 : '<div class="wall-item-lock"></div>');
151
152                         if(can_write_wall($a,$a->profile['uid'])) {
153                                 if($item['id'] == $item['parent']) {
154                                         $likebuttons = replace_macros($like_tpl,array(
155                                                 '$id' => $item['id'],
156                                                 '$likethis' => t("I like this \x28toggle\x29"),
157                                                 '$nolike' => t("I don't like this \x28toggle\x29"),
158                                                 '$share' => t('Share'),
159                                                 '$wait' => t('Please wait') 
160                                         ));
161                                 }
162                                 if($item['last-child']) {
163                                         $comment = replace_macros($cmnt_tpl,array(
164                                                 '$return_path' => '', 
165                                                 '$jsreload' => $_SESSION['return_url'],
166                                                 '$type' => 'wall-comment',
167                                                 '$id' => $item['item_id'],
168                                                 '$parent' => $item['parent'],
169                                                 '$profile_uid' =>  $a->profile['uid'],
170                                                 '$mylink' => $contact['url'],
171                                                 '$mytitle' => t('This is you'),
172                                                 '$myphoto' => $contact['thumb'],
173                                                 '$ww' => ''
174                                         ));
175                                 }
176                         }
177
178
179                         $profile_url = $item['url'];
180                         $sparkle = '';
181
182
183                         // Top-level wall post not written by the wall owner (wall-to-wall)
184                         // First figure out who owns it. 
185
186                         $osparkle = '';
187
188                         if(($item['parent'] == $item['item_id']) && (! $item['self'])) {
189                                 
190                                 if($item['type'] === 'wall') {
191                                         // I do. Put me on the left of the wall-to-wall notice.
192                                         $owner_url = $a->contact['url'];
193                                         $owner_photo = $a->contact['thumb'];
194                                         $owner_name = $a->contact['name'];
195                                         $template = $wallwall;
196                                         $commentww = 'ww';      
197                                 }
198                                 if($item['type'] === 'remote' && ($item['owner-link'] != $item['author-link'])) {
199                                         // Could be anybody. 
200                                         $owner_url = $item['owner-link'];
201                                         $owner_photo = $item['owner-avatar'];
202                                         $owner_name = $item['owner-name'];
203                                         $template = $wallwall;
204                                         $commentww = 'ww';
205                                         // If it is our contact, use a friendly redirect link
206                                         if((link_compare($item['owner-link'],$item['url'])) && ($item['network'] === 'dfrn')) {
207                                                 $owner_url = $redirect_url;
208                                                 $osparkle = ' sparkle';
209                                         }
210
211
212                                 }
213                         }
214
215                         $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
216
217                         $profile_name   = (((strlen($item['author-name']))   && $diff_author) ? $item['author-name']   : $item['name']);
218                         $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
219
220                         $edpost = '';
221                         if((local_user()) && ($item['uid'] == local_user()) && ($item['id'] == $item['parent']) && (intval($item['wall']) == 1)) 
222                                 $edpost = '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>';
223                         // Can we use our special contact URL for this author? 
224
225                         if(strlen($item['author-link'])) {
226                                 $profile_link = $item['author-link'];
227                                 if(link_compare($item['author-link'],$item['url']) && ($item['network'] === 'dfrn') && (! $item['self'])) {
228                                         $profile_link = $redirect_url;
229                                         $sparkle = ' sparkle';
230                                 }
231                                 elseif(isset($author_contacts[$item['author-link']])) {
232                                         $profile_link = $a->get_baseurl() . '/redir/' . $author_contacts[$item['author-link']];
233                                         $sparkle = ' sparkle';
234                                 }
235                         }
236
237                         if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
238                                 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
239                         else 
240                                 $drop = replace_macros(load_view_file('view/wall_fake_drop.tpl'), array('$id' => $item['id']));
241
242                         $like    = ((isset($alike[$item['id']])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
243                         $dislike = ((isset($dlike[$item['id']])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
244
245                         $location = (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
246                         $coord = (($item['coord']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
247                         if($coord) {
248                                 if($location)
249                                         $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
250                                 else
251                                         $location = '<span class="smalltext">' . $coord . '</span>';
252                         }
253
254                         $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
255
256                         if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
257                                 $indent .= ' shiny'; 
258
259
260                         $tmp_item = replace_macros($template,array(
261                                 '$id' => $item['item_id'],
262                                 '$linktitle' => t('View $name\'s profile'),
263                                 '$olinktitle' => t('View $owner_name\'s profile'),
264                                 '$to' => t('to'),
265                                 '$wall' => t('Wall-to-Wall'),
266                                 '$vwall' => t('via Wall-To-Wall:'),
267                                 '$item_photo_menu' => item_photo_menu($item),
268                                 '$profile_url' => $profile_link,
269                                 '$name' => $profile_name,
270                                 '$sparkle' => $sparkle,
271                                 '$osparkle' => $osparkle,
272                                 '$thumb' => $profile_avatar,
273                                 '$title' => $item['title'],
274                                 '$body' => smilies(bbcode($item['body'])),
275                                 '$ago' => relative_date($item['created']),
276                                 '$lock' => $lock,
277                                 '$location' => $location,
278                                 '$indent' => $indent,
279                                 '$owner_url' => $owner_url,
280                                 '$owner_photo' => $owner_photo,
281                                 '$owner_name' => $owner_name,
282                                 '$plink' => get_plink($item),
283                                 '$edpost' => $edpost,
284                                 '$drop' => $drop,
285                                 '$vote' => $likebuttons,
286                                 '$like' => $like,
287                                 '$dislike' => $dislike,
288                                 '$comment' => $comment
289                         ));
290
291                         $arr = array('item' => $item, 'output' => $tmp_item);
292                         call_hooks('display_item', $arr);
293
294                         $o .= $arr['output'];
295
296
297                 }
298         }
299         else {
300                 $r = q("SELECT `id` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
301                         dbesc($item_id),
302                         dbesc($item_id)
303                 );
304                 if(count($r)) {
305                         if($r[0]['deleted']) {
306                                 notice( t('Item has been removed.') . EOL );
307                         }
308                         else {  
309                                 notice( t('Permission denied.') . EOL ); 
310                         }
311                 }
312                 else {
313                         notice( t('Item not found.') . EOL );
314                 }
315
316         }
317
318         $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>';
319
320         return $o;
321 }
322