streams/mod/viewsrc.php

47 lines
1,011 B
PHP
Raw Normal View History

<?php
function viewsrc_content(&$a) {
$o = '';
2014-09-23 04:37:19 +00:00
$sys = get_sys_channel();
$item_id = ((argc() > 1) ? intval(argv(1)) : 0);
$json = ((argc() > 2 && argv(2) === 'json') ? true : false);
2015-01-29 04:56:04 +00:00
if(! local_channel()) {
notice( t('Permission denied.') . EOL);
}
if(! $item_id) {
$a->error = 404;
notice( t('Item not found.') . EOL);
}
2015-01-29 04:56:04 +00:00
if(local_channel() && $item_id) {
2015-01-23 02:41:10 +00:00
$r = q("select id, item_flags, item_obscured, body from item where item_restrict = 0 and uid in (%d , %d) and id = %d limit 1",
2015-01-29 04:56:04 +00:00
intval(local_channel()),
2014-09-23 04:37:19 +00:00
intval($sys['channel_id']),
intval($item_id)
);
2014-08-24 04:12:33 +00:00
if($r) {
2015-01-23 02:41:10 +00:00
if(intval($r[0]['item_obscured']))
2014-08-24 04:12:33 +00:00
$r[0]['body'] = crypto_unencapsulate(json_decode($r[0]['body'],true),get_config('system','prvkey'));
$o = (($json) ? json_encode($r[0]['body']) : str_replace("\n",'<br />',$r[0]['body']));
2014-08-24 04:12:33 +00:00
}
2012-08-31 01:17:38 +00:00
}
if(is_ajax()) {
print '<div><i class="icon-pencil"> ' . t('Source of Item') . ' ' . $r[0]['id'] . '</i></div>';
echo $o;
killme();
}
return $o;
}