mirror of
https://github.com/friendica/friendica
synced 2025-04-26 03:10:13 +00:00
Merge pull request #7101 from nupplaphil/task/mod_viewsrc
Move mod/viewsrc to src/Module/ItemBody
This commit is contained in:
commit
1e6affada1
3 changed files with 44 additions and 35 deletions
|
@ -170,6 +170,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
43
src/Module/ItemBody.php
Normal 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.'));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue