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` FROM `item`
20 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
21 AND `guid` = '%s' AND `uid` = %d", $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'", $a->argv[1]);
38 // AND `item`.`private` = 0 AND `item`.`wall` = 1
40 $nick = $r[0]["nickname"];
41 $itemuid = $r[0]["uid"];
45 if ($r[0]["id"] != $r[0]["parent"])
46 $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body` FROM `item`
47 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
48 AND `id` = %d", $r[0]["parent"]);
50 $profiledata = display_fetchauthor($a, $r[0]);
52 if (strstr(normalise_link($profiledata["url"]), normalise_link($a->get_baseurl()))) {
53 $nickname = str_replace(normalise_link($a->get_baseurl())."/profile/", "", normalise_link($profiledata["url"]));
55 if (($nickname != $a->user["nickname"])) {
56 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
57 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
58 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1",
64 $profiledata["network"] = NETWORK_DFRN;
66 $profiledata = array();
70 notice( t('Item not found.') . EOL);
75 profile_load($a, $nick, 0, $profiledata);
79 function display_fetchauthor($a, $item) {
80 require_once("mod/proxy.php");
81 require_once("include/bbcode.php");
83 $profiledata = array();
84 $profiledata["uid"] = -1;
85 $profiledata["nickname"] = $item["author-name"];
86 $profiledata["name"] = $item["author-name"];
87 $profiledata["picdate"] = "";
88 $profiledata["photo"] = proxy_url($item["author-avatar"]);
89 $profiledata["url"] = $item["author-link"];
90 $profiledata["network"] = $item["network"];
92 // Fetching profile data from unique contacts
93 // To-do: Extend "unique contacts" table for further contact data like location, ...
94 $r = q("SELECT `avatar`, `nick` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"]));
96 $profiledata["photo"] = proxy_url($r[0]["avatar"]);
97 if ($r[0]["nick"] != "")
98 $profiledata["nickname"] = $r[0]["nick"];
100 // Is this case possible?
101 // Fetching further contact data from the contact table, when it isn't available in the "unique contacts"
102 $r = q("SELECT `photo`, `nick` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
103 normalise_link($profiledata["url"]), $itemuid);
105 $profiledata["photo"] = proxy_url($r[0]["photo"]);
106 if ($r[0]["nick"] != "")
107 $profiledata["nickname"] = $r[0]["nick"];
111 // Check for a repeated message
113 $body = trim($item["body"]);
115 // Skip if it isn't a pure repeated messages
116 // Does it start with a share?
117 if (!$skip AND strpos($body, "[share") > 0)
120 // Does it end with a share?
121 if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8)))
125 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
126 // Skip if there is no shared message in there
127 if ($body == $attributes)
133 preg_match("/author='(.*?)'/ism", $attributes, $matches);
134 if ($matches[1] != "")
135 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
137 preg_match('/author="(.*?)"/ism', $attributes, $matches);
138 if ($matches[1] != "")
139 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
142 preg_match("/profile='(.*?)'/ism", $attributes, $matches);
143 if ($matches[1] != "")
144 $profiledata["url"] = $matches[1];
146 preg_match('/profile="(.*?)"/ism', $attributes, $matches);
147 if ($matches[1] != "")
148 $profiledata["url"] = $matches[1];
151 preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
152 if ($matches[1] != "")
153 $profiledata["photo"] = $matches[1];
155 preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
156 if ($matches[1] != "")
157 $profiledata["photo"] = $matches[1];
159 $profiledata["nickname"] = $profiledata["name"];
160 $profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
164 if ($profiledata["network"] == NETWORK_DFRN) {
165 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"])."&addr=".bin2hex($a->get_baseurl()."/profile/".$a->user["nickname"]);
166 $profiledata["remoteconnect"] = $connect;
167 } elseif ($profiledata["network"] == NETWORK_DIASPORA)
168 $profiledata["remoteconnect"] = $a->get_baseurl()."/contacts?add=".GetProfileUsername($profiledata["url"], "", true);
169 } elseif ($profiledata["network"] == NETWORK_DFRN) {
170 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
171 $profiledata["remoteconnect"] = $connect;
174 return($profiledata);
177 function display_content(&$a, $update = 0) {
179 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
180 notice( t('Public access denied.') . EOL);
184 require_once("include/bbcode.php");
185 require_once('include/security.php');
186 require_once('include/conversation.php');
187 require_once('include/acl_selectors.php');
192 $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
196 $nick = $_REQUEST['nick'];
199 $nick = (($a->argc > 1) ? $a->argv[1] : '');
203 $item_id = $_REQUEST['item_id'];
204 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
207 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
213 $r = q("SELECT `id` FROM `item`
214 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
215 AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user());
217 $item_id = $r[0]["id"];
218 $nick = $a->user["nickname"];
223 $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
224 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
225 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
226 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
227 AND `item`.`private` = 0 AND NOT `user`.`hidewall`
228 AND `item`.`guid` = '%s'", $a->argv[1]);
229 // AND `item`.`private` = 0 AND `item`.`wall` = 1
231 $item_id = $r[0]["id"];
232 $nick = $r[0]["nickname"];
240 notice( t('Item not found.') . EOL);
247 $remote_contact = false;
251 if(is_array($_SESSION['remote'])) {
252 foreach($_SESSION['remote'] as $v) {
253 if($v['uid'] == $a->profile['uid']) {
254 $contact_id = $v['cid'];
261 $groups = init_groups_visitor($contact_id);
262 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
264 intval($a->profile['uid'])
268 $remote_contact = true;
272 if(! $remote_contact) {
274 $contact_id = $_SESSION['cid'];
275 $contact = $a->contact;
279 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
280 intval($a->profile['uid'])
283 $a->page_contact = $r[0];
285 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
287 if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
288 notice( t('Access to this profile has been restricted.') . EOL);
293 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
297 'allow_location' => $a->user['allow_location'],
298 'default_location' => $a->user['default-location'],
299 'nickname' => $a->user['nickname'],
300 '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'),
301 'acl' => populate_acl($a->user, $celeb),
303 'visitor' => 'block',
304 'profile_uid' => local_user(),
305 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
307 $o .= status_editor($a,$x,0,true);
310 $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
312 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
316 $r = q("SELECT id FROM item WHERE item.uid = %d
317 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s'))
318 $sql_extra AND unseen = 1",
319 intval($a->profile['uid']),
328 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
330 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
331 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
332 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
333 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
334 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
335 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
336 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
337 and `item`.`moderated` = 0
338 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
341 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
342 intval($a->profile['uid']),
345 intval($a->profile['uid'])
348 if(!$r && local_user()) {
349 // Check if this is another person's link to a post that we have
350 $r = q("SELECT `item`.uri FROM `item`
351 WHERE (`item`.`id` = '%s' OR `item`.`uri` = '%s' )
357 $item_uri = $r[0]['uri'];
358 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
360 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
361 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
362 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
363 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
364 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
365 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
366 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
367 and `item`.`moderated` = 0
368 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
369 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
370 intval(local_user()),
380 if((local_user()) && (local_user() == $a->profile['uid'])) {
381 q("UPDATE `item` SET `unseen` = 0
382 WHERE `parent` = %d AND `unseen` = 1",
383 intval($r[0]['parent'])
387 $items = conv_sort($r,"`commented`");
390 $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
391 $o .= conversation($a,$items,'display', $update);
393 // Preparing the meta header
394 require_once('include/bbcode.php');
395 require_once("include/html2plain.php");
396 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
397 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
398 $author_name = $r[0]["author-name"];
402 $image = $r[0]["thumb"];
405 $title = $author_name;
407 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
408 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
409 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
411 //<meta name="keywords" content="">
412 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
413 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
414 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
415 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
417 // Schema.org microdata
418 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
419 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
420 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
421 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
424 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
425 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
426 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
427 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
428 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
431 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
432 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
435 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
436 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
437 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
438 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
439 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
440 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
446 $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
451 if($r[0]['deleted']) {
452 notice( t('Item has been removed.') . EOL );
455 notice( t('Permission denied.') . EOL );
459 notice( t('Item not found.') . EOL );