Fix code style

This commit is contained in:
Art4 2025-03-17 07:38:53 +00:00
parent 77e785dd7d
commit 674b6c55de
18 changed files with 81 additions and 87 deletions

View file

@ -134,7 +134,7 @@ HELP;
); );
$fnname = 'string_plural_select_' . $lang; $fnname = 'string_plural_select_' . $lang;
$out = 'if(! function_exists("' . $fnname . '")) {' . "\n"; $out = 'if(! function_exists("' . $fnname . '")) {' . "\n";
$out .= 'function ' . $fnname . '($n){' . "\n"; $out .= 'function ' . $fnname . '($n){' . "\n";
$out .= ' $n = intval($n);' . "\n"; $out .= ' $n = intval($n);' . "\n";
$out .= ' ' . $return . "\n"; $out .= ' ' . $return . "\n";
@ -192,13 +192,13 @@ HELP;
if ($q === false || $s < $q) { if ($q === false || $s < $q) {
list($then, $else) = explode(':', $string, 2); list($then, $else) = explode(':', $string, 2);
$node['then'] = $then; $node['then'] = $then;
$parsedElse = []; $parsedElse = [];
self::parse($else, $parsedElse); self::parse($else, $parsedElse);
$node['else'] = $parsedElse; $node['else'] = $parsedElse;
} else { } else {
list($if, $thenelse) = explode('?', $string, 2); list($if, $thenelse) = explode('?', $string, 2);
$node['if'] = $if; $node['if'] = $if;
self::parse($thenelse, $node); self::parse($thenelse, $node);
} }
} }
@ -214,7 +214,7 @@ HELP;
private static function render($tree): string private static function render($tree): string
{ {
if (is_array($tree)) { if (is_array($tree)) {
$if = trim($tree['if']); $if = trim($tree['if']);
$then = trim($tree['then']); $then = trim($tree['then']);
$else = self::render($tree['else']); $else = self::render($tree['else']);

View file

@ -83,7 +83,10 @@ class Introduction extends BaseRepository
$BaseCollection = parent::_selectByBoundaries( $BaseCollection = parent::_selectByBoundaries(
['`uid` = ? AND NOT `ignore`',$uid], ['`uid` = ? AND NOT `ignore`',$uid],
['order' => ['id' => 'DESC']], ['order' => ['id' => 'DESC']],
$min_id, $max_id, $limit); $min_id,
$max_id,
$limit
);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new IntroductionPersistenceException(sprintf('Cannot select Introductions for used %d', $uid), $e); throw new IntroductionPersistenceException(sprintf('Cannot select Introductions for used %d', $uid), $e);
} }

View file

@ -169,14 +169,14 @@ class UserDefinedChannel extends BaseRepository
$uids = array_column($users, 'uid'); $uids = array_column($users, 'uid');
$usercondition = ['uid' => $uids]; $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) { foreach ($this->select($condition) as $channel) {
if (!empty($channel->languages) && in_array($language, $channel->languages)) { if (!empty($channel->languages) && in_array($language, $channel->languages)) {
return true; return true;
} }
} }
$search = ''; $search = '';
$condition = DBA::mergeConditions($usercondition, ["`full-text-search` != ? AND `circle` = ? AND `valid`", '', 0]); $condition = DBA::mergeConditions($usercondition, ["`full-text-search` != ? AND `circle` = ? AND `valid`", '', 0]);
foreach ($this->select($condition) as $channel) { foreach ($this->select($condition) as $channel) {
$search .= '(' . $channel->fullTextSearch . ') '; $search .= '(' . $channel->fullTextSearch . ') ';
@ -201,7 +201,7 @@ class UserDefinedChannel extends BaseRepository
{ {
$condition = $this->getUserCondition(); $condition = $this->getUserCondition();
$condition = DBA::mergeConditions($condition, ["`account-type` IN (?, ?) AND `uid` != ?", User::ACCOUNT_TYPE_RELAY, User::ACCOUNT_TYPE_COMMUNITY, 0]); $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)) { if (empty($users)) {
return []; return [];
} }

View file

@ -121,8 +121,7 @@ class PostMedia extends BaseEntity
?UriInterface $publisherImage = null, ?UriInterface $publisherImage = null,
?string $blurhash = null, ?string $blurhash = null,
int $id = null int $id = null
) ) {
{
$this->uriId = $uriId; $this->uriId = $uriId;
$this->url = $url; $this->url = $url;
$this->type = $type; $this->type = $type;
@ -223,8 +222,8 @@ class PostMedia extends BaseEntity
if ($newWidth && $newHeight && $size) { if ($newWidth && $newHeight && $size) {
$dimensionts = Images::getScalingDimensions($newWidth, $newHeight, Proxy::getPixelsFromSize($size)); $dimensionts = Images::getScalingDimensions($newWidth, $newHeight, Proxy::getPixelsFromSize($size));
$newWidth = $dimensionts['width']; $newWidth = $dimensionts['width'];
$newHeight = $dimensionts['height']; $newHeight = $dimensionts['height'];
} }
return new self( return new self(

View file

@ -167,7 +167,7 @@ class PostMedia extends BaseRepository
// Peertube videos are delivered in many different resolutions. We pick a moderate one. // 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 // 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. // 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; $video[(string) $PostMedia->url] = $PostMedia;
} else { } else {
$attachments['visual'][] = $PostMedia; $attachments['visual'][] = $PostMedia;

View file

@ -40,7 +40,7 @@ class Hook
public static function loadHooks() public static function loadHooks()
{ {
self::$hooks = []; 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)) { while ($hook = DBA::fetch($stmt)) {
self::add($hook['hook'], $hook['file'], $hook['function']); self::add($hook['hook'], $hook['file'], $hook['function']);

View file

@ -62,15 +62,15 @@ class Database
protected $server_info = ''; protected $server_info = '';
/** @var PDO|mysqli|null */ /** @var PDO|mysqli|null */
protected $connection; protected $connection;
protected $driver = ''; protected $driver = '';
protected $pdo_emulate_prepares = false; protected $pdo_emulate_prepares = false;
private $error = ''; private $error = '';
private $errorno = 0; private $errorno = 0;
private $affected_rows = 0; private $affected_rows = 0;
protected $in_transaction = false; protected $in_transaction = false;
protected $in_retrial = false; protected $in_retrial = false;
protected $testmode = false; protected $testmode = false;
private $relation = []; private $relation = [];
/** @var DbaDefinition */ /** @var DbaDefinition */
protected $dbaDefinition; protected $dbaDefinition;
/** @var ViewDefinition */ /** @var ViewDefinition */
@ -86,7 +86,7 @@ class Database
$this->viewDefinition = $viewDefinition; $this->viewDefinition = $viewDefinition;
// Use dummy values - necessary for the first factory call of the logger itself // 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->profiler = new Profiler($config);
$this->connect(); $this->connect();
@ -630,7 +630,7 @@ class Database
} elseif (is_string($args[$param])) { } elseif (is_string($args[$param])) {
$param_types .= 's'; $param_types .= 's';
} elseif (is_object($args[$param]) && method_exists($args[$param], '__toString')) { } elseif (is_object($args[$param]) && method_exists($args[$param], '__toString')) {
$param_types .= 's'; $param_types .= 's';
$args[$param] = (string)$args[$param]; $args[$param] = (string)$args[$param];
} else { } else {
$param_types .= 'b'; $param_types .= 'b';
@ -677,9 +677,9 @@ class Database
} }
$this->logger->error('DB Error', [ $this->logger->error('DB Error', [
'code' => $errorno, 'code' => $errorno,
'error' => $error, 'error' => $error,
'params' => $this->replaceParameters($sql, $args), 'params' => $this->replaceParameters($sql, $args),
]); ]);
// On a lost connection we try to reconnect - but only once. // On a lost connection we try to reconnect - but only once.
@ -784,9 +784,9 @@ class Database
} }
$this->logger->error('DB Error', [ $this->logger->error('DB Error', [
'code' => $errorno, 'code' => $errorno,
'error' => $error, 'error' => $error,
'params' => $this->replaceParameters($sql, $params), 'params' => $this->replaceParameters($sql, $params),
]); ]);
// On a lost connection we simply quit. // On a lost connection we simply quit.
@ -1335,7 +1335,7 @@ class Database
return true; return true;
} }
$fields = $this->castFields($table, $fields); $fields = $this->castFields($table, $fields);
$direct_fields = []; $direct_fields = [];
foreach ($fields as $key => $value) { foreach ($fields as $key => $value) {

View file

@ -65,7 +65,7 @@ class Attachment extends BaseFactory
* @return \Friendica\Object\Api\Mastodon\Attachment * @return \Friendica\Object\Api\Mastodon\Attachment
* @throws 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'], '/'))) : ''; $filetype = !empty($attachment['mimetype']) ? strtolower(substr($attachment['mimetype'], 0, strpos($attachment['mimetype'], '/'))) : '';

View file

@ -111,7 +111,7 @@ class Status extends BaseFactory
*/ */
private function createFromArray(array $item, int $uid, bool $include_entities): \Friendica\Object\Api\Twitter\Status 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); $author = $this->twitterUser->createFromContactId($item['author-id'], $uid, true);
if (!empty($item['causer-id']) && ($item['post-reason'] == Item::PR_ANNOUNCEMENT)) { if (!empty($item['causer-id']) && ($item['post-reason'] == Item::PR_ANNOUNCEMENT)) {
@ -203,6 +203,6 @@ class Status extends BaseFactory
$entities = []; $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);
} }
} }

