]> git.mxchange.org Git - friendica.git/commitdiff
Move admin/addons to src/Module
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 21 Apr 2019 16:20:04 +0000 (12:20 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 2 May 2019 13:52:44 +0000 (09:52 -0400)
- Add Module\Admin\Addons\Index class
- Add route for admin/addons
- Add addons admin aside menu entry
- Remove unused template admin/addons.tpl from base and frio
- Remove addon list from mod/admin

mod/admin.php
src/App/Router.php
src/Core/Addon.php
src/Module/Admin/Addons/Index.php [new file with mode: 0644]
src/Module/BaseAdminModule.php
view/templates/admin/addons.tpl [deleted file]
view/theme/frio/templates/admin/addons.tpl [deleted file]

index a717943d6baf26b3f1ecd9cb3c0d9670a8e1a0d4..b3933a16bf32d076cdbdb4e0f12ff07d374912e3 100644 (file)
@@ -1762,56 +1762,6 @@ function admin_page_addons(App $a, array $addons_admin)
                        '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"),
                ]);
        }
-
-       /*
-        * List addons
-        */
-       if (!empty($_GET['a']) && $_GET['a'] == "r") {
-               BaseModule::checkFormSecurityTokenRedirectOnError($a->getBaseURL() . '/admin/addons', 'admin_themes', 't');
-               Addon::reload();
-               info("Addons reloaded");
-               $a->internalRedirect('admin/addons');
-       }
-
-       $addons = [];
-       $files = glob("addon/*/");
-       if (is_array($files)) {
-               foreach ($files as $file) {
-                       if (is_dir($file)) {
-                               list($tmp, $id) = array_map("trim", explode("/", $file));
-                               $info = Addon::getInfo($id);
-                               $show_addon = true;
-
-                               // If the addon is unsupported, then only show it, when it is enabled
-                               if ((strtolower($info["status"]) == "unsupported") && !Addon::isEnabled($id)) {
-                                       $show_addon = false;
-                               }
-
-                               // Override the above szenario, when the admin really wants to see outdated stuff
-                               if (Config::get("system", "show_unsupported_addons")) {
-                                       $show_addon = true;
-                               }
-
-                               if ($show_addon) {
-                                       $addons[] = [$id, (Addon::isEnabled($id) ? "on" : "off"), $info];
-                               }
-                       }
-               }
-       }
-
-       $t = Renderer::getMarkupTemplate('admin/addons.tpl');
-       return Renderer::replaceMacros($t, [
-               '$title' => L10n::t('Administration'),
-               '$page' => L10n::t('Addons'),
-               '$submit' => L10n::t('Save Settings'),
-               '$reload' => L10n::t('Reload active addons'),
-               '$baseurl' => System::baseUrl(true),
-               '$function' => 'addons',
-               '$addons' => $addons,
-               '$pcount' => count($addons),
-               '$noplugshint' => L10n::t('There are currently no addons available on your node. You can find the official addon repository at %1$s and might find other interesting addons in the open addon registry at %2$s', 'https://github.com/friendica/friendica-addons', 'http://addons.friendi.ca'),
-               '$form_security_token' => BaseModule::getFormSecurityToken("admin_themes"),
-       ]);
 }
 
 /**
index e1accefd9fe27f653eaf324b5fa16129494c1e2b..eacf95db354b3ee62c381de3b5c0435bb0491537 100644 (file)
@@ -120,6 +120,8 @@ class Router
 
                $this->routeCollector->addGroup('/admin', function (RouteCollector $collector) {
                        $collector->addRoute(['GET']        , '[/]'                     , Module\Admin\Summary::class);
+
+                       $collector->addRoute(['GET', 'POST'], '/addons'                 , Module\Admin\Addons\Index::class);
                        $collector->addRoute(['GET']        , '/federation'             , Module\Admin\Federation::class);
 
                        $collector->addRoute(['GET', 'POST'], '/themes'                 , Module\Admin\Themes\Index::class);
index 06a731b2cdd594b4b6cebba0e542e06bd69a01b2..2c28c24ee9299c244f3326978f9efecbd91566c4 100644 (file)
@@ -26,6 +26,29 @@ class Addon extends BaseObject
         */
        private static $addons = [];
 
