From 9f4fb4906af351f56e4527ad8ba457b479c33281 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 27 Apr 2019 22:19:54 -0400 Subject: [PATCH] Move addon admin list generation to Core\Addon --- src/Core/Addon.php | 32 +++++++++++++++++++++++ src/Module/Admin/Addons/Details.php | 13 +++------ src/Module/Admin/Addons/Index.php | 9 ------- src/Module/BaseAdminModule.php | 9 ++----- view/theme/frio/templates/admin/aside.tpl | 6 ++--- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/Core/Addon.php b/src/Core/Addon.php index 4dd34eb16..b6f64ad74 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -27,6 +27,14 @@ class Addon extends BaseObject */ private static $addons = []; + /** + * Returns the list of available addons with their current status and info. + * This list is made from scanning the addon/ folder. + * Unsupported addons are excluded unless they already are enabled or system.show_unsupported_addon is set. + * + * @return array + * @throws \Exception + */ public static function getAvailableList() { $addons = []; @@ -50,6 +58,30 @@ class Addon extends BaseObject return $addons; } + /** + * Returns a list of addons that can be configured at the node level. + * The list is formatted for display in the admin panel aside. + * + * @return array + * @throws \Exception + */ + public static function getAdminList() + { + $addons_admin = []; + $addonsAdminStmt = DBA::select('addon', ['name'], ['plugin_admin' => 1], ['order' => ['name']]); + while ($addon = DBA::fetch($addonsAdminStmt)) { + $addons_admin[$addon['name']] = [ + 'url' => 'admin/addons/' . $addon['name'], + 'name' => $addon['name'], + 'class' => 'addon' + ]; + } + DBA::close($addonsAdminStmt); + + return $addons_admin; + } + + /** * @brief Synchronize addons: * diff --git a/src/Module/Admin/Addons/Details.php b/src/Module/Admin/Addons/Details.php index 9ef2035de..25e538122 100644 --- a/src/Module/Admin/Addons/Details.php +++ b/src/Module/Admin/Addons/Details.php @@ -6,7 +6,6 @@ use Friendica\Content\Text\Markdown; use Friendica\Core\Addon; use Friendica\Core\L10n; use Friendica\Core\Renderer; -use Friendica\Database\DBA; use Friendica\Module\BaseAdminModule; use Friendica\Util\Strings; @@ -42,13 +41,7 @@ class Details extends BaseAdminModule $a = self::getApp(); - $addons_admin = []; - $addonsAdminStmt = DBA::select('addon', ['name'], ['plugin_admin' => 1], ['order' => ['name']]); - foreach (DBA::toArray($addonsAdminStmt) as $addon) { - $addonName = $addon['name']; - // temp addons with admin - $addons_admin[] = $addonName; - } + $addons_admin = Addon::getAdminList(); if ($a->argc > 2) { // @TODO: Replace with parameter from router @@ -93,7 +86,7 @@ class Details extends BaseAdminModule } $admin_form = ''; - if (in_array($addon, $addons_admin)) { + if (array_key_exists($addon, $addons_admin)) { require_once "addon/$addon/$addon.php"; $func = $addon . '_addon_admin'; $func($a, $admin_form); @@ -126,4 +119,4 @@ class Details extends BaseAdminModule $a->internalRedirect('admin/addons'); } -} \ No newline at end of file +} diff --git a/src/Module/Admin/Addons/Index.php b/src/Module/Admin/Addons/Index.php index 6c8d48dc4..9df486c10 100644 --- a/src/Module/Admin/Addons/Index.php +++ b/src/Module/Admin/Addons/Index.php @@ -2,12 +2,9 @@ namespace Friendica\Module\Admin\Addons; -use Friendica\Content\Text\Markdown; use Friendica\Core\Addon; -use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; -use Friendica\Database\DBA; use Friendica\Module\BaseAdminModule; class Index extends BaseAdminModule @@ -46,12 +43,6 @@ class Index extends BaseAdminModule $a->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'); diff --git a/src/Module/BaseAdminModule.php b/src/Module/BaseAdminModule.php index 140f1223e..5e56bd8d7 100644 --- a/src/Module/BaseAdminModule.php +++ b/src/Module/BaseAdminModule.php @@ -3,6 +3,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\Core\Addon; use Friendica\Core\L10n; use Friendica\Core\Renderer; use Friendica\Core\System; @@ -97,15 +98,9 @@ abstract class BaseAdminModule extends BaseModule ]], ]; - $addons_admin = []; - $addonsAdminStmt = DBA::select('addon', ['name'], ['plugin_admin' => 1], ['order' => ['name']]); - foreach (DBA::toArray($addonsAdminStmt) as $addon) { - $addons_admin[] = ['admin/addons/' . $addon['name'], $addon['name'], 'addon']; - } - $t = Renderer::getMarkupTemplate('admin/aside.tpl'); $a->page['aside'] .= Renderer::replaceMacros($t, [ - '$admin' => ['addons_admin' => $addons_admin], + '$admin' => ['addons_admin' => Addon::getAdminList()], '$subpages' => $aside_sub, '$admtxt' => L10n::t('Admin'), '$plugadmtxt' => L10n::t('Addon Features'), diff --git a/view/theme/frio/templates/admin/aside.tpl b/view/theme/frio/templates/admin/aside.tpl index 5da73e135..0ba58e5ae 100644 --- a/view/theme/frio/templates/admin/aside.tpl +++ b/view/theme/frio/templates/admin/aside.tpl @@ -43,9 +43,9 @@

{{$plugadmtxt}}