]> git.mxchange.org Git - friendica.git/blob - mod/display.php
Only show supported networks in sidebar and contact list
[friendica.git] / mod / display.php
1 <?php
2
3 function display_init(&$a) {
4
5         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
6                 return;
7         }
8
9         $nick = (($a->argc > 1) ? $a->argv[1] : '');
10         $profiledata = array();
11
12         // If there is only one parameter, then check if this parameter could be a guid
13         if ($a->argc == 2) {
14                 $nick = "";
15                 $itemuid = 0;
16
17                 // Does the local user have this item?
18                 if (local_user()) {
19                         $r = q("SELECT `id`, `parent`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item`
20                                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
21                                         AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
22                         if (count($r)) {
23                                 $nick = $a->user["nickname"];
24                                 $itemuid = local_user();
25                         }
26                 }
27
28                 // Or is it anywhere on the server?
29                 if ($nick == "") {
30                         $r = q("SELECT `user`.`nickname`, `item`.`id`, `item`.`parent`, `item`.`author-name`,
31                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`body`
32                                 FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
33                                 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
34                                         AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
35                                         AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
36                                         AND `item`.`private` = 0 AND NOT `user`.`hidewall`
37                                         AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
38                                 //      AND `item`.`private` = 0 AND `item`.`wall` = 1
39                         if (count($r)) {
40                                 $nick = $r[0]["nickname"];
41                                 $itemuid = $r[0]["uid"];
42                         }
43                 }
44
45                 // Is it an item with uid=0?
46                 if ($nick == "") {
47                         $r = q("SELECT `item`.`id`, `item`.`parent`, `item`.`author-name`,
48                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`body`
49                                 FROM `item` WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
50                                         AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
51                                         AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
52                                         AND `item`.`private` = 0 AND `item`.`uid` = 0
53                                         AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
54                                 //      AND `item`.`private` = 0 AND `item`.`wall` = 1
55                 }
56                 if (count($r)) {
57                         if ($r[0]["id"] != $r[0]["parent"])
58                                 $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item`
59                                         WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
60                                                 AND `id` = %d", $r[0]["parent"]);
61
62                         $profiledata = display_fetchauthor($a, $r[0]);
63
64                         if (strstr(normalise_link($profiledata["url"]), normalise_link($a->get_baseurl()))) {
65                                 $nickname = str_replace(normalise_link($a->get_baseurl())."/profile/", "", normalise_link($profiledata["url"]));
66
67                                 if (($nickname != $a->user["nickname"])) {
68                                         $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
69                                                 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
70                                                 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1",
71                                                 dbesc($nickname)
72                                         );
73                                         if (count($r))
74                                                 $profiledata = $r[0];
75
76                                         $profiledata["network"] = NETWORK_DFRN;
77                                 } else
78                                         $profiledata = array();
79                         }
80                 } else {
81                         $a->error = 404;
82                         notice( t('Item not found.') . EOL);
83                         return;
84                 }
85         }
86
87         profile_load($a, $nick, 0, $profiledata);
88
89 }
90
91 function display_fetchauthor($a, $item) {
92         require_once("mod/proxy.php");
93         require_once("include/bbcode.php");
94
95         $profiledata = array();
96         $profiledata["uid"] = -1;
97         $profiledata["nickname"] = $item["author-name"];
98         $profiledata["name"] = $item["author-name"];
99         $profiledata["picdate"] = "";
100         $profiledata["photo"] = proxy_url($item["author-avatar"], false, PROXY_SIZE_SMALL);
101         $profiledata["url"] = $item["author-link"];
102         $profiledata["network"] = $item["network"];
103
104         // Check for a repeated message
105         $skip = false;
106         $body = trim($item["body"]);
107
108         // Skip if it isn't a pure repeated messages
109         // Does it start with a share?
110         if (!$skip AND strpos($body, "[share") > 0)
111                 $skip = true;
112
113         // Does it end with a share?
114         if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8)))
115                 $skip = true;
116
117         if (!$skip) {
118                 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
119                 // Skip if there is no shared message in there
120                 if ($body == $attributes)
121                         $skip = true;
122         }
123
124         if (!$skip) {
125                 $author = "";
126                 preg_match("/author='(.*?)'/ism", $attributes, $matches);
127                 if ($matches[1] != "")
128                         $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
129
130                 preg_match('/author="(.*?)"/ism', $attributes, $matches);
131                 if ($matches[1] != "")
132                         $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
133
134                 $profile = "";
135                 preg_match("/profile='(.*?)'/ism", $attributes, $matches);
136                 if ($matches[1] != "")
137                         $profiledata["url"] = $matches[1];
138
139                 preg_match('/profile="(.*?)"/ism', $attributes, $matches);
140                 if ($matches[1] != "")
141                         $profiledata["url"] = $matches[1];
142
143                 $avatar = "";
144                 preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
145                 if ($matches[1] != "")
146                         $profiledata["photo"] = $matches[1];
147
148                 preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
149                 if ($matches[1] != "")
150                         $profiledata["photo"] = $matches[1];
151
152                 $profiledata["nickname"] = $profiledata["name"];
153                 $profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
154
155                 $profiledata["address"] = "";
156                 $profiledata["about"] = "";
157         }
158
159         // Fetching further contact data from the contact table
160         $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s'",
161                 dbesc(normalise_link($profiledata["url"])), intval($item["uid"]), dbesc($item["network"]));
162
163         if (!count($r))
164                 $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
165                         dbesc(normalise_link($profiledata["url"])), intval($item["uid"]));
166
167         if (!count($r))
168                 $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
169                         dbesc(normalise_link($profiledata["url"])));
170
171         if (count($r)) {
172                 if ((($r[0]["uid"] != local_user()) OR !local_user()) AND ($profiledata["network"] == NETWORK_DIASPORA)) {
173                         $r[0]["location"] = "";
174                         $r[0]["about"] = "";
175                 }
176
177                 $profiledata["photo"] = proxy_url($r[0]["photo"], false, PROXY_SIZE_SMALL);
178                 $profiledata["address"] = bbcode($r[0]["location"]);
179                 $profiledata["about"] = bbcode($r[0]["about"]);
180                 if ($r[0]["nick"] != "")
181                         $profiledata["nickname"] = $r[0]["nick"];
182         }
183
184         // Fetching profile data from unique contacts
185         $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($profiledata["url"])));
186         if (count($r)) {
187                 if ($profiledata["photo"] == "")
188                         $profiledata["photo"] = proxy_url($r[0]["avatar"], false, PROXY_SIZE_SMALL);
189                 if (($profiledata["address"] == "") AND ($profiledata["network"] != NETWORK_DIASPORA))
190                         $profiledata["address"] = bbcode($r[0]["location"]);
191                 if (($profiledata["about"] == "") AND ($profiledata["network"] != NETWORK_DIASPORA))
192                         $profiledata["about"] = bbcode($r[0]["about"]);
193                 if (($profiledata["nickname"] == "") AND ($r[0]["nick"] != ""))
194                         $profiledata["nickname"] = $r[0]["nick"];
195         }
196
197         if (local_user()) {
198                 if (in_array($profiledata["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
199                         $profiledata["remoteconnect"] = $a->get_baseurl()."/follow?url=".urlencode($profiledata["url"]);
200         } elseif ($profiledata["network"] == NETWORK_DFRN) {
201                 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
202                 $profiledata["remoteconnect"] = $connect;
203         }
204
205         return($profiledata);
206 }
207
208 function display_content(&$a, $update = 0) {
209
210         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
211                 notice( t('Public access denied.') . EOL);
212                 return;
213         }
214
215         require_once("include/bbcode.php");
216         require_once('include/security.php');
217         require_once('include/conversation.php');
218         require_once('include/acl_selectors.php');
219
220
221         $o = '';
222
223         $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
224
225
226         if($update) {
227                 $nick = $_REQUEST['nick'];
228         }
229         else {
230                 $nick = (($a->argc > 1) ? $a->argv[1] : '');
231         }
232
233         if($update) {
234                 $item_id = $_REQUEST['item_id'];
235                 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
236         }
237         else {
238                 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
239
240                 if ($a->argc == 2) {
241                         $nick = "";
242
243                         if (local_user()) {
244                                 $r = q("SELECT `id` FROM `item`
245                                         WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
246                                                 AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
247                                 if (count($r)) {
248                                         $item_id = $r[0]["id"];
249                                         $nick = $a->user["nickname"];
250                                 }
251                         }
252
253                         if ($nick == "") {
254                                 $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
255                                         WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
256                                                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
257                                                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
258                                                 AND `item`.`private` = 0  AND NOT `user`.`hidewall`
259                                                 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
260                                         //      AND `item`.`private` = 0 AND `item`.`wall` = 1
261                                 if (count($r)) {
262                                         $item_id = $r[0]["id"];
263                                         $nick = $r[0]["nickname"];
264                                 }
265                         }
266                         if ($nick == "") {
267                                 $r = q("SELECT `item`.`id` FROM `item`
268                                         WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
269                                                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
270                                                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
271                                                 AND `item`.`private` = 0  AND `item`.`uid` = 0
272                                                 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
273                                         //      AND `item`.`private` = 0 AND `item`.`wall` = 1
274                                 if (count($r)) {
275                                         $item_id = $r[0]["id"];
276                                 }
277                         }
278                 }
279         }
280
281         if(! $item_id) {
282                 $a->error = 404;
283                 notice( t('Item not found.') . EOL);
284                 return;
285         }
286
287         $groups = array();
288
289         $contact = null;
290         $remote_contact = false;
291
292         $contact_id = 0;
293
294         if(is_array($_SESSION['remote'])) {
295                 foreach($_SESSION['remote'] as $v) {
296                         if($v['uid'] == $a->profile['uid']) {
297                                 $contact_id = $v['cid'];
298                                 break;
299                         }
300                 }
301         }
302
303         if($contact_id) {
304                 $groups = init_groups_visitor($contact_id);
305                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
306                         intval($contact_id),
307                         intval($a->profile['uid'])
308                 );
309                 if(count($r)) {
310                         $contact = $r[0];
311                         $remote_contact = true;
312                 }
313         }
314
315         if(! $remote_contact) {
316                 if(local_user()) {
317                         $contact_id = $_SESSION['cid'];
318                         $contact = $a->contact;
319                 }
320         }
321
322         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
323                 intval($a->profile['uid'])
324         );
325         if(count($r))
326                 $a->page_contact = $r[0];
327
328         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
329
330         if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
331                 notice( t('Access to this profile has been restricted.') . EOL);
332                 return;
333         }
334
335         if ($is_owner) {
336                 $x = array(
337                         'is_owner' => true,
338                         'allow_location' => $a->user['allow_location'],
339                         'default_location' => $a->user['default-location'],
340                         'nickname' => $a->user['nickname'],
341                         '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'),
342                         'acl' => populate_acl($a->user, true),
343                         'bang' => '',
344                         'visitor' => 'block',
345                         'profile_uid' => local_user(),
346                         'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
347                 );
348                 $o .= status_editor($a,$x,0,true);
349         }
350
351         $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
352
353         //              AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
354
355         if($update) {
356
357                 $r = q("SELECT id FROM item WHERE item.uid = %d
358                         AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s'))
359                         $sql_extra AND unseen = 1",
360                         intval($a->profile['uid']),
361                         dbesc($item_id),
362                         dbesc($item_id)
363                 );
364
365                 if(!$r)
366                         return '';
367         }
368
369         //      AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
370
371         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,  `item`.`network` AS `item_network`,
372                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
373                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
374                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
375                 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
376                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
377                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
378                 and `item`.`moderated` = 0
379                 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
380                 AND uid = %d)
381                 $sql_extra
382                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
383                 intval($a->profile['uid']),
384                 dbesc($item_id),
385                 dbesc($item_id),
386                 intval($a->profile['uid'])
387         );
388
389         if(!$r && local_user()) {
390                 // Check if this is another person's link to a post that we have
391                 $r = q("SELECT `item`.uri FROM `item`
392                         WHERE (`item`.`id` = '%s' OR `item`.`uri` = '%s' )
393                         LIMIT 1",
394                         dbesc($item_id),
395                         dbesc($item_id)
396                 );
397                 if($r) {
398                         $item_uri = $r[0]['uri'];
399                         //      AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
400
401                         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,  `item`.`network` AS `item_network`,
402                                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
403                                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
404                                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
405                                 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
406                                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
407                                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
408                                 and `item`.`moderated` = 0
409                                 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
410                                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
411                                 intval(local_user()),
412                                 dbesc($item_uri),
413                                 intval(local_user())
414                         );
415                 }
416         }
417
418
419         if($r) {
420
421                 if((local_user()) && (local_user() == $a->profile['uid'])) {
422                         q("UPDATE `item` SET `unseen` = 0
423                                 WHERE `parent` = %d AND `unseen` = 1",
424                                 intval($r[0]['parent'])
425                         );
426                 }
427
428                 $items = conv_sort($r,"`commented`");
429
430                 if(!$update)
431                         $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
432                 $o .= conversation($a,$items,'display', $update);
433
434                 // Preparing the meta header
435                 require_once('include/bbcode.php');
436                 require_once("include/html2plain.php");
437                 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
438                 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
439                 $author_name = $r[0]["author-name"];
440
441                 $image = "";
442                 if ($image == "")
443                         $image = $r[0]["thumb"];
444
445                 if ($title == "")
446                         $title = $author_name;
447
448                 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
449                 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
450                 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
451
452                 //<meta name="keywords" content="">
453                 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
454                 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
455                 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
456                 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
457
458                 // Schema.org microdata
459                 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
460                 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
461                 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
462                 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
463
464                 // Twitter cards
465                 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
466                 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
467                 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
468                 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
469                 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
470
471                 // Dublin Core
472                 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
473                 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
474
475                 // Open Graph
476                 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
477                 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
478                 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
479                 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
480                 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
481                 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
482                 // article:tag
483
484                 return $o;
485         }
486
487         $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
488                 dbesc($item_id),
489                 dbesc($item_id)
490         );
491         if($r) {
492                 if($r[0]['deleted']) {
493                         notice( t('Item has been removed.') . EOL );
494                 }
495                 else {
496                         notice( t('Permission denied.') . EOL );
497                 }
498         }
499         else {
500                 notice( t('Item not found.') . EOL );
501         }
502
503         return $o;
504 }
505