2019-05-05 19:15:33 +02:00
|
|
|
<?php
|
2024-08-24 15:27:00 +02:00
|
|
|
|
|
|
|
// Copyright (C) 2010-2024, the Friendica project
|
|
|
|
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-05-05 19:15:33 +02:00
|
|
|
|
2019-05-19 03:02:58 +02:00
|
|
|
namespace Friendica\Module\Debug;
|
2019-05-05 19:15:33 +02:00
|
|
|
|
|
|
|
use Friendica\BaseModule;
|
2022-05-18 02:13:54 +00:00
|
|
|
use Friendica\Core\System;
|
2019-12-15 22:34:11 +01:00
|
|
|
use Friendica\DI;
|
2021-01-16 04:16:09 +00:00
|
|
|
use Friendica\Model\Post;
|
2024-11-04 13:36:57 +01:00
|
|
|
use Friendica\Network\HTTPException\NotFoundException;
|
|
|
|
use Friendica\Network\HTTPException\UnauthorizedException;
|
2019-05-05 19:15:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Print the body of an Item
|
|
|
|
*/
|
|
|
|
class ItemBody extends BaseModule
|
|
|
|
{
|
2024-11-04 13:36:57 +01:00
|
|
|
/**
|
|
|
|
* @throws NotFoundException|UnauthorizedException
|
|
|
|
*
|
|
|
|
* @return string|never
|
|
|
|
*/
|
2021-11-20 15:38:03 +01:00
|
|
|
protected function content(array $request = []): string
|
2019-05-05 19:15:33 +02:00
|
|
|
{
|
2022-10-20 22:59:12 +02:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2024-11-04 13:36:57 +01:00
|
|
|
throw new UnauthorizedException(DI::l10n()->t('Access denied.'));
|
2019-05-05 19:15:33 +02:00
|
|
|
}
|
|
|
|
|
2021-11-14 23:19:25 +01:00
|
|
|
if (empty($this->parameters['item'])) {
|
2024-11-04 13:36:57 +01:00
|
|
|
throw new NotFoundException(DI::l10n()->t('Item not found.'));
|
2019-05-05 19:15:33 +02:00
|
|
|
}
|
|
|
|
|
2021-11-14 23:19:25 +01:00
|
|
|
$itemId = intval($this->parameters['item']);
|
2021-07-25 15:23:37 +00:00
|
|
|
|
2022-10-20 22:59:12 +02:00
|
|
|
$item = Post::selectFirst(['body'], ['uid' => [0, DI::userSession()->getLocalUserId()], 'uri-id' => $itemId]);
|
2019-05-05 19:15:33 +02:00
|
|
|
|
2024-11-04 13:36:57 +01:00
|
|
|
if (empty($item)) {
|
|
|
|
throw new NotFoundException(DI::l10n()->t('Item not found.'));
|
2019-05-05 19:15:33 +02:00
|
|
|
}
|
2024-11-04 13:36:57 +01:00
|
|
|
|
|
|
|
// TODO: Extract this code into controller
|
|
|
|
if (DI::mode()->isAjax()) {
|
|
|
|
echo str_replace("\n", '<br />', $item['body']);
|
|
|
|
System::exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
return str_replace("\n", '<br />', $item['body']);
|
2019-05-05 19:15:33 +02:00
|
|
|
}
|
|
|
|
}
|