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 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 = q("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());
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($a->get_baseurl()))) {
87 $nickname = str_replace(normalise_link($a->get_baseurl())."/profile/", "", normalise_link($profiledata["url"]));
89 if (($nickname != $a->user["nickname"])) {
90 $r = q("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",
98 $profiledata["network"] = NETWORK_DFRN;
100 $profiledata = array();
104 notice( t('Item not found.') . EOL);
109 profile_load($a, $nick, 0, $profiledata);
113 function display_fetchauthor($a, $item) {
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 // Don't show details from Diaspora contacts if you don't follow the contact
180 $showdetails = ($profiledata["network"] != NETWORK_DIASPORA);
182 // Fetching further contact data from the contact table
183 $r = q("SELECT `uid`, `network`, `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`
184 FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)",
185 dbesc(normalise_link($profiledata["url"])), intval(local_user()), dbesc($item["network"]),
186 intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
188 $r = q("SELECT `uid`, `network`, `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`
189 FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `rel` IN (%d, %d)",
190 dbesc(normalise_link($profiledata["url"])), intval(local_user()),
191 intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND));
194 $profiledata["name"] = $r[0]["name"];
195 $profiledata["photo"] = $r[0]["photo"];
196 $profiledata["nickname"] = $r[0]["nick"];
197 $profiledata["addr"] = $r[0]["addr"];
198 $profiledata["keywords"] = $r[0]["keywords"];
199 $profiledata["network"] = $r[0]["network"];
201 if (local_user() OR $showdetails) {
203 $profiledata["address"] = $r[0]["location"];
204 $profiledata["about"] = $r[0]["about"];
205 $profiledata["gender"] = $r[0]["gender"];
209 // Fetching profile data from global contacts
210 if ($profiledata["network"] != NETWORK_FEED) {
211 $r = q("SELECT `name`, `photo`, `nick`, `addr`, `location`, `about`, `gender`, `keywords`, `network` FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($profiledata["url"])));
213 $profiledata["name"] = $r[0]["name"];
214 $profiledata["photo"] = $r[0]["photo"];
215 $profiledata["nickname"] = $r[0]["nick"];
216 $profiledata["addr"] = $r[0]["addr"];
217 $profiledata["network"] = $r[0]["network"];
219 if ($r[0]["keywords"])
220 $profiledata["keywords"] = $r[0]["keywords"];
223 if ($r[0]["location"])
224 $profiledata["address"] = $r[0]["location"];
227 $profiledata["about"] = $r[0]["about"];
230 $profiledata["gender"] = $r[0]["gender"];
236 if (in_array($profiledata["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
237 $profiledata["remoteconnect"] = $a->get_baseurl()."/follow?url=".urlencode($profiledata["url"]);
238 } elseif ($profiledata["network"] == NETWORK_DFRN) {
239 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
240 $profiledata["remoteconnect"] = $connect;
243 return($profiledata);
246 function display_content(&$a, $update = 0) {
248 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
249 notice( t('Public access denied.') . EOL);
253 require_once('include/security.php');
254 require_once('include/conversation.php');
255 require_once('include/acl_selectors.php');
260 $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
264 $nick = $_REQUEST['nick'];
267 $nick = (($a->argc > 1) ? $a->argv[1] : '');
271 $item_id = $_REQUEST['item_id'];
272 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
275 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
281 $r = q("SELECT `id` FROM `item`
282 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
283 AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user());
285 $item_id = $r[0]["id"];
286 $nick = $a->user["nickname"];
291 $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
292 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
293 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
294 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
295 AND NOT `item`.`private` AND NOT `user`.`hidewall`
296 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
297 // AND NOT `item`.`private` AND `item`.`wall`
299 $item_id = $r[0]["id"];
300 $nick = $r[0]["nickname"];
304 $r = q("SELECT `item`.`id` FROM `item`
305 WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
306 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
307 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
308 AND NOT `item`.`private` AND `item`.`uid` = 0
309 AND `item`.`guid` = '%s'", dbesc($a->argv[1]));
310 // AND NOT `item`.`private` AND `item`.`wall`
312 $item_id = $r[0]["id"];
318 if ($item_id AND !is_numeric($item_id)) {
319 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
320 dbesc($item_id), intval($a->profile['uid']));
322 $item_id = $r[0]["id"];
329 notice(t('Item not found.').EOL);
337 $remote_contact = false;
341 if(is_array($_SESSION['remote'])) {
342 foreach($_SESSION['remote'] as $v) {
343 if($v['uid'] == $a->profile['uid']) {
344 $contact_id = $v['cid'];
351 $groups = init_groups_visitor($contact_id);
352 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
354 intval($a->profile['uid'])
358 $remote_contact = true;
362 if(! $remote_contact) {
364 $contact_id = $_SESSION['cid'];
365 $contact = $a->contact;
369 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1",
370 intval($a->profile['uid'])
373 $a->page_contact = $r[0];
375 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
377 if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
378 notice( t('Access to this profile has been restricted.') . EOL);
382 // We need the editor here to be able to reshare an item.
387 'allow_location' => $a->user['allow_location'],
388 'default_location' => $a->user['default-location'],
389 'nickname' => $a->user['nickname'],
390 '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'),
391 'acl' => populate_acl($a->user, true),
393 'visitor' => 'block',
394 'profile_uid' => local_user(),
395 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
397 $o .= status_editor($a,$x,0,true);
400 $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
404 $r = q("SELECT `id` FROM `item` WHERE `item`.`uid` = %d
405 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d)
406 $sql_extra AND `unseen`",
407 intval($a->profile['uid']),
415 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
416 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
417 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
418 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
419 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
420 AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
421 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted`
422 AND NOT `item`.`moderated`
423 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `id` = %d)
425 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
426 intval($a->profile['uid']),
430 if(!$r && local_user()) {
431 // Check if this is another person's link to a post that we have
432 $r = q("SELECT `item`.uri FROM `item`
433 WHERE (`item`.`id` = %d OR `item`.`uri` = '%s')
439 $item_uri = $r[0]['uri'];
441 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
442 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
443 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
444 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
445 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
446 AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
447 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted`
448 AND NOT `item`.`moderated`
449 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
450 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
451 intval(local_user()),
461 if((local_user()) && (local_user() == $a->profile['uid'])) {
462 $unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `parent` = %d",
463 intval($r[0]['parent']));
466 q("UPDATE `item` SET `unseen` = 0
467 WHERE `parent` = %d AND `unseen`",
468 intval($r[0]['parent'])
472 $items = conv_sort($r,"`commented`");
475 $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
476 $o .= conversation($a,$items,'display', $update);
478 // Preparing the meta header
479 require_once('include/bbcode.php');
480 require_once("include/html2plain.php");
481 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
482 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
483 $author_name = $r[0]["author-name"];
487 $image = $r[0]["thumb"];
490 $title = $author_name;
492 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
493 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
494 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
496 //<meta name="keywords" content="">
497 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
498 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
499 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
500 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
502 // Schema.org microdata
503 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
504 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
505 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
506 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
509 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
510 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
511 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
512 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
513 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
516 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
517 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
520 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
521 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
522 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
523 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
524 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
525 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
531 $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
536 if($r[0]['deleted']) {
537 notice( t('Item has been removed.') . EOL );
540 notice( t('Permission denied.') . EOL );
544 notice( t('Item not found.') . EOL );