]> git.mxchange.org Git - friendica.git/commitdiff
Move admin/addons/{addon} to src/Module
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 21 Apr 2019 19:47:25 +0000 (15:47 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 2 May 2019 13:52:44 +0000 (09:52 -0400)
- Add Module\Admin\Addons\Details class
- Add route for admin/addons/{addon}
- Remove addons pages from mod/admin

mod/admin.php
src/App/Router.php
src/Module/Admin/Addons/Details.php [new file with mode: 0644]
view/templates/admin/addons/details.tpl [new file with mode: 0644]

index b3933a16bf32d076cdbdb4e0f12ff07d374912e3..22fd5adf3e0479832a420281b0ae3daa7cc53583 100644 (file)
@@ -10,7 +10,6 @@ use Friendica\BaseModule;
 use Friendica\Content\Feature;
 use Friendica\Content\Pager;
 use Friendica\Content\Text\Markdown;
-use Friendica\Core\Addon;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
 use Friendica\Core\Logger;
@@ -91,17 +90,6 @@ function admin_post(App $a)
                        case 'users':
                                admin_page_users_post($a);
                                break;
-                       case 'addons':
-                               if ($a->argc > 2 &&
-                                       is_file("addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php")) {
-                                       include_once "addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php";
-                                       if (function_exists($a->argv[2] . '_addon_admin_post')) {
-                                               $func = $a->argv[2] . '_addon_admin_post';
-                                               $func($a);
-                                       }
-                               }
-                               $return_path = 'admin/addons/' . $a->argv[2];
-                               break;
                        case 'themes':
                                if ($a->argc < 2) {
                                        if ($a->isAjax()) {
@@ -220,17 +208,7 @@ function admin_content(App $a)
                ]]
        ];
 
-       /* get addons admin page */
-
-       $r = q("SELECT `name` FROM `addon` WHERE `plugin_admin` = 1 ORDER BY `name`");
        $aside_tools['addons_admin'] = [];
