]> git.mxchange.org Git - friendica.git/commitdiff
Move mod/filerm to src/Module/FilerM
authorPhilipp Holzer <admin@philipp.info>
Sat, 4 May 2019 08:30:05 +0000 (10:30 +0200)
committerPhilipp Holzer <admin@philipp.info>
Sun, 5 May 2019 08:02:10 +0000 (10:02 +0200)
mod/filerm.php [deleted file]
src/App/Router.php
src/Module/Filer.php [deleted file]
src/Module/Filer/RemoveTag.php [new file with mode: 0644]
src/Module/Filer/SaveTag.php [new file with mode: 0644]

diff --git a/mod/filerm.php b/mod/filerm.php
deleted file mode 100644 (file)
index 9013dd6..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-use Friendica\App;
-use Friendica\Core\Logger;
-use Friendica\Model\FileTag;
-use Friendica\Util\XML;
-
-function filerm_content(App $a)
-{
-       if (! local_user())
-       {
-               exit();
-       }
-
-       $term = XML::unescape(trim(defaults($_GET, 'term', '')));
-       $cat = XML::unescape(trim(defaults($_GET, 'cat', '')));
-
-       $category = (($cat) ? true : false);
-
-       if ($category)
-       {
-               $term = $cat;
-       }
-
-       $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
-
-       Logger::log('filerm: tag ' . $term . ' item ' . $item_id  . ' category ' . ($category ? 'true' :  'false'));
-
-       if ($item_id && strlen($term)) {
-               if (FileTag::unsaveFile(local_user(), $item_id, $term, $category)) {
-                       info('Item removed');
-               }
-       }
-       else {
-               info('Item was not deleted');
-       }
-
-       $a->internalRedirect('/network?f=&file=' . rawurlencode($term));
-       exit();
-}
index b94c0bb58dbe47439cdb32c2cc1f8b242d51f001..48d63224ed855f51cb75b38eedae9c8521281972 100644 (file)
@@ -109,7 +109,8 @@ class Router
                        $collector->addRoute(['GET'], '/{guid}/status_message',              Module\Diaspora\Fetch::class);
                        $collector->addRoute(['GET'], '/{guid}/reshare',                     Module\Diaspora\Fetch::class);
                });
-               $this->routeCollector->addRoute(['GET'],         '/filer[/{id:\d+}]',    Module\Filer::class);
+               $this->routeCollector->addRoute(['GET'],         '/filer[/{id:\d+}]',    Module\Filer\SaveTag::class);
+               $this->routeCollector->addRoute(['GET'],         '/filerm/{id:\d+}',     Module\Filer\RemoveTag::class);
                $this->routeCollector->addRoute(['GET'],         '/followers/{owner}',   Module\Followers::class);
                $this->routeCollector->addRoute(['GET'],         '/following/{owner}',   Module\Following::class);
                $this->routeCollector->addGroup('/group', function (RouteCollector $collector) {
diff --git a/src/Module/Filer.php b/src/Module/Filer.php
deleted file mode 100644 (file)
index da59084..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-
-namespace Friendica\Module;
-
-use Friendica\BaseModule;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
-use Friendica\Core\Renderer;
-use Friendica\Model;
-use Friendica\Util\XML;
-
-/**
- * Shows a dialog for adding tags to a file
- */
-class Filer extends BaseModule
-{
-       public static function init()
-       {
-               if (!local_user()) {
-                       info(L10n::t('You must be logged in to use this module'));
-                       self::getApp()->internalRedirect();
-               }
-       }
-
-       public static function rawContent()
-       {
-               $a = self::getApp();
-               $logger = $a->getLogger();
-
-               $term = XML::unescape(trim(defaults($_GET, 'term', '')));
-               // @TODO: Replace with parameter from router
-               $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
-
-               $logger->info('filer', ['tag' => $term, 'item' => $item_id]);
-
-               if ($item_id && strlen($term)) {
-                       // file item
-                       Model\FileTag::saveFile(local_user(), $item_id, $term);
-                       info(L10n::t('Filetag %s saved to item', $term));
-               }
-
-               // return filer dialog
-               $filetags = PConfig::get(local_user(), 'system', 'filetags');
-               $filetags = Model\FileTag::fileToList($filetags, 'file');
-               $filetags = explode(",", $filetags);
-
-               $tpl = Renderer::getMarkupTemplate("filer_dialog.tpl");
-               echo Renderer::replaceMacros($tpl, [
-                       '$field' => ['term', L10n::t("Save to Folder:"), '', '', $filetags, L10n::t('- select -')],
-                       '$submit' => L10n::t('Save'),
-               ]);
-
-               exit;
-       }
-}
diff --git a/src/Module/Filer/RemoveTag.php b/src/Module/Filer/RemoveTag.php
new file mode 100644 (file)
index 0000000..bddaaf9
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+namespace Friendica\Module\Filer;
+
+use Friendica\BaseModule;
+use Friendica\Model\FileTag;
+use Friendica\Network\HTTPException;
+use Friendica\Util\XML;
+
+/**
+ * Remove a tag from a file
+ */
+class RemoveTag extends BaseModule
+{
+       public static function content()
+       {
+               if (!local_user()) {
+                       throw new HTTPException\ForbiddenException();
+               }
+
+               $app = self::getApp();
+               $logger = $app->getLogger();
+
+               $item_id = (($app->argc > 1) ? intval($app->argv[1]) : 0);
+
+               $term = XML::unescape(trim(defaults($_GET, 'term', '')));
+               $cat = XML::unescape(trim(defaults($_GET, 'cat', '')));
+
+               $category = (($cat) ? true : false);
+
+               if ($category) {
+                       $term = $cat;
+               }
+
+               $logger->info('Filer - Remove Tag', [
+                       'term'     => $term,
+                       'item'     => $item_id,
+                       'category' => ($category ? 'true' : 'false')
+               ]);
+
+               if ($item_id && strlen($term)) {
+                       if (FileTag::unsaveFile(local_user(), $item_id, $term, $category)) {
+                               info('Item removed');
+                       }
+               } else {
+                       info('Item was not deleted');
+               }
+
+               $app->internalRedirect('/network?f=&file=' . rawurlencode($term));
+       }
+}
diff --git a/src/Module/Filer/SaveTag.php b/src/Module/Filer/SaveTag.php
new file mode 100644 (file)
index 0000000..f5d6115
--- /dev/null
@@ -0,0 +1,55 @@
+<?php
+
+namespace Friendica\Module\Filer;
+
+use Friendica\BaseModule;
+use Friendica\Core\L10n;
+use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
+use Friendica\Model;
+use Friendica\Util\XML;
+
+/**
+ * Shows a dialog for adding tags to a file
+ */
+class SaveTag extends BaseModule
+{
+       public static function init()
+       {
+               if (!local_user()) {
+                       info(L10n::t('You must be logged in to use this module'));
+                       self::getApp()->internalRedirect();
+               }
+       }
+
+       public static function rawContent()
+       {
+               $a = self::getApp();
+               $logger = $a->getLogger();
+
+               $term = XML::unescape(trim(defaults($_GET, 'term', '')));
+               // @TODO: Replace with parameter from router
+               $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
+
+               $logger->info('filer', ['tag' => $term, 'item' => $item_id]);
+
+               if ($item_id && strlen($term)) {
+                       // file item
+                       Model\FileTag::saveFile(local_user(), $item_id, $term);
+                       info(L10n::t('Filetag %s saved to item', $term));
+               }
+
+               // return filer dialog
+               $filetags = PConfig::get(local_user(), 'system', 'filetags');
+               $filetags = Model\FileTag::fileToList($filetags, 'file');
+               $filetags = explode(",", $filetags);
+
+               $tpl = Renderer::getMarkupTemplate("filer_dialog.tpl");
+               echo Renderer::replaceMacros($tpl, [
+                       '$field' => ['term', L10n::t("Save to Folder:"), '', '', $filetags, L10n::t('- select -')],
+                       '$submit' => L10n::t('Save'),
+               ]);
+
+               exit;
+       }
+}