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