mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-07 15:54:26 +02:00
Merge branch 'develop' into eventdispatcher-part3
This commit is contained in:
commit
ea172010f8
91 changed files with 821 additions and 799 deletions
32
.github/workflows/code-quality.yml
vendored
32
.github/workflows/code-quality.yml
vendored
|
@ -76,6 +76,38 @@ jobs:
|
|||
- name: Run PHPStan
|
||||
run: composer run phpstan
|
||||
|
||||
phpstan-addons:
|
||||
name: PHPStan in addons (PHP ${{ matrix.php }})
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
operating-system: ['ubuntu-latest']
|
||||
php: ['8.4']
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- name: Setup PHP with composer and extensions
|
||||
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
coverage: xdebug
|
||||
tools: none
|
||||
|
||||
- name: Clone addon repository
|
||||
run: git clone -b develop --single-branch https://git.friendi.ca/friendica/friendica-addons.git addon
|
||||
|
||||
- name: Install Composer dependencies
|
||||
uses: "ramsey/composer-install@v2"
|
||||
|
||||
- name: Run PHPStan in addons
|
||||
run: composer run phpstan-addons
|
||||
|
||||
phpmd:
|
||||
name: PHPMD (PHP ${{ matrix.php }})
|
||||
runs-on: ubuntu-latest
|
||||
|
|
52
.phpstan-addons.neon
Normal file
52
.phpstan-addons.neon
Normal file
|
@ -0,0 +1,52 @@
|
|||
# SPDX-FileCopyrightText: 2010 - 2024 the Friendica project
|
||||
#
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
parameters:
|
||||
level: 3
|
||||
|
||||
paths:
|
||||
- addon/
|
||||
|
||||
excludePaths:
|
||||
analyse:
|
||||
- addon/*/lang/*
|
||||
- addon/*/vendor/*
|
||||
- addon/convert/UnitConvertor.php
|
||||
- addon/pumpio/oauth/*
|
||||
|
||||
scanDirectories:
|
||||
- mod
|
||||
- src
|
||||
- static
|
||||
- vendor
|
||||
- view
|
||||
|
||||
dynamicConstantNames:
|
||||
- DB_UPDATE_VERSION
|
||||
|
||||
ignoreErrors:
|
||||
|
||||
-
|
||||
# Ignore missing SMTP class in PHPMailer 5.2.21
|
||||
# see https://github.com/PHPMailer/PHPMailer/blob/v5.2.21/class.smtp.php
|
||||
message: '(^.+ an unknown class SMTP\.$)'
|
||||
path: addon/mailstream/phpmailer
|
||||
|
||||
-
|
||||
# Ignore missing SMTP class in PHPMailer 5.2.21
|
||||
# see https://github.com/PHPMailer/PHPMailer/blob/v5.2.21/class.smtp.php
|
||||
message: '(^Property .+ has unknown class SMTP as its type\.$)'
|
||||
path: addon/mailstream/phpmailer
|
||||
|
||||
-
|
||||
# Ignore missing SMTP class in PHPMailer 5.2.21
|
||||
# see https://github.com/PHPMailer/PHPMailer/blob/v5.2.21/class.smtp.php
|
||||
message: '(^Method .+ has invalid return type SMTP\.$)'
|
||||
path: addon/mailstream/phpmailer
|
||||
|
||||
-
|
||||
# Ignore missing SMTP class in PHPMailer 5.2.21
|
||||
# see https://github.com/PHPMailer/PHPMailer/blob/v5.2.21/class.smtp.php
|
||||
message: '(^Instantiated class SMTP not found\.$)'
|
||||
path: addon/mailstream/phpmailer
|
|
@ -3,10 +3,9 @@
|
|||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
parameters:
|
||||
level: 2
|
||||
level: 3
|
||||
|
||||
paths:
|
||||
- addon/
|
||||
- bin/auth_ejabberd.php
|
||||
- bin/console.php
|
||||
- bin/daemon.php
|
||||
|
@ -15,13 +14,6 @@ parameters:
|
|||
- index.php
|
||||
- src/
|
||||
|
||||
excludePaths:
|
||||
analyse:
|
||||
- addon/*/lang/*
|
||||
- addon/*/vendor/*
|
||||
- addon/convert/UnitConvertor.php
|
||||
- addon/pumpio/oauth/*
|
||||
|
||||
scanDirectories:
|
||||
- mod
|
||||
- static
|
||||
|
@ -46,27 +38,3 @@ parameters:
|
|||
# Ignore missing IMAP\Connection class in PHP <= 8.0
|
||||
message: '(^Parameter .+ has invalid type IMAP\\Connection\.$)'
|
||||
path: src
|
||||
|
||||
-
|
||||
# Ignore missing SMTP class in PHPMailer 5.2.21
|
||||
# see https://github.com/PHPMailer/PHPMailer/blob/v5.2.21/class.smtp.php
|
||||
message: '(^.+ an unknown class SMTP\.$)'
|
||||
path: addon/mailstream/phpmailer
|
||||
|
||||
-
|
||||
# Ignore missing SMTP class in PHPMailer 5.2.21
|
||||
# see https://github.com/PHPMailer/PHPMailer/blob/v5.2.21/class.smtp.php
|
||||
message: '(^Property .+ has unknown class SMTP as its type\.$)'
|
||||
path: addon/mailstream/phpmailer
|
||||
|
||||
-
|
||||
# Ignore missing SMTP class in PHPMailer 5.2.21
|
||||
# see https://github.com/PHPMailer/PHPMailer/blob/v5.2.21/class.smtp.php
|
||||
message: '(^Method .+ has invalid return type SMTP\.$)'
|
||||
path: addon/mailstream/phpmailer
|
||||
|
||||
-
|
||||
# Ignore missing SMTP class in PHPMailer 5.2.21
|
||||
# see https://github.com/PHPMailer/PHPMailer/blob/v5.2.21/class.smtp.php
|
||||
message: '(^Instantiated class SMTP not found\.$)'
|
||||
path: addon/mailstream/phpmailer
|
||||
|
|
|
@ -78,9 +78,16 @@ steps:
|
|||
image: friendicaci/php${PHP_MAJOR_VERSION}:php${PHP_VERSION}
|
||||
when:
|
||||
matrix:
|
||||
PHP_MAJOR_VERSION: 8.2
|
||||
PHP_MAJOR_VERSION: 8.3
|
||||
commands:
|
||||
- bin/composer.phar run phpstan;
|
||||
phpstan-addons:
|
||||
image: friendicaci/php${PHP_MAJOR_VERSION}:php${PHP_VERSION}
|
||||
when:
|
||||
matrix:
|
||||
PHP_MAJOR_VERSION: 8.3
|
||||
commands:
|
||||
- bin/composer.phar run phpstan-addons;
|
||||
test:
|
||||
image: friendicaci/php${PHP_MAJOR_VERSION}:php${PHP_VERSION}
|
||||
environment:
|
||||
|
|
|
@ -164,6 +164,7 @@
|
|||
"test:unit": "phpunit -c tests/phpunit.xml --testsuite unit",
|
||||
"phpmd": "phpmd src/ text .phpmd-ruleset.xml --color --cache",
|
||||
"phpstan": "phpstan analyze --memory-limit 1024M --configuration .phpstan.neon",
|
||||
"phpstan-addons": "phpstan analyze --memory-limit 1024M --configuration .phpstan-addons.neon",
|
||||
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './view/asset/*' -print0 | xargs -0 -n1 php -l",
|
||||
"docker:translate": "docker run --rm -v $PWD:/data -w /data friendicaci/transifex bin/run_xgettext.sh",
|
||||
"lang:recreate": "bin/run_xgettext.sh",
|
||||
|
|
|
@ -24,7 +24,7 @@ class BaseCollection extends \ArrayIterator
|
|||
* @param BaseEntity[] $entities
|
||||
* @param int|null $totalCount
|
||||
*/
|
||||
public function __construct(array $entities = [], int $totalCount = null)
|
||||
public function __construct(array $entities = [], ?int $totalCount = null)
|
||||
{
|
||||
parent::__construct($entities);
|
||||
|
||||
|
@ -102,7 +102,7 @@ class BaseCollection extends \ArrayIterator
|
|||
* @return BaseCollection
|
||||
* @see array_filter()
|
||||
*/
|
||||
public function filter(callable $callback = null, int $flag = 0): BaseCollection
|
||||
public function filter(?callable $callback = null, int $flag = 0): BaseCollection
|
||||
{
|
||||
$class = get_class($this);
|
||||
|
||||
|
@ -111,8 +111,6 @@ class BaseCollection extends \ArrayIterator
|
|||
|
||||
/**
|
||||
* Reverse the orders of the elements in the collection
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function reverse(): BaseCollection
|
||||
{
|
||||
|
@ -125,7 +123,6 @@ class BaseCollection extends \ArrayIterator
|
|||
* Split the collection in smaller collections no bigger than the provided length
|
||||
*
|
||||
* @param int $length
|
||||
* @return static[]
|
||||
*/
|
||||
public function chunk(int $length): array
|
||||
{
|
||||
|
@ -133,11 +130,14 @@ class BaseCollection extends \ArrayIterator
|
|||
throw new \RangeException('BaseCollection->chunk(): Size parameter expected to be greater than 0');
|
||||
}
|
||||
|
||||
return array_map(function ($array) {
|
||||
$class = get_class($this);
|
||||
return array_map(
|
||||
function ($array) {
|
||||
$class = get_class($this);
|
||||
|
||||
return new $class($array);
|
||||
}, array_chunk($this->getArrayCopy(), $length));
|
||||
return new $class($array);
|
||||
},
|
||||
array_chunk($this->getArrayCopy(), $length)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -130,17 +130,33 @@ abstract class BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
* @return BaseEntity
|
||||
* Selects the fields of the first row as array
|
||||
*
|
||||
* @throws NotFoundException
|
||||
*
|
||||
* @return array The resulted fields as array
|
||||
*/
|
||||
final protected function _selectFirstRowAsArray(array $condition, array $params = []): array
|
||||
{
|
||||
$fields = $this->db->selectFirst(static::$table_name, [], $condition, $params);
|
||||
|
||||
if (!$this->db->isResult($fields)) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 2025.05 Use `\Friendica\BaseRepository::_selectFirstRowAsArray()` instead
|
||||
*
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
protected function _selectOne(array $condition, array $params = []): BaseEntity
|
||||
{
|
||||
$fields = $this->db->selectFirst(static::$table_name, [], $condition, $params);
|
||||
if (!$this->db->isResult($fields)) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@trigger_error('`' . __METHOD__ . '()` is deprecated since 2025.05 and will be removed after 5 months, use `\Friendica\BaseRepository::_selectFirstRowAsArray()` instead.', E_USER_DEPRECATED);
|
||||
|
||||
$fields = $this->_selectFirstRowAsArray( $condition, $params);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ HELP;
|
|||
return $help;
|
||||
}
|
||||
|
||||
public function __construct(Mode $appMode, array $argv = null)
|
||||
public function __construct(Mode $appMode, ?array $argv = null)
|
||||
{
|
||||
parent::__construct($argv);
|
||||
|
||||
|
@ -84,13 +84,13 @@ HELP;
|
|||
|
||||
switch ($command) {
|
||||
case 'add':
|
||||
return $this->addContact();
|
||||
return ($this->addContact()) ? 0 : 1;
|
||||
case 'remove':
|
||||
return $this->removeContact();
|
||||
return ($this->removeContact()) ? 0 : 1;
|
||||
case 'search':
|
||||
return $this->searchContact();
|
||||
return ($this->searchContact()) ? 0 : 1;
|
||||
case 'terminate':
|
||||
return $this->terminateContact();
|
||||
return ($this->terminateContact()) ? 0 : 1;
|
||||
default:
|
||||
throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.');
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ HELP;
|
|||
/**
|
||||
* Marks a contact for removal
|
||||
*/
|
||||
private function removeContact()
|
||||
private function removeContact(): bool
|
||||
{
|
||||
$cid = $this->getArgument(1);
|
||||
if (empty($cid)) {
|
||||
|
@ -218,6 +218,8 @@ HELP;
|
|||
}
|
||||
|
||||
ContactModel::remove($cid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -134,7 +134,7 @@ HELP;
|
|||
);
|
||||
|
||||
$fnname = 'string_plural_select_' . $lang;
|
||||
$out = 'if(! function_exists("' . $fnname . '")) {' . "\n";
|
||||
$out = 'if(! function_exists("' . $fnname . '")) {' . "\n";
|
||||
$out .= 'function ' . $fnname . '($n){' . "\n";
|
||||
$out .= ' $n = intval($n);' . "\n";
|
||||
$out .= ' ' . $return . "\n";
|
||||
|
@ -175,11 +175,11 @@ HELP;
|
|||
* @param string $string
|
||||
* @param array|string $node
|
||||
*/
|
||||
private static function parse(string $string, &$node = [])
|
||||
private static function parse(string $string, &$node)
|
||||
{
|
||||
// Removes extra outward parentheses
|
||||
if (strpos($string, '(') === 0 && strrpos($string, ')') === strlen($string) - 1) {
|
||||
$string = substr($string, 1, -1);
|
||||
$string = (string) substr($string, 1, -1);
|
||||
}
|
||||
|
||||
$q = strpos($string, '?');
|
||||
|
@ -192,13 +192,13 @@ HELP;
|
|||
|
||||
if ($q === false || $s < $q) {
|
||||
list($then, $else) = explode(':', $string, 2);
|
||||
$node['then'] = $then;
|
||||
$parsedElse = [];
|
||||
$node['then'] = $then;
|
||||
$parsedElse = [];
|
||||
self::parse($else, $parsedElse);
|
||||
$node['else'] = $parsedElse;
|
||||
} else {
|
||||
list($if, $thenelse) = explode('?', $string, 2);
|
||||
$node['if'] = $if;
|
||||
$node['if'] = $if;
|
||||
self::parse($thenelse, $node);
|
||||
}
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ HELP;
|
|||
private static function render($tree): string
|
||||
{
|
||||
if (is_array($tree)) {
|
||||
$if = trim($tree['if']);
|
||||
$if = trim($tree['if']);
|
||||
$then = trim($tree['then']);
|
||||
$else = self::render($tree['else']);
|
||||
|
||||
|
|
|
@ -106,21 +106,21 @@ HELP;
|
|||
case 'password':
|
||||
return $this->password();
|
||||
case 'add':
|
||||
return $this->addUser();
|
||||
return ($this->addUser()) ? 0 : 1;
|
||||
case 'allow':
|
||||
return $this->pendingUser(true);
|
||||
return ($this->pendingUser(true)) ? 0 : 1;
|
||||
case 'deny':
|
||||
return $this->pendingUser(false);
|
||||
return ($this->pendingUser(false)) ? 0 : 1;
|
||||
case 'block':
|
||||
return $this->blockUser(true);
|
||||
return ($this->blockUser(true)) ? 0 : 1;
|
||||
case 'unblock':
|
||||
return $this->blockUser(false);
|
||||
return ($this->blockUser(false)) ? 0 : 1;
|
||||
case 'delete':
|
||||
return $this->deleteUser();
|
||||
return ($this->deleteUser()) ? 0 : 1;
|
||||
case 'list':
|
||||
return $this->listUser();
|
||||
return ($this->listUser()) ? 0 : 1;
|
||||
case 'search':
|
||||
return $this->searchUser();
|
||||
return ($this->searchUser()) ? 0 : 1;
|
||||
case 'config':
|
||||
return ($this->configUser()) ? 0 : 1;
|
||||
default:
|
||||
|
@ -178,7 +178,7 @@ HELP;
|
|||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function password()
|
||||
private function password(): int
|
||||
{
|
||||
$user = $this->getUserByNick(1);
|
||||
|
||||
|
@ -212,7 +212,7 @@ HELP;
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
private function addUser()
|
||||
private function addUser(): bool
|
||||
{
|
||||
$name = $this->getArgument(1);
|
||||
$nick = $this->getArgument(2);
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
namespace Friendica\Contact\FriendSuggest\Repository;
|
||||
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Contact\FriendSuggest\Collection;
|
||||
use Friendica\Contact\FriendSuggest\Collection\FriendSuggests as FriendSuggestsCollection;
|
||||
use Friendica\Contact\FriendSuggest\Entity\FriendSuggest as FriendSuggestEntity;
|
||||
use Friendica\Contact\FriendSuggest\Exception\FriendSuggestNotFoundException;
|
||||
use Friendica\Contact\FriendSuggest\Exception\FriendSuggestPersistenceException;
|
||||
use Friendica\Contact\FriendSuggest\Factory;
|
||||
use Friendica\Contact\FriendSuggest\Factory\FriendSuggest as FriendSuggestFactory;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
@ -20,12 +20,12 @@ use Psr\Log\LoggerInterface;
|
|||
|
||||
class FriendSuggest extends BaseRepository
|
||||
{
|
||||
/** @var Factory\FriendSuggest */
|
||||
/** @var FriendSuggestFactory */
|
||||
protected $factory;
|
||||
|
||||
protected static $table_name = 'fsuggest';
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\FriendSuggest $factory)
|
||||
public function __construct(Database $database, LoggerInterface $logger, FriendSuggestFactory $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
}
|
||||
|
@ -49,20 +49,17 @@ class FriendSuggest extends BaseRepository
|
|||
*/
|
||||
private function selectOne(array $condition, array $params = []): FriendSuggestEntity
|
||||
{
|
||||
return parent::_selectOne($condition, $params);
|
||||
$fields = $this->_selectFirstRowAsArray($condition, $params);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
*
|
||||
* @return Collection\FriendSuggests
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function select(array $condition, array $params = []): Collection\FriendSuggests
|
||||
private function select(array $condition, array $params = []): FriendSuggestsCollection
|
||||
{
|
||||
return new Collection\FriendSuggests(parent::_select($condition, $params)->getArrayCopy());
|
||||
return new FriendSuggestsCollection(parent::_select($condition, $params)->getArrayCopy());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,13 +75,9 @@ class FriendSuggest extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $cid
|
||||
*
|
||||
* @return Collection\FriendSuggests
|
||||
*
|
||||
* @throws FriendSuggestPersistenceException In case the underlying storage cannot select the suggestion
|
||||
*/
|
||||
public function selectForContact(int $cid): Collection\FriendSuggests
|
||||
public function selectForContact(int $cid): FriendSuggestsCollection
|
||||
{
|
||||
try {
|
||||
return $this->select(['cid' => $cid]);
|
||||
|
@ -114,13 +107,9 @@ class FriendSuggest extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Collection\FriendSuggests $fsuggests
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws FriendSuggestNotFoundException in case the underlying storage cannot delete the suggestion
|
||||
*/
|
||||
public function delete(Collection\FriendSuggests $fsuggests): bool
|
||||
public function delete(FriendSuggestsCollection $fsuggests): bool
|
||||
{
|
||||
try {
|
||||
$ids = $fsuggests->column('id');
|
||||
|
|
|
@ -10,9 +10,9 @@ namespace Friendica\Contact\Introduction\Repository;
|
|||
use Friendica\BaseRepository;
|
||||
use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException;
|
||||
use Friendica\Contact\Introduction\Exception\IntroductionPersistenceException;
|
||||
use Friendica\Contact\Introduction\Collection;
|
||||
use Friendica\Contact\Introduction\Entity;
|
||||
use Friendica\Contact\Introduction\Factory;
|
||||
use Friendica\Contact\Introduction\Collection\Introductions as IntroductionsCollection;
|
||||
use Friendica\Contact\Introduction\Entity\Introduction as IntroductionEntity;
|
||||
use Friendica\Contact\Introduction\Factory\Introduction as IntroductionFactory;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
@ -20,37 +20,30 @@ use Psr\Log\LoggerInterface;
|
|||
|
||||
class Introduction extends BaseRepository
|
||||
{
|
||||
/** @var Factory\Introduction */
|
||||
/** @var IntroductionFactory */
|
||||
protected $factory;
|
||||
|
||||
protected static $table_name = 'intro';
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\Introduction $factory)
|
||||
public function __construct(Database $database, LoggerInterface $logger, IntroductionFactory $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
*
|
||||
* @return Entity\Introduction
|
||||
*
|
||||
* @throws NotFoundException the underlying exception if there's no Introduction with the given conditions
|
||||
*/
|
||||
private function selectOne(array $condition, array $params = []): Entity\Introduction
|
||||
private function selectOne(array $condition, array $params = []): IntroductionEntity
|
||||
{
|
||||
return parent::_selectOne($condition, $params);
|
||||
$fields = $this->_selectFirstRowAsArray( $condition, $params);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given Introduction into a DB compatible row array
|
||||
*
|
||||
* @param Entity\Introduction $introduction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function convertToTableRow(Entity\Introduction $introduction): array
|
||||
protected function convertToTableRow(IntroductionEntity $introduction): array
|
||||
{
|
||||
return [
|
||||
'uid' => $introduction->uid,
|
||||
|
@ -65,14 +58,9 @@ class Introduction extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $uid
|
||||
*
|
||||
* @return Entity\Introduction
|
||||
*
|
||||
* @throws IntroductionNotFoundException in case there is no Introduction with this id
|
||||
*/
|
||||
public function selectOneById(int $id, int $uid): Entity\Introduction
|
||||
public function selectOneById(int $id, int $uid): IntroductionEntity
|
||||
{
|
||||
try {
|
||||
return $this->selectOne(['id' => $id, 'uid' => $uid]);
|
||||
|
@ -88,33 +76,30 @@ class Introduction extends BaseRepository
|
|||
* @param int|null $min_id
|
||||
* @param int|null $max_id
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection\Introductions
|
||||
*/
|
||||
public function selectForUser(int $uid, int $min_id = null, int $max_id = null, int $limit = self::LIMIT): Collection\Introductions
|
||||
public function selectForUser(int $uid, ?int $min_id = null, ?int $max_id = null, int $limit = self::LIMIT): IntroductionsCollection
|
||||
{
|
||||
try {
|
||||
$BaseCollection = parent::_selectByBoundaries(
|
||||
['`uid` = ? AND NOT `ignore`',$uid],
|
||||
['order' => ['id' => 'DESC']],
|
||||
$min_id, $max_id, $limit);
|
||||
$min_id,
|
||||
$max_id,
|
||||
$limit
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
throw new IntroductionPersistenceException(sprintf('Cannot select Introductions for used %d', $uid), $e);
|
||||
}
|
||||
|
||||
return new Collection\Introductions($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount());
|
||||
return new IntroductionsCollection($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the introduction for a given contact
|
||||
*
|
||||
* @param int $cid
|
||||
*
|
||||
* @return Entity\Introduction
|
||||
*
|
||||
* @throws IntroductionNotFoundException in case there is not Introduction for this contact
|
||||
*/
|
||||
public function selectForContact(int $cid): Entity\Introduction
|
||||
public function selectForContact(int $cid): IntroductionEntity
|
||||
{
|
||||
try {
|
||||
return $this->selectOne(['contact-id' => $cid]);
|
||||
|
@ -150,13 +135,9 @@ class Introduction extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Entity\Introduction $introduction
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws IntroductionPersistenceException in case the underlying storage cannot delete the Introduction
|
||||
*/
|
||||
public function delete(Entity\Introduction $introduction): bool
|
||||
public function delete(IntroductionEntity $introduction): bool
|
||||
{
|
||||
if (!$introduction->id) {
|
||||
return false;
|
||||
|
@ -170,13 +151,9 @@ class Introduction extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Entity\Introduction $introduction
|
||||
*
|
||||
* @return Entity\Introduction
|
||||
*
|
||||
* @throws IntroductionPersistenceException In case the underlying storage cannot save the Introduction
|
||||
*/
|
||||
public function save(Entity\Introduction $introduction): Entity\Introduction
|
||||
public function save(IntroductionEntity $introduction): IntroductionEntity
|
||||
{
|
||||
try {
|
||||
$fields = $this->convertToTableRow($introduction);
|
||||
|
|
|
@ -7,59 +7,54 @@
|
|||
|
||||
namespace Friendica\Contact\LocalRelationship\Repository;
|
||||
|
||||
use Friendica\Contact\LocalRelationship\Entity;
|
||||
use Friendica\Contact\LocalRelationship\Exception;
|
||||
use Friendica\Contact\LocalRelationship\Factory;
|
||||
use Exception;
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Contact\LocalRelationship\Entity\LocalRelationship as LocalRelationshipEntity;
|
||||
use Friendica\Contact\LocalRelationship\Exception\LocalRelationshipPersistenceException;
|
||||
use Friendica\Contact\LocalRelationship\Factory\LocalRelationship as LocalRelationshipFactory;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class LocalRelationship extends \Friendica\BaseRepository
|
||||
class LocalRelationship extends BaseRepository
|
||||
{
|
||||
protected static $table_name = 'user-contact';
|
||||
|
||||
/** @var Factory\LocalRelationship */
|
||||
/** @var LocalRelationshipFactory */
|
||||
protected $factory;
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\LocalRelationship $factory)
|
||||
public function __construct(Database $database, LoggerInterface $logger, LocalRelationshipFactory $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @param int $cid
|
||||
* @return Entity\LocalRelationship
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function selectForUserContact(int $uid, int $cid): Entity\LocalRelationship
|
||||
public function selectForUserContact(int $uid, int $cid): LocalRelationshipEntity
|
||||
{
|
||||
return $this->_selectOne(['uid' => $uid, 'cid' => $cid]);
|
||||
$fields = $this->_selectFirstRowAsArray(['uid' => $uid, 'cid' => $cid]);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the existing local relationship between a user and a public contact or a default
|
||||
* relationship if it doesn't.
|
||||
*
|
||||
* @param int $uid
|
||||
* @param int $cid
|
||||
* @return Entity\LocalRelationship
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function getForUserContact(int $uid, int $cid): Entity\LocalRelationship
|
||||
public function getForUserContact(int $uid, int $cid): LocalRelationshipEntity
|
||||
{
|
||||
try {
|
||||
return $this->selectForUserContact($uid, $cid);
|
||||
} catch (HTTPException\NotFoundException $e) {
|
||||
} catch (NotFoundException $e) {
|
||||
return $this->factory->createFromTableRow(['uid' => $uid, 'cid' => $cid]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @param int $cid
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function existsForUserContact(int $uid, int $cid): bool
|
||||
{
|
||||
|
@ -68,12 +63,8 @@ class LocalRelationship extends \Friendica\BaseRepository
|
|||
|
||||
/**
|
||||
* Converts a given local relationship into a DB compatible row array
|
||||
*
|
||||
* @param Entity\LocalRelationship $localRelationship
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function convertToTableRow(Entity\LocalRelationship $localRelationship): array
|
||||
protected function convertToTableRow(LocalRelationshipEntity $localRelationship): array
|
||||
{
|
||||
return [
|
||||
'uid' => $localRelationship->userId,
|
||||
|
@ -97,13 +88,9 @@ class LocalRelationship extends \Friendica\BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Entity\LocalRelationship $localRelationship
|
||||
*
|
||||
* @return Entity\LocalRelationship
|
||||
*
|
||||
* @throws Exception\LocalRelationshipPersistenceException In case the underlying storage cannot save the LocalRelationship
|
||||
* @throws LocalRelationshipPersistenceException In case the underlying storage cannot save the LocalRelationship
|
||||
*/
|
||||
public function save(Entity\LocalRelationship $localRelationship): Entity\LocalRelationship
|
||||
public function save(LocalRelationshipEntity $localRelationship): LocalRelationshipEntity
|
||||
{
|
||||
try {
|
||||
$fields = $this->convertToTableRow($localRelationship);
|
||||
|
@ -111,8 +98,8 @@ class LocalRelationship extends \Friendica\BaseRepository
|
|||
$this->db->insert(self::$table_name, $fields, Database::INSERT_UPDATE);
|
||||
|
||||
return $localRelationship;
|
||||
} catch (\Exception $exception) {
|
||||
throw new Exception\LocalRelationshipPersistenceException(sprintf('Cannot insert/update the local relationship %d for user %d', $localRelationship->contactId, $localRelationship->userId), $exception);
|
||||
} catch (Exception $exception) {
|
||||
throw new LocalRelationshipPersistenceException(sprintf('Cannot insert/update the local relationship %d for user %d', $localRelationship->contactId, $localRelationship->userId), $exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
namespace Friendica\Content\Conversation\Repository;
|
||||
|
||||
use Friendica\BaseCollection;
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Content\Conversation\Collection\UserDefinedChannels;
|
||||
use Friendica\Content\Conversation\Entity;
|
||||
use Friendica\Content\Conversation\Factory;
|
||||
use Friendica\Content\Conversation\Entity\UserDefinedChannel as UserDefinedChannelEntity;
|
||||
use Friendica\Content\Conversation\Factory\UserDefinedChannel as UserDefinedChannelFactory;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
|
@ -21,13 +21,16 @@ use Friendica\Model\User;
|
|||
use Friendica\Util\DateTimeFormat;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class UserDefinedChannel extends \Friendica\BaseRepository
|
||||
class UserDefinedChannel extends BaseRepository
|
||||
{
|
||||
protected static $table_name = 'channel';
|
||||
|
||||
/** @var UserDefinedChannelFactory */
|
||||
protected $factory;
|
||||
|
||||
private IManageConfigValues $config;
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\UserDefinedChannel $factory, IManageConfigValues $config)
|
||||
public function __construct(Database $database, LoggerInterface $logger, UserDefinedChannelFactory $factory, IManageConfigValues $config)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
|
||||
|
@ -40,7 +43,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
* @return UserDefinedChannels
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function _select(array $condition, array $params = []): BaseCollection
|
||||
protected function _select(array $condition, array $params = []): UserDefinedChannels
|
||||
{
|
||||
$rows = $this->db->selectToArray(static::$table_name, [], $condition, $params);
|
||||
|
||||
|
@ -62,12 +65,13 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
*
|
||||
* @param int $id The id of the user defined channel
|
||||
* @param int $uid The user that this channel belongs to. (Not part of the primary key)
|
||||
* @return Entity\UserDefinedChannel
|
||||
* @throws \Friendica\Network\HTTPException\NotFoundException
|
||||
*/
|
||||
public function selectById(int $id, int $uid): Entity\UserDefinedChannel
|
||||
public function selectById(int $id, int $uid): UserDefinedChannelEntity
|
||||
{
|
||||
return $this->_selectOne(['id' => $id, 'uid' => $uid]);
|
||||
$fields = $this->_selectFirstRowAsArray(['id' => $id, 'uid' => $uid]);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,7 +110,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
return $this->_select(['uid' => $uid]);
|
||||
}
|
||||
|
||||
public function save(Entity\UserDefinedChannel $Channel): Entity\UserDefinedChannel
|
||||
public function save(UserDefinedChannelEntity $Channel): UserDefinedChannelEntity
|
||||
{
|
||||
$fields = [
|
||||
'label' => $Channel->label,
|
||||
|
@ -165,14 +169,14 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
$uids = array_column($users, 'uid');
|
||||
|
||||
$usercondition = ['uid' => $uids];
|
||||
$condition = DBA::mergeConditions($usercondition, ["`languages` != ? AND `include-tags` = ? AND `full-text-search` = ? AND `circle` = ?", '', '', '', 0]);
|
||||
$condition = DBA::mergeConditions($usercondition, ["`languages` != ? AND `include-tags` = ? AND `full-text-search` = ? AND `circle` = ?", '', '', '', 0]);
|
||||
foreach ($this->select($condition) as $channel) {
|
||||
if (!empty($channel->languages) && in_array($language, $channel->languages)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$search = '';
|
||||
$search = '';
|
||||
$condition = DBA::mergeConditions($usercondition, ["`full-text-search` != ? AND `circle` = ? AND `valid`", '', 0]);
|
||||
foreach ($this->select($condition) as $channel) {
|
||||
$search .= '(' . $channel->fullTextSearch . ') ';
|
||||
|
@ -197,7 +201,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
{
|
||||
$condition = $this->getUserCondition();
|
||||
$condition = DBA::mergeConditions($condition, ["`account-type` IN (?, ?) AND `uid` != ?", User::ACCOUNT_TYPE_RELAY, User::ACCOUNT_TYPE_COMMUNITY, 0]);
|
||||
$users = $this->db->selectToArray('user', ['uid'], $condition);
|
||||
$users = $this->db->selectToArray('user', ['uid'], $condition);
|
||||
if (empty($users)) {
|
||||
return [];
|
||||
}
|
||||
|
@ -210,7 +214,7 @@ class UserDefinedChannel extends \Friendica\BaseRepository
|
|||
$disposableFullTextSearch = new DisposableFullTextSearch($this->db, $searchtext);
|
||||
|
||||
$filteredChannels = $this->select(['uid' => array_column($users, 'uid'), 'publish' => true, 'valid' => true])->filter(
|
||||
function (Entity\UserDefinedChannel $channel) use ($owner_id, $reshare_id, $language, $tags, $media_type, $disposableFullTextSearch, $searchtext) {
|
||||
function (UserDefinedChannelEntity $channel) use ($owner_id, $reshare_id, $language, $tags, $media_type, $disposableFullTextSearch, $searchtext) {
|
||||
static $uids = [];
|
||||
|
||||
// Filter out channels from already picked users
|
||||
|
|
|
@ -92,6 +92,7 @@ class PageInfo
|
|||
{
|
||||
$eventDispatcher = DI::eventDispatcher();
|
||||
|
||||
/** @var array<string,mixed> */
|
||||
$data = $eventDispatcher->dispatch(
|
||||
new ArrayFilterEvent(ArrayFilterEvent::PAGE_INFO, $data),
|
||||
)->getArray();
|
||||
|
|
|
@ -13,7 +13,6 @@ use Friendica\Util\Images;
|
|||
use Friendica\Util\Proxy;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
|
||||
/**
|
||||
* @property-read int $id
|
||||
* @property-read int $uriId
|
||||
|
@ -122,8 +121,7 @@ class PostMedia extends BaseEntity
|
|||
?UriInterface $publisherImage = null,
|
||||
?string $blurhash = null,
|
||||
int $id = null
|
||||
)
|
||||
{
|
||||
) {
|
||||
$this->uriId = $uriId;
|
||||
$this->url = $url;
|
||||
$this->type = $type;
|
||||
|
@ -210,7 +208,7 @@ class PostMedia extends BaseEntity
|
|||
*
|
||||
* @param \GuzzleHttp\Psr7\Uri $preview
|
||||
* @param string $size
|
||||
* @return $this
|
||||
* @return self
|
||||
*/
|
||||
public function withPreview(\GuzzleHttp\Psr7\Uri $preview, string $size = ''): self
|
||||
{
|
||||
|
@ -224,8 +222,8 @@ class PostMedia extends BaseEntity
|
|||
|
||||
if ($newWidth && $newHeight && $size) {
|
||||
$dimensionts = Images::getScalingDimensions($newWidth, $newHeight, Proxy::getPixelsFromSize($size));
|
||||
$newWidth = $dimensionts['width'];
|
||||
$newHeight = $dimensionts['height'];
|
||||
$newWidth = $dimensionts['width'];
|
||||
$newHeight = $dimensionts['height'];
|
||||
}
|
||||
|
||||
return new self(
|
||||
|
|
|
@ -9,8 +9,9 @@ namespace Friendica\Content\Post\Factory;
|
|||
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Capabilities\ICanCreateFromTableRow;
|
||||
use Friendica\Content\Post\Entity;
|
||||
use Friendica\Network;
|
||||
use Friendica\Content\Post\Entity\PostMedia as PostMediaEntity;
|
||||
use Friendica\Network\Entity\MimeType as MimeTypeEntity;
|
||||
use Friendica\Network\Factory\MimeType as MimeTypeFactory;
|
||||
use Friendica\Util\Network as UtilNetwork;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
@ -18,10 +19,10 @@ use stdClass;
|
|||
|
||||
class PostMedia extends BaseFactory implements ICanCreateFromTableRow
|
||||
{
|
||||
/** @var Network\Factory\MimeType */
|
||||
/** @var MimeTypeFactory */
|
||||
private $mimeTypeFactory;
|
||||
|
||||
public function __construct(Network\Factory\MimeType $mimeTypeFactory, LoggerInterface $logger)
|
||||
public function __construct(MimeTypeFactory $mimeTypeFactory, LoggerInterface $logger)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
|
||||
|
@ -31,9 +32,9 @@ class PostMedia extends BaseFactory implements ICanCreateFromTableRow
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function createFromTableRow(array $row)
|
||||
public function createFromTableRow(array $row): PostMediaEntity
|
||||
{
|
||||
return new Entity\PostMedia(
|
||||
return new PostMediaEntity(
|
||||
$row['uri-id'],
|
||||
UtilNetwork::createUriFromString($row['url']),
|
||||
$row['type'],
|
||||
|
@ -58,13 +59,13 @@ class PostMedia extends BaseFactory implements ICanCreateFromTableRow
|
|||
);
|
||||
}
|
||||
|
||||
public function createFromBlueskyImageEmbed(int $uriId, stdClass $image): Entity\PostMedia
|
||||
public function createFromBlueskyImageEmbed(int $uriId, stdClass $image): PostMediaEntity
|
||||
{
|
||||
return new Entity\PostMedia(
|
||||
return new PostMediaEntity(
|
||||
$uriId,
|
||||
new Uri($image->fullsize),
|
||||
Entity\PostMedia::TYPE_IMAGE,
|
||||
new Network\Entity\MimeType('unkn', 'unkn'),
|
||||
PostMediaEntity::TYPE_IMAGE,
|
||||
new MimeTypeEntity('unkn', 'unkn'),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
|
@ -77,13 +78,13 @@ class PostMedia extends BaseFactory implements ICanCreateFromTableRow
|
|||
}
|
||||
|
||||
|
||||
public function createFromBlueskyExternalEmbed(int $uriId, stdClass $external): Entity\PostMedia
|
||||
public function createFromBlueskyExternalEmbed(int $uriId, stdClass $external): PostMediaEntity
|
||||
{
|
||||
return new Entity\PostMedia(
|
||||
return new PostMediaEntity(
|
||||
$uriId,
|
||||
new Uri($external->uri),
|
||||
Entity\PostMedia::TYPE_HTML,
|
||||
new Network\Entity\MimeType('text', 'html'),
|
||||
PostMediaEntity::TYPE_HTML,
|
||||
new MimeTypeEntity('text', 'html'),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
|
|
|
@ -7,11 +7,10 @@
|
|||
|
||||
namespace Friendica\Content\Post\Repository;
|
||||
|
||||
use Friendica\BaseCollection;
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Content\Post\Collection;
|
||||
use Friendica\Content\Post\Entity;
|
||||
use Friendica\Content\Post\Factory;
|
||||
use Friendica\Content\Post\Collection\PostMedias as PostMediasCollection;
|
||||
use Friendica\Content\Post\Entity\PostMedia as PostMediaEntity;
|
||||
use Friendica\Content\Post\Factory\PostMedia as PostMediaFactory;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Util\Strings;
|
||||
|
@ -21,16 +20,19 @@ class PostMedia extends BaseRepository
|
|||
{
|
||||
protected static $table_name = 'post-media';
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\PostMedia $factory)
|
||||
/** @var PostMediaFactory */
|
||||
protected $factory;
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, PostMediaFactory $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
}
|
||||
|
||||
protected function _select(array $condition, array $params = []): BaseCollection
|
||||
protected function _select(array $condition, array $params = []): PostMediasCollection
|
||||
{
|
||||
$rows = $this->db->selectToArray(static::$table_name, [], $condition, $params);
|
||||
|
||||
$Entities = new Collection\PostMedias();
|
||||
$Entities = new PostMediasCollection();
|
||||
foreach ($rows as $fields) {
|
||||
try {
|
||||
$Entities[] = $this->factory->createFromTableRow($fields);
|
||||
|
@ -42,17 +44,19 @@ class PostMedia extends BaseRepository
|
|||
return $Entities;
|
||||
}
|
||||
|
||||
public function selectOneById(int $postMediaId): Entity\PostMedia
|
||||
public function selectOneById(int $postMediaId): PostMediaEntity
|
||||
{
|
||||
return $this->_selectOne(['id' => $postMediaId]);
|
||||
$fields = $this->_selectFirstRowAsArray(['id' => $postMediaId]);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
public function selectByUriId(int $uriId): Collection\PostMedias
|
||||
public function selectByUriId(int $uriId): PostMediasCollection
|
||||
{
|
||||
return $this->_select(["`uri-id` = ? AND `type` != ?", $uriId, Post\Media::UNKNOWN]);
|
||||
}
|
||||
|
||||
public function save(Entity\PostMedia $PostMedia): Entity\PostMedia
|
||||
public function save(PostMediaEntity $PostMedia): PostMediaEntity
|
||||
{
|
||||
$fields = [
|
||||
'uri-id' => $PostMedia->uriId,
|
||||
|
@ -97,14 +101,14 @@ class PostMedia extends BaseRepository
|
|||
* @param int $uri_id URI id
|
||||
* @param array $links list of links that shouldn't be added
|
||||
* @param bool $has_media
|
||||
* @return Collection\PostMedias[] Three collections in "visual", "link" and "additional" keys
|
||||
* @return PostMediasCollection[] Three collections in "visual", "link" and "additional" keys
|
||||
*/
|
||||
public function splitAttachments(int $uri_id, array $links = [], bool $has_media = true): array
|
||||
{
|
||||
$attachments = [
|
||||
'visual' => new Collection\PostMedias(),
|
||||
'link' => new Collection\PostMedias(),
|
||||
'additional' => new Collection\PostMedias(),
|
||||
'visual' => new PostMediasCollection(),
|
||||
'link' => new PostMediasCollection(),
|
||||
'additional' => new PostMediasCollection(),
|
||||
];
|
||||
|
||||
if (!$has_media) {
|
||||
|
@ -137,7 +141,7 @@ class PostMedia extends BaseRepository
|
|||
|
||||
// Currently these two types are ignored here.
|
||||
// Posts are added differently and contacts are not displayed as attachments.
|
||||
if (in_array($PostMedia->type, [Entity\PostMedia::TYPE_ACCOUNT, Entity\PostMedia::TYPE_ACTIVITY])) {
|
||||
if (in_array($PostMedia->type, [PostMediaEntity::TYPE_ACCOUNT, PostMediaEntity::TYPE_ACTIVITY])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -148,22 +152,22 @@ class PostMedia extends BaseRepository
|
|||
//$PostMedia->filetype = $filetype;
|
||||
//$PostMedia->subtype = $subtype;
|
||||
|
||||
if ($PostMedia->type == Entity\PostMedia::TYPE_HTML || ($PostMedia->mimetype->type == 'text' && $PostMedia->mimetype->subtype == 'html')) {
|
||||
if ($PostMedia->type == PostMediaEntity::TYPE_HTML || ($PostMedia->mimetype->type == 'text' && $PostMedia->mimetype->subtype == 'html')) {
|
||||
$attachments['link'][] = $PostMedia;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
in_array($PostMedia->type, [Entity\PostMedia::TYPE_AUDIO, Entity\PostMedia::TYPE_IMAGE, Entity\PostMedia::TYPE_HLS]) ||
|
||||
in_array($PostMedia->type, [PostMediaEntity::TYPE_AUDIO, PostMediaEntity::TYPE_IMAGE, PostMediaEntity::TYPE_HLS]) ||
|
||||
in_array($PostMedia->mimetype->type, ['audio', 'image'])
|
||||
) {
|
||||
$attachments['visual'][] = $PostMedia;
|
||||
} elseif (($PostMedia->type == Entity\PostMedia::TYPE_VIDEO) || ($PostMedia->mimetype->type == 'video')) {
|
||||
} elseif (($PostMedia->type == PostMediaEntity::TYPE_VIDEO) || ($PostMedia->mimetype->type == 'video')) {
|
||||
if (!empty($PostMedia->height)) {
|
||||
// Peertube videos are delivered in many different resolutions. We pick a moderate one.
|
||||
// Since only Peertube provides a "height" parameter, this wouldn't be executed
|
||||
// when someone for example on Mastodon was sharing multiple videos in a single post.
|
||||
$heights[$PostMedia->height] = (string)$PostMedia->url;
|
||||
$heights[$PostMedia->height] = (string)$PostMedia->url;
|
||||
$video[(string) $PostMedia->url] = $PostMedia;
|
||||
} else {
|
||||
$attachments['visual'][] = $PostMedia;
|
||||
|
|
|
@ -257,6 +257,7 @@ class ConfigFileManager
|
|||
|
||||
// map the legacy configuration structure to the current structure
|
||||
foreach ($htConfigCategories as $htConfigCategory) {
|
||||
/** @phpstan-ignore-next-line $a->config could be modified after `include $fullName` */
|
||||
if (is_array($a->config[$htConfigCategory])) {
|
||||
$keys = array_keys($a->config[$htConfigCategory]);
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class Hook
|
|||
public static function loadHooks()
|
||||
{
|
||||
self::$hooks = [];
|
||||
$stmt = DBA::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
|
||||
$stmt = DBA::select('hook', ['hook', 'file', 'function'], [], ['order' => ['priority' => 'desc', 'file']]);
|
||||
|
||||
while ($hook = DBA::fetch($stmt)) {
|
||||
self::add($hook['hook'], $hook['file'], $hook['function']);
|
||||
|
|
|
@ -48,8 +48,8 @@ final class SyslogLoggerFactory implements LoggerFactory
|
|||
*/
|
||||
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;
|
||||
$logOpts = (int) $this->config->get('system', 'syslog_flags') ?? SyslogLogger::DEFAULT_FLAGS;
|
||||
$logFacility = (int) $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));
|
||||
|
@ -58,7 +58,7 @@ final class SyslogLoggerFactory implements LoggerFactory
|
|||
return new SyslogLogger(
|
||||
$logChannel,
|
||||
$this->introspection,
|
||||
(string) SyslogLogger::logLevels[$logLevel],
|
||||
SyslogLogger::logLevels[$logLevel],
|
||||
$logOpts,
|
||||
$logFacility
|
||||
);
|
||||
|
|
|
@ -22,21 +22,19 @@ class StreamLogger extends AbstractLogger
|
|||
|
||||
/**
|
||||
* The minimum loglevel at which this logger will be triggered
|
||||
* @var string
|
||||
*/
|
||||
private $logLevel;
|
||||
private int $logLevel;
|
||||
|
||||
/**
|
||||
* The stream, where the current logger is writing into
|
||||
* @var resource
|
||||
* @var resource|null
|
||||
*/
|
||||
private $stream;
|
||||
|
||||
/**
|
||||
* The current process ID
|
||||
* @var int
|
||||
*/
|
||||
private $pid;
|
||||
private int $pid;
|
||||
|
||||
/**
|
||||
* Translates LogLevel log levels to integer values
|
||||
|
|
|
@ -29,7 +29,7 @@ class SyslogLogger extends AbstractLogger
|
|||
|
||||
/**
|
||||
* Translates LogLevel log levels to syslog log priorities.
|
||||
* @var array
|
||||
* @var array<string,int>
|
||||
*/
|
||||
public const logLevels = [
|
||||
LogLevel::DEBUG => LOG_DEBUG,
|
||||
|
@ -60,39 +60,33 @@ class SyslogLogger extends AbstractLogger
|
|||
/**
|
||||
* Indicates what logging options will be used when generating a log message
|
||||
* @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $logOpts;
|
||||
private int $logOpts;
|
||||
|
||||
/**
|
||||
* Used to specify what type of program is logging the message
|
||||
* @see http://php.net/manual/en/function.openlog.php#refsect1-function.openlog-parameters
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $logFacility;
|
||||
private int $logFacility;
|
||||
|
||||
/**
|
||||
* The minimum loglevel at which this logger will be triggered
|
||||
* @var int
|
||||
*/
|
||||
private $logLevel;
|
||||
private int $logLevel;
|
||||
|
||||
/**
|
||||
* A error message of the current operation
|
||||
* @var string
|
||||
*/
|
||||
private $errorMessage;
|
||||
private string $errorMessage;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param string $logLevel The minimum loglevel at which this logger will be triggered
|
||||
* @param string $logOptions
|
||||
* @param string $logFacility
|
||||
* @param int $logLevel The minimum loglevel at which this logger will be triggered
|
||||
* @param int $logOptions
|
||||
* @param int $logFacility
|
||||
*/
|
||||
public function __construct(string $channel, IHaveCallIntrospections $introspection, string $logLevel, string $logOptions, string $logFacility)
|
||||
public function __construct(string $channel, IHaveCallIntrospections $introspection, int $logLevel, int $logOptions, int $logFacility)
|
||||
{
|
||||
parent::__construct($channel, $introspection);
|
||||
|
||||
|
@ -166,7 +160,7 @@ class SyslogLogger extends AbstractLogger
|
|||
restore_error_handler();
|
||||
|
||||
if (!$opened) {
|
||||
throw new LoggerException(sprintf('Can\'t open syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, $this->logFacility));
|
||||
throw new LoggerException(sprintf('Can\'t open syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, (string) $this->logFacility));
|
||||
}
|
||||
|
||||
$this->syslogWrapper($priority, $message);
|
||||
|
@ -215,7 +209,7 @@ class SyslogLogger extends AbstractLogger
|
|||
restore_error_handler();
|
||||
|
||||
if (!$written) {
|
||||
throw new LoggerException(sprintf('Can\'t write into syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, $this->logFacility));
|
||||
throw new LoggerException(sprintf('Can\'t write into syslog for ident "%s" and facility "%s": ' . $this->errorMessage, $this->channel, (string) $this->logFacility));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class PConfig
|
|||
*/
|
||||
public function isConnected(): bool
|
||||
{
|
||||
return $this->db->isConnected() & !$this->mode->isInstall();
|
||||
return $this->db->isConnected() && !$this->mode->isInstall();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -101,7 +101,7 @@ class UserSession implements IHandleUserSessions
|
|||
public function getUserIDForVisitorContactID(int $cid): int
|
||||
{
|
||||
if (empty($this->session->get('remote'))) {
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return array_search($cid, $this->session->get('remote'));
|
||||
|
|
|
@ -80,7 +80,7 @@ class Database implements ICanWriteToStorage
|
|||
throw new StorageException(sprintf('Database storage failed to update %s', $reference), 500, new Exception($this->dba->errorMessage(), $this->dba->errorNo()));
|
||||
}
|
||||
|
||||
return $this->dba->lastInsertId();
|
||||
return (string) $this->dba->lastInsertId();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -452,19 +452,17 @@ class System
|
|||
|
||||
/**
|
||||
* Returns the current Load of the System
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function currentLoad()
|
||||
public static function currentLoad(): float
|
||||
{
|
||||
if (!function_exists('sys_getloadavg')) {
|
||||
return false;
|
||||
return (float) 0;
|
||||
}
|
||||
|
||||
$load_arr = sys_getloadavg();
|
||||
|
||||
if (!is_array($load_arr)) {
|
||||
return false;
|
||||
return (float) 0;
|
||||
}
|
||||
|
||||
return round(max($load_arr[0], $load_arr[1]), 2);
|
||||
|
|
|
@ -217,7 +217,7 @@ class Update
|
|||
->set('system', 'maintenance', false)
|
||||
->delete('system', 'maintenance_reason')
|
||||
->commit();
|
||||
return $r;
|
||||
return 'Pre update failed';
|
||||
} else {
|
||||
DI::logger()->notice('Pre update executed.', ['version' => $version]);
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ class Update
|
|||
->set('system', 'maintenance', false)
|
||||
->delete('system', 'maintenance_reason')
|
||||
->commit();
|
||||
return $r;
|
||||
return 'Post update failed';
|
||||
} else {
|
||||
DI::config()->set('system', 'build', $version);
|
||||
DI::logger()->notice('Post update executed.', ['version' => $version]);
|
||||
|
|
|
@ -272,12 +272,13 @@ class Worker
|
|||
*
|
||||
* @param integer $priority The priority that should be checked
|
||||
*
|
||||
* @return integer Is there a process running with that priority?
|
||||
* @return bool Is there a process running with that priority?
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function processWithPriorityActive(int $priority): int
|
||||
private static function processWithPriorityActive(int $priority): bool
|
||||
{
|
||||
$condition = ["`priority` <= ? AND `pid` != 0 AND NOT `done`", $priority];
|
||||
|
||||
return DBA::exists('workerqueue', $condition);
|
||||
}
|
||||
|
||||
|
@ -956,7 +957,7 @@ class Worker
|
|||
/**
|
||||
* Returns the priority of the next workerqueue job
|
||||
*
|
||||
* @return string|bool priority or FALSE on failure
|
||||
* @return int|false priority or FALSE on failure
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function nextPriority()
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
namespace Friendica\Core\Worker\Repository;
|
||||
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Core\Worker\Entity\Process as ProcessEntity;
|
||||
use Friendica\Core\Worker\Exception\ProcessPersistenceException;
|
||||
use Friendica\Core\Worker\Factory\Process as ProcessFactory;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Core\Worker\Factory;
|
||||
use Friendica\Core\Worker\Entity;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
|
@ -24,13 +24,13 @@ class Process extends BaseRepository
|
|||
|
||||
protected static $table_name = 'process';
|
||||
|
||||
/** @var Factory\Process */
|
||||
/** @var ProcessFactory */
|
||||
protected $factory;
|
||||
|
||||
/** @var string */
|
||||
private $currentHost;
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\Process $factory, array $server)
|
||||
public function __construct(Database $database, LoggerInterface $logger, ProcessFactory $factory, array $server)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
|
||||
|
@ -39,13 +39,8 @@ class Process extends BaseRepository
|
|||
|
||||
/**
|
||||
* Starts and Returns the process for a given PID at the current host
|
||||
*
|
||||
* @param int $pid
|
||||
* @param string $command
|
||||
*
|
||||
* @return Entity\Process
|
||||
*/
|
||||
public function create(int $pid, string $command): Entity\Process
|
||||
public function create(int $pid, string $command): ProcessEntity
|
||||
{
|
||||
// Cleanup inactive process
|
||||
$this->deleteInactive();
|
||||
|
@ -64,7 +59,9 @@ class Process extends BaseRepository
|
|||
}
|
||||
}
|
||||
|
||||
$result = $this->_selectOne(['pid' => $pid, 'hostname' => $this->currentHost]);
|
||||
$fields = $this->_selectFirstRowAsArray(['pid' => $pid, 'hostname' => $this->currentHost]);
|
||||
|
||||
$result = $this->factory->createFromTableRow($fields);
|
||||
|
||||
$this->db->commit();
|
||||
|
||||
|
@ -74,7 +71,7 @@ class Process extends BaseRepository
|
|||
}
|
||||
}
|
||||
|
||||
public function delete(Entity\Process $process)
|
||||
public function delete(ProcessEntity $process)
|
||||
{
|
||||
try {
|
||||
if (!$this->db->delete(static::$table_name, [
|
||||
|
|
|
@ -60,17 +60,17 @@ class Database
|
|||
protected $syslock = null;
|
||||
|
||||
protected $server_info = '';
|
||||
/** @var PDO|mysqli */
|
||||
/** @var PDO|mysqli|null */
|
||||
protected $connection;
|
||||
protected $driver = '';
|
||||
protected $driver = '';
|
||||
protected $pdo_emulate_prepares = false;
|
||||
private $error = '';
|
||||
private $errorno = 0;
|
||||
private $affected_rows = 0;
|
||||
protected $in_transaction = false;
|
||||
protected $in_retrial = false;
|
||||
protected $testmode = false;
|
||||
private $relation = [];
|
||||
private $error = '';
|
||||
private $errorno = 0;
|
||||
private $affected_rows = 0;
|
||||
protected $in_transaction = false;
|
||||
protected $in_retrial = false;
|
||||
protected $testmode = false;
|
||||
private $relation = [];
|
||||
/** @var DbaDefinition */
|
||||
protected $dbaDefinition;
|
||||
/** @var ViewDefinition */
|
||||
|
@ -86,7 +86,7 @@ class Database
|
|||
$this->viewDefinition = $viewDefinition;
|
||||
|
||||
// Use dummy values - necessary for the first factory call of the logger itself
|
||||
$this->logger = new NullLogger();
|
||||
$this->logger = new NullLogger();
|
||||
$this->profiler = new Profiler($config);
|
||||
|
||||
$this->connect();
|
||||
|
@ -253,7 +253,7 @@ class Database
|
|||
/**
|
||||
* Return the database object.
|
||||
*
|
||||
* @return PDO|mysqli
|
||||
* @return PDO|mysqli|null
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
|
@ -474,7 +474,7 @@ class Database
|
|||
*
|
||||
* @param string $sql SQL statement
|
||||
*
|
||||
* @return bool|object statement object or result object
|
||||
* @return bool|mysqli_result|mysqli_stmt|object|PDOStatement statement object or result object
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function p(string $sql)
|
||||
|
@ -630,7 +630,7 @@ class Database
|
|||
} elseif (is_string($args[$param])) {
|
||||
$param_types .= 's';
|
||||
} elseif (is_object($args[$param]) && method_exists($args[$param], '__toString')) {
|
||||
$param_types .= 's';
|
||||
$param_types .= 's';
|
||||
$args[$param] = (string)$args[$param];
|
||||
} else {
|
||||
$param_types .= 'b';
|
||||
|
@ -677,9 +677,9 @@ class Database
|
|||
}
|
||||
|
||||
$this->logger->error('DB Error', [
|
||||
'code' => $errorno,
|
||||
'error' => $error,
|
||||
'params' => $this->replaceParameters($sql, $args),
|
||||
'code' => $errorno,
|
||||
'error' => $error,
|
||||
'params' => $this->replaceParameters($sql, $args),
|
||||
]);
|
||||
|
||||
// On a lost connection we try to reconnect - but only once.
|
||||
|
@ -784,9 +784,9 @@ class Database
|
|||
}
|
||||
|
||||
$this->logger->error('DB Error', [
|
||||
'code' => $errorno,
|
||||
'error' => $error,
|
||||
'params' => $this->replaceParameters($sql, $params),
|
||||
'code' => $errorno,
|
||||
'error' => $error,
|
||||
'params' => $this->replaceParameters($sql, $params),
|
||||
]);
|
||||
|
||||
// On a lost connection we simply quit.
|
||||
|
@ -1335,7 +1335,7 @@ class Database
|
|||
return true;
|
||||
}
|
||||
|
||||
$fields = $this->castFields($table, $fields);
|
||||
$fields = $this->castFields($table, $fields);
|
||||
$direct_fields = [];
|
||||
|
||||
foreach ($fields as $key => $value) {
|
||||
|
|
|
@ -41,7 +41,6 @@ class Photo extends BaseFactory
|
|||
* @param int $scale
|
||||
* @param int $uid
|
||||
* @param string $type
|
||||
* @return Array
|
||||
*/
|
||||
public function createFromId(string $photo_id, int $scale = null, int $uid, string $type = 'json', bool $with_posts = true): array
|
||||
{
|
||||
|
@ -66,7 +65,7 @@ class Photo extends BaseFactory
|
|||
$data['id'] = $data['resource-id'];
|
||||
|
||||
if (is_int($scale)) {
|
||||
$data['data'] = base64_encode(ModelPhoto::getImageDataForPhoto($data));
|
||||
$data['data'] = base64_encode(ModelPhoto::getImageDataForPhoto($data) ?? '');
|
||||
}
|
||||
|
||||
if ($type == 'xml') {
|
||||
|
|
|
@ -11,7 +11,7 @@ use Friendica\App\BaseURL;
|
|||
use Friendica\BaseFactory;
|
||||
use Friendica\Model\Attach;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Util\Images;
|
||||
use Friendica\Util\Proxy;
|
||||
|
@ -32,7 +32,7 @@ class Attachment extends BaseFactory
|
|||
/**
|
||||
* @param int $uriId Uri-ID of the attachments
|
||||
* @return array
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function createFromUriId(int $uriId): array
|
||||
{
|
||||
|
@ -47,23 +47,25 @@ class Attachment extends BaseFactory
|
|||
/**
|
||||
* @param int $id id of the media
|
||||
* @return \Friendica\Object\Api\Mastodon\Attachment
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function createFromId(int $id): \Friendica\Object\Api\Mastodon\Attachment
|
||||
{
|
||||
$attachment = Post\Media::getById($id);
|
||||
|
||||
if (empty($attachment)) {
|
||||
return [];
|
||||
throw new InternalServerErrorException();
|
||||
}
|
||||
|
||||
return $this->createFromMediaArray($attachment);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $attachment
|
||||
* @return \Friendica\Object\Api\Mastodon\Attachment
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
private function createFromMediaArray(array $attachment): \Friendica\Object\Api\Mastodon\Attachment
|
||||
private function createFromMediaArray(array $attachment): \Friendica\Object\Api\Mastodon\Attachment
|
||||
{
|
||||
$filetype = !empty($attachment['mimetype']) ? strtolower(substr($attachment['mimetype'], 0, strpos($attachment['mimetype'], '/'))) : '';
|
||||
|
||||
|
@ -100,7 +102,7 @@ class Attachment extends BaseFactory
|
|||
* @param int $id id of the photo
|
||||
*
|
||||
* @return array
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function createFromPhoto(int $id): array
|
||||
{
|
||||
|
@ -136,7 +138,7 @@ class Attachment extends BaseFactory
|
|||
* @param int $id id of the attachment
|
||||
*
|
||||
* @return array
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function createFromAttach(int $id): array
|
||||
{
|
||||
|
|
|
@ -39,7 +39,7 @@ class Status extends BaseFactory
|
|||
private $mention;
|
||||
/** @var Activities entity */
|
||||
private $activities;
|
||||
/** @var Activities entity */
|
||||
/** @var Attachment entity */
|
||||
private $attachment;
|
||||
/** @var ContentItem */
|
||||
private $contentItem;
|
||||
|
@ -111,7 +111,7 @@ class Status extends BaseFactory
|
|||
*/
|
||||
private function createFromArray(array $item, int $uid, bool $include_entities): \Friendica\Object\Api\Twitter\Status
|
||||
{
|
||||
$item = Post\Media::addHTMLAttachmentToItem($item);
|
||||
$item = Post\Media::addHTMLAttachmentToItem($item);
|
||||
$author = $this->twitterUser->createFromContactId($item['author-id'], $uid, true);
|
||||
|
||||
if (!empty($item['causer-id']) && ($item['post-reason'] == Item::PR_ANNOUNCEMENT)) {
|
||||
|
@ -165,7 +165,7 @@ class Status extends BaseFactory
|
|||
$urls = $this->url->createFromUriId($item['uri-id']);
|
||||
$mentions = $this->mention->createFromUriId($item['uri-id']);
|
||||
} else {
|
||||
$attachments = $this->attachment->createFromUriId($item['uri-id'], $text);
|
||||
$attachments = $this->attachment->createFromUriId($item['uri-id']);
|
||||
}
|
||||
|
||||
$friendica_activities = $this->activities->createFromUriId($item['uri-id'], $uid);
|
||||
|
@ -180,7 +180,7 @@ class Status extends BaseFactory
|
|||
$urls = array_merge($urls, $this->url->createFromUriId($shared_uri_id));
|
||||
$mentions = array_merge($mentions, $this->mention->createFromUriId($shared_uri_id));
|
||||
} else {
|
||||
$attachments = array_merge($attachments, $this->attachment->createFromUriId($shared_uri_id, $text));
|
||||
$attachments = array_merge($attachments, $this->attachment->createFromUriId($shared_uri_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,6 +203,6 @@ class Status extends BaseFactory
|
|||
$entities = [];
|
||||
}
|
||||
|
||||
return new \Friendica\Object\Api\Twitter\Status($text, $statusnetHtml, $friendicaHtml, $item, $author, $owner, $retweeted, $quoted, $geo, $friendica_activities, $entities, $attachments, $friendica_comments, $liked);
|
||||
return new \Friendica\Object\Api\Twitter\Status($text, $statusnetHtml, $friendicaHtml, $item, $author, $owner, $retweeted, $quoted, $geo, $friendica_activities, $entities, $attachments, $friendica_comments, $liked);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,26 +8,37 @@
|
|||
namespace Friendica\Federation\Repository;
|
||||
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Federation\Factory;
|
||||
use Friendica\Federation\Entity;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Friendica\Federation\Entity\GServer as GServerEntity;
|
||||
use Friendica\Federation\Factory\GServer as GServerFactory;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
|
||||
class GServer extends \Friendica\BaseRepository
|
||||
final class GServer
|
||||
{
|
||||
protected static $table_name = 'gserver';
|
||||
private string $table_name = 'gserver';
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\GServer $factory)
|
||||
private Database $db;
|
||||
|
||||
private GServerFactory $factory;
|
||||
|
||||
public function __construct(Database $database, GServerFactory $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
$this->db = $database;
|
||||
$this->factory = $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $gsid
|
||||
* @return Entity\GServer
|
||||
*
|
||||
* @throws \Friendica\Network\HTTPException\NotFoundException
|
||||
*/
|
||||
public function selectOneById(int $gsid): Entity\GServer
|
||||
public function selectOneById(int $gsid): GServerEntity
|
||||
{
|
||||
return $this->_selectOne(['id' => $gsid]);
|
||||
$fields = $this->db->selectFirst($this->table_name, [], ['id' => $gsid], []);
|
||||
|
||||
if (!$this->db->isResult($fields)) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,8 @@ class User
|
|||
* Insert a user-contact for a given contact array
|
||||
*
|
||||
* @param array $contact
|
||||
* @return void
|
||||
*/
|
||||
public static function insertForContactArray(array $contact)
|
||||
public static function insertForContactArray(array $contact): bool
|
||||
{
|
||||
if (empty($contact['uid'])) {
|
||||
// We don't create entries for the public user - by now
|
||||
|
@ -339,7 +338,7 @@ class User
|
|||
{
|
||||
$pcid = Contact::getPublicContactId($cid, $uid);
|
||||
if (!$pcid) {
|
||||
return false;
|
||||
return self::FREQUENCY_DEFAULT;
|
||||
}
|
||||
|
||||
$public_contact = DBA::selectFirst('user-contact', ['channel-frequency'], ['cid' => $pcid, 'uid' => $uid]);
|
||||
|
|
|
@ -310,7 +310,7 @@ class Event
|
|||
);
|
||||
}
|
||||
|
||||
return $event['id'];
|
||||
return (int) $event['id'];
|
||||
}
|
||||
|
||||
public static function getItemArrayForId(int $event_id, array $item = []): array
|
||||
|
|
|
@ -2200,8 +2200,6 @@ class GServer
|
|||
* Converts input value to a boolean value
|
||||
*
|
||||
* @param string|integer $val
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private static function toBoolean($val): bool
|
||||
{
|
||||
|
@ -2211,7 +2209,7 @@ class GServer
|
|||
return false;
|
||||
}
|
||||
|
||||
return $val;
|
||||
return (bool) $val;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -671,7 +671,7 @@ class Item
|
|||
/**
|
||||
* Inserts item record
|
||||
*
|
||||
* @param array $item Item array to be inserted
|
||||
* @param array<string,mixed> $item Item array to be inserted
|
||||
* @param int $notify Notification (type?)
|
||||
* @param bool $post_local (???)
|
||||
* @return int Zero means error, otherwise primary key (id) is being returned
|
||||
|
@ -694,6 +694,7 @@ class Item
|
|||
|
||||
// If it is a posting where users should get notifications, then define it as wall posting
|
||||
if ($notify) {
|
||||
/** @var array<string,mixed> */
|
||||
$item = $itemHelper->prepareOriginPost($item);
|
||||
|
||||
if (is_int($notify) && in_array($notify, Worker::PRIORITIES)) {
|
||||
|
@ -707,6 +708,7 @@ class Item
|
|||
$item['network'] = trim(($item['network'] ?? '') ?: Protocol::PHANTOM);
|
||||
}
|
||||
|
||||
/** @var array<string,mixed> */
|
||||
$item = $itemHelper->prepareItemData($item, (bool) $notify);
|
||||
|
||||
// Store conversation data
|
||||
|
@ -748,6 +750,7 @@ class Item
|
|||
}
|
||||
}
|
||||
|
||||
/** @var array<string,mixed> */
|
||||
$item = $itemHelper->validateItemData($item);
|
||||
|
||||
// Ensure that there is an avatar cache
|
||||
|
@ -853,6 +856,7 @@ class Item
|
|||
new ArrayFilterEvent(ArrayFilterEvent::INSERT_POST_LOCAL, $hook_data)
|
||||
)->getArray();
|
||||
|
||||
/** @var array<string,mixed> */
|
||||
$item = $hook_data['item'] ?? $item;
|
||||
|
||||
if ($dummy_session) {
|
||||
|
|
|
@ -21,7 +21,7 @@ class ParsedLogIterator implements \Iterator
|
|||
/** @var ReversedFileReader */
|
||||
private $reader;
|
||||
|
||||
/** @var ParsedLogLine current iterator value*/
|
||||
/** @var ParsedLogLine|null current iterator value*/
|
||||
private $value = null;
|
||||
|
||||
/** @var int max number of lines to read */
|
||||
|
|
|
@ -244,7 +244,7 @@ class Photo
|
|||
*
|
||||
* @param array $photo Photo data. Needs at least 'id', 'type', 'backend-class', 'backend-ref'
|
||||
*
|
||||
* @return \Friendica\Object\Image|null Image object or null on error
|
||||
* @return string|null Image data as string or null on error
|
||||
*/
|
||||
public static function getImageDataForPhoto(array $photo)
|
||||
{
|
||||
|
@ -254,7 +254,7 @@ class Photo
|
|||
|
||||
try {
|
||||
$backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? '');
|
||||
/// @todo refactoring this returning, because the storage returns a "string" which is casted in different ways - a check "instanceof Image" will fail!
|
||||
|
||||
return $backendClass->get($photo['backend-ref'] ?? '');
|
||||
} catch (InvalidClassStorageException $storageException) {
|
||||
try {
|
||||
|
@ -834,10 +834,9 @@ class Photo
|
|||
* - Sharing a post with a group will create a photo that only the group can see.
|
||||
* - Sharing a photo again that been shared non public before doesn't alter the permissions.
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function setPermissionFromBody($body, $uid, $original_contact_id, $str_contact_allow, $str_circle_allow, $str_contact_deny, $str_circle_deny)
|
||||
public static function setPermissionFromBody($body, $uid, $original_contact_id, $str_contact_allow, $str_circle_allow, $str_contact_deny, $str_circle_deny): bool
|
||||
{
|
||||
// Simplify image codes
|
||||
$img_body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
|
||||
|
|
|
@ -170,9 +170,8 @@ class Delayed
|
|||
* @param array $attachments
|
||||
* @param int $preparation_mode
|
||||
* @param string $uri
|
||||
* @return bool
|
||||
*/
|
||||
public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = self::PREPARED, string $uri = '')
|
||||
public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = self::PREPARED, string $uri = ''): int
|
||||
{
|
||||
if (!empty($attachments)) {
|
||||
$item['attachments'] = $attachments;
|
||||
|
|
|
@ -7,12 +7,14 @@
|
|||
|
||||
namespace Friendica\Moderation\Repository;
|
||||
|
||||
use Friendica\BaseEntity;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Moderation\Factory;
|
||||
use Friendica\Moderation\Collection;
|
||||
use Friendica\Moderation\Collection\Report\Posts as PostsCollection;
|
||||
use Friendica\Moderation\Collection\Report\Rules as RulesCollection;
|
||||
use Friendica\Moderation\Entity\Report as ReportEntity;
|
||||
use Friendica\Moderation\Factory\Report as ReportFactory;
|
||||
use Friendica\Moderation\Factory\Report\Post as PostFactory;
|
||||
use Friendica\Moderation\Factory\Report\Rule as RuleFactory;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
@ -21,14 +23,14 @@ final class Report extends \Friendica\BaseRepository
|
|||
{
|
||||
protected static $table_name = 'report';
|
||||
|
||||
/** @var Factory\Report */
|
||||
/** @var ReportFactory */
|
||||
protected $factory;
|
||||
/** @var Factory\Report\Post */
|
||||
/** @var PostFactory */
|
||||
protected $postFactory;
|
||||
/** @var Factory\Report\Rule */
|
||||
/** @var RuleFactory */
|
||||
protected $ruleFactory;
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\Report $factory, Factory\Report\Post $postFactory, Factory\Report\Rule $ruleFactory)
|
||||
public function __construct(Database $database, LoggerInterface $logger, ReportFactory $factory, PostFactory $postFactory, RuleFactory $ruleFactory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
|
||||
|
@ -37,12 +39,12 @@ final class Report extends \Friendica\BaseRepository
|
|||
$this->ruleFactory = $ruleFactory;
|
||||
}
|
||||
|
||||
public function selectOneById(int $lastInsertId): \Friendica\Moderation\Entity\Report
|
||||
public function selectOneById(int $lastInsertId): ReportEntity
|
||||
{
|
||||
return $this->_selectOne(['id' => $lastInsertId]);
|
||||
}
|
||||
|
||||
public function save(\Friendica\Moderation\Entity\Report $Report): \Friendica\Moderation\Entity\Report
|
||||
public function save(ReportEntity $Report): ReportEntity
|
||||
{
|
||||
$fields = [
|
||||
'reporter-id' => $Report->reporterCid,
|
||||
|
@ -73,7 +75,7 @@ final class Report extends \Friendica\BaseRepository
|
|||
if (Post::exists(['uri-id' => $post->uriId])) {
|
||||
$this->db->insert('report-post', ['rid' => $newReportId, 'uri-id' => $post->uriId, 'status' => $post->status]);
|
||||
} else {
|
||||
DI::logger()->notice('Post does not exist', ['uri-id' => $post->uriId, 'report' => $Report]);
|
||||
$this->logger->notice('Post does not exist', ['uri-id' => $post->uriId, 'report' => $Report]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,15 +89,18 @@ final class Report extends \Friendica\BaseRepository
|
|||
return $Report;
|
||||
}
|
||||
|
||||
protected function _selectOne(array $condition, array $params = []): BaseEntity
|
||||
/**
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
protected function _selectOne(array $condition, array $params = []): ReportEntity
|
||||
{
|
||||
$fields = $this->db->selectFirst(self::$table_name, [], $condition, $params);
|
||||
if (!$this->db->isResult($fields)) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$reportPosts = new Collection\Report\Posts(array_map([$this->postFactory, 'createFromTableRow'], $this->db->selectToArray('report-post', ['uri-id', 'status'], ['rid' => $condition['id'] ?? 0])));
|
||||
$reportRules = new Collection\Report\Rules(array_map([$this->ruleFactory, 'createFromTableRow'], $this->db->selectToArray('report-rule', ['line-id', 'text'], ['rid' => $condition['id'] ?? 0])));
|
||||
$reportPosts = new PostsCollection(array_map([$this->postFactory, 'createFromTableRow'], $this->db->selectToArray('report-post', ['uri-id', 'status'], ['rid' => $condition['id'] ?? 0])));
|
||||
$reportRules = new RulesCollection(array_map([$this->ruleFactory, 'createFromTableRow'], $this->db->selectToArray('report-rule', ['line-id', 'text'], ['rid' => $condition['id'] ?? 0])));
|
||||
|
||||
return $this->factory->createFromTableRow($fields, $reportPosts, $reportRules);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class Accounts extends BaseApi
|
|||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
return Circle::removeMembers($this->parameters['id'], $request['account_ids']);
|
||||
Circle::removeMembers($this->parameters['id'], $request['account_ids']);
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
|
|
|
@ -13,6 +13,7 @@ use Friendica\Model\Contact;
|
|||
use Friendica\Model\Photo;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
/**
|
||||
|
@ -43,12 +44,13 @@ class Media extends BaseApi
|
|||
|
||||
if (in_array($type, [Post\Media::IMAGE, Post\Media::UNKNOWN, Post\Media::APPLICATION])) {
|
||||
$media = Photo::upload($uid, $request['file'], '', null, null, '', '', $request['description']);
|
||||
if (!empty($media)) {
|
||||
$this->logger->info('Uploaded photo', ['media' => $media]);
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromPhoto($media['id']));
|
||||
} elseif ($type == Post\Media::IMAGE) {
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromPhoto($media['id']));
|
||||
|
||||
if (empty($media)) {
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity('Error while uploading media.'));
|
||||
}
|
||||
|
||||
$this->logger->info('Uploaded photo', ['media' => $media]);
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromPhoto($media['id']));
|
||||
}
|
||||
|
||||
$tempFileName = $request['file']['tmp_name'];
|
||||
|
@ -97,14 +99,24 @@ class Media extends BaseApi
|
|||
$photo = Photo::selectFirst(['resource-id'], ['id' => $this->parameters['id'], 'uid' => $uid]);
|
||||
if (empty($photo['resource-id'])) {
|
||||
$media = Post\Media::getById($this->parameters['id']);
|
||||
|
||||
if (empty($media['uri-id'])) {
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if (!Post::exists(['uri-id' => $media['uri-id'], 'uid' => $uid, 'origin' => true])) {
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Post\Media::updateById(['description' => $request['description']], $this->parameters['id']);
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id']));
|
||||
|
||||
try {
|
||||
$attachment = DI::mstdnAttachment()->createFromId($this->parameters['id'] . '1');
|
||||
} catch (InternalServerErrorException $th) {
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$this->jsonExit($attachment);
|
||||
}
|
||||
|
||||
Photo::update(['desc' => $request['description']], ['resource-id' => $photo['resource-id']]);
|
||||
|
|
|
@ -219,9 +219,10 @@ class Search extends BaseApi
|
|||
|
||||
$condition = ["`id` IN (SELECT `tid` FROM `post-tag` WHERE `type` = ?) AND `name` LIKE ?", Tag::HASHTAG, $q . '%'];
|
||||
|
||||
$tags = DBA::select('tag', ['name'], $condition, $params);
|
||||
$tags = DBA::selectToArray('tag', ['name'], $condition, $params);
|
||||
|
||||
$hashtags = [];
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
if ($version == 1) {
|
||||
$hashtags[] = $tag['name'];
|
||||
|
|
|
@ -44,10 +44,11 @@ class Ownership extends BaseApi
|
|||
$this->checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
|
||||
$circles = $this->dba->select('group', [], ['deleted' => false, 'uid' => $uid, 'cid' => null]);
|
||||
$circles = $this->dba->selectToArray('group', [], ['deleted' => false, 'uid' => $uid, 'cid' => null]);
|
||||
|
||||
// loop through all circles
|
||||
$lists = [];
|
||||
|
||||
foreach ($circles as $circle) {
|
||||
$lists[] = $this->friendicaCircle->createFromId($circle['id']);
|
||||
}
|
||||
|
|
|
@ -61,9 +61,9 @@ class Network extends Timeline
|
|||
protected $dateFrom;
|
||||
/** @var string */
|
||||
protected $dateTo;
|
||||
/** @var int */
|
||||
/** @var bool */
|
||||
protected $star;
|
||||
/** @var int */
|
||||
/** @var bool */
|
||||
protected $mention;
|
||||
|
||||
/** @var AppHelper */
|
||||
|
|
|
@ -11,7 +11,6 @@ use Friendica\App;
|
|||
use Friendica\BaseModule;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Module\Response;
|
||||
|
@ -59,20 +58,20 @@ class RemoveTag extends BaseModule
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $request The $_REQUEST array
|
||||
* @param string|null $type Output parameter with the computed type
|
||||
* @param string|null $term Output parameter with the computed term
|
||||
* @param array $request The $_REQUEST array
|
||||
* @param string|int|null $type Output parameter with the computed type
|
||||
* @param string|null $term Output parameter with the computed term
|
||||
*
|
||||
* @return int The relevant HTTP code
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function removeTag(array $request, string &$type = null, string &$term = null): int
|
||||
private function removeTag(array $request, &$type = null, string &$term = null): int
|
||||
{
|
||||
$item_id = $this->parameters['id'] ?? 0;
|
||||
|
||||
$term = trim($request['term'] ?? '');
|
||||
$cat = trim($request['cat'] ?? '');
|
||||
$cat = trim($request['cat'] ?? '');
|
||||
|
||||
if (!empty($cat)) {
|
||||
$type = Post\Category::CATEGORY;
|
||||
|
|
|
@ -308,7 +308,9 @@ class Photo extends BaseApi
|
|||
|
||||
// For local users directly use the photo record that is marked as the profile
|
||||
if (DI::baseUrl()->isLocalUrl($contact['url'])) {
|
||||
$contact = Contact::selectFirst($fields, ['nurl' => $contact['nurl'], 'self' => true]);
|
||||
$nurl = $contact['nurl'];
|
||||
$contact = Contact::selectFirst($fields, ['nurl' => $nurl, 'self' => true]);
|
||||
|
||||
if (!empty($contact)) {
|
||||
if ($customsize <= Proxy::PIXEL_MICRO) {
|
||||
$scale = 6;
|
||||
|
@ -324,7 +326,7 @@ class Photo extends BaseApi
|
|||
$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']]);
|
||||
$this->logger->notice('Local Contact was not found', ['url' => $nurl]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,36 +8,55 @@
|
|||
namespace Friendica\Navigation\Notifications\Collection;
|
||||
|
||||
use Friendica\BaseCollection;
|
||||
use Friendica\Navigation\Notifications\Entity;
|
||||
use Friendica\Navigation\Notifications\Entity\Notification as NotificationEntity;
|
||||
|
||||
class Notifications extends BaseCollection
|
||||
{
|
||||
/**
|
||||
* @return Entity\Notification
|
||||
*/
|
||||
public function current(): Entity\Notification
|
||||
public function current(): NotificationEntity
|
||||
{
|
||||
return parent::current();
|
||||
}
|
||||
|
||||
public function setSeen(): Notifications
|
||||
{
|
||||
return $this->map(function (Entity\Notification $Notification) {
|
||||
$Notification->setSeen();
|
||||
$notifications = $this->map(function (NotificationEntity $notification) {
|
||||
$notification->setSeen();
|
||||
});
|
||||
|
||||
if (!$notifications instanceof Notifications) {
|
||||
// Show the possible error explicitly
|
||||
throw new \Exception(sprintf(
|
||||
'BaseCollection::map() should return instance of %s, but returns %s instead.',
|
||||
Notifications::class,
|
||||
get_class($notifications),
|
||||
));
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
public function setDismissed(): Notifications
|
||||
{
|
||||
return $this->map(function (Entity\Notification $Notification) {
|
||||
$Notification->setDismissed();
|
||||
$notifications = $this->map(function (NotificationEntity $notification) {
|
||||
$notification->setDismissed();
|
||||
});
|
||||
|
||||
if (!$notifications instanceof Notifications) {
|
||||
// Show the possible error explicitly
|
||||
throw new \Exception(sprintf(
|
||||
'BaseCollection::map() should return instance of %s, but returns %s instead.',
|
||||
Notifications::class,
|
||||
get_class($notifications),
|
||||
));
|
||||
}
|
||||
|
||||
return $notifications;
|
||||
}
|
||||
|
||||
public function countUnseen(): int
|
||||
{
|
||||
return array_reduce($this->getArrayCopy(), function (int $carry, Entity\Notification $Notification) {
|
||||
return $carry + ($Notification->seen ? 0 : 1);
|
||||
return array_reduce($this->getArrayCopy(), function (int $carry, NotificationEntity $notification) {
|
||||
return $carry + ($notification->seen ? 0 : 1);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,22 +8,30 @@
|
|||
namespace Friendica\Navigation\Notifications\Collection;
|
||||
|
||||
use Friendica\BaseCollection;
|
||||
use Friendica\Navigation\Notifications\Entity;
|
||||
use Friendica\Navigation\Notifications\Entity\Notify as NotifyEntity;
|
||||
|
||||
class Notifies extends BaseCollection
|
||||
{
|
||||
/**
|
||||
* @return Entity\Notify
|
||||
*/
|
||||
public function current(): Entity\Notify
|
||||
public function current(): NotifyEntity
|
||||
{
|
||||
return parent::current();
|
||||
}
|
||||
|
||||
public function setSeen(): Notifies
|
||||
{
|
||||
return $this->map(function (Entity\Notify $Notify) {
|
||||
$Notify->setSeen();
|
||||
$notifies = $this->map(function (NotifyEntity $notify) {
|
||||
$notify->setSeen();
|
||||
});
|
||||
|
||||
if (!$notifies instanceof Notifies) {
|
||||
// Show the possible error explicitly
|
||||
throw new \Exception(sprintf(
|
||||
'BaseCollection::map() should return instance of %s, but returns %s instead.',
|
||||
Notifies::class,
|
||||
get_class($notifies),
|
||||
));
|
||||
}
|
||||
|
||||
return $notifies;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use Friendica\Core\Renderer;
|
|||
use Psr\Http\Message\UriInterface;
|
||||
|
||||
/**
|
||||
* @property-read string $type
|
||||
* @property-read int $type
|
||||
* @property-read string $name
|
||||
* @property-read UriInterface $url
|
||||
* @property-read UriInterface $photo
|
||||
|
@ -33,7 +33,8 @@ use Psr\Http\Message\UriInterface;
|
|||
* @property-read int|null $parentUriId
|
||||
* @property-read int|null $id
|
||||
*
|
||||
* @deprecated since 2022.05 Use \Friendica\Navigation\Notifications\Entity\Notification instead
|
||||
* @deprecated 2022.05 Use \Friendica\Navigation\Notifications\Entity\Notification instead
|
||||
* @see \Friendica\Navigation\Notifications\Entity\Notification
|
||||
*/
|
||||
class Notify extends BaseEntity
|
||||
{
|
||||
|
|
|
@ -15,8 +15,8 @@ use Friendica\Database\Database;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Post\UserNotification;
|
||||
use Friendica\Model\Verb;
|
||||
use Friendica\Navigation\Notifications\Collection;
|
||||
use Friendica\Navigation\Notifications\Entity;
|
||||
use Friendica\Navigation\Notifications\Collection\Notifications as NotificationsCollection;
|
||||
use Friendica\Navigation\Notifications\Entity\Notification as NotificationEntity;
|
||||
use Friendica\Navigation\Notifications\Factory;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Protocol\Activity;
|
||||
|
@ -41,19 +41,18 @@ class Notification extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
* @return Entity\Notification
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
private function selectOne(array $condition, array $params = []): Entity\Notification
|
||||
private function selectOne(array $condition, array $params = []): NotificationEntity
|
||||
{
|
||||
return parent::_selectOne($condition, $params);
|
||||
$fields = $this->_selectFirstRowAsArray( $condition, $params);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
private function select(array $condition, array $params = []): Collection\Notifications
|
||||
private function select(array $condition, array $params = []): NotificationsCollection
|
||||
{
|
||||
return new Collection\Notifications(parent::_select($condition, $params)->getArrayCopy());
|
||||
return new NotificationsCollection(parent::_select($condition, $params)->getArrayCopy());
|
||||
}
|
||||
|
||||
public function countForUser($uid, array $condition, array $params = []): int
|
||||
|
@ -71,23 +70,21 @@ class Notification extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return Entity\Notification
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function selectOneById(int $id): Entity\Notification
|
||||
public function selectOneById(int $id): NotificationEntity
|
||||
{
|
||||
return $this->selectOne(['id' => $id]);
|
||||
}
|
||||
|
||||
public function selectOneForUser(int $uid, array $condition, array $params = []): Entity\Notification
|
||||
public function selectOneForUser(int $uid, array $condition, array $params = []): NotificationEntity
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition, ['uid' => $uid]);
|
||||
|
||||
return $this->selectOne($condition, $params);
|
||||
}
|
||||
|
||||
public function selectForUser(int $uid, array $condition = [], array $params = []): Collection\Notifications
|
||||
public function selectForUser(int $uid, array $condition = [], array $params = []): NotificationsCollection
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition, ['uid' => $uid]);
|
||||
|
||||
|
@ -98,12 +95,9 @@ class Notification extends BaseRepository
|
|||
/**
|
||||
* Returns only the most recent notifications for the same conversation or contact
|
||||
*
|
||||
* @param int $uid
|
||||
*
|
||||
* @return Collection\Notifications
|
||||
* @throws Exception
|
||||
*/
|
||||
public function selectDetailedForUser(int $uid): Collection\Notifications
|
||||
public function selectDetailedForUser(int $uid): NotificationsCollection
|
||||
{
|
||||
$notify_type = $this->pconfig->get($uid, 'system', 'notify_type');
|
||||
if (!is_null($notify_type)) {
|
||||
|
@ -113,11 +107,11 @@ class Notification extends BaseRepository
|
|||
}
|
||||
|
||||
if (!$this->pconfig->get($uid, 'system', 'notify_like')) {
|
||||
$condition = DBA::mergeConditions($condition, ['NOT `vid` IN (?, ?)', Verb::getID(\Friendica\Protocol\Activity::LIKE), Verb::getID(\Friendica\Protocol\Activity::DISLIKE)]);
|
||||
$condition = DBA::mergeConditions($condition, ['NOT `vid` IN (?, ?)', Verb::getID(Activity::LIKE), Verb::getID(Activity::DISLIKE)]);
|
||||
}
|
||||
|
||||
if (!$this->pconfig->get($uid, 'system', 'notify_announce')) {
|
||||
$condition = DBA::mergeConditions($condition, ['`vid` != ?', Verb::getID(\Friendica\Protocol\Activity::ANNOUNCE)]);
|
||||
$condition = DBA::mergeConditions($condition, ['`vid` != ?', Verb::getID(Activity::ANNOUNCE)]);
|
||||
}
|
||||
|
||||
return $this->selectForUser($uid, $condition, ['limit' => 50, 'order' => ['id' => true]]);
|
||||
|
@ -126,33 +120,30 @@ class Notification extends BaseRepository
|
|||
/**
|
||||
* Returns only the most recent notifications for the same conversation or contact
|
||||
*
|
||||
* @param int $uid
|
||||
*
|
||||
* @return Collection\Notifications
|
||||
* @throws Exception
|
||||
*/
|
||||
public function selectDigestForUser(int $uid): Collection\Notifications
|
||||
public function selectDigestForUser(int $uid): NotificationsCollection
|
||||
{
|
||||
$values = [$uid];
|
||||
|
||||
$type_condition = '';
|
||||
$notify_type = $this->pconfig->get($uid, 'system', 'notify_type');
|
||||
$notify_type = $this->pconfig->get($uid, 'system', 'notify_type');
|
||||
if (!is_null($notify_type)) {
|
||||
$type_condition = 'AND `type` & ? != 0';
|
||||
$values[] = $notify_type | UserNotification::TYPE_SHARED | UserNotification::TYPE_FOLLOW;
|
||||
$values[] = $notify_type | UserNotification::TYPE_SHARED | UserNotification::TYPE_FOLLOW;
|
||||
}
|
||||
|
||||
$like_condition = '';
|
||||
if (!$this->pconfig->get($uid, 'system', 'notify_like')) {
|
||||
$like_condition = 'AND NOT `vid` IN (?, ?)';
|
||||
$values[] = Verb::getID(\Friendica\Protocol\Activity::LIKE);
|
||||
$values[] = Verb::getID(\Friendica\Protocol\Activity::DISLIKE);
|
||||
$values[] = Verb::getID(Activity::LIKE);
|
||||
$values[] = Verb::getID(Activity::DISLIKE);
|
||||
}
|
||||
|
||||
$announce_condition = '';
|
||||
if (!$this->pconfig->get($uid, 'system', 'notify_announce')) {
|
||||
$announce_condition = 'AND vid != ?';
|
||||
$values[] = Verb::getID(\Friendica\Protocol\Activity::ANNOUNCE);
|
||||
$values[] = Verb::getID(Activity::ANNOUNCE);
|
||||
}
|
||||
|
||||
$rows = $this->db->p("
|
||||
|
@ -171,15 +162,20 @@ class Notification extends BaseRepository
|
|||
LIMIT 50
|
||||
", ...$values);
|
||||
|
||||
$Entities = new Collection\Notifications();
|
||||
foreach ($rows as $fields) {
|
||||
$Entities[] = $this->factory->createFromTableRow($fields);
|
||||
$entities = new NotificationsCollection();
|
||||
|
||||
if (!is_iterable($rows)) {
|
||||
return $entities;
|
||||
}
|
||||
|
||||
return $Entities;
|
||||
foreach ($rows as $fields) {
|
||||
$entities[] = $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public function selectAllForUser(int $uid): Collection\Notifications
|
||||
public function selectAllForUser(int $uid): NotificationsCollection
|
||||
{
|
||||
return $this->selectForUser($uid);
|
||||
}
|
||||
|
@ -199,7 +195,7 @@ class Notification extends BaseRepository
|
|||
{
|
||||
$BaseCollection = parent::_selectByBoundaries($condition, $params, $min_id, $max_id, $limit);
|
||||
|
||||
return new Collection\Notifications($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount());
|
||||
return new NotificationsCollection($BaseCollection->getArrayCopy(), $BaseCollection->getTotalCount());
|
||||
}
|
||||
|
||||
public function setAllSeenForUser(int $uid, array $condition = []): bool
|
||||
|
@ -217,11 +213,9 @@ class Notification extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Entity\Notification $Notification
|
||||
* @return Entity\Notification
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save(Entity\Notification $Notification): Entity\Notification
|
||||
public function save(NotificationEntity $Notification): NotificationEntity
|
||||
{
|
||||
$fields = [
|
||||
'uid' => $Notification->uid,
|
||||
|
@ -259,12 +253,12 @@ class Notification extends BaseRepository
|
|||
public function deleteForItem(int $itemUriId): bool
|
||||
{
|
||||
$conditionTarget = [
|
||||
'vid' => Verb::getID(Activity::POST),
|
||||
'vid' => Verb::getID(Activity::POST),
|
||||
'target-uri-id' => $itemUriId,
|
||||
];
|
||||
|
||||
$conditionParent = [
|
||||
'vid' => Verb::getID(Activity::POST),
|
||||
'vid' => Verb::getID(Activity::POST),
|
||||
'parent-uri-id' => $itemUriId,
|
||||
];
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@ use Friendica\Event\ArrayFilterEvent;
|
|||
use Friendica\Factory\Api\Mastodon\Notification as NotificationFactory;
|
||||
use Friendica\Model;
|
||||
use Friendica\Navigation\Notifications\Collection;
|
||||
use Friendica\Navigation\Notifications\Entity;
|
||||
use Friendica\Navigation\Notifications\Entity\Notification as NotificationEntity;
|
||||
use Friendica\Navigation\Notifications\Entity\Notify as NotifyEntity;
|
||||
use Friendica\Navigation\Notifications\Exception;
|
||||
use Friendica\Navigation\Notifications\Factory;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
@ -32,7 +33,7 @@ use Psr\EventDispatcher\EventDispatcherInterface;
|
|||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* @deprecated since 2022.05 Use \Friendica\Navigation\Notifications\Repository\Notification instead
|
||||
* @deprecated 2022.05 Use `\Friendica\Navigation\Notifications\Repository\Notification` instead
|
||||
*/
|
||||
class Notify extends BaseRepository
|
||||
{
|
||||
|
@ -85,15 +86,13 @@ class Notify extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
*
|
||||
* @return Entity\Notify
|
||||
* @throws HTTPException\NotFoundException
|
||||
*/
|
||||
private function selectOne(array $condition, array $params = []): Entity\Notify
|
||||
private function selectOne(array $condition, array $params = []): NotifyEntity
|
||||
{
|
||||
return parent::_selectOne($condition, $params);
|
||||
$fields = $this->_selectFirstRowAsArray( $condition, $params);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
private function select(array $condition, array $params = []): Collection\Notifies
|
||||
|
@ -118,10 +117,9 @@ class Notify extends BaseRepository
|
|||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return Entity\Notify
|
||||
* @throws HTTPException\NotFoundException
|
||||
*/
|
||||
public function selectOneById(int $id): Entity\Notify
|
||||
public function selectOneById(int $id): NotifyEntity
|
||||
{
|
||||
return $this->selectOne(['id' => $id]);
|
||||
}
|
||||
|
@ -153,14 +151,11 @@ class Notify extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Entity\Notify $Notify
|
||||
*
|
||||
* @return Entity\Notify
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws Exception\NotificationCreationInterceptedException
|
||||
*/
|
||||
public function save(Entity\Notify $Notify): Entity\Notify
|
||||
public function save(NotifyEntity $Notify): NotifyEntity
|
||||
{
|
||||
$fields = [
|
||||
'type' => $Notify->type,
|
||||
|
@ -198,7 +193,7 @@ class Notify extends BaseRepository
|
|||
return $Notify;
|
||||
}
|
||||
|
||||
public function setAllSeenForRelatedNotify(Entity\Notify $Notify): bool
|
||||
public function setAllSeenForRelatedNotify(NotifyEntity $Notify): bool
|
||||
{
|
||||
$condition = [
|
||||
'(`link` = ? OR (`parent` != 0 AND `parent` = ? AND `otype` = ?)) AND `uid` = ?',
|
||||
|
@ -691,7 +686,7 @@ class Notify extends BaseRepository
|
|||
return false;
|
||||
}
|
||||
|
||||
public function shouldShowOnDesktop(Entity\Notification $Notification, string $type = null): bool
|
||||
public function shouldShowOnDesktop(NotificationEntity $Notification, string $type = null): bool
|
||||
{
|
||||
if (is_null($type)) {
|
||||
$type = NotificationFactory::getType($Notification);
|
||||
|
@ -723,7 +718,7 @@ class Notify extends BaseRepository
|
|||
return false;
|
||||
}
|
||||
|
||||
public function createFromNotification(Entity\Notification $Notification): bool
|
||||
public function createFromNotification(NotificationEntity $Notification): bool
|
||||
{
|
||||
$this->logger->info('Start', ['uid' => $Notification->uid, 'id' => $Notification->id, 'type' => $Notification->type]);
|
||||
|
||||
|
|
|
@ -61,6 +61,34 @@ class Introduction implements \JsonSerializable
|
|||
/** @var string */
|
||||
private $about;
|
||||
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
$this->label = $data['label'] ?? '';
|
||||
$this->type = $data['str_type'] ?? '';
|
||||
$this->intro_id = $data['intro_id'] ?? -1;
|
||||
$this->madeBy = $data['madeBy'] ?? '';
|
||||
$this->madeByUrl = $data['madeByUrl'] ?? '';
|
||||
$this->madeByZrl = $data['madeByZrl'] ?? '';
|
||||
$this->madeByAddr = $data['madeByAddr'] ?? '';
|
||||
$this->contactId = $data['contactId'] ?? -1;
|
||||
$this->photo = $data['photo'] ?? '';
|
||||
$this->name = $data['name'] ?? '';
|
||||
$this->url = $data['url'] ?? '';
|
||||
$this->zrl = $data['zrl'] ?? '';
|
||||
$this->hidden = $data['hidden'] ?? false;
|
||||
$this->postNewFriend = $data['postNewFriend'] ?? '';
|
||||
$this->knowYou = $data['knowYou'] ?? false;
|
||||
$this->note = $data['note'] ?? '';
|
||||
$this->request = $data['request'] ?? '';
|
||||
$this->dfrnId = -1;
|
||||
$this->addr = $data['addr'] ?? '';
|
||||
$this->network = $data['network'] ?? '';
|
||||
$this->uid = $data['uid'] ?? -1;
|
||||
$this->keywords = $data['keywords'] ?? '';
|
||||
$this->location = $data['location'] ?? '';
|
||||
$this->about = $data['about'] ?? '';
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
|
@ -131,7 +159,7 @@ class Introduction implements \JsonSerializable
|
|||
return $this->postNewFriend;
|
||||
}
|
||||
|
||||
public function getKnowYou(): string
|
||||
public function getKnowYou(): bool
|
||||
{
|
||||
return $this->knowYou;
|
||||
}
|
||||
|
@ -181,34 +209,6 @@ class Introduction implements \JsonSerializable
|
|||
return $this->about;
|
||||
}
|
||||
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
$this->label = $data['label'] ?? '';
|
||||
$this->type = $data['str_type'] ?? '';
|
||||
$this->intro_id = $data['intro_id'] ?? -1;
|
||||
$this->madeBy = $data['madeBy'] ?? '';
|
||||
$this->madeByUrl = $data['madeByUrl'] ?? '';
|
||||
$this->madeByZrl = $data['madeByZrl'] ?? '';
|
||||
$this->madeByAddr = $data['madeByAddr'] ?? '';
|
||||
$this->contactId = $data['contactId'] ?? -1;
|
||||
$this->photo = $data['photo'] ?? '';
|
||||
$this->name = $data['name'] ?? '';
|
||||
$this->url = $data['url'] ?? '';
|
||||
$this->zrl = $data['zrl'] ?? '';
|
||||
$this->hidden = $data['hidden'] ?? false;
|
||||
$this->postNewFriend = $data['postNewFriend'] ?? '';
|
||||
$this->knowYou = $data['knowYou'] ?? false;
|
||||
$this->note = $data['note'] ?? '';
|
||||
$this->request = $data['request'] ?? '';
|
||||
$this->dfrnId = -1;
|
||||
$this->addr = $data['addr'] ?? '';
|
||||
$this->network = $data['network'] ?? '';
|
||||
$this->uid = $data['uid'] ?? -1;
|
||||
$this->keywords = $data['keywords'] ?? '';
|
||||
$this->location = $data['location'] ?? '';
|
||||
$this->about = $data['about'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
|
|
@ -225,11 +225,11 @@ class CurlResult implements ICanHandleHttpResponses
|
|||
}
|
||||
}
|
||||
|
||||
$this->redirectUrl = (string)Uri::fromParts((array)$redirect_parts);
|
||||
$this->isRedirectUrl = true;
|
||||
$this->redirectUrl = (string)Uri::fromParts((array)$redirect_parts);
|
||||
$this->isRedirectUrl = true;
|
||||
$this->redirectIsPermanent = $this->returnCode == 301 || $this->returnCode == 308;
|
||||
} else {
|
||||
$this->isRedirectUrl = false;
|
||||
$this->isRedirectUrl = false;
|
||||
$this->redirectIsPermanent = false;
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ class CurlResult implements ICanHandleHttpResponses
|
|||
/** {@inheritDoc} */
|
||||
public function getReturnCode(): string
|
||||
{
|
||||
return $this->returnCode;
|
||||
return (string) $this->returnCode;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
@ -100,7 +100,7 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
|
|||
/** {@inheritDoc} */
|
||||
public function getReturnCode(): string
|
||||
{
|
||||
return $this->getStatusCode();
|
||||
return (string) $this->getStatusCode();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
@ -62,37 +62,37 @@ class Notification extends BaseDataTransferObject
|
|||
/** @var string Message (Plaintext) */
|
||||
protected $msg_plain;
|
||||
|
||||
public function __construct(Notify $Notify)
|
||||
public function __construct(Notify $notify)
|
||||
{
|
||||
$this->id = $Notify->id;
|
||||
$this->type = $Notify->type;
|
||||
$this->name = $Notify->name;
|
||||
$this->url = $Notify->url->__toString();
|
||||
$this->photo = $Notify->photo->__toString();
|
||||
$this->date = DateTimeFormat::local($Notify->date->format(DateTimeFormat::MYSQL));
|
||||
$this->msg = $Notify->msg;
|
||||
$this->uid = $Notify->uid;
|
||||
$this->link = $Notify->link->__toString();
|
||||
$this->iid = $Notify->itemId;
|
||||
$this->parent = $Notify->parent;
|
||||
$this->seen = $Notify->seen;
|
||||
$this->verb = $Notify->verb;
|
||||
$this->otype = $Notify->otype;
|
||||
$this->name_cache = $Notify->name_cache;
|
||||
$this->msg_cache = $Notify->msg_cache;
|
||||
$this->timestamp = $Notify->date->format('U');
|
||||
$this->id = $notify->id;
|
||||
$this->type = $notify->type;
|
||||
$this->name = $notify->name;
|
||||
$this->url = $notify->url->__toString();
|
||||
$this->photo = $notify->photo->__toString();
|
||||
$this->date = DateTimeFormat::local($notify->date->format(DateTimeFormat::MYSQL));
|
||||
$this->msg = $notify->msg;
|
||||
$this->uid = $notify->uid;
|
||||
$this->link = $notify->link->__toString();
|
||||
$this->iid = $notify->itemId;
|
||||
$this->parent = $notify->parent;
|
||||
$this->seen = $notify->seen;
|
||||
$this->verb = $notify->verb;
|
||||
$this->otype = $notify->otype;
|
||||
$this->name_cache = $notify->name_cache;
|
||||
$this->msg_cache = $notify->msg_cache;
|
||||
$this->timestamp = (int) $notify->date->format('U');
|
||||
$this->date_rel = Temporal::getRelativeDate($this->date);
|
||||
|
||||
try {
|
||||
$this->msg_html = BBCode::convertForUriId($Notify->uriId, $this->msg, BBCode::EXTERNAL);
|
||||
$this->msg_html = BBCode::convertForUriId($notify->uriId, $this->msg, BBCode::EXTERNAL);
|
||||
} catch (\Exception $e) {
|
||||
$this->msg_html = '';
|
||||
$this->msg_html = '';
|
||||
}
|
||||
|
||||
try {
|
||||
$this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0];
|
||||
} catch (\Exception $e) {
|
||||
$this->msg_plain = '';
|
||||
$this->msg_plain = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,12 @@ class Field extends BaseDataTransferObject
|
|||
protected $name;
|
||||
/** @var string (HTML) */
|
||||
protected $value;
|
||||
/** @var string (Datetime)*/
|
||||
/** @var string|null (Datetime)*/
|
||||
protected $verified_at;
|
||||
|
||||
public function __construct(string $name, string $value)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->name = $name;
|
||||
$this->value = $value;
|
||||
// Link verification unsupported
|
||||
$this->verified_at = null;
|
||||
|
|
|
@ -44,9 +44,9 @@ class Notification extends BaseDataTransferObject
|
|||
protected $created_at;
|
||||
/** @var bool */
|
||||
protected $dismissed;
|
||||
/** @var Account */
|
||||
/** @var array */
|
||||
protected $account;
|
||||
/** @var Status|null */
|
||||
/** @var array|null */
|
||||
protected $status = null;
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ class Poll extends BaseDataTransferObject
|
|||
/** @var bool|null */
|
||||
protected $voted = false;
|
||||
/** @var array|null */
|
||||
protected $own_votes = false;
|
||||
protected $own_votes = null;
|
||||
/** @var array */
|
||||
protected $options = [];
|
||||
/** @var Emoji[] */
|
||||
|
|
|
@ -18,7 +18,7 @@ use Friendica\Util\Network;
|
|||
*/
|
||||
class Relationship extends BaseDataTransferObject
|
||||
{
|
||||
/** @var int */
|
||||
/** @var string */
|
||||
protected $id;
|
||||
/** @var bool */
|
||||
protected $following = false;
|
||||
|
@ -93,7 +93,5 @@ class Relationship extends BaseDataTransferObject
|
|||
$this->blocked_by = $isBlocked;
|
||||
$this->note = $contactRecord['info'];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class ScheduledStatus extends BaseDataTransferObject
|
|||
'in_reply_to_id' => null,
|
||||
'application_id' => ''
|
||||
];
|
||||
/** @var Attachment */
|
||||
/** @var array */
|
||||
protected $media_attachments = [];
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@ class Status extends BaseDataTransferObject
|
|||
protected $edited_at;
|
||||
/** @var string|null */
|
||||
protected $in_reply_to_id = null;
|
||||
/** @var Status|null - Fedilab extension, see issue https://github.com/friendica/friendica/issues/12672 */
|
||||
/** @var Status[]|null - Fedilab extension, see issue https://github.com/friendica/friendica/issues/12672 */
|
||||
protected $in_reply_to_status = null;
|
||||
/** @var string|null */
|
||||
protected $in_reply_to_account_id = null;
|
||||
|
@ -66,25 +66,25 @@ class Status extends BaseDataTransferObject
|
|||
protected $content;
|
||||
/** @var array */
|
||||
protected $filtered = [];
|
||||
/** @var Status|null */
|
||||
/** @var Status[]|null */
|
||||
protected $reblog = null;
|
||||
/** @var Status|null - Akkoma extension, see issue https://github.com/friendica/friendica/issues/12603 */
|
||||
/** @var Status[]|null - Akkoma extension, see issue https://github.com/friendica/friendica/issues/12603 */
|
||||
protected $quote = null;
|
||||
/** @var Application */
|
||||
/** @var array */
|
||||
protected $application = null;
|
||||
/** @var Account */
|
||||
/** @var array */
|
||||
protected $account;
|
||||
/** @var Attachment */
|
||||
/** @var Attachment[] */
|
||||
protected $media_attachments = [];
|
||||
/** @var Mention */
|
||||
/** @var Mention[] */
|
||||
protected $mentions = [];
|
||||
/** @var Tag */
|
||||
/** @var Tag[] */
|
||||
protected $tags = [];
|
||||
/** @var Emoji[] */
|
||||
protected $emojis = [];
|
||||
/** @var Card|null */
|
||||
/** @var array|null */
|
||||
protected $card = null;
|
||||
/** @var Poll|null */
|
||||
/** @var array|null */
|
||||
protected $poll = null;
|
||||
/** @var FriendicaExtension */
|
||||
protected $friendica;
|
||||
|
|
|
@ -29,9 +29,9 @@ class DirectMessage extends BaseDataTransferObject
|
|||
protected $sender_screen_name = null;
|
||||
/** @var string */
|
||||
protected $recipient_screen_name = null;
|
||||
/** @var User */
|
||||
/** @var array */
|
||||
protected $sender;
|
||||
/** @var User */
|
||||
/** @var array */
|
||||
protected $recipient;
|
||||
/** @var string|null */
|
||||
protected $title;
|
||||
|
|
|
@ -31,7 +31,7 @@ class Media extends BaseDataTransferObject
|
|||
protected $media_url;
|
||||
/** @var string */
|
||||
protected $media_url_https;
|
||||
/** @var string */
|
||||
/** @var array<string, array<string, mixed>> */
|
||||
protected $sizes;
|
||||
/** @var string */
|
||||
protected $type;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Friendica\Object\Api\Twitter;
|
||||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseDataTransferObject;
|
||||
|
||||
/**
|
||||
|
@ -37,7 +36,7 @@ class Mention extends BaseDataTransferObject
|
|||
*/
|
||||
public function __construct(array $tag, array $contact, array $indices)
|
||||
{
|
||||
$this->id = (string)($contact['id'] ?? 0);
|
||||
$this->id = (int)($contact['id'] ?? 0);
|
||||
$this->id_str = (string)($contact['id'] ?? 0);
|
||||
$this->indices = $indices;
|
||||
$this->name = $tag['name'];
|
||||
|
|
|
@ -45,11 +45,11 @@ class Status extends BaseDataTransferObject
|
|||
protected $geo;
|
||||
/** @var bool */
|
||||
protected $favorited = false;
|
||||
/** @var User */
|
||||
/** @var array */
|
||||
protected $user;
|
||||
/** @var User */
|
||||
/** @var array */
|
||||
protected $friendica_author;
|
||||
/** @var User */
|
||||
/** @var array */
|
||||
protected $friendica_owner;
|
||||
/** @var bool */
|
||||
protected $friendica_private;
|
||||
|
@ -67,9 +67,9 @@ class Status extends BaseDataTransferObject
|
|||
protected $friendica_html;
|
||||
/** @var int */
|
||||
protected $friendica_comments;
|
||||
/** @var Status|null */
|
||||
/** @var array|null */
|
||||
protected $retweeted_status = null;
|
||||
/** @var Status|null */
|
||||
/** @var array|null */
|
||||
protected $quoted_status = null;
|
||||
/** @var array */
|
||||
protected $attachments;
|
||||
|
|
|
@ -29,7 +29,7 @@ class ParsedLogLine
|
|||
/** @var string */
|
||||
public $message = null;
|
||||
|
||||
/** @var string */
|
||||
/** @var string|null */
|
||||
public $data = null;
|
||||
|
||||
/** @var string */
|
||||
|
|
|
@ -48,7 +48,7 @@ class Post
|
|||
private $parent = null;
|
||||
|
||||
/**
|
||||
* @var Thread
|
||||
* @var Thread|null
|
||||
*/
|
||||
private $thread = null;
|
||||
private $redirect_url = null;
|
||||
|
@ -70,7 +70,7 @@ class Post
|
|||
$this->setTemplate('wall');
|
||||
$this->toplevel = $this->getId() == $this->getDataValue('parent');
|
||||
|
||||
if (!empty(DI::userSession()->getUserIDForVisitorContactID($this->getDataValue('contact-id')))) {
|
||||
if (DI::userSession()->getUserIDForVisitorContactID($this->getDataValue('contact-id')) !== 0) {
|
||||
$this->visiting = true;
|
||||
}
|
||||
|
||||
|
@ -824,7 +824,7 @@ class Post
|
|||
* Get a child by its ID
|
||||
*
|
||||
* @param integer $id The child id
|
||||
* @return Thread|null Thread or NULL if not found
|
||||
* @return Post|null Post or NULL if not found
|
||||
*/
|
||||
public function getChild(int $id)
|
||||
{
|
||||
|
|
|
@ -77,8 +77,7 @@ class Thread
|
|||
break;
|
||||
default:
|
||||
DI::logger()->info('[ERROR] Conversation::setMode : Unhandled mode ('. $mode .').');
|
||||
return false;
|
||||
break;
|
||||
return;
|
||||
}
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
|
|
@ -8,31 +8,33 @@
|
|||
namespace Friendica\Profile\ProfileField\Collection;
|
||||
|
||||
use Friendica\BaseCollection;
|
||||
use Friendica\Profile\ProfileField\Entity;
|
||||
use Friendica\Profile\ProfileField\Entity\ProfileField as ProfileFieldEntity;
|
||||
|
||||
class ProfileFields extends BaseCollection
|
||||
{
|
||||
public function current(): Entity\ProfileField
|
||||
public function current(): ProfileFieldEntity
|
||||
{
|
||||
return parent::current();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable $callback
|
||||
* @return ProfileFields (as an extended form of BaseCollection)
|
||||
*/
|
||||
public function map(callable $callback): BaseCollection
|
||||
public function map(callable $callback): ProfileFields
|
||||
{
|
||||
return parent::map($callback);
|
||||
$profileFields = parent::map($callback);
|
||||
|
||||
if (!$profileFields instanceof ProfileFields) {
|
||||
// Show the possible error explicitly
|
||||
throw new \Exception(sprintf(
|
||||
'BaseCollection::map() should return instance of %s, but returns %s instead.',
|
||||
ProfileFields::class,
|
||||
get_class($profileFields),
|
||||
));
|
||||
}
|
||||
|
||||
return $profileFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable|null $callback
|
||||
* @param int $flag
|
||||
* @return ProfileFields as an extended version of BaseCollection
|
||||
*/
|
||||
public function filter(callable $callback = null, int $flag = 0): BaseCollection
|
||||
public function filter(?callable $callback = null, int $flag = 0): ProfileFields
|
||||
{
|
||||
return parent::filter($callback, $flag);
|
||||
return new self(array_filter($this->getArrayCopy(), $callback, $flag));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -848,17 +848,17 @@ class Processor
|
|||
return $class;
|
||||
}
|
||||
|
||||
public function fetchUriId(string $uri, int $uid): string
|
||||
public function fetchUriId(string $uri, int $uid): int
|
||||
{
|
||||
$reply = Post::selectFirst(['uri-id'], ['uri' => $uri, 'uid' => [$uid, 0]]);
|
||||
if (!empty($reply['uri-id'])) {
|
||||
$this->logger->debug('Post exists', ['uri' => $uri]);
|
||||
return $reply['uri-id'];
|
||||
return (int) $reply['uri-id'];
|
||||
}
|
||||
$reply = Post::selectFirst(['uri-id'], ['extid' => $uri, 'uid' => [$uid, 0]]);
|
||||
if (!empty($reply['uri-id'])) {
|
||||
$this->logger->debug('Post with extid exists', ['uri' => $uri]);
|
||||
return $reply['uri-id'];
|
||||
return (int) $reply['uri-id'];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -250,7 +250,7 @@ class Receiver
|
|||
* @param string $object_id Object ID of the provided object
|
||||
* @param integer $uid User ID
|
||||
*
|
||||
* @return string with object type or NULL
|
||||
* @return string|null string with object type or NULL
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
|
|
|
@ -607,64 +607,64 @@ class DFRN
|
|||
* @param string $element Element name for the activity
|
||||
* @param string $activity activity value
|
||||
* @param int $uriid Uri-Id of the post
|
||||
* @return DOMElement XML activity object
|
||||
* @return DOMElement|false XML activity object or false on error
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @todo Find proper type-hints
|
||||
*/
|
||||
private static function createActivity(DOMDocument $doc, string $element, string $activity, int $uriid)
|
||||
{
|
||||
if ($activity) {
|
||||
$entry = $doc->createElement($element);
|
||||
|
||||
$r = XML::parseString($activity);
|
||||
if (!$r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($r->type) {
|
||||
XML::addElement($doc, $entry, "activity:object-type", $r->type);
|
||||
}
|
||||
|
||||
if ($r->id) {
|
||||
XML::addElement($doc, $entry, "id", $r->id);
|
||||
}
|
||||
|
||||
if ($r->title) {
|
||||
XML::addElement($doc, $entry, "title", $r->title);
|
||||
}
|
||||
|
||||
if ($r->link) {
|
||||
if (substr($r->link, 0, 1) == '<') {
|
||||
if (strstr($r->link, '&') && (! strstr($r->link, '&'))) {
|
||||
$r->link = str_replace('&', '&', $r->link);
|
||||
}
|
||||
|
||||
$r->link = preg_replace('/\<link(.*?)\"\>/', '<link$1"/>', $r->link);
|
||||
|
||||
// XML does need a single element as root element so we add a dummy element here
|
||||
$data = XML::parseString("<dummy>" . $r->link . "</dummy>");
|
||||
if (is_object($data)) {
|
||||
foreach ($data->link as $link) {
|
||||
$attributes = [];
|
||||
foreach ($link->attributes() as $parameter => $value) {
|
||||
$attributes[$parameter] = $value;
|
||||
}
|
||||
XML::addElement($doc, $entry, "link", "", $attributes);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$attributes = ["rel" => "alternate", "type" => "text/html", "href" => $r->link];
|
||||
XML::addElement($doc, $entry, "link", "", $attributes);
|
||||
}
|
||||
}
|
||||
if ($r->content) {
|
||||
XML::addElement($doc, $entry, "content", BBCode::convertForUriId($uriid, $r->content, BBCode::EXTERNAL), ["type" => "html"]);
|
||||
}
|
||||
|
||||
return $entry;
|
||||
if (!$activity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
$entry = $doc->createElement($element);
|
||||
|
||||
$r = XML::parseString($activity);
|
||||
if (!$r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($r->type) {
|
||||
XML::addElement($doc, $entry, "activity:object-type", $r->type);
|
||||
}
|
||||
|
||||
if ($r->id) {
|
||||
XML::addElement($doc, $entry, "id", $r->id);
|
||||
}
|
||||
|
||||
if ($r->title) {
|
||||
XML::addElement($doc, $entry, "title", $r->title);
|
||||
}
|
||||
|
||||
if ($r->link) {
|
||||
if (substr($r->link, 0, 1) == '<') {
|
||||
if (strstr($r->link, '&') && (! strstr($r->link, '&'))) {
|
||||
$r->link = str_replace('&', '&', $r->link);
|
||||
}
|
||||
|
||||
$r->link = preg_replace('/\<link(.*?)\"\>/', '<link$1"/>', $r->link);
|
||||
|
||||
// XML does need a single element as root element so we add a dummy element here
|
||||
$data = XML::parseString("<dummy>" . $r->link . "</dummy>");
|
||||
if (is_object($data)) {
|
||||
foreach ($data->link as $link) {
|
||||
$attributes = [];
|
||||
foreach ($link->attributes() as $parameter => $value) {
|
||||
$attributes[$parameter] = $value;
|
||||
}
|
||||
XML::addElement($doc, $entry, "link", "", $attributes);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$attributes = ["rel" => "alternate", "type" => "text/html", "href" => $r->link];
|
||||
XML::addElement($doc, $entry, "link", "", $attributes);
|
||||
}
|
||||
}
|
||||
if ($r->content) {
|
||||
XML::addElement($doc, $entry, "content", BBCode::convertForUriId($uriid, $r->content, BBCode::EXTERNAL), ["type" => "html"]);
|
||||
}
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1925,7 +1925,7 @@ class DFRN
|
|||
// Check if the message is wanted
|
||||
if (!self::isSolicitedMessage($item, $importer)) {
|
||||
DBA::delete('item-uri', ['uri' => $item['uri']]);
|
||||
return 403;
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the type of the item (Top level post, reply or remote reply)
|
||||
|
@ -2051,7 +2051,7 @@ class DFRN
|
|||
Item::distribute($posted_id);
|
||||
}
|
||||
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
} else { // $entrytype == self::TOP_LEVEL
|
||||
if (($item['uid'] != 0) && !Contact::isSharing($item['owner-id'], $item['uid']) && !Contact::isSharing($item['author-id'], $item['uid'])) {
|
||||
|
@ -2099,7 +2099,7 @@ class DFRN
|
|||
}
|
||||
|
||||
if (!$uri || !$importer['id']) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
$condition = ['uri' => $uri, 'uid' => $importer['importer_uid']];
|
||||
|
|
|
@ -337,7 +337,7 @@ class Diaspora
|
|||
* @param string $xml urldecoded Diaspora salmon
|
||||
* @param string $privKey The private key of the importer
|
||||
*
|
||||
* @return array
|
||||
* @return array|false array with decoded data or false on error
|
||||
* 'message' -> decoded Diaspora XML message
|
||||
* 'author' -> author diaspora handle
|
||||
* 'key' -> author public key (converted to pkcs#8)
|
||||
|
@ -1051,7 +1051,7 @@ class Diaspora
|
|||
* @param string $server The url of the server
|
||||
* @param int $level Endless loop prevention
|
||||
*
|
||||
* @return array
|
||||
* @return array|false The message as array or false on error
|
||||
* 'message' => The message XML
|
||||
* 'author' => The author handle
|
||||
* 'key' => The public key of the author
|
||||
|
@ -2795,7 +2795,7 @@ class Diaspora
|
|||
// without a public key nothing will work
|
||||
if (!$pubkey) {
|
||||
DI::logger()->notice('pubkey missing: contact id: ' . $contact['id']);
|
||||
return false;
|
||||
return '';
|
||||
}
|
||||
|
||||
$aes_key = random_bytes(32);
|
||||
|
@ -2809,7 +2809,7 @@ class Diaspora
|
|||
|
||||
$encrypted_key_bundle = '';
|
||||
if (!@openssl_public_encrypt($json, $encrypted_key_bundle, $pubkey)) {
|
||||
return false;
|
||||
return '';
|
||||
}
|
||||
|
||||
$json_object = json_encode(
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
namespace Friendica\Protocol\Diaspora\Repository;
|
||||
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\Definition\DbaDefinition;
|
||||
|
@ -14,11 +17,12 @@ use Friendica\Model\APContact;
|
|||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\ItemURI;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Protocol\Diaspora\Entity;
|
||||
use Friendica\Protocol\Diaspora\Factory;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Protocol\Diaspora\Entity\DiasporaContact as DiasporaContactEntity;
|
||||
use Friendica\Protocol\Diaspora\Factory\DiasporaContact as DiasporaContactFactory;
|
||||
use Friendica\Protocol\WebFingerUri;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\UriInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
@ -30,12 +34,12 @@ class DiasporaContact extends BaseRepository
|
|||
|
||||
protected static $table_name = 'diaspora-contact-view';
|
||||
|
||||
/** @var Factory\DiasporaContact */
|
||||
/** @var DiasporaContactFactory */
|
||||
protected $factory;
|
||||
/** @var DbaDefinition */
|
||||
private $definition;
|
||||
|
||||
public function __construct(DbaDefinition $definition, Database $database, LoggerInterface $logger, Factory\DiasporaContact $factory)
|
||||
public function __construct(DbaDefinition $definition, Database $database, LoggerInterface $logger, DiasporaContactFactory $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
|
||||
|
@ -43,67 +47,58 @@ class DiasporaContact extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
* @return Entity\DiasporaContact
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function selectOne(array $condition, array $params = []): Entity\DiasporaContact
|
||||
public function selectOne(array $condition, array $params = []): DiasporaContactEntity
|
||||
{
|
||||
return parent::_selectOne($condition, $params);
|
||||
$fields = $this->_selectFirstRowAsArray( $condition, $params);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uriId
|
||||
* @return Entity\DiasporaContact
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function selectOneByUriId(int $uriId): Entity\DiasporaContact
|
||||
public function selectOneByUriId(int $uriId): DiasporaContactEntity
|
||||
{
|
||||
return $this->selectOne(['uri-id' => $uriId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UriInterface $uri
|
||||
* @return Entity\DiasporaContact
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function selectOneByUri(UriInterface $uri): Entity\DiasporaContact
|
||||
public function selectOneByUri(UriInterface $uri): DiasporaContactEntity
|
||||
{
|
||||
try {
|
||||
return $this->selectOne(['url' => (string) $uri]);
|
||||
} catch (HTTPException\NotFoundException $e) {
|
||||
} catch (NotFoundException $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->selectOne(['addr' => (string) $uri]);
|
||||
} catch (HTTPException\NotFoundException $e) {
|
||||
} catch (NotFoundException $e) {
|
||||
}
|
||||
|
||||
return $this->selectOne(['alias' => (string) $uri]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WebFingerUri $uri
|
||||
* @return Entity\DiasporaContact
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function selectOneByAddr(WebFingerUri $uri): Entity\DiasporaContact
|
||||
public function selectOneByAddr(WebFingerUri $uri): DiasporaContactEntity
|
||||
{
|
||||
return $this->selectOne(['addr' => $uri->getAddr()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uriId
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function existsByUriId(int $uriId): bool
|
||||
{
|
||||
return $this->db->exists(self::$table_name, ['uri-id' => $uriId]);
|
||||
}
|
||||
|
||||
public function save(Entity\DiasporaContact $DiasporaContact): Entity\DiasporaContact
|
||||
public function save(DiasporaContactEntity $DiasporaContact): DiasporaContactEntity
|
||||
{
|
||||
$uriId = $DiasporaContact->uriId ?? ItemURI::insert(['uri' => $DiasporaContact->url, 'guid' => $DiasporaContact->guid]);
|
||||
|
||||
|
@ -145,10 +140,9 @@ class DiasporaContact extends BaseRepository
|
|||
*
|
||||
* @param WebFingerUri $uri Profile address
|
||||
* @param boolean $update true = always update, false = never update, null = update when not found or outdated
|
||||
* @return Entity\DiasporaContact
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function getByAddr(WebFingerUri $uri, ?bool $update = self::UPDATE_IF_MISSING_OR_OUTDATED): Entity\DiasporaContact
|
||||
public function getByAddr(WebFingerUri $uri, ?bool $update = self::UPDATE_IF_MISSING_OR_OUTDATED): DiasporaContactEntity
|
||||
{
|
||||
if ($update !== self::ALWAYS_UPDATE) {
|
||||
try {
|
||||
|
@ -156,7 +150,7 @@ class DiasporaContact extends BaseRepository
|
|||
if ($update === self::NEVER_UPDATE) {
|
||||
return $dcontact;
|
||||
}
|
||||
} catch (HTTPException\NotFoundException $e) {
|
||||
} catch (NotFoundException $e) {
|
||||
if ($update === self::NEVER_UPDATE) {
|
||||
throw $e;
|
||||
}
|
||||
|
@ -169,7 +163,7 @@ class DiasporaContact extends BaseRepository
|
|||
|
||||
$contact = Contact::getByURL($uri, $update, ['uri-id']);
|
||||
if (empty($contact['uri-id'])) {
|
||||
throw new HTTPException\NotFoundException('Diaspora profile with URI ' . $uri . ' not found');
|
||||
throw new NotFoundException('Diaspora profile with URI ' . $uri . ' not found');
|
||||
}
|
||||
|
||||
return self::selectOneByUriId($contact['uri-id']);
|
||||
|
@ -180,10 +174,9 @@ class DiasporaContact extends BaseRepository
|
|||
*
|
||||
* @param UriInterface $uri Profile URL
|
||||
* @param boolean $update true = always update, false = never update, null = update when not found or outdated
|
||||
* @return Entity\DiasporaContact
|
||||
* @throws HTTPException\NotFoundException
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function getByUrl(UriInterface $uri, ?bool $update = self::UPDATE_IF_MISSING_OR_OUTDATED): Entity\DiasporaContact
|
||||
public function getByUrl(UriInterface $uri, ?bool $update = self::UPDATE_IF_MISSING_OR_OUTDATED): DiasporaContactEntity
|
||||
{
|
||||
if ($update !== self::ALWAYS_UPDATE) {
|
||||
try {
|
||||
|
@ -191,7 +184,7 @@ class DiasporaContact extends BaseRepository
|
|||
if ($update === self::NEVER_UPDATE) {
|
||||
return $dcontact;
|
||||
}
|
||||
} catch (HTTPException\NotFoundException $e) {
|
||||
} catch (NotFoundException $e) {
|
||||
if ($update === self::NEVER_UPDATE) {
|
||||
throw $e;
|
||||
}
|
||||
|
@ -204,7 +197,7 @@ class DiasporaContact extends BaseRepository
|
|||
|
||||
$contact = Contact::getByURL($uri, $update, ['uri-id']);
|
||||
if (empty($contact['uri-id'])) {
|
||||
throw new HTTPException\NotFoundException('Diaspora profile with URI ' . $uri . ' not found');
|
||||
throw new NotFoundException('Diaspora profile with URI ' . $uri . ' not found');
|
||||
}
|
||||
|
||||
return self::selectOneByUriId($contact['uri-id']);
|
||||
|
@ -214,27 +207,27 @@ class DiasporaContact extends BaseRepository
|
|||
* Update or create a diaspora-contact entry via a probe array
|
||||
*
|
||||
* @param array $data Probe array
|
||||
* @return Entity\DiasporaContact
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateFromProbeArray(array $data): Entity\DiasporaContact
|
||||
public function updateFromProbeArray(array $data): DiasporaContactEntity
|
||||
{
|
||||
if (empty($data['url'])) {
|
||||
throw new \InvalidArgumentException('Missing url key in Diaspora probe data array');
|
||||
throw new InvalidArgumentException('Missing url key in Diaspora probe data array');
|
||||
}
|
||||
|
||||
if (empty($data['guid'])) {
|
||||
throw new \InvalidArgumentException('Missing guid key in Diaspora probe data array');
|
||||
throw new InvalidArgumentException('Missing guid key in Diaspora probe data array');
|
||||
}
|
||||
|
||||
if (empty($data['pubkey'])) {
|
||||
throw new \InvalidArgumentException('Missing pubkey key in Diaspora probe data array');
|
||||
throw new InvalidArgumentException('Missing pubkey key in Diaspora probe data array');
|
||||
}
|
||||
|
||||
$uriId = ItemURI::insert(['uri' => $data['url'], 'guid' => $data['guid']]);
|
||||
|
||||
$contact = Contact::getByUriId($uriId, ['id', 'created']);
|
||||
$apcontact = APContact::getByURL($data['url'], false);
|
||||
|
||||
if (!empty($apcontact)) {
|
||||
$interacting_count = $apcontact['followers_count'];
|
||||
$interacted_count = $apcontact['following_count'];
|
||||
|
@ -250,10 +243,10 @@ class DiasporaContact extends BaseRepository
|
|||
$DiasporaContact = $this->factory->createfromProbeData(
|
||||
$data,
|
||||
$uriId,
|
||||
new \DateTime($contact['created'] ?? 'now', new \DateTimeZone('UTC')),
|
||||
new DateTime($contact['created'] ?? 'now', new DateTimeZone('UTC')),
|
||||
$interacting_count ?? 0,
|
||||
$interacted_count ?? 0,
|
||||
$post_count ?? 0
|
||||
$interacted_count ?? 0,
|
||||
$post_count ?? 0
|
||||
);
|
||||
|
||||
$DiasporaContact = $this->save($DiasporaContact);
|
||||
|
@ -269,7 +262,7 @@ class DiasporaContact extends BaseRepository
|
|||
* @param string $guid Hexadecimal string guid
|
||||
*
|
||||
* @return string the contact url or null
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getUrlByGuid(string $guid): ?string
|
||||
{
|
||||
|
|
|
@ -15,9 +15,9 @@ use Friendica\Model\Circle;
|
|||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Security\PermissionSet\Exception\PermissionSetNotFoundException;
|
||||
use Friendica\Security\PermissionSet\Exception\PermissionSetPersistenceException;
|
||||
use Friendica\Security\PermissionSet\Factory;
|
||||
use Friendica\Security\PermissionSet\Collection;
|
||||
use Friendica\Security\PermissionSet\Entity;
|
||||
use Friendica\Security\PermissionSet\Factory\PermissionSet as PermissionSetFactory;
|
||||
use Friendica\Security\PermissionSet\Collection\PermissionSets as PermissionSetsCollection;
|
||||
use Friendica\Security\PermissionSet\Entity\PermissionSet as PermissionSetEntity;
|
||||
use Friendica\Util\ACLFormatter;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
@ -26,7 +26,7 @@ class PermissionSet extends BaseRepository
|
|||
/** @var int Virtual permission set id for public permission */
|
||||
const PUBLIC = 0;
|
||||
|
||||
/** @var Factory\PermissionSet */
|
||||
/** @var PermissionSetFactory */
|
||||
protected $factory;
|
||||
|
||||
protected static $table_name = 'permissionset';
|
||||
|
@ -34,7 +34,7 @@ class PermissionSet extends BaseRepository
|
|||
/** @var ACLFormatter */
|
||||
private $aclFormatter;
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\PermissionSet $factory, ACLFormatter $aclFormatter)
|
||||
public function __construct(Database $database, LoggerInterface $logger, PermissionSetFactory $factory, ACLFormatter $aclFormatter)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
|
||||
|
@ -42,34 +42,28 @@ class PermissionSet extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
*
|
||||
* @return Entity\PermissionSet
|
||||
* @throws NotFoundException
|
||||
* @throws Exception
|
||||
*/
|
||||
private function selectOne(array $condition, array $params = []): Entity\PermissionSet
|
||||
private function selectOne(array $condition, array $params = []): PermissionSetEntity
|
||||
{
|
||||
return parent::_selectOne($condition, $params);
|
||||
$fields = parent::_selectFirstRowAsArray($condition, $params);
|
||||
|
||||
return $this->factory->createFromTableRow($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private function select(array $condition, array $params = []): Collection\PermissionSets
|
||||
private function select(array $condition, array $params = []): PermissionSetsCollection
|
||||
{
|
||||
return new Collection\PermissionSets(parent::_select($condition, $params)->getArrayCopy());
|
||||
return new PermissionSetsCollection(parent::_select($condition, $params)->getArrayCopy());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given PermissionSet into a DB compatible row array
|
||||
*
|
||||
* @param Entity\PermissionSet $permissionSet
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function convertToTableRow(Entity\PermissionSet $permissionSet): array
|
||||
protected function convertToTableRow(PermissionSetEntity $permissionSet): array
|
||||
{
|
||||
return [
|
||||
'uid' => $permissionSet->uid,
|
||||
|
@ -83,12 +77,11 @@ class PermissionSet extends BaseRepository
|
|||
/**
|
||||
* @param int $id A PermissionSet table row id or self::PUBLIC
|
||||
* @param int $uid The owner of the PermissionSet
|
||||
* @return Entity\PermissionSet
|
||||
*
|
||||
* @throws PermissionSetNotFoundException
|
||||
* @throws PermissionSetPersistenceException
|
||||
*/
|
||||
public function selectOneById(int $id, int $uid): Entity\PermissionSet
|
||||
public function selectOneById(int $id, int $uid): PermissionSetEntity
|
||||
{
|
||||
if ($id === self::PUBLIC) {
|
||||
return $this->factory->createFromString($uid);
|
||||
|
@ -109,11 +102,9 @@ class PermissionSet extends BaseRepository
|
|||
* @param int $cid Contact id of the visitor
|
||||
* @param int $uid User id whom the items belong, used for ownership check.
|
||||
*
|
||||
* @return Collection\PermissionSets
|
||||
*
|
||||
* @throws PermissionSetPersistenceException
|
||||
*/
|
||||
public function selectByContactId(int $cid, int $uid): Collection\PermissionSets
|
||||
public function selectByContactId(int $cid, int $uid): PermissionSetsCollection
|
||||
{
|
||||
try {
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
|
||||
|
@ -128,8 +119,8 @@ class PermissionSet extends BaseRepository
|
|||
|
||||
$circle_ids = [];
|
||||
if (!empty($user_contact_str) && $this->db->exists('contact', [
|
||||
'id' => $cid,
|
||||
'uid' => $uid,
|
||||
'id' => $cid,
|
||||
'uid' => $uid,
|
||||
'blocked' => false
|
||||
])) {
|
||||
$circle_ids = Circle::getIdsByContactId($cid);
|
||||
|
@ -162,16 +153,14 @@ class PermissionSet extends BaseRepository
|
|||
*
|
||||
* @param int $uid
|
||||
*
|
||||
* @return Entity\PermissionSet
|
||||
*
|
||||
* @throws PermissionSetPersistenceException
|
||||
*/
|
||||
public function selectDefaultForUser(int $uid): Entity\PermissionSet
|
||||
public function selectDefaultForUser(int $uid): PermissionSetEntity
|
||||
{
|
||||
try {
|
||||
$self_contact = Contact::selectFirst(['id'], ['uid' => $uid, 'self' => true]);
|
||||
} catch (Exception $exception) {
|
||||
throw new PermissionSetPersistenceException(sprintf('Cannot select Contact for user %d', $uid));
|
||||
throw new PermissionSetPersistenceException(sprintf('Cannot select Contact for user %d', $uid), $exception);
|
||||
}
|
||||
|
||||
if (!$this->db->isResult($self_contact)) {
|
||||
|
@ -188,10 +177,8 @@ class PermissionSet extends BaseRepository
|
|||
* Fetch the public PermissionSet
|
||||
*
|
||||
* @param int $uid
|
||||
*
|
||||
* @return Entity\PermissionSet
|
||||
*/
|
||||
public function selectPublicForUser(int $uid): Entity\PermissionSet
|
||||
public function selectPublicForUser(int $uid): PermissionSetEntity
|
||||
{
|
||||
return $this->factory->createFromString($uid, '', '', '', '', self::PUBLIC);
|
||||
}
|
||||
|
@ -199,13 +186,9 @@ class PermissionSet extends BaseRepository
|
|||
/**
|
||||
* Selects or creates a PermissionSet based on its fields
|
||||
*
|
||||
* @param Entity\PermissionSet $permissionSet
|
||||
*
|
||||
* @return Entity\PermissionSet
|
||||
*
|
||||
* @throws PermissionSetPersistenceException
|
||||
*/
|
||||
public function selectOrCreate(Entity\PermissionSet $permissionSet): Entity\PermissionSet
|
||||
public function selectOrCreate(PermissionSetEntity $permissionSet): PermissionSetEntity
|
||||
{
|
||||
if ($permissionSet->id) {
|
||||
return $permissionSet;
|
||||
|
@ -226,13 +209,9 @@ class PermissionSet extends BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Entity\PermissionSet $permissionSet
|
||||
*
|
||||
* @return Entity\PermissionSet
|
||||
*
|
||||
* @throws PermissionSetPersistenceException
|
||||
*/
|
||||
public function save(Entity\PermissionSet $permissionSet): Entity\PermissionSet
|
||||
public function save(PermissionSetEntity $permissionSet): PermissionSetEntity
|
||||
{
|
||||
// Don't save/update the common public PermissionSet
|
||||
if ($permissionSet->isPublic()) {
|
||||
|
|
|
@ -45,25 +45,25 @@ class Security
|
|||
return true;
|
||||
} elseif ($verified === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$user = User::getById($owner);
|
||||
if (!$user || $user['blockwall']) {
|
||||
$verified = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
$contact = Contact::getById($cid);
|
||||
if (!is_array($contact) || $contact['blocked'] || $contact['readonly'] || $contact['pending']) {
|
||||
$verified = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (in_array($contact['rel'], [Contact::SHARING, Contact::FRIEND]) || ($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
|
||||
$verified = 2;
|
||||
return true;
|
||||
} else {
|
||||
$user = User::getById($owner);
|
||||
if (!$user || $user['blockwall']) {
|
||||
$verified = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
$contact = Contact::getById($cid);
|
||||
if ($contact || $contact['blocked'] || $contact['readonly'] || $contact['pending']) {
|
||||
$verified = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (in_array($contact['rel'], [Contact::SHARING, Contact::FRIEND]) || ($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY)) {
|
||||
$verified = 2;
|
||||
return true;
|
||||
} else {
|
||||
$verified = 1;
|
||||
}
|
||||
$verified = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,33 +79,25 @@ class Security
|
|||
*/
|
||||
public static function getPermissionsSQLByUserId(int $owner_id, bool $accessible = false)
|
||||
{
|
||||
$local_user = DI::userSession()->getLocalUserId();
|
||||
$local_user = DI::userSession()->getLocalUserId();
|
||||
$remote_contact = DI::userSession()->getRemoteContactID($owner_id);
|
||||
$acc_sql = '';
|
||||
$acc_sql = '';
|
||||
|
||||
if ($accessible) {
|
||||
$acc_sql = ' OR `accessible`';
|
||||
}
|
||||
|
||||
/*
|
||||
* Construct permissions
|
||||
*
|
||||
* default permissions - anonymous user
|
||||
*/
|
||||
// Construct permissions: default permissions - anonymous user
|
||||
$sql = " AND (allow_cid = ''
|
||||
AND allow_gid = ''
|
||||
AND deny_cid = ''
|
||||
AND deny_gid = ''" . $acc_sql . ") ";
|
||||
|
||||
/*
|
||||
* Profile owner - everything is visible
|
||||
*/
|
||||
if ($local_user && $local_user == $owner_id) {
|
||||
// Profile owner - everything is visible
|
||||
$sql = '';
|
||||
/*
|
||||
* Authenticated visitor. Load the circles the visitor belongs to.
|
||||
*/
|
||||
} elseif ($remote_contact) {
|
||||
// Authenticated visitor. Load the circles the visitor belongs to.
|
||||
$circleIds = '<<>>'; // should be impossible to match
|
||||
|
||||
foreach (Circle::getIdsByContactId($remote_contact) as $circleId) {
|
||||
|
|
|
@ -8,28 +8,27 @@
|
|||
namespace Friendica\User\Settings\Repository;
|
||||
|
||||
use Exception;
|
||||
use Friendica\BaseCollection;
|
||||
use Friendica\BaseEntity;
|
||||
use Friendica\BaseRepository;
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Federation\Repository\GServer;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\User\Settings\Collection;
|
||||
use Friendica\User\Settings\Entity;
|
||||
use Friendica\User\Settings\Factory;
|
||||
use Friendica\User\Settings\Collection\UserGServers as UserGServersCollection;
|
||||
use Friendica\User\Settings\Entity\UserGServer as UserGServerEntity;
|
||||
use Friendica\User\Settings\Factory\UserGServer as UserGServerFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class UserGServer extends \Friendica\BaseRepository
|
||||
class UserGServer extends BaseRepository
|
||||
{
|
||||
protected static $table_name = 'user-gserver';
|
||||
|
||||
/** @var Factory\UserGServer */
|
||||
/** @var UserGServerFactory */
|
||||
protected $factory;
|
||||
/** @var GServer */
|
||||
protected $gserverRepository;
|
||||
|
||||
public function __construct(GServer $gserverRepository, Database $database, LoggerInterface $logger, Factory\UserGServer $factory)
|
||||
public function __construct(GServer $gserverRepository, Database $database, LoggerInterface $logger, UserGServerFactory $factory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
|
||||
|
@ -39,12 +38,9 @@ class UserGServer extends \Friendica\BaseRepository
|
|||
/**
|
||||
* Returns an existing UserGServer entity or create one on the fly
|
||||
*
|
||||
* @param int $uid
|
||||
* @param int $gsid
|
||||
* @param bool $hydrate Populate the related GServer entity
|
||||
* @return Entity\UserGServer
|
||||
*/
|
||||
public function getOneByUserAndServer(int $uid, int $gsid, bool $hydrate = true): Entity\UserGServer
|
||||
public function getOneByUserAndServer(int $uid, int $gsid, bool $hydrate = true): UserGServerEntity
|
||||
{
|
||||
try {
|
||||
return $this->selectOneByUserAndServer($uid, $gsid, $hydrate);
|
||||
|
@ -54,18 +50,15 @@ class UserGServer extends \Friendica\BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @param int $gsid
|
||||
* @param bool $hydrate Populate the related GServer entity
|
||||
* @return Entity\UserGServer
|
||||
* @throws NotFoundException
|
||||
*/
|
||||
public function selectOneByUserAndServer(int $uid, int $gsid, bool $hydrate = true): Entity\UserGServer
|
||||
public function selectOneByUserAndServer(int $uid, int $gsid, bool $hydrate = true): UserGServerEntity
|
||||
{
|
||||
return $this->_selectOne(['uid' => $uid, 'gsid' => $gsid], [], $hydrate);
|
||||
}
|
||||
|
||||
public function save(Entity\UserGServer $userGServer): Entity\UserGServer
|
||||
public function save(UserGServerEntity $userGServer): UserGServerEntity
|
||||
{
|
||||
$fields = [
|
||||
'uid' => $userGServer->uid,
|
||||
|
@ -78,7 +71,7 @@ class UserGServer extends \Friendica\BaseRepository
|
|||
return $userGServer;
|
||||
}
|
||||
|
||||
public function selectByUserWithPagination(int $uid, Pager $pager): Collection\UserGServers
|
||||
public function selectByUserWithPagination(int $uid, Pager $pager): UserGServersCollection
|
||||
{
|
||||
return $this->_select(['uid' => $uid], ['limit' => [$pager->getStart(), $pager->getItemsPerPage()]]);
|
||||
}
|
||||
|
@ -94,20 +87,18 @@ class UserGServer extends \Friendica\BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param Entity\UserGServer $userGServer
|
||||
* @return bool
|
||||
* @throws InternalServerErrorException in case the underlying storage cannot delete the record
|
||||
*/
|
||||
public function delete(Entity\UserGServer $userGServer): bool
|
||||
public function delete(UserGServerEntity $userGServer): bool
|
||||
{
|
||||
try {
|
||||
return $this->db->delete(self::$table_name, ['uid' => $userGServer->uid, 'gsid' => $userGServer->gsid]);
|
||||
} catch (\Exception $exception) {
|
||||
} catch (Exception $exception) {
|
||||
throw new InternalServerErrorException('Cannot delete the UserGServer', $exception);
|
||||
}
|
||||
}
|
||||
|
||||
protected function _selectOne(array $condition, array $params = [], bool $hydrate = true): BaseEntity
|
||||
protected function _selectOne(array $condition, array $params = [], bool $hydrate = true): UserGServerEntity
|
||||
{
|
||||
$fields = $this->db->selectFirst(static::$table_name, [], $condition, $params);
|
||||
if (!$this->db->isResult($fields)) {
|
||||
|
@ -118,16 +109,13 @@ class UserGServer extends \Friendica\BaseRepository
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param array $params
|
||||
* @return Collection\UserGServers
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _select(array $condition, array $params = [], bool $hydrate = true): BaseCollection
|
||||
protected function _select(array $condition, array $params = [], bool $hydrate = true): UserGServersCollection
|
||||
{
|
||||
$rows = $this->db->selectToArray(static::$table_name, [], $condition, $params);
|
||||
|
||||
$Entities = new Collection\UserGServers();
|
||||
$Entities = new UserGServersCollection();
|
||||
foreach ($rows as $fields) {
|
||||
$Entities[] = $this->factory->createFromTableRow($fields, $hydrate ? $this->gserverRepository->selectOneById($fields['gsid']) : null);
|
||||
}
|
||||
|
@ -135,7 +123,7 @@ class UserGServer extends \Friendica\BaseRepository
|
|||
return $Entities;
|
||||
}
|
||||
|
||||
public function listIgnoredByUser(int $uid): Collection\UserGServers
|
||||
public function listIgnoredByUser(int $uid): UserGServersCollection
|
||||
{
|
||||
return $this->_select(['uid' => $uid, 'ignored' => 1], [], false);
|
||||
}
|
||||
|
|
|
@ -225,19 +225,18 @@ class Crypto
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/crypto.php
|
||||
*
|
||||
* @param array $data ['iv' => $iv, 'key' => $key, 'alg' => $alg, 'data' => $data]
|
||||
* @param string $prvkey The private key used for decryption.
|
||||
*
|
||||
* @return string|boolean The decrypted string or false on failure.
|
||||
* @return string|false The decrypted string or false on failure.
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function unencapsulate(array $data, $prvkey)
|
||||
{
|
||||
if (!$data) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$alg = $data['alg'] ?? 'aes256cbc';
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Friendica\Util;
|
||||
|
||||
use Exception;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
|
@ -213,7 +214,7 @@ class HTTPSignature
|
|||
|
||||
$headers = [];
|
||||
foreach ($matches as $match) {
|
||||
$headers[$match[1]] = trim($match[2] ?: $match[3], '"');
|
||||
$headers[$match[1]] = trim((string) $match[2], '"');
|
||||
}
|
||||
|
||||
// if the header is encrypted, decrypt with (default) site private key and continue
|
||||
|
@ -247,7 +248,7 @@ class HTTPSignature
|
|||
private static function decryptSigheader(array $headers, string $prvkey): string
|
||||
{
|
||||
if (!empty($headers['iv']) && !empty($headers['key']) && !empty($headers['data'])) {
|
||||
return Crypto::unencapsulate($headers, $prvkey);
|
||||
return (string) Crypto::unencapsulate($headers, $prvkey);
|
||||
}
|
||||
|
||||
return '';
|
||||
|
@ -537,14 +538,12 @@ class HTTPSignature
|
|||
|
||||
if (!empty($uid)) {
|
||||
$owner = User::getOwnerDataById($uid);
|
||||
if (!$owner) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$owner = User::getSystemAccount();
|
||||
if (!$owner) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$owner) {
|
||||
throw new Exception('Could not find owner for uid ' . $uid);
|
||||
}
|
||||
|
||||
if (!empty($owner['uprvkey'])) {
|
||||
|
|
|
@ -243,14 +243,11 @@ class JsonLD
|
|||
|
||||
return json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches an element array from a JSON array
|
||||
*
|
||||
* @param $array
|
||||
* @param $element
|
||||
* @param $key
|
||||
*
|
||||
* @return array fetched element
|
||||
* @return array|null fetched element or null
|
||||
*/
|
||||
public static function fetchElementArray($array, $element, $key = null, $type = null, $type_value = null)
|
||||
{
|
||||
|
|
|
@ -26,13 +26,13 @@ class ReversedFileReader implements \Iterator
|
|||
/** @var int */
|
||||
private $pos = -1;
|
||||
|
||||
/** @var array */
|
||||
/** @var array|null */
|
||||
private $buffer = null;
|
||||
|
||||
/** @var int */
|
||||
private $key = -1;
|
||||
|
||||
/** @var string */
|
||||
/** @var string|null */
|
||||
private $value = null;
|
||||
|
||||
/**
|
||||
|
@ -53,6 +53,7 @@ class ReversedFileReader implements \Iterator
|
|||
$this->buffer = null;
|
||||
$this->key = -1;
|
||||
$this->value = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ class Strings
|
|||
{
|
||||
// If this method is called for an infinite (== unlimited) amount of bytes:
|
||||
if ($bytes == INF) {
|
||||
return INF;
|
||||
return 'INF';
|
||||
}
|
||||
|
||||
$units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
|
||||
|
@ -509,7 +509,7 @@ class Strings
|
|||
function ($matches) use ($blocks) {
|
||||
$return = $matches[0];
|
||||
if (isset($blocks[intval($matches[1])])) {
|
||||
$return = $blocks[$matches[1]];
|
||||
$return = $blocks[intval($matches[1])];
|
||||
}
|
||||
return $return;
|
||||
},
|
||||
|
|
|
@ -405,7 +405,7 @@ class Temporal
|
|||
*/
|
||||
public static function getDaysInMonth(int $y, int $m): int
|
||||
{
|
||||
return date('t', mktime(0, 0, 0, $m, 1, $y));
|
||||
return (int) date('t', mktime(0, 0, 0, $m, 1, $y));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -184,7 +184,7 @@ class XML
|
|||
* @param integer $recursion_depth recursion counter for internal use - default 0
|
||||
* internal use, recursion counter
|
||||
*
|
||||
* @return array | string The array from the xml element or the string
|
||||
* @return array|string|null The array from the xml element or the string
|
||||
*/
|
||||
public static function elementToArray($xml_element, int &$recursion_depth = 0)
|
||||
{
|
||||
|
|
|
@ -17,16 +17,16 @@ class SyslogLoggerFactoryWrapper extends SyslogLogger
|
|||
{
|
||||
public function create(IManageConfigValues $config): LoggerInterface
|
||||
{
|
||||
$logOpts = $config->get('system', 'syslog_flags') ?? SyslogLoggerClass::DEFAULT_FLAGS;
|
||||
$logFacility = $config->get('system', 'syslog_facility') ?? SyslogLoggerClass::DEFAULT_FACILITY;
|
||||
$logOpts = (int) $config->get('system', 'syslog_flags') ?? SyslogLoggerClass::DEFAULT_FLAGS;
|
||||
$logFacility = (int) $config->get('system', 'syslog_facility') ?? SyslogLoggerClass::DEFAULT_FACILITY;
|
||||
$loglevel = SyslogLogger::mapLegacyConfigDebugLevel($config->get('system', 'loglevel'));
|
||||
|
||||
if (array_key_exists($loglevel, SyslogLoggerClass::logLevels)) {
|
||||
$loglevel = SyslogLoggerClass::logLevels[$loglevel];
|
||||
} else {
|
||||
if (!array_key_exists($loglevel, SyslogLoggerClass::logLevels)) {
|
||||
throw new LogLevelException(sprintf('The level "%s" is not valid.', $loglevel));
|
||||
}
|
||||
|
||||
$loglevel = SyslogLoggerClass::logLevels[$loglevel];
|
||||
|
||||
return new SyslogLoggerWrapper($this->channel, $this->introspection, $loglevel, $logOpts, $logFacility);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class SyslogLoggerWrapper extends SyslogLogger
|
|||
{
|
||||
private $content;
|
||||
|
||||
public function __construct(string $channel, IHaveCallIntrospections $introspection, string $logLevel, string $logOptions, string $logFacility)
|
||||
public function __construct(string $channel, IHaveCallIntrospections $introspection, int $logLevel, int $logOptions, int $logFacility)
|
||||
{
|
||||
parent::__construct($channel, $introspection, $logLevel, $logOptions, $logFacility);
|
||||
|
||||
|
|
|
@ -152,13 +152,13 @@ class UserSessionTest extends MockedTestCase
|
|||
'data' => [
|
||||
'remote' => ['3' => '21'],
|
||||
],
|
||||
'expected' => false,
|
||||
'expected' => 0,
|
||||
],
|
||||
'empty' => [
|
||||
'cid' => 21,
|
||||
'data' => [
|
||||
],
|
||||
'expected' => false,
|
||||
'expected' => 0,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ class UserSessionTest extends MockedTestCase
|
|||
public function testGetUserIdForVisitorContactID(int $cid, array $data, $expected)
|
||||
{
|
||||
$userSession = new UserSession(new ArraySession($data));
|
||||
$this->assertEquals($expected, $userSession->getUserIDForVisitorContactID($cid));
|
||||
$this->assertSame($expected, $userSession->getUserIDForVisitorContactID($cid));
|
||||
}
|
||||
|
||||
public function dataAuthenticated()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue