Move mod/viewsrc to src/Module/ItemBody

This commit is contained in:
Philipp Holzer 2019-05-05 19:15:33 +02:00
parent 155d541860
commit 49a3179578
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
3 changed files with 44 additions and 35 deletions

View file

@ -1,35 +0,0 @@
<?php
/**
* @file mod/viewsrc.php
*/
use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Database\DBA;
use Friendica\Model\Item;
function viewsrc_content(App $a)
{
if (!local_user()) {
notice(L10n::t('Access denied.') . EOL);
return;
}
$o = '';
$item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
if (!$item_id) {
throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Item not found.'));
}
$item = Item::selectFirst(['body'], ['uid' => local_user(), 'id' => $item_id]);
if (DBA::isResult($item)) {
if ($a->isAjax()) {
echo str_replace("\n", '<br />', $item['body']);
exit();
} else {
$o .= str_replace("\n", '<br />', $item['body']);
}
}
return $o;
}

View file

@ -167,6 +167,7 @@ class Router
$this->routeCollector->addRoute(['GET'], '/rsd.xml', Module\ReallySimpleDiscovery::class);
$this->routeCollector->addRoute(['GET'], '/statistics.json', Module\Statistics::class);
$this->routeCollector->addRoute(['GET'], '/tos', Module\Tos::class);
$this->routeCollector->addRoute(['GET'], '/viewsrc/{item:\d+}', Module\ItemBody::class);
$this->routeCollector->addRoute(['GET'], '/webfinger', Module\WebFinger::class);
$this->routeCollector->addRoute(['GET'], '/xrd', Module\Xrd::class);
}

43
src/Module/ItemBody.php Normal file
View file

@ -0,0 +1,43 @@
<?php
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Model\Item;
use Friendica\Network\HTTPException;
/**
* Print the body of an Item
*/
class ItemBody extends BaseModule
{
public static function content()
{
if (!local_user()) {
throw new HTTPException\UnauthorizedException(L10n::t('Access denied.'));
}
$app = self::getApp();
// @TODO: Replace with parameter from router
$itemId = (($app->argc > 1) ? intval($app->argv[1]) : 0);
if (!$itemId) {
throw new HTTPException\NotFoundException(L10n::t('Item not found.'));
}
$item = Item::selectFirst(['body'], ['uid' => local_user(), 'id' => $itemId]);
if (!empty($item)) {
if ($app->isAjax()) {
echo str_replace("\n", '<br />', $item['body']);
exit();
} else {
return str_replace("\n", '<br />', $item['body']);
}
} else {
throw new HTTPException\NotFoundException(L10n::t('Item not found.'));
}
}
}