streams/Code/Module/Viewsrc.php

74 lines
2.2 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2016-04-19 03:38:38 +00:00
2019-09-30 02:20:09 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\Channel;
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
class Viewsrc extends Controller
{
public function get()
{
$o = '';
2022-01-25 01:26:12 +00:00
$sys = Channel::get_system();
2021-12-02 23:02:31 +00:00
$item_id = ((argc() > 1) ? intval(argv(1)) : 0);
$json = ((argc() > 2 && argv(2) === 'json') ? true : false);
$dload = ((argc() > 2 && argv(2) === 'download') ? true : false);
if (!local_channel()) {
notice(t('Permission denied.') . EOL);
}
if (!$item_id) {
App::$error = 404;
notice(t('Item not found.') . EOL);
}
$item_normal = item_normal_search();
if (local_channel() && $item_id) {
2021-12-03 03:01:39 +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",
2021-12-02 23:02:31 +00:00
intval(local_channel()),
intval($sys['channel_id']),
intval($item_id)
);
if ($r) {
2021-12-03 03:01:39 +00:00
if (intval($r[0]['item_obscured'])) {
2021-12-02 23:02:31 +00:00
$dload = true;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +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));
}
}
$inspect = ((is_site_admin()) ? '| <a href="' . z_root() . '/inspect/item/' . $r[0]['id'] . '" target="_blank">' . t('Inspect') . '</a>' : EMPTY_STR);
2021-12-02 23:02:31 +00:00
if (is_ajax()) {
echo '<div class="p-1">';
echo '<div>' . t('Local id:') . ' ' . $r[0]['id'] . ' | <a href="' . $r[0]['plink'] . '" target="_blank">' . t('Permanent link') . '</a> | <a href="' . $r[0]['llink'] . '" target="_blank">' . t('Local link') . '</a>' . $inspect . '</div>';
2021-12-02 23:02:31 +00:00
echo '<hr>';
echo '<pre class="p-1">' . $o . '</pre>';
echo '</div>';
killme();
}
return $o;
}
2016-04-19 03:38:38 +00:00
}