]> git.mxchange.org Git - friendica.git/blob - mod/display.php
Merge branch 'master' of https://github.com/friendica/friendica into threaded_items
[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         require_once('include/acl_selectors.php');
15
16
17         $o = '<div id="live-display"></div>' . "\r\n";
18
19         $a->page['htmlhead'] .= get_markup_template('display-head.tpl');
20
21
22         $nick = (($a->argc > 1) ? $a->argv[1] : '');
23         profile_load($a,$nick);
24
25         $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
26
27         if(! $item_id) {
28                 $a->error = 404;
29                 notice( t('Item not found.') . EOL);
30                 return;
31         }
32
33         $groups = array();
34
35         $contact = null;
36         $remote_contact = false;
37
38         if(remote_user()) {
39                 $contact_id = $_SESSION['visitor_id'];
40                 $groups = init_groups_visitor($contact_id);
41                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
42                         intval($contact_id),
43                         intval($a->profile['uid'])
44                 );
45                 if(count($r)) {
46                         $contact = $r[0];
47                         $remote_contact = true;
48                 }
49         }
50
51         if(! $remote_contact) {
52                 if(local_user()) {
53                         $contact_id = $_SESSION['cid'];
54                         $contact = $a->contact;
55                 }
56         }
57
58         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
59                 intval($a->profile['uid'])
60         );
61         if(count($r))
62                 $a->page_contact = $r[0];
63
64         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
65
66         if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
67                 notice( t('Access to this profile has been restricted.') . EOL);
68                 return;
69         }
70         
71         if ($is_owner)
72                 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
73
74                 $x = array(
75                         'is_owner' => true,
76                         'allow_location' => $a->user['allow_location'],
77                         'default_location' => $a->user['default-location'],
78                         'nickname' => $a->user['nickname'],
79                         'lockstate' => ( (is_array($a->user)) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))) ? 'lock' : 'unlock'),
80                         'acl' => populate_acl($a->user, $celeb),
81                         'bang' => '',
82                         'visitor' => 'block',
83                         'profile_uid' => local_user()
84                 );      
85                 $o .= status_editor($a,$x,0,true);
86
87
88         $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
89
90         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
91                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
92                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
93                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
94                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
95                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
96                 and `item`.`moderated` = 0
97                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
98                 AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s' ))
99                 $sql_extra
100                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
101                 intval($a->profile['uid']),
102                 dbesc($item_id),
103                 dbesc($item_id)
104         );
105
106
107         if(count($r)) {
108
109                 if((local_user()) && (local_user() == $a->profile['uid'])) {
110                         q("UPDATE `item` SET `unseen` = 0 
111                                 WHERE `parent` = %d AND `unseen` = 1",
112                                 intval($r[0]['parent'])
113                         );
114                 }
115
116
117                 $o .= conversation($a,$r,'display', false);
118
119         }
120         else {
121                 $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
122                         dbesc($item_id),
123                         dbesc($item_id)
124                 );
125                 if(count($r)) {
126                         if($r[0]['deleted']) {
127                                 notice( t('Item has been removed.') . EOL );
128                         }
129                         else {  
130                                 notice( t('Permission denied.') . EOL ); 
131                         }
132                 }
133                 else {
134                         notice( t('Item not found.') . EOL );
135                 }
136
137         }
138
139         return $o;
140 }
141