1
1
Fork 0

Move addon admin list generation to Core\Addon

This commit is contained in:
Hypolite Petovan 2019-04-27 22:19:54 -04:00
parent 9774c95b80
commit 9f4fb4906a
5 changed files with 40 additions and 29 deletions

View file

@ -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:
*

View file

@ -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');
}
}
}

View file

@ -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');

View file

@ -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'),

View file

@ -43,9 +43,9 @@
<h3>{{$plugadmtxt}}</h3>
<ul role="menu">
{{foreach $admin.addons_admin as $name => $item}}
<li role="menuitem" class="{{$item.2}}">
<a href="{{$item.0}}" {{if $item.accesskey}}accesskey="{{$item.accesskey}}"{{/if}}>
{{$item.1}}
<li role="menuitem" class="{{$item.class}}">
<a href="{{$item.url}}" {{if $item.accesskey}}accesskey="{{$item.accesskey}}"{{/if}}>
{{$item.name}}
</a>
</li>
{{/foreach}}