Merge remote-tracking branch 'upstream/develop' into api
This commit is contained in:
-20
@@ -540,25 +540,6 @@ class App
|
||||
return Core\Theme::getStylesheetPath($this->getCurrentTheme());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base url for use in cmdline programs which don't have
|
||||
* $_SERVER variables
|
||||
*/
|
||||
public function checkURL()
|
||||
{
|
||||
$url = $this->config->get('system', 'url');
|
||||
|
||||
// if the url isn't set or the stored url is radically different
|
||||
// than the currently visited url, store the current value accordingly.
|
||||
// "Radically different" ignores common variations such as http vs https
|
||||
// and www.example.com vs example.com.
|
||||
// We will only change the url to an ip address if there is no existing setting
|
||||
|
||||
if (empty($url) || (!Util\Strings::compareLink($url, $this->baseURL->get())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $this->baseURL->getHostname()))) {
|
||||
$this->config->set('system', 'url', $this->baseURL->get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend App script
|
||||
*
|
||||
@@ -657,7 +638,6 @@ class App
|
||||
if ($this->mode->isInstall() && $moduleName !== 'install') {
|
||||
$this->baseURL->redirect('install');
|
||||
} else {
|
||||
$this->checkURL();
|
||||
Core\Update::check($this->getBasePath(), false);
|
||||
Core\Addon::loadAddons();
|
||||
Core\Hook::loadHooks();
|
||||
|
||||
+7
-98
@@ -257,109 +257,18 @@ class BaseURL
|
||||
*/
|
||||
public function __construct(IManageConfigValues $config, array $server)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->server = $server;
|
||||
|
||||
$this->determineSchema();
|
||||
$this->checkConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the current config during loading
|
||||
*/
|
||||
public function checkConfig()
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->server = $server;
|
||||
$this->hostname = $this->config->get('config', 'hostname');
|
||||
$this->urlPath = $this->config->get('system', 'urlpath');
|
||||
$this->sslPolicy = $this->config->get('system', 'ssl_policy');
|
||||
$this->urlPath = $this->config->get('system', 'urlpath') ?? '';
|
||||
$this->sslPolicy = $this->config->get('system', 'ssl_policy') ?? static::DEFAULT_SSL_SCHEME;
|
||||
$this->url = $this->config->get('system', 'url');
|
||||
|
||||
if (empty($this->hostname)) {
|
||||
$this->determineHostname();
|
||||
|
||||
if (!empty($this->hostname)) {
|
||||
$this->config->set('config', 'hostname', $this->hostname);
|
||||
}
|
||||
if (empty($this->hostname) || empty($this->url)) {
|
||||
throw new \Exception('Invalid config - Missing system.url or config.hostname');
|
||||
}
|
||||
|
||||
if (!isset($this->urlPath)) {
|
||||
$this->determineURLPath();
|
||||
$this->config->set('system', 'urlpath', $this->urlPath);
|
||||
}
|
||||
|
||||
if (!isset($this->sslPolicy)) {
|
||||
if ($this->scheme == 'https') {
|
||||
$this->sslPolicy = self::SSL_POLICY_FULL;
|
||||
} else {
|
||||
$this->sslPolicy = self::DEFAULT_SSL_SCHEME;
|
||||
}
|
||||
$this->config->set('system', 'ssl_policy', $this->sslPolicy);
|
||||
}
|
||||
|
||||
if (empty($this->url)) {
|
||||
$this->determineBaseUrl();
|
||||
|
||||
if (!empty($this->url)) {
|
||||
$this->config->set('system', 'url', $this->url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the hostname of this node if not set already
|
||||
*/
|
||||
private function determineHostname()
|
||||
{
|
||||
$this->hostname = '';
|
||||
|
||||
if (!empty($this->server['SERVER_NAME'])) {
|
||||
$this->hostname = $this->server['SERVER_NAME'];
|
||||
|
||||
if (!empty($this->server['SERVER_PORT']) && $this->server['SERVER_PORT'] != 80 && $this->server['SERVER_PORT'] != 443) {
|
||||
$this->hostname .= ':' . $this->server['SERVER_PORT'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Figure out if we are running at the top of a domain or in a sub-directory
|
||||
*/
|
||||
private function determineURLPath()
|
||||
{
|
||||
$this->urlPath = '';
|
||||
|
||||
/*
|
||||
* The automatic path detection in this function is currently deactivated,
|
||||
* see issue https://github.com/friendica/friendica/issues/6679
|
||||
*
|
||||
* The problem is that the function seems to be confused with some url.
|
||||
* These then confuses the detection which changes the url path.
|
||||
*/
|
||||
|
||||
/* Relative script path to the web server root
|
||||
* Not all of those $_SERVER properties can be present, so we do by inverse priority order
|
||||
*/
|
||||
$relative_script_path =
|
||||
($this->server['REDIRECT_URL'] ?? '') ?:
|
||||
($this->server['REDIRECT_URI'] ?? '') ?:
|
||||
($this->server['REDIRECT_SCRIPT_URL'] ?? '') ?:
|
||||
($this->server['SCRIPT_URL'] ?? '') ?:
|
||||
$this->server['REQUEST_URI'] ?? '';
|
||||
|
||||
/* $relative_script_path gives /relative/path/to/friendica/module/parameter
|
||||
* QUERY_STRING gives pagename=module/parameter
|
||||
*
|
||||
* To get /relative/path/to/friendica we perform dirname() for as many levels as there are slashes in the QUERY_STRING
|
||||
*/
|
||||
if (!empty($relative_script_path)) {
|
||||
// Module
|
||||
if (!empty($this->server['QUERY_STRING'])) {
|
||||
$this->urlPath = trim(dirname($relative_script_path, substr_count(trim($this->server['QUERY_STRING'], '/'), '/') + 1), '/');
|
||||
} else {
|
||||
// Root page
|
||||
$this->urlPath = trim($relative_script_path, '/');
|
||||
}
|
||||
}
|
||||
$this->determineSchema();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ class Request
|
||||
public function __construct(IManageConfigValues $config, array $server = [])
|
||||
{
|
||||
$this->remoteAddress = $this->determineRemoteAddress($config, $server);
|
||||
$this->requestId = $server[static::DEFAULT_REQUEST_ID_HEADER] ?? System::createGUID(8);
|
||||
$this->requestId = $server[static::DEFAULT_REQUEST_ID_HEADER] ?? System::createGUID(8, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -316,7 +316,7 @@ class OEmbed
|
||||
if ($stopoembed == true) {
|
||||
return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "<!-- oembed $1 --><i>" . DI::l10n()->t('Embedding disabled') . " : $1</i><!-- /oembed $1 -->", $text);
|
||||
}
|
||||
return preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", ['self', 'replaceCallback'], $text);
|
||||
return preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", [self::class, 'replaceCallback'], $text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -218,8 +218,8 @@ class Smilies
|
||||
return $text;
|
||||
}
|
||||
|
||||
$text = preg_replace_callback('/<(pre)>(.*?)<\/pre>/ism', 'self::encode', $text);
|
||||
$text = preg_replace_callback('/<(code)>(.*?)<\/code>/ism', 'self::encode', $text);
|
||||
$text = preg_replace_callback('/<(pre)>(.*?)<\/pre>/ism', [self::class, 'encode'], $text);
|
||||
$text = preg_replace_callback('/<(code)>(.*?)<\/code>/ism', [self::class, 'encode'], $text);
|
||||
|
||||
if ($no_images) {
|
||||
$cleaned = ['texts' => [], 'icons' => []];
|
||||
@@ -233,11 +233,11 @@ class Smilies
|
||||
$smilies = $cleaned;
|
||||
}
|
||||
|
||||
$text = preg_replace_callback('/<(3+)/', 'self::heartReplaceCallback', $text);
|
||||
$text = preg_replace_callback('/<(3+)/', [self::class, 'heartReplaceCallback'], $text);
|
||||
$text = self::strOrigReplace($smilies['texts'], $smilies['icons'], $text);
|
||||
|
||||
$text = preg_replace_callback('/<(code)>(.*?)<\/code>/ism', 'self::decode', $text);
|
||||
$text = preg_replace_callback('/<(pre)>(.*?)<\/pre>/ism', 'self::decode', $text);
|
||||
$text = preg_replace_callback('/<(code)>(.*?)<\/code>/ism', [self::class, 'decode'], $text);
|
||||
$text = preg_replace_callback('/<(pre)>(.*?)<\/pre>/ism', [self::class, 'decode'], $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
@@ -1415,8 +1415,8 @@ class BBCode
|
||||
public static function cleanPictureLinks(string $text): string
|
||||
{
|
||||
DI::profiler()->startRecording('rendering');
|
||||
$return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $text);
|
||||
$return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $return);
|
||||
$return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'cleanPictureLinksCallback'], $text);
|
||||
$return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'cleanPictureLinksCallback'], $return);
|
||||
DI::profiler()->stopRecording();
|
||||
return $return;
|
||||
}
|
||||
@@ -1450,7 +1450,7 @@ class BBCode
|
||||
{
|
||||
DI::profiler()->startRecording('rendering');
|
||||
$regexp = "/([@!])\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
|
||||
$body = preg_replace_callback($regexp, ['self', 'mentionCallback'], $body);
|
||||
$body = preg_replace_callback($regexp, [self::class, 'mentionCallback'], $body);
|
||||
DI::profiler()->stopRecording();
|
||||
return $body;
|
||||
}
|
||||
@@ -2002,12 +2002,12 @@ class BBCode
|
||||
|
||||
if (!$for_plaintext) {
|
||||
if (in_array($simple_html, [self::OSTATUS, self::MASTODON_API, self::TWITTER_API, self::ACTIVITYPUB])) {
|
||||
$text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
|
||||
$text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", 'self::convertUrlForActivityPubCallback', $text);
|
||||
$text = preg_replace_callback("/\[url\](.*?)\[\/url\]/ism", [self::class, 'convertUrlForActivityPubCallback'], $text);
|
||||
$text = preg_replace_callback("/\[url\=(.*?)\](.*?)\[\/url\]/ism", [self::class, 'convertUrlForActivityPubCallback'], $text);
|
||||
}
|
||||
} else {
|
||||
$text = preg_replace("(\[url\](.*?)\[\/url\])ism", " $1 ", $text);
|
||||
$text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'self::removePictureLinksCallback', $text);
|
||||
$text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", [self::class, 'removePictureLinksCallback'], $text);
|
||||
}
|
||||
|
||||
// Bookmarks in red - will be converted to bookmarks in friendica
|
||||
@@ -2017,7 +2017,7 @@ class BBCode
|
||||
"[bookmark=$1]$2[/bookmark]", $text);
|
||||
|
||||
if (in_array($simple_html, [self::OSTATUS, self::TWITTER])) {
|
||||
$text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", "self::expandLinksCallback", $text);
|
||||
$text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", [self::class, 'expandLinksCallback'], $text);
|
||||
//$text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $text);
|
||||
$text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", ' $2 [url]$1[/url]', $text);
|
||||
}
|
||||
@@ -2327,7 +2327,7 @@ class BBCode
|
||||
$url_search_string = "^\[\]";
|
||||
$text = preg_replace_callback(
|
||||
"/([@!])\[(.*?)\]\(([$url_search_string]*?)\)/ism",
|
||||
['self', 'bbCodeMention2DiasporaCallback'],
|
||||
[self::class, 'bbCodeMention2DiasporaCallback'],
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1032,7 +1032,7 @@ class HTML
|
||||
// the quotes, e.g.:
|
||||
//
|
||||
// concat("'foo'", '"', "bar")
|
||||
return 'concat(' . implode(', \'"\', ', array_map(['self', 'xpathQuote'], explode('"', $value))) . ')';
|
||||
return 'concat(' . implode(', \'"\', ', array_map([self::class, 'xpathQuote'], explode('"', $value))) . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -144,7 +144,7 @@ class TagCloud
|
||||
$x ++;
|
||||
}
|
||||
|
||||
usort($tags, 'self::tagsSort');
|
||||
usort($tags, [self::class, 'tagsSort']);
|
||||
$range = max(0.01, $max - $min) * 1.0001;
|
||||
|
||||
for ($x = 0; $x < count($tags); $x ++) {
|
||||
|
||||
@@ -214,6 +214,17 @@ class ConfigFileTransformer
|
||||
case "NULL":
|
||||
return "null";
|
||||
case "object":
|
||||
if (method_exists($value, '__toString')) {
|
||||
return sprintf('\'%s\'', $value);
|
||||
} elseif ($value instanceof \Serializable) {
|
||||
try {
|
||||
return $value->serialize();
|
||||
} catch (\Exception $e) {
|
||||
throw new \InvalidArgumentException(sprintf('Cannot serialize %s.', gettype($value)), $e);
|
||||
}
|
||||
} else {
|
||||
throw new \InvalidArgumentException(sprintf('%s is an object without stringify.', gettype($value)));
|
||||
}
|
||||
case "resource":
|
||||
case "resource (closed)":
|
||||
throw new \InvalidArgumentException(sprintf('%s in configs are not supported yet.', gettype($value)));
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Hooks\Capabilities;
|
||||
|
||||
/**
|
||||
* All classes, implementing this interface are valid Strategies for Hook calls
|
||||
*/
|
||||
interface IAmAStrategy
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Hooks\Capabilities;
|
||||
|
||||
use Friendica\Core\Hooks\Exceptions\HookInstanceException;
|
||||
use Friendica\Core\Hooks\Exceptions\HookRegisterArgumentException;
|
||||
|
||||
/**
|
||||
* Managing special instance and decorator treatments for classes
|
||||
*/
|
||||
interface ICanManageInstances
|
||||
{
|
||||
/**
|
||||
* Register a class(strategy) for a given interface with a unique name.
|
||||
*
|
||||
* @see https://refactoring.guru/design-patterns/strategy
|
||||
*
|
||||
* @param string $interface The interface, which the given class implements
|
||||
* @param string $name An arbitrary identifier for the given class, which will be used for factories, dependency injections etc.
|
||||
* @param string $class The fully-qualified given class name
|
||||
* @param ?array $arguments Additional arguments, which can be passed to the constructor
|
||||
*
|
||||
* @return $this This interface for chain-calls
|
||||
*
|
||||
* @throws HookRegisterArgumentException in case the given class for the interface isn't valid or already set
|
||||
*/
|
||||
public function registerStrategy(string $interface, string $name, string $class, array $arguments = null): self;
|
||||
|
||||
/**
|
||||
* Register a new decorator for a given class or interface
|
||||
* @see https://refactoring.guru/design-patterns/decorator
|
||||
*
|
||||
* @note Decorator attach new behaviors to classes without changing them or without letting them know about it.
|
||||
*
|
||||
* @param string $class The fully-qualified class or interface name, which gets decorated by a class
|
||||
* @param string $decoratorClass The fully-qualified name of the class which mimics the given class or interface and adds new functionality
|
||||
* @param array $arguments Additional arguments, which can be passed to the constructor of "decoratorClass"
|
||||
*
|
||||
* @return $this This interface for chain-calls
|
||||
*
|
||||
* @throws HookRegisterArgumentException in case the given class for the class or interface isn't valid
|
||||
*/
|
||||
public function registerDecorator(string $class, string $decoratorClass, array $arguments = []): self;
|
||||
|
||||
/**
|
||||
* Returns a new instance of a given class for the corresponding name
|
||||
*
|
||||
* The instance will be build based on the registered strategy and the (unique) name
|
||||
*
|
||||
* In case, there are registered decorators for this class as well, all decorators of the list will be wrapped
|
||||
* around the instance before returning it
|
||||
*
|
||||
* @param string $class The fully-qualified name of the given class or interface which will get returned
|
||||
* @param string $name An arbitrary identifier to find a concrete instance strategy.
|
||||
* @param array $arguments Additional arguments, which can be passed to the constructor of "$class" at runtime
|
||||
*
|
||||
* @return object The concrete instance of the type "$class"
|
||||
*
|
||||
* @throws HookInstanceException In case the class cannot get created
|
||||
*/
|
||||
public function getInstance(string $class, string $name, array $arguments = []): object;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Hooks\Exceptions;
|
||||
|
||||
class HookInstanceException extends \RuntimeException
|
||||
{
|
||||
public function __construct($message = "", \Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, 500, $previous);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Hooks\Exceptions;
|
||||
|
||||
class HookRegisterArgumentException extends \RuntimeException
|
||||
{
|
||||
public function __construct($message = "", \Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, 500, $previous);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Hooks\Model;
|
||||
|
||||
use Dice\Dice;
|
||||
use Friendica\Core\Hooks\Capabilities\IAmAStrategy;
|
||||
use Friendica\Core\Hooks\Capabilities\ICanManageInstances;
|
||||
use Friendica\Core\Hooks\Exceptions\HookInstanceException;
|
||||
use Friendica\Core\Hooks\Exceptions\HookRegisterArgumentException;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
class InstanceManager implements ICanManageInstances
|
||||
{
|
||||
protected $instance = [];
|
||||
protected $instanceArguments = [];
|
||||
protected $decorator = [];
|
||||
|
||||
/** @var Dice */
|
||||
protected $dice;
|
||||
|
||||
public function __construct(Dice $dice)
|
||||
{
|
||||
$this->dice = $dice;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function registerStrategy(string $interface, string $name, string $class, array $arguments = null): ICanManageInstances
|
||||
{
|
||||
if (!is_a($class, $interface, true)) {
|
||||
throw new HookRegisterArgumentException(sprintf('%s is not a valid class for the interface %s', $class, $interface));
|
||||
}
|
||||
|
||||
if (!is_a($class, IAmAStrategy::class, true)) {
|
||||
throw new HookRegisterArgumentException(sprintf('%s does not inherit from the marker interface %s', $class, IAmAStrategy::class));
|
||||
}
|
||||
|
||||
if (!empty($this->instance[$interface][$name])) {
|
||||
throw new HookRegisterArgumentException(sprintf('A class with the name %s is already set for the interface %s', $name, $interface));
|
||||
}
|
||||
|
||||
$this->instance[$interface][$name] = $class;
|
||||
$this->instanceArguments[$interface][$name] = $arguments;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function registerDecorator(string $class, string $decoratorClass, array $arguments = []): ICanManageInstances
|
||||
{
|
||||
if (!is_a($decoratorClass, $class, true)) {
|
||||
throw new HookRegisterArgumentException(sprintf('%s is not a valid substitution for the given class or interface %s', $decoratorClass, $class));
|
||||
}
|
||||
|
||||
$this->decorator[$class][] = [
|
||||
'class' => $decoratorClass,
|
||||
'arguments' => $arguments,
|
||||
];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function getInstance(string $class, string $name, array $arguments = []): object
|
||||
{
|
||||
if (empty($this->instance[$class][$name])) {
|
||||
throw new HookInstanceException(sprintf('The class with the name %s isn\'t registered for the class or interface %s', $name, $class));
|
||||
}
|
||||
|
||||
$instance = $this->dice->create($this->instance[$class][$name], array_merge($this->instanceArguments[$class][$name] ?? [], $arguments));
|
||||
|
||||
foreach ($this->decorator[$class] ?? [] as $decorator) {
|
||||
$this->dice = $this->dice->addRule($class, [
|
||||
'instanceOf' => $decorator['class'],
|
||||
'constructParams' => empty($decorator['arguments']) ? null : $decorator['arguments'],
|
||||
/// @todo maybe support call structures for hooks as well in a later stage - could make factory calls easier
|
||||
'call' => null,
|
||||
'substitutions' => [$class => $instance],
|
||||
]);
|
||||
|
||||
$instance = $this->dice->create($class);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2023, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Core\Logger\Exception;
|
||||
|
||||
use Throwable;
|
||||
|
||||
class LoggerInvalidException extends \RuntimeException
|
||||
{
|
||||
public function __construct($message = "", Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, 500, $previous);
|
||||
}
|
||||
}
|
||||
@@ -22,16 +22,11 @@
|
||||
namespace Friendica\Core\Logger\Factory;
|
||||
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core;
|
||||
use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections;
|
||||
use Friendica\Core\Hooks\Capabilities\ICanManageInstances;
|
||||
use Friendica\Core\Logger\Exception\LogLevelException;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Util\FileSystem;
|
||||
use Friendica\Core\Logger\Type\ProfilerLogger;
|
||||
use Friendica\Core\Logger\Type\StreamLogger;
|
||||
use Friendica\Core\Logger\Type\SyslogLogger;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Psr\Log\NullLogger;
|
||||
@@ -44,115 +39,55 @@ class Logger
|
||||
const DEV_CHANNEL = 'dev';
|
||||
|
||||
/** @var string The log-channel (app, worker, ...) */
|
||||
private $channel;
|
||||
protected $channel;
|
||||
/** @var ICanManageInstances */
|
||||
protected $instanceManager;
|
||||
/** @var IManageConfigValues */
|
||||
protected $config;
|
||||
|
||||
public function __construct(string $channel, bool $includeAddon = true)
|
||||
public function __construct(string $channel, ICanManageInstances $instanceManager, IManageConfigValues $config, string $logfile = null)
|
||||
{
|
||||
$this->channel = $channel;
|
||||
$this->channel = $channel;
|
||||
$this->instanceManager = $instanceManager;
|
||||
$this->config = $config;
|
||||
|
||||
/// @fixme clean solution = Making Addon & Hook dynamic and load them inside the constructor, so there's no custom load logic necessary anymore
|
||||
if ($includeAddon) {
|
||||
Core\Addon::loadAddons();
|
||||
Core\Hook::loadHooks();
|
||||
$this->instanceManager
|
||||
->registerStrategy(LoggerInterface::class, 'syslog', SyslogLogger::class)
|
||||
->registerStrategy(LoggerInterface::class, 'stream', StreamLogger::class, isset($logfile) ? [$logfile] : null);
|
||||
|
||||
if ($this->config->get('system', 'profiling') ?? false) {
|
||||
$this->instanceManager->registerDecorator(LoggerInterface::class, ProfilerLogger::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PSR-3 compliant logger instances
|
||||
*
|
||||
* @param Database $database The Friendica Database instance
|
||||
* @param IManageConfigValues $config The config
|
||||
* @param Profiler $profiler The profiler of the app
|
||||
* @param FileSystem $fileSystem FileSystem utils
|
||||
* @param string|null $minLevel (optional) Override minimum Loglevel to log
|
||||
* @param string|null $loglevel (optional) A given loglevel in case the loglevel in the config isn't applicable
|
||||
*
|
||||
* @return LoggerInterface The PSR-3 compliant logger instance
|
||||
*/
|
||||
public function create(Database $database, IManageConfigValues $config, Profiler $profiler, FileSystem $fileSystem, IHaveCallIntrospections $introspection, ?string $minLevel = null): LoggerInterface
|
||||
public function create(string $loglevel = null): LoggerInterface
|
||||
{
|
||||
if (empty($config->get('system', 'debugging', false))) {
|
||||
$logger = new NullLogger();
|
||||
$database->setLogger($logger);
|
||||
if (empty($this->config->get('system', 'debugging') ?? false)) {
|
||||
return new NullLogger();
|
||||
}
|
||||
|
||||
$loglevel = $loglevel ?? static::mapLegacyConfigDebugLevel($this->config->get('system', 'loglevel'));
|
||||
$name = $this->config->get('system', 'logger_config') ?? 'stream';
|
||||
|
||||
try {
|
||||
/** @var LoggerInterface */
|
||||
return $this->instanceManager->getInstance(LoggerInterface::class, $name, [$this->channel, $loglevel]);
|
||||
} catch (LogLevelException $exception) {
|
||||
// If there's a wrong config value for loglevel, try again with standard
|
||||
$logger = $this->create(LogLevel::NOTICE);
|
||||
$logger->warning('Invalid loglevel set in config.', ['loglevel' => $loglevel]);
|
||||
return $logger;
|
||||
} catch (\Throwable $e) {
|
||||
// No logger ...
|
||||
return new NullLogger();
|
||||
}
|
||||
|
||||
$minLevel = $minLevel ?? $config->get('system', 'loglevel');
|
||||
$loglevel = self::mapLegacyConfigDebugLevel((string)$minLevel);
|
||||
|
||||
$name = $config->get('system', 'logger_config', 'stream');
|
||||
|
||||
switch ($name) {
|
||||
case 'syslog':
|
||||
try {
|
||||
$logger = new SyslogLogger($this->channel, $introspection, $loglevel, $config->get('system', 'syslog_flags', SyslogLogger::DEFAULT_FLAGS), $config->get('system', 'syslog_facility', SyslogLogger::DEFAULT_FACILITY));
|
||||
} catch (LogLevelException $exception) {
|
||||
// If there's a wrong config value for loglevel, try again with standard
|
||||
$logger = $this->create($database, $config, $profiler, $fileSystem, $introspection, LogLevel::NOTICE);
|
||||
$logger->warning('Invalid loglevel set in config.', ['loglevel' => $loglevel]);
|
||||
} catch (\Throwable $e) {
|
||||
// No logger ...
|
||||
$logger = new NullLogger();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'stream':
|
||||
default:
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'channel' => $this->channel,
|
||||
'introspection' => $introspection,
|
||||
'loglevel' => $loglevel,
|
||||
'logger' => null,
|
||||
];
|
||||
try {
|
||||
Core\Hook::callAll('logger_instance', $data);
|
||||
} catch (InternalServerErrorException $exception) {
|
||||
$data['logger'] = null;
|
||||
}
|
||||
|
||||
if (($data['logger'] ?? null) instanceof LoggerInterface) {
|
||||
$logger = $data['logger'];
|
||||
}
|
||||
|
||||
if (empty($logger)) {
|
||||
$stream = $config->get('system', 'logfile');
|
||||
// just add a stream in case it's either writable or not file
|
||||
if (!is_file($stream) || is_writable($stream)) {
|
||||
try {
|
||||
$logger = new StreamLogger($this->channel, $stream, $introspection, $fileSystem, $loglevel);
|
||||
} catch (LogLevelException $exception) {
|
||||
// If there's a wrong config value for loglevel, try again with standard
|
||||
$logger = $this->create($database, $config, $profiler, $fileSystem, $introspection, LogLevel::NOTICE);
|
||||
$logger->warning('Invalid loglevel set in config.', ['loglevel' => $loglevel]);
|
||||
} catch (\Throwable $t) {
|
||||
// No logger ...
|
||||
$logger = new NullLogger();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$logger = new SyslogLogger($this->channel, $introspection, $loglevel);
|
||||
} catch (LogLevelException $exception) {
|
||||
// If there's a wrong config value for loglevel, try again with standard
|
||||
$logger = $this->create($database, $config, $profiler, $fileSystem, $introspection, LogLevel::NOTICE);
|
||||
$logger->warning('Invalid loglevel set in config.', ['loglevel' => $loglevel]);
|
||||
} catch (\Throwable $e) {
|
||||
// No logger ...
|
||||
$logger = new NullLogger();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$profiling = $config->get('system', 'profiling', false);
|
||||
|
||||
// In case profiling is enabled, wrap the ProfilerLogger around the current logger
|
||||
if (isset($profiling) && $profiling !== false) {
|
||||
$logger = new ProfilerLogger($logger, $profiler);
|
||||
}
|
||||
|
||||
$database->setLogger($logger);
|
||||
return $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,63 +98,24 @@ class Logger
|
||||
*
|
||||
* It should never get filled during normal usage of Friendica
|
||||
*
|
||||
* @param IManageConfigValues $config The config
|
||||
* @param Profiler $profiler The profiler of the app
|
||||
* @param FileSystem $fileSystem FileSystem utils
|
||||
*
|
||||
* @return LoggerInterface The PSR-3 compliant logger instance
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createDev(IManageConfigValues $config, Profiler $profiler, FileSystem $fileSystem, IHaveCallIntrospections $introspection)
|
||||
public function createDev()
|
||||
{
|
||||
$debugging = $config->get('system', 'debugging');
|
||||
$stream = $config->get('system', 'dlogfile');
|
||||
$developerIp = $config->get('system', 'dlogip');
|
||||
$debugging = $this->config->get('system', 'debugging');
|
||||
$stream = $this->config->get('system', 'dlogfile');
|
||||
$developerIp = $this->config->get('system', 'dlogip');
|
||||
|
||||
if ((!isset($developerIp) || !$debugging) &&
|
||||
(!is_file($stream) || is_writable($stream))) {
|
||||
return new NullLogger();
|
||||
}
|
||||
|
||||
$name = $config->get('system', 'logger_config', 'stream');
|
||||
$name = $this->config->get('system', 'logger_config') ?? 'stream';
|
||||
|
||||
switch ($name) {
|
||||
|
||||
case 'syslog':
|
||||
$logger = new SyslogLogger(self::DEV_CHANNEL, $introspection, LogLevel::DEBUG);
|
||||
break;
|
||||
|
||||
case 'stream':
|
||||
default:
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'channel' => self::DEV_CHANNEL,
|
||||
'introspection' => $introspection,
|
||||
'loglevel' => LogLevel::DEBUG,
|
||||
'logger' => null,
|
||||
];
|
||||
try {
|
||||
Core\Hook::callAll('logger_instance', $data);
|
||||
} catch (InternalServerErrorException $exception) {
|
||||
$data['logger'] = null;
|
||||
}
|
||||
|
||||
if (($data['logger'] ?? null) instanceof LoggerInterface) {
|
||||
return $data['logger'];
|
||||
}
|
||||
|
||||
$logger = new StreamLogger(self::DEV_CHANNEL, $stream, $introspection, $fileSystem, LogLevel::DEBUG);
|
||||
break;
|
||||
}
|
||||
|
||||
$profiling = $config->get('system', 'profiling', false);
|
||||
|
||||
// In case profiling is enabled, wrap the ProfilerLogger around the current logger
|
||||
if (isset($profiling) && $profiling !== false) {
|
||||
$logger = new ProfilerLogger($logger, $profiler);
|
||||
}
|
||||
|
||||
return $logger;
|
||||
/** @var LoggerInterface */
|
||||
return $this->instanceManager->getInstance(LoggerInterface::class, $name, [self::DEV_CHANNEL, LogLevel::DEBUG, $stream]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
|
||||
namespace Friendica\Core\Logger\Type;
|
||||
|
||||
use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections;
|
||||
use Friendica\Core\Logger\Exception\LoggerException;
|
||||
use Friendica\Core\Logger\Util\Introspection;
|
||||
use Friendica\Util\Strings;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
@@ -46,7 +46,7 @@ abstract class AbstractLogger implements LoggerInterface
|
||||
|
||||
/**
|
||||
* The Introspection for the current call
|
||||
* @var Introspection
|
||||
* @var IHaveCallIntrospections
|
||||
*/
|
||||
protected $introspection;
|
||||
|
||||
@@ -69,11 +69,11 @@ abstract class AbstractLogger implements LoggerInterface
|
||||
|
||||
/**
|
||||
* @param string $channel The output channel
|
||||
* @param Introspection $introspection The introspection of the current call
|
||||
* @param IHaveCallIntrospections $introspection The introspection of the current call
|
||||
*
|
||||
* @throws LoggerException
|
||||
*/
|
||||
public function __construct(string $channel, Introspection $introspection)
|
||||
public function __construct(string $channel, IHaveCallIntrospections $introspection)
|
||||
{
|
||||
$this->channel = $channel;
|
||||
$this->introspection = $introspection;
|
||||
|
||||
@@ -21,18 +21,20 @@
|
||||
|
||||
namespace Friendica\Core\Logger\Type;
|
||||
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Hooks\Capabilities\IAmAStrategy;
|
||||
use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections;
|
||||
use Friendica\Core\Logger\Exception\LoggerArgumentException;
|
||||
use Friendica\Core\Logger\Exception\LoggerException;
|
||||
use Friendica\Core\Logger\Exception\LogLevelException;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\FileSystem;
|
||||
use Friendica\Core\Logger\Util\Introspection;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
/**
|
||||
* A Logger instance for logging into a stream (file, stdout, stderr)
|
||||
*/
|
||||
class StreamLogger extends AbstractLogger
|
||||
class StreamLogger extends AbstractLogger implements IAmAStrategy
|
||||
{
|
||||
/**
|
||||
* The minimum loglevel at which this logger will be triggered
|
||||
@@ -80,16 +82,20 @@ class StreamLogger extends AbstractLogger
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param string|resource $stream The stream to write with this logger (either a file or a stream, i.e. stdout)
|
||||
* @param string $level The minimum loglevel at which this logger will be triggered
|
||||
*
|
||||
* @throws LoggerArgumentException
|
||||
* @throws LogLevelException
|
||||
*/
|
||||
public function __construct($channel, $stream, Introspection $introspection, FileSystem $fileSystem, string $level = LogLevel::DEBUG)
|
||||
public function __construct(string $channel, IManageConfigValues $config, IHaveCallIntrospections $introspection, FileSystem $fileSystem, string $level = LogLevel::DEBUG)
|
||||
{
|
||||
$this->fileSystem = $fileSystem;
|
||||
|
||||
$stream = $this->logfile ?? $config->get('system', 'logfile');
|
||||
if ((file_exists($stream) && !is_writable($stream)) || is_writable(basename($stream))) {
|
||||
throw new LoggerArgumentException(sprintf('%s is not a valid logfile', $stream));
|
||||
}
|
||||
|
||||
parent::__construct($channel, $introspection);
|
||||
|
||||
if (is_resource($stream)) {
|
||||
|
||||
@@ -21,16 +21,18 @@
|
||||
|
||||
namespace Friendica\Core\Logger\Type;
|
||||
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Hooks\Capabilities\IAmAStrategy;
|
||||
use Friendica\Core\Logger\Capabilities\IHaveCallIntrospections;
|
||||
use Friendica\Core\Logger\Exception\LoggerException;
|
||||
use Friendica\Core\Logger\Exception\LogLevelException;
|
||||
use Friendica\Core\Logger\Util\Introspection;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
/**
|
||||
* A Logger instance for syslogging (fast, but simple)
|
||||
* @see http://php.net/manual/en/function.syslog.php
|
||||
*/
|
||||
class SyslogLogger extends AbstractLogger
|
||||
class SyslogLogger extends AbstractLogger implements IAmAStrategy
|
||||
{
|
||||
const IDENT = 'Friendica';
|
||||
|
||||
@@ -100,17 +102,16 @@ class SyslogLogger extends AbstractLogger
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param string $level The minimum loglevel at which this logger will be triggered
|
||||
* @param int $logOpts Indicates what logging options will be used when generating a log message
|
||||
* @param int $logFacility Used to specify what type of program is logging the message
|
||||
*
|
||||
* @throws LogLevelException
|
||||
* @throws LoggerException
|
||||
*/
|
||||
public function __construct($channel, Introspection $introspection, string $level = LogLevel::NOTICE, int $logOpts = self::DEFAULT_FLAGS, int $logFacility = self::DEFAULT_FACILITY )
|
||||
public function __construct(string $channel, IManageConfigValues $config, IHaveCallIntrospections $introspection, string $level = LogLevel::NOTICE)
|
||||
{
|
||||
parent::__construct($channel, $introspection);
|
||||
$this->logOpts = $logOpts;
|
||||
$this->logFacility = $logFacility;
|
||||
|
||||
$this->logOpts = $config->get('system', 'syslog_flags') ?? static::DEFAULT_FLAGS;
|
||||
$this->logFacility = $config->get('system', 'syslog_facility') ?? static::DEFAULT_FACILITY;
|
||||
$this->logLevel = $this->mapLevelToPriority($level);
|
||||
$this->introspection->addClasses([self::class]);
|
||||
}
|
||||
|
||||
@@ -527,7 +527,7 @@ class DBA
|
||||
public static function buildTableString(array $tables): string
|
||||
{
|
||||
// Quote each entry
|
||||
return implode(',', array_map(['self', 'quoteIdentifier'], $tables));
|
||||
return implode(',', array_map([self::class, 'quoteIdentifier'], $tables));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -717,7 +717,7 @@ class DBA
|
||||
{
|
||||
$groupby_string = '';
|
||||
if (!empty($params['group_by'])) {
|
||||
$groupby_string = " GROUP BY " . implode(', ', array_map(['self', 'quoteIdentifier'], $params['group_by']));
|
||||
$groupby_string = " GROUP BY " . implode(', ', array_map([self::class, 'quoteIdentifier'], $params['group_by']));
|
||||
}
|
||||
|
||||
$order_string = '';
|
||||
|
||||
@@ -783,7 +783,7 @@ class DBStructure
|
||||
}
|
||||
|
||||
if (!DBA::exists('verb', ['id' => 0])) {
|
||||
DBA::insert('verb', ['name' => '']);
|
||||
DBA::insert('verb', ['name' => ''], Database::INSERT_IGNORE);
|
||||
$lastid = DBA::lastInsertId();
|
||||
if ($lastid != 0) {
|
||||
DBA::update('verb', ['id' => 0], ['id' => $lastid]);
|
||||
@@ -819,7 +819,7 @@ class DBStructure
|
||||
}
|
||||
|
||||
if (self::existsTable('contact') && !DBA::exists('contact', ['id' => 0])) {
|
||||
DBA::insert('contact', ['nurl' => '']);
|
||||
DBA::insert('contact', ['nurl' => ''], Database::INSERT_IGNORE);
|
||||
$lastid = DBA::lastInsertId();
|
||||
if ($lastid != 0) {
|
||||
DBA::update('contact', ['id' => 0], ['id' => $lastid]);
|
||||
@@ -834,7 +834,7 @@ class DBStructure
|
||||
}
|
||||
|
||||
if (self::existsTable('tag') && !DBA::exists('tag', ['id' => 0])) {
|
||||
DBA::insert('tag', ['name' => '']);
|
||||
DBA::insert('tag', ['name' => ''], Database::INSERT_IGNORE);
|
||||
$lastid = DBA::lastInsertId();
|
||||
if ($lastid != 0) {
|
||||
DBA::update('tag', ['id' => 0], ['id' => $lastid]);
|
||||
@@ -850,7 +850,7 @@ class DBStructure
|
||||
|
||||
if (self::existsTable('permissionset')) {
|
||||
if (!DBA::exists('permissionset', ['id' => 0])) {
|
||||
DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']);
|
||||
DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''], Database::INSERT_IGNORE);
|
||||
$lastid = DBA::lastInsertId();
|
||||
if ($lastid != 0) {
|
||||
DBA::update('permissionset', ['id' => 0], ['id' => $lastid]);
|
||||
@@ -878,7 +878,7 @@ class DBStructure
|
||||
}
|
||||
$fields = ['id' => $set['psid'], 'uid' => $set['uid'], 'allow_cid' => $permission,
|
||||
'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''];
|
||||
DBA::insert('permissionset', $fields);
|
||||
DBA::insert('permissionset', $fields, Database::INSERT_IGNORE);
|
||||
}
|
||||
DBA::close($sets);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ use PDO;
|
||||
use PDOException;
|
||||
use PDOStatement;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
/**
|
||||
* This class is for the low level database stuff that does driver specific things.
|
||||
@@ -81,16 +80,14 @@ class Database
|
||||
/** @var ViewDefinition */
|
||||
protected $viewDefinition;
|
||||
|
||||
public function __construct(IManageConfigValues $config, Profiler $profiler, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition)
|
||||
public function __construct(IManageConfigValues $config, Profiler $profiler, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition, LoggerInterface $logger)
|
||||
{
|
||||
// We are storing these values for being able to perform a reconnect
|
||||
$this->config = $config;
|
||||
$this->profiler = $profiler;
|
||||
$this->config = $config;
|
||||
$this->profiler = $profiler;
|
||||
$this->dbaDefinition = $dbaDefinition;
|
||||
$this->viewDefinition = $viewDefinition;
|
||||
|
||||
// Temporary NullLogger until we can fetch the logger class from the config
|
||||
$this->logger = new NullLogger();
|
||||
$this->logger = $logger;
|
||||
|
||||
$this->connect();
|
||||
}
|
||||
@@ -196,21 +193,6 @@ class Database
|
||||
$this->testmode = $test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the logger for DBA
|
||||
*
|
||||
* @note this is necessary because if we want to load the logger configuration
|
||||
* from the DB, but there's an error, we would print out an exception.
|
||||
* So the logger gets updated after the logger configuration can be retrieved
|
||||
* from the database
|
||||
*
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function setLogger(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the profiler for DBA
|
||||
*
|
||||
|
||||
@@ -87,6 +87,10 @@ class DbaDefinition
|
||||
$data[$field] = mb_substr($data[$field], 0, $result[1]);
|
||||
} elseif (is_string($data[$field]) && preg_match("/binary\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) {
|
||||
$data[$field] = substr($data[$field], 0, $result[1]);
|
||||
} elseif (is_numeric($data[$field]) && $definition[$table]['fields'][$field]['type'] === 'int') {
|
||||
$data[$field] = min(max((int)$data[$field], -2147483648), 2147483647);
|
||||
} elseif (is_numeric($data[$field]) && $definition[$table]['fields'][$field]['type'] === 'int unsigned') {
|
||||
$data[$field] = min(max((int)$data[$field], 0), 4294967295);
|
||||
}
|
||||
$fields[$field] = $data[$field];
|
||||
}
|
||||
|
||||
@@ -243,15 +243,13 @@ class Contact
|
||||
* @throws \Exception
|
||||
* @todo Let's get rid of boolean type of $old_fields
|
||||
*/
|
||||
public static function update(array $fields, array $condition, $old_fields = [])
|
||||
public static function update(array $fields, array $condition, $old_fields = []): bool
|
||||
{
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('contact', $fields);
|
||||
$ret = DBA::update('contact', $fields, $condition, $old_fields);
|
||||
|
||||
// Apply changes to the "user-contact" table on dedicated fields
|
||||
Contact\User::updateByContactUpdate($fields, $condition);
|
||||
|
||||
return $ret;
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('contact', $fields);
|
||||
return DBA::update('contact', $fields, $condition, $old_fields);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2970,7 +2968,7 @@ class Contact
|
||||
}
|
||||
|
||||
// check if we already have a contact
|
||||
$condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($ret['url'])];
|
||||
$condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($ret['url']), 'deleted' => false];
|
||||
$contact = DBA::selectFirst('contact', ['id', 'rel', 'url', 'pending', 'hub-verify'], $condition);
|
||||
|
||||
$protocol = self::getProtocol($ret['url'], $ret['network']);
|
||||
@@ -3293,7 +3291,7 @@ class Contact
|
||||
if ($contact['rel'] == self::SHARING || in_array($contact['network'], [Protocol::FEED, Protocol::MAIL])) {
|
||||
self::remove($contact['id']);
|
||||
} else {
|
||||
self::update(['rel' => self::FOLLOWER], ['id' => $contact['id']]);
|
||||
self::update(['rel' => self::FOLLOWER, 'pending' => false], ['id' => $contact['id']]);
|
||||
}
|
||||
|
||||
Worker::add(Worker::PRIORITY_LOW, 'ContactDiscoveryForUser', $contact['uid']);
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@ class Event
|
||||
|
||||
public static function sortByDate(array $event_list): array
|
||||
{
|
||||
usort($event_list, ['self', 'compareDatesCallback']);
|
||||
usort($event_list, [self::class, 'compareDatesCallback']);
|
||||
return $event_list;
|
||||
}
|
||||
|
||||
|
||||
+10
-6
@@ -455,22 +455,26 @@ class GServer
|
||||
* Set failed server status
|
||||
*
|
||||
* @param string $url
|
||||
* @return void
|
||||
*/
|
||||
public static function setFailureByUrl(string $url)
|
||||
{
|
||||
$gserver = DBA::selectFirst('gserver', [], ['nurl' => Strings::normaliseLink($url)]);
|
||||
$nurl = Strings::normaliseLink($url);
|
||||
|
||||
$gserver = DBA::selectFirst('gserver', [], ['nurl' => $nurl]);
|
||||
if (DBA::isResult($gserver)) {
|
||||
$next_update = self::getNextUpdateDate(false, $gserver['created'], $gserver['last_contact']);
|
||||
self::update(['url' => $url, 'failed' => true, 'blocked' => Network::isUrlBlocked($url), 'last_failure' => DateTimeFormat::utcNow(),
|
||||
'next_contact' => $next_update, 'network' => Protocol::PHANTOM, 'detection-method' => null],
|
||||
['nurl' => Strings::normaliseLink($url)]);
|
||||
['nurl' => $nurl]);
|
||||
Logger::info('Set failed status for existing server', ['url' => $url]);
|
||||
if (self::isDefunct($gserver)) {
|
||||
self::archiveContacts($gserver['id']);
|
||||
}
|
||||
return;
|
||||
}
|
||||
self::insert(['url' => $url, 'nurl' => Strings::normaliseLink($url),
|
||||
|
||||
self::insert(['url' => $url, 'nurl' => $nurl,
|
||||
'network' => Protocol::PHANTOM, 'created' => DateTimeFormat::utcNow(),
|
||||
'failed' => true, 'last_failure' => DateTimeFormat::utcNow()]);
|
||||
Logger::info('Set failed status for new server', ['url' => $url]);
|
||||
@@ -556,7 +560,7 @@ class GServer
|
||||
// If the URL missmatches, then we mark the old entry as failure
|
||||
if (!Strings::compareLink($url, $original_url)) {
|
||||
self::setFailureByUrl($original_url);
|
||||
if (!self::getID($url, true)) {
|
||||
if (!self::getID($url, true) && !Network::isUrlBlocked($url)) {
|
||||
self::detect($url, $network, $only_nodeinfo);
|
||||
}
|
||||
return false;
|
||||
@@ -577,7 +581,7 @@ class GServer
|
||||
(((parse_url($url, PHP_URL_HOST) != parse_url($valid_url, PHP_URL_HOST)) || (parse_url($url, PHP_URL_PATH) != parse_url($valid_url, PHP_URL_PATH))) && empty(parse_url($valid_url, PHP_URL_PATH)))) {
|
||||
Logger::debug('Found redirect. Mark old entry as failure', ['old' => $url, 'new' => $valid_url]);
|
||||
self::setFailureByUrl($url);
|
||||
if (!self::getID($valid_url, true)) {
|
||||
if (!self::getID($valid_url, true) && !Network::isUrlBlocked($valid_url)) {
|
||||
self::detect($valid_url, $network, $only_nodeinfo);
|
||||
}
|
||||
return false;
|
||||
@@ -591,7 +595,7 @@ class GServer
|
||||
$valid_url = (string)Uri::fromParts($parts);
|
||||
|
||||
self::setFailureByUrl($url);
|
||||
if (!self::getID($valid_url, true)) {
|
||||
if (!self::getID($valid_url, true) && !Network::isUrlBlocked($valid_url)) {
|
||||
self::detect($valid_url, $network, $only_nodeinfo);
|
||||
}
|
||||
return false;
|
||||
|
||||
+12
-12
@@ -55,17 +55,17 @@ class Nodeinfo
|
||||
|
||||
$userStats = User::getStatistics();
|
||||
|
||||
$config->set('nodeinfo', 'total_users', $userStats['total_users']);
|
||||
$config->set('nodeinfo', 'active_users_halfyear', $userStats['active_users_halfyear']);
|
||||
$config->set('nodeinfo', 'active_users_monthly', $userStats['active_users_monthly']);
|
||||
$config->set('nodeinfo', 'active_users_weekly', $userStats['active_users_weekly']);
|
||||
DI::keyValue()->set('nodeinfo_total_users', $userStats['total_users']);
|
||||
DI::keyValue()->set('nodeinfo_active_users_halfyear', $userStats['active_users_halfyear']);
|
||||
DI::keyValue()->set('nodeinfo_active_users_monthly', $userStats['active_users_monthly']);
|
||||
DI::keyValue()->set('nodeinfo_active_users_weekly', $userStats['active_users_weekly']);
|
||||
|
||||
$logger->info('user statistics', $userStats);
|
||||
|
||||
$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]);
|
||||
$config->set('nodeinfo', 'local_posts', $posts);
|
||||
$config->set('nodeinfo', 'local_comments', $comments);
|
||||
DI::keyValue()->set('nodeinfo_local_posts', $posts);
|
||||
DI::keyValue()->set('nodeinfo_local_comments', $comments);
|
||||
|
||||
$logger->info('User actitivy', ['posts' => $posts, 'comments' => $comments]);
|
||||
}
|
||||
@@ -83,14 +83,14 @@ class Nodeinfo
|
||||
$usage->users = new \stdClass;
|
||||
|
||||
if (!empty($config->get('system', 'nodeinfo'))) {
|
||||
$usage->users->total = intval($config->get('nodeinfo', 'total_users'));
|
||||
$usage->users->activeHalfyear = intval($config->get('nodeinfo', 'active_users_halfyear'));
|
||||
$usage->users->activeMonth = intval($config->get('nodeinfo', 'active_users_monthly'));
|
||||
$usage->localPosts = intval($config->get('nodeinfo', 'local_posts'));
|
||||
$usage->localComments = intval($config->get('nodeinfo', 'local_comments'));
|
||||
$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'));
|
||||
|
||||
if ($version2) {
|
||||
$usage->users->activeWeek = intval($config->get('nodeinfo', 'active_users_weekly'));
|
||||
$usage->users->activeWeek = intval(DI::keyValue()->get('nodeinfo_active_users_weekly'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -757,7 +757,7 @@ class User
|
||||
}
|
||||
|
||||
/**
|
||||
* Allowed characters are a-z, A-Z, 0-9 and special characters except white spaces, accentuated letters and colon (:).
|
||||
* Allowed characters are a-z, A-Z, 0-9 and special characters except white spaces and accentuated letters.
|
||||
*
|
||||
* Password length is limited to 72 characters if the current default password hashing algorithm is Blowfish.
|
||||
* From the manual: "Using the PASSWORD_BCRYPT as the algorithm, will result in the password parameter being
|
||||
@@ -770,13 +770,13 @@ class User
|
||||
*/
|
||||
public static function getPasswordRegExp(string $delimiter = null): string
|
||||
{
|
||||
$allowed_characters = '!"#$%&\'()*+,-./;<=>?@[\]^_`{|}~';
|
||||
$allowed_characters = ':!"#$%&\'()*+,-./;<=>?@[\]^_`{|}~';
|
||||
|
||||
if ($delimiter) {
|
||||
$allowed_characters = preg_quote($allowed_characters, $delimiter);
|
||||
}
|
||||
|
||||
return '^[a-zA-Z0-9' . $allowed_characters . ']' . (PASSWORD_DEFAULT !== PASSWORD_BCRYPT ? '{1,72}' : '+') . '$';
|
||||
return '^[a-zA-Z0-9' . $allowed_characters . ']' . (PASSWORD_DEFAULT === PASSWORD_BCRYPT ? '{1,72}' : '+') . '$';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -804,7 +804,7 @@ class User
|
||||
}
|
||||
|
||||
if (!preg_match('/' . self::getPasswordRegExp('/') . '/', $password)) {
|
||||
throw new Exception(DI::l10n()->t('The password can\'t contain accentuated letters, white spaces or colons (:)'));
|
||||
throw new Exception(DI::l10n()->t("The password can't contain white spaces nor accentuated letters"));
|
||||
}
|
||||
|
||||
return self::updatePasswordHashed($uid, self::hashPassword($password));
|
||||
|
||||
@@ -197,7 +197,7 @@ class Profile extends BaseModule
|
||||
Contact\User::setIgnored($contact['id'], DI::userSession()->getLocalUserId(), true);
|
||||
$message = $this->t('Contact has been ignored');
|
||||
}
|
||||
|
||||
|
||||
// @TODO: add $this->localRelationship->save($localRelationship);
|
||||
DI::sysmsg()->addInfo($message);
|
||||
}
|
||||
@@ -213,7 +213,7 @@ class Profile extends BaseModule
|
||||
Contact\User::setCollapsed($contact['id'], DI::userSession()->getLocalUserId(), true);
|
||||
$message = $this->t('Contact has been collapsed');
|
||||
}
|
||||
|
||||
|
||||
// @TODO: add $this->localRelationship->save($localRelationship);
|
||||
DI::sysmsg()->addInfo($message);
|
||||
}
|
||||
@@ -239,9 +239,6 @@ class Profile extends BaseModule
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
]);
|
||||
|
||||
$contact['blocked'] = Contact\User::isBlocked($contact['id'], DI::userSession()->getLocalUserId());
|
||||
$contact['readonly'] = Contact\User::isIgnored($contact['id'], DI::userSession()->getLocalUserId());
|
||||
|
||||
switch ($localRelationship->rel) {
|
||||
case Contact::FRIEND: $relation_text = $this->t('You are mutual friends with %s', $contact['name']); break;
|
||||
case Contact::FOLLOWER: $relation_text = $this->t('You are sharing with %s', $contact['name']); break;
|
||||
@@ -361,16 +358,13 @@ class Profile extends BaseModule
|
||||
'$last_update' => $last_update,
|
||||
'$udnow' => $this->t('Update now'),
|
||||
'$contact_id' => $contact['id'],
|
||||
'$block_text' => ($contact['blocked'] ? $this->t('Unblock') : $this->t('Block')),
|
||||
'$ignore_text' => ($contact['readonly'] ? $this->t('Unignore') : $this->t('Ignore')),
|
||||
'$insecure' => (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]) ? '' : $insecure),
|
||||
'$info' => $localRelationship->info,
|
||||
'$cinfo' => ['info', '', $localRelationship->info, ''],
|
||||
'$blocked' => ($contact['blocked'] ? $this->t('Currently blocked') : ''),
|
||||
'$ignored' => ($contact['readonly'] ? $this->t('Currently ignored') : ''),
|
||||
'$collapsed' => (Contact\User::isCollapsed($contact['id'], DI::userSession()->getLocalUserId()) ? $this->t('Currently collapsed') : ''),
|
||||
'$pending' => $localRelationship->pending ? $this->t('Awaiting connection acknowledge') : '',
|
||||
'$blocked' => $localRelationship->blocked ? $this->t('Currently blocked') : '',
|
||||
'$ignored' => $localRelationship->ignored ? $this->t('Currently ignored') : '',
|
||||
'$collapsed' => $localRelationship->collapsed ? $this->t('Currently collapsed') : '',
|
||||
'$archived' => ($contact['archive'] ? $this->t('Currently archived') : ''),
|
||||
'$pending' => ($contact['pending'] ? $this->t('Awaiting connection acknowledge') : ''),
|
||||
'$insecure' => (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::MAIL, Protocol::DIASPORA]) ? '' : $insecure),
|
||||
'$cinfo' => ['info', '', $localRelationship->info, ''],
|
||||
'$hidden' => ['hidden', $this->t('Hide this contact from others'), $localRelationship->hidden, $this->t('Replies/likes to your public posts <strong>may</strong> still be visible')],
|
||||
'$notify_new_posts' => ['notify_new_posts', $this->t('Notification for new posts'), ($localRelationship->notifyNewPosts), $this->t('Send a notification of every new post of this contact')],
|
||||
'$fetch_further_information' => $fetch_further_information,
|
||||
|
||||
@@ -36,7 +36,7 @@ class Maintenance extends BaseModule
|
||||
{
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
$reason = DI::config()->get('system', 'maintenance_reason');
|
||||
$reason = DI::config()->get('system', 'maintenance_reason') ?? '';
|
||||
|
||||
if ((substr(Strings::normaliseLink($reason), 0, 7) === 'http://') ||
|
||||
(substr(Strings::normaliseLink($reason), 0, 8) === 'https://')) {
|
||||
|
||||
@@ -61,7 +61,10 @@ class Token extends BaseApi
|
||||
}
|
||||
|
||||
if (empty($request['client_id']) && substr($authorization, 0, 6) == 'Basic ') {
|
||||
$datapair = explode(':', base64_decode(trim(substr($authorization, 6))));
|
||||
// Per RFC2617, usernames can't contain a colon but password can,
|
||||
// so we cut on the first colon to obtain the username and the password
|
||||
// @see https://www.rfc-editor.org/rfc/rfc2617#section-2
|
||||
$datapair = explode(':', base64_decode(trim(substr($authorization, 6))), 2);
|
||||
if (count($datapair) == 2) {
|
||||
$request['client_id'] = $datapair[0];
|
||||
$request['client_secret'] = $datapair[1];
|
||||
|
||||
@@ -98,7 +98,7 @@ class PasswordTooLong extends \Friendica\BaseModule
|
||||
'$return_url' => $request['return_url'] ?? '',
|
||||
|
||||
'$password_current' => ['password_current', $this->l10n->t('Current Password:'), '', $this->l10n->t('Your current password to confirm the changes'), 'required', 'autocomplete="off"'],
|
||||
'$password' => ['password', $this->l10n->t('New Password:'), '', $this->l10n->t('Allowed characters are a-z, A-Z, 0-9 and special characters except white spaces, accentuated letters and colon (:).') . ' ' . $this->l10n->t('Password length is limited to 72 characters.'), 'required', 'autocomplete="off"', User::getPasswordRegExp()],
|
||||
'$password' => ['password', $this->l10n->t('New Password:'), '', $this->l10n->t('Allowed characters are a-z, A-Z, 0-9 and special characters except white spaces and accentuated letters.') . ' ' . $this->l10n->t('Password length is limited to 72 characters.'), 'required', 'autocomplete="off"', User::getPasswordRegExp()],
|
||||
'$password_confirm' => ['password_confirm', $this->l10n->t('Confirm:'), '', '', 'required', 'autocomplete="off"'],
|
||||
]);
|
||||
|
||||
|
||||
@@ -549,7 +549,7 @@ class Account extends BaseSettings
|
||||
|
||||
$notify_type = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'notify_type');
|
||||
|
||||
$passwordRules = DI::l10n()->t('Allowed characters are a-z, A-Z, 0-9 and special characters except white spaces, accentuated letters and colon (:).')
|
||||
$passwordRules = DI::l10n()->t('Allowed characters are a-z, A-Z, 0-9 and special characters except white spaces and accentuated letters.')
|
||||
. (PASSWORD_DEFAULT === PASSWORD_BCRYPT ? ' ' . DI::l10n()->t('Password length is limited to 72 characters.') : '');
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('settings/account.tpl');
|
||||
|
||||
@@ -25,6 +25,7 @@ use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
@@ -35,13 +36,15 @@ class Statistics extends BaseModule
|
||||
{
|
||||
/** @var IManageConfigValues */
|
||||
protected $config;
|
||||
|
||||
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, Response $response, array $server, array $parameters = [])
|
||||
/** @var IManageKeyValuePairs */
|
||||
protected $keyValue;
|
||||
|
||||
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 = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->config = $config;
|
||||
|
||||
$this->config = $config;
|
||||
$this->keyValue = $keyValue;
|
||||
if (!$this->config->get("system", "nodeinfo")) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@@ -72,10 +75,10 @@ class Statistics extends BaseModule
|
||||
'network' => App::PLATFORM,
|
||||
'version' => App::VERSION . '-' . DB_UPDATE_VERSION,
|
||||
'registrations_open' => $registration_open,
|
||||
'total_users' => $this->config->get('nodeinfo', 'total_users'),
|
||||
'active_users_halfyear' => $this->config->get('nodeinfo', 'active_users_halfyear'),
|
||||
'active_users_monthly' => $this->config->get('nodeinfo', 'active_users_monthly'),
|
||||
'local_posts' => $this->config->get('nodeinfo', 'local_posts'),
|
||||
'total_users' => $this->keyValue->get('nodeinfo_total_users'),
|
||||
'active_users_halfyear' => $this->keyValue->get('nodeinfo_active_users_halfyear'),
|
||||
'active_users_monthly' => $this->keyValue->get('nodeinfo_active_users_monthly'),
|
||||
'local_posts' => $this->keyValue->get('nodeinfo_local_posts'),
|
||||
'services' => $services,
|
||||
], $services);
|
||||
|
||||
|
||||
@@ -614,7 +614,7 @@ class Notify extends BaseRepository
|
||||
|
||||
$emailBuilder->setHeader('Message-ID', $message_id);
|
||||
$log_msg = "No previous notification found for this parent:\n" .
|
||||
" parent: ${params['parent']}\n" . " uid : ${params['uid']}\n";
|
||||
" parent: {$params['parent']}\n" . " uid : {$params['uid']}\n";
|
||||
$this->logger->info($log_msg);
|
||||
} else {
|
||||
// If not, just "follow" the thread.
|
||||
|
||||
@@ -69,6 +69,10 @@ class HttpClient implements ICanSendHttpRequests
|
||||
$this->logger->debug('Request start.', ['url' => $url, 'method' => $method]);
|
||||
|
||||
$host = parse_url($url, PHP_URL_HOST);
|
||||
if (empty($host)) {
|
||||
throw new \InvalidArgumentException('Unable to retrieve the host in URL: ' . $url);
|
||||
}
|
||||
|
||||
if(!filter_var($host, FILTER_VALIDATE_IP) && !@dns_get_record($host . '.', DNS_A + DNS_AAAA) && !gethostbyname($host)) {
|
||||
$this->logger->debug('URL cannot be resolved.', ['url' => $url, 'callstack' => System::callstack(20)]);
|
||||
$this->profiler->stopRecording();
|
||||
|
||||
@@ -54,6 +54,8 @@ class Card extends BaseDataTransferObject
|
||||
protected $image;
|
||||
/** @var string */
|
||||
protected $blurhash;
|
||||
/** @var array */
|
||||
protected $history;
|
||||
|
||||
/**
|
||||
* Creates a card record from an attachment array.
|
||||
|
||||
@@ -25,7 +25,6 @@ use Friendica\BaseDataTransferObject;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
|
||||
/**
|
||||
@@ -45,9 +44,9 @@ class Stats extends BaseDataTransferObject
|
||||
public function __construct(IManageConfigValues $config, Database $database)
|
||||
{
|
||||
if (!empty($config->get('system', 'nodeinfo'))) {
|
||||
$this->user_count = intval($config->get('nodeinfo', 'total_users'));
|
||||
$this->status_count = $config->get('nodeinfo', 'local_posts') + $config->get('nodeinfo', 'local_comments');
|
||||
$this->domain_count = $database->count('gserver', ["`network` in (?, ?) AND NOT `failed`", Protocol::DFRN, Protocol::ACTIVITYPUB]);
|
||||
$this->user_count = intval(DI::keyValue()->get('nodeinfo_total_users'));
|
||||
$this->status_count = DI::keyValue()->get('nodeinfo_local_posts') + DI::keyValue()->get('nodeinfo_local_comments');
|
||||
$this->domain_count = $database->count('gserver', ["`network` in (?, ?) AND NOT `failed` AND NOT `blocked`", Protocol::DFRN, Protocol::ACTIVITYPUB]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1661,7 +1661,7 @@ class Transmitter
|
||||
*
|
||||
* } elseif (($type == 'Article') && empty($data['summary'])) {
|
||||
* $regexp = "/[@!]\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
|
||||
* $summary = preg_replace_callback($regexp, ['self', 'mentionAddrCallback'], $body);
|
||||
* $summary = preg_replace_callback($regexp, [self::class, 'mentionAddrCallback'], $body);
|
||||
* $data['summary'] = BBCode::toPlaintext(Plaintext::shorten(self::removePictures($summary), 1000));
|
||||
* }
|
||||
*/
|
||||
|
||||
@@ -646,7 +646,7 @@ class ParseUrl
|
||||
$arr_tags = str_getcsv($string);
|
||||
if (count($arr_tags)) {
|
||||
// add the # sign to every tag
|
||||
array_walk($arr_tags, ['self', 'arrAddHashes']);
|
||||
array_walk($arr_tags, [self::class, 'arrAddHashes']);
|
||||
|
||||
return $arr_tags;
|
||||
}
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ class Proxy
|
||||
{
|
||||
$html = str_replace(Strings::normaliseLink(DI::baseUrl()) . '/', DI::baseUrl() . '/', $html);
|
||||
|
||||
return preg_replace_callback('/(<img [^>]*src *= *["\'])([^"\']+)(["\'][^>]*>)/siU', 'self::replaceUrl', $html);
|
||||
return preg_replace_callback('/(<img [^>]*src *= *["\'])([^"\']+)(["\'][^>]*>)/siU', [self::class, 'replaceUrl'], $html);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,7 +57,7 @@ class UpdateServerPeers
|
||||
$total = 0;
|
||||
$added = 0;
|
||||
foreach ($peers as $peer) {
|
||||
if (Network::isUrlBlocked('http://' . $peer)) {
|
||||
if (Network::isUrlBlocked('https://' . $peer)) {
|
||||
// Ignore blocked systems as soon as possible in the loop to avoid being slowed down by tar pits
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user