From: Hypolite Petovan Date: Sun, 21 Apr 2019 16:20:04 +0000 (-0400) Subject: Move admin/addons to src/Module X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9bbb4385345640b39d51086b9d8e0471ff682591;p=friendica.git Move admin/addons to src/Module - 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 --- diff --git a/mod/admin.php b/mod/admin.php index a717943d6b..b3933a16bf 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -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"), - ]); } /** diff --git a/src/App/Router.php b/src/App/Router.php index e1accefd9f..eacf95db35 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -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); diff --git a/src/Core/Addon.php b/src/Core/Addon.php index 06a731b2cd..2c28c24ee9 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -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 index 0000000000..20d8ff196e --- /dev/null +++ b/src/Module/Admin/Addons/Index.php @@ -0,0 +1,72 @@ +internalRedirect('admin/addons'); + } + + $addons_admin = []; + $addonsAdminStmt = DBA::select('addon', ['name'], ['plugin_admin' => 1], ['order' => ['name']]); + foreach (DBA::toArray($addonsAdminStmt) as $addon) { + $addons_admin[] = $addon['name']; + } + + $addons = Addon::getAvailableList(); + + $t = Renderer::getMarkupTemplate('admin/addons/index.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' => parent::getFormSecurityToken('admin_addons'), + ]); + } +} \ No newline at end of file diff --git a/src/Module/BaseAdminModule.php b/src/Module/BaseAdminModule.php index 330b9dd749..44ef39113f 100644 --- a/src/Module/BaseAdminModule.php +++ b/src/Module/BaseAdminModule.php @@ -53,6 +53,7 @@ abstract class BaseAdminModule extends BaseModule 'federation' => ['admin/federation' , L10n::t('Federation Statistics') , 'federation'] ]], 'configuration' => [L10n::t('Configuration'), [ + 'addons' => ['admin/addons' , L10n::t('Addons') , 'addons'], 'themes' => ['admin/themes' , L10n::t('Themes') , 'themes'], 'tos' => ['admin/tos' , L10n::t('Terms of Service') , 'tos'], ]], diff --git a/view/templates/admin/addons.tpl b/view/templates/admin/addons.tpl deleted file mode 100644 index c144a5eec6..0000000000 --- a/view/templates/admin/addons.tpl +++ /dev/null @@ -1,22 +0,0 @@ - -
-

{{$title}} - {{$page}}

- {{if $pcount eq 0}} -
- {{$noplugshint}} -
- {{else}} - {{$reload}} - - {{/if}} -
diff --git a/view/theme/frio/templates/admin/addons.tpl b/view/theme/frio/templates/admin/addons.tpl deleted file mode 100644 index fa598f4679..0000000000 --- a/view/theme/frio/templates/admin/addons.tpl +++ /dev/null @@ -1,22 +0,0 @@ - -
-

{{$title}} - {{$page}}

- {{if $pcount eq 0}} -
- {{$noplugshint}} -
- {{else}} - {{$reload}} - - {{/if}} -