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
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();
71 profile_load($a, $nick, 0, $profiledata);
75 function display_fetchauthor($a, $item) {
76 require_once("mod/proxy.php");
77 require_once("include/bbcode.php");
79 $profiledata = array();
80 $profiledata["uid"] = -1;
81 $profiledata["nickname"] = $item["author-name"];
82 $profiledata["name"] = $item["author-name"];
83 $profiledata["picdate"] = "";
84 $profiledata["photo"] = proxy_url($item["author-avatar"]);
85 $profiledata["url"] = $item["author-link"];
86 $profiledata["network"] = $item["network"];
88 // Fetching profile data from unique contacts
89 // To-do: Extend "unique contacts" table for further contact data like location, ...
90 $r = q("SELECT `avatar`, `nick` FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($profiledata["url"]));
92 $profiledata["photo"] = proxy_url($r[0]["avatar"]);
93 if ($r[0]["nick"] != "")
94 $profiledata["nickname"] = $r[0]["nick"];
96 // Is this case possible?
97 // Fetching further contact data from the contact table, when it isn't available in the "unique contacts"
98 $r = q("SELECT `photo`, `nick` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
99 normalise_link($profiledata["url"]), $itemuid);
101 $profiledata["photo"] = proxy_url($r[0]["photo"]);
102 if ($r[0]["nick"] != "")
103 $profiledata["nickname"] = $r[0]["nick"];
107 // Check for a repeated message
109 $body = trim($item["body"]);
111 // Skip if it isn't a pure repeated messages
112 // Does it start with a share?
113 if (!$skip AND strpos($body, "[share") > 0)
116 // Does it end with a share?
117 if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8)))
121 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
122 // Skip if there is no shared message in there
123 if ($body == $attributes)
129 preg_match("/author='(.*?)'/ism", $attributes, $matches);
130 if ($matches[1] != "")
131 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
133 preg_match('/author="(.*?)"/ism', $attributes, $matches);
134 if ($matches[1] != "")
135 $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
138 preg_match("/profile='(.*?)'/ism", $attributes, $matches);
139 if ($matches[1] != "")
140 $profiledata["url"] = $matches[1];
142 preg_match('/profile="(.*?)"/ism', $attributes, $matches);
143 if ($matches[1] != "")
144 $profiledata["url"] = $matches[1];
147 preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
148 if ($matches[1] != "")
149 $profiledata["photo"] = $matches[1];
151 preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
152 if ($matches[1] != "")
153 $profiledata["photo"] = $matches[1];
155 $profiledata["nickname"] = $profiledata["name"];
156 $profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
160 if ($profiledata["network"] == NETWORK_DFRN) {
161 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"])."&addr=".bin2hex($a->get_baseurl()."/profile/".$a->user["nickname"]);
162 $profiledata["remoteconnect"] = $connect;
163 } elseif ($profiledata["network"] == NETWORK_DIASPORA)
164 $profiledata["remoteconnect"] = $a->get_baseurl()."/contacts?add=".GetProfileUsername($profiledata["url"], "", true);
165 } elseif ($profiledata["network"] == NETWORK_DFRN) {
166 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
167 $profiledata["remoteconnect"] = $connect;
170 return($profiledata);
173 function display_content(&$a, $update = 0) {
175 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
176 notice( t('Public access denied.') . EOL);
180 require_once("include/bbcode.php");
181 require_once('include/security.php');
182 require_once('include/conversation.php');
183 require_once('include/acl_selectors.php');
188 $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
192 $nick = $_REQUEST['nick'];
195 $nick = (($a->argc > 1) ? $a->argv[1] : '');
199 $item_id = $_REQUEST['item_id'];
200 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
203 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
209 $r = q("SELECT `id` FROM `item`
210 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
211 AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user());
213 $item_id = $r[0]["id"];
214 $nick = $a->user["nickname"];
219 $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
220 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
221 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
222 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
223 AND `item`.`private` = 0
224 AND `item`.`guid` = '%s'", $a->argv[1]);
225 // AND `item`.`private` = 0 AND `item`.`wall` = 1
227 $item_id = $r[0]["id"];
228 $nick = $r[0]["nickname"];
236 notice( t('Item not found.') . EOL);
243 $remote_contact = false;
247 if(is_array($_SESSION['remote'])) {
248 foreach($_SESSION['remote'] as $v) {
249 if($v['uid'] == $a->profile['uid']) {
250 $contact_id = $v['cid'];
257 $groups = init_groups_visitor($contact_id);
258 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
260 intval($a->profile['uid'])
264 $remote_contact = true;
268 if(! $remote_contact) {
270 $contact_id = $_SESSION['cid'];
271 $contact = $a->contact;
275 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
276 intval($a->profile['uid'])
279 $a->page_contact = $r[0];
281 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
283 if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
284 notice( t('Access to this profile has been restricted.') . EOL);
289 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
293 'allow_location' => $a->user['allow_location'],
294 'default_location' => $a->user['default-location'],
295 'nickname' => $a->user['nickname'],
296 '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'),
297 'acl' => populate_acl($a->user, $celeb),
299 'visitor' => 'block',
300 'profile_uid' => local_user(),
301 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
303 $o .= status_editor($a,$x,0,true);
306 $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
308 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
312 $r = q("SELECT id FROM item WHERE item.uid = %d
313 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s'))
314 $sql_extra AND unseen = 1",
315 intval($a->profile['uid']),
324 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
326 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
327 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
328 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
329 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
330 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
331 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
332 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
333 and `item`.`moderated` = 0
334 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
337 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
338 intval($a->profile['uid']),
341 intval($a->profile['uid'])
344 if(!$r && local_user()) {
345 // Check if this is another person's link to a post that we have
346 $r = q("SELECT `item`.uri FROM `item`
347 WHERE (`item`.`id` = '%s' OR `item`.`uri` = '%s' )
353 $item_uri = $r[0]['uri'];
354 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
356 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
357 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
358 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
359 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
360 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
361 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
362 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
363 and `item`.`moderated` = 0
364 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
365 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
366 intval(local_user()),
376 if((local_user()) && (local_user() == $a->profile['uid'])) {
377 q("UPDATE `item` SET `unseen` = 0
378 WHERE `parent` = %d AND `unseen` = 1",
379 intval($r[0]['parent'])
383 $items = conv_sort($r,"`commented`");
386 $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
387 $o .= conversation($a,$items,'display', $update);
389 // Preparing the meta header
390 require_once('include/bbcode.php');
391 require_once("include/html2plain.php");
392 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
393 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
394 $author_name = $r[0]["author-name"];
398 $image = $r[0]["thumb"];
401 $title = $author_name;
403 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
404 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
405 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
407 //<meta name="keywords" content="">
408 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
409 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
410 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
411 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
413 // Schema.org microdata
414 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
415 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
416 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
417 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
420 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
421 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
422 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
423 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
424 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
427 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
428 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
431 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
432 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
433 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
434 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
435 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
436 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
442 $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
447 if($r[0]['deleted']) {
448 notice( t('Item has been removed.') . EOL );
451 notice( t('Permission denied.') . EOL );
455 notice( t('Item not found.') . EOL );