5 function display_init(App $a) {
7 if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
11 $nick = (($a->argc > 1) ? $a->argv[1] : '');
12 $profiledata = array();
14 // If there is only one parameter, then check if this parameter could be a guid
19 // Does the local user have this item?
21 $r = qu("SELECT `id`, `parent`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid`, `owner-link` FROM `item`
22 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
23 AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
24 if (dbm::is_result($r)) {
25 $nick = $a->user["nickname"];
26 $itemuid = local_user();
30 // Or is it anywhere on the server?
32 $r = qu("SELECT `user`.`nickname`, `item`.`id`, `item`.`parent`, `item`.`author-name`,
33 `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`owner-link`, `item`.`body`
34 FROM `item` STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
35 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
36 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
37 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
38 AND NOT `item`.`private` AND NOT `user`.`hidewall`
39 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
40 if (dbm::is_result($r)) {
41 $nick = $r[0]["nickname"];
42 $itemuid = $r[0]["uid"];
46 // Is it an item with uid=0?
48 $r = qu("SELECT `item`.`id`, `item`.`parent`, `item`.`author-name`, `item`.`author-link`,
49 `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`owner-link`, `item`.`body`
50 FROM `item` WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
51 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
52 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
53 AND NOT `item`.`private` AND `item`.`uid` = 0
54 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
56 if (dbm::is_result($r)) {
57 if ($r[0]["id"] != $r[0]["parent"]) {
58 $r = qu("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 the wohle thread to our local storage so that we can interact.
65 // We really should change this need for the future since it scales very bad.
66 $contactid = get_contact($r[0]['owner-link'], local_user());
68 $items = qu("SELECT * FROM `item` WHERE `parent` = %d ORDER BY `id`", intval($r[0]["id"]));
69 foreach ($items AS $item) {
70 $itemcontactid = get_contact($item['owner-link'], local_user());
71 if (!$itemcontactid) {
72 $itemcontactid = $contactid;
75 $item['uid'] = local_user();
77 $item['contact-id'] = $itemcontactid;
78 $local_copy = item_store($item, false, false, true);
79 logger("Stored local copy for post ".$item['guid']." under id ".$local_copy, LOGGER_DEBUG);
84 $profiledata = display_fetchauthor($a, $r[0]);
86 if (strstr(normalise_link($profiledata["url"]), normalise_link(App::get_baseurl()))) {
87 $nickname = str_replace(normalise_link(App::get_baseurl())."/profile/", "", normalise_link($profiledata["url"]));
89 if (($nickname != $a->user["nickname"])) {
90 $r = qu("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
91 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
92 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` AND `contact`.`self` LIMIT 1",
95 if (dbm::is_result($r)) {
98 $profiledata["network"] = NETWORK_DFRN;
100 $profiledata = array();
105 notice(t('Item not found.') . EOL);
110 profile_load($a, $nick, 0, $profiledata);
113 function display_fetchauthor($a, $item) {
115 require_once("include/Contact.php");
117 $profiledata = array();
118 $profiledata["uid"] = -1;
119 $profiledata["nickname"] = $item["author-name"];
120 $profiledata["name"] = $item["author-name"];
121 $profiledata["picdate"] = "";
122 $profiledata["photo"] = $item["author-avatar"];
123 $profiledata["url"] = $item["author-link"];
124 $profiledata["network"] = $item["network"];
126 // Check for a repeated message
128 $body = trim($item["body"]);
130 // Skip if it isn't a pure repeated messages
131 // Does it start with a share?
132 if (!$skip AND strpos($body, "[share") > 0) {
135 // Does it end with a share?
136 if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8))) {
140 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
141 // Skip if there is no shared message in there
142 if ($body == $attributes) {
149 preg_match("/author='(.*?)'/ism", $attributes, $matches);
150 if ($matches[1] != "") {
151 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
153 preg_match('/author="(.*?)"/ism', $attributes, $matches);
154 if ($matches[1] != "") {
155 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
158 preg_match("/profile='(.*?)'/ism", $attributes, $matches);
159 if ($matches[1] != "") {
160 $profiledata["url"] = $matches[1];
162 preg_match('/profile="(.*?)"/ism', $attributes, $matches);
163 if ($matches[1] != "") {
164 $profiledata["url"] = $matches[1];
167 preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
168 if ($matches[1] != "") {
169 $profiledata["photo"] = $matches[1];
171 preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
172 if ($matches[1] != "") {
173 $profiledata["photo"] = $matches[1];
175 $profiledata["nickname"] = $profiledata["name"];
176 $profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
178 $profiledata["address"] = "";
179 $profiledata["about"] = "";
182 $profiledata = get_contact_details_by_url($profiledata["url"], local_user(), $profiledata);
184 $profiledata["photo"] = App::remove_baseurl($profiledata["photo"]);
187 if (in_array($profiledata["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
188 $profiledata["remoteconnect"] = App::get_baseurl()."/follow?url=".urlencode($profiledata["url"]);
190 } elseif ($profiledata["network"] == NETWORK_DFRN) {
191 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
192 $profiledata["remoteconnect"] = $connect;
195 return($profiledata);
198 function display_content(App $a, $update = 0) {
200 if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
201 notice(t('Public access denied.') . EOL);
205 require_once('include/security.php');
206 require_once('include/conversation.php');
207 require_once('include/acl_selectors.php');
213 $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));
222 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
228 $r = qu("SELECT `id` FROM `item`
229 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
230 AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
231 if (dbm::is_result($r)) {
232 $item_id = $r[0]["id"];
233 $nick = $a->user["nickname"];
238 $r = qu("SELECT `user`.`nickname`, `item`.`id` FROM `item` STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
239 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
240 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
241 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
242 AND NOT `item`.`private` AND NOT `user`.`hidewall`
243 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
244 // AND NOT `item`.`private` AND `item`.`wall`
245 if (dbm::is_result($r)) {
246 $item_id = $r[0]["id"];
247 $nick = $r[0]["nickname"];
251 $r = qu("SELECT `item`.`id` FROM `item`
252 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
253 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
254 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
255 AND NOT `item`.`private` AND `item`.`uid` = 0
256 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
257 // AND NOT `item`.`private` AND `item`.`wall`
258 if (dbm::is_result($r)) {
259 $item_id = $r[0]["id"];
265 if ($item_id AND !is_numeric($item_id)) {
266 $r = qu("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
267 dbesc($item_id), intval($a->profile['uid']));
268 if (dbm::is_result($r)) {
269 $item_id = $r[0]["id"];
277 notice(t('Item not found.').EOL);
281 $alternate = App::get_baseurl().'/display/'.$nick.'/'.$item_id.'.atom';
282 $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'),
283 array('$alternate' => $alternate));
289 $remote_contact = false;
293 if (is_array($_SESSION['remote'])) {
294 foreach ($_SESSION['remote'] as $v) {
295 if ($v['uid'] == $a->profile['uid']) {
296 $contact_id = $v['cid'];
303 $groups = init_groups_visitor($contact_id);
304 $r = qu("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
306 intval($a->profile['uid'])
308 if (dbm::is_result($r)) {
310 $remote_contact = true;
314 if (!$remote_contact) {
316 $contact_id = $_SESSION['cid'];
317 $contact = $a->contact;
321 $r = qu("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1",
322 intval($a->profile['uid'])
324 if (dbm::is_result($r)) {
325 $a->page_contact = $r[0];
327 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
329 if ($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
330 notice(t('Access to this profile has been restricted.') . EOL);
334 // We need the editor here to be able to reshare an item.
339 'allow_location' => $a->user['allow_location'],
340 'default_location' => $a->user['default-location'],
341 'nickname' => $a->user['nickname'],
342 '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'),
343 'acl' => populate_acl($a->user, true),
345 'visitor' => 'block',
346 'profile_uid' => local_user(),
347 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
349 $o .= status_editor($a,$x,0,true);
352 $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
356 $r = qu("SELECT `id` FROM `item` WHERE `item`.`uid` = %d
357 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d)
358 $sql_extra AND `unseen`",
359 intval($a->profile['uid']),
368 $r = qu(item_query()." AND `item`.`uid` = %d
369 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d)
371 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
372 intval($a->profile['uid']),
377 if (!$r && local_user()) {
378 // Check if this is another person's link to a post that we have
379 $r = qu("SELECT `item`.uri FROM `item`
380 WHERE (`item`.`id` = %d OR `item`.`uri` = '%s')
385 if (dbm::is_result($r)) {
386 $item_uri = $r[0]['uri'];
388 $r = qu(item_query()." AND `item`.`uid` = %d
389 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
390 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
391 intval(local_user()),
400 if ((local_user()) && (local_user() == $a->profile['uid'])) {
401 $unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `parent` = %d",
402 intval($r[0]['parent']));
405 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d AND `unseen`",
406 intval($r[0]['parent'])
411 $items = conv_sort($r,"`commented`");
414 $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
416 $o .= conversation($a,$items,'display', $update);
418 // Preparing the meta header
419 require_once('include/bbcode.php');
420 require_once("include/html2plain.php");
421 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
422 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
423 $author_name = $r[0]["author-name"];
425 $image = $a->remove_baseurl($r[0]["author-thumb"]);
428 $title = $author_name;
431 // Limit the description to 160 characters
432 if (strlen($description) > 160) {
433 $description = substr($description, 0, 157) . '...';
436 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
437 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
438 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
440 //<meta name="keywords" content="">
441 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
442 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
443 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
444 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
446 // Schema.org microdata
447 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
448 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
449 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
450 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
453 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
454 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
455 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
456 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
457 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
460 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
461 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
464 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
465 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
466 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
467 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
468 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
469 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
475 $r = qu("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
480 if ($r[0]['deleted']) {
481 notice(t('Item has been removed.') . EOL );
483 notice(t('Permission denied.') . EOL );
486 notice(t('Item not found.') . EOL );