Merge pull request #7101 from nupplaphil/task/mod_viewsrc

Move mod/viewsrc to src/Module/ItemBody
This commit is contained in:
Hypolite Petovan 2019-05-05 20:32:42 -04:00 committed by GitHub
commit 1e6affada1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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

@ -170,6 +170,7 @@ class Router
$this->routeCollector->addRoute(['GET'], '/rsd.xml', Module\ReallySimpleDiscovery::class); $this->routeCollector->addRoute(['GET'], '/rsd.xml', Module\ReallySimpleDiscovery::class);
$this->routeCollector->addRoute(['GET'], '/statistics.json', Module\Statistics::class); $this->routeCollector->addRoute(['GET'], '/statistics.json', Module\Statistics::class);
$this->routeCollector->addRoute(['GET'], '/tos', Module\Tos::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'], '/webfinger', Module\WebFinger::class);
$this->routeCollector->addRoute(['GET'], '/xrd', Module\Xrd::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.'));
}
}
}