diff --git a/mod/admin.php b/mod/admin.php index a717943d6..b3933a16b 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 e1accefd9..eacf95db3 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 06a731b2c..2c28c24ee 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 000000000..20d8ff196 --- /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 330b9dd74..44ef39113 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 c144a5eec..000000000 --- a/view/templates/admin/addons.tpl +++ /dev/null @@ -1,22 +0,0 @@ - -