-       $addons_admin = [];
-       foreach ($r as $h) {
-               $addon = $h['name'];
-               $aside_tools['addons_admin'][] = ["admin/addons/" . $addon, $addon, "addon"];
-               // temp addons with admin
-               $addons_admin[] = $addon;
-       }
 
        $t = Renderer::getMarkupTemplate('admin/aside.tpl');
        $a->page['aside'] .= Renderer::replaceMacros($t, [
@@ -253,9 +231,6 @@ function admin_content(App $a)
                        case 'users':
                                $o = admin_page_users($a);
                                break;
-                       case 'addons':
-                               $o = admin_page_addons($a, $addons_admin);
-                               break;
                        case 'themes':
                                $o = admin_page_themes($a);
                                break;
@@ -1668,102 +1643,6 @@ function admin_page_users(App $a)
        return $o;
 }
 
-/**
- * @brief Addons admin page
- *
- * This function generates the admin panel page for managing addons on the
- * friendica node. If an addon name is given a single page showing the details
- * for this addon is generated. If no name is given, a list of available
- * addons is shown.
- *
- * The template used for displaying the list of addons and the details of the
- * addon are the same as used for the templates.
- *
- * The returned string returned hulds the HTML code of the page.
- *
- * @param App   $a
- * @param array $addons_admin A list of admin addon names
- * @return string
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
-function admin_page_addons(App $a, array $addons_admin)
-{
-       /*
-        * Single addon
-        */
-       if ($a->argc == 3) {
-               $addon = $a->argv[2];
-               if (!is_file("addon/$addon/$addon.php")) {
-                       notice(L10n::t("Item not found."));
-                       return '';
-               }
-
-               if (defaults($_GET, 'a', '') == "t") {
-                       BaseModule::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_themes', 't');
-
-                       // Toggle addon status
-                       if (Addon::isEnabled($addon)) {
-                               Addon::uninstall($addon);
-                               info(L10n::t("Addon %s disabled.", $addon));
-                       } else {
-                               Addon::install($addon);
-                               info(L10n::t("Addon %s enabled.", $addon));
-                       }
-
-                       Addon::saveEnabledList();
-                       $a->internalRedirect('admin/addons');
-                       return ''; // NOTREACHED
-               }
-
-               // display addon details
-               if (Addon::isEnabled($addon)) {
-                       $status = "on";
-                       $action = L10n::t("Disable");
-               } else {
-                       $status = "off";
-                       $action = L10n::t("Enable");
-               }
-
-               $readme = null;
-               if (is_file("addon/$addon/README.md")) {
-                       $readme = Markdown::convert(file_get_contents("addon/$addon/README.md"), false);
-               } elseif (is_file("addon/$addon/README")) {
-                       $readme = "<pre>" . file_get_contents("addon/$addon/README") . "</pre>";
-               }
-
-               $admin_form = "";
-               if (in_array($addon, $addons_admin)) {
-                       require_once "addon/$addon/$addon.php";
-                       $func = $addon . '_addon_admin';
-                       $func($a, $admin_form);
-               }
-
-               $t = Renderer::getMarkupTemplate('admin/addon_details.tpl');
-
-               return Renderer::replaceMacros($t, [
-                       '$title' => L10n::t('Administration'),
-                       '$page' => L10n::t('Addons'),
-                       '$toggle' => L10n::t('Toggle'),
-                       '$settings' => L10n::t('Settings'),
-                       '$baseurl' => $a->getBaseURL(true),
-
-                       '$addon' => $addon,
-                       '$status' => $status,
-                       '$action' => $action,
-                       '$info' => Addon::getInfo($addon),
-                       '$str_author' => L10n::t('Author: '),
-                       '$str_maintainer' => L10n::t('Maintainer: '),
-
-                       '$admin_form' => $admin_form,
-                       '$function' => 'addons',
-                       '$screenshot' => '',
-                       '$readme' => $readme,
-
-                       '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"),
-               ]);
-       }
-}
-
 /**
  * @param array  $themes
  * @param string $th
index eacf95db354b3ee62c381de3b5c0435bb0491537..6c152eb8a0d93168a49698a0d1d305bf3d0ae45b 100644 (file)
@@ -122,6 +122,8 @@ class Router
                        $collector->addRoute(['GET']        , '[/]'                     , Module\Admin\Summary::class);
 
                        $collector->addRoute(['GET', 'POST'], '/addons'                 , Module\Admin\Addons\Index::class);
+                       $collector->addRoute(['GET', 'POST'], '/addons/{addon}'         , Module\Admin\Addons\Details::class);
+
                        $collector->addRoute(['GET']        , '/federation'             , Module\Admin\Federation::class);
 
                        $collector->addRoute(['GET', 'POST'], '/themes'                 , Module\Admin\Themes\Index::class);
diff --git a/src/Module/Admin/Addons/Details.php b/src/Module/Admin/Addons/Details.php
new file mode 100644 (file)
index 0000000..9ef2035
--- /dev/null
@@ -0,0 +1,129 @@
+<?php\r
+\r
+namespace Friendica\Module\Admin\Addons;\r
+\r
+use Friendica\Content\Text\Markdown;\r
+use Friendica\Core\Addon;\r
+use Friendica\Core\L10n;\r
+use Friendica\Core\Renderer;\r
+use Friendica\Database\DBA;\r
+use Friendica\Module\BaseAdminModule;\r
+use Friendica\Util\Strings;\r
+\r
+class Details extends BaseAdminModule\r
+{\r
+       public static function post()\r
+       {\r
+               parent::post();\r
+\r
+               $a = self::getApp();\r
+\r
+               if ($a->argc > 2) {\r
+                       // @TODO: Replace with parameter from router\r
+                       $addon = $a->argv[2];\r
+                       $addon = Strings::sanitizeFilePathItem($addon);\r
+                       if (is_file('addon/' . $addon . '/' . $addon . '.php')) {\r
+                               include_once 'addon/' . $addon . '/' . $addon . '.php';\r
+                               if (function_exists($addon . '_addon_admin_post')) {\r
+                                       $func = $addon . '_addon_admin_post';\r
+                                       $func($a);\r
+                               }\r
+\r
+                               $a->internalRedirect('admin/addons/' . $addon);\r
+                       }\r
+               }\r
+\r
+               $a->internalRedirect('admin/addons');\r
+       }\r
+\r
+       public static function content()\r
+       {\r
+               parent::content();\r
+\r
+               $a = self::getApp();\r
+\r
+               $addons_admin = [];\r
+               $addonsAdminStmt = DBA::select('addon', ['name'], ['plugin_admin' => 1], ['order' => ['name']]);\r
+               foreach (DBA::toArray($addonsAdminStmt) as $addon) {\r
+                       $addonName = $addon['name'];\r
+                       // temp addons with admin\r
+                       $addons_admin[] = $addonName;\r
+               }\r
+\r
+               if ($a->argc > 2) {\r
+                       // @TODO: Replace with parameter from router\r
+                       $addon = $a->argv[2];\r
+                       $addon = Strings::sanitizeFilePathItem($addon);\r
+                       if (!is_file("addon/$addon/$addon.php")) {\r
+                               notice(L10n::t('Item not found.'));\r
+                               $a->internalRedirect('admin/addons');\r
+                       }\r
+\r
+                       if (defaults($_GET, 'action', '') == 'toggle') {\r
+                               parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_themes', 't');\r
+\r
+                               // Toggle addon status\r
+                               if (Addon::isEnabled($addon)) {\r
+                                       Addon::uninstall($addon);\r
+                                       info(L10n::t('Addon %s disabled.', $addon));\r
+                               } else {\r
+                                       Addon::install($addon);\r
+                                       info(L10n::t('Addon %s enabled.', $addon));\r
+                               }\r
+\r
+                               Addon::saveEnabledList();\r
+\r
+                               $a->internalRedirect('admin/addons/' . $addon);\r
+                       }\r
+\r
+                       // display addon details\r
+                       if (Addon::isEnabled($addon)) {\r
+                               $status = 'on';\r
+                               $action = L10n::t('Disable');\r
+                       } else {\r
+                               $status = 'off';\r
+                               $action = L10n::t('Enable');\r
+                       }\r
+\r
+                       $readme = null;\r
+                       if (is_file("addon/$addon/README.md")) {\r
+                               $readme = Markdown::convert(file_get_contents("addon/$addon/README.md"), false);\r
+                       } elseif (is_file("addon/$addon/README")) {\r
+                               $readme = '<pre>' . file_get_contents("addon/$addon/README") . '</pre>';\r
+                       }\r
+\r
+                       $admin_form = '';\r
+                       if (in_array($addon, $addons_admin)) {\r
+                               require_once "addon/$addon/$addon.php";\r
+                               $func = $addon . '_addon_admin';\r
+                               $func($a, $admin_form);\r
+                       }\r
+\r
+                       $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');\r
+\r
+                       return Renderer::replaceMacros($t, [\r
+                               '$title' => L10n::t('Administration'),\r
+                               '$page' => L10n::t('Addons'),\r
+                               '$toggle' => L10n::t('Toggle'),\r
+                               '$settings' => L10n::t('Settings'),\r
+                               '$baseurl' => $a->getBaseURL(true),\r
+\r
+                               '$addon' => $addon,\r
+                               '$status' => $status,\r
+                               '$action' => $action,\r
+                               '$info' => Addon::getInfo($addon),\r
+                               '$str_author' => L10n::t('Author: '),\r
+                               '$str_maintainer' => L10n::t('Maintainer: '),\r
+\r
+                               '$admin_form' => $admin_form,\r
+                               '$function' => 'addons',\r
+                               '$screenshot' => '',\r
+                               '$readme' => $readme,\r
+\r
+                               '$form_security_token' => parent::getFormSecurityToken('admin_themes'),\r
+                       ]);\r
+               }\r
+\r
+               $a->internalRedirect('admin/addons');\r
+       }\r
+}
\ No newline at end of file
diff --git a/view/templates/admin/addons/details.tpl b/view/templates/admin/addons/details.tpl
new file mode 100644 (file)
index 0000000..f5bb165
--- /dev/null
@@ -0,0 +1,37 @@
+
+<div id="adminpage">
+       <h1>{{$title}} - {{$page}}</h1>
+
+       <p><span class="toggleaddon icon {{$status}}"></span> {{$info.name}} - {{$info.version}} : <a href="{{$baseurl}}/admin/{{$function}}/{{$addon}}/?action=toggle&amp;t={{$form_security_token}}">{{$action}}</a></p>
+       <p>{{$info.description nofilter}}</p>
+
+       <p class="author">{{$str_author}}
+       {{foreach $info.author as $a name=authors}}
+               {{if $a.link}}<a href="{{$a.link}}">{{$a.name}}</a>{{else}}{{$a.name}}{{/if}}{{if $smarty.foreach.authors.last}}{{else}}, {{/if}}
+       {{/foreach}}
+       </p>
+
+       <p class="maintainer">{{$str_maintainer}}
+       {{foreach $info.maintainer as $a name=maintainers}}
+               {{if $a.link}}<a href="{{$a.link}}">{{$a.name}}</a>{{else}}{{$a.name}}{{/if}}{{if $smarty.foreach.maintainers.last}}{{else}}, {{/if}}
+       {{/foreach}}
+       </p>
+
+       {{if $screenshot}}
+       <a href="{{$screenshot.0}}" class="screenshot"><img src="{{$screenshot.0}}" alt="{{$screenshot.1}}" /></a>
+       {{/if}}
+
+       {{if $admin_form}}
+       <h3>{{$settings}}</h3>
+       <form method="post" action="{{$baseurl}}/admin/{{$function}}/{{$addon}}">
+               {{$admin_form nofilter}}
+       </form>
+       {{/if}}
+
+       {{if $readme}}
+       <h3>Readme</h3>
+       <div id="addon_readme">
+               {{$readme nofilter}}
+       </div>
+       {{/if}}
+</div>