Merge remote-tracking branch 'origin/develop' into task/obsolete-urlpath

This commit is contained in:
Philipp 2025-05-03 21:48:32 +02:00
commit b782ff6e22
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
32 changed files with 1138 additions and 646 deletions

View file

@ -35,10 +35,12 @@ class TrendingTags
}
$tpl = Renderer::getMarkupTemplate('widget/trending_tags.tpl');
$o = Renderer::replaceMacros($tpl, [
'$title' => DI::l10n()->tt('Trending Tags (last %d hour)', 'Trending Tags (last %d hours)', $period),
'$more' => DI::l10n()->t('More Trending Tags'),
'$tags' => $tags,
$o = Renderer::replaceMacros($tpl, [
'$title' => DI::l10n()->tt('Trending Tags (last %d hour)', 'Trending Tags (last %d hours)', $period),
'$more' => DI::l10n()->t('More Trending Tags'),
'$showmore' => DI::l10n()->t('Show More'),
'$showless' => DI::l10n()->t('Show Less'),
'$tags' => $tags,
]);
return $o;

View file

@ -51,6 +51,11 @@ class L10n
'zh-cn' => '简体中文',
];
const LANG_PARENTS = [
'en-gb' => 'en', 'da-dk' => 'da', 'fi-fi' => 'fi',
'nb-no' => 'nb', 'pt-br' => 'pt', 'zh-cn' => 'zh'
];
/** @var string Undetermined language */
const UNDETERMINED_LANGUAGE = 'un';
@ -150,6 +155,11 @@ class L10n
$a = new \stdClass();
$a->strings = [];
$child = array_search($lang, $this::LANG_PARENTS);
if ($child) {
$lang = $child;
}
// load enabled addons strings
$addons = array_keys($this->config->get('addons') ?? []);
foreach ($addons as $addon) {
@ -203,6 +213,8 @@ class L10n
// start with quality zero (every guessed language is more acceptable ..)
$current_q = 0;
$supported = self::getSupportedLanguages();
foreach ($acceptedLanguages as $acceptedLanguage) {
$res = preg_match(
'/^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i',
@ -230,8 +242,7 @@ class L10n
while (count($lang_code)) {
// try to mix them so we can get double-code parts too
$match_lang = strtolower(join('-', $lang_code));
if (file_exists(__DIR__ . "/../../view/lang/$match_lang") &&
is_dir(__DIR__ . "/../../view/lang/$match_lang")) {
if (in_array($match_lang, $supported)) {
if ($lang_quality > $current_q) {
$current_lang = $match_lang;
$current_q = $lang_quality;
@ -247,6 +258,20 @@ class L10n
return $current_lang;
}
private static function getSupportedLanguages(): array
{
$languages = [];
foreach (glob('view/lang/*/strings.php') as $language) {
$code = str_replace(['view/lang/', '/strings.php'], [], $language);
if (!empty(self::LANG_PARENTS[$code])) {
$languages[] = self::LANG_PARENTS[$code];
}
$languages[] = $code;
}
return $languages;
}
/**
* Return the localized version of the provided string with optional string interpolation
*
@ -402,8 +427,10 @@ class L10n
];
if (in_array('cld2', get_loaded_extensions())) {
$additional_langs = array_merge($additional_langs,
['dv', 'kn', 'lo', 'ml', 'or', 'pa', 'sd', 'si', 'te', 'yi']);
$additional_langs = array_merge(
$additional_langs,
['dv', 'kn', 'lo', 'ml', 'or', 'pa', 'sd', 'si', 'te', 'yi']
);
}
$langs = array_merge($additional_langs, array_keys($this->getAvailableLanguages()));
@ -419,7 +446,7 @@ class L10n
*/
public function getLanguageCodes(bool $international = false): array
{
$iso639 = new \Matriphe\ISO639\ISO639;
$iso639 = new \Matriphe\ISO639\ISO639();
// In ISO 639-2 undetermined languages have got the code "und".
// There is no official code for ISO 639-1, but "un" is not assigned to any language.
@ -477,13 +504,17 @@ class L10n
*/
public function getDay(string $s): string
{
$ret = str_replace(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
$ret = str_replace(
['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
[$this->t('Monday'), $this->t('Tuesday'), $this->t('Wednesday'), $this->t('Thursday'), $this->t('Friday'), $this->t('Saturday'), $this->t('Sunday')],
$s);
$s
);
$ret = str_replace(['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
$ret = str_replace(
['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
[$this->t('January'), $this->t('February'), $this->t('March'), $this->t('April'), $this->t('May'), $this->t('June'), $this->t('July'), $this->t('August'), $this->t('September'), $this->t('October'), $this->t('November'), $this->t('December')],
$ret);
$ret
);
return $ret;
}
@ -496,13 +527,17 @@ class L10n
*/
public function getDayShort(string $s): string
{
$ret = str_replace(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
$ret = str_replace(
['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
[$this->t('Mon'), $this->t('Tue'), $this->t('Wed'), $this->t('Thu'), $this->t('Fri'), $this->t('Sat'), $this->t('Sun')],
$s);
$s
);
$ret = str_replace(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
$ret = str_replace(
['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
[$this->t('Jan'), $this->t('Feb'), $this->t('Mar'), $this->t('Apr'), $this->t('May'), $this->t('Jun'), $this->t('Jul'), $this->t('Aug'), $this->t('Sep'), $this->t('Oct'), $this->t('Nov'), $this->t('Dec')],
$ret);
$ret
);
return $ret;
}

View file

@ -12,6 +12,8 @@ use Psr\Log\LogLevel;
/**
* Abstract class for creating logger types, which includes common necessary logic/content
*
* @deprecated 2025.02 Implement `\Friendica\Core\Logger\Factory\LoggerFactory` instead
*/
abstract class AbstractLoggerTypeFactory
{
@ -25,6 +27,8 @@ abstract class AbstractLoggerTypeFactory
*/
public function __construct(IHaveCallIntrospections $introspection, string $channel)
{
@trigger_error('Class `' . __CLASS__ . '` is deprecated since 2025.02 and will be removed after 5 months, implement `\Friendica\Core\Logger\Factory\LoggerFactory` instead.', E_USER_DEPRECATED);
$this->channel = $channel;
$this->introspection = $introspection;
}
@ -44,21 +48,21 @@ abstract class AbstractLoggerTypeFactory
// legacy WARNING
case "0":
return LogLevel::ERROR;
// legacy INFO
// legacy INFO
case "1":
return LogLevel::WARNING;
// legacy TRACE
// legacy TRACE
case "2":
return LogLevel::NOTICE;
// legacy DEBUG
// legacy DEBUG
case "3":
return LogLevel::INFO;
// legacy DATA
// legacy DATA
case "4":
// legacy ALL
// legacy ALL
case "5":
return LogLevel::DEBUG;
// default if nothing set
// default if nothing set
default:
return $level;
}

View file

@ -0,0 +1,73 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Core\Logger\Factory;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
/**
* Delegates the creation of a logger based on config to other factories
*
* @internal
*/
final class DelegatingLoggerFactory implements LoggerFactory
{
private IManageConfigValues $config;
/** @var array<string,LoggerFactory> */
private array $factories = [];
public function __construct(IManageConfigValues $config)
{
$this->config = $config;
}
public function registerFactory(string $name, LoggerFactory $factory): void
{
$this->factories[$name] = $factory;
}
/**
* Creates and returns a PSR-3 Logger instance.
*
* Calling this method multiple times with the same parameters SHOULD return the same object.
*
* @param \Psr\Log\LogLevel::* $logLevel The log level
* @param \Friendica\Core\Logger\Capability\LogChannel::* $logChannel The log channel
*/
public function createLogger(string $logLevel, string $logChannel): LoggerInterface
{
$factoryName = $this->config->get('system', 'logger_config') ?? '';
/**
* @deprecated 2025.02 The value `monolog` for `system.logger_config` inside the `config/local.config.php` file is deprecated, please use `stream` or `syslog` instead.
*/
if ($factoryName === 'monolog') {
@trigger_error('The config `system.logger_config` with value `monolog` is deprecated since 2025.02 and will stop working in 5 months, please change the value to `stream` or `syslog` in the `config/local.config.php` file.', \E_USER_DEPRECATED);
$factoryName = 'stream';
}
if (!array_key_exists($factoryName, $this->factories)) {
return new NullLogger();
}
$factory = $this->factories[$factoryName];
try {
$logger = $factory->createLogger($logLevel, $logChannel);
} catch (\Throwable $th) {
return new NullLogger();
}
return $logger;
}
}

View file

@ -1,61 +0,0 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Core\Logger\Factory;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hooks\Capability\ICanCreateInstances;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
/**
* Bridge for the legacy Logger factory.
*
* This class can be removed after the following classes are replaced or
* refactored implementing the `\Friendica\Core\Logger\Factory\LoggerFactory`:
*
* - Friendica\Core\Logger\Factory\StreamLogger
* - Friendica\Core\Logger\Factory\SyslogLogger
* - monolog addon: Friendica\Addon\monolog\src\Factory\Monolog
*
* @see \Friendica\Core\Logger\Factory\StreamLogger
* @see \Friendica\Core\Logger\Factory\SyslogLogger
*
* @internal
*/
final class LegacyLoggerFactory implements LoggerFactory
{
private ICanCreateInstances $instanceCreator;
private IManageConfigValues $config;
private Profiler $profiler;
public function __construct(ICanCreateInstances $instanceCreator, IManageConfigValues $config, Profiler $profiler)
{
$this->instanceCreator = $instanceCreator;
$this->config = $config;
$this->profiler = $profiler;
}
/**
* Creates and returns a PSR-3 Logger instance.
*
* Calling this method multiple times with the same parameters SHOULD return the same object.
*
* @param \Psr\Log\LogLevel::* $logLevel The log level
* @param \Friendica\Core\Logger\Capability\LogChannel::* $logChannel The log channel
*/
public function createLogger(string $logLevel, string $logChannel): LoggerInterface
{
$factory = new Logger($logChannel);
return $factory->create($this->instanceCreator, $this->config, $this->profiler);
}
}

View file

@ -18,6 +18,8 @@ use Throwable;
/**
* The logger factory for the core logging instances
*
* @deprecated 2025.02 Implement `\Friendica\Core\Logger\Factory\LoggerFactory` instead
*/
class Logger
{
@ -26,6 +28,8 @@ class Logger
public function __construct(string $channel = LogChannel::DEFAULT)
{
@trigger_error('Class `' . __CLASS__ . '` is deprecated since 2025.02 and will be removed after 5 months, implement `\Friendica\Core\Logger\Factory\LoggerFactory` instead.', E_USER_DEPRECATED);
$this->channel = $channel;
}

View file

@ -20,6 +20,8 @@ use Psr\Log\NullLogger;
/**
* The logger factory for the StreamLogger instance
*
* @deprecated 2025.02 Implement `\Friendica\Core\Logger\Factory\LoggerFactory` instead
* @see StreamLoggerFactory
* @see StreamLoggerClass
*/
class StreamLogger extends AbstractLoggerTypeFactory
@ -38,6 +40,8 @@ class StreamLogger extends AbstractLoggerTypeFactory
*/
public function create(IManageConfigValues $config, string $logfile = null, string $channel = null): LoggerInterface
{
@trigger_error('Class `' . __CLASS__ . '` is deprecated since 2025.02 and will be removed after 5 months, implement `\Friendica\Core\Logger\Factory\LoggerFactory` instead.', E_USER_DEPRECATED);
$fileSystem = new FileSystem();
$logfile = $logfile ?? $config->get('system', 'logfile');

View file

@ -0,0 +1,76 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Core\Logger\Factory;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Logger\Capability\IHaveCallIntrospections;
use Friendica\Core\Logger\Exception\LoggerArgumentException;
use Friendica\Core\Logger\Exception\LogLevelException;
use Friendica\Core\Logger\Type\StreamLogger;
use Friendica\Core\Logger\Util\FileSystemUtil;
use Psr\Log\LoggerInterface;
/**
* The logger factory for the StreamLogger instance
*
* @see StreamLogger
*
* @internal
*/
final class StreamLoggerFactory implements LoggerFactory
{
private IManageConfigValues $config;
private IHaveCallIntrospections $introspection;
private FileSystemUtil $fileSystem;
public function __construct(
IManageConfigValues $config,
IHaveCallIntrospections $introspection,
FileSystemUtil $fileSystem
) {
$this->config = $config;
$this->introspection = $introspection;
$this->fileSystem = $fileSystem;
}
/**
* Creates and returns a PSR-3 Logger instance.
*
* Calling this method multiple times with the same parameters SHOULD return the same object.
*
* @param \Psr\Log\LogLevel::* $logLevel The log level
* @param \Friendica\Core\Logger\Capability\LogChannel::* $logChannel The log channel
*
* @throws LoggerArgumentException
* @throws LogLevelException
*/
public function createLogger(string $logLevel, string $logChannel): LoggerInterface
{
$logfile = $this->config->get('system', 'logfile');
if (!file_exists($logfile) || !is_writable($logfile)) {
throw new LoggerArgumentException(sprintf('"%s" is not a valid logfile.', $logfile));
}
if (! array_key_exists($logLevel, StreamLogger::levelToInt)) {
throw new LogLevelException(sprintf('The log level "%s" is not supported by "%s".', $logLevel, StreamLogger::class));
}
return new StreamLogger(
$logChannel,
$this->introspection,
$this->fileSystem->createStream($logfile),
StreamLogger::levelToInt[$logLevel],
getmypid()
);
}
}

View file

@ -16,6 +16,8 @@ use Psr\Log\LoggerInterface;
/**
* The logger factory for the SyslogLogger instance
*
* @deprecated 2025.02 Implement `\Friendica\Core\Logger\Factory\LoggerFactory` instead
* @see SyslogLoggerFactory
* @see SyslogLoggerClass
*/
class SyslogLogger extends AbstractLoggerTypeFactory
@ -31,6 +33,8 @@ class SyslogLogger extends AbstractLoggerTypeFactory
*/
public function create(IManageConfigValues $config): LoggerInterface
{
@trigger_error('Class `' . __CLASS__ . '` is deprecated since 2025.02 and will be removed after 5 months, implement `\Friendica\Core\Logger\Factory\LoggerFactory` instead.', E_USER_DEPRECATED);
$logOpts = $config->get('system', 'syslog_flags') ?? SyslogLoggerClass::DEFAULT_FLAGS;
$logFacility = $config->get('system', 'syslog_facility') ?? SyslogLoggerClass::DEFAULT_FACILITY;
$loglevel = SyslogLogger::mapLegacyConfigDebugLevel($config->get('system', 'loglevel'));

View file

@ -0,0 +1,66 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Core\Logger\Factory;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Logger\Capability\IHaveCallIntrospections;
use Friendica\Core\Logger\Exception\LogLevelException;
use Friendica\Core\Logger\Type\SyslogLogger;
use Psr\Log\LoggerInterface;
/**
* The logger factory for the SyslogLogger instance
*
* @see SyslogLogger
*
* @internal
*/
final class SyslogLoggerFactory implements LoggerFactory
{
private IManageConfigValues $config;
private IHaveCallIntrospections $introspection;
public function __construct(
IManageConfigValues $config,
IHaveCallIntrospections $introspection
) {
$this->config = $config;
$this->introspection = $introspection;
}
/**
* Creates and returns a PSR-3 Logger instance.
*
* Calling this method multiple times with the same parameters SHOULD return the same object.
*
* @param \Psr\Log\LogLevel::* $logLevel The log level
* @param \Friendica\Core\Logger\Capability\LogChannel::* $logChannel The log channel
*
* @throws LogLevelException
*/
public function createLogger(string $logLevel, string $logChannel): LoggerInterface
{
$logOpts = (string) $this->config->get('system', 'syslog_flags') ?? SyslogLogger::DEFAULT_FLAGS;
$logFacility = (string) $this->config->get('system', 'syslog_facility') ?? SyslogLogger::DEFAULT_FACILITY;
if (!array_key_exists($logLevel, SyslogLogger::logLevels)) {
throw new LogLevelException(sprintf('The log level "%s" is not supported by "%s".', $logLevel, SyslogLogger::class));
}
return new SyslogLogger(
$logChannel,
$this->introspection,
(string) SyslogLogger::logLevels[$logLevel],
$logOpts,
$logFacility
);
}
}

View file

@ -208,7 +208,7 @@ class ErrorHandler
*/
private function handleException(Throwable $e): void
{
$level = LogLevel::ERROR;
$level = LogLevel::CRITICAL;
foreach ($this->uncaughtExceptionLevelMap as $class => $candidate) {
if ($e instanceof $class) {
$level = $candidate;

View file

@ -12,7 +12,7 @@ use Friendica\Core\Logger\Exception\LoggerUnusableException;
/**
* Util class for filesystem manipulation for Logger classes
*/
class FileSystem
class FileSystem implements FileSystemUtil
{
/**
* @var string a error message
@ -31,7 +31,7 @@ class FileSystem
public function createDir(string $file): string
{
$dirname = null;
$pos = strpos($file, '://');
$pos = strpos($file, '://');
if (!$pos) {
$dirname = realpath(dirname($file));

View file

@ -0,0 +1,40 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace Friendica\Core\Logger\Util;
use Friendica\Core\Logger\Exception\LoggerUnusableException;
/**
* interface for Util class for filesystem manipulation for Logger classes
*
* @internal
*/
interface FileSystemUtil
{
/**
* Creates a directory based on a file, which gets accessed
*
* @param string $file The file
*
* @return string The directory name (empty if no directory is found, like urls)
*
* @throws LoggerUnusableException
*/
public function createDir(string $file): string;
/**
* Creates a stream based on a URL (could be a local file or a real URL)
*
* @param string $url The file/url
*
* @return resource the open stream resource
*
* @throws LoggerUnusableException
*/
public function createStream(string $url);
}

View file

@ -397,7 +397,7 @@ class Event
{
// First day of the week (0 = Sunday).
$firstDay = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'first_day_of_week') ?? 0;
$defaultView = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'defaultView') ?? 'month';
$defaultView = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'default_view') ?? 'month';
return [
'firstDay' => $firstDay,

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;
/**
@ -26,13 +24,14 @@ class Nodeinfo
*/
public static function update()
{
$config = DI::config();
$logger = DI::logger();
$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'))) {
@ -50,12 +49,12 @@ class Nodeinfo
$logger->info('user statistics - done', $userStats);
$posts = DBA::count('post-thread', ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin`)"]);
$posts = DBA::count('post-thread', ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin`)"]);
$comments = DBA::count('post', ["NOT `deleted` AND `gravity` = ? AND `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)", Item::GRAVITY_COMMENT]);
DI::keyValue()->set('nodeinfo_local_posts', $posts);
DI::keyValue()->set('nodeinfo_local_comments', $comments);
$posts = DBA::count('post', ['deleted' => false, 'gravity' => Item::GRAVITY_COMMENT]);
$posts = DBA::count('post', ['deleted' => false, 'gravity' => Item::GRAVITY_COMMENT]);
$comments = DBA::count('post', ['deleted' => false, 'gravity' => Item::GRAVITY_COMMENT]);
DI::keyValue()->set('nodeinfo_total_posts', $posts);
DI::keyValue()->set('nodeinfo_total_comments', $comments);
@ -66,21 +65,21 @@ 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 = new stdClass();
$usage->users = new stdClass();
if (!empty($config->get('system', 'nodeinfo'))) {
$usage->users->total = intval(DI::keyValue()->get('nodeinfo_total_users'));
$usage->users->total = intval(DI::keyValue()->get('nodeinfo_total_users'));
$usage->users->activeHalfyear = intval(DI::keyValue()->get('nodeinfo_active_users_halfyear'));
$usage->users->activeMonth = intval(DI::keyValue()->get('nodeinfo_active_users_monthly'));
$usage->localPosts = intval(DI::keyValue()->get('nodeinfo_local_posts'));
$usage->localComments = intval(DI::keyValue()->get('nodeinfo_local_comments'));
$usage->users->activeMonth = intval(DI::keyValue()->get('nodeinfo_active_users_monthly'));
$usage->localPosts = intval(DI::keyValue()->get('nodeinfo_local_posts'));
$usage->localComments = intval(DI::keyValue()->get('nodeinfo_local_comments'));
if ($version2) {
$usage->users->activeWeek = intval(DI::keyValue()->get('nodeinfo_active_users_weekly'));
@ -97,45 +96,47 @@ class Nodeinfo
*/
public static function getServices(): array
{
$addonHelper = DI::addonHelper();
$services = [
'inbound' => [],
'outbound' => [],
];
if (Addon::isEnabled('bluesky')) {
$services['inbound'][] = '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')) {
$services['inbound'][] = 'gnusocial';
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')) {
$services['inbound'][] = '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

@ -130,6 +130,7 @@ class Photo extends BaseApi
$photo = MPhoto::getPhoto($photoid, $scale, self::getCurrentUserID());
if ($photo === false) {
$this->logger->notice('Photo was not loaded', ['parameters' => $this->parameters, 'id' => $photoid]);
throw new HTTPException\NotFoundException(DI::l10n()->t('The Photo with id %s is not available.', $photoid));
}
}
@ -137,6 +138,7 @@ class Photo extends BaseApi
$fetch = microtime(true) - $stamp;
if ($photo === false) {
$this->logger->notice('Photo was not loaded', ['parameters' => $this->parameters]);
throw new HTTPException\NotFoundException();
}
@ -151,6 +153,7 @@ class Photo extends BaseApi
$mimetype = $photo['type'];
}
if (empty($imgdata) && empty($photo['blurhash'])) {
$this->logger->notice('Image data was not loaded', ['parameters' => $this->parameters, 'class' => $photo['backend-class'], 'ref' => $photo['backend-ref']]);
throw new HTTPException\NotFoundException();
}
@ -317,7 +320,11 @@ class Photo extends BaseApi
$photo = MPhoto::selectFirst([], ['scale' => $scale, 'uid' => $contact['uid'], 'profile' => 1]);
if (!empty($photo)) {
return $photo;
} else {
$this->logger->notice('Profile photo was not loaded', ['scale' => $scale, 'uid' => $contact['uid']]);
}
} else {
$this->logger->notice('Local Contact was not found', ['url' => $contact['nurl']]);
}
}
@ -333,6 +340,7 @@ class Photo extends BaseApi
if (!empty($photo)) {
return $photo;
} else {
$this->logger->notice('Photo was not loaded', ['resource-id' => $resourceid]);
$url = $contact['avatar'];
}
} else {
@ -340,6 +348,8 @@ class Photo extends BaseApi
}
} elseif (!empty($contact['avatar'])) {
$url = $contact['avatar'];
} else {
$url = '';
}
// If it is a local link, we save resources by just redirecting to it.
@ -381,8 +391,6 @@ class Photo extends BaseApi
}
}
$url = '';
if (empty($mimetext) && !empty($contact['blurhash'])) {
$image = new Image('', image_type_to_mime_type(IMAGETYPE_WEBP));
$image->getFromBlurHash($contact['blurhash'], $customsize, $customsize);

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->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->config = $config;
$this->keyValue = $keyValue;
$this->dba = $dba;
$this->addonHelper = $addonHelper;
}
protected function content(array $request = []): string
@ -85,14 +101,14 @@ class Stats extends BaseModule
'datetime' => DateTimeFormat::utc($this->keyValue->get('last_worker_execution'), DateTimeFormat::JSON),
'timestamp' => strtotime($this->keyValue->get('last_worker_execution')),
],
'jpm' => [
'jpm' => [
1 => $this->dba->count('workerqueue', ["`done` AND `executed` > ?", DateTimeFormat::utc('now - 1 minute')]),
3 => round($this->dba->count('workerqueue', ["`done` AND `executed` > ?", DateTimeFormat::utc('now - 3 minute')]) / 3),
5 => round($this->dba->count('workerqueue', ["`done` AND `executed` > ?", DateTimeFormat::utc('now - 5 minute')]) / 5),
],
'active' => [],
'deferred' => [],
'total' => [],
'active' => [],
'deferred' => [],
'total' => [],
],
'jetstream' => [
'drift' => intval($this->keyValue->get('jetstream_drift')),
@ -145,14 +161,14 @@ class Stats extends BaseModule
'closed' => $this->dba->count('report', ['status' => Report::STATUS_CLOSED]),
],
'update' => [
'available' => Update::isAvailable(),
'available' => Update::isAvailable(),
'available_version' => Update::getAvailableVersion(),
'status' => Update::getStatus(),
'db_status' => DBStructure::getUpdateStatus(),
'db_status' => DBStructure::getUpdateStatus(),
],
'server' => [
'version' => App::VERSION,
'php' => [
'version' => App::VERSION,
'php' => [
'version' => phpversion(),
'upload_max_filesize' => ini_get('upload_max_filesize'),
'post_max_size' => ini_get('post_max_size'),
@ -164,12 +180,12 @@ class Stats extends BaseModule
],
];
if (Addon::isEnabled('bluesky')) {
$statistics['packets']['inbound'][Protocol::BLUESKY] = intval($this->keyValue->get('stats_packets_inbound_' . Protocol::BLUESKY) ?? 0);
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')) {
$statistics['packets']['inbound'][Protocol::TUMBLR] = intval($this->keyValue->get('stats_packets_inbound_' . Protocol::TUMBLR) ?? 0);
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);
}
@ -202,7 +218,7 @@ class Stats extends BaseModule
$jobs = $this->dba->p("SELECT COUNT(*) AS `entries`, `priority` FROM `workerqueue` WHERE NOT `done` AND `retrial` = ? GROUP BY `priority`", 0);
while ($entry = $this->dba->fetch($jobs)) {
$running = $this->dba->count('workerqueue-view', ['priority' => $entry['priority']]);
$running = $this->dba->count('workerqueue-view', ['priority' => $entry['priority']]);
$statistics['worker']['active']['total'] += $running;
$statistics['worker']['active'][$entry['priority']] = $running;
$statistics['worker']['total']['total'] += $entry['entries'];

View file

@ -1729,7 +1729,7 @@ class Probe
$data = [
'network' => Protocol::BLUESKY,
'url' => $profile->did,
'alias' => ATProtocol::WEB . '/profile/' . $nick,
'alias' => ATProtocol::WEB . '/profile/' . $profile->did,
'name' => $name ?: $nick,
'nick' => $nick,
'addr' => $nick,

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

@ -117,7 +117,7 @@ class Actor
$name = $profile->displayName ?? $nick;
$fields = [
'alias' => ATProtocol::WEB . '/profile/' . $nick,
'alias' => ATProtocol::WEB . '/profile/' . $profile->did,
'name' => $name ?: $nick,
'nick' => $nick,
'addr' => $nick,

View file

@ -72,7 +72,7 @@ class Processor
public function processIdentity(stdClass $data)
{
$fields = [
'alias' => ATProtocol::WEB . '/profile/' . $data->identity->handle,
'alias' => ATProtocol::WEB . '/profile/' . $data->identity->did,
'nick' => $data->identity->handle,
'addr' => $data->identity->handle,
'updated' => DateTimeFormat::utc($data->identity->time, DateTimeFormat::MYSQL),
@ -327,7 +327,7 @@ class Processor
private function getHeaderFromJetstream(stdClass $data, int $uid, int $protocol = Conversation::PARCEL_JETSTREAM): array
{
$contact = $this->actor->getContactByDID($data->did, $uid, 0);
$contact = $this->actor->getContactByDID($data->did, $uid, 0, true);
if (empty($contact)) {
$this->logger->info('Contact not found for user', ['did' => $data->did, 'uid' => $uid]);
return [];
@ -392,7 +392,7 @@ class Processor
if (empty($post->author) || empty($post->cid) || empty($parts->rkey)) {
return [];
}
$contact = $this->actor->getContactByDID($post->author->did, $uid, 0);
$contact = $this->actor->getContactByDID($post->author->did, $uid, 0, true);
if (empty($contact)) {
$this->logger->info('Contact not found for user', ['did' => $post->author->did, 'uid' => $uid]);
return [];

View file

@ -339,7 +339,8 @@ return [
'lock_driver' => '',
// logger_config (String)
// Sets the logging adapter of Friendica globally (monolog, syslog, stream)
// Sets the logging adapter of Friendica globally (syslog, stream)
// @deprecated 2025.02 The value `monolog` is deprecated, please use `stream` or `syslog` instead.
'logger_config' => 'stream',
// syslog_flags (Integer)

View file

@ -171,11 +171,24 @@ return (function(string $basepath, array $getVars, array $serverVars, array $coo
],
\Friendica\Core\Logger\LoggerManager::class => [
'substitutions' => [
\Friendica\Core\Logger\Factory\LoggerFactory::class => \Friendica\Core\Logger\Factory\LegacyLoggerFactory::class,
\Friendica\Core\Logger\Factory\LoggerFactory::class => \Friendica\Core\Logger\Factory\DelegatingLoggerFactory::class,
],
],
\Friendica\Core\Logger\Factory\LoggerFactory::class => [
'instanceOf' => \Friendica\Core\Logger\Factory\LegacyLoggerFactory::class,
'instanceOf' => \Friendica\Core\Logger\Factory\DelegatingLoggerFactory::class,
'call' => [
['registerFactory', ['stream', [Dice::INSTANCE => '$StreamLoggerFactory']]],
['registerFactory', ['syslog', [Dice::INSTANCE => '$SyslogLoggerFactory']]],
],
],
'$StreamLoggerFactory' => [
'instanceOf' => \Friendica\Core\Logger\Factory\StreamLoggerFactory::class,
'substitutions' => [
\Friendica\Core\Logger\Util\FileSystemUtil::class => \Friendica\Core\Logger\Util\FileSystem::class,
],
],
'$SyslogLoggerFactory' => [
'instanceOf' => \Friendica\Core\Logger\Factory\SyslogLoggerFactory::class,
],
\Friendica\Core\Logger\Type\SyslogLogger::class => [
'instanceOf' => \Friendica\Core\Logger\Factory\SyslogLogger::class,

View file

@ -0,0 +1,75 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Test\Unit\Core\Logger\Factory;
use Exception;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Logger\Capability\LogChannel;
use Friendica\Core\Logger\Factory\DelegatingLoggerFactory;
use Friendica\Core\Logger\Factory\LoggerFactory;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Psr\Log\NullLogger;
class DelegatingLoggerFactoryTest extends TestCase
{
public function testCreateLoggerReturnsPsrLogger(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'logger_config', null, 'test'],
]);
$factory = new DelegatingLoggerFactory($config);
$factory->registerFactory('test', $this->createStub(LoggerFactory::class));
$this->assertInstanceOf(
LoggerInterface::class,
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
);
}
public function testCreateLoggerWithoutRegisteredFactoryReturnsNullLogger(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'logger_config', null, 'not-existing-factory'],
]);
$factory = new DelegatingLoggerFactory($config);
$this->assertInstanceOf(
NullLogger::class,
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
);
}
public function testCreateLoggerWithExceptionThrowingFactoryReturnsNullLogger(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'logger_config', null, 'test'],
]);
$factory = new DelegatingLoggerFactory($config);
$brokenFactory = $this->createStub(LoggerFactory::class);
$brokenFactory->method('createLogger')->willThrowException(new Exception());
$factory->registerFactory('test', $brokenFactory);
$this->assertInstanceOf(
NullLogger::class,
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
);
}
}

View file

@ -1,36 +0,0 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Test\Unit\Core\Logger\Factory;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Hooks\Capability\ICanCreateInstances;
use Friendica\Core\Logger\Capability\LogChannel;
use Friendica\Core\Logger\Factory\LegacyLoggerFactory;
use Friendica\Util\Profiler;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
class LegacyLoggerFactoryTest extends TestCase
{
public function testCreateLoggerReturnsPsrLogger(): void
{
$factory = new LegacyLoggerFactory(
$this->createStub(ICanCreateInstances::class),
$this->createStub(IManageConfigValues::class),
$this->createStub(Profiler::class),
);
$this->assertInstanceOf(
LoggerInterface::class,
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
);
}
}

View file

@ -0,0 +1,81 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Test\Unit\Core\Logger\Factory;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Logger\Capability\IHaveCallIntrospections;
use Friendica\Core\Logger\Capability\LogChannel;
use Friendica\Core\Logger\Exception\LoggerArgumentException;
use Friendica\Core\Logger\Exception\LogLevelException;
use Friendica\Core\Logger\Factory\StreamLoggerFactory;
use Friendica\Core\Logger\Util\FileSystemUtil;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
class StreamLoggerFactoryTest extends TestCase
{
public function testCreateLoggerReturnsPsrLogger(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'logfile', null, dirname(__DIR__, 4) . '/datasets/log/empty.friendica.log.txt'],
]);
$factory = new StreamLoggerFactory(
$config,
$this->createStub(IHaveCallIntrospections::class),
$this->createStub(FileSystemUtil::class),
);
$this->assertInstanceOf(
LoggerInterface::class,
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
);
}
public function testCreateLoggerWithInvalidLogfileThrowsException(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'logfile', null, dirname(__DIR__, 1) . '/not-existing-logfile.txt'],
]);
$factory = new StreamLoggerFactory(
$config,
$this->createStub(IHaveCallIntrospections::class),
$this->createStub(FileSystemUtil::class),
);
$this->expectException(LoggerArgumentException::class);
$this->expectExceptionMessage('tests/Unit/Core/Logger/not-existing-logfile.txt" is not a valid logfile.');
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT);
}
public function testCreateLoggerWithInvalidLoglevelThrowsException(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'logfile', null, dirname(__DIR__, 4) . '/datasets/log/empty.friendica.log.txt'],
]);
$factory = new StreamLoggerFactory(
$config,
$this->createStub(IHaveCallIntrospections::class),
$this->createStub(FileSystemUtil::class),
);
$this->expectException(LogLevelException::class);
$this->expectExceptionMessage('The log level "unsupported-loglevel" is not supported by "Friendica\Core\Logger\Type\StreamLogger".');
$factory->createLogger('unsupported-loglevel', LogChannel::DEFAULT);
}
}

View file

@ -0,0 +1,61 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types=1);
namespace Friendica\Test\Unit\Core\Logger\Factory;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Logger\Capability\IHaveCallIntrospections;
use Friendica\Core\Logger\Capability\LogChannel;
use Friendica\Core\Logger\Exception\LogLevelException;
use Friendica\Core\Logger\Factory\SyslogLoggerFactory;
use Friendica\Core\Logger\Type\SyslogLogger;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
class SyslogLoggerFactoryTest extends TestCase
{
public function testCreateLoggerReturnsPsrLogger(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'syslog_flags', null, SyslogLogger::DEFAULT_FLAGS],
['system', 'syslog_facility', null, SyslogLogger::DEFAULT_FACILITY],
]);
$factory = new SyslogLoggerFactory(
$config,
$this->createStub(IHaveCallIntrospections::class),
);
$this->assertInstanceOf(
LoggerInterface::class,
$factory->createLogger(LogLevel::DEBUG, LogChannel::DEFAULT)
);
}
public function testCreateLoggerWithInvalidLoglevelThrowsException(): void
{
$config = $this->createStub(IManageConfigValues::class);
$config->method('get')->willReturnMap([
['system', 'syslog_flags', null, SyslogLogger::DEFAULT_FLAGS],
['system', 'syslog_facility', null, SyslogLogger::DEFAULT_FACILITY],
]);
$factory = new SyslogLoggerFactory(
$config,
$this->createStub(IHaveCallIntrospections::class),
);
$this->expectException(LogLevelException::class);
$this->expectExceptionMessage('The log level "unsupported-loglevel" is not supported by "Friendica\Core\Logger\Type\SyslogLogger".');
$factory->createLogger('unsupported-loglevel', LogChannel::DEFAULT);
}
}

File diff suppressed because it is too large Load diff

View file

@ -27,7 +27,7 @@
<div style="text-align: left; margin-top: 10px;">
<a href="#" onclick="toggleTags(event)" role="button" aria-expanded="false" aria-controls="more-tags" style="text-decoration: none; color: inherit; cursor: pointer; display: inline-flex; align-items: center; font-weight: bold;">
<i id="caret-icon" class="fa fa-caret-right" aria-hidden="true" style="margin-right: 5px;"></i>
<span id="link-text">Show More</span>
<span id="link-text">{{$showmore}}</span>
</a>
</div>
<ul id="more-tags" style="display:none; list-style-type: none; padding: 0; margin: 0;">
@ -53,16 +53,16 @@
if (moreTags.style.display === 'none') {
moreTags.style.display = 'block';
linkText.textContent = 'Show Less';
linkText.textContent = '{{$showless}}';
link.setAttribute('aria-expanded', 'true');
caretIcon.className = 'fa fa-caret-down';
} else {
moreTags.style.display = 'none';
linkText.textContent = 'Show More';
linkText.textContent = '{{$showmore}}';
link.setAttribute('aria-expanded', 'false');
caretIcon.className = 'fa fa-caret-right';
}
}
initWidget('trending-tags-sidebar', 'trending-tags-sidebar-inflated');
</script>
</script>

View file

@ -61,7 +61,7 @@
{{if $nav.network}}
<li class="nav-segment">
<a accesskey="n" class="nav-menu {{$sel.network}}" href="{{$nav.network.0}}"
data-toggle="tooltip" aria-label="{{$nav.network.3}}" title="{{$nav.network.3}}"><i
data-toggle="tooltip" data-viewport="#topbar-first" aria-label="{{$nav.network.3}}" title="{{$nav.network.3}}"><i
class="fa fa-lg fa-th fa-fw" aria-hidden="true"></i><span id="net-update"
class="nav-network-badge badge nav-notification"></span></a>
</li>
@ -70,14 +70,14 @@
{{if $nav.channel}}
<li class="nav-segment">
<a accesskey="l" class="nav-menu {{$sel.channel}}" href="{{$nav.channel.0}}"
data-toggle="tooltip" aria-label="{{$nav.channel.3}}" title="{{$nav.channel.3}}"><i
data-toggle="tooltip" data-viewport="#topbar-first" aria-label="{{$nav.channel.3}}" title="{{$nav.channel.3}}"><i
class="fa fa-lg fa-newspaper-o fa-fw" aria-hidden="true"></i></a>
</li>
{{/if}}
{{if $nav.home}}
<li class="nav-segment">
<a accesskey="p" class="nav-menu {{$sel.home}}" href="{{$nav.home.0}}" data-toggle="tooltip"
<a accesskey="p" class="nav-menu {{$sel.home}}" href="{{$nav.home.0}}" data-toggle="tooltip" data-viewport="#topbar-first"
aria-label="{{$nav.home.3}}" title="{{$nav.home.3}}"><i class="fa fa-lg fa-home fa-fw"
aria-hidden="true"></i><span id="home-update"
class="nav-home-badge badge nav-notification"></span></a>
@ -87,14 +87,14 @@
{{if $nav.community}}
<li class="nav-segment">
<a accesskey="c" class="nav-menu {{$sel.community}}" href="{{$nav.community.0}}"
data-toggle="tooltip" aria-label="{{$nav.community.3}}" title="{{$nav.community.3}}"><i
data-toggle="tooltip" data-viewport="#topbar-first" aria-label="{{$nav.community.3}}" title="{{$nav.community.3}}"><i
class="fa fa-lg fa-bullseye fa-fw" aria-hidden="true"></i></a>
</li>
{{/if}}
{{if $nav.messages}}
<li class="nav-segment hidden-xs">
<a accesskey="m" id="nav-messages-link" href="{{$nav.messages.0}}" data-toggle="tooltip"
<a accesskey="m" id="nav-messages-link" href="{{$nav.messages.0}}" data-toggle="tooltip" data-viewport="#topbar-first"
aria-label="{{$nav.messages.1}}" title="{{$nav.messages.1}}"
class="nav-menu {{$sel.messages}}"><i class="fa fa-envelope fa-lg fa-fw"
aria-hidden="true"></i><span id="mail-update"
@ -104,7 +104,7 @@
{{if $nav.calendar}}
<li class="nav-segment hidden-xs">
<a accesskey="e" id="nav-calendar-link" href="{{$nav.calendar.0}}" data-toggle="tooltip"
<a accesskey="e" id="nav-calendar-link" href="{{$nav.calendar.0}}" data-toggle="tooltip" data-viewport="#topbar-first"
aria-label="{{$nav.calendar.1}}" title="{{$nav.calendar.1}}" class="nav-menu"><i
class="fa fa-lg fa-calendar fa-fw"></i></a>
</li>
@ -112,7 +112,7 @@
{{if $nav.contacts}}
<li class="nav-segment hidden-xs">
<a accesskey="k" id="nav-contacts-link" href="{{$nav.contacts.0}}" data-toggle="tooltip"
<a accesskey="k" id="nav-contacts-link" href="{{$nav.contacts.0}}" data-toggle="tooltip" data-viewport="#topbar-first"
aria-label="{{$nav.contacts.1}}" title="{{$nav.contacts.1}}"
class="nav-menu {{$sel.contacts}} {{$nav.contacts.2}}"><i
class="fa fa-users fa-lg fa-fw"></i></a>
@ -503,7 +503,7 @@
<form class="navbar-form" role="search" method="get" action="{{$nav.search.0}}">
<div class="form-group form-group-search">
<input id="nav-search-input-field-mobile" class="form-control form-search" type="text" name="q"
data-toggle="tooltip" title="{{$search_hint}}" placeholder="{{$nav.search.1}}">
data-toggle="tooltip" data-viewport="#topbar-first" title="{{$search_hint}}" placeholder="{{$nav.search.1}}">
<button class="btn btn-default btn-sm form-button-search" type="submit">{{$nav.search.1}}</button>
</div>
</form>

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()
@ -93,7 +92,7 @@ EOT;
// Hide the left menu bar
/// @TODO maybe move this static array out where it should belong?
if (empty(DI::page()['aside']) && in_array($args->get(0), ["community", "calendar", "help", "delegation", "notifications",
"probe", "webfinger", "login", "invite", "credits"])) {
"probe", "webfinger", "login", "invite", "credits"])) {
DI::page()['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
}
}
@ -117,12 +116,12 @@ function get_vier_config($key, $default = false, $admin = false)
function vier_community_info()
{
$show_pages = get_vier_config("show_pages", 1);
$show_profiles = get_vier_config("show_profiles", 1);
$show_helpers = get_vier_config("show_helpers", 1);
$show_services = get_vier_config("show_services", 1);
$show_friends = get_vier_config("show_friends", 1);
$show_lastusers = get_vier_config("show_lastusers", 1);
$show_pages = get_vier_config("show_pages", 1);
$show_profiles = get_vier_config("show_profiles", 1);
$show_helpers = get_vier_config("show_helpers", 1);
$show_services = get_vier_config("show_services", 1);
$show_friends = get_vier_config("show_friends", 1);
$show_lastusers = get_vier_config("show_lastusers", 1);
// get_baseurl
$aside['$url'] = $url = (string)DI::baseUrl();
@ -138,10 +137,10 @@ function vier_community_info()
foreach ($contacts as $contact) {
$entry = Renderer::replaceMacros($tpl, [
'$id' => $contact['id'],
'$id' => $contact['id'],
'$profile_link' => 'contact/follow?url=' . urlencode($contact['url']),
'$photo' => Contact::getMicro($contact),
'$alt_text' => $contact['name'],
'$photo' => Contact::getMicro($contact),
'$alt_text' => $contact['name'],
]);
$aside['$community_profiles_items'][] = $entry;
}
@ -165,11 +164,11 @@ function vier_community_info()
foreach ($profiles as $profile) {
$profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
$entry = Renderer::replaceMacros($tpl, [
'$id' => $profile['id'],
$entry = Renderer::replaceMacros($tpl, [
'$id' => $profile['id'],
'$profile_link' => $profile_link,
'$photo' => DI::baseUrl()->remove($profile['thumb']),
'$alt_text' => $profile['name']]);
'$photo' => DI::baseUrl()->remove($profile['thumb']),
'$alt_text' => $profile['name']]);
$aside['$lastusers_items'][] = $entry;
}
}
@ -177,18 +176,18 @@ function vier_community_info()
//right_aside FIND FRIENDS
if ($show_friends && DI::userSession()->getLocalUserId()) {
$nv = [];
$nv['findpeople'] = DI::l10n()->t('Find People');
$nv['desc'] = DI::l10n()->t('Enter name or interest');
$nv['label'] = DI::l10n()->t('Connect/Follow');
$nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
$nv['findthem'] = DI::l10n()->t('Find');
$nv['suggest'] = DI::l10n()->t('Friend Suggestions');
$nv['similar'] = DI::l10n()->t('Similar Interests');
$nv['random'] = DI::l10n()->t('Random Profile');
$nv['inv'] = DI::l10n()->t('Invite Friends');
$nv['directory'] = DI::l10n()->t('Global Directory');
$nv['global_dir'] = Search::getGlobalDirectory();
$nv = [];
$nv['findpeople'] = DI::l10n()->t('Find People');
$nv['desc'] = DI::l10n()->t('Enter name or interest');
$nv['label'] = DI::l10n()->t('Connect/Follow');
$nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
$nv['findthem'] = DI::l10n()->t('Find');
$nv['suggest'] = DI::l10n()->t('Friend Suggestions');
$nv['similar'] = DI::l10n()->t('Similar Interests');
$nv['random'] = DI::l10n()->t('Random Profile');
$nv['inv'] = DI::l10n()->t('Invite Friends');
$nv['directory'] = DI::l10n()->t('Global Directory');
$nv['global_dir'] = Search::getGlobalDirectory();
$nv['local_directory'] = DI::l10n()->t('Local Directory');
$aside['$nv'] = $nv;
@ -224,14 +223,14 @@ function vier_community_info()
$tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
if ($r) {
$helpers = [];
$helpers = [];
$helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
$aside['$helpers_items'] = [];
foreach ($r as $rr) {
$entry = Renderer::replaceMacros($tpl, [
'$url' => $rr['url'],
'$url' => $rr['url'],
'$title' => $rr['name'],
]);
$aside['$helpers_items'][] = $entry;
@ -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"];
}
@ -303,14 +304,14 @@ function vier_community_info()
$tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
if (DBA::isResult($r)) {
$con_services = [];
$con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
$con_services = [];
$con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
$aside['$con_services'] = $con_services;
foreach ($r as $rr) {
$entry = Renderer::replaceMacros($tpl, [
'$url' => $url,
'$photo' => $rr['photo'],
'$url' => $url,
'$photo' => $rr['photo'],
'$alt_text' => $rr['name'],
]);
$aside['$connector_items'][] = $entry;
@ -320,7 +321,7 @@ function vier_community_info()
//end connectable services
//print right_aside
$tpl = Renderer::getMarkupTemplate('communityhome.tpl');
$tpl = Renderer::getMarkupTemplate('communityhome.tpl');
DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
}