Merge pull request #14909 from Art4/replace-addon-class-with-addonhelper

Replace Addon class with AddonHelper
This commit is contained in:
Philipp 2025-05-03 21:18:31 +02:00 committed by GitHub
commit 38e89b152c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 149 additions and 115 deletions

View file

@ -7,11 +7,9 @@
namespace Friendica\Model;
use Friendica\Core\Addon;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use stdClass;
/**
@ -28,11 +26,12 @@ class Nodeinfo
{
$config = DI::config();
$logger = DI::logger();
$addonHelper = DI::addonHelper();
// If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
if (Addon::isEnabled('statistics_json')) {
if ($addonHelper->isAddonEnabled('statistics_json')) {
$config->set('system', 'nodeinfo', true);
Addon::uninstall('statistics_json');
$addonHelper->uninstallAddon('statistics_json');
}
if (empty($config->get('system', 'nodeinfo'))) {
@ -66,14 +65,14 @@ class Nodeinfo
/**
* Return the supported services
*
* @return Object with supported services
* @return stdClass with supported services
*/
public static function getUsage(bool $version2 = false)
public static function getUsage(bool $version2 = false): stdClass
{
$config = DI::config();
$usage = new stdClass();
$usage->users = new \stdClass;
$usage->users = new stdClass();
if (!empty($config->get('system', 'nodeinfo'))) {
$usage->users->total = intval(DI::keyValue()->get('nodeinfo_total_users'));
@ -97,45 +96,47 @@ class Nodeinfo
*/
public static function getServices(): array
{
$addonHelper = DI::addonHelper();
$services = [
'inbound' => [],
'outbound' => [],
];
if (Addon::isEnabled('bluesky')) {
if ($addonHelper->isAddonEnabled('bluesky')) {
$services['inbound'][] = 'bluesky';
$services['outbound'][] = 'bluesky';
}
if (Addon::isEnabled('dwpost')) {
if ($addonHelper->isAddonEnabled('dwpost')) {
$services['outbound'][] = 'dreamwidth';
}
if (Addon::isEnabled('statusnet')) {
if ($addonHelper->isAddonEnabled('statusnet')) {
$services['inbound'][] = 'gnusocial';
$services['outbound'][] = 'gnusocial';
}
if (Addon::isEnabled('ijpost')) {
if ($addonHelper->isAddonEnabled('ijpost')) {
$services['outbound'][] = 'insanejournal';
}
if (Addon::isEnabled('libertree')) {
if ($addonHelper->isAddonEnabled('libertree')) {
$services['outbound'][] = 'libertree';
}
if (Addon::isEnabled('ljpost')) {
if ($addonHelper->isAddonEnabled('ljpost')) {
$services['outbound'][] = 'livejournal';
}
if (Addon::isEnabled('pumpio')) {
if ($addonHelper->isAddonEnabled('pumpio')) {
$services['inbound'][] = 'pumpio';
$services['outbound'][] = 'pumpio';
}
$services['outbound'][] = 'smtp';
if (Addon::isEnabled('tumblr')) {
if ($addonHelper->isAddonEnabled('tumblr')) {
$services['outbound'][] = 'tumblr';
}
if (Addon::isEnabled('twitter')) {
if ($addonHelper->isAddonEnabled('twitter')) {
$services['outbound'][] = 'twitter';
}
if (Addon::isEnabled('wppost')) {
if ($addonHelper->isAddonEnabled('wppost')) {
$services['outbound'][] = 'wordpress';
}

View file

@ -8,8 +8,10 @@
namespace Friendica\Module;
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\KeyValueStorage\Capability\IManageKeyValuePairs;
use Friendica\Core\L10n;
@ -23,13 +25,27 @@ class Statistics extends BaseModule
protected $config;
/** @var IManageKeyValuePairs */
protected $keyValue;
private AddonHelper $addonHelper;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, IManageKeyValuePairs $keyValue, Response $response, array $server, array $parameters = [])
{
public function __construct(
L10n $l10n,
BaseURL $baseUrl,
Arguments $args,
LoggerInterface $logger,
Profiler $profiler,
IManageConfigValues $config,
IManageKeyValuePairs $keyValue,
AddonHelper $addonHelper,
Response $response,
array $server,
array $parameters = []
) {
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->config = $config;
$this->keyValue = $keyValue;
$this->addonHelper = $addonHelper;
if (!$this->config->get("system", "nodeinfo")) {
throw new NotFoundException();
}
@ -37,22 +53,21 @@ class Statistics extends BaseModule
protected function rawContent(array $request = [])
{
$registration_open =
Register::getPolicy() !== Register::CLOSED
$registration_open = Register::getPolicy() !== Register::CLOSED
&& !$this->config->get('config', 'invitation_only');
/// @todo mark the "service" addons and load them dynamically here
$services = [
'appnet' => Addon::isEnabled('appnet'),
'bluesky' => Addon::isEnabled('bluesky'),
'dreamwidth' => Addon::isEnabled('dreamwidth'),
'gnusocial' => Addon::isEnabled('gnusocial'),
'libertree' => Addon::isEnabled('libertree'),
'livejournal' => Addon::isEnabled('livejournal'),
'pumpio' => Addon::isEnabled('pumpio'),
'twitter' => Addon::isEnabled('twitter'),
'tumblr' => Addon::isEnabled('tumblr'),
'wordpress' => Addon::isEnabled('wordpress'),
'appnet' => $this->addonHelper->isAddonEnabled('appnet'),
'bluesky' => $this->addonHelper->isAddonEnabled('bluesky'),
'dreamwidth' => $this->addonHelper->isAddonEnabled('dreamwidth'),
'gnusocial' => $this->addonHelper->isAddonEnabled('gnusocial'),
'libertree' => $this->addonHelper->isAddonEnabled('libertree'),
'livejournal' => $this->addonHelper->isAddonEnabled('livejournal'),
'pumpio' => $this->addonHelper->isAddonEnabled('pumpio'),
'twitter' => $this->addonHelper->isAddonEnabled('twitter'),
'tumblr' => $this->addonHelper->isAddonEnabled('tumblr'),
'wordpress' => $this->addonHelper->isAddonEnabled('wordpress'),
];
$statistics = array_merge([

View file

@ -8,8 +8,10 @@
namespace Friendica\Module;
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\KeyValueStorage\Capability\IManageKeyValuePairs;
use Friendica\Core\L10n;
@ -40,14 +42,28 @@ class Stats extends BaseModule
protected $logger;
/** @var IManageKeyValuePairs */
protected $keyValue;
private AddonHelper $addonHelper;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, IManageKeyValuePairs $keyValue, Database $dba, Response $response, array $server, array $parameters = [])
{
public function __construct(
L10n $l10n,
BaseURL $baseUrl,
Arguments $args,
LoggerInterface $logger,
Profiler $profiler,
IManageConfigValues $config,
IManageKeyValuePairs $keyValue,
Database $dba,
AddonHelper $addonHelper,
Response $response,
array $server,
array $parameters = []
) {
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->config = $config;
$this->keyValue = $keyValue;
$this->dba = $dba;
$this->addonHelper = $addonHelper;
}
protected function content(array $request = []): string
@ -164,11 +180,11 @@ class Stats extends BaseModule
],
];
if (Addon::isEnabled('bluesky')) {
if ($this->addonHelper->isAddonEnabled('bluesky')) {
$statistics['packets']['inbound'][Protocol::BLUESKY] = intval($this->keyValue->get('stats_packets_inbound_' . Protocol::BLUESKY) ?? 0);
$statistics['packets']['outbound'][Protocol::BLUESKY] = intval($this->keyValue->get('stats_packets_outbound_' . Protocol::BLUESKY) ?? 0);
}
if (Addon::isEnabled('tumblr')) {
if ($this->addonHelper->isAddonEnabled('tumblr')) {
$statistics['packets']['inbound'][Protocol::TUMBLR] = intval($this->keyValue->get('stats_packets_inbound_' . Protocol::TUMBLR) ?? 0);
$statistics['packets']['outbound'][Protocol::TUMBLR] = intval($this->keyValue->get('stats_packets_outbound_' . Protocol::TUMBLR) ?? 0);
}

View file

@ -9,7 +9,6 @@ namespace Friendica\Object;
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
use Friendica\Core\Addon;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\DI;
@ -1118,12 +1117,14 @@ class Post
$conv = $this->getThread();
if ($conv->isWritable() && $this->isWritable()) {
$addonHelper = DI::addonHelper();
/*
* Hmmm, code depending on the presence of a particular addon?
* This should be better if done by a hook
*/
$qcomment = null;
if (Addon::isEnabled('qcomment')) {
if ($addonHelper->isAddonEnabled('qcomment')) {
$words = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'qcomment', 'words');
$qcomment = $words ? explode("\n", $words) : [];
}

View file

@ -14,9 +14,8 @@
* Description: "Vier" is a very compact and modern theme. It uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/
*/
use Friendica\App;
use Friendica\App\Mode;
use Friendica\Content\GroupManager;
use Friendica\Core\Addon;
use Friendica\Core\Renderer;
use Friendica\Core\Search;
use Friendica\Database\DBA;
@ -35,7 +34,7 @@ function vier_init()
$args = DI::args();
if (
DI::mode()->has(App\Mode::MAINTENANCEDISABLED)
DI::mode()->has(Mode::MAINTENANCEDISABLED)
&& (
$args->get(0) === 'profile' && $args->get(1) === (DI::userSession()->getLocalUserNickname() ?? '')
|| $args->get(0) === 'network' && DI::userSession()->getLocalUserId()
@ -244,55 +243,57 @@ function vier_community_info()
// connectable services
if ($show_services) {
$addonHelper = DI::addonHelper();
/// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
$r = [];
if (Addon::isEnabled("buffer")) {
if ($addonHelper->isAddonEnabled("buffer")) {
$r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
}
if (Addon::isEnabled("blogger")) {
if ($addonHelper->isAddonEnabled("blogger")) {
$r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
}
if (Addon::isEnabled("dwpost")) {
if ($addonHelper->isAddonEnabled("dwpost")) {
$r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
}
if (Addon::isEnabled("ifttt")) {
if ($addonHelper->isAddonEnabled("ifttt")) {
$r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
}
if (Addon::isEnabled("statusnet")) {
if ($addonHelper->isAddonEnabled("statusnet")) {
$r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
}
/// @TODO old-lost code (and below)?
//if (Addon::isEnabled("ijpost")) {
//if ($addonHelper->isAddonEnabled("ijpost")) {
// $r[] = array("photo" => "images/", "name" => "");
//}
if (Addon::isEnabled("libertree")) {
if ($addonHelper->isAddonEnabled("libertree")) {
$r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
}
//if (Addon::isEnabled("ljpost")) {
//if ($addonHelper->isAddonEnabled("ljpost")) {
// $r[] = array("photo" => "images/", "name" => "");
//}
if (Addon::isEnabled("pumpio")) {
if ($addonHelper->isAddonEnabled("pumpio")) {
$r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
}
if (Addon::isEnabled("tumblr")) {
if ($addonHelper->isAddonEnabled("tumblr")) {
$r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
}
if (Addon::isEnabled("twitter")) {
if ($addonHelper->isAddonEnabled("twitter")) {
$r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
}
if (Addon::isEnabled("wppost")) {
if ($addonHelper->isAddonEnabled("wppost")) {
$r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
}