Merge pull request #14770 from Art4/new-addonproxy

New AddonHelper
This commit is contained in:
Hypolite Petovan 2025-02-10 07:53:24 -05:00 committed by GitHub
commit 17207dbb67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 909 additions and 330 deletions

View file

@ -8,7 +8,6 @@
namespace Friendica\Module\Admin\Addons;
use Friendica\Content\Text\Markdown;
use Friendica\Core\Addon;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseAdmin;
@ -42,12 +41,12 @@ class Details extends BaseAdmin
{
parent::content();
$addons_admin = Addon::getAdminList();
$addonHelper = DI::addonHelper();
$addon = Strings::sanitizeFilePathItem($this->parameters['addon']);
if (!is_file("addon/$addon/$addon.php")) {
DI::sysmsg()->addNotice(DI::l10n()->t('Addon not found.'));
Addon::uninstall($addon);
$addonHelper->uninstallAddon($addon);
DI::baseUrl()->redirect('admin/addons');
}
@ -55,11 +54,11 @@ class Details extends BaseAdmin
self::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons_details', 't');
// Toggle addon status
if (Addon::isEnabled($addon)) {
Addon::uninstall($addon);
if ($addonHelper->isAddonEnabled($addon)) {
$addonHelper->uninstallAddon($addon);
DI::sysmsg()->addInfo(DI::l10n()->t('Addon %s disabled.', $addon));
} else {
Addon::install($addon);
$addonHelper->installAddon($addon);
DI::sysmsg()->addInfo(DI::l10n()->t('Addon %s enabled.', $addon));
}
@ -67,7 +66,7 @@ class Details extends BaseAdmin
}
// display addon details
if (Addon::isEnabled($addon)) {
if ($addonHelper->isAddonEnabled($addon)) {
$status = 'on';
$action = DI::l10n()->t('Disable');
} else {
@ -82,32 +81,42 @@ class Details extends BaseAdmin
$readme = '<pre>' . file_get_contents("addon/$addon/README") . '</pre>';
}
$addons_admin = $addonHelper->getEnabledAddonsWithAdminSettings();
$admin_form = '';
if (array_key_exists($addon, $addons_admin)) {
if (in_array($addon, $addons_admin)) {
require_once "addon/$addon/$addon.php";
$func = $addon . '_addon_admin';
$func($admin_form);
}
$addonInfo = $addonHelper->getAddonInfo($addon);
$t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
return Renderer::replaceMacros($t, [
'$title' => DI::l10n()->t('Administration'),
'$page' => DI::l10n()->t('Addons'),
'$toggle' => DI::l10n()->t('Toggle'),
'$title' => DI::l10n()->t('Administration'),
'$page' => DI::l10n()->t('Addons'),
'$toggle' => DI::l10n()->t('Toggle'),
'$settings' => DI::l10n()->t('Settings'),
'$addon' => $addon,
'$addon' => $addon,
'$status' => $status,
'$action' => $action,
'$info' => Addon::getInfo($addon),
'$str_author' => DI::l10n()->t('Author: '),
'$info' => [
'name' => $addonInfo->getName(),
'version' => $addonInfo->getVersion(),
'description' => $addonInfo->getDescription(),
'author' => $addonInfo->getAuthors(),
'maintainer' => $addonInfo->getMaintainers(),
],
'$str_author' => DI::l10n()->t('Author: '),
'$str_maintainer' => DI::l10n()->t('Maintainer: '),
'$admin_form' => $admin_form,
'$function' => 'addons',
'$function' => 'addons',
'$screenshot' => '',
'$readme' => $readme,
'$readme' => $readme,
'$form_security_token' => self::getFormSecurityToken('admin_addons_details'),
]);

View file

@ -7,7 +7,6 @@
namespace Friendica\Module\Admin\Addons;
use Friendica\Core\Addon;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseAdmin;
@ -24,22 +23,25 @@ class Index extends BaseAdmin
{
parent::content();
$addonHelper = DI::addonHelper();
// reload active themes
if (!empty($_GET['action'])) {
self::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons', 't');
switch ($_GET['action']) {
case 'reload':
Addon::reload();
$addonHelper->reloadAddons();
DI::sysmsg()->addInfo(DI::l10n()->t('Addons reloaded'));
break;
case 'toggle' :
case 'toggle':
$addon = $_GET['addon'] ?? '';
if (Addon::isEnabled($addon)) {
Addon::uninstall($addon);
if ($addonHelper->isAddonEnabled($addon)) {
$addonHelper->uninstallAddon($addon);
DI::sysmsg()->addInfo(DI::l10n()->t('Addon %s disabled.', $addon));
} elseif (Addon::install($addon)) {
} elseif ($addonHelper->installAddon($addon)) {
DI::sysmsg()->addInfo(DI::l10n()->t('Addon %s enabled.', $addon));
} else {
DI::sysmsg()->addNotice(DI::l10n()->t('Addon %s failed to install.', $addon));
@ -52,18 +54,34 @@ class Index extends BaseAdmin
DI::baseUrl()->redirect('admin/addons');
}
$addons = Addon::getAvailableList();
$addons = [];
foreach ($addonHelper->getAvailableAddons() as $addonId) {
$addonInfo = $addonHelper->getAddonInfo($addonId);
$info = [
'name' => $addonInfo->getName(),
'description' => $addonInfo->getDescription(),
'version' => $addonInfo->getVersion(),
];
$addons[] = [
$addonId,
($addonHelper->isAddonEnabled($addonId) ? 'on' : 'off'),
$info,
];
}
$t = Renderer::getMarkupTemplate('admin/addons/index.tpl');
return Renderer::replaceMacros($t, [
'$title' => DI::l10n()->t('Administration'),
'$page' => DI::l10n()->t('Addons'),
'$submit' => DI::l10n()->t('Save Settings'),
'$reload' => DI::l10n()->t('Reload active addons'),
'$function' => 'addons',
'$addons' => $addons,
'$pcount' => count($addons),
'$noplugshint' => DI::l10n()->t('There are currently no addons available on your node. You can find the official addon repository at %1$s.', 'https://git.friendi.ca/friendica/friendica-addons'),
'$title' => DI::l10n()->t('Administration'),
'$page' => DI::l10n()->t('Addons'),
'$submit' => DI::l10n()->t('Save Settings'),
'$reload' => DI::l10n()->t('Reload active addons'),
'$function' => 'addons',
'$addons' => $addons,
'$pcount' => count($addons),
'$noplugshint' => DI::l10n()->t('There are currently no addons available on your node. You can find the official addon repository at %1$s.', 'https://git.friendi.ca/friendica/friendica-addons'),
'$form_security_token' => self::getFormSecurityToken('admin_addons'),
]);
}

View file

@ -8,7 +8,6 @@
namespace Friendica\Module\Admin;
use Friendica\App;
use Friendica\Core\Addon;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Renderer;
use Friendica\Core\Update;
@ -27,13 +26,14 @@ class Summary extends BaseAdmin
{
parent::content();
$basePath = DI::appHelper()->getBasePath();
$basePath = DI::appHelper()->getBasePath();
$addonPath = DI::addonHelper()->getAddonPath();
// are there MyISAM tables in the DB? If so, trigger a warning message
$warningtext = [];
$templateEngine = Renderer::getTemplateEngine();
$errors = [];
$errors = [];
$templateEngine->testInstall($errors);
foreach ($errors as $error) {
$warningtext[] = DI::l10n()->t('Template engine (%s) error: %s', $templateEngine::$name, $error);
@ -51,7 +51,7 @@ class Summary extends BaseAdmin
// Avoid the database error 1615 "Prepared statement needs to be re-prepared", see https://github.com/friendica/friendica/issues/8550
if (!DI::config()->get('database', 'pdo_emulate_prepares')) {
$table_definition_cache = DBA::getVariable('table_definition_cache');
$table_open_cache = DBA::getVariable('table_open_cache');
$table_open_cache = DBA::getVariable('table_open_cache');
if (!empty($table_definition_cache) && !empty($table_open_cache)) {
$suggested_definition_cache = min(400 + round((int) $table_open_cache / 2, 1), 2000);
if ($suggested_definition_cache > $table_definition_cache) {
@ -100,9 +100,13 @@ class Summary extends BaseAdmin
// Check server vitality
if (!self::checkSelfHostMeta()) {
$well_known = DI::baseUrl() . Probe::HOST_META;
$warningtext[] = DI::l10n()->t('<a href="%s">%s</a> is not reachable on your system. This is a severe configuration issue that prevents server to server communication. See <a href="%s">the installation page</a> for help.',
$well_known, $well_known, DI::baseUrl() . '/help/Install');
$well_known = DI::baseUrl() . Probe::HOST_META;
$warningtext[] = DI::l10n()->t(
'<a href="%s">%s</a> is not reachable on your system. This is a severe configuration issue that prevents server to server communication. See <a href="%s">the installation page</a> for help.',
$well_known,
$well_known,
DI::baseUrl() . '/help/Install'
);
}
// Check logfile permission
@ -114,8 +118,8 @@ class Summary extends BaseAdmin
}
// check legacy basepath settings
$configLoader = (new Config())->createConfigFileManager($basePath, $_SERVER);
$configCache = new Cache();
$configLoader = (new Config())->createConfigFileManager($basePath, $addonPath, $_SERVER);
$configCache = new Cache();
$configLoader->setupCache($configCache);
$confBasepath = $configCache->get('system', 'basepath');
$currBasepath = DI::config()->get('system', 'basepath');
@ -125,25 +129,31 @@ class Summary extends BaseAdmin
'from' => $currBasepath,
'to' => $confBasepath,
]);
$warningtext[] = DI::l10n()->t('Friendica\'s system.basepath was updated from \'%s\' to \'%s\'. Please remove the system.basepath from your db to avoid differences.',
$warningtext[] = DI::l10n()->t(
'Friendica\'s system.basepath was updated from \'%s\' to \'%s\'. Please remove the system.basepath from your db to avoid differences.',
$currBasepath,
$confBasepath);
$confBasepath
);
} elseif (!is_dir($currBasepath)) {
DI::logger()->alert('Friendica\'s system.basepath is wrong.', [
'from' => $currBasepath,
'to' => $confBasepath,
]);
$warningtext[] = DI::l10n()->t('Friendica\'s current system.basepath \'%s\' is wrong and the config file \'%s\' isn\'t used.',
$warningtext[] = DI::l10n()->t(
'Friendica\'s current system.basepath \'%s\' is wrong and the config file \'%s\' isn\'t used.',
$currBasepath,
$confBasepath);
$confBasepath
);
} else {
DI::logger()->alert('Friendica\'s system.basepath is wrong.', [
'from' => $currBasepath,
'to' => $confBasepath,
]);
$warningtext[] = DI::l10n()->t('Friendica\'s current system.basepath \'%s\' is not equal to the config file \'%s\'. Please fix your configuration.',
$warningtext[] = DI::l10n()->t(
'Friendica\'s current system.basepath \'%s\' is not equal to the config file \'%s\'. Please fix your configuration.',
$currBasepath,
$confBasepath);
$confBasepath
);
}
}
@ -177,7 +187,7 @@ class Summary extends BaseAdmin
'$platform' => App::PLATFORM,
'$codename' => App::CODENAME,
'$build' => DI::config()->get('system', 'build'),
'$addons' => [DI::l10n()->t('Active addons'), Addon::getEnabledList()],
'$addons' => [DI::l10n()->t('Active addons'), DI::addonHelper()->getEnabledAddons()],
'$serversettings' => $server_settings,
'$warningtext' => $warningtext,
]);

View file

@ -8,7 +8,6 @@
namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Core\Addon;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Network\HTTPException;
@ -69,43 +68,53 @@ abstract class BaseAdmin extends BaseModule
// not part of $aside to make the template more adjustable
$aside_sub = [
'information' => [DI::l10n()->t('Information'), [
'overview' => ['admin' , DI::l10n()->t('Overview') , 'overview'],
'federation' => ['admin/federation' , DI::l10n()->t('Federation Statistics') , 'federation']
'overview' => ['admin' , DI::l10n()->t('Overview') , 'overview'],
'federation' => ['admin/federation' , DI::l10n()->t('Federation Statistics') , 'federation']
]],
'configuration' => [DI::l10n()->t('Configuration'), [
'site' => ['admin/site' , DI::l10n()->t('Site') , 'site'],
'storage' => ['admin/storage' , DI::l10n()->t('Storage') , 'storage'],
'addons' => ['admin/addons' , DI::l10n()->t('Addons') , 'addons'],
'themes' => ['admin/themes' , DI::l10n()->t('Themes') , 'themes'],
'features' => ['admin/features' , DI::l10n()->t('Additional features') , 'features'],
'tos' => ['admin/tos' , DI::l10n()->t('Terms of Service') , 'tos'],
'site' => ['admin/site' , DI::l10n()->t('Site') , 'site'],
'storage' => ['admin/storage' , DI::l10n()->t('Storage') , 'storage'],
'addons' => ['admin/addons' , DI::l10n()->t('Addons') , 'addons'],
'themes' => ['admin/themes' , DI::l10n()->t('Themes') , 'themes'],
'features' => ['admin/features' , DI::l10n()->t('Additional features') , 'features'],
'tos' => ['admin/tos' , DI::l10n()->t('Terms of Service') , 'tos'],
]],
'database' => [DI::l10n()->t('Database'), [
'dbsync' => ['admin/dbsync' , DI::l10n()->t('DB updates') , 'dbsync'],
'deferred' => ['admin/queue/deferred', DI::l10n()->t('Inspect Deferred Workers'), 'deferred'],
'workerqueue' => ['admin/queue' , DI::l10n()->t('Inspect worker Queue') , 'workerqueue'],
'dbsync' => ['admin/dbsync' , DI::l10n()->t('DB updates') , 'dbsync'],
'deferred' => ['admin/queue/deferred', DI::l10n()->t('Inspect Deferred Workers'), 'deferred'],
'workerqueue' => ['admin/queue' , DI::l10n()->t('Inspect worker Queue') , 'workerqueue'],
]],
'logs' => [DI::l10n()->t('Logs'), [
'logsconfig' => ['admin/logs/', DI::l10n()->t('Logs') , 'logs'],
'logsview' => ['admin/logs/view' , DI::l10n()->t('View Logs') , 'viewlogs'],
'logsconfig' => ['admin/logs/', DI::l10n()->t('Logs') , 'logs'],
'logsview' => ['admin/logs/view' , DI::l10n()->t('View Logs') , 'viewlogs'],
]],
'diagnostics' => [DI::l10n()->t('Diagnostics'), [
'phpinfo' => ['admin/phpinfo?t=' . self::getFormSecurityToken('phpinfo'), DI::l10n()->t('PHP Info') , 'phpinfo'],
'probe' => ['probe' , DI::l10n()->t('probe address') , 'probe'],
'webfinger' => ['webfinger' , DI::l10n()->t('check webfinger') , 'webfinger'],
'babel' => ['babel' , DI::l10n()->t('Babel') , 'babel'],
'debug/ap' => ['debug/ap' , DI::l10n()->t('ActivityPub Conversion') , 'debug/ap'],
'phpinfo' => ['admin/phpinfo?t=' . self::getFormSecurityToken('phpinfo'), DI::l10n()->t('PHP Info') , 'phpinfo'],
'probe' => ['probe' , DI::l10n()->t('probe address') , 'probe'],
'webfinger' => ['webfinger' , DI::l10n()->t('check webfinger') , 'webfinger'],
'babel' => ['babel' , DI::l10n()->t('Babel') , 'babel'],
'debug/ap' => ['debug/ap' , DI::l10n()->t('ActivityPub Conversion') , 'debug/ap'],
]],
];
$addons_admin = [];
foreach (DI::addonHelper()->getEnabledAddonsWithAdminSettings() as $addonId) {
$addons_admin[$addonId] = [
'url' => 'admin/addons/' . $addonId,
'name' => $addonId,
'class' => 'addon',
];
}
$t = Renderer::getMarkupTemplate('admin/aside.tpl');
DI::page()['aside'] .= Renderer::replaceMacros($t, [
'$admin' => ['addons_admin' => Addon::getAdminList()],
'$subpages' => $aside_sub,
'$admtxt' => DI::l10n()->t('Admin'),
'$admin' => ['addons_admin' => $addons_admin],
'$subpages' => $aside_sub,
'$admtxt' => DI::l10n()->t('Admin'),
'$plugadmtxt' => DI::l10n()->t('Addon Features'),
'$h_pending' => DI::l10n()->t('User registrations waiting for confirmation'),
'$admurl' => 'admin/'
'$h_pending' => DI::l10n()->t('User registrations waiting for confirmation'),
'$admurl' => 'admin/'
]);
return '';

View file

@ -56,7 +56,7 @@ class SaveTag extends BaseModule
$tpl = Renderer::getMarkupTemplate("filer_dialog.tpl");
echo Renderer::replaceMacros($tpl, [
'$field' => ['term', $this->t("Folder:"), '', '', $filetags, $this->t('- select -')],
'$field' => ['term', $this->t("Folder:"), '', '', $filetags, $this->t('- select -')],
'$submit' => $this->t('Save'),
]);

View file

@ -11,7 +11,7 @@ use Friendica\App;
use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\BaseModule;
use Friendica\Core\Addon;
use Friendica\Core\Addon\AddonHelper;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hook;
use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
@ -31,6 +31,7 @@ use Psr\Log\LoggerInterface;
*/
class Friendica extends BaseModule
{
private AddonHelper $addonHelper;
/** @var IManageConfigValues */
private $config;
/** @var IManageKeyValuePairs */
@ -38,18 +39,19 @@ class Friendica extends BaseModule
/** @var IHandleUserSessions */
private $session;
public function __construct(IHandleUserSessions $session, IManageKeyValuePairs $keyValue, IManageConfigValues $config, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
public function __construct(AddonHelper $addonHelper, IHandleUserSessions $session, IManageKeyValuePairs $keyValue, IManageConfigValues $config, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->config = $config;
$this->keyValue = $keyValue;
$this->session = $session;
$this->config = $config;
$this->keyValue = $keyValue;
$this->session = $session;
$this->addonHelper = $addonHelper;
}
protected function content(array $request = []): string
{
$visibleAddonList = Addon::getVisibleList();
$visibleAddonList = $this->addonHelper->getVisibleEnabledAddons();
if (!empty($visibleAddonList)) {
$sorted = $visibleAddonList;
@ -83,8 +85,8 @@ class Friendica extends BaseModule
if (!empty($blockList) && ($this->config->get('blocklist', 'public') || $this->session->isAuthenticated())) {
$blocked = [
'title' => $this->t('On this server the following remote servers are blocked.'),
'header' => [
'title' => $this->t('On this server the following remote servers are blocked.'),
'header' => [
$this->t('Blocked domain'),
$this->t('Reason for the block'),
],
@ -102,11 +104,13 @@ class Friendica extends BaseModule
$tpl = Renderer::getMarkupTemplate('friendica.tpl');
return Renderer::replaceMacros($tpl, [
'about' => $this->t('This is Friendica, version %s that is running at the web location %s. The database version is %s, the post update version is %s.',
'about' => $this->t(
'This is Friendica, version %s that is running at the web location %s. The database version is %s, the post update version is %s.',
'<strong>' . App::VERSION . '</strong>',
$this->baseUrl,
'<strong>' . $this->config->get('system', 'build') . '/' . DB_UPDATE_VERSION . '</strong>',
'<strong>' . $this->keyValue->get('post_update_version') . '/' . PostUpdate::VERSION . '</strong>'),
'<strong>' . $this->keyValue->get('post_update_version') . '/' . PostUpdate::VERSION . '</strong>'
),
'friendica' => $this->t('Please visit <a href="https://friendi.ca">Friendi.ca</a> to learn more about the Friendica project.'),
'bugs' => $this->t('Bug reports and issues: please visit') . ' ' . '<a href="https://github.com/friendica/friendica/issues?state=open">' . $this->t('the bugtracker at github') . '</a>',
'info' => $this->t('Suggestions, praise, etc. - please email "info" at "friendi - dot - ca'),
@ -148,7 +152,7 @@ class Friendica extends BaseModule
$register_policy = $register_policies[$register_policy_int];
}
$admin = [];
$admin = [];
$administrator = User::getFirstAdmin(['username', 'nickname']);
if (!empty($administrator)) {
$admin = [
@ -157,11 +161,11 @@ class Friendica extends BaseModule
];
}
$visible_addons = Addon::getVisibleList();
$visible_addons = $this->addonHelper->getVisibleEnabledAddons();
$this->config->reload();
$locked_features = [];
$featureLocks = $this->config->get('config', 'feature_lock');
$featureLocks = $this->config->get('config', 'feature_lock');
if (isset($featureLocks)) {
foreach ($featureLocks as $feature => $lock) {
if ($feature === 'config_loaded') {