From 9092cb1beb623966f75a9871e40db8b78a048f4c Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 18 May 2019 20:02:21 +0200 Subject: [PATCH 1/4] Move mod/notice to src/Module/Notice --- mod/notice.php | 23 --------------------- src/App/Router.php | 1 + src/Model/ItemUser.php | 36 +++++++++++++++++++++++++++++++++ src/Module/GnuSocial/Notice.php | 34 +++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 23 deletions(-) delete mode 100644 mod/notice.php create mode 100644 src/Model/ItemUser.php create mode 100644 src/Module/GnuSocial/Notice.php diff --git a/mod/notice.php b/mod/notice.php deleted file mode 100644 index b0a6a54391..0000000000 --- a/mod/notice.php +++ /dev/null @@ -1,23 +0,0 @@ - friendica items permanent-url compatibility - */ - -use Friendica\App; -use Friendica\Core\L10n; -use Friendica\Database\DBA; - -function notice_init(App $a) -{ - $id = $a->argv[1]; - $r = q("SELECT `user`.`nickname` FROM `user` LEFT JOIN `item` ON `item`.`uid` = `user`.`uid` WHERE `item`.`id` = %d", intval($id)); - if (DBA::isResult($r)) { - $nick = $r[0]['nickname']; - $a->internalRedirect('display/' . $nick . '/' . $id); - } else { - throw new \Friendica\Network\HTTPException\NotFoundException(L10n::t('Item not found.')); - } - - return; -} diff --git a/src/App/Router.php b/src/App/Router.php index 133544c819..87f4d6e874 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -169,6 +169,7 @@ class Router $collector->addRoute(['GET'], '/view/{id:\d+}', Module\Notifications\Notify::class); $collector->addRoute(['GET'], '/mark/all', Module\Notifications\Notify::class); }); + $this->routeCollector->addRoute(['GET'], '/notice/{id:\d+}', Module\GnuSocial\Notice::class); $this->routeCollector->addRoute(['GET'], '/objects/{guid}', Module\Objects::class); $this->routeCollector->addGroup('/oembed', function (RouteCollector $collector) { $collector->addRoute(['GET'], '/b2h', Module\Oembed::class); diff --git a/src/Model/ItemUser.php b/src/Model/ItemUser.php new file mode 100644 index 0000000000..c157150339 --- /dev/null +++ b/src/Model/ItemUser.php @@ -0,0 +1,36 @@ + $id]); + if (empty($item)) { + return false; + } + + $user = DBA::selectFirst('user', $fields, ['uid' => $item['uid']]); + if (!empty($user)) { + return $user; + } else { + return false; + } + } +} diff --git a/src/Module/GnuSocial/Notice.php b/src/Module/GnuSocial/Notice.php new file mode 100644 index 0000000000..ce4a5c5094 --- /dev/null +++ b/src/Module/GnuSocial/Notice.php @@ -0,0 +1,34 @@ + friendica items permanent-url compatibility + */ +class Notice extends BaseModule +{ + public static function rawContent() + { + $a = self::getApp(); + + // @TODO: Replace with parameter from router + $id = ($a->argc > 1) ? $a->argv[1] : 0; + + if (empty($id)) { + throw new HTTPException\NotFoundException(L10n::t('Item not found.')); + } + + $user = ItemUser::getUserForItemId($id, ['nickname']); + + if (empty($user)) { + throw new HTTPException\NotFoundException(L10n::t('Item not found.')); + } else { + $a->internalRedirect('display/' . $user['nickname'] . '/' . $id); + } + } +} From ce3b1210640ce653ef91cbf033788474c1f88b0c Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 18 May 2019 20:04:57 +0200 Subject: [PATCH 2/4] rename rawContent() to content() --- src/Module/GnuSocial/Notice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/GnuSocial/Notice.php b/src/Module/GnuSocial/Notice.php index ce4a5c5094..a364fa79f0 100644 --- a/src/Module/GnuSocial/Notice.php +++ b/src/Module/GnuSocial/Notice.php @@ -12,7 +12,7 @@ use Friendica\Network\HTTPException; */ class Notice extends BaseModule { - public static function rawContent() + public static function content() { $a = self::getApp(); From d81c1d81b3388649ac85d65434ce75b66109e7e6 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 18 May 2019 20:37:37 +0200 Subject: [PATCH 3/4] correct notice redirect --- src/Model/ItemUser.php | 36 --------------------------------- src/Module/GnuSocial/Notice.php | 8 +++++--- 2 files changed, 5 insertions(+), 39 deletions(-) delete mode 100644 src/Model/ItemUser.php diff --git a/src/Model/ItemUser.php b/src/Model/ItemUser.php deleted file mode 100644 index c157150339..0000000000 --- a/src/Model/ItemUser.php +++ /dev/null @@ -1,36 +0,0 @@ - $id]); - if (empty($item)) { - return false; - } - - $user = DBA::selectFirst('user', $fields, ['uid' => $item['uid']]); - if (!empty($user)) { - return $user; - } else { - return false; - } - } -} diff --git a/src/Module/GnuSocial/Notice.php b/src/Module/GnuSocial/Notice.php index a364fa79f0..5df28a1f0d 100644 --- a/src/Module/GnuSocial/Notice.php +++ b/src/Module/GnuSocial/Notice.php @@ -4,6 +4,8 @@ namespace Friendica\Module\GnuSocial; use Friendica\BaseModule; use Friendica\Core\L10n; +use Friendica\Database\DBA; +use Friendica\Model\Item; use Friendica\Model\ItemUser; use Friendica\Network\HTTPException; @@ -23,12 +25,12 @@ class Notice extends BaseModule throw new HTTPException\NotFoundException(L10n::t('Item not found.')); } - $user = ItemUser::getUserForItemId($id, ['nickname']); + $item = DBA::selectFirst('item', ['guid'], ['id' => $id]); - if (empty($user)) { + if (empty($item )) { throw new HTTPException\NotFoundException(L10n::t('Item not found.')); } else { - $a->internalRedirect('display/' . $user['nickname'] . '/' . $id); + $a->internalRedirect('display/' . $item['guid']); } } } From d91b3bb59c0513965597853a97b144950d47501d Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 18 May 2019 20:38:21 +0200 Subject: [PATCH 4/4] remove unused dependencies --- src/Module/GnuSocial/Notice.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Module/GnuSocial/Notice.php b/src/Module/GnuSocial/Notice.php index 5df28a1f0d..88598ff2a4 100644 --- a/src/Module/GnuSocial/Notice.php +++ b/src/Module/GnuSocial/Notice.php @@ -5,8 +5,6 @@ namespace Friendica\Module\GnuSocial; use Friendica\BaseModule; use Friendica\Core\L10n; use Friendica\Database\DBA; -use Friendica\Model\Item; -use Friendica\Model\ItemUser; use Friendica\Network\HTTPException; /**