]> git.mxchange.org Git - friendica.git/commitdiff
Move mod/notice to src/Module/Notice
authorPhilipp Holzer <admin+github@philipp.info>
Sat, 18 May 2019 18:02:21 +0000 (20:02 +0200)
committerPhilipp Holzer <admin+github@philipp.info>
Sun, 19 May 2019 00:53:31 +0000 (02:53 +0200)
mod/notice.php [deleted file]
src/App/Router.php
src/Model/ItemUser.php [new file with mode: 0644]
src/Module/GnuSocial/Notice.php [new file with mode: 0644]

diff --git a/mod/notice.php b/mod/notice.php
deleted file mode 100644 (file)
index b0a6a54..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-/**
- * @file mod/notice.php
- * GNU Social -> 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;
-}
index 133544c819c233ac558dedaa7884bf541eefbd4f..87f4d6e8743d85a834e4dc60bbefabd2ae816677 100644 (file)
@@ -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 (file)
index 0000000..c157150
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+namespace Friendica\Model;
+
+use Exception;
+use Friendica\Database\DBA;
+
+/**
+ * Model for user specific operations of items
+ */
+class ItemUser
+{
+       /**
+        * Returns fields of the user for an item
+        *
+        * @param int   $id     The item id
+        * @param array $fields The fields, which should get returned
+        *
+        * @return array|bool
+        * @throws Exception In case of a DB-failure
+        */
+       public static function getUserForItemId($id, array $fields = [])
+       {
+               $item = DBA::selectFirst('item', ['uid'], ['id' => $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 (file)
index 0000000..ce4a5c5
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+namespace Friendica\Module\GnuSocial;
+
+use Friendica\BaseModule;
+use Friendica\Core\L10n;
+use Friendica\Model\ItemUser;
+use Friendica\Network\HTTPException;
+
+/**
+ * GNU Social -> 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);
+               }
+       }
+}