]> git.mxchange.org Git - friendica.git/blob - mod/display.php
Merge remote-tracking branch 'friendica/master'
[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         $a->page['htmlhead'] .= '<script>$(document).ready(function() { $(".comment-edit-wrapper  textarea").contact_autocomplete(baseurl+"/acl"); });</script>';
19
20
21         $nick = (($a->argc > 1) ? $a->argv[1] : '');
22         profile_load($a,$nick);
23
24         $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
25
26         if(! $item_id) {
27                 $a->error = 404;
28                 notice( t('Item not found.') . EOL);
29                 return;
30         }
31
32         $groups = array();
33
34         $contact = null;
35         $remote_contact = false;
36
37         if(remote_user()) {
38                 $contact_id = $_SESSION['visitor_id'];
39                 $groups = init_groups_visitor($contact_id);
40                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
41                         intval($contact_id),
42                         intval($a->profile['uid'])
43                 );
44                 if(count($r)) {
45                         $contact = $r[0];
46                         $remote_contact = true;
47                 }
48         }
49
50         if(! $remote_contact) {
51                 if(local_user()) {
52                         $contact_id = $_SESSION['cid'];
53                         $contact = $a->contact;
54                 }
55         }
56
57         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
58                 intval($a->profile['uid'])
59         );
60         if(count($r))
61                 $a->page_contact = $r[0];
62
63         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
64
65         if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
66                 notice( t('Access to this profile has been restricted.') . EOL);
67                 return;
68         }
69
70         $sql_extra = permissions_sql($a->profile['uid'],$remote_contact,$groups);
71
72         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
73                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
74                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
75                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
76                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
77                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
78                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
79                 AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s' ))
80                 $sql_extra
81                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
82                 intval($a->profile['uid']),
83                 dbesc($item_id),
84                 dbesc($item_id)
85         );
86
87
88         if(count($r)) {
89
90                 if((local_user()) && (local_user() == $a->profile['uid'])) {
91                         q("UPDATE `item` SET `unseen` = 0 
92                                 WHERE `parent` = %d AND `unseen` = 1",
93                                 intval($r[0]['parent'])
94                         );
95                 }
96
97
98                 $o .= conversation($a,$r,'display', false);
99
100         }
101         else {
102                 $r = q("SELECT `id` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
103                         dbesc($item_id),
104                         dbesc($item_id)
105                 );
106                 if(count($r)) {
107                         if($r[0]['deleted']) {
108                                 notice( t('Item has been removed.') . EOL );
109                         }
110                         else {  
111                                 notice( t('Permission denied.') . EOL ); 
112                         }
113                 }
114                 else {
115                         notice( t('Item not found.') . EOL );
116                 }
117
118         }
119
120         return $o;
121 }
122