3 function display_init(&$a) {
5 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
9 $nick = (($a->argc > 1) ? $a->argv[1] : '');
10 $profiledata = array();
12 // If there is only one parameter, then check if this parameter could be a guid
17 // Does the local user have this item?
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());
23 $nick = $a->user["nickname"];
24 $itemuid = local_user();
28 // Or is it anywhere on the server?
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
40 $nick = $r[0]["nickname"];
41 $itemuid = $r[0]["uid"];
45 // Is it an item with uid=0?
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
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"]);
62 $profiledata = display_fetchauthor($a, $r[0]);
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"]));
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",
76 $profiledata["network"] = NETWORK_DFRN;
78 $profiledata = array();
82 notice( t('Item not found.') . EOL);
87 profile_load($a, $nick, 0, $profiledata);
91 function display_fetchauthor($a, $item) {
93 $profiledata = array();
94 $profiledata["uid"] = -1;
95 $profiledata["nickname"] = $item["author-name"];
96 $profiledata["name"] = $item["author-name"];
97 $profiledata["picdate"] = "";
98 $profiledata["photo"] = $item["author-avatar"];
99 $profiledata["url"] = $item["author-link"];
100 $profiledata["network"] = $item["network"];
102 // Check for a repeated message
104 $body = trim($item["body"]);
106 // Skip if it isn't a pure repeated messages
107 // Does it start with a share?
108 if (!$skip AND strpos($body, "[share") > 0)
111 // Does it end with a share?
112 if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8)))
116 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
117 // Skip if there is no shared message in there
118 if ($body == $attributes)
124 preg_match("/author='(.*?)'/ism", $attributes, $matches);
125 if ($matches[1] != "")
126 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
128 preg_match('/author="(.*?)"/ism', $attributes, $matches);
129 if ($matches[1] != "")
130 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
133 preg_match("/profile='(.*?)'/ism", $attributes, $matches);
134 if ($matches[1] != "")
135 $profiledata["url"] = $matches[1];
137 preg_match('/profile="(.*?)"/ism', $attributes, $matches);
138 if ($matches[1] != "")
139 $profiledata["url"] = $matches[1];
142 preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
143 if ($matches[1] != "")
144 $profiledata["photo"] = $matches[1];
146 preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
147 if ($matches[1] != "")
148 $profiledata["photo"] = $matches[1];
150 $profiledata["nickname"] = $profiledata["name"];
151 $profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
153 $profiledata["address"] = "";
154 $profiledata["about"] = "";
157 // Fetching further contact data from the contact table
158 $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s'",
159 dbesc(normalise_link($profiledata["url"])), intval($item["uid"]), dbesc($item["network"]));
162 $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
163 dbesc(normalise_link($profiledata["url"])), intval($item["uid"]));
166 $r = q("SELECT `uid`, `network`, `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
167 dbesc(normalise_link($profiledata["url"])));
170 if ((($r[0]["uid"] != local_user()) OR !local_user()) AND ($profiledata["network"] == NETWORK_DIASPORA)) {
171 $r[0]["location"] = "";
175 $profiledata["photo"] = $r[0]["photo"];
176 $profiledata["address"] = $r[0]["location"];
177 $profiledata["about"] = $r[0]["about"];
178 if ($r[0]["nick"] != "")
179 $profiledata["nickname"] = $r[0]["nick"];
182 // Fetching profile data from unique contacts
183 $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($profiledata["url"])));
185 if ($profiledata["photo"] == "")
186 $profiledata["photo"] = $r[0]["avatar"];
187 if (($profiledata["address"] == "") AND ($profiledata["network"] != NETWORK_DIASPORA))
188 $profiledata["address"] = $r[0]["location"];
189 if (($profiledata["about"] == "") AND ($profiledata["network"] != NETWORK_DIASPORA))
190 $profiledata["about"] = $r[0]["about"];
191 if (($profiledata["nickname"] == "") AND ($r[0]["nick"] != ""))
192 $profiledata["nickname"] = $r[0]["nick"];
196 if (in_array($profiledata["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
197 $profiledata["remoteconnect"] = $a->get_baseurl()."/follow?url=".urlencode($profiledata["url"]);
198 } elseif ($profiledata["network"] == NETWORK_DFRN) {
199 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
200 $profiledata["remoteconnect"] = $connect;
203 return($profiledata);
206 function display_content(&$a, $update = 0) {
208 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
209 notice( t('Public access denied.') . EOL);
213 require_once('include/security.php');
214 require_once('include/conversation.php');
215 require_once('include/acl_selectors.php');
220 $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
224 $nick = $_REQUEST['nick'];
227 $nick = (($a->argc > 1) ? $a->argv[1] : '');
231 $item_id = $_REQUEST['item_id'];
232 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
235 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
241 $r = q("SELECT `id` FROM `item`
242 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
243 AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
245 $item_id = $r[0]["id"];
246 $nick = $a->user["nickname"];
251 $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
252 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
253 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
254 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
255 AND `item`.`private` = 0 AND NOT `user`.`hidewall`
256 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
257 // AND `item`.`private` = 0 AND `item`.`wall` = 1
259 $item_id = $r[0]["id"];
260 $nick = $r[0]["nickname"];
264 $r = q("SELECT `item`.`id` FROM `item`
265 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
266 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
267 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
268 AND `item`.`private` = 0 AND `item`.`uid` = 0
269 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
270 // AND `item`.`private` = 0 AND `item`.`wall` = 1
272 $item_id = $r[0]["id"];
280 notice( t('Item not found.') . EOL);
287 $remote_contact = false;
291 if(is_array($_SESSION['remote'])) {
292 foreach($_SESSION['remote'] as $v) {
293 if($v['uid'] == $a->profile['uid']) {
294 $contact_id = $v['cid'];
301 $groups = init_groups_visitor($contact_id);
302 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
304 intval($a->profile['uid'])
308 $remote_contact = true;
312 if(! $remote_contact) {
314 $contact_id = $_SESSION['cid'];
315 $contact = $a->contact;
319 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
320 intval($a->profile['uid'])
323 $a->page_contact = $r[0];
325 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
327 if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
328 notice( t('Access to this profile has been restricted.') . EOL);
335 'allow_location' => $a->user['allow_location'],
336 'default_location' => $a->user['default-location'],
337 'nickname' => $a->user['nickname'],
338 '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'),
339 'acl' => populate_acl($a->user, true),
341 'visitor' => 'block',
342 'profile_uid' => local_user(),
343 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
345 $o .= status_editor($a,$x,0,true);
348 $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
350 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
354 $r = q("SELECT id FROM item WHERE item.uid = %d
355 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s'))
356 $sql_extra AND unseen = 1",
357 intval($a->profile['uid']),
366 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
368 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
369 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
370 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
371 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
372 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
373 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
374 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
375 and `item`.`moderated` = 0
376 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
379 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
380 intval($a->profile['uid']),
383 intval($a->profile['uid'])
386 if(!$r && local_user()) {
387 // Check if this is another person's link to a post that we have
388 $r = q("SELECT `item`.uri FROM `item`
389 WHERE (`item`.`id` = '%s' OR `item`.`uri` = '%s' )
395 $item_uri = $r[0]['uri'];
396 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
398 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
399 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
400 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
401 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
402 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
403 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
404 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
405 and `item`.`moderated` = 0
406 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
407 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
408 intval(local_user()),
418 if((local_user()) && (local_user() == $a->profile['uid'])) {
419 q("UPDATE `item` SET `unseen` = 0
420 WHERE `parent` = %d AND `unseen` = 1",
421 intval($r[0]['parent'])
425 $items = conv_sort($r,"`commented`");
428 $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
429 $o .= conversation($a,$items,'display', $update);
431 // Preparing the meta header
432 require_once('include/bbcode.php');
433 require_once("include/html2plain.php");
434 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
435 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
436 $author_name = $r[0]["author-name"];
440 $image = $r[0]["thumb"];
443 $title = $author_name;
445 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
446 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
447 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
449 //<meta name="keywords" content="">
450 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
451 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
452 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
453 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
455 // Schema.org microdata
456 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
457 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
458 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
459 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
462 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
463 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
464 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
465 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
466 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
469 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
470 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
473 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
474 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
475 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
476 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
477 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
478 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
484 $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
489 if($r[0]['deleted']) {
490 notice( t('Item has been removed.') . EOL );
493 notice( t('Permission denied.') . EOL );
497 notice( t('Item not found.') . EOL );