+       public static function getAvailableList()
+       {
+               $addons = [];
+               $files = glob('addon/*/');
+               if (is_array($files)) {
+                       foreach ($files as $file) {
+                               if (is_dir($file)) {
+                                       list($tmp, $addon) = array_map('trim', explode('/', $file));
+                                       $info = self::getInfo($addon);
+
+                                       if (Config::get('system', 'show_unsupported_addons')
+                                               || strtolower($info['status']) != 'unsupported'
+                                               || self::isEnabled($addon)
+                                       ) {
+                                               $addons[] = [$addon, (self::isEnabled($addon) ? 'on' : 'off'), $info];
+                                       }
+                               }
+                       }
+               }
+
+               return $addons;
+       }
+
        /**
         * @brief Synchronize addons:
         *
@@ -94,6 +117,8 @@ class Addon extends BaseObject
                }
 
                unset(self::$addons[array_search($addon, self::$addons)]);
+
+               Addon::saveEnabledList();
        }
 
        /**
@@ -136,9 +161,11 @@ class Addon extends BaseObject
                                self::$addons[] = $addon;
                        }
 
+                       Addon::saveEnabledList();
+
                        return true;
                } else {
-                       Logger::error("Addon {addon}: {action} failed", ['action' => 'uninstall', 'addon' => $addon]);
+                       Logger::error("Addon {addon}: {action} failed", ['action' => 'install', 'addon' => $addon]);
                        return false;
                }
        }
@@ -283,11 +310,10 @@ class Addon extends BaseObject
         * Saves the current enabled addon list in the system.addon config key
         *
         * @return boolean
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
        public static function saveEnabledList()
        {
-               return Config::set("system", "addon", implode(", ", self::$addons));
+               return Config::set('system', 'addon', implode(', ', self::$addons));
        }
 
        /**
diff --git a/src/Module/Admin/Addons/Index.php b/src/Module/Admin/Addons/Index.php
new file mode 100644 (file)
index 0000000..20d8ff1
--- /dev/null
@@ -0,0 +1,72 @@
+<?php\r
+\r
+namespace Friendica\Module\Admin\Addons;\r
+\r
+use Friendica\Content\Text\Markdown;\r
+use Friendica\Core\Addon;\r
+use Friendica\Core\Config;\r
+use Friendica\Core\L10n;\r
+use Friendica\Core\Renderer;\r
+use Friendica\Core\System;\r
+use Friendica\Database\DBA;\r
+use Friendica\Module\BaseAdminModule;\r
+\r
+class Index extends BaseAdminModule\r
+{\r
+       public static function content()\r
+       {\r
+               parent::content();\r
+\r
+               $a = self::getApp();\r
+\r
+               // reload active themes\r
+               if (!empty($_GET['action'])) {\r
+                       parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons', 't');\r
+\r
+                       switch ($_GET['action']) {\r
+                               case 'reload':\r
+                                       Addon::reload();\r
+                                       info('Addons reloaded');\r
+                                       break;\r
+\r
+                               case 'toggle' :\r
+                                       $addon = defaults($_GET, 'addon', '');\r
+                                       if (Addon::isEnabled($addon)) {\r
+                                               Addon::uninstall($addon);\r
+                                               info(L10n::t('Addon %s disabled.', $addon));\r
+                                       } elseif (Addon::install($addon)) {\r
+                                               info(L10n::t('Addon %s enabled.', $addon));\r
+                                       } else {\r
+                                               info(L10n::t('Addon %s failed to install.', $addon));\r
+                                       }\r
+\r
+                                       break;\r
+\r
+                       }\r
+\r
+                       $a->internalRedirect('admin/addons');\r
+               }\r
+\r
+               $addons_admin = [];\r
+               $addonsAdminStmt = DBA::select('addon', ['name'], ['plugin_admin' => 1], ['order' => ['name']]);\r
+               foreach (DBA::toArray($addonsAdminStmt) as $addon) {\r
+                       $addons_admin[] = $addon['name'];\r
+               }\r
+\r
+               $addons = Addon::getAvailableList();\r
+\r
+               $t = Renderer::getMarkupTemplate('admin/addons/index.tpl');\r
+               return Renderer::replaceMacros($t, [\r
+                       '$title' => L10n::t('Administration'),\r
+                       '$page' => L10n::t('Addons'),\r
+                       '$submit' => L10n::t('Save Settings'),\r
+                       '$reload' => L10n::t('Reload active addons'),\r
+                       '$baseurl' => System::baseUrl(true),\r
+                       '$function' => 'addons',\r
+                       '$addons' => $addons,\r
+                       '$pcount' => count($addons),\r
+                       '$noplugshint' => L10n::t('There are currently no addons available on your node. You can find the official addon repository at %1$s and might find other interesting addons in the open addon registry at %2$s', 'https://github.com/friendica/friendica-addons', 'http://addons.friendi.ca'),\r
+                       '$form_security_token' => parent::getFormSecurityToken('admin_addons'),\r
+               ]);\r
+       }\r
+}
\ No newline at end of file
index 330b9dd749ed388c68d7a6e72e993a7bc2fe733d..44ef39113fb4983ca5f83090c1fd59dba6c83f51 100644 (file)
@@ -53,6 +53,7 @@ abstract class BaseAdminModule extends BaseModule
                                'federation'   => ['admin/federation'  , L10n::t('Federation Statistics')   , 'federation']\r
                        ]],\r
                        'configuration' => [L10n::t('Configuration'), [\r
+                               'addons'       => ['admin/addons'      , L10n::t('Addons')                  , 'addons'],\r
                                'themes'       => ['admin/themes'      , L10n::t('Themes')                  , 'themes'],\r
                                'tos'          => ['admin/tos'         , L10n::t('Terms of Service')        , 'tos'],\r
                        ]],\r
diff --git a/view/templates/admin/addons.tpl b/view/templates/admin/addons.tpl
deleted file mode 100644 (file)
index c144a5e..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-
-<div id='adminpage'>
-       <h1>{{$title}} - {{$page}}</h1>
-               {{if $pcount eq 0}}
-                   <div class="error-message">
-                   {{$noplugshint}}
-                   </div>
-               {{else}}
-               <a class="btn" href="{{$baseurl}}/admin/{{$function}}?a=r&amp;t={{$form_security_token}}">{{$reload}}</a>
-               <ul id='addonslist'>
-               {{foreach $addons as $p}}
-                       <li class='addon {{$p.1}}'>
-                               <a class='toggleaddon' href='{{$baseurl}}/admin/{{$function}}/{{$p.0}}?a=t&amp;t={{$form_security_token}}' title="{{if $p.1==on}}Disable{{else}}Enable{{/if}}" ><span class='icon {{$p.1}}'></span></a>
-                               <a href='{{$baseurl}}/admin/{{$function}}/{{$p.0}}'><span class='name'>{{$p.2.name}}</span></a> - <span class="version">{{$p.2.version}}</span>
-                               {{if $p.2.experimental}} {{$experimental}} {{/if}}{{if $p.2.unsupported}} {{$unsupported}} {{/if}}
-
-                               <div class='desc'>{{$p.2.description nofilter}}</div>
-                       </li>
-               {{/foreach}}
-               </ul>
-               {{/if}}
-</div>
diff --git a/view/theme/frio/templates/admin/addons.tpl b/view/theme/frio/templates/admin/addons.tpl
deleted file mode 100644 (file)
index fa598f4..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-
-<div id='adminpage'>
-       <h1>{{$title}} - {{$page}}</h1>
-               {{if $pcount eq 0}}
-                   <div class="error-message">
-                   {{$noplugshint}}
-                   </div>
-               {{else}}
-               <a class="btn" href="{{$baseurl}}/admin/{{$function}}?a=r&amp;t={{$form_security_token}}">{{$reload}}</a>
-               <ul id='addonslist'>
-               {{foreach $addons as $p}}
-                       <li class="addon {{$p.1}}">
-                               <span class="offset-anchor" id="{{$p.0}}"></span>
-                               <a class='toggleaddon' href='{{$baseurl}}/admin/{{$function}}/{{$p.0}}?a=t&amp;t={{$form_security_token}}#{{$p.0}}' title="{{if $p.1==on}}Disable{{else}}Enable{{/if}}" ><span class='icon {{$p.1}}'></span></a>
-                               <a href='{{$baseurl}}/admin/{{$function}}/{{$p.0}}'><span class='name'>{{$p.2.name}}</span></a> - <span class="version">{{$p.2.version}}</span>
-                               {{if $p.2.experimental}} {{$experimental}} {{/if}}{{if $p.2.unsupported}} {{$unsupported}} {{/if}}
-                               <div class='desc'>{{$p.2.description nofilter}}</div>
-                       </li>
-               {{/foreach}}
-               </ul>
-               {{/if}}
-</div>