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
This commit is contained in:
Hypolite Petovan 2019-04-21 12:20:04 -04:00
parent a13bc14933
commit 9bbb438534
7 changed files with 104 additions and 97 deletions

View 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"),
]);
}
/**

View 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);

View 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));
}
/**

View file

@ -0,0 +1,72 @@
<?php
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\Core\System;
use Friendica\Database\DBA;
use Friendica\Module\BaseAdminModule;
class Index extends BaseAdminModule
{
public static function content()
{
parent::content();
$a = self::getApp();
// reload active themes
if (!empty($_GET['action'])) {
parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons', 't');
switch ($_GET['action']) {
case 'reload':
Addon::reload();
info('Addons reloaded');
break;
case 'toggle' :
$addon = defaults($_GET, 'addon', '');
if (Addon::isEnabled($addon)) {
Addon::uninstall($addon);
info(L10n::t('Addon %s disabled.', $addon));
} elseif (Addon::install($addon)) {
info(L10n::t('Addon %s enabled.', $addon));
} else {
info(L10n::t('Addon %s failed to install.', $addon));
}
break;
}
$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');
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'),
]);
}
}

View file

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

View file

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

View file

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