streams/Code/Module/Inspect.php

93 lines
2.5 KiB
PHP
Raw Normal View History

2019-04-29 04:17:04 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2019-04-29 04:17:04 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\Activity;
use Code\Lib\Channel;
2019-04-29 04:17:04 +00:00
2021-12-02 23:02:31 +00:00
class Inspect extends Controller
{
public function get()
{
$output = EMPTY_STR;
if (!is_site_admin()) {
notice(t('Permission denied.') . EOL);
return $output;
}
2022-01-25 01:26:12 +00:00
$sys = Channel::get_system();
2021-12-02 23:02:31 +00:00
if (argc() > 2) {
$item_type = argv(1);
$item_id = argv(2);
} elseif (argc() > 1) {
$item_type = 'item';
$item_id = argv(1);
}
if (!$item_id) {
App::$error = 404;
notice(t('Item not found.') . EOL);
}
if ($item_type === 'item') {
2021-12-03 03:01:39 +00:00
$r = q(
"select * from item where uuid = '%s' or id = %d ",
2021-12-02 23:02:31 +00:00
dbesc($item_id),
intval($item_id)
);
if ($r) {
xchan_query($r);
$items = fetch_post_tags($r, true);
}
if (!$items) {
return $output;
}
foreach ($items as $item) {
if ($item['obj']) {
$item['obj'] = json_decode($item['obj'], true);
}
if ($item['target']) {
$item['target'] = json_decode($item['target'], true);
}
if ($item['attach']) {
$item['attach'] = json_decode($item['attach'], true);
}
$output .= '<pre>' . print_array($item) . '</pre>' . EOL . EOL;
$output .= '<pre>' . escape_tags(json_encode(Activity::encode_activity($item, true), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) . '</pre>' . EOL . EOL;
$output .= '<pre>' . escape_tags(json_encode(json_decode(get_iconfig($item['id'], 'activitypub', 'rawmsg'), true), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) . '</pre>' . EOL . EOL;
}
}
if ($item_type === 'xchan') {
2021-12-03 03:01:39 +00:00
$items = q(
2022-06-17 02:46:54 +00:00
"select * from xchan left join hubloc on xchan_hash = hubloc_hash where (hubloc_hash = '%s' or hubloc_addr = '%s') and hubloc_deleted = 0 ",
2021-12-02 23:02:31 +00:00
dbesc($item_id),
dbesc($item_id)
);
if (!$items) {
return $output;
}
foreach ($items as $item) {
$output .= '<pre>' . print_array($item) . '</pre>' . EOL . EOL;
}
}
return $output;
}
2019-04-29 04:17:04 +00:00
}