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` 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`, `uid` 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 further contact data from the contact table
93 $r = q("SELECT `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
94 normalise_link($profiledata["url"]), $item["uid"]);
96 $profiledata["photo"] = proxy_url($r[0]["photo"]);
97 $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"]));
98 $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"]));
99 if ($r[0]["nick"] != "")
100 $profiledata["nickname"] = $r[0]["nick"];
103 // Fetching profile data from unique contacts
104 $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"]));
106 if ($profiledata["photo"] == "")
107 $profiledata["photo"] = proxy_url($r[0]["avatar"]);
108 if ($profiledata["address"] == "")
109 $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"]));
110 if ($profiledata["about"] == "")
111 $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"]));
112 if (($profiledata["nickname"] == "") AND ($r[0]["nick"] != ""))
113 $profiledata["nickname"] = $r[0]["nick"];
116 // Check for a repeated message
118 $body = trim($item["body"]);
120 // Skip if it isn't a pure repeated messages
121 // Does it start with a share?
122 if (!$skip AND strpos($body, "[share") > 0)
125 // Does it end with a share?
126 if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8)))
130 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
131 // Skip if there is no shared message in there
132 if ($body == $attributes)
138 preg_match("/author='(.*?)'/ism", $attributes, $matches);
139 if ($matches[1] != "")
140 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
142 preg_match('/author="(.*?)"/ism', $attributes, $matches);
143 if ($matches[1] != "")
144 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
147 preg_match("/profile='(.*?)'/ism", $attributes, $matches);
148 if ($matches[1] != "")
149 $profiledata["url"] = $matches[1];
151 preg_match('/profile="(.*?)"/ism', $attributes, $matches);
152 if ($matches[1] != "")
153 $profiledata["url"] = $matches[1];
156 preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
157 if ($matches[1] != "")
158 $profiledata["photo"] = $matches[1];
160 preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
161 if ($matches[1] != "")
162 $profiledata["photo"] = $matches[1];
164 $profiledata["nickname"] = $profiledata["name"];
165 $profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
167 $profiledata["address"] = "";
168 $profiledata["about"] = "";
170 // Fetching profile data from unique contacts
171 if ($profiledata["url"] != "") {
172 $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"]));
174 $profiledata["photo"] = proxy_url($r[0]["avatar"]);
175 $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"]));
176 $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"]));
177 if ($r[0]["nick"] != "")
178 $profiledata["nickname"] = $r[0]["nick"];
184 if ($profiledata["network"] == NETWORK_DFRN) {
185 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"])."&addr=".bin2hex($a->get_baseurl()."/profile/".$a->user["nickname"]);
186 $profiledata["remoteconnect"] = $connect;
187 } elseif ($profiledata["network"] == NETWORK_DIASPORA)
188 $profiledata["remoteconnect"] = $a->get_baseurl()."/contacts?add=".GetProfileUsername($profiledata["url"], "", true);
189 } elseif ($profiledata["network"] == NETWORK_DFRN) {
190 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
191 $profiledata["remoteconnect"] = $connect;
194 return($profiledata);
197 function display_content(&$a, $update = 0) {
199 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
200 notice( t('Public access denied.') . EOL);
204 require_once("include/bbcode.php");
205 require_once('include/security.php');
206 require_once('include/conversation.php');
207 require_once('include/acl_selectors.php');
212 $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
216 $nick = $_REQUEST['nick'];
219 $nick = (($a->argc > 1) ? $a->argv[1] : '');
223 $item_id = $_REQUEST['item_id'];
224 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
227 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
233 $r = q("SELECT `id` FROM `item`
234 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
235 AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user());
237 $item_id = $r[0]["id"];
238 $nick = $a->user["nickname"];
243 $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
244 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
245 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
246 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
247 AND `item`.`private` = 0 AND NOT `user`.`hidewall`
248 AND `item`.`guid` = '%s'", $a->argv[1]);
249 // AND `item`.`private` = 0 AND `item`.`wall` = 1
251 $item_id = $r[0]["id"];
252 $nick = $r[0]["nickname"];
260 notice( t('Item not found.') . EOL);
267 $remote_contact = false;
271 if(is_array($_SESSION['remote'])) {
272 foreach($_SESSION['remote'] as $v) {
273 if($v['uid'] == $a->profile['uid']) {
274 $contact_id = $v['cid'];
281 $groups = init_groups_visitor($contact_id);
282 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
284 intval($a->profile['uid'])
288 $remote_contact = true;
292 if(! $remote_contact) {
294 $contact_id = $_SESSION['cid'];
295 $contact = $a->contact;
299 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
300 intval($a->profile['uid'])
303 $a->page_contact = $r[0];
305 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
307 if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
308 notice( t('Access to this profile has been restricted.') . EOL);
313 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
317 'allow_location' => $a->user['allow_location'],
318 'default_location' => $a->user['default-location'],
319 'nickname' => $a->user['nickname'],
320 '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'),
321 'acl' => populate_acl($a->user, $celeb),
323 'visitor' => 'block',
324 'profile_uid' => local_user(),
325 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
327 $o .= status_editor($a,$x,0,true);
330 $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
332 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
336 $r = q("SELECT id FROM item WHERE item.uid = %d
337 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s'))
338 $sql_extra AND unseen = 1",
339 intval($a->profile['uid']),
348 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
350 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
351 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
352 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
353 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
354 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
355 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
356 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
357 and `item`.`moderated` = 0
358 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
361 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
362 intval($a->profile['uid']),
365 intval($a->profile['uid'])
368 if(!$r && local_user()) {
369 // Check if this is another person's link to a post that we have
370 $r = q("SELECT `item`.uri FROM `item`
371 WHERE (`item`.`id` = '%s' OR `item`.`uri` = '%s' )
377 $item_uri = $r[0]['uri'];
378 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
380 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
381 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
382 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
383 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
384 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
385 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
386 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
387 and `item`.`moderated` = 0
388 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
389 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
390 intval(local_user()),
400 if((local_user()) && (local_user() == $a->profile['uid'])) {
401 q("UPDATE `item` SET `unseen` = 0
402 WHERE `parent` = %d AND `unseen` = 1",
403 intval($r[0]['parent'])
407 $items = conv_sort($r,"`commented`");
410 $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
411 $o .= conversation($a,$items,'display', $update);
413 // Preparing the meta header
414 require_once('include/bbcode.php');
415 require_once("include/html2plain.php");
416 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
417 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
418 $author_name = $r[0]["author-name"];
422 $image = $r[0]["thumb"];
425 $title = $author_name;
427 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
428 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
429 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
431 //<meta name="keywords" content="">
432 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
433 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
434 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
435 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
437 // Schema.org microdata
438 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
439 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
440 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
441 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
444 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
445 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
446 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
447 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
448 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
451 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
452 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
455 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
456 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
457 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
458 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
459 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
460 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
466 $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
471 if($r[0]['deleted']) {
472 notice( t('Item has been removed.') . EOL );
475 notice( t('Permission denied.') . EOL );
479 notice( t('Item not found.') . EOL );