]> git.mxchange.org Git - friendica.git/blob - mod/display.php
Merge pull request #927 from annando/master
[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                 return;
8         }
9
10         $nick = (($a->argc > 1) ? $a->argv[1] : '');
11         profile_load($a,$nick);
12
13 }
14
15
16 function display_content(&$a, $update = 0) {
17
18         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
19                 notice( t('Public access denied.') . EOL);
20                 return;
21         }
22
23         require_once("include/bbcode.php");
24         require_once('include/security.php');
25         require_once('include/conversation.php');
26         require_once('include/acl_selectors.php');
27
28
29         $o = '';
30
31         $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
32
33
34         if($update) {
35                 $nick = $_REQUEST['nick'];
36         }
37         else {
38                 $nick = (($a->argc > 1) ? $a->argv[1] : '');
39         }
40
41         if($update) {
42                 $item_id = $_REQUEST['item_id'];
43                 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
44         }
45         else {
46                 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
47         }
48
49         if(! $item_id) {
50                 $a->error = 404;
51                 notice( t('Item not found.') . EOL);
52                 return;
53         }
54
55         $groups = array();
56
57         $contact = null;
58         $remote_contact = false;
59
60         $contact_id = 0;
61
62         if(is_array($_SESSION['remote'])) {
63                 foreach($_SESSION['remote'] as $v) {
64                         if($v['uid'] == $a->profile['uid']) {
65                                 $contact_id = $v['cid'];
66                                 break;
67                         }
68                 }
69         }
70
71         if($contact_id) {
72                 $groups = init_groups_visitor($contact_id);
73                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
74                         intval($contact_id),
75                         intval($a->profile['uid'])
76                 );
77                 if(count($r)) {
78                         $contact = $r[0];
79                         $remote_contact = true;
80                 }
81         }
82
83         if(! $remote_contact) {
84                 if(local_user()) {
85                         $contact_id = $_SESSION['cid'];
86                         $contact = $a->contact;
87                 }
88         }
89
90         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
91                 intval($a->profile['uid'])
92         );
93         if(count($r))
94                 $a->page_contact = $r[0];
95
96         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
97
98         if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
99                 notice( t('Access to this profile has been restricted.') . EOL);
100                 return;
101         }
102
103         if ($is_owner) {
104                 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
105
106                 $x = array(
107                         'is_owner' => true,
108                         'allow_location' => $a->user['allow_location'],
109                         'default_location' => $a->user['default-location'],
110                         'nickname' => $a->user['nickname'],
111                         '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'),
112                         'acl' => populate_acl($a->user, $celeb),
113                         'bang' => '',
114                         'visitor' => 'block',
115                         'profile_uid' => local_user(),
116                         'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
117                 );
118                 $o .= status_editor($a,$x,0,true);
119         }
120
121         $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
122
123         //              AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
124
125         if($update) {
126
127                 $r = q("SELECT id FROM item WHERE item.uid = %d
128                         AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s'))
129                         $sql_extra AND unseen = 1",
130                         intval($a->profile['uid']),
131                         dbesc($item_id),
132                         dbesc($item_id)
133                 );
134
135                 if(!$r)
136                         return '';
137         }
138
139         //      AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
140
141         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,  `item`.`network` AS `item_network`,
142                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
143                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
144                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
145                 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
146                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
147                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
148                 and `item`.`moderated` = 0
149                 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
150                 AND uid = %d)
151                 $sql_extra
152                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
153                 intval($a->profile['uid']),
154                 dbesc($item_id),
155                 dbesc($item_id),
156                 intval($a->profile['uid'])
157         );
158
159         if(!$r && local_user()) {
160                 // Check if this is another person's link to a post that we have
161                 $r = q("SELECT `item`.uri FROM `item`
162                         WHERE (`item`.`id` = '%s' OR `item`.`uri` = '%s' )
163                         LIMIT 1",
164                         dbesc($item_id),
165                         dbesc($item_id)
166                 );
167                 if($r) {
168                         $item_uri = $r[0]['uri'];
169                         //      AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
170
171                         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,  `item`.`network` AS `item_network`,
172                                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
173                                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
174                                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
175                                 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
176                                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
177                                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
178                                 and `item`.`moderated` = 0
179                                 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
180                                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
181                                 intval(local_user()),
182                                 dbesc($item_uri),
183                                 intval(local_user())
184                         );
185                 }
186         }
187
188
189         if($r) {
190
191                 if((local_user()) && (local_user() == $a->profile['uid'])) {
192                         q("UPDATE `item` SET `unseen` = 0
193                                 WHERE `parent` = %d AND `unseen` = 1",
194                                 intval($r[0]['parent'])
195                         );
196                 }
197
198                 $items = conv_sort($r,"`commented`");
199
200                 if(!$update)
201                         $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
202                 $o .= conversation($a,$items,'display', $update);
203
204                 // Preparing the meta header
205                 require_once('include/bbcode.php');
206                 require_once("include/html2plain.php");
207                 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
208                 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
209                 $author_name = $r[0]["author-name"];
210
211                 $image = "";
212                 if ($image == "")
213                         $image = $r[0]["thumb"];
214
215                 if ($title == "")
216                         $title = $author_name;
217
218                 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
219                 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
220                 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
221
222                 //<meta name="keywords" content="">
223                 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
224                 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
225                 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
226                 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
227
228                 // Schema.org microdata
229                 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
230                 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
231                 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
232                 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
233
234                 // Twitter cards
235                 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
236                 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
237                 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
238                 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
239                 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
240
241                 // Dublin Core
242                 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
243                 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
244
245                 // Open Graph
246                 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
247                 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
248                 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
249                 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
250                 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
251                 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
252                 // article:tag
253
254                 return $o;
255         }
256
257         $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
258                 dbesc($item_id),
259                 dbesc($item_id)
260         );
261         if($r) {
262                 if($r[0]['deleted']) {
263                         notice( t('Item has been removed.') . EOL );
264                 }
265                 else {
266                         notice( t('Permission denied.') . EOL );
267                 }
268         }
269         else {
270                 notice( t('Item not found.') . EOL );
271         }
272
273         return $o;
274 }
275