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