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` 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`
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
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` FROM `item`
47 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
48 AND `id` = %d", $r[0]["parent"]);
50 if (!strstr(normalise_link($r[0]["author-link"]), normalise_link($a->get_baseurl()))) {
51 require_once("mod/proxy.php");
52 require_once("include/bbcode.php");
53 $profiledata["uid"] = -1;
54 $profiledata["nickname"] = $r[0]["author-name"];
55 $profiledata["name"] = $r[0]["author-name"];
56 $profiledata["picdate"] = "";
57 $profiledata["photo"] = proxy_url($r[0]["author-avatar"]);
58 $profiledata["url"] = $r[0]["author-link"];
59 $profiledata["network"] = $r[0]["network"];
61 // Fetching profile data from unique contacts
62 // To-do: Extend "unique contacts" table for further contact data like location, ...
63 $r = q("SELECT `avatar`, `nick` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"]));
65 $profiledata["photo"] = proxy_url($r[0]["avatar"]);
66 if ($r[0]["nick"] != "")
67 $profiledata["nickname"] = $r[0]["nick"];
69 // Is this case possible?
70 // Fetching further contact data from the contact table, when it isn't available in the "unique contacts"
71 $r = q("SELECT `photo`, `nick` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
72 normalise_link($profiledata["url"]), $itemuid);
74 $profiledata["photo"] = proxy_url($r[0]["photo"]);
75 if ($r[0]["nick"] != "")
76 $profiledata["nickname"] = $r[0]["nick"];
81 if ($profiledata["network"] == NETWORK_DFRN) {
82 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"])."&addr=".bin2hex($a->get_baseurl()."/profile/".$a->user["nickname"]);
83 $profiledata["remoteconnect"] = $connect;
84 } elseif ($profiledata["network"] == NETWORK_DIASPORA)
85 $profiledata["remoteconnect"] = $a->get_baseurl()."/contacts?add=".GetProfileUsername($profiledata["url"], "", true);
86 } elseif ($profiledata["network"] == NETWORK_DFRN) {
87 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
88 $profiledata["remoteconnect"] = $connect;
91 $nickname = str_replace(normalise_link($a->get_baseurl())."/profile/", "", normalise_link($r[0]["author-link"]));
93 if (($nickname != $a->user["nickname"])) {
94 $profiledata["url"] = $r[0]["author-link"];
96 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
97 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
98 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1",
102 $profiledata = $r[0];
103 $profiledata["network"] = NETWORK_DFRN;
109 profile_load($a, $nick, 0, $profiledata);
114 function display_content(&$a, $update = 0) {
116 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
117 notice( t('Public access denied.') . EOL);
121 require_once("include/bbcode.php");
122 require_once('include/security.php');
123 require_once('include/conversation.php');
124 require_once('include/acl_selectors.php');
129 $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
133 $nick = $_REQUEST['nick'];
136 $nick = (($a->argc > 1) ? $a->argv[1] : '');
140 $item_id = $_REQUEST['item_id'];
141 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
144 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
150 $r = q("SELECT `id` FROM `item`
151 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
152 AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user());
154 $item_id = $r[0]["id"];
155 $nick = $a->user["nickname"];
160 $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
161 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
162 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
163 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
164 AND `item`.`private` = 0
165 AND `item`.`guid` = '%s'", $a->argv[1]);
166 // AND `item`.`private` = 0 AND `item`.`wall` = 1
168 $item_id = $r[0]["id"];
169 $nick = $r[0]["nickname"];
177 notice( t('Item not found.') . EOL);
184 $remote_contact = false;
188 if(is_array($_SESSION['remote'])) {
189 foreach($_SESSION['remote'] as $v) {
190 if($v['uid'] == $a->profile['uid']) {
191 $contact_id = $v['cid'];
198 $groups = init_groups_visitor($contact_id);
199 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
201 intval($a->profile['uid'])
205 $remote_contact = true;
209 if(! $remote_contact) {
211 $contact_id = $_SESSION['cid'];
212 $contact = $a->contact;
216 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
217 intval($a->profile['uid'])
220 $a->page_contact = $r[0];
222 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
224 if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
225 notice( t('Access to this profile has been restricted.') . EOL);
230 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
234 'allow_location' => $a->user['allow_location'],
235 'default_location' => $a->user['default-location'],
236 'nickname' => $a->user['nickname'],
237 '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'),
238 'acl' => populate_acl($a->user, $celeb),
240 'visitor' => 'block',
241 'profile_uid' => local_user(),
242 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
244 $o .= status_editor($a,$x,0,true);
247 $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
249 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
253 $r = q("SELECT id FROM item WHERE item.uid = %d
254 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s'))
255 $sql_extra AND unseen = 1",
256 intval($a->profile['uid']),
265 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
267 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
268 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
269 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
270 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
271 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
272 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
273 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
274 and `item`.`moderated` = 0
275 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
278 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
279 intval($a->profile['uid']),
282 intval($a->profile['uid'])
285 if(!$r && local_user()) {
286 // Check if this is another person's link to a post that we have
287 $r = q("SELECT `item`.uri FROM `item`
288 WHERE (`item`.`id` = '%s' OR `item`.`uri` = '%s' )
294 $item_uri = $r[0]['uri'];
295 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
297 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
298 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
299 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
300 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
301 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
302 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
303 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
304 and `item`.`moderated` = 0
305 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
306 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
307 intval(local_user()),
317 if((local_user()) && (local_user() == $a->profile['uid'])) {
318 q("UPDATE `item` SET `unseen` = 0
319 WHERE `parent` = %d AND `unseen` = 1",
320 intval($r[0]['parent'])
324 $items = conv_sort($r,"`commented`");
327 $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
328 $o .= conversation($a,$items,'display', $update);
330 // Preparing the meta header
331 require_once('include/bbcode.php');
332 require_once("include/html2plain.php");
333 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
334 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
335 $author_name = $r[0]["author-name"];
339 $image = $r[0]["thumb"];
342 $title = $author_name;
344 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
345 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
346 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
348 //<meta name="keywords" content="">
349 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
350 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
351 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
352 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
354 // Schema.org microdata
355 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
356 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
357 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
358 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
361 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
362 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
363 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
364 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
365 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
368 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
369 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
372 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
373 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
374 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
375 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
376 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
377 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
383 $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
388 if($r[0]['deleted']) {
389 notice( t('Item has been removed.') . EOL );
392 notice( t('Permission denied.') . EOL );
396 notice( t('Item not found.') . EOL );