]> git.mxchange.org Git - friendica.git/blob - mod/display.php
Merge pull request #562 from fermionic/20121225-smarty-includes-like-friendicas
[friendica.git] / mod / display.php
1 <?php
2
3
4 function display_content(&$a, $update = 0) {
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 = '';
18
19         $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
20
21
22         if($update) {
23                 $nick = $_REQUEST['nick'];
24         }
25         else {
26                 $nick = (($a->argc > 1) ? $a->argv[1] : '');
27         }
28         profile_load($a,$nick);
29
30         if($update) {
31                 $item_id = $_REQUEST['item_id'];
32         }
33         else {
34                 $item_id = (($a->argc > 2) ? intval($a->argv[2]) : 0);
35         }
36
37         if(! $item_id) {
38                 $a->error = 404;
39                 notice( t('Item not found.') . EOL);
40                 return;
41         }
42
43         $groups = array();
44
45         $contact = null;
46         $remote_contact = false;
47
48         $contact_id = 0;
49
50         if(is_array($_SESSION['remote'])) {
51                 foreach($_SESSION['remote'] as $v) {
52                         if($v['uid'] == $a->profile['uid']) {
53                                 $contact_id = $v['cid'];
54                                 break;
55                         }
56                 }
57         }
58
59         if($contact_id) {
60                 $groups = init_groups_visitor($contact_id);
61                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
62                         intval($contact_id),
63                         intval($a->profile['uid'])
64                 );
65                 if(count($r)) {
66                         $contact = $r[0];
67                         $remote_contact = true;
68                 }
69         }
70
71         if(! $remote_contact) {
72                 if(local_user()) {
73                         $contact_id = $_SESSION['cid'];
74                         $contact = $a->contact;
75                 }
76         }
77
78         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
79                 intval($a->profile['uid'])
80         );
81         if(count($r))
82                 $a->page_contact = $r[0];
83
84         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
85
86         if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
87                 notice( t('Access to this profile has been restricted.') . EOL);
88                 return;
89         }
90         
91         if ($is_owner) {
92                 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
93
94                 $x = array(
95                         'is_owner' => true,
96                         'allow_location' => $a->user['allow_location'],
97                         'default_location' => $a->user['default-location'],
98                         'nickname' => $a->user['nickname'],
99                         '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'),
100                         'acl' => populate_acl($a->user, $celeb),
101                         'bang' => '',
102                         'visitor' => 'block',
103                         'profile_uid' => local_user()
104                 );      
105                 $o .= status_editor($a,$x,0,true);
106         }
107
108         $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
109
110         if($update) {
111                 $r = q("SELECT id FROM item WHERE item.uid = %d
112                         AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s' ))
113                         $sql_extra AND unseen = 1",
114                         intval($a->profile['uid']),
115                         dbesc($item_id),
116                         dbesc($item_id) 
117                 );
118                 if(!$r)
119                         return '';
120         }
121
122         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, 
123                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
124                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
125                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
126                 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
127                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
128                 and `item`.`moderated` = 0
129                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
130                 AND `item`.`parent` = ( SELECT `parent` FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s' ))
131                 $sql_extra
132                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
133                 intval($a->profile['uid']),
134                 dbesc($item_id),
135                 dbesc($item_id)
136         );
137
138
139         if(count($r)) {
140
141                 if((local_user()) && (local_user() == $a->profile['uid'])) {
142                         q("UPDATE `item` SET `unseen` = 0 
143                                 WHERE `parent` = %d AND `unseen` = 1",
144                                 intval($r[0]['parent'])
145                         );
146                 }
147
148                 $items = conv_sort($r,"`commented`");
149
150                 if(!$update)
151                         $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
152                 $o .= conversation($a,$items,'display', $update);
153
154         }
155         else {
156                 $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
157                         dbesc($item_id),
158                         dbesc($item_id)
159                 );
160                 if(count($r)) {
161                         if($r[0]['deleted']) {
162                                 notice( t('Item has been removed.') . EOL );
163                         }
164                         else {  
165                                 notice( t('Permission denied.') . EOL ); 
166                         }
167                 }
168                 else {
169                         notice( t('Item not found.') . EOL );
170                 }
171
172         }
173
174         return $o;
175 }
176