View file

@ -71,7 +71,7 @@ class RemoveTag extends BaseModule
$item_id = $this->parameters['id'] ?? 0; $item_id = $this->parameters['id'] ?? 0;
$term = trim($request['term'] ?? ''); $term = trim($request['term'] ?? '');
$cat = trim($request['cat'] ?? ''); $cat = trim($request['cat'] ?? '');
if (!empty($cat)) { if (!empty($cat)) {
$type = Post\Category::CATEGORY; $type = Post\Category::CATEGORY;

View file

@ -127,23 +127,23 @@ class Notification extends BaseRepository
$values = [$uid]; $values = [$uid];
$type_condition = ''; $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)) { if (!is_null($notify_type)) {
$type_condition = 'AND `type` & ? != 0'; $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 = ''; $like_condition = '';
if (!$this->pconfig->get($uid, 'system', 'notify_like')) { if (!$this->pconfig->get($uid, 'system', 'notify_like')) {
$like_condition = 'AND NOT `vid` IN (?, ?)'; $like_condition = 'AND NOT `vid` IN (?, ?)';
$values[] = Verb::getID(Activity::LIKE); $values[] = Verb::getID(Activity::LIKE);
$values[] = Verb::getID(Activity::DISLIKE); $values[] = Verb::getID(Activity::DISLIKE);
} }
$announce_condition = ''; $announce_condition = '';
if (!$this->pconfig->get($uid, 'system', 'notify_announce')) { if (!$this->pconfig->get($uid, 'system', 'notify_announce')) {
$announce_condition = 'AND vid != ?'; $announce_condition = 'AND vid != ?';
$values[] = Verb::getID(Activity::ANNOUNCE); $values[] = Verb::getID(Activity::ANNOUNCE);
} }
$rows = $this->db->p(" $rows = $this->db->p("
@ -253,12 +253,12 @@ class Notification extends BaseRepository
public function deleteForItem(int $itemUriId): bool public function deleteForItem(int $itemUriId): bool
{ {
$conditionTarget = [ $conditionTarget = [
'vid' => Verb::getID(Activity::POST), 'vid' => Verb::getID(Activity::POST),
'target-uri-id' => $itemUriId, 'target-uri-id' => $itemUriId,
]; ];
$conditionParent = [ $conditionParent = [
'vid' => Verb::getID(Activity::POST), 'vid' => Verb::getID(Activity::POST),
'parent-uri-id' => $itemUriId, 'parent-uri-id' => $itemUriId,
]; ];

View file

@ -63,30 +63,30 @@ class Introduction implements \JsonSerializable
public function __construct(array $data = []) public function __construct(array $data = [])
{ {
$this->label = $data['label'] ?? ''; $this->label = $data['label'] ?? '';
$this->type = $data['str_type'] ?? ''; $this->type = $data['str_type'] ?? '';
$this->intro_id = $data['intro_id'] ?? -1; $this->intro_id = $data['intro_id'] ?? -1;
$this->madeBy = $data['madeBy'] ?? ''; $this->madeBy = $data['madeBy'] ?? '';
$this->madeByUrl = $data['madeByUrl'] ?? ''; $this->madeByUrl = $data['madeByUrl'] ?? '';
$this->madeByZrl = $data['madeByZrl'] ?? ''; $this->madeByZrl = $data['madeByZrl'] ?? '';
$this->madeByAddr = $data['madeByAddr'] ?? ''; $this->madeByAddr = $data['madeByAddr'] ?? '';
$this->contactId = $data['contactId'] ?? -1; $this->contactId = $data['contactId'] ?? -1;
$this->photo = $data['photo'] ?? ''; $this->photo = $data['photo'] ?? '';
$this->name = $data['name'] ?? ''; $this->name = $data['name'] ?? '';
$this->url = $data['url'] ?? ''; $this->url = $data['url'] ?? '';
$this->zrl = $data['zrl'] ?? ''; $this->zrl = $data['zrl'] ?? '';
$this->hidden = $data['hidden'] ?? false; $this->hidden = $data['hidden'] ?? false;
$this->postNewFriend = $data['postNewFriend'] ?? ''; $this->postNewFriend = $data['postNewFriend'] ?? '';
$this->knowYou = $data['knowYou'] ?? false; $this->knowYou = $data['knowYou'] ?? false;
$this->note = $data['note'] ?? ''; $this->note = $data['note'] ?? '';
$this->request = $data['request'] ?? ''; $this->request = $data['request'] ?? '';
$this->dfrnId = -1; $this->dfrnId = -1;
$this->addr = $data['addr'] ?? ''; $this->addr = $data['addr'] ?? '';
$this->network = $data['network'] ?? ''; $this->network = $data['network'] ?? '';
$this->uid = $data['uid'] ?? -1; $this->uid = $data['uid'] ?? -1;
$this->keywords = $data['keywords'] ?? ''; $this->keywords = $data['keywords'] ?? '';
$this->location = $data['location'] ?? ''; $this->location = $data['location'] ?? '';
$this->about = $data['about'] ?? ''; $this->about = $data['about'] ?? '';
} }
public function getLabel(): string public function getLabel(): string

View file

@ -225,11 +225,11 @@ class CurlResult implements ICanHandleHttpResponses
} }
} }
$this->redirectUrl = (string)Uri::fromParts((array)$redirect_parts); $this->redirectUrl = (string)Uri::fromParts((array)$redirect_parts);
$this->isRedirectUrl = true; $this->isRedirectUrl = true;
$this->redirectIsPermanent = $this->returnCode == 301 || $this->returnCode == 308; $this->redirectIsPermanent = $this->returnCode == 301 || $this->returnCode == 308;
} else { } else {
$this->isRedirectUrl = false; $this->isRedirectUrl = false;
$this->redirectIsPermanent = false; $this->redirectIsPermanent = false;
} }
} }

View file

@ -84,15 +84,15 @@ class Notification extends BaseDataTransferObject
$this->date_rel = Temporal::getRelativeDate($this->date); $this->date_rel = Temporal::getRelativeDate($this->date);
try { 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) { } catch (\Exception $e) {
$this->msg_html = ''; $this->msg_html = '';
} }
try { try {
$this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0]; $this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0];
} catch (\Exception $e) { } catch (\Exception $e) {
$this->msg_plain = ''; $this->msg_plain = '';
} }
} }
} }

View file

@ -25,7 +25,7 @@ class Field extends BaseDataTransferObject
public function __construct(string $name, string $value) public function __construct(string $name, string $value)
{ {
$this->name = $name; $this->name = $name;
$this->value = $value; $this->value = $value;
// Link verification unsupported // Link verification unsupported
$this->verified_at = null; $this->verified_at = null;

View file

@ -245,8 +245,8 @@ class DiasporaContact extends BaseRepository
$uriId, $uriId,
new DateTime($contact['created'] ?? 'now', new DateTimeZone('UTC')), new DateTime($contact['created'] ?? 'now', new DateTimeZone('UTC')),
$interacting_count ?? 0, $interacting_count ?? 0,
$interacted_count ?? 0, $interacted_count ?? 0,
$post_count ?? 0 $post_count ?? 0
); );
$DiasporaContact = $this->save($DiasporaContact); $DiasporaContact = $this->save($DiasporaContact);

View file

@ -119,8 +119,8 @@ class PermissionSet extends BaseRepository
$circle_ids = []; $circle_ids = [];
if (!empty($user_contact_str) && $this->db->exists('contact', [ if (!empty($user_contact_str) && $this->db->exists('contact', [
'id' => $cid, 'id' => $cid,
'uid' => $uid, 'uid' => $uid,
'blocked' => false 'blocked' => false
])) { ])) {
$circle_ids = Circle::getIdsByContactId($cid); $circle_ids = Circle::getIdsByContactId($cid);

View file

@ -79,33 +79,25 @@ class Security
*/ */
public static function getPermissionsSQLByUserId(int $owner_id, bool $accessible = false) 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); $remote_contact = DI::userSession()->getRemoteContactID($owner_id);
$acc_sql = ''; $acc_sql = '';
if ($accessible) { if ($accessible) {
$acc_sql = ' OR `accessible`'; $acc_sql = ' OR `accessible`';
} }
/* // Construct permissions: default permissions - anonymous user
* Construct permissions
*
* default permissions - anonymous user
*/
$sql = " AND (allow_cid = '' $sql = " AND (allow_cid = ''
AND allow_gid = '' AND allow_gid = ''
AND deny_cid = '' AND deny_cid = ''
AND deny_gid = ''" . $acc_sql . ") "; AND deny_gid = ''" . $acc_sql . ") ";
/*
* Profile owner - everything is visible
*/
if ($local_user && $local_user == $owner_id) { if ($local_user && $local_user == $owner_id) {
// Profile owner - everything is visible
$sql = ''; $sql = '';
/*
* Authenticated visitor. Load the circles the visitor belongs to.
*/
} elseif ($remote_contact) { } elseif ($remote_contact) {
// Authenticated visitor. Load the circles the visitor belongs to.
$circleIds = '<<>>'; // should be impossible to match $circleIds = '<<>>'; // should be impossible to match
foreach (Circle::getIdsByContactId($remote_contact) as $circleId) { foreach (Circle::getIdsByContactId($remote_contact) as $circleId) {