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 = qu("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 = qu("SELECT STRAIGHT_JOIN `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]));
39 $nick = $r[0]["nickname"];
40 $itemuid = $r[0]["uid"];
44 // Is it an item with uid=0?
46 $r = qu("SELECT `item`.`id`, `item`.`parent`, `item`.`author-name`, `item`.`author-link`,
47 `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`owner-link`, `item`.`body`
48 FROM `item` WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
49 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
50 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
51 AND NOT `item`.`private` AND `item`.`uid` = 0
52 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
55 if ($r[0]["id"] != $r[0]["parent"])
56 $r = qu("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid`, `owner-link` FROM `item`
57 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
58 AND `id` = %d", $r[0]["parent"]);
60 if (($itemuid != local_user()) AND local_user()) {
61 // Do we know this contact but we haven't got this item?
62 // Copy the wohle thread to our local storage so that we can interact.
63 // We really should change this need for the future since it scales very bad.
64 $contactid = get_contact($r[0]['owner-link'], local_user());
66 $items = qu("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id`", intval($r[0]["id"]));
67 foreach ($items AS $item) {
68 $itemcontactid = get_contact($item['owner-link'], local_user());
70 $itemcontactid = $contactid;
73 $item['uid'] = local_user();
75 $item['contact-id'] = $itemcontactid;
76 $local_copy = item_store($item, false, false, true);
77 logger("Stored local copy for post ".$item['guid']." under id ".$local_copy, LOGGER_DEBUG);
82 $profiledata = display_fetchauthor($a, $r[0]);
84 if (strstr(normalise_link($profiledata["url"]), normalise_link($a->get_baseurl()))) {
85 $nickname = str_replace(normalise_link($a->get_baseurl())."/profile/", "", normalise_link($profiledata["url"]));
87 if (($nickname != $a->user["nickname"])) {
88 $r = qu("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
89 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
90 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` AND `contact`.`self` LIMIT 1",
96 $profiledata["network"] = NETWORK_DFRN;
98 $profiledata = array();
102 notice( t('Item not found.') . EOL);
107 profile_load($a, $nick, 0, $profiledata);
111 function display_fetchauthor($a, $item) {
113 require_once("include/Contact.php");
115 $profiledata = array();
116 $profiledata["uid"] = -1;
117 $profiledata["nickname"] = $item["author-name"];
118 $profiledata["name"] = $item["author-name"];
119 $profiledata["picdate"] = "";
120 $profiledata["photo"] = $item["author-avatar"];
121 $profiledata["url"] = $item["author-link"];
122 $profiledata["network"] = $item["network"];
124 // Check for a repeated message
126 $body = trim($item["body"]);
128 // Skip if it isn't a pure repeated messages
129 // Does it start with a share?
130 if (!$skip AND strpos($body, "[share") > 0)
133 // Does it end with a share?
134 if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8)))
138 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
139 // Skip if there is no shared message in there
140 if ($body == $attributes)
146 preg_match("/author='(.*?)'/ism", $attributes, $matches);
147 if ($matches[1] != "")
148 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
150 preg_match('/author="(.*?)"/ism', $attributes, $matches);
151 if ($matches[1] != "")
152 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
155 preg_match("/profile='(.*?)'/ism", $attributes, $matches);
156 if ($matches[1] != "")
157 $profiledata["url"] = $matches[1];
159 preg_match('/profile="(.*?)"/ism', $attributes, $matches);
160 if ($matches[1] != "")
161 $profiledata["url"] = $matches[1];
164 preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
165 if ($matches[1] != "")
166 $profiledata["photo"] = $matches[1];
168 preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
169 if ($matches[1] != "")
170 $profiledata["photo"] = $matches[1];
172 $profiledata["nickname"] = $profiledata["name"];
173 $profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
175 $profiledata["address"] = "";
176 $profiledata["about"] = "";
179 $profiledata = get_contact_details_by_url($profiledata["url"], local_user(), $profiledata);
181 $profiledata["photo"] = App::remove_baseurl($profiledata["photo"]);
184 if (in_array($profiledata["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
185 $profiledata["remoteconnect"] = $a->get_baseurl()."/follow?url=".urlencode($profiledata["url"]);
186 } elseif ($profiledata["network"] == NETWORK_DFRN) {
187 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
188 $profiledata["remoteconnect"] = $connect;
191 return($profiledata);
194 function display_content(&$a, $update = 0) {
196 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
197 notice( t('Public access denied.') . EOL);
201 require_once('include/security.php');
202 require_once('include/conversation.php');
203 require_once('include/acl_selectors.php');
208 $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
212 $nick = $_REQUEST['nick'];
215 $nick = (($a->argc > 1) ? $a->argv[1] : '');
219 $item_id = $_REQUEST['item_id'];
220 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
223 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
229 $r = qu("SELECT `id` FROM `item`
230 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
231 AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
233 $item_id = $r[0]["id"];
234 $nick = $a->user["nickname"];
239 $r = qu("SELECT STRAIGHT_JOIN `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
240 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
241 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
242 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
243 AND NOT `item`.`private` AND NOT `user`.`hidewall`
244 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
245 // AND NOT `item`.`private` AND `item`.`wall`
247 $item_id = $r[0]["id"];
248 $nick = $r[0]["nickname"];
252 $r = qu("SELECT `item`.`id` FROM `item`
253 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
254 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
255 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
256 AND NOT `item`.`private` AND `item`.`uid` = 0
257 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
258 // AND NOT `item`.`private` AND `item`.`wall`
260 $item_id = $r[0]["id"];
266 if ($item_id AND !is_numeric($item_id)) {
267 $r = qu("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
268 dbesc($item_id), intval($a->profile['uid']));
270 $item_id = $r[0]["id"];
277 notice(t('Item not found.').EOL);
285 $remote_contact = false;
289 if(is_array($_SESSION['remote'])) {
290 foreach($_SESSION['remote'] as $v) {
291 if($v['uid'] == $a->profile['uid']) {
292 $contact_id = $v['cid'];
299 $groups = init_groups_visitor($contact_id);
300 $r = qu("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
302 intval($a->profile['uid'])
306 $remote_contact = true;
310 if(! $remote_contact) {
312 $contact_id = $_SESSION['cid'];
313 $contact = $a->contact;
317 $r = qu("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1",
318 intval($a->profile['uid'])
321 $a->page_contact = $r[0];
323 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
325 if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
326 notice( t('Access to this profile has been restricted.') . EOL);
330 // We need the editor here to be able to reshare an item.
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);
352 $r = qu("SELECT `id` FROM `item` WHERE `item`.`uid` = %d
353 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d)
354 $sql_extra AND `unseen`",
355 intval($a->profile['uid']),
363 $r = qu(item_query()." AND `item`.`uid` = %d
364 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d)
366 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
367 intval($a->profile['uid']),
372 if(!$r && local_user()) {
373 // Check if this is another person's link to a post that we have
374 $r = qu("SELECT `item`.uri FROM `item`
375 WHERE (`item`.`id` = %d OR `item`.`uri` = '%s')
381 $item_uri = $r[0]['uri'];
383 $r = qu(item_query()." AND `item`.`uid` = %d
384 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
385 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
386 intval(local_user()),
395 if((local_user()) && (local_user() == $a->profile['uid'])) {
396 $unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `parent` = %d",
397 intval($r[0]['parent']));
400 q("UPDATE `item` SET `unseen` = 0
401 WHERE `parent` = %d AND `unseen`",
402 intval($r[0]['parent'])
406 $items = conv_sort($r,"`commented`");
409 $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
410 $o .= conversation($a,$items,'display', $update);
412 // Preparing the meta header
413 require_once('include/bbcode.php');
414 require_once("include/html2plain.php");
415 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
416 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
417 $author_name = $r[0]["author-name"];
419 $image = $a->remove_baseurl($r[0]["thumb"]);
422 $title = $author_name;
424 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
425 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
426 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
428 //<meta name="keywords" content="">
429 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
430 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
431 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
432 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
434 // Schema.org microdata
435 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
436 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
437 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
438 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
441 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
442 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
443 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
444 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
445 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
448 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
449 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
452 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
453 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
454 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
455 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
456 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
457 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
463 $r = qu("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
468 if($r[0]['deleted']) {
469 notice( t('Item has been removed.') . EOL );
472 notice( t('Permission denied.') . EOL );
476 notice( t('Item not found.') . EOL );