]> git.mxchange.org Git - friendica.git/commitdiff
Move admin/deleteitem to src/Module/Admin
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 26 Apr 2019 03:47:49 +0000 (23:47 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 2 May 2019 13:52:52 +0000 (09:52 -0400)
mod/admin.php
src/App/Router.php
src/Module/Admin/Item/Delete.php [new file with mode: 0644]
src/Module/BaseAdminModule.php
view/templates/admin/deleteitem.tpl [deleted file]
view/templates/admin/item/delete.tpl [new file with mode: 0644]

index 1632f7c0aa1327f7175c51af9d22198c3f0f1332..d1096a68b75e03c8acf70c34f1b375f6dc3afd19 100644 (file)
@@ -65,13 +65,6 @@ function admin_post(App $a)
        }
 
        $return_path = 'admin';
-       if ($a->argc > 1) {
-               switch ($a->argv[1]) {
-                       case 'deleteitem':
-                               admin_page_deleteitem_post($a);
-                               break;
-               }
-       }
 
        $a->internalRedirect($return_path);
        return; // NOTREACHED
@@ -166,9 +159,6 @@ function admin_content(App $a)
        // urls
        if ($a->argc > 1) {
                switch ($a->argv[1]) {
-                       case 'deleteitem':
-                               $o = admin_page_deleteitem($a);
-                               break;
                        default:
                                notice(L10n::t("Item not found."));
                }
@@ -182,67 +172,6 @@ function admin_content(App $a)
        }
 }
 
-/**
- * @brief Subpage where the admin can delete an item from their node given the GUID
- *
- * This subpage of the admin panel offers the nodes admin to delete an item from
- * the node, given the GUID or the display URL such as http://example.com/display/123456.
- * The item will then be marked as deleted in the database and processed accordingly.
- *
- * @param App $a
- * @return string
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
-function admin_page_deleteitem(App $a)
-{
-       $t = Renderer::getMarkupTemplate('admin/deleteitem.tpl');
-
-       return Renderer::replaceMacros($t, [
-               '$title' => L10n::t('Administration'),
-               '$page' => L10n::t('Delete Item'),
-               '$submit' => L10n::t('Delete this Item'),
-               '$intro1' => L10n::t('On this page you can delete an item from your node. If the item is a top level posting, the entire thread will be deleted.'),
-               '$intro2' => L10n::t('You need to know the GUID of the item. You can find it e.g. by looking at the display URL. The last part of http://example.com/display/123456 is the GUID, here 123456.'),
-               '$deleteitemguid' => ['deleteitemguid', L10n::t("GUID"), '', L10n::t("The GUID of the item you want to delete."), 'required', 'autofocus'],
-               '$baseurl' => System::baseUrl(),
-               '$form_security_token' => BaseModule::getFormSecurityToken("admin_deleteitem")
-       ]);
-}
-
-/**
- * @brief Process send data from Admin Delete Item Page
- *
- * The GUID passed through the form should be only the GUID. But we also parse
- * URLs like the full /display URL to make the process more easy for the admin.
- *
- * @param App $a
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
-function admin_page_deleteitem_post(App $a)
-{
-       if (empty($_POST['page_deleteitem_submit'])) {
-               return;
-       }
-
-       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/deleteitem/', 'admin_deleteitem');
-
-       if (!empty($_POST['page_deleteitem_submit'])) {
-               $guid = trim(Strings::escapeTags($_POST['deleteitemguid']));
-               // The GUID should not include a "/", so if there is one, we got an URL
-               // and the last part of it is most likely the GUID.
-               if (strpos($guid, '/')) {
-                       $guid = substr($guid, strrpos($guid, '/') + 1);
-               }
-               // Now that we have the GUID, drop those items, which will also delete the
-               // associated threads.
-               Item::delete(['guid' => $guid]);
-       }
-
-       info(L10n::t('Item marked for deletion.') . EOL);
-       $a->internalRedirect('admin/deleteitem');
-       return; // NOTREACHED
-}
-
 function admin_page_server_vital()
 {
        // Fetch the host-meta to check if this really is a vital server
index 6352a18130d43bf74fa37a72fa1e8ebb761f862c..c70c0c480c4d53bfb48f523e181aef5e9650cb8b 100644 (file)
@@ -134,6 +134,8 @@ class Router
                        $collector->addRoute(['GET', 'POST'], '/features'               , Module\Admin\Features::class);
                        $collector->addRoute(['GET']        , '/federation'             , Module\Admin\Federation::class);
 
+                       $collector->addRoute(['GET', 'POST'], '/item/delete'            , Module\Admin\Item\Delete::class);
+
                        $collector->addRoute(['GET']        , '/logs/view'              , Module\Admin\Logs\View::class);
                        $collector->addRoute(['GET', 'POST'], '/logs'                   , Module\Admin\Logs\Settings::class);
 
diff --git a/src/Module/Admin/Item/Delete.php b/src/Module/Admin/Item/Delete.php
new file mode 100644 (file)
index 0000000..94bab4e
--- /dev/null
@@ -0,0 +1,57 @@
+<?php\r
+\r
+namespace Friendica\Module\Admin\Item;\r
+\r
+use Friendica\Core\L10n;\r
+use Friendica\Core\Renderer;\r
+use Friendica\Core\System;\r
+use Friendica\Model\Item;\r
+use Friendica\Module\BaseAdminModule;\r
+use Friendica\Util\Strings;\r
+\r
+class Delete extends BaseAdminModule\r
+{\r
+       public static function post()\r
+       {\r
+               parent::post();\r
+\r
+               if (empty($_POST['page_deleteitem_submit'])) {\r
+                       return;\r
+               }\r
+\r
+               parent::checkFormSecurityTokenRedirectOnError('/admin/item/delete', 'admin_deleteitem');\r
+\r
+               if (!empty($_POST['page_deleteitem_submit'])) {\r
+                       $guid = trim(Strings::escapeTags($_POST['deleteitemguid']));\r
+                       // The GUID should not include a "/", so if there is one, we got an URL\r
+                       // and the last part of it is most likely the GUID.\r
+                       if (strpos($guid, '/')) {\r
+                               $guid = substr($guid, strrpos($guid, '/') + 1);\r
+                       }\r
+                       // Now that we have the GUID, drop those items, which will also delete the\r
+                       // associated threads.\r
+                       Item::delete(['guid' => $guid]);\r
+               }\r
+\r
+               info(L10n::t('Item marked for deletion.') . EOL);\r
+               self::getApp()->internalRedirect('admin/item/delete');\r
+       }\r
+\r
+       public static function content()\r
+       {\r
+               parent::content();\r
+\r
+               $t = Renderer::getMarkupTemplate('admin/item/delete.tpl');\r
+\r
+               return Renderer::replaceMacros($t, [\r
+                       '$title' => L10n::t('Administration'),\r
+                       '$page' => L10n::t('Delete Item'),\r
+                       '$submit' => L10n::t('Delete this Item'),\r
+                       '$intro1' => L10n::t('On this page you can delete an item from your node. If the item is a top level posting, the entire thread will be deleted.'),\r
+                       '$intro2' => L10n::t('You need to know the GUID of the item. You can find it e.g. by looking at the display URL. The last part of http://example.com/display/123456 is the GUID, here 123456.'),\r
+                       '$deleteitemguid' => ['deleteitemguid', L10n::t("GUID"), '', L10n::t("The GUID of the item you want to delete."), 'required', 'autofocus'],\r
+                       '$baseurl' => System::baseUrl(),\r
+                       '$form_security_token' => parent::getFormSecurityToken("admin_deleteitem")\r
+               ]);\r
+       }\r
+}
\ No newline at end of file
index 7ad36e8cc304a2b76872f8e3162d6dfc29c3bc4d..93f60172d23555a8851143a8efe1b0b0bb185815 100644 (file)
@@ -68,6 +68,7 @@ abstract class BaseAdminModule extends BaseModule
                        'tools' => [L10n::t('Tools'), [\r
                                'contactblock' => ['admin/blocklist/contact', L10n::t('Contact Blocklist')  , 'contactblock'],\r
                                'blocklist'    => ['admin/blocklist/server' , L10n::t('Server Blocklist')   , 'blocklist'],\r
+                               'deleteitem'   => ['admin/item/delete' , L10n::t('Delete Item')             , 'deleteitem'],\r
                        ]],\r
                        'logs' => [L10n::t('Logs'), [\r
                                'logsconfig'   => ['admin/logs/', L10n::t('Logs')                   , 'logs'],\r
diff --git a/view/templates/admin/deleteitem.tpl b/view/templates/admin/deleteitem.tpl
deleted file mode 100644 (file)
index f5abc96..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<div id="adminpage">
-       <h1>{{$title}} - {{$page}}</h1>
-       <p>{{$intro1}}</p>
-       <p>{{$intro2}}</p>
-
-       <form action="{{$baseurl}}/admin/deleteitem" method="post">
-               <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
-               {{include file="field_input.tpl" field=$deleteitemguid}}
-               <div class="submit"><input type="submit" name="page_deleteitem_submit" value="{{$submit}}" /></div>
-       </form>
-
-</div>
diff --git a/view/templates/admin/item/delete.tpl b/view/templates/admin/item/delete.tpl
new file mode 100644 (file)
index 0000000..497b776
--- /dev/null
@@ -0,0 +1,12 @@
+<div id="adminpage">
+       <h1>{{$title}} - {{$page}}</h1>
+       <p>{{$intro1}}</p>
+       <p>{{$intro2}}</p>
+
+       <form action="{{$baseurl}}/admin/item/delete" method="post">
+               <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
+               {{include file="field_input.tpl" field=$deleteitemguid}}
+               <div class="submit"><input type="submit" name="page_deleteitem_submit" value="{{$submit}}" /></div>
+       </form>
+
+</div>