]> git.mxchange.org Git - friendica.git/blob - mod/display.php
Merge pull request #1752 from tobiasd/20150712-issue1747
[friendica.git] / mod / display.php
1 <?php
2
3 function display_init(&$a) {
4
5         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
6                 return;
7         }
8
9         $nick = (($a->argc > 1) ? $a->argv[1] : '');
10         $profiledata = array();
11
12         // If there is only one parameter, then check if this parameter could be a guid
13         if ($a->argc == 2) {
14                 $nick = "";
15                 $itemuid = 0;
16
17                 // Does the local user have this item?
18                 if (local_user()) {
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());
22                         if (count($r)) {
23                                 $nick = $a->user["nickname"];
24                                 $itemuid = local_user();
25                         }
26                 }
27
28                 // Or is it anywhere on the server?
29                 if ($nick == "") {
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
39                         if (count($r)) {
40                                 $nick = $r[0]["nickname"];
41                                 $itemuid = $r[0]["uid"];
42                         }
43                 }
44
45                 // Is it an item with uid=0?
46                 if ($nick == "") {
47                         $r = q("SELECT `item`.`id`, `item`.`parent`, `item`.`author-name`,
48                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`body`
49                                 FROM `item` WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
50                                         AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
51                                         AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
52                                         AND `item`.`private` = 0 AND `item`.`uid` = 0
53                                         AND `item`.`guid` = '%s'", $a->argv[1]);
54                                 //      AND `item`.`private` = 0 AND `item`.`wall` = 1
55                 }
56                 if (count($r)) {
57                         if ($r[0]["id"] != $r[0]["parent"])
58                                 $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item`
59                                         WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
60                                                 AND `id` = %d", $r[0]["parent"]);
61
62                         $profiledata = display_fetchauthor($a, $r[0]);
63
64                         if (strstr(normalise_link($profiledata["url"]), normalise_link($a->get_baseurl()))) {
65                                 $nickname = str_replace(normalise_link($a->get_baseurl())."/profile/", "", normalise_link($profiledata["url"]));
66
67                                 if (($nickname != $a->user["nickname"])) {
68                                         $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`
69                                                 INNER JOIN `contact` on `contact`.`uid` = `profile`.`uid` INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
70                                                 WHERE `user`.`nickname` = '%s' AND `profile`.`is-default` = 1 and `contact`.`self` = 1 LIMIT 1",
71                                                 dbesc($nickname)
72                                         );
73                                         if (count($r))
74                                                 $profiledata = $r[0];
75
76                                         $profiledata["network"] = NETWORK_DFRN;
77                                 } else
78                                         $profiledata = array();
79                         }
80                 } else {
81                         $a->error = 404;
82                         notice( t('Item not found.') . EOL);
83                         return;
84                 }
85         }
86
87         profile_load($a, $nick, 0, $profiledata);
88
89 }
90
91 function display_fetchauthor($a, $item) {
92         require_once("mod/proxy.php");
93         require_once("include/bbcode.php");
94
95         $profiledata = array();
96         $profiledata["uid"] = -1;
97         $profiledata["nickname"] = $item["author-name"];
98         $profiledata["name"] = $item["author-name"];
99         $profiledata["picdate"] = "";
100         $profiledata["photo"] = proxy_url($item["author-avatar"]);
101         $profiledata["url"] = $item["author-link"];
102         $profiledata["network"] = $item["network"];
103
104         // Fetching further contact data from the contact table
105         $r = q("SELECT `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s'",
106                 dbesc(normalise_link($profiledata["url"])), intval($item["uid"]), dbesc($item["network"]));
107
108         if (!count($r))
109                 $r = q("SELECT `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
110                         dbesc(normalise_link($profiledata["url"])), intval($item["uid"]));
111
112         if (!count($r))
113                 $r = q("SELECT `photo`, `nick`, `location`, `about` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
114                         dbesc(normalise_link($profiledata["url"])));
115
116         if (count($r)) {
117                 $profiledata["photo"] = proxy_url($r[0]["photo"]);
118                 $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"]));
119                 $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"]));
120                 if ($r[0]["nick"] != "")
121                         $profiledata["nickname"] = $r[0]["nick"];
122         }
123
124         // Fetching profile data from unique contacts
125         $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($profiledata["url"])));
126         if (count($r)) {
127                 if ($profiledata["photo"] == "")
128                         $profiledata["photo"] = proxy_url($r[0]["avatar"]);
129                 if ($profiledata["address"] == "")
130                         $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"]));
131                 if ($profiledata["about"] == "")
132                         $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"]));
133                 if (($profiledata["nickname"] == "") AND ($r[0]["nick"] != ""))
134                         $profiledata["nickname"] = $r[0]["nick"];
135         }
136
137         // Check for a repeated message
138         $skip = false;
139         $body = trim($item["body"]);
140
141         // Skip if it isn't a pure repeated messages
142         // Does it start with a share?
143         if (!$skip AND strpos($body, "[share") > 0)
144                 $skip = true;
145
146         // Does it end with a share?
147         if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8)))
148                 $skip = true;
149
150         if (!$skip) {
151                 $attributes = preg_replace("/\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","$1",$body);
152                 // Skip if there is no shared message in there
153                 if ($body == $attributes)
154                         $skip = true;
155         }
156
157         if (!$skip) {
158                 $author = "";
159                 preg_match("/author='(.*?)'/ism", $attributes, $matches);
160                 if ($matches[1] != "")
161                         $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
162
163                 preg_match('/author="(.*?)"/ism', $attributes, $matches);
164                 if ($matches[1] != "")
165                         $profiledata["name"] = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
166
167                 $profile = "";
168                 preg_match("/profile='(.*?)'/ism", $attributes, $matches);
169                 if ($matches[1] != "")
170                         $profiledata["url"] = $matches[1];
171
172                 preg_match('/profile="(.*?)"/ism', $attributes, $matches);
173                 if ($matches[1] != "")
174                         $profiledata["url"] = $matches[1];
175
176                 $avatar = "";
177                 preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
178                 if ($matches[1] != "")
179                         $profiledata["photo"] = $matches[1];
180
181                 preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
182                 if ($matches[1] != "")
183                         $profiledata["photo"] = $matches[1];
184
185                 $profiledata["nickname"] = $profiledata["name"];
186                 $profiledata["network"] = GetProfileUsername($profiledata["url"], "", false, true);
187
188                 $profiledata["address"] = "";
189                 $profiledata["about"] = "";
190
191                 // Fetching profile data from unique contacts
192                 if ($profiledata["url"] != "") {
193                         $r = q("SELECT `avatar`, `nick`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($profiledata["url"])));
194                         if (count($r)) {
195                                 $profiledata["photo"] = proxy_url($r[0]["avatar"]);
196                                 $profiledata["address"] = proxy_parse_html(bbcode($r[0]["location"]));
197                                 $profiledata["about"] = proxy_parse_html(bbcode($r[0]["about"]));
198                                 if ($r[0]["nick"] != "")
199                                         $profiledata["nickname"] = $r[0]["nick"];
200                         }
201                 }
202         }
203
204         if (local_user()) {
205                 if (in_array($profiledata["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
206                         $profiledata["remoteconnect"] = $a->get_baseurl()."/follow?url=".urlencode($profiledata["url"]);
207                 //if ($profiledata["network"] == NETWORK_DFRN) {
208                 //      $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"])."&addr=".bin2hex($a->get_baseurl()."/profile/".$a->user["nickname"]);
209                 //      $profiledata["remoteconnect"] = $connect;
210                 //} elseif ($profiledata["network"] == NETWORK_DIASPORA)
211                 //      $profiledata["remoteconnect"] = $a->get_baseurl()."/contacts?add=".GetProfileUsername($profiledata["url"], "", true);
212         } elseif ($profiledata["network"] == NETWORK_DFRN) {
213                 $connect = str_replace("/profile/", "/dfrn_request/", $profiledata["url"]);
214                 $profiledata["remoteconnect"] = $connect;
215         }
216
217         return($profiledata);
218 }
219
220 function display_content(&$a, $update = 0) {
221
222         if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
223                 notice( t('Public access denied.') . EOL);
224                 return;
225         }
226
227         require_once("include/bbcode.php");
228         require_once('include/security.php');
229         require_once('include/conversation.php');
230         require_once('include/acl_selectors.php');
231
232
233         $o = '';
234
235         $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
236
237
238         if($update) {
239                 $nick = $_REQUEST['nick'];
240         }
241         else {
242                 $nick = (($a->argc > 1) ? $a->argv[1] : '');
243         }
244
245         if($update) {
246                 $item_id = $_REQUEST['item_id'];
247                 $a->profile = array('uid' => intval($update), 'profile_uid' => intval($update));
248         }
249         else {
250                 $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
251
252                 if ($a->argc == 2) {
253                         $nick = "";
254
255                         if (local_user()) {
256                                 $r = q("SELECT `id` FROM `item`
257                                         WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
258                                                 AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user());
259                                 if (count($r)) {
260                                         $item_id = $r[0]["id"];
261                                         $nick = $a->user["nickname"];
262                                 }
263                         }
264
265                         if ($nick == "") {
266                                 $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
267                                         WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
268                                                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
269                                                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
270                                                 AND `item`.`private` = 0  AND NOT `user`.`hidewall`
271                                                 AND `item`.`guid` = '%s'", $a->argv[1]);
272                                         //      AND `item`.`private` = 0 AND `item`.`wall` = 1
273                                 if (count($r)) {
274                                         $item_id = $r[0]["id"];
275                                         $nick = $r[0]["nickname"];
276                                 }
277                         }
278                         if ($nick == "") {
279                                 $r = q("SELECT `item`.`id` FROM `item`
280                                         WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
281                                                 AND `item`.`allow_cid` = ''  AND `item`.`allow_gid` = ''
282                                                 AND `item`.`deny_cid`  = '' AND `item`.`deny_gid`  = ''
283                                                 AND `item`.`private` = 0  AND `item`.`uid` = 0
284                                                 AND `item`.`guid` = '%s'", $a->argv[1]);
285                                         //      AND `item`.`private` = 0 AND `item`.`wall` = 1
286                                 if (count($r)) {
287                                         $item_id = $r[0]["id"];
288                                 }
289                         }
290                 }
291         }
292
293         if(! $item_id) {
294                 $a->error = 404;
295                 notice( t('Item not found.') . EOL);
296                 return;
297         }
298
299         $groups = array();
300
301         $contact = null;
302         $remote_contact = false;
303
304         $contact_id = 0;
305
306         if(is_array($_SESSION['remote'])) {
307                 foreach($_SESSION['remote'] as $v) {
308                         if($v['uid'] == $a->profile['uid']) {
309                                 $contact_id = $v['cid'];
310                                 break;
311                         }
312                 }
313         }
314
315         if($contact_id) {
316                 $groups = init_groups_visitor($contact_id);
317                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
318                         intval($contact_id),
319                         intval($a->profile['uid'])
320                 );
321                 if(count($r)) {
322                         $contact = $r[0];
323                         $remote_contact = true;
324                 }
325         }
326
327         if(! $remote_contact) {
328                 if(local_user()) {
329                         $contact_id = $_SESSION['cid'];
330                         $contact = $a->contact;
331                 }
332         }
333
334         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
335                 intval($a->profile['uid'])
336         );
337         if(count($r))
338                 $a->page_contact = $r[0];
339
340         $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
341
342         if($a->profile['hidewall'] && (! $is_owner) && (! $remote_contact)) {
343                 notice( t('Access to this profile has been restricted.') . EOL);
344                 return;
345         }
346
347         if ($is_owner) {
348                 $x = array(
349                         'is_owner' => true,
350                         'allow_location' => $a->user['allow_location'],
351                         'default_location' => $a->user['default-location'],
352                         'nickname' => $a->user['nickname'],
353                         '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'),
354                         'acl' => populate_acl($a->user, true),
355                         'bang' => '',
356                         'visitor' => 'block',
357                         'profile_uid' => local_user(),
358                         'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
359                 );
360                 $o .= status_editor($a,$x,0,true);
361         }
362
363         $sql_extra = item_permissions_sql($a->profile['uid'],$remote_contact,$groups);
364
365         //              AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' ))
366
367         if($update) {
368
369                 $r = q("SELECT id FROM item WHERE item.uid = %d
370                         AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s'))
371                         $sql_extra AND unseen = 1",
372                         intval($a->profile['uid']),
373                         dbesc($item_id),
374                         dbesc($item_id)
375                 );
376
377                 if(!$r)
378                         return '';
379         }
380
381         //      AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE ( `id` = '%s' OR `uri` = '%s' )
382
383         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,  `item`.`network` AS `item_network`,
384                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
385                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`,
386                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
387                 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
388                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
389                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
390                 and `item`.`moderated` = 0
391                 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE (`id` = '%s' OR `uri` = '%s')
392                 AND uid = %d)
393                 $sql_extra
394                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC",
395                 intval($a->profile['uid']),
396                 dbesc($item_id),
397                 dbesc($item_id),
398                 intval($a->profile['uid'])
399         );
400
401         if(!$r && local_user()) {
402                 // Check if this is another person's link to a post that we have
403                 $r = q("SELECT `item`.uri FROM `item`
404                         WHERE (`item`.`id` = '%s' OR `item`.`uri` = '%s' )
405                         LIMIT 1",
406                         dbesc($item_id),
407                         dbesc($item_id)
408                 );
409                 if($r) {
410                         $item_uri = $r[0]['uri'];
411                         //      AND `item`.`parent` = ( SELECT `parent` FROM `item` FORCE INDEX (PRIMARY, `uri`) WHERE `uri` = '%s' AND uid = %d )
412
413                         $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,  `item`.`network` AS `item_network`,
414                                 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
415                                 `contact`.`network`, `contact`.`thumb`, `contact`.`self`, `contact`.`writable`, 
416                                 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
417                                 FROM `item` INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
418                                 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
419                                 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
420                                 and `item`.`moderated` = 0
421                                 AND `item`.`parent` = (SELECT `parent` FROM `item` WHERE `uri` = '%s' AND uid = %d)
422                                 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC ",
423                                 intval(local_user()),
424                                 dbesc($item_uri),
425                                 intval(local_user())
426                         );
427                 }
428         }
429
430
431         if($r) {
432
433                 if((local_user()) && (local_user() == $a->profile['uid'])) {
434                         q("UPDATE `item` SET `unseen` = 0
435                                 WHERE `parent` = %d AND `unseen` = 1",
436                                 intval($r[0]['parent'])
437                         );
438                 }
439
440                 $items = conv_sort($r,"`commented`");
441
442                 if(!$update)
443                         $o .= "<script> var netargs = '?f=&nick=" . $nick . "&item_id=" . $item_id . "'; </script>";
444                 $o .= conversation($a,$items,'display', $update);
445
446                 // Preparing the meta header
447                 require_once('include/bbcode.php');
448                 require_once("include/html2plain.php");
449                 $description = trim(html2plain(bbcode($r[0]["body"], false, false), 0, true));
450                 $title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
451                 $author_name = $r[0]["author-name"];
452
453                 $image = "";
454                 if ($image == "")
455                         $image = $r[0]["thumb"];
456
457                 if ($title == "")
458                         $title = $author_name;
459
460                 $description = htmlspecialchars($description, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
461                 $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
462                 $author_name = htmlspecialchars($author_name, ENT_COMPAT, 'UTF-8', true); // allow double encoding here
463
464                 //<meta name="keywords" content="">
465                 $a->page['htmlhead'] .= '<meta name="author" content="'.$author_name.'" />'."\n";
466                 $a->page['htmlhead'] .= '<meta name="title" content="'.$title.'" />'."\n";
467                 $a->page['htmlhead'] .= '<meta name="fulltitle" content="'.$title.'" />'."\n";
468                 $a->page['htmlhead'] .= '<meta name="description" content="'.$description.'" />'."\n";
469
470                 // Schema.org microdata
471                 $a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
472                 $a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
473                 $a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
474                 $a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
475
476                 // Twitter cards
477                 $a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
478                 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
479                 $a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
480                 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
481                 $a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
482
483                 // Dublin Core
484                 $a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
485                 $a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
486
487                 // Open Graph
488                 $a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
489                 $a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
490                 $a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
491                 $a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
492                 $a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
493                 $a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";
494                 // article:tag
495
496                 return $o;
497         }
498
499         $r = q("SELECT `id`,`deleted` FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
500                 dbesc($item_id),
501                 dbesc($item_id)
502         );
503         if($r) {
504                 if($r[0]['deleted']) {
505                         notice( t('Item has been removed.') . EOL );
506                 }
507                 else {
508                         notice( t('Permission denied.') . EOL );
509                 }
510         }
511         else {
512                 notice( t('Item not found.') . EOL );
513         }
514
515         return $o;
516 }
517