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`, `owner-link` FROM `item`
20 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
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`.`owner-link`, `item`.`body`
32 FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
33 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
34 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
35 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
36 AND NOT `item`.`private` AND NOT `user`.`hidewall`
37 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
38 // AND NOT `item`.`private` AND `item`.`wall`
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`, `item`.`author-link`,
48 `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`owner-link`, `item`.`body`
49 FROM `item` WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
50 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
51 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
52 AND NOT `item`.`private` AND `item`.`uid` = 0
53 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
54 // AND NOT `item`.`private` AND `item`.`wall`
57 if ($r[0]["id"] != $r[0]["parent"])
58 $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid`, `owner-link` FROM `item`
59 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
60 AND `id` = %d", $r[0]["parent"]);
62 if (($itemuid != local_user()) AND local_user()) {
63 // Do we know this contact but we haven't got this item?
64 // Copy it to our local storage.
65 $contactid = get_contact($r[0]['owner-link'], local_user());
67 $item = q("SELECT * FROM `item` WHERE `id` = %d", intval($r[0]["id"]));
68 unset($item[0]['id']);
69 $item[0]['uid'] = local_user();
70 $item[0]['origin'] = 0;
71 $item[0]['contact-id'] = $contactid;
72 $local_copy = item_store($item[0], false, false, true);
73 logger("Stored local copy for post ".$item[0]['id']." under id ".$local_copy, LOGGER_DEBUG);
77 $profiledata = display_fetchauthor($a, $r[0]);
79 if (strstr(normalise_link($profiledata["url"]), normalise_link($a->get_baseurl()))) {
80 $nickname = str_replace(normalise_link($a->get_baseurl())."/profile/", "", normalise_link($profiledata["url"]));
82 if (($nickname != $a->user["nickname"])) {
83 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
84 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
85 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` AND `contact`.`self` LIMIT 1",
91 $profiledata["network"] = NETWORK_DFRN;
93 $profiledata = array();
97 notice( t('Item not found.') . EOL);
102 profile_load($a, $nick, 0, $profiledata);
106 function display_fetchauthor($a, $item) {
108 $profiledata = array();
109 $profiledata["uid"] = -1;
110 $profiledata["nickname"] = $item["author-name"];
111 $profiledata["name"] = $item["author-name"];
112 $profiledata["picdate"] = "";
113 $profiledata["photo"] = $item["author-avatar"];
114 $profiledata["url"] = $item["author-link"];
115 $profiledata["network"] = $item["network"];
117 // Check for a repeated message
119 $body = trim($item["body"]);
121 // Skip if it isn't a pure repeated messages
122 // Does it start with a share?
123 if (!$skip AND strpos($body, "[share") > 0)
126 // Does it end with a share?
127 if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8)))
131 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
132 // Skip if there is no shared message in there
133 if ($body == $attributes)
139 preg_match("/author='(.*?)'/ism", $attributes, $matches);
140 if ($matches[1] != "")
141 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
143 preg_match('/author="(.*?)"/ism', $attributes, $matches);
144 if ($matches[1] != "")
145 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
148 preg_match("/profile='(.*?)'/ism", $attributes, $matches);
149 if ($matches[1] != "")
150 $profiledata["url"] = $matches[1];
152 preg_match('/profile="(.*?)"/ism', $attributes, $matches);
153 if ($matches[1] != "")
154 $profiledata["url"] = $matches[1];
157 preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
158 if ($matches[1] != "")
159 $profiledata["photo"] = $matches[1];
161 preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
162 if ($matches[1] != "")
163 $profiledata["photo"] = $matches[1];
165 $profiledata["nickname"] = $profiledata["name"];
166 $profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
168 $profiledata["address"] = "";
169 $profiledata["about"] = "";
172 // Don't show details from Diaspora contacts if you don't follow the contact
173 $showdetails = ($profiledata["network"] != NETWORK_DIASPORA);
175 // Fetching further contact data from the contact table
176 $r = q("SELECT `uid`, `network`, `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`
177 FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)",
178 dbesc(normalise_link($profiledata["url"])), intval(local_user()), dbesc($item["network"]),
179 intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
181 $r = q("SELECT `uid`, `network`, `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`
182 FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `rel` IN (%d, %d)",
183 dbesc(normalise_link($profiledata["url"])), intval(local_user()),
184 intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
187 $profiledata["name"] = $r[0]["name"];
188 $profiledata["photo"] = $r[0]["photo"];
189 $profiledata["nickname"] = $r[0]["nick"];
190 $profiledata["addr"] = $r[0]["addr"];
191 $profiledata["keywords"] = $r[0]["keywords"];
192 $profiledata["network"] = $r[0]["network"];
194 if (local_user() OR $showdetails) {
196 $profiledata["address"] = $r[0]["location"];
197 $profiledata["about"] = $r[0]["about"];
198 $profiledata["gender"] = $r[0]["gender"];
202 // Fetching profile data from global contacts
203 if ($profiledata["network"] != NETWORK_FEED) {
204 $r = q("SELECT `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`, `network` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"])));
206 $profiledata["name"] = $r[0]["name"];
207 $profiledata["photo"] = $r[0]["photo"];
208 $profiledata["nickname"] = $r[0]["nick"];
209 $profiledata["addr"] = $r[0]["addr"];
210 $profiledata["network"] = $r[0]["network"];
212 if ($r[0]["keywords"])
213 $profiledata["keywords"] = $r[0]["keywords"];
216 if ($r[0]["location"])
217 $profiledata["address"] = $r[0]["location"];
220 $profiledata["about"] = $r[0]["about"];
223 $profiledata["gender"] = $r[0]["gender"];
229 if (in_array($profiledata["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
230 $profiledata["remoteconnect"] = $a->get_baseurl()."/follow?url=".urlencode($profiledata["url"]);
231 } elseif ($profiledata["network"] == NETWORK_DFRN) {
232 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
233 $profiledata["remoteconnect"] = $connect;
236 return($profiledata);
239 function display_content(&$a, $update = 0) {
241 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
242 notice( t('Public access denied.') . EOL);
246 require_once('include/security.php');
247 require_once('include/conversation.php');
248 require_once('include/acl_selectors.php');
253 $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
257 $nick = $_REQUEST['nick'];
260 $nick = (($a->argc > 1) ? $a->argv[1] : '');
264 $item_id = $_REQUEST['item_id'];
265 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
268 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
274 $r = q("SELECT `id` FROM `item`
275 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
276 AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
278 $item_id = $r[0]["id"];
279 $nick = $a->user["nickname"];
284 $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
285 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
286 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
287 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
288 AND NOT `item`.`private` AND NOT `user`.`hidewall`
289 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
290 // AND NOT `item`.`private` AND `item`.`wall`
292 $item_id = $r[0]["id"];
293 $nick = $r[0]["nickname"];
297 $r = q("SELECT `item`.`id` FROM `item`
298 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
299 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
300 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
301 AND NOT `item`.`private` AND `item`.`uid` = 0
302 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
303 // AND NOT `item`.`private` AND `item`.`wall`
305 $item_id = $r[0]["id"];
311 if ($item_id AND !is_numeric($item_id)) {
312 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
313 dbesc($item_id), intval($a->profile['uid']));
315 $item_id = $r[0]["id"];
322 notice(t('Item not found.').EOL);
330 $remote_contact = false;
334 if(is_array($_SESSION['remote'])) {
335 foreach($_SESSION['remote'] as $v) {
336 if($v['uid'] == $a->profile['uid']) {
337 $contact_id = $v['cid'];
344 $groups = init_groups_visitor($contact_id);
345 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
347 intval($a->profile['uid'])
351 $remote_contact = true;
355 if(! $remote_contact) {
357 $contact_id = $_SESSION['cid'];
358 $contact = $a->contact;
362 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1",
363 intval($a->profile['uid'])
366 $a->page_contact = $r[0];
368 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
370 if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
371 notice( t('Access to this profile has been restricted.') . EOL);
375 // We need the editor here to be able to reshare an item.
380 'allow_location' => $a->user['allow_location'],
381 'default_location' => $a->user['default-location'],
382 'nickname' => $a->user['nickname'],
383 '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'),
384 'acl' => populate_acl($a->user, true),
386 'visitor' => 'block',
387 'profile_uid' => local_user(),
388 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
390 $o .= status_editor($a,$x,0,true);
393 $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
397 $r = q("SELECT `id` FROM `item` WHERE `item`.`uid` = %d
398 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d)
399 $sql_extra AND `unseen`",
400 intval($a->profile['uid']),
408 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
409 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
410 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
411 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
412 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
413 AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
414 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted`
415 AND NOT `item`.`moderated`
416 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d)
418 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
419 intval($a->profile['uid']),
423 if(!$r && local_user()) {
424 // Check if this is another person's link to a post that we have
425 $r = q("SELECT `item`.uri FROM `item`
426 WHERE (`item`.`id` = %d OR `item`.`uri` = '%s')
432 $item_uri = $r[0]['uri'];
434 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
435 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
436 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
437 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
438 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
439 AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
440 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted`
441 AND NOT `item`.`moderated`
442 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
443 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
444 intval(local_user()),
454 if((local_user()) && (local_user() == $a->profile['uid'])) {
455 $unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `parent` = %d",
456 intval($r[0]['parent']));
459 q("UPDATE `item` SET `unseen` = 0
460 WHERE `parent` = %d AND `unseen`",
461 intval($r[0]['parent'])
465 $items = conv_sort($r,"`commented`");
468 $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
469 $o .= conversation($a,$items,'display', $update);
471 // Preparing the meta header
472 require_once('include/bbcode.php');
473 require_once("include/html2plain.php");
474 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
475 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
476 $author_name = $r[0]["author-name"];
480 $image = $r[0]["thumb"];
483 $title = $author_name;
485 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
486 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
487 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
489 //<meta name="keywords" content="">
490 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
491 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
492 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
493 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
495 // Schema.org microdata
496 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
497 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
498 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
499 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
502 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
503 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
504 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
505 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
506 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
509 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
510 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
513 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
514 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
515 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
516 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
517 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
518 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
524 $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
529 if($r[0]['deleted']) {
530 notice( t('Item has been removed.') . EOL );
533 notice( t('Permission denied.') . EOL );
537 notice( t('Item not found.') . EOL );