From 49a31795782550597411723756d32cd69cc19b86 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 5 May 2019 19:15:33 +0200 Subject: [PATCH] Move mod/viewsrc to src/Module/ItemBody --- mod/viewsrc.php | 35 --------------------------------- src/App/Router.php | 1 + src/Module/ItemBody.php | 43 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 35 deletions(-) delete mode 100644 mod/viewsrc.php create mode 100644 src/Module/ItemBody.php diff --git a/mod/viewsrc.php b/mod/viewsrc.php deleted file mode 100644 index 55eb0b990c..0000000000 --- a/mod/viewsrc.php +++ /dev/null @@ -1,35 +0,0 @@ -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", '
', $item['body']); - exit(); - } else { - $o .= str_replace("\n", '
', $item['body']); - } - } - return $o; -} diff --git a/src/App/Router.php b/src/App/Router.php index 1dffb6b406..f1d5c09d74 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -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); } diff --git a/src/Module/ItemBody.php b/src/Module/ItemBody.php new file mode 100644 index 0000000000..ee50b52b28 --- /dev/null +++ b/src/Module/ItemBody.php @@ -0,0 +1,43 @@ +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", '
', $item['body']); + exit(); + } else { + return str_replace("\n", '
', $item['body']); + } + } else { + throw new HTTPException\NotFoundException(L10n::t('Item not found.')); + } + } +} -- 2.39.5