3 function display_init(&$a) {
5 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
9 $nick = (($a->argc > 1) ? $a->argv[1] : '');
11 // If there is only one parameter, then check if this parameter could be a guid
15 // Does the local user have this item?
17 $r = q("SELECT `id` FROM `item`
18 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
19 AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user());
21 $nick = $a->user["nickname"];
24 // Or is it anywhere on the server?
26 $r = q("SELECT `user`.`nickname` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
27 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
28 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
29 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
30 AND `item`.`private` = 0 AND `item`.`wall` = 1
31 AND `item`.`guid` = '%s'", $a->argv[1]);
33 $nick = $r[0]["nickname"];
37 profile_load($a,$nick);
42 function display_content(&$a, $update = 0) {
44 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
45 notice( t('Public access denied.') . EOL);
49 require_once("include/bbcode.php");
50 require_once('include/security.php');
51 require_once('include/conversation.php');
52 require_once('include/acl_selectors.php');
57 $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
61 $nick = $_REQUEST['nick'];
64 $nick = (($a->argc > 1) ? $a->argv[1] : '');
68 $item_id = $_REQUEST['item_id'];
69 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
72 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
78 $r = q("SELECT `id` FROM `item`
79 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
80 AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user());
82 $item_id = $r[0]["id"];
83 $nick = $a->user["nickname"];
88 $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
89 WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
90 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
91 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
92 AND `item`.`private` = 0 AND `item`.`wall` = 1
93 AND `item`.`guid` = '%s'", $a->argv[1]);
95 $item_id = $r[0]["id"];
96 $nick = $r[0]["nickname"];
104 notice( t('Item not found.') . EOL);
111 $remote_contact = false;
115 if(is_array($_SESSION['remote'])) {
116 foreach($_SESSION['remote'] as $v) {
117 if($v['uid'] == $a->profile['uid']) {
118 $contact_id = $v['cid'];
125 $groups = init_groups_visitor($contact_id);
126 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
128 intval($a->profile['uid'])
132 $remote_contact = true;
136 if(! $remote_contact) {
138 $contact_id = $_SESSION['cid'];
139 $contact = $a->contact;
143 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
144 intval($a->profile['uid'])
147 $a->page_contact = $r[0];
149 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
151 if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
152 notice( t('Access to this profile has been restricted.') . EOL);
157 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
161 'allow_location' => $a->user['allow_location'],
162 'default_location' => $a->user['default-location'],
163 'nickname' => $a->user['nickname'],
164 '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'),
165 'acl' => populate_acl($a->user, $celeb),
167 'visitor' => 'block',
168 'profile_uid' => local_user(),
169 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
171 $o .= status_editor($a,$x,0,true);
174 $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
176 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
180 $r = q("SELECT id FROM item WHERE item.uid = %d
181 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s'))
182 $sql_extra AND unseen = 1",
183 intval($a->profile['uid']),
192 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
194 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
195 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
196 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
197 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
198 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
199 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
200 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
201 and `item`.`moderated` = 0
202 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
205 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
206 intval($a->profile['uid']),
209 intval($a->profile['uid'])
212 if(!$r && local_user()) {
213 // Check if this is another person's link to a post that we have
214 $r = q("SELECT `item`.uri FROM `item`
215 WHERE (`item`.`id` = '%s' OR `item`.`uri` = '%s' )
221 $item_uri = $r[0]['uri'];
222 // AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
224 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
225 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
226 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
227 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
228 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
229 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
230 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
231 and `item`.`moderated` = 0
232 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
233 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
234 intval(local_user()),
244 if((local_user()) && (local_user() == $a->profile['uid'])) {
245 q("UPDATE `item` SET `unseen` = 0
246 WHERE `parent` = %d AND `unseen` = 1",
247 intval($r[0]['parent'])
251 $items = conv_sort($r,"`commented`");
254 $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
255 $o .= conversation($a,$items,'display', $update);
257 // Preparing the meta header
258 require_once('include/bbcode.php');
259 require_once("include/html2plain.php");
260 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
261 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
262 $author_name = $r[0]["author-name"];
266 $image = $r[0]["thumb"];
269 $title = $author_name;
271 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
272 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
273 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
275 //<meta name="keywords" content="">
276 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
277 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
278 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
279 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
281 // Schema.org microdata
282 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
283 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
284 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
285 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
288 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
289 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
290 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
291 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
292 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
295 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
296 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
299 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
300 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
301 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
302 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
303 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
304 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
310 $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
315 if($r[0]['deleted']) {
316 notice( t('Item has been removed.') . EOL );
319 notice( t('Permission denied.') . EOL );
323 notice( t('Item not found.') . EOL );