streams/Zotlabs/Module/Viewsrc.php

72 lines
1.7 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
namespace Zotlabs\Module;
2019-09-30 02:20:09 +00:00
use App;
use Zotlabs\Web\Controller;
2016-04-19 03:38:38 +00:00
2019-09-30 02:20:09 +00:00
class Viewsrc extends Controller {
2016-04-19 03:38:38 +00:00
function get() {
$o = '';
$sys = get_sys_channel();
$item_id = ((argc() > 1) ? intval(argv(1)) : 0);
$json = ((argc() > 2 && argv(2) === 'json') ? true : false);
$dload = ((argc() > 2 && argv(2) === 'download') ? true : false);
2016-04-19 03:38:38 +00:00
2019-09-30 02:20:09 +00:00
if (! local_channel()) {
2016-04-19 03:38:38 +00:00
notice( t('Permission denied.') . EOL);
}
2019-09-30 02:20:09 +00:00
if (! $item_id) {
App::$error = 404;
2016-04-19 03:38:38 +00:00
notice( t('Item not found.') . EOL);
}
$item_normal = item_normal_search();
2016-04-19 03:38:38 +00:00
2019-09-30 02:20:09 +00:00
if (local_channel() && $item_id) {
2018-06-09 14:38:15 +00:00
$r = q("select id, item_flags, mimetype, item_obscured, body, llink, plink from item where uid in (%d , %d) and id = %d $item_normal limit 1",
2016-04-19 03:38:38 +00:00
intval(local_channel()),
intval($sys['channel_id']),
intval($item_id)
);
2019-09-30 02:20:09 +00:00
if ($r) {
if (intval($r[0]['item_obscured']))
$dload = true;
2019-09-30 02:20:09 +00:00
if ($dload) {
header('Content-type: ' . $r[0]['mimetype']);
header('Content-disposition: attachment; filename="' . t('item') . '-' . $item_id . '"' );
echo $r[0]['body'];
killme();
}
$content = escape_tags($r[0]['body']);
$o = (($json) ? json_encode($content) : str_replace("\n",'<br />',$content));
2016-04-19 03:38:38 +00:00
}
}
2019-09-30 02:20:09 +00:00
$inspect = ((is_site_admin()) ? '| <a href="' . z_root() . '/inspect/item/' . $r[0]['id'] . '" target="_blank">' . t('inspect') . '</a>' : EMPTY_STR);
if (is_ajax()) {
2018-06-09 14:38:15 +00:00
echo '<div class="p-1">';
2019-09-30 02:20:09 +00:00
echo '<div>id: ' . $r[0]['id'] . ' | <a href="' . $r[0]['plink'] . '" target="_blank">plink</a> | <a href="' . $r[0]['llink'] . '" target="_blank">llink</a>' . $inspect . '</div>';
2018-06-09 14:38:15 +00:00
echo '<hr>';
echo '<pre class="p-1">' . $o . '</pre>';
echo '</div>';
2016-04-19 03:38:38 +00:00
killme();
}
return $o;
}
}