mirror of
https://github.com/friendica/friendica
synced 2025-04-26 15:50:10 +00:00
Merge remote-tracking branch 'upstream/develop' into server-detection
This commit is contained in:
commit
8b7cb5d9ef
328 changed files with 13242 additions and 10211 deletions
|
@ -48,7 +48,7 @@ class APContact
|
|||
* @param string $addr Address
|
||||
* @return array webfinger data
|
||||
*/
|
||||
private static function fetchWebfingerData(string $addr)
|
||||
private static function fetchWebfingerData(string $addr): array
|
||||
{
|
||||
$addr_parts = explode('@', $addr);
|
||||
if (count($addr_parts) != 2) {
|
||||
|
@ -116,15 +116,16 @@ class APContact
|
|||
* @return array profile array
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
* @todo Rewrite parameter $update to avoid true|false|null (boolean is binary, null adds a third case)
|
||||
*/
|
||||
public static function getByURL($url, $update = null)
|
||||
public static function getByURL(string $url, $update = null): array
|
||||
{
|
||||
if (empty($url) || Network::isUrlBlocked($url)) {
|
||||
Logger::info('Domain is blocked', ['url' => $url]);
|
||||
return [];
|
||||
}
|
||||
|
||||
$fetched_contact = false;
|
||||
$fetched_contact = [];
|
||||
|
||||
if (empty($update)) {
|
||||
if (is_null($update)) {
|
||||
|
@ -222,14 +223,14 @@ class APContact
|
|||
$apcontact['type'] = str_replace('as:', '', JsonLD::fetchElement($compacted, '@type'));
|
||||
$apcontact['following'] = JsonLD::fetchElement($compacted, 'as:following', '@id');
|
||||
$apcontact['followers'] = JsonLD::fetchElement($compacted, 'as:followers', '@id');
|
||||
$apcontact['inbox'] = JsonLD::fetchElement($compacted, 'ldp:inbox', '@id');
|
||||
$apcontact['inbox'] = (JsonLD::fetchElement($compacted, 'ldp:inbox', '@id') ?? '');
|
||||
self::unarchiveInbox($apcontact['inbox'], false);
|
||||
|
||||
$apcontact['outbox'] = JsonLD::fetchElement($compacted, 'as:outbox', '@id');
|
||||
|
||||
$apcontact['sharedinbox'] = '';
|
||||
if (!empty($compacted['as:endpoints'])) {
|
||||
$apcontact['sharedinbox'] = JsonLD::fetchElement($compacted['as:endpoints'], 'as:sharedInbox', '@id');
|
||||
$apcontact['sharedinbox'] = (JsonLD::fetchElement($compacted['as:endpoints'], 'as:sharedInbox', '@id') ?? '');
|
||||
self::unarchiveInbox($apcontact['sharedinbox'], true);
|
||||
}
|
||||
|
||||
|
@ -243,9 +244,10 @@ class APContact
|
|||
$apcontact['name'] = $apcontact['nick'];
|
||||
}
|
||||
|
||||
$apcontact['about'] = HTML::toBBCode(JsonLD::fetchElement($compacted, 'as:summary', '@value'));
|
||||
$apcontact['about'] = HTML::toBBCode(JsonLD::fetchElement($compacted, 'as:summary', '@value') ?? '');
|
||||
|
||||
$ims = JsonLD::fetchElementArray($compacted, 'vcard:hasInstantMessage');
|
||||
|
||||
if (!empty($ims)) {
|
||||
foreach ($ims as $link) {
|
||||
if (substr($link, 0, 5) == 'xmpp:') {
|
||||
|
@ -466,7 +468,7 @@ class APContact
|
|||
}
|
||||
|
||||
// Limit the length on incoming fields
|
||||
$apcontact = DBStructure::getFieldsForTable('apcontact', $apcontact);
|
||||
$apcontact = DI::dbaDefinition()->truncateFieldsForTable('apcontact', $apcontact);
|
||||
|
||||
if (DBA::exists('apcontact', ['url' => $apcontact['url']])) {
|
||||
DBA::update('apcontact', $apcontact, ['url' => $apcontact['url']]);
|
||||
|
@ -527,8 +529,9 @@ class APContact
|
|||
*
|
||||
* @param string $url inbox url
|
||||
* @param boolean $shared Shared Inbox
|
||||
* @return void
|
||||
*/
|
||||
private static function unarchiveInbox($url, $shared)
|
||||
private static function unarchiveInbox(string $url, bool $shared)
|
||||
{
|
||||
if (empty($url)) {
|
||||
return;
|
||||
|
|
|
@ -23,7 +23,6 @@ namespace Friendica\Model;
|
|||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
use Friendica\Core\Storage\Exception\InvalidClassStorageException;
|
||||
use Friendica\Core\Storage\Exception\ReferenceStorageException;
|
||||
|
@ -44,9 +43,9 @@ class Attach
|
|||
* @return array field list
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function getFields()
|
||||
private static function getFields(): array
|
||||
{
|
||||
$allfields = DBStructure::definition(DI::app()->getBasePath(), false);
|
||||
$allfields = DI::dbaDefinition()->getAll();
|
||||
$fields = array_keys($allfields['attach']['fields']);
|
||||
array_splice($fields, array_search('data', $fields), 1);
|
||||
return $fields;
|
||||
|
@ -59,7 +58,7 @@ class Attach
|
|||
* @param array $conditions Array of fields for conditions
|
||||
* @param array $params Array of several parameters
|
||||
*
|
||||
* @return array
|
||||
* @return array|bool
|
||||
*
|
||||
* @throws \Exception
|
||||
* @see \Friendica\Database\DBA::selectToArray
|
||||
|
@ -102,7 +101,7 @@ class Attach
|
|||
* @return boolean
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function exists(array $conditions)
|
||||
public static function exists(array $conditions): bool
|
||||
{
|
||||
return DBA::exists('attach', $conditions);
|
||||
}
|
||||
|
@ -117,7 +116,7 @@ class Attach
|
|||
* @throws \Exception
|
||||
* @see \Friendica\Database\DBA::select
|
||||
*/
|
||||
public static function getById($id)
|
||||
public static function getById(int $id)
|
||||
{
|
||||
return self::selectFirst([], ['id' => $id]);
|
||||
}
|
||||
|
@ -132,7 +131,7 @@ class Attach
|
|||
* @throws \Exception
|
||||
* @see \Friendica\Database\DBA::select
|
||||
*/
|
||||
public static function getByIdWithPermission($id)
|
||||
public static function getByIdWithPermission(int $id)
|
||||
{
|
||||
$r = self::selectFirst(['uid'], ['id' => $id]);
|
||||
if ($r === false) {
|
||||
|
@ -156,10 +155,10 @@ class Attach
|
|||
*
|
||||
* @param array $item Attachment data. Needs at least 'id', 'backend-class', 'backend-ref'
|
||||
*
|
||||
* @return string file data
|
||||
* @return string|null file data or null on failure
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getData($item)
|
||||
public static function getData(array $item)
|
||||
{
|
||||
if (!empty($item['data'])) {
|
||||
return $item['data'];
|
||||
|
@ -195,10 +194,10 @@ class Attach
|
|||
* @param string $deny_cid Permissions, denied contacts.optional, default = ''
|
||||
* @param string $deny_gid Permissions, denied greoup.optional, default = ''
|
||||
*
|
||||
* @return boolean/integer Row id on success, False on errors
|
||||
* @return boolean|integer Row id on success, False on errors
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function store($data, $uid, $filename, $filetype = '' , $filesize = null, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '')
|
||||
public static function store(string $data, int $uid, string $filename, string $filetype = '' , int $filesize = null, string $allow_cid = '', string $allow_gid = '', string $deny_cid = '', string $deny_gid = '')
|
||||
{
|
||||
if ($filetype === '') {
|
||||
$filetype = Mimetype::getContentType($filename);
|
||||
|
@ -241,17 +240,17 @@ class Attach
|
|||
/**
|
||||
* Store new file metadata in db and binary in default backend from existing file
|
||||
*
|
||||
* @param $src
|
||||
* @param $uid
|
||||
* @param string $filename
|
||||
* @param string $src Source file name
|
||||
* @param int $uid User id
|
||||
* @param string $filename Optional file name
|
||||
* @param string $allow_cid
|
||||
* @param string $allow_gid
|
||||
* @param string $deny_cid
|
||||
* @param string $deny_gid
|
||||
* @return boolean True on success
|
||||
* @return boolean|int Insert id or false on failure
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function storeFile($src, $uid, $filename = '', $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '')
|
||||
public static function storeFile(string $src, int $uid, string $filename = '', string $allow_cid = '', string $allow_gid = '', string $deny_cid = '', string $deny_gid = '')
|
||||
{
|
||||
if ($filename === '') {
|
||||
$filename = basename($src);
|
||||
|
@ -276,7 +275,7 @@ class Attach
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @see \Friendica\Database\DBA::update
|
||||
*/
|
||||
public static function update($fields, $conditions, Image $img = null, array $old_fields = [])
|
||||
public static function update(array $fields, array $conditions, Image $img = null, array $old_fields = []): bool
|
||||
{
|
||||
if (!is_null($img)) {
|
||||
// get items to update
|
||||
|
@ -311,7 +310,7 @@ class Attach
|
|||
* @throws \Exception
|
||||
* @see \Friendica\Database\DBA::delete
|
||||
*/
|
||||
public static function delete(array $conditions, array $options = [])
|
||||
public static function delete(array $conditions, array $options = []): bool
|
||||
{
|
||||
// get items to delete data info
|
||||
$items = self::selectToArray(['backend-class','backend-ref'], $conditions);
|
||||
|
|
|
@ -119,7 +119,7 @@ class Contact
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function selectToArray(array $fields = [], array $condition = [], array $params = [])
|
||||
public static function selectToArray(array $fields = [], array $condition = [], array $params = []): array
|
||||
{
|
||||
return DBA::selectToArray('contact', $fields, $condition, $params);
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ class Contact
|
|||
* @param array $fields Array of selected fields, empty for all
|
||||
* @param array $condition Array of fields for condition
|
||||
* @param array $params Array of several parameters
|
||||
* @return array
|
||||
* @return array|bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function selectFirst(array $fields = [], array $condition = [], array $params = [])
|
||||
|
@ -148,7 +148,7 @@ class Contact
|
|||
* @return int id of the created contact
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function insert(array $fields, int $duplicate_mode = Database::INSERT_DEFAULT)
|
||||
public static function insert(array $fields, int $duplicate_mode = Database::INSERT_DEFAULT): int
|
||||
{
|
||||
if (!empty($fields['baseurl']) && empty($fields['gsid'])) {
|
||||
$fields['gsid'] = GServer::getID($fields['baseurl'], true);
|
||||
|
@ -187,6 +187,7 @@ class Contact
|
|||
*
|
||||
* @return boolean was the update successfull?
|
||||
* @throws \Exception
|
||||
* @todo Let's get rid of boolean type of $old_fields
|
||||
*/
|
||||
public static function update(array $fields, array $condition, $old_fields = [])
|
||||
{
|
||||
|
@ -204,7 +205,7 @@ class Contact
|
|||
* @return array|boolean Contact record if it exists, false otherwise
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getById($id, $fields = [])
|
||||
public static function getById(int $id, array $fields = [])
|
||||
{
|
||||
return DBA::selectFirst('contact', $fields, ['id' => $id]);
|
||||
}
|
||||
|
@ -217,7 +218,7 @@ class Contact
|
|||
* @return array|boolean Contact record if it exists, false otherwise
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getByUriId($uri_id, $fields = [])
|
||||
public static function getByUriId(int $uri_id, array $fields = [])
|
||||
{
|
||||
return DBA::selectFirst('contact', $fields, ['uri-id' => $uri_id], ['order' => ['uid']]);
|
||||
}
|
||||
|
@ -231,7 +232,7 @@ class Contact
|
|||
* @param integer $uid User ID of the contact
|
||||
* @return array contact array
|
||||
*/
|
||||
public static function getByURL(string $url, $update = null, array $fields = [], int $uid = 0)
|
||||
public static function getByURL(string $url, $update = null, array $fields = [], int $uid = 0): array
|
||||
{
|
||||
if ($update || is_null($update)) {
|
||||
$cid = self::getIdForURL($url, $uid, $update);
|
||||
|
@ -302,7 +303,7 @@ class Contact
|
|||
* @param array $fields Field list
|
||||
* @return array contact array
|
||||
*/
|
||||
public static function getByURLForUser(string $url, int $uid = 0, $update = false, array $fields = [])
|
||||
public static function getByURLForUser(string $url, int $uid = 0, $update = false, array $fields = []): array
|
||||
{
|
||||
if ($uid != 0) {
|
||||
$contact = self::getByURL($url, $update, $fields, $uid);
|
||||
|
@ -333,7 +334,7 @@ class Contact
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function isFollower($cid, $uid)
|
||||
public static function isFollower(int $cid, int $uid): bool
|
||||
{
|
||||
if (Contact\User::isBlocked($cid, $uid)) {
|
||||
return false;
|
||||
|
@ -358,7 +359,7 @@ class Contact
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function isFollowerByURL($url, $uid)
|
||||
public static function isFollowerByURL(string $url, uid $uid): bool
|
||||
{
|
||||
$cid = self::getIdForURL($url, $uid);
|
||||
|
||||
|
@ -370,16 +371,16 @@ class Contact
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests if the given user follow the given contact
|
||||
* Tests if the given user shares with the given contact
|
||||
*
|
||||
* @param int $cid Either public contact id or user's contact id
|
||||
* @param int $uid User ID
|
||||
*
|
||||
* @return boolean is the contact url being followed?
|
||||
* @return boolean is the contact sharing with given user?
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function isSharing($cid, $uid)
|
||||
public static function isSharing(int $cid, int $uid): bool
|
||||
{
|
||||
if (Contact\User::isBlocked($cid, $uid)) {
|
||||
return false;
|
||||
|
@ -404,7 +405,7 @@ class Contact
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function isSharingByURL($url, $uid)
|
||||
public static function isSharingByURL(string $url, int $uid): bool
|
||||
{
|
||||
$cid = self::getIdForURL($url, $uid);
|
||||
|
||||
|
@ -425,7 +426,7 @@ class Contact
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function getBasepath($url, $dont_update = false)
|
||||
public static function getBasepath(string $url, bool $dont_update = false): string
|
||||
{
|
||||
$contact = DBA::selectFirst('contact', ['id', 'baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]);
|
||||
if (!DBA::isResult($contact)) {
|
||||
|
@ -459,7 +460,7 @@ class Contact
|
|||
*
|
||||
* @return boolean Is it the same server?
|
||||
*/
|
||||
public static function isLocal($url)
|
||||
public static function isLocal(string $url): bool
|
||||
{
|
||||
if (!parse_url($url, PHP_URL_SCHEME)) {
|
||||
$addr_parts = explode('@', $url);
|
||||
|
@ -473,10 +474,9 @@ class Contact
|
|||
* Check if the given contact ID is on the same server
|
||||
*
|
||||
* @param string $url The contact link
|
||||
*
|
||||
* @return boolean Is it the same server?
|
||||
*/
|
||||
public static function isLocalById(int $cid)
|
||||
public static function isLocalById(int $cid): bool
|
||||
{
|
||||
$contact = DBA::selectFirst('contact', ['url', 'baseurl'], ['id' => $cid]);
|
||||
if (!DBA::isResult($contact)) {
|
||||
|
@ -500,7 +500,7 @@ class Contact
|
|||
* @return integer|boolean Public contact id for given user id
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getPublicIdByUserId($uid)
|
||||
public static function getPublicIdByUserId(int $uid)
|
||||
{
|
||||
$self = DBA::selectFirst('contact', ['url'], ['self' => true, 'uid' => $uid]);
|
||||
if (!DBA::isResult($self)) {
|
||||
|
@ -519,7 +519,7 @@ class Contact
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function getPublicAndUserContactID($cid, $uid)
|
||||
public static function getPublicAndUserContactID(int $cid, int $uid): array
|
||||
{
|
||||
// We have to use the legacy function as long as the post update hasn't finished
|
||||
if (DI::config()->get('system', 'post_update_version') < 1427) {
|
||||
|
@ -555,12 +555,11 @@ class Contact
|
|||
*
|
||||
* @param int $cid Either public contact id or user's contact id
|
||||
* @param int $uid User ID
|
||||
*
|
||||
* @return array with public and user's contact id
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
private static function legacyGetPublicAndUserContactID($cid, $uid)
|
||||
private static function legacyGetPublicAndUserContactID(int $cid, int $uid): array
|
||||
{
|
||||
if (empty($uid) || empty($cid)) {
|
||||
return [];
|
||||
|
@ -596,12 +595,11 @@ class Contact
|
|||
* @param int $cid A contact ID
|
||||
* @param int $uid The User ID
|
||||
* @param array $fields The selected fields for the contact
|
||||
*
|
||||
* @return array The contact details
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getContactForUser($cid, $uid, array $fields = [])
|
||||
public static function getContactForUser(int $cid, int $uid, array $fields = []): array
|
||||
{
|
||||
$contact = DBA::selectFirst('contact', $fields, ['id' => $cid, 'uid' => $uid]);
|
||||
|
||||
|
@ -619,7 +617,7 @@ class Contact
|
|||
* @return bool Operation success
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function createSelfFromUserId($uid)
|
||||
public static function createSelfFromUserId(int $uid): bool
|
||||
{
|
||||
$user = DBA::selectFirst('user', ['uid', 'username', 'nickname', 'pubkey', 'prvkey'],
|
||||
['uid' => $uid, 'account_expired' => false]);
|
||||
|
@ -676,12 +674,12 @@ class Contact
|
|||
/**
|
||||
* Updates the self-contact for the provided user id
|
||||
*
|
||||
* @param int $uid
|
||||
* @param boolean $update_avatar Force the avatar update
|
||||
* @return bool "true" if updated
|
||||
* @param int $uid
|
||||
* @param bool $update_avatar Force the avatar update
|
||||
* @return bool "true" if updated
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function updateSelfFromUserID($uid, $update_avatar = false)
|
||||
public static function updateSelfFromUserID(int $uid, bool $update_avatar = false): bool
|
||||
{
|
||||
$fields = ['id', 'uri-id', 'name', 'nick', 'location', 'about', 'keywords', 'avatar', 'prvkey', 'pubkey', 'manually-approve',
|
||||
'xmpp', 'matrix', 'contact-type', 'forum', 'prv', 'avatar-date', 'url', 'nurl', 'unsearchable',
|
||||
|
@ -794,9 +792,10 @@ class Contact
|
|||
* Marks a contact for removal
|
||||
*
|
||||
* @param int $id contact id
|
||||
* @return void
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function remove($id)
|
||||
public static function remove(int $id)
|
||||
{
|
||||
// We want just to make sure that we don't delete our "self" contact
|
||||
$contact = DBA::selectFirst('contact', ['uri-id', 'photo', 'thumb', 'micro', 'uid'], ['id' => $id, 'self' => false]);
|
||||
|
@ -821,6 +820,7 @@ class Contact
|
|||
* Unfollow the remote contact
|
||||
*
|
||||
* @param array $contact Target user-specific contact (uid != 0) array
|
||||
* @return void
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
|
@ -850,6 +850,7 @@ class Contact
|
|||
* The local relationship is updated immediately, the eventual remote server is messaged in the background.
|
||||
*
|
||||
* @param array $contact User-specific contact array (uid != 0) to revoke the follow from
|
||||
* @return void
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
|
@ -877,6 +878,7 @@ class Contact
|
|||
* Completely severs a relationship with a contact
|
||||
*
|
||||
* @param array $contact User-specific contact (uid != 0) array
|
||||
* @return void
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
|
@ -924,7 +926,7 @@ class Contact
|
|||
* up or some other transient event and that there's a possibility we could recover from it.
|
||||
*
|
||||
* @param array $contact contact to mark for archival
|
||||
* @return null
|
||||
* @return void
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function markForArchival(array $contact)
|
||||
|
@ -977,7 +979,7 @@ class Contact
|
|||
* @see Contact::markForArchival()
|
||||
*
|
||||
* @param array $contact contact to be unmarked for archival
|
||||
* @return null
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function unmarkForArchival(array $contact)
|
||||
|
@ -1024,7 +1026,7 @@ class Contact
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function photoMenu(array $contact, $uid = 0)
|
||||
public static function photoMenu(array $contact, int $uid = 0): array
|
||||
{
|
||||
$pm_url = '';
|
||||
$status_link = '';
|
||||
|
@ -1167,7 +1169,7 @@ class Contact
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function getIdForURL($url, $uid = 0, $update = null, $default = [])
|
||||
public static function getIdForURL(string $url, int $uid = 0, $update = null, array $default = []): int
|
||||
{
|
||||
$contact_id = 0;
|
||||
|
||||
|
@ -1179,7 +1181,7 @@ class Contact
|
|||
$contact = self::getByURL($url, false, ['id', 'network', 'uri-id'], $uid);
|
||||
|
||||
if (!empty($contact)) {
|
||||
$contact_id = $contact["id"];
|
||||
$contact_id = $contact['id'];
|
||||
|
||||
if (empty($update) && (!empty($contact['uri-id']) || is_bool($update))) {
|
||||
Logger::debug('Contact found', ['url' => $url, 'uid' => $uid, 'update' => $update, 'cid' => $contact_id]);
|
||||
|
@ -1196,10 +1198,10 @@ class Contact
|
|||
$data = [];
|
||||
|
||||
if (empty($default['network']) || $update) {
|
||||
$data = Probe::uri($url, "", $uid);
|
||||
$data = Probe::uri($url, '', $uid);
|
||||
|
||||
// Take the default values when probing failed
|
||||
if (!empty($default) && !in_array($data["network"], array_merge(Protocol::NATIVE_SUPPORT, [Protocol::PUMPIO]))) {
|
||||
if (!empty($default) && !in_array($data['network'], array_merge(Protocol::NATIVE_SUPPORT, [Protocol::PUMPIO]))) {
|
||||
$data = array_merge($data, $default);
|
||||
}
|
||||
} elseif (!empty($default['network'])) {
|
||||
|
@ -1311,7 +1313,7 @@ class Contact
|
|||
* @return boolean Is the contact archived?
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function isArchived(int $cid)
|
||||
public static function isArchived(int $cid): bool
|
||||
{
|
||||
if ($cid == 0) {
|
||||
return false;
|
||||
|
@ -1351,11 +1353,10 @@ class Contact
|
|||
* Checks if the contact is blocked
|
||||
*
|
||||
* @param int $cid contact id
|
||||
*
|
||||
* @return boolean Is the contact blocked?
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function isBlocked($cid)
|
||||
public static function isBlocked(int $cid): bool
|
||||
{
|
||||
if ($cid == 0) {
|
||||
return false;
|
||||
|
@ -1377,11 +1378,10 @@ class Contact
|
|||
* Checks if the contact is hidden
|
||||
*
|
||||
* @param int $cid contact id
|
||||
*
|
||||
* @return boolean Is the contact hidden?
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function isHidden($cid)
|
||||
public static function isHidden(int $cid): bool
|
||||
{
|
||||
if ($cid == 0) {
|
||||
return false;
|
||||
|
@ -1405,7 +1405,7 @@ class Contact
|
|||
* @return string posts in HTML
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getPostsFromUrl($contact_url, $thread_mode = false, $update = 0, $parent = 0, bool $only_media = false)
|
||||
public static function getPostsFromUrl(string $contact_url, bool $thread_mode = false, int $update = 0, int $parent = 0, bool $only_media = false): string
|
||||
{
|
||||
return self::getPostsFromId(self::getIdForURL($contact_url), $thread_mode, $update, $parent, $only_media);
|
||||
}
|
||||
|
@ -1421,7 +1421,7 @@ class Contact
|
|||
* @return string posts in HTML
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getPostsFromId($cid, $thread_mode = false, $update = 0, $parent = 0, bool $only_media = false)
|
||||
public static function getPostsFromId(int $cid, bool $thread_mode = false, int $update = 0, int $parent = 0, bool $only_media = false): string
|
||||
{
|
||||
$contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]);
|
||||
if (!DBA::isResult($contact)) {
|
||||
|
@ -1526,7 +1526,7 @@ class Contact
|
|||
* @param int $type type of contact or account
|
||||
* @return string
|
||||
*/
|
||||
public static function getAccountType(int $type)
|
||||
public static function getAccountType(int $type): string
|
||||
{
|
||||
switch ($type) {
|
||||
case self::TYPE_ORGANISATION:
|
||||
|
@ -1552,11 +1552,11 @@ class Contact
|
|||
/**
|
||||
* Blocks a contact
|
||||
*
|
||||
* @param int $cid
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
* @param int $cid Contact id to block
|
||||
* @param string $reason Block reason
|
||||
* @return bool Whether it was successful
|
||||
*/
|
||||
public static function block($cid, $reason = null)
|
||||
public static function block(int $cid, string $reason = null): bool
|
||||
{
|
||||
$return = self::update(['blocked' => true, 'block_reason' => $reason], ['id' => $cid]);
|
||||
|
||||
|
@ -1566,11 +1566,10 @@ class Contact
|
|||
/**
|
||||
* Unblocks a contact
|
||||
*
|
||||
* @param int $cid
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
* @param int $cid Contact id to unblock
|
||||
* @return bool Whether it was successfull
|
||||
*/
|
||||
public static function unblock($cid)
|
||||
public static function unblock(int $cid): bool
|
||||
{
|
||||
$return = self::update(['blocked' => false, 'block_reason' => null], ['id' => $cid]);
|
||||
|
||||
|
@ -1580,7 +1579,7 @@ class Contact
|
|||
/**
|
||||
* Ensure that cached avatar exist
|
||||
*
|
||||
* @param integer $cid
|
||||
* @param integer $cid Contact id
|
||||
*/
|
||||
public static function checkAvatarCache(int $cid)
|
||||
{
|
||||
|
@ -1620,7 +1619,7 @@ class Contact
|
|||
* @param bool $no_update Don't perfom an update if no cached avatar was found
|
||||
* @return string photo path
|
||||
*/
|
||||
private static function getAvatarPath(array $contact, string $size, $no_update = false)
|
||||
private static function getAvatarPath(array $contact, string $size, bool $no_update = false): string
|
||||
{
|
||||
$contact = self::checkAvatarCacheByArray($contact, $no_update);
|
||||
|
||||
|
@ -1654,7 +1653,7 @@ class Contact
|
|||
* @param bool $no_update Don't perfom an update if no cached avatar was found
|
||||
* @return string photo path
|
||||
*/
|
||||
public static function getPhoto(array $contact, bool $no_update = false)
|
||||
public static function getPhoto(array $contact, bool $no_update = false): string
|
||||
{
|
||||
return self::getAvatarPath($contact, Proxy::SIZE_SMALL, $no_update);
|
||||
}
|
||||
|
@ -1666,7 +1665,7 @@ class Contact
|
|||
* @param bool $no_update Don't perfom an update if no cached avatar was found
|
||||
* @return string photo path
|
||||
*/
|
||||
public static function getThumb(array $contact, bool $no_update = false)
|
||||
public static function getThumb(array $contact, bool $no_update = false): string
|
||||
{
|
||||
return self::getAvatarPath($contact, Proxy::SIZE_THUMB, $no_update);
|
||||
}
|
||||
|
@ -1678,7 +1677,7 @@ class Contact
|
|||
* @param bool $no_update Don't perfom an update if no cached avatar was found
|
||||
* @return string photo path
|
||||
*/
|
||||
public static function getMicro(array $contact, bool $no_update = false)
|
||||
public static function getMicro(array $contact, bool $no_update = false): string
|
||||
{
|
||||
return self::getAvatarPath($contact, Proxy::SIZE_MICRO, $no_update);
|
||||
}
|
||||
|
@ -1690,7 +1689,7 @@ class Contact
|
|||
* @param bool $no_update Don't perfom an update if no cached avatar was found
|
||||
* @return array contact array with avatar cache fields
|
||||
*/
|
||||
private static function checkAvatarCacheByArray(array $contact, bool $no_update = false)
|
||||
private static function checkAvatarCacheByArray(array $contact, bool $no_update = false): array
|
||||
{
|
||||
$update = false;
|
||||
$contact_fields = [];
|
||||
|
@ -1796,7 +1795,7 @@ class Contact
|
|||
* @param string $size Size of the avatar picture
|
||||
* @return string avatar URL
|
||||
*/
|
||||
public static function getDefaultAvatar(array $contact, string $size)
|
||||
public static function getDefaultAvatar(array $contact, string $size): string
|
||||
{
|
||||
switch ($size) {
|
||||
case Proxy::SIZE_MICRO:
|
||||
|
@ -1958,7 +1957,7 @@ class Contact
|
|||
* @param string $updated Contact update date
|
||||
* @return string avatar link
|
||||
*/
|
||||
public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''):string
|
||||
public static function getAvatarUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''): string
|
||||
{
|
||||
// We have to fetch the "updated" variable when it wasn't provided
|
||||
// The parameter can be provided to improve performance
|
||||
|
@ -1999,7 +1998,7 @@ class Contact
|
|||
* @param string $size One of the Proxy::SIZE_* constants
|
||||
* @return string avatar link
|
||||
*/
|
||||
public static function getAvatarUrlForUrl(string $url, int $uid, string $size = ''):string
|
||||
public static function getAvatarUrlForUrl(string $url, int $uid, string $size = ''): string
|
||||
{
|
||||
$condition = ["`nurl` = ? AND ((`uid` = ? AND `network` IN (?, ?)) OR `uid` = ?)",
|
||||
Strings::normaliseLink($url), $uid, Protocol::FEED, Protocol::MAIL, 0];
|
||||
|
@ -2015,7 +2014,7 @@ class Contact
|
|||
* @param string $updated Contact update date
|
||||
* @return string header link
|
||||
*/
|
||||
public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''):string
|
||||
public static function getHeaderUrlForId(int $cid, string $size = '', string $updated = '', string $guid = ''): string
|
||||
{
|
||||
// We have to fetch the "updated" variable when it wasn't provided
|
||||
// The parameter can be provided to improve performance
|
||||
|
@ -2312,6 +2311,8 @@ class Contact
|
|||
}
|
||||
|
||||
/**
|
||||
* Updates contact record by provided id and optional network
|
||||
*
|
||||
* @param integer $id contact id
|
||||
* @param string $network Optional network we are probing for
|
||||
* @return boolean
|
||||
|
@ -2335,13 +2336,15 @@ class Contact
|
|||
}
|
||||
|
||||
/**
|
||||
* Updates contact record by provided id and probed data
|
||||
*
|
||||
* @param integer $id contact id
|
||||
* @param array $ret Probed data
|
||||
* @return boolean
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
private static function updateFromProbeArray(int $id, array $ret)
|
||||
private static function updateFromProbeArray(int $id, array $ret): bool
|
||||
{
|
||||
/*
|
||||
Warning: Never ever fetch the public key via Probe::uri and write it into the contacts.
|
||||
|
@ -2552,12 +2555,14 @@ class Contact
|
|||
}
|
||||
|
||||
/**
|
||||
* Updates contact record by provided URL
|
||||
*
|
||||
* @param integer $url contact url
|
||||
* @return integer Contact id
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function updateFromProbeByURL($url)
|
||||
public static function updateFromProbeByURL(string $url): int
|
||||
{
|
||||
$id = self::getIdForURL($url);
|
||||
|
||||
|
@ -2578,7 +2583,7 @@ class Contact
|
|||
* @param string $network Network of that contact
|
||||
* @return string with protocol
|
||||
*/
|
||||
public static function getProtocol($url, $network)
|
||||
public static function getProtocol(string $url, string $network): string
|
||||
{
|
||||
if ($network != Protocol::DFRN) {
|
||||
return $network;
|
||||
|
@ -2614,7 +2619,7 @@ class Contact
|
|||
* @throws HTTPException\NotFoundException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function createFromProbeForUser(int $uid, $url, $network = '')
|
||||
public static function createFromProbeForUser(int $uid, string $url, string $network = ''): array
|
||||
{
|
||||
$result = ['cid' => -1, 'success' => false, 'message' => ''];
|
||||
|
||||
|
@ -2803,7 +2808,7 @@ class Contact
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function addRelationship(array $importer, array $contact, array $datarray, $sharing = false, $note = '')
|
||||
public static function addRelationship(array $importer, array $contact, array $datarray, bool $sharing = false, string $note = '')
|
||||
{
|
||||
// Should always be set
|
||||
if (empty($datarray['author-id'])) {
|
||||
|
@ -2945,6 +2950,7 @@ class Contact
|
|||
* Update the local relationship when a local user loses a follower
|
||||
*
|
||||
* @param array $contact User-specific contact (uid != 0) array
|
||||
* @return void
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
|
@ -3030,7 +3036,7 @@ class Contact
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function pruneUnavailable(array $contact_ids)
|
||||
public static function pruneUnavailable(array $contact_ids): array
|
||||
{
|
||||
if (empty($contact_ids)) {
|
||||
return [];
|
||||
|
@ -3058,7 +3064,7 @@ class Contact
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function magicLink($contact_url, $url = '')
|
||||
public static function magicLink(string $contact_url, string $url = ''): string
|
||||
{
|
||||
if (!Session::isAuthenticated()) {
|
||||
return $url ?: $contact_url; // Equivalent to: ($url != '') ? $url : $contact_url;
|
||||
|
@ -3085,7 +3091,7 @@ class Contact
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function magicLinkById($cid, $url = '')
|
||||
public static function magicLinkById(int $cid, string $url = ''): string
|
||||
{
|
||||
$contact = DBA::selectFirst('contact', ['id', 'network', 'url', 'uid'], ['id' => $cid]);
|
||||
|
||||
|
@ -3102,7 +3108,7 @@ class Contact
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function magicLinkByContact($contact, $url = '')
|
||||
public static function magicLinkByContact(array $contact, string $url = ''): string
|
||||
{
|
||||
$destination = $url ?: $contact['url']; // Equivalent to ($url != '') ? $url : $contact['url'];
|
||||
|
||||
|
@ -3143,7 +3149,7 @@ class Contact
|
|||
*
|
||||
* @return boolean "true" if it is a forum
|
||||
*/
|
||||
public static function isForum($contactid)
|
||||
public static function isForum(int $contactid): bool
|
||||
{
|
||||
$fields = ['contact-type'];
|
||||
$condition = ['id' => $contactid];
|
||||
|
@ -3162,7 +3168,7 @@ class Contact
|
|||
* @param array $contact
|
||||
* @return bool
|
||||
*/
|
||||
public static function canReceivePrivateMessages(array $contact)
|
||||
public static function canReceivePrivateMessages(array $contact): bool
|
||||
{
|
||||
$protocol = $contact['network'] ?? $contact['protocol'] ?? Protocol::PHANTOM;
|
||||
$self = $contact['self'] ?? false;
|
||||
|
@ -3180,7 +3186,7 @@ class Contact
|
|||
* @return array with search results
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function searchByName(string $search, string $mode = '', int $uid = 0)
|
||||
public static function searchByName(string $search, string $mode = '', int $uid = 0): array
|
||||
{
|
||||
if (empty($search)) {
|
||||
return [];
|
||||
|
@ -3223,7 +3229,7 @@ class Contact
|
|||
* @param array $urls
|
||||
* @return array result "count", "added" and "updated"
|
||||
*/
|
||||
public static function addByUrls(array $urls)
|
||||
public static function addByUrls(array $urls): array
|
||||
{
|
||||
$added = 0;
|
||||
$updated = 0;
|
||||
|
@ -3256,7 +3262,7 @@ class Contact
|
|||
* @return array The profile array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getRandomContact()
|
||||
public static function getRandomContact(): array
|
||||
{
|
||||
$contact = DBA::selectFirst('contact', ['id', 'network', 'url', 'uid'], [
|
||||
"`uid` = ? AND `network` = ? AND NOT `failed` AND `last-item` > ?",
|
||||
|
|
|
@ -36,7 +36,7 @@ class Group
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getById(int $gid)
|
||||
public static function getById(int $gid): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ class Relation
|
|||
* @param array $rel
|
||||
* @return array contact list
|
||||
*/
|
||||
private static function getContacts(int $uid, array $rel)
|
||||
private static function getContacts(int $uid, array $rel): array
|
||||
{
|
||||
$list = [];
|
||||
$profile = Profile::getByUID($uid);
|
||||
|
@ -182,8 +182,15 @@ class Relation
|
|||
return $list;
|
||||
}
|
||||
|
||||
$condition = ['rel' => $rel, 'uid' => $uid, 'self' => false, 'deleted' => false,
|
||||
'hidden' => false, 'archive' => false, 'pending' => false];
|
||||
$condition = [
|
||||
'rel' => $rel,
|
||||
'uid' => $uid,
|
||||
'self' => false,
|
||||
'deleted' => false,
|
||||
'hidden' => false,
|
||||
'archive' => false,
|
||||
'pending' => false,
|
||||
];
|
||||
$condition = DBA::mergeConditions($condition, ["`url` IN (SELECT `url` FROM `apcontact`)"]);
|
||||
$contacts = DBA::select('contact', ['url'], $condition);
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
|
@ -201,7 +208,7 @@ class Relation
|
|||
* @param array $contact Contact array
|
||||
* @return boolean True if contact is discoverable
|
||||
*/
|
||||
public static function isDiscoverable(string $url, array $contact = [])
|
||||
public static function isDiscoverable(string $url, array $contact = []): bool
|
||||
{
|
||||
$contact_discovery = DI::config()->get('system', 'contact_discovery');
|
||||
|
||||
|
@ -254,12 +261,14 @@ class Relation
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $uid user
|
||||
* Returns an array of suggested contacts for given user id
|
||||
*
|
||||
* @param int $uid User id
|
||||
* @param int $start optional, default 0
|
||||
* @param int $limit optional, default 80
|
||||
* @return array
|
||||
*/
|
||||
static public function getSuggestions(int $uid, int $start = 0, int $limit = 80)
|
||||
static public function getSuggestions(int $uid, int $start = 0, int $limit = 80): array
|
||||
{
|
||||
$cid = Contact::getPublicIdByUserId($uid);
|
||||
$totallimit = $start + $limit;
|
||||
|
@ -272,20 +281,25 @@ class Relation
|
|||
|
||||
// The query returns contacts where contacts interacted with whom the given user follows.
|
||||
// Contacts who already are in the user's contact table are ignored.
|
||||
$results = DBA::select('contact', [],
|
||||
["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` IN
|
||||
$results = DBA::select('contact', [], ["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` IN
|
||||
(SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ?)
|
||||
AND NOT `cid` IN (SELECT `id` FROM `contact` WHERE `uid` = ? AND `nurl` IN
|
||||
(SELECT `nurl` FROM `contact` WHERE `uid` = ? AND `rel` IN (?, ?))))
|
||||
AND NOT `hidden` AND `network` IN (?, ?, ?, ?)",
|
||||
$cid, 0, $uid, Contact::FRIEND, Contact::SHARING,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, $diaspora, $ostatus],
|
||||
['order' => ['last-item' => true], 'limit' => $totallimit]
|
||||
$cid,
|
||||
0,
|
||||
$uid, Contact::FRIEND, Contact::SHARING,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, $diaspora, $ostatus,
|
||||
], [
|
||||
'order' => ['last-item' => true],
|
||||
'limit' => $totallimit,
|
||||
]
|
||||
);
|
||||
|
||||
while ($contact = DBA::fetch($results)) {
|
||||
$contacts[$contact['id']] = $contact;
|
||||
}
|
||||
|
||||
DBA::close($results);
|
||||
|
||||
Logger::info('Contacts of contacts who are followed by the given user', ['uid' => $uid, 'cid' => $cid, 'count' => count($contacts)]);
|
||||
|
@ -365,12 +379,12 @@ class Relation
|
|||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function countFollows(int $cid, array $condition = [])
|
||||
public static function countFollows(int $cid, array $condition = []): int
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
|
||||
$cid]
|
||||
);
|
||||
$condition = DBA::mergeConditions($condition, [
|
||||
'`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
|
||||
$cid,
|
||||
]);
|
||||
|
||||
return DI::dba()->count('contact', $condition);
|
||||
}
|
||||
|
@ -556,7 +570,7 @@ class Relation
|
|||
* @param int $count
|
||||
* @param int $offset
|
||||
* @param bool $shuffle
|
||||
* @return array
|
||||
* @return array|bool Array on success, false on failure
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function listCommon(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
|
||||
|
@ -581,7 +595,7 @@ class Relation
|
|||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function countCommonFollows(int $sourceId, int $targetId, array $condition = [])
|
||||
public static function countCommonFollows(int $sourceId, int $targetId, array $condition = []): int
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
|
||||
|
@ -601,7 +615,7 @@ class Relation
|
|||
* @param int $count
|
||||
* @param int $offset
|
||||
* @param bool $shuffle
|
||||
* @return array
|
||||
* @return array|bool Array on success, false on failure
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function listCommonFollows(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
|
||||
|
@ -626,7 +640,7 @@ class Relation
|
|||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function countCommonFollowers(int $sourceId, int $targetId, array $condition = [])
|
||||
public static function countCommonFollowers(int $sourceId, int $targetId, array $condition = []): int
|
||||
{
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)
|
||||
|
@ -646,7 +660,7 @@ class Relation
|
|||
* @param int $count
|
||||
* @param int $offset
|
||||
* @param bool $shuffle
|
||||
* @return array
|
||||
* @return array|bool Array on success, false on failure
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function listCommonFollowers(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
|
||||
|
|
|
@ -28,6 +28,7 @@ use Friendica\Core\System;
|
|||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\ItemURI;
|
||||
use PDOException;
|
||||
|
@ -82,11 +83,11 @@ class User
|
|||
/**
|
||||
* Apply changes from contact update data to user-contact table
|
||||
*
|
||||
* @param array $fields
|
||||
* @param array $condition
|
||||
* @return void
|
||||
* @throws PDOException
|
||||
* @throws Exception
|
||||
* @param array $fields
|
||||
* @param array $condition
|
||||
* @return void
|
||||
* @throws PDOException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function updateByContactUpdate(array $fields, array $condition)
|
||||
{
|
||||
|
@ -106,7 +107,7 @@ class User
|
|||
DBA::close($contacts);
|
||||
}
|
||||
|
||||
DBA::commit();
|
||||
DBA::commit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,7 +130,7 @@ class User
|
|||
$fields['rel'] = Contact::SELF;
|
||||
}
|
||||
|
||||
return DBStructure::getFieldsForTable('user-contact', $fields);
|
||||
return DI::dbaDefinition()->truncateFieldsForTable('user-contact', $fields);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,9 +139,10 @@ class User
|
|||
* @param int $cid Either public contact id or user's contact id
|
||||
* @param int $uid User ID
|
||||
* @param boolean $blocked Is the contact blocked or unblocked?
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function setBlocked($cid, $uid, $blocked)
|
||||
public static function setBlocked(int $cid, int $uid, bool $blocked)
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
|
||||
if (empty($cdata)) {
|
||||
|
@ -170,7 +172,7 @@ class User
|
|||
* @return boolean is the contact id blocked for the given user?
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function isBlocked($cid, $uid)
|
||||
public static function isBlocked(int $cid, int $uid): bool
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
|
||||
if (empty($cdata)) {
|
||||
|
@ -182,7 +184,7 @@ class User
|
|||
if (!empty($cdata['public'])) {
|
||||
$public_contact = DBA::selectFirst('user-contact', ['blocked'], ['cid' => $cdata['public'], 'uid' => $uid]);
|
||||
if (DBA::isResult($public_contact)) {
|
||||
$public_blocked = $public_contact['blocked'];
|
||||
$public_blocked = (bool) $public_contact['blocked'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,7 +193,7 @@ class User
|
|||
if (!empty($cdata['user'])) {
|
||||
$user_contact = DBA::selectFirst('contact', ['blocked'], ['id' => $cdata['user'], 'pending' => false]);
|
||||
if (DBA::isResult($user_contact)) {
|
||||
$user_blocked = $user_contact['blocked'];
|
||||
$user_blocked = (bool) $user_contact['blocked'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,9 +210,10 @@ class User
|
|||
* @param int $cid Either public contact id or user's contact id
|
||||
* @param int $uid User ID
|
||||
* @param boolean $ignored Is the contact ignored or unignored?
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function setIgnored($cid, $uid, $ignored)
|
||||
public static function setIgnored(int $cid, int $uid, bool $ignored)
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
|
||||
if (empty($cdata)) {
|
||||
|
@ -229,11 +232,10 @@ class User
|
|||
*
|
||||
* @param int $cid Either public contact id or user's contact id
|
||||
* @param int $uid User ID
|
||||
*
|
||||
* @return boolean is the contact id ignored for the given user?
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function isIgnored($cid, $uid)
|
||||
public static function isIgnored(int $cid, int $uid): bool
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
|
||||
if (empty($cdata)) {
|
||||
|
@ -245,7 +247,7 @@ class User
|
|||
if (!empty($cdata['public'])) {
|
||||
$public_contact = DBA::selectFirst('user-contact', ['ignored'], ['cid' => $cdata['public'], 'uid' => $uid]);
|
||||
if (DBA::isResult($public_contact)) {
|
||||
$public_ignored = $public_contact['ignored'];
|
||||
$public_ignored = (bool) $public_contact['ignored'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +256,7 @@ class User
|
|||
if (!empty($cdata['user'])) {
|
||||
$user_contact = DBA::selectFirst('contact', ['readonly'], ['id' => $cdata['user'], 'pending' => false]);
|
||||
if (DBA::isResult($user_contact)) {
|
||||
$user_ignored = $user_contact['readonly'];
|
||||
$user_ignored = (bool) $user_contact['readonly'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,9 +273,10 @@ class User
|
|||
* @param int $cid Either public contact id or user's contact id
|
||||
* @param int $uid User ID
|
||||
* @param boolean $collapsed are the contact's posts collapsed or uncollapsed?
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function setCollapsed($cid, $uid, $collapsed)
|
||||
public static function setCollapsed(int $cid, int $uid, bool $collapsed)
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
|
||||
if (empty($cdata)) {
|
||||
|
@ -288,16 +291,15 @@ class User
|
|||
*
|
||||
* @param int $cid Either public contact id or user's contact id
|
||||
* @param int $uid User ID
|
||||
*
|
||||
* @return boolean is the contact id blocked for the given user?
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function isCollapsed($cid, $uid)
|
||||
public static function isCollapsed(int $cid, int $uid): bool
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
|
||||
if (empty($cdata)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$collapsed = false;
|
||||
|
@ -305,7 +307,7 @@ class User
|
|||
if (!empty($cdata['public'])) {
|
||||
$public_contact = DBA::selectFirst('user-contact', ['collapsed'], ['cid' => $cdata['public'], 'uid' => $uid]);
|
||||
if (DBA::isResult($public_contact)) {
|
||||
$collapsed = $public_contact['collapsed'];
|
||||
$collapsed = (bool) $public_contact['collapsed'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -318,9 +320,10 @@ class User
|
|||
* @param int $cid Either public contact id or user's contact id
|
||||
* @param int $uid User ID
|
||||
* @param boolean $blocked Is the user blocked or unblocked by the contact?
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function setIsBlocked($cid, $uid, $blocked)
|
||||
public static function setIsBlocked(int $cid, int $uid, bool $blocked)
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
|
||||
if (empty($cdata)) {
|
||||
|
@ -335,11 +338,10 @@ class User
|
|||
*
|
||||
* @param int $cid Either public contact id or user's contact id
|
||||
* @param int $uid User ID
|
||||
*
|
||||
* @return boolean Is the user blocked or unblocked by the contact?
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function isIsBlocked($cid, $uid)
|
||||
public static function isIsBlocked(int $cid, int $uid): bool
|
||||
{
|
||||
$cdata = Contact::getPublicAndUserContactID($cid, $uid);
|
||||
if (empty($cdata)) {
|
||||
|
|
|
@ -62,7 +62,7 @@ class Conversation
|
|||
*/
|
||||
const RELAY = 3;
|
||||
|
||||
public static function getByItemUri($item_uri)
|
||||
public static function getByItemUri(string $item_uri)
|
||||
{
|
||||
return DBA::selectFirst('conversation', [], ['item-uri' => $item_uri]);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class Conversation
|
|||
* @return array Item array with removed conversation data
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function insert(array $arr)
|
||||
public static function insert(array $arr): array
|
||||
{
|
||||
if (in_array(($arr['network'] ?? '') ?: Protocol::PHANTOM,
|
||||
[Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::TWITTER]) && !empty($arr['uri'])) {
|
||||
|
|
|
@ -41,7 +41,7 @@ use Friendica\Util\XML;
|
|||
class Event
|
||||
{
|
||||
|
||||
public static function getHTML(array $event, $simple = false, $uriid = 0)
|
||||
public static function getHTML(array $event, bool $simple = false, int $uriid = 0): string
|
||||
{
|
||||
if (empty($event)) {
|
||||
return '';
|
||||
|
@ -127,7 +127,7 @@ class Event
|
|||
* @param array $event Array which contains the event data.
|
||||
* @return string The event as a bbcode formatted string.
|
||||
*/
|
||||
private static function getBBCode(array $event)
|
||||
private static function getBBCode(array $event): string
|
||||
{
|
||||
$o = '';
|
||||
|
||||
|
@ -157,11 +157,10 @@ class Event
|
|||
/**
|
||||
* Extract bbcode formatted event data from a string.
|
||||
*
|
||||
* @params: string $s The string which should be parsed for event data.
|
||||
* @param $text
|
||||
* @param string $text The string which should be parsed for event data.
|
||||
* @return array The array with the event information.
|
||||
*/
|
||||
public static function fromBBCode($text)
|
||||
public static function fromBBCode(string $text): array
|
||||
{
|
||||
$ev = [];
|
||||
|
||||
|
@ -195,13 +194,13 @@ class Event
|
|||
return $ev;
|
||||
}
|
||||
|
||||
public static function sortByDate($event_list)
|
||||
public static function sortByDate(array $event_list): array
|
||||
{
|
||||
usort($event_list, ['self', 'compareDatesCallback']);
|
||||
return $event_list;
|
||||
}
|
||||
|
||||
private static function compareDatesCallback($event_a, $event_b)
|
||||
private static function compareDatesCallback(array $event_a, array $event_b)
|
||||
{
|
||||
$date_a = DateTimeFormat::local($event_a['start']);
|
||||
$date_b = DateTimeFormat::local($event_b['start']);
|
||||
|
@ -223,7 +222,7 @@ class Event
|
|||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function delete($event_id)
|
||||
public static function delete(int $event_id)
|
||||
{
|
||||
if ($event_id == 0) {
|
||||
return;
|
||||
|
@ -242,14 +241,14 @@ class Event
|
|||
* @return int The new event id.
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function store($arr)
|
||||
public static function store(array $arr): int
|
||||
{
|
||||
$event = [];
|
||||
$event['id'] = intval($arr['id'] ?? 0);
|
||||
$event['uid'] = intval($arr['uid'] ?? 0);
|
||||
$event['cid'] = intval($arr['cid'] ?? 0);
|
||||
$event['guid'] = ($arr['guid'] ?? '') ?: System::createUUID();
|
||||
$event['uri'] = ($arr['uri'] ?? '') ?: Item::newURI($event['uid'], $event['guid']);
|
||||
$event['uri'] = ($arr['uri'] ?? '') ?: Item::newURI($event['guid']);
|
||||
$event['uri-id'] = ItemURI::insert(['uri' => $event['uri'], 'guid' => $event['guid']]);
|
||||
$event['type'] = ($arr['type'] ?? '') ?: 'event';
|
||||
$event['summary'] = $arr['summary'] ?? '';
|
||||
|
@ -317,7 +316,7 @@ class Event
|
|||
return $event['id'];
|
||||
}
|
||||
|
||||
public static function getItemArrayForId(int $event_id, array $item = []):array
|
||||
public static function getItemArrayForId(int $event_id, array $item = []): array
|
||||
{
|
||||
if (empty($event_id)) {
|
||||
return $item;
|
||||
|
@ -374,7 +373,7 @@ class Event
|
|||
return $item;
|
||||
}
|
||||
|
||||
public static function getItemArrayForImportedId(int $event_id, array $item = []):array
|
||||
public static function getItemArrayForImportedId(int $event_id, array $item = []): array
|
||||
{
|
||||
if (empty($event_id)) {
|
||||
return $item;
|
||||
|
@ -404,7 +403,7 @@ class Event
|
|||
* @return array Array with translations strings.
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function getStrings()
|
||||
public static function getStrings(): array
|
||||
{
|
||||
// First day of the week (0 = Sunday).
|
||||
$firstDay = DI::pConfig()->get(local_user(), 'system', 'first_day_of_week', 0);
|
||||
|
@ -477,7 +476,7 @@ class Event
|
|||
*
|
||||
* @todo We should replace this with a separate update function if there is some time left.
|
||||
*/
|
||||
private static function removeDuplicates(array $dates)
|
||||
private static function removeDuplicates(array $dates): array
|
||||
{
|
||||
$dates2 = [];
|
||||
|
||||
|
@ -500,7 +499,7 @@ class Event
|
|||
* @return array Query result
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getListById($owner_uid, $event_id, $sql_extra = '')
|
||||
public static function getListById(int $owner_uid, int $event_id, string $sql_extra = ''): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
|
@ -536,7 +535,7 @@ class Event
|
|||
* @return array Query results.
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getListByDate($owner_uid, $event_params, $sql_extra = '')
|
||||
public static function getListByDate(int $owner_uid, array $event_params, string $sql_extra = ''): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
|
@ -570,7 +569,7 @@ class Event
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function prepareListForTemplate(array $event_result)
|
||||
public static function prepareListForTemplate(array $event_result): array
|
||||
{
|
||||
$event_list = [];
|
||||
|
||||
|
@ -651,12 +650,12 @@ class Event
|
|||
* @param array $events Query result for events.
|
||||
* @param string $format The output format (ical/csv).
|
||||
*
|
||||
* @param $timezone
|
||||
* @param string $timezone Timezone (missing parameter!)
|
||||
* @return string Content according to selected export format.
|
||||
*
|
||||
* @todo Implement timezone support
|
||||
*/
|
||||
private static function formatListForExport(array $events, $format)
|
||||
private static function formatListForExport(array $events, string $format): string
|
||||
{
|
||||
$o = '';
|
||||
|
||||
|
@ -757,7 +756,7 @@ class Event
|
|||
* @return array Query results.
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function getListByUserId($uid = 0)
|
||||
private static function getListByUserId(int $uid = 0): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
|
@ -797,7 +796,7 @@ class Event
|
|||
* @throws \Exception
|
||||
* @todo Respect authenticated users with events_by_uid().
|
||||
*/
|
||||
public static function exportListByUserId($uid, $format = 'ical')
|
||||
public static function exportListByUserId(int $uid, string $format = 'ical'): array
|
||||
{
|
||||
$process = false;
|
||||
|
||||
|
@ -845,7 +844,8 @@ class Event
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function getItemHTML(array $item) {
|
||||
public static function getItemHTML(array $item): string
|
||||
{
|
||||
$same_date = false;
|
||||
$finish = false;
|
||||
|
||||
|
@ -933,10 +933,11 @@ class Event
|
|||
* @return array The array with the location data.
|
||||
* 'name' => The name of the location,<br>
|
||||
* 'address' => The address of the location,<br>
|
||||
* 'coordinates' => Latitude and longitude (e.g. '48.864716,2.349014').<br>
|
||||
* 'coordinates' => Latitude and longitude (e.g. '48.864716,2.349014').<br>
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function locationToArray($s = '') {
|
||||
private static function locationToArray(string $s = ''): array
|
||||
{
|
||||
if ($s == '') {
|
||||
return [];
|
||||
}
|
||||
|
@ -981,7 +982,7 @@ class Event
|
|||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createBirthday($contact, $birthday)
|
||||
public static function createBirthday(array $contact, string $birthday): bool
|
||||
{
|
||||
// Check for duplicates
|
||||
$condition = [
|
||||
|
@ -1011,8 +1012,7 @@ class Event
|
|||
'type' => 'birthday',
|
||||
];
|
||||
|
||||
self::store($values);
|
||||
|
||||
return true;
|
||||
// Check if self::store() was success
|
||||
return (self::store($values) > 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class FContact
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function getByURL($handle, $update = null)
|
||||
public static function getByURL(string $handle, $update = null): array
|
||||
{
|
||||
$person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'addr' => $handle]);
|
||||
if (!DBA::isResult($person)) {
|
||||
|
@ -90,7 +90,7 @@ class FContact
|
|||
* @param array $arr The fcontact data
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updateFromProbeArray($arr)
|
||||
public static function updateFromProbeArray(array $arr)
|
||||
{
|
||||
$uriid = ItemURI::insert(['uri' => $arr['url'], 'guid' => $arr['guid']]);
|
||||
|
||||
|
@ -103,17 +103,27 @@ class FContact
|
|||
$posts = Post::countPosts(['author-id' => $contact['id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]]);
|
||||
}
|
||||
|
||||
$fields = ['name' => $arr["name"], 'photo' => $arr["photo"],
|
||||
'request' => $arr["request"], 'nick' => $arr["nick"],
|
||||
'addr' => strtolower($arr["addr"]), 'guid' => $arr["guid"],
|
||||
'batch' => $arr["batch"], 'notify' => $arr["notify"],
|
||||
'poll' => $arr["poll"], 'confirm' => $arr["confirm"],
|
||||
'alias' => $arr["alias"], 'pubkey' => $arr["pubkey"],
|
||||
'uri-id' => $uriid, 'interacting_count' => $interacting ?? 0,
|
||||
'interacted_count' => $interacted ?? 0, 'post_count' => $posts ?? 0,
|
||||
'updated' => DateTimeFormat::utcNow()];
|
||||
$fields = [
|
||||
'name' => $arr['name'],
|
||||
'photo' => $arr['photo'],
|
||||
'request' => $arr['request'],
|
||||
'nick' => $arr['nick'],
|
||||
'addr' => strtolower($arr['addr']),
|
||||
'guid' => $arr['guid'],
|
||||
'batch' => $arr['batch'],
|
||||
'notify' => $arr['notify'],
|
||||
'poll' => $arr['poll'],
|
||||
'confirm' => $arr['confirm'],
|
||||
'alias' => $arr['alias'],
|
||||
'pubkey' => $arr['pubkey'],
|
||||
'uri-id' => $uriid,
|
||||
'interacting_count' => $interacting ?? 0,
|
||||
'interacted_count' => $interacted ?? 0,
|
||||
'post_count' => $posts ?? 0,
|
||||
'updated' => DateTimeFormat::utcNow(),
|
||||
];
|
||||
|
||||
$condition = ['url' => $arr["url"], 'network' => $arr["network"]];
|
||||
$condition = ['url' => $arr['url'], 'network' => $arr['network']];
|
||||
|
||||
DBA::update('fcontact', $fields, $condition, true);
|
||||
}
|
||||
|
@ -122,12 +132,11 @@ class FContact
|
|||
* get a url (scheme://domain.tld/u/user) from a given Diaspora*
|
||||
* fcontact guid
|
||||
*
|
||||
* @param mixed $fcontact_guid Hexadecimal string guid
|
||||
*
|
||||
* @return string the contact url or null
|
||||
* @param string $fcontact_guid Hexadecimal string guid
|
||||
* @return string|null the contact url or null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getUrlByGuid($fcontact_guid)
|
||||
public static function getUrlByGuid(string $fcontact_guid)
|
||||
{
|
||||
Logger::info('fcontact', ['guid' => $fcontact_guid]);
|
||||
|
||||
|
|
|
@ -35,10 +35,9 @@ class FileTag
|
|||
* URL encode <, >, left and right brackets
|
||||
*
|
||||
* @param string $s String to be URL encoded.
|
||||
*
|
||||
* @return string The URL encoded string.
|
||||
*/
|
||||
private static function encode($s)
|
||||
private static function encode(string $s): string
|
||||
{
|
||||
return str_replace(['<', '>', '[', ']'], ['%3c', '%3e', '%5b', '%5d'], $s);
|
||||
}
|
||||
|
@ -47,10 +46,9 @@ class FileTag
|
|||
* URL decode <, >, left and right brackets
|
||||
*
|
||||
* @param string $s The URL encoded string to be decoded
|
||||
*
|
||||
* @return string The decoded string.
|
||||
*/
|
||||
private static function decode($s)
|
||||
private static function decode(string $s): string
|
||||
{
|
||||
return str_replace(['%3c', '%3e', '%5b', '%5d'], ['<', '>', '[', ']'], $s);
|
||||
}
|
||||
|
@ -62,10 +60,9 @@ class FileTag
|
|||
*
|
||||
* @param array $array A list of tags.
|
||||
* @param string $type Optional file type.
|
||||
*
|
||||
* @return string A list of file tags.
|
||||
*/
|
||||
public static function arrayToFile(array $array, string $type = 'file')
|
||||
public static function arrayToFile(array $array, string $type = 'file'): string
|
||||
{
|
||||
$tag_list = '';
|
||||
if ($type == 'file') {
|
||||
|
@ -92,10 +89,9 @@ class FileTag
|
|||
*
|
||||
* @param string $file File tags
|
||||
* @param string $type Optional file type.
|
||||
*
|
||||
* @return array List of tag names.
|
||||
*/
|
||||
public static function fileToArray(string $file, string $type = 'file')
|
||||
public static function fileToArray(string $file, string $type = 'file'): array
|
||||
{
|
||||
$matches = [];
|
||||
$return = [];
|
||||
|
|
|
@ -30,7 +30,6 @@ use Friendica\Core\System;
|
|||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\Register;
|
||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
||||
|
@ -110,7 +109,7 @@ class GServer
|
|||
*
|
||||
* @param string $url
|
||||
* @param boolean $no_check Don't check if the server hadn't been found
|
||||
* @return int gserver id
|
||||
* @return int|null gserver id or NULL on empty URL or failed check
|
||||
*/
|
||||
public static function getID(string $url, bool $no_check = false)
|
||||
{
|
||||
|
@ -170,7 +169,7 @@ class GServer
|
|||
*
|
||||
* @return boolean 'true' if server seems vital
|
||||
*/
|
||||
public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false)
|
||||
public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false): bool
|
||||
{
|
||||
if ($server == '') {
|
||||
$contact = Contact::getByURL($profile, null, ['baseurl']);
|
||||
|
@ -246,7 +245,7 @@ class GServer
|
|||
*
|
||||
* @return boolean 'true' if server seems vital
|
||||
*/
|
||||
public static function check(string $server_url, string $network = '', bool $force = false, bool $only_nodeinfo = false)
|
||||
public static function check(string $server_url, string $network = '', bool $force = false, bool $only_nodeinfo = false): bool
|
||||
{
|
||||
$server_url = self::cleanURL($server_url);
|
||||
if ($server_url == '') {
|
||||
|
@ -258,7 +257,7 @@ class GServer
|
|||
if ($gserver['created'] <= DBA::NULL_DATETIME) {
|
||||
$fields = ['created' => DateTimeFormat::utcNow()];
|
||||
$condition = ['nurl' => Strings::normaliseLink($server_url)];
|
||||
DBA::update('gserver', $fields, $condition);
|
||||
self::update($fields, $condition);
|
||||
}
|
||||
|
||||
if (!$force && (strtotime($gserver['next_contact']) > time())) {
|
||||
|
@ -283,7 +282,7 @@ class GServer
|
|||
$gserver = DBA::selectFirst('gserver', [], ['nurl' => Strings::normaliseLink($url)]);
|
||||
if (DBA::isResult($gserver)) {
|
||||
$next_update = self::getNextUpdateDate(false, $gserver['created'], $gserver['last_contact']);
|
||||
DBA::update('gserver', ['url' => $url, 'failed' => true, 'last_failure' => DateTimeFormat::utcNow(),
|
||||
self::update(['url' => $url, 'failed' => true, 'last_failure' => DateTimeFormat::utcNow(),
|
||||
'next_contact' => $next_update, 'network' => Protocol::PHANTOM, 'detection-method' => null],
|
||||
['nurl' => Strings::normaliseLink($url)]);
|
||||
Logger::info('Set failed status for existing server', ['url' => $url]);
|
||||
|
@ -301,7 +300,7 @@ class GServer
|
|||
* @param string $url
|
||||
* @return string cleaned URL
|
||||
*/
|
||||
public static function cleanURL(string $url)
|
||||
public static function cleanURL(string $url): string
|
||||
{
|
||||
$url = trim($url, '/');
|
||||
$url = str_replace('/index.php', '', $url);
|
||||
|
@ -324,7 +323,7 @@ class GServer
|
|||
*
|
||||
* @return boolean 'true' if server could be detected
|
||||
*/
|
||||
public static function detect(string $url, string $network = '', bool $only_nodeinfo = false)
|
||||
public static function detect(string $url, string $network = '', bool $only_nodeinfo = false): bool
|
||||
{
|
||||
Logger::info('Detect server type', ['server' => $url]);
|
||||
|
||||
|
@ -559,16 +558,13 @@ class GServer
|
|||
$serverdata['last_contact'] = DateTimeFormat::utcNow();
|
||||
$serverdata['failed'] = false;
|
||||
|
||||
// Limit the length on incoming fields
|
||||
$serverdata = DBStructure::getFieldsForTable('gserver', $serverdata);
|
||||
|
||||
$gserver = DBA::selectFirst('gserver', ['network'], ['nurl' => Strings::normaliseLink($url)]);
|
||||
if (!DBA::isResult($gserver)) {
|
||||
$serverdata['created'] = DateTimeFormat::utcNow();
|
||||
$ret = DBA::insert('gserver', $serverdata);
|
||||
$id = DBA::lastInsertId();
|
||||
} else {
|
||||
$ret = DBA::update('gserver', $serverdata, ['nurl' => $serverdata['nurl']]);
|
||||
$ret = self::update($serverdata, ['nurl' => $serverdata['nurl']]);
|
||||
$gserver = DBA::selectFirst('gserver', ['id'], ['nurl' => $serverdata['nurl']]);
|
||||
if (DBA::isResult($gserver)) {
|
||||
$id = $gserver['id'];
|
||||
|
@ -582,14 +578,14 @@ class GServer
|
|||
$max_users = max($apcontacts, $contacts);
|
||||
if ($max_users > $serverdata['registered-users']) {
|
||||
Logger::info('Update registered users', ['id' => $id, 'url' => $serverdata['nurl'], 'registered-users' => $max_users]);
|
||||
DBA::update('gserver', ['registered-users' => $max_users], ['id' => $id]);
|
||||
self::update(['registered-users' => $max_users], ['id' => $id]);
|
||||
}
|
||||
|
||||
if (empty($serverdata['active-month-users'])) {
|
||||
$contacts = DBA::count('contact', ["`uid` = ? AND `gsid` = ? AND NOT `failed` AND `last-item` > ?", 0, $id, DateTimeFormat::utc('now - 30 days')]);
|
||||
if ($contacts > 0) {
|
||||
Logger::info('Update monthly users', ['id' => $id, 'url' => $serverdata['nurl'], 'monthly-users' => $contacts]);
|
||||
DBA::update('gserver', ['active-month-users' => $contacts], ['id' => $id]);
|
||||
self::update(['active-month-users' => $contacts], ['id' => $id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -597,7 +593,7 @@ class GServer
|
|||
$contacts = DBA::count('contact', ["`uid` = ? AND `gsid` = ? AND NOT `failed` AND `last-item` > ?", 0, $id, DateTimeFormat::utc('now - 180 days')]);
|
||||
if ($contacts > 0) {
|
||||
Logger::info('Update halfyear users', ['id' => $id, 'url' => $serverdata['nurl'], 'halfyear-users' => $contacts]);
|
||||
DBA::update('gserver', ['active-halfyear-users' => $contacts], ['id' => $id]);
|
||||
self::update(['active-halfyear-users' => $contacts], ['id' => $id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -618,6 +614,7 @@ class GServer
|
|||
* Fetch relay data from a given server url
|
||||
*
|
||||
* @param string $server_url address of the server
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function discoverRelay(string $server_url)
|
||||
|
@ -650,7 +647,7 @@ class GServer
|
|||
|
||||
if (($gserver['relay-subscribe'] != $data['subscribe']) || ($gserver['relay-scope'] != $data['scope'])) {
|
||||
$fields = ['relay-subscribe' => $data['subscribe'], 'relay-scope' => $data['scope']];
|
||||
DBA::update('gserver', $fields, ['id' => $gserver['id']]);
|
||||
self::update($fields, ['id' => $gserver['id']]);
|
||||
}
|
||||
|
||||
DBA::delete('gserver-tag', ['gserver-id' => $gserver['id']]);
|
||||
|
@ -714,7 +711,6 @@ class GServer
|
|||
* Fetch server data from '/statistics.json' on the given server
|
||||
*
|
||||
* @param string $url URL of the given server
|
||||
*
|
||||
* @return array server data
|
||||
*/
|
||||
private static function fetchStatistics(string $url, array $serverdata)
|
||||
|
@ -809,7 +805,7 @@ class GServer
|
|||
* @return array Server data
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function fetchNodeinfo(string $url, ICanHandleHttpResponses $httpResult)
|
||||
private static function fetchNodeinfo(string $url, ICanHandleHttpResponses $httpResult): array
|
||||
{
|
||||
if (!$httpResult->isSuccess()) {
|
||||
return [];
|
||||
|
@ -860,7 +856,7 @@ class GServer
|
|||
* @return array Server data
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function parseNodeinfo1(string $nodeinfo_url)
|
||||
private static function parseNodeinfo1(string $nodeinfo_url): array
|
||||
{
|
||||
$curlResult = DI::httpClient()->get($nodeinfo_url, HttpClientAccept::JSON);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
|
@ -957,7 +953,7 @@ class GServer
|
|||
* @return array Server data
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function parseNodeinfo2(string $nodeinfo_url)
|
||||
private static function parseNodeinfo2(string $nodeinfo_url): array
|
||||
{
|
||||
$curlResult = DI::httpClient()->get($nodeinfo_url, HttpClientAccept::JSON);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
|
@ -969,8 +965,11 @@ class GServer
|
|||
return [];
|
||||
}
|
||||
|
||||
$server = ['detection-method' => self::DETECT_NODEINFO_2,
|
||||
'register_policy' => Register::CLOSED];
|
||||
$server = [
|
||||
'detection-method' => self::DETECT_NODEINFO_2,
|
||||
'register_policy' => Register::CLOSED,
|
||||
'platform' => 'unknown',
|
||||
];
|
||||
|
||||
if (!empty($nodeinfo['openRegistrations'])) {
|
||||
$server['register_policy'] = Register::OPEN;
|
||||
|
@ -1155,10 +1154,9 @@ class GServer
|
|||
*
|
||||
* @param string $url URL of the given server
|
||||
* @param array $serverdata array with server data
|
||||
*
|
||||
* @return array server data
|
||||
*/
|
||||
private static function fetchSiteinfo(string $url, array $serverdata)
|
||||
private static function fetchSiteinfo(string $url, array $serverdata): array
|
||||
{
|
||||
$curlResult = DI::httpClient()->get($url . '/siteinfo.json', HttpClientAccept::JSON);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
|
@ -1276,10 +1274,9 @@ class GServer
|
|||
* Checks if the server contains a valid host meta file
|
||||
*
|
||||
* @param string $url URL of the given server
|
||||
*
|
||||
* @return boolean 'true' if the server seems to be vital
|
||||
*/
|
||||
private static function validHostMeta(string $url)
|
||||
private static function validHostMeta(string $url): bool
|
||||
{
|
||||
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
|
||||
$curlResult = DI::httpClient()->get($url . '/.well-known/host-meta', HttpClientAccept::XRD_XML, [HttpClientOptions::TIMEOUT => $xrd_timeout]);
|
||||
|
@ -1322,10 +1319,9 @@ class GServer
|
|||
*
|
||||
* @param string $url URL of the given server
|
||||
* @param array $serverdata array with server data
|
||||
*
|
||||
* @return array server data
|
||||
*/
|
||||
private static function detectNetworkViaContacts(string $url, array $serverdata)
|
||||
private static function detectNetworkViaContacts(string $url, array $serverdata): array
|
||||
{
|
||||
$contacts = [];
|
||||
|
||||
|
@ -1374,10 +1370,9 @@ class GServer
|
|||
*
|
||||
* @param string $url URL of the given server
|
||||
* @param array $serverdata array with server data
|
||||
*
|
||||
* @return array server data
|
||||
*/
|
||||
private static function checkPoCo(string $url, array $serverdata)
|
||||
private static function checkPoCo(string $url, array $serverdata): array
|
||||
{
|
||||
$serverdata['poco'] = '';
|
||||
|
||||
|
@ -1406,10 +1401,9 @@ class GServer
|
|||
*
|
||||
* @param string $url URL of the given server
|
||||
* @param array $serverdata array with server data
|
||||
*
|
||||
* @return array server data
|
||||
*/
|
||||
public static function checkMastodonDirectory(string $url, array $serverdata)
|
||||
public static function checkMastodonDirectory(string $url, array $serverdata): array
|
||||
{
|
||||
$curlResult = DI::httpClient()->get($url . '/api/v1/directory?limit=1', HttpClientAccept::JSON);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
|
@ -1436,7 +1430,7 @@ class GServer
|
|||
*
|
||||
* @return array server data
|
||||
*/
|
||||
private static function detectPeertube(string $url, array $serverdata)
|
||||
private static function detectPeertube(string $url, array $serverdata): array
|
||||
{
|
||||
$curlResult = DI::httpClient()->get($url . '/api/v1/config', HttpClientAccept::JSON);
|
||||
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
|
||||
|
@ -1512,7 +1506,15 @@ class GServer
|
|||
return $serverdata;
|
||||
}
|
||||
|
||||
private static function fetchWeeklyUsage(string $url, array $serverdata) {
|
||||
/**
|
||||
* Fetches weekly usage data
|
||||
*
|
||||
* @param string $url URL of the given server
|
||||
* @param array $serverdata array with server data
|
||||
* @return array server data
|
||||
*/
|
||||
private static function fetchWeeklyUsage(string $url, array $serverdata): array
|
||||
{
|
||||
$curlResult = DI::httpClient()->get($url . '/api/v1/instance/activity', HttpClientAccept::JSON);
|
||||
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
|
||||
return $serverdata;
|
||||
|
@ -1548,10 +1550,9 @@ class GServer
|
|||
*
|
||||
* @param string $url URL of the given server
|
||||
* @param array $serverdata array with server data
|
||||
*
|
||||
* @return array server data
|
||||
*/
|
||||
private static function detectMastodonAlikes(string $url, array $serverdata)
|
||||
private static function detectMastodonAlikes(string $url, array $serverdata): array
|
||||
{
|
||||
$curlResult = DI::httpClient()->get($url . '/api/v1/instance', HttpClientAccept::JSON);
|
||||
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
|
||||
|
@ -1620,10 +1621,9 @@ class GServer
|
|||
*
|
||||
* @param string $url URL of the given server
|
||||
* @param array $serverdata array with server data
|
||||
*
|
||||
* @return array server data
|
||||
*/
|
||||
private static function detectHubzilla(string $url, array $serverdata)
|
||||
private static function detectHubzilla(string $url, array $serverdata): array
|
||||
{
|
||||
$curlResult = DI::httpClient()->get($url . '/api/statusnet/config.json', HttpClientAccept::JSON);
|
||||
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
|
||||
|
@ -1697,10 +1697,9 @@ class GServer
|
|||
* Converts input value to a boolean value
|
||||
*
|
||||
* @param string|integer $val
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private static function toBoolean($val)
|
||||
private static function toBoolean($val): bool
|
||||
{
|
||||
if (($val == 'true') || ($val == 1)) {
|
||||
return true;
|
||||
|
@ -1716,10 +1715,9 @@ class GServer
|
|||
*
|
||||
* @param string $url URL of the given server
|
||||
* @param array $serverdata array with server data
|
||||
*
|
||||
* @return array server data
|
||||
*/
|
||||
private static function detectGNUSocial(string $url, array $serverdata)
|
||||
private static function detectGNUSocial(string $url, array $serverdata): array
|
||||
{
|
||||
// Test for GNU Social
|
||||
$curlResult = DI::httpClient()->get($url . '/api/gnusocial/version.json', HttpClientAccept::JSON);
|
||||
|
@ -1771,10 +1769,9 @@ class GServer
|
|||
*
|
||||
* @param string $url URL of the given server
|
||||
* @param array $serverdata array with server data
|
||||
*
|
||||
* @return array server data
|
||||
*/
|
||||
private static function detectFriendica(string $url, array $serverdata)
|
||||
private static function detectFriendica(string $url, array $serverdata): array
|
||||
{
|
||||
// There is a bug in some versions of Friendica that will return an ActivityStream actor when the content type "application/json" is requested.
|
||||
// Because of this me must not use ACCEPT_JSON here.
|
||||
|
@ -1849,7 +1846,7 @@ class GServer
|
|||
*
|
||||
* @return array server data
|
||||
*/
|
||||
private static function analyseRootBody($curlResult, array $serverdata)
|
||||
private static function analyseRootBody($curlResult, array $serverdata): array
|
||||
{
|
||||
if (empty($curlResult->getBody())) {
|
||||
return $serverdata;
|
||||
|
@ -2008,7 +2005,7 @@ class GServer
|
|||
*
|
||||
* @return array server data
|
||||
*/
|
||||
private static function analyseRootHeader($curlResult, array $serverdata)
|
||||
private static function analyseRootHeader($curlResult, array $serverdata): array
|
||||
{
|
||||
if ($curlResult->getHeader('server') == 'Mastodon') {
|
||||
$serverdata['platform'] = 'mastodon';
|
||||
|
@ -2062,7 +2059,7 @@ class GServer
|
|||
Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', $gserver);
|
||||
|
||||
$fields = ['last_poco_query' => DateTimeFormat::utcNow()];
|
||||
DBA::update('gserver', $fields, ['nurl' => $gserver['nurl']]);
|
||||
self::update($fields, ['nurl' => $gserver['nurl']]);
|
||||
|
||||
if (--$no_of_queries == 0) {
|
||||
break;
|
||||
|
@ -2180,17 +2177,17 @@ class GServer
|
|||
}
|
||||
|
||||
Logger::info('Protocol for server', ['protocol' => $protocol, 'old' => $old, 'id' => $gsid, 'url' => $gserver['url'], 'callstack' => System::callstack(20)]);
|
||||
DBA::update('gserver', ['protocol' => $protocol], ['id' => $gsid]);
|
||||
self::update(['protocol' => $protocol], ['id' => $gsid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the protocol of the given server
|
||||
*
|
||||
* @param int $gsid Server id
|
||||
* @return int
|
||||
* @return ?int One of Post\DeliveryData protocol constants or null if unknown or gserver is missing
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getProtocol(int $gsid)
|
||||
public static function getProtocol(int $gsid): ?int
|
||||
{
|
||||
if (empty($gsid)) {
|
||||
return null;
|
||||
|
@ -2203,4 +2200,19 @@ class GServer
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforces gserver table field maximum sizes to avoid "Data too long" database errors
|
||||
*
|
||||
* @param array $fields
|
||||
* @param array $condition
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function update(array $fields, array $condition): bool
|
||||
{
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('gserver', $fields);
|
||||
|
||||
return DBA::update('gserver', $fields, $condition);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,14 @@ class Group
|
|||
const FOLLOWERS = '~';
|
||||
const MUTUALS = '&';
|
||||
|
||||
public static function getByUserId($uid, $includesDeleted = false)
|
||||
/**
|
||||
* Fetches group record by user id and maybe includes deleted groups as well
|
||||
*
|
||||
* @param int $uid User id to fetch group(s) for
|
||||
* @param bool $includesDeleted Whether deleted groups should be included
|
||||
* @return array|bool Array on success, bool on error
|
||||
*/
|
||||
public static function getByUserId(int $uid, bool $includesDeleted = false)
|
||||
{
|
||||
$conditions = ['uid' => $uid, 'cid' => null];
|
||||
|
||||
|
@ -51,15 +58,18 @@ class Group
|
|||
}
|
||||
|
||||
/**
|
||||
* @param int $group_id
|
||||
* Checks whether given group id is found in database
|
||||
*
|
||||
* @param int $group_id Groupd it
|
||||
* @param int $uid Optional user id
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function exists($group_id, $uid = null)
|
||||
public static function exists(int $group_id, int $uid = null): bool
|
||||
{
|
||||
$condition = ['id' => $group_id, 'deleted' => false];
|
||||
|
||||
if (isset($uid)) {
|
||||
if (!is_null($uid)) {
|
||||
$condition = [
|
||||
'uid' => $uid
|
||||
];
|
||||
|
@ -73,12 +83,12 @@ class Group
|
|||
*
|
||||
* Note: If we found a deleted group with the same name, we restore it
|
||||
*
|
||||
* @param int $uid
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
* @param int $uid User id to create group for
|
||||
* @param string $name Name of group
|
||||
* @return int|boolean Id of newly created group or false on error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function create($uid, $name)
|
||||
public static function create(int $uid, string $name)
|
||||
{
|
||||
$return = false;
|
||||
if (!empty($uid) && !empty($name)) {
|
||||
|
@ -114,7 +124,7 @@ class Group
|
|||
* @return bool Was the update successful?
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function update($id, $name)
|
||||
public static function update(int $id, string $name): bool
|
||||
{
|
||||
return DBA::update('group', ['name' => $name], ['id' => $id]);
|
||||
}
|
||||
|
@ -122,11 +132,11 @@ class Group
|
|||
/**
|
||||
* Get a list of group ids a contact belongs to
|
||||
*
|
||||
* @param int $cid
|
||||
* @return array
|
||||
* @param int $cid Contact id
|
||||
* @return array Group ids
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getIdsByContactId($cid)
|
||||
public static function getIdsByContactId(int $cid): array
|
||||
{
|
||||
$return = [];
|
||||
|
||||
|
@ -185,12 +195,12 @@ class Group
|
|||
*
|
||||
* Returns false if no group has been found.
|
||||
*
|
||||
* @param int $uid
|
||||
* @param string $name
|
||||
* @return int|boolean
|
||||
* @param int $uid User id
|
||||
* @param string $name Group name
|
||||
* @return int|boolean Groups' id number or false on error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getIdByName($uid, $name)
|
||||
public static function getIdByName(int $uid, string $name)
|
||||
{
|
||||
if (!$uid || !strlen($name)) {
|
||||
return false;
|
||||
|
@ -211,7 +221,7 @@ class Group
|
|||
* @return boolean
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function remove($gid)
|
||||
public static function remove(int $gid): bool
|
||||
{
|
||||
if (!$gid) {
|
||||
return false;
|
||||
|
@ -314,13 +324,14 @@ class Group
|
|||
* Adds contacts to a group
|
||||
*
|
||||
* @param int $gid
|
||||
* @param array $contacts
|
||||
* @param array $contacts Array with contact ids
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function addMembers(int $gid, array $contacts)
|
||||
{
|
||||
if (!$gid || !$contacts) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
// @TODO Backward compatibility with user contacts, remove by version 2022.03
|
||||
|
@ -342,8 +353,9 @@ class Group
|
|||
/**
|
||||
* Removes contacts from a group
|
||||
*
|
||||
* @param int $gid
|
||||
* @param array $contacts
|
||||
* @param int $gid Group id
|
||||
* @param array $contacts Contact ids
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function removeMembers(int $gid, array $contacts)
|
||||
|
@ -369,19 +381,20 @@ class Group
|
|||
$contactIds[] = $cdata['user'];
|
||||
}
|
||||
|
||||
DBA::delete('group_member', ['gid' => $gid, 'contact-id' => $contactIds]);
|
||||
// Return status of deletion
|
||||
return DBA::delete('group_member', ['gid' => $gid, 'contact-id' => $contactIds]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the combined list of contact ids from a group id list
|
||||
*
|
||||
* @param int $uid
|
||||
* @param array $group_ids
|
||||
* @param boolean $check_dead
|
||||
* @param int $uid User id
|
||||
* @param array $group_ids Groups ids
|
||||
* @param boolean $check_dead Whether check "dead" records (?)
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function expand($uid, array $group_ids, $check_dead = false)
|
||||
public static function expand(int $uid, array $group_ids, bool $check_dead = false): array
|
||||
{
|
||||
if (!is_array($group_ids) || !count($group_ids)) {
|
||||
return [];
|
||||
|
@ -454,13 +467,13 @@ class Group
|
|||
/**
|
||||
* Returns a templated group selection list
|
||||
*
|
||||
* @param int $uid
|
||||
* @param int $uid User id
|
||||
* @param int $gid An optional pre-selected group
|
||||
* @param string $label An optional label of the list
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function displayGroupSelection($uid, $gid = 0, $label = '')
|
||||
public static function displayGroupSelection(int $uid, int $gid = 0, string $label = ''): string
|
||||
{
|
||||
$display_groups = [
|
||||
[
|
||||
|
@ -502,12 +515,12 @@ class Group
|
|||
* 'standard' => include link 'Edit groups'
|
||||
* 'extended' => include link 'Create new group'
|
||||
* 'full' => include link 'Create new group' and provide for each group a link to edit this group
|
||||
* @param string $group_id
|
||||
* @param int $cid
|
||||
* @return string
|
||||
* @param string|int $group_id Distinct group id or 'everyone'
|
||||
* @param int $cid Contact id
|
||||
* @return string Sidebar widget HTML code
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function sidebarWidget($every = 'contact', $each = 'group', $editmode = 'standard', $group_id = '', $cid = 0)
|
||||
public static function sidebarWidget(string $every = 'contact', string $each = 'group', string $editmode = 'standard', $group_id = '', int $cid = 0)
|
||||
{
|
||||
if (!local_user()) {
|
||||
return '';
|
||||
|
@ -589,7 +602,7 @@ class Group
|
|||
* @param integer $id Contact ID
|
||||
* @return integer Group IO
|
||||
*/
|
||||
public static function getIdForForum(int $id)
|
||||
public static function getIdForForum(int $id): int
|
||||
{
|
||||
Logger::info('Get id for forum id', ['id' => $id]);
|
||||
$contact = Contact::getById($id, ['uid', 'name', 'contact-type', 'manually-approve']);
|
||||
|
@ -617,6 +630,7 @@ class Group
|
|||
* Fetch the followers of a given contact id and store them as group members
|
||||
*
|
||||
* @param integer $id Contact ID
|
||||
* @return void
|
||||
*/
|
||||
public static function updateMembersForForum(int $id)
|
||||
{
|
||||
|
|
|
@ -96,8 +96,8 @@ class Item
|
|||
'event-created', 'event-edited', 'event-start', 'event-finish',
|
||||
'event-summary', 'event-desc', 'event-location', 'event-type',
|
||||
'event-nofinish', 'event-ignore', 'event-id',
|
||||
"question-id", "question-multiple", "question-voters", "question-end-time",
|
||||
"has-categories", "has-media",
|
||||
'question-id', 'question-multiple', 'question-voters', 'question-end-time',
|
||||
'has-categories', 'has-media',
|
||||
'delivery_queue_count', 'delivery_queue_done', 'delivery_queue_failed'
|
||||
];
|
||||
|
||||
|
@ -226,7 +226,7 @@ class Item
|
|||
|
||||
foreach ($notify_items as $notify_item) {
|
||||
$post = Post::selectFirst(['uri-id', 'uid'], ['id' => $notify_item]);
|
||||
Worker::add(PRIORITY_HIGH, "Notifier", Delivery::POST, (int)$post['uri-id'], (int)$post['uid']);
|
||||
Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::POST, (int)$post['uri-id'], (int)$post['uid']);
|
||||
}
|
||||
|
||||
return $rows;
|
||||
|
@ -237,9 +237,10 @@ class Item
|
|||
*
|
||||
* @param array $condition The condition for finding the item entries
|
||||
* @param integer $priority Priority for the notification
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function markForDeletion($condition, $priority = PRIORITY_HIGH)
|
||||
public static function markForDeletion(array $condition, int $priority = PRIORITY_HIGH)
|
||||
{
|
||||
$items = Post::select(['id'], $condition);
|
||||
while ($item = Post::fetch($items)) {
|
||||
|
@ -253,9 +254,10 @@ class Item
|
|||
*
|
||||
* @param array $condition The condition for finding the item entries
|
||||
* @param integer $uid User who wants to delete this item
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function deleteForUser($condition, $uid)
|
||||
public static function deleteForUser(array $condition, int $uid)
|
||||
{
|
||||
if ($uid == 0) {
|
||||
return;
|
||||
|
@ -282,11 +284,10 @@ class Item
|
|||
*
|
||||
* @param integer $item_id
|
||||
* @param integer $priority Priority for the notification
|
||||
*
|
||||
* @return boolean success
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function markForDeletionById($item_id, $priority = PRIORITY_HIGH)
|
||||
public static function markForDeletionById(int $item_id, int $priority = PRIORITY_HIGH): bool
|
||||
{
|
||||
Logger::info('Mark item for deletion by id', ['id' => $item_id, 'callstack' => System::callstack()]);
|
||||
// locate item to be deleted
|
||||
|
@ -331,7 +332,7 @@ class Item
|
|||
// If item has attachments, drop them
|
||||
$attachments = Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT]);
|
||||
foreach($attachments as $attachment) {
|
||||
if (preg_match("|attach/(\d+)|", $attachment['url'], $matches)) {
|
||||
if (preg_match('|attach/(\d+)|', $attachment['url'], $matches)) {
|
||||
Attach::delete(['id' => $matches[1], 'uid' => $item['uid']]);
|
||||
}
|
||||
}
|
||||
|
@ -360,7 +361,7 @@ class Item
|
|||
|
||||
// send the notification upstream/downstream
|
||||
if ($priority) {
|
||||
Worker::add(['priority' => $priority, 'dont_fork' => true], "Notifier", Delivery::DELETION, (int)$item['uri-id'], (int)$item['uid']);
|
||||
Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', Delivery::DELETION, (int)$item['uri-id'], (int)$item['uid']);
|
||||
}
|
||||
} elseif ($item['uid'] != 0) {
|
||||
Post\User::update($item['uri-id'], $item['uid'], ['hidden' => true]);
|
||||
|
@ -372,7 +373,14 @@ class Item
|
|||
return true;
|
||||
}
|
||||
|
||||
public static function guid($item, $notify)
|
||||
/**
|
||||
* Get guid from given item record
|
||||
*
|
||||
* @param array $item Item record
|
||||
* @param bool Whether to notify (?)
|
||||
* @return string Guid
|
||||
*/
|
||||
public static function guid(array $item, bool $notify): string
|
||||
{
|
||||
if (!empty($item['guid'])) {
|
||||
return trim($item['guid']);
|
||||
|
@ -425,7 +433,13 @@ class Item
|
|||
return $guid;
|
||||
}
|
||||
|
||||
private static function contactId($item)
|
||||
/**
|
||||
* Returns contact id from given item record
|
||||
*
|
||||
* @param array $item Item record
|
||||
* @return int Contact id
|
||||
*/
|
||||
private static function contactId(array $item): int
|
||||
{
|
||||
if (!empty($item['contact-id']) && DBA::exists('contact', ['self' => true, 'id' => $item['contact-id']])) {
|
||||
return $item['contact-id'];
|
||||
|
@ -451,17 +465,17 @@ class Item
|
|||
* @param array $item The item fields that are to be inserted
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function spool($orig_item)
|
||||
private static function spool(array $item)
|
||||
{
|
||||
// Now we store the data in the spool directory
|
||||
// We use "microtime" to keep the arrival order and "mt_rand" to avoid duplicates
|
||||
$file = 'item-' . round(microtime(true) * 10000) . '-' . mt_rand() . '.msg';
|
||||
|
||||
$spoolpath = System::getSpoolPath();
|
||||
if ($spoolpath != "") {
|
||||
if ($spoolpath != '') {
|
||||
$spool = $spoolpath . '/' . $file;
|
||||
|
||||
file_put_contents($spool, json_encode($orig_item));
|
||||
file_put_contents($spool, json_encode($item));
|
||||
Logger::warning("Item wasn't stored - Item was spooled into file", ['file' => $file]);
|
||||
}
|
||||
}
|
||||
|
@ -469,10 +483,10 @@ class Item
|
|||
/**
|
||||
* Check if the item array is a duplicate
|
||||
*
|
||||
* @param array $item
|
||||
* @param array $item Item record
|
||||
* @return boolean is it a duplicate?
|
||||
*/
|
||||
private static function isDuplicate(array $item)
|
||||
private static function isDuplicate(array $item): bool
|
||||
{
|
||||
// Checking if there is already an item with the same guid
|
||||
$condition = ['guid' => $item['guid'], 'network' => $item['network'], 'uid' => $item['uid']];
|
||||
|
@ -521,10 +535,10 @@ class Item
|
|||
/**
|
||||
* Check if the item array is valid
|
||||
*
|
||||
* @param array $item
|
||||
* @param array $item Item record
|
||||
* @return boolean item is valid
|
||||
*/
|
||||
public static function isValid(array $item)
|
||||
public static function isValid(array $item): bool
|
||||
{
|
||||
// When there is no content then we don't post it
|
||||
if (($item['body'] . $item['title'] == '') && (empty($item['uri-id']) || !Post\Media::existsByURIId($item['uri-id']))) {
|
||||
|
@ -591,10 +605,10 @@ class Item
|
|||
/**
|
||||
* Check if the item array is too old
|
||||
*
|
||||
* @param array $item
|
||||
* @param array $item Item record
|
||||
* @return boolean item is too old
|
||||
*/
|
||||
public static function isTooOld(array $item)
|
||||
public static function isTooOld(array $item): bool
|
||||
{
|
||||
// check for create date and expire time
|
||||
$expire_interval = DI::config()->get('system', 'dbclean-expire-days', 0);
|
||||
|
@ -623,15 +637,20 @@ class Item
|
|||
/**
|
||||
* Return the id of the given item array if it has been stored before
|
||||
*
|
||||
* @param array $item
|
||||
* @return integer item id
|
||||
* @param array $item Item record
|
||||
* @return integer Item id or zero on error
|
||||
*/
|
||||
private static function getDuplicateID(array $item)
|
||||
private static function getDuplicateID(array $item): int
|
||||
{
|
||||
if (empty($item['network']) || in_array($item['network'], Protocol::FEDERATED)) {
|
||||
$condition = ["`uri-id` = ? AND `uid` = ? AND `network` IN (?, ?, ?, ?)",
|
||||
$item['uri-id'], $item['uid'],
|
||||
Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::DFRN, Protocol::OSTATUS];
|
||||
$condition = ['`uri-id` = ? AND `uid` = ? AND `network` IN (?, ?, ?, ?)',
|
||||
$item['uri-id'],
|
||||
$item['uid'],
|
||||
Protocol::ACTIVITYPUB,
|
||||
Protocol::DIASPORA,
|
||||
Protocol::DFRN,
|
||||
Protocol::OSTATUS
|
||||
];
|
||||
$existing = Post::selectFirst(['id', 'network'], $condition);
|
||||
if (DBA::isResult($existing)) {
|
||||
// We only log the entries with a different user id than 0. Otherwise we would have too many false positives
|
||||
|
@ -640,12 +659,12 @@ class Item
|
|||
'uri-id' => $item['uri-id'],
|
||||
'uid' => $item['uid'],
|
||||
'network' => $item['network'],
|
||||
'existing_id' => $existing["id"],
|
||||
'existing_network' => $existing["network"]
|
||||
'existing_id' => $existing['id'],
|
||||
'existing_network' => $existing['network']
|
||||
]);
|
||||
}
|
||||
|
||||
return $existing["id"];
|
||||
return $existing['id'];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@ -658,7 +677,7 @@ class Item
|
|||
* @return array item array with parent data
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function getTopLevelParent(array $item)
|
||||
private static function getTopLevelParent(array $item): array
|
||||
{
|
||||
$fields = ['uid', 'uri', 'parent-uri', 'id', 'deleted',
|
||||
'uri-id', 'parent-uri-id',
|
||||
|
@ -709,7 +728,7 @@ class Item
|
|||
* @param array $item
|
||||
* @return integer gravity
|
||||
*/
|
||||
private static function getGravity(array $item)
|
||||
private static function getGravity(array $item): int
|
||||
{
|
||||
$activity = DI::activity();
|
||||
|
||||
|
@ -724,11 +743,20 @@ class Item
|
|||
} elseif ($activity->match($item['verb'], Activity::ANNOUNCE)) {
|
||||
return GRAVITY_ACTIVITY;
|
||||
}
|
||||
|
||||
Logger::info('Unknown gravity for verb', ['verb' => $item['verb']]);
|
||||
return GRAVITY_UNKNOWN; // Should not happen
|
||||
}
|
||||
|
||||
public static function insert(array $item, int $notify = 0, bool $post_local = true)
|
||||
/**
|
||||
* Inserts item record
|
||||
*
|
||||
* @param array $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
|
||||
*/
|
||||
public static function insert(array $item, int $notify = 0, bool $post_local = true): int
|
||||
{
|
||||
$orig_item = $item;
|
||||
|
||||
|
@ -752,7 +780,7 @@ class Item
|
|||
$uid = intval($item['uid']);
|
||||
|
||||
$item['guid'] = self::guid($item, $notify);
|
||||
$item['uri'] = substr(trim($item['uri'] ?? '') ?: self::newURI($item['uid'], $item['guid']), 0, 255);
|
||||
$item['uri'] = substr(trim($item['uri'] ?? '') ?: self::newURI($item['guid']), 0, 255);
|
||||
|
||||
// Store URI data
|
||||
$item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]);
|
||||
|
@ -869,7 +897,7 @@ class Item
|
|||
Contact::checkAvatarCache($item['owner-id']);
|
||||
|
||||
// The contact-id should be set before "self::insert" was called - but there seems to be issues sometimes
|
||||
$item["contact-id"] = self::contactId($item);
|
||||
$item['contact-id'] = self::contactId($item);
|
||||
|
||||
if (!empty($item['direction']) && in_array($item['direction'], [Conversation::PUSH, Conversation::RELAY]) &&
|
||||
empty($item['origin']) &&self::isTooOld($item)) {
|
||||
|
@ -944,8 +972,8 @@ class Item
|
|||
$item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
|
||||
|
||||
// Is this item available in the global items (with uid=0)?
|
||||
if ($item["uid"] == 0) {
|
||||
$item["global"] = true;
|
||||
if ($item['uid'] == 0) {
|
||||
$item['global'] = true;
|
||||
|
||||
// Set the global flag on all items if this was a global item entry
|
||||
Post::update(['global' => true], ['uri-id' => $item['uri-id']]);
|
||||
|
@ -954,8 +982,8 @@ class Item
|
|||
}
|
||||
|
||||
// ACL settings
|
||||
if (!empty($item["allow_cid"] . $item["allow_gid"] . $item["deny_cid"] . $item["deny_gid"])) {
|
||||
$item["private"] = self::PRIVATE;
|
||||
if (!empty($item['allow_cid'] . $item['allow_gid'] . $item['deny_cid'] . $item['deny_gid'])) {
|
||||
$item['private'] = self::PRIVATE;
|
||||
}
|
||||
|
||||
if ($notify && $post_local) {
|
||||
|
@ -1323,7 +1351,7 @@ class Item
|
|||
* @param string $signed_text Original text (for Diaspora signatures), JSON encoded.
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function distribute($itemid, $signed_text = '')
|
||||
public static function distribute(int $itemid, string $signed_text = '')
|
||||
{
|
||||
$condition = ["`id` IN (SELECT `parent` FROM `post-user-view` WHERE `id` = ?)", $itemid];
|
||||
$parent = Post::selectFirst(['owner-id'], $condition);
|
||||
|
@ -1417,7 +1445,7 @@ class Item
|
|||
* @param integer $source_uid User id of the source post
|
||||
* @return integer stored item id
|
||||
*/
|
||||
public static function storeForUserByUriId(int $uri_id, int $uid, array $fields = [], int $source_uid = 0)
|
||||
public static function storeForUserByUriId(int $uri_id, int $uid, array $fields = [], int $source_uid = 0): int
|
||||
{
|
||||
if ($uid == $source_uid) {
|
||||
Logger::warning('target UID must not be be equal to the source UID', ['uri-id' => $uri_id, 'uid' => $uid]);
|
||||
|
@ -1525,7 +1553,7 @@ class Item
|
|||
* @return integer stored item id
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function storeForUser(array $item, int $uid)
|
||||
private static function storeForUser(array $item, int $uid): int
|
||||
{
|
||||
if (Post::exists(['uri-id' => $item['uri-id'], 'uid' => $uid])) {
|
||||
if (!empty($item['event-id'])) {
|
||||
|
@ -1613,7 +1641,7 @@ class Item
|
|||
* @param integer $itemid Item ID that should be added
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function addShadow($itemid)
|
||||
private static function addShadow(int $itemid)
|
||||
{
|
||||
$fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id'];
|
||||
$condition = ['id' => $itemid, 'gravity' => GRAVITY_PARENT];
|
||||
|
@ -1676,7 +1704,7 @@ class Item
|
|||
* @param integer $itemid Item ID that should be added
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function addShadowPost($itemid)
|
||||
private static function addShadowPost(int $itemid)
|
||||
{
|
||||
$item = Post::selectFirst(self::ITEM_FIELDLIST, ['id' => $itemid]);
|
||||
if (!DBA::isResult($item)) {
|
||||
|
@ -1740,7 +1768,7 @@ class Item
|
|||
* @return string detected language
|
||||
* @throws \Text_LanguageDetect_Exception
|
||||
*/
|
||||
private static function getLanguage(array $item)
|
||||
private static function getLanguage(array $item): string
|
||||
{
|
||||
if (!empty($item['language'])) {
|
||||
return $item['language'];
|
||||
|
@ -1784,7 +1812,7 @@ class Item
|
|||
return '';
|
||||
}
|
||||
|
||||
public static function getLanguageMessage(array $item)
|
||||
public static function getLanguageMessage(array $item): string
|
||||
{
|
||||
$iso639 = new \Matriphe\ISO639\ISO639;
|
||||
|
||||
|
@ -1802,38 +1830,37 @@ class Item
|
|||
* Posts that are created on this system are using System::createUUID.
|
||||
* Received ActivityPub posts are using Processor::getGUIDByURL.
|
||||
*
|
||||
* @param string $uri uri of an item entry
|
||||
* @param string $host hostname for the GUID prefix
|
||||
* @return string unique guid
|
||||
* @param string $uri uri of an item entry
|
||||
* @param string|null $host hostname for the GUID prefix
|
||||
* @return string Unique guid
|
||||
*/
|
||||
public static function guidFromUri($uri, $host)
|
||||
public static function guidFromUri(string $uri, string $host = null): string
|
||||
{
|
||||
// Our regular guid routine is using this kind of prefix as well
|
||||
// We have to avoid that different routines could accidentally create the same value
|
||||
$parsed = parse_url($uri);
|
||||
|
||||
// Remove the scheme to make sure that "https" and "http" doesn't make a difference
|
||||
unset($parsed["scheme"]);
|
||||
unset($parsed['scheme']);
|
||||
|
||||
// Glue it together to be able to make a hash from it
|
||||
$host_id = implode("/", $parsed);
|
||||
$host_id = implode('/', $parsed);
|
||||
|
||||
// Use a mixture of several hashes to provide some GUID like experience
|
||||
return hash("crc32", $host) . '-'. hash('joaat', $host_id) . '-'. hash('fnv164', $host_id);
|
||||
return hash('crc32', $host) . '-'. hash('joaat', $host_id) . '-'. hash('fnv164', $host_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* generate an unique URI
|
||||
*
|
||||
* @param integer $uid User id
|
||||
* @param string $guid An existing GUID (Otherwise it will be generated)
|
||||
* @param string $guid An existing GUID (Otherwise it will be generated)
|
||||
*
|
||||
* @return string
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function newURI($uid, $guid = "")
|
||||
public static function newURI(string $guid = ''): string
|
||||
{
|
||||
if ($guid == "") {
|
||||
if ($guid == '') {
|
||||
$guid = System::createUUID();
|
||||
}
|
||||
|
||||
|
@ -1850,7 +1877,7 @@ class Item
|
|||
* @param array $arr Contains the just posted item record
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function updateContact($arr)
|
||||
private static function updateContact(array $arr)
|
||||
{
|
||||
// Unarchive the author
|
||||
$contact = DBA::selectFirst('contact', [], ['id' => $arr["author-id"]]);
|
||||
|
@ -1897,7 +1924,7 @@ class Item
|
|||
}
|
||||
}
|
||||
|
||||
public static function setHashtags($body)
|
||||
public static function setHashtags(string $body): string
|
||||
{
|
||||
$body = BBCode::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) {
|
||||
$tags = BBCode::getTags($body);
|
||||
|
@ -1971,7 +1998,7 @@ class Item
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
private static function tagDeliver($uid, $item_id)
|
||||
private static function tagDeliver(int $uid, int $item_id): bool
|
||||
{
|
||||
$mention = false;
|
||||
|
||||
|
@ -2066,7 +2093,7 @@ class Item
|
|||
self::performActivity($item['id'], 'announce', $item['uid']);
|
||||
}
|
||||
|
||||
public static function isRemoteSelf($contact, &$datarray)
|
||||
public static function isRemoteSelf(array $contact, array &$datarray): bool
|
||||
{
|
||||
if (!$contact['remote_self']) {
|
||||
return false;
|
||||
|
@ -2122,7 +2149,7 @@ class Item
|
|||
$old_uri_id = $datarray["uri-id"] ?? 0;
|
||||
$datarray["guid"] = System::createUUID();
|
||||
unset($datarray["plink"]);
|
||||
$datarray["uri"] = self::newURI($contact['uid'], $datarray["guid"]);
|
||||
$datarray["uri"] = self::newURI($datarray["guid"]);
|
||||
$datarray["uri-id"] = ItemURI::getIdByURI($datarray["uri"]);
|
||||
$datarray["extid"] = Protocol::DFRN;
|
||||
$urlpart = parse_url($datarray2['author-link']);
|
||||
|
@ -2160,7 +2187,7 @@ class Item
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function fixPrivatePhotos($s, $uid, $item = null, $cid = 0)
|
||||
public static function fixPrivatePhotos(string $s, int $uid, array $item = null, int $cid = 0): string
|
||||
{
|
||||
if (DI::config()->get('system', 'disable_embedded')) {
|
||||
return $s;
|
||||
|
@ -2254,13 +2281,14 @@ class Item
|
|||
return $new_body;
|
||||
}
|
||||
|
||||
private static function hasPermissions($obj)
|
||||
private static function hasPermissions(array $obj)
|
||||
{
|
||||
return !empty($obj['allow_cid']) || !empty($obj['allow_gid']) ||
|
||||
!empty($obj['deny_cid']) || !empty($obj['deny_gid']);
|
||||
}
|
||||
|
||||
private static function samePermissions($uid, $obj1, $obj2)
|
||||
// @TODO $uid is unused parameter
|
||||
private static function samePermissions($uid, array $obj1, array $obj2): bool
|
||||
{
|
||||
// first part is easy. Check that these are exactly the same.
|
||||
if (($obj1['allow_cid'] == $obj2['allow_cid'])
|
||||
|
@ -2288,7 +2316,7 @@ class Item
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function enumeratePermissions(array $obj, bool $check_dead = false)
|
||||
public static function enumeratePermissions(array $obj, bool $check_dead = false): array
|
||||
{
|
||||
$aclFormater = DI::aclFormatter();
|
||||
|
||||
|
@ -2376,7 +2404,7 @@ class Item
|
|||
Logger::notice('User ' . $uid . ": expired $expired items; expire items: $expire_items, expire notes: $expire_notes, expire starred: $expire_starred, expire photos: $expire_photos");
|
||||
}
|
||||
|
||||
public static function firstPostDate($uid, $wall = false)
|
||||
public static function firstPostDate(int $uid, bool $wall = false)
|
||||
{
|
||||
$user = User::getById($uid, ['register_date']);
|
||||
if (empty($user)) {
|
||||
|
@ -2417,7 +2445,7 @@ class Item
|
|||
* array $arr
|
||||
* 'post_id' => ID of posted item
|
||||
*/
|
||||
public static function performActivity(int $item_id, string $verb, int $uid, string $allow_cid = null, string $allow_gid = null, string $deny_cid = null, string $deny_gid = null)
|
||||
public static function performActivity(int $item_id, string $verb, int $uid, string $allow_cid = null, string $allow_gid = null, string $deny_cid = null, string $deny_gid = null): bool
|
||||
{
|
||||
if (empty($uid)) {
|
||||
return false;
|
||||
|
@ -2562,7 +2590,7 @@ class Item
|
|||
|
||||
$new_item = [
|
||||
'guid' => System::createUUID(),
|
||||
'uri' => self::newURI($item['uid']),
|
||||
'uri' => self::newURI(),
|
||||
'uid' => $item['uid'],
|
||||
'contact-id' => $owner['id'],
|
||||
'wall' => $item['wall'],
|
||||
|
@ -2611,7 +2639,7 @@ class Item
|
|||
* @param integer $owner_id User ID for which the permissions should be fetched
|
||||
* @return array condition
|
||||
*/
|
||||
public static function getPermissionsConditionArrayByUserId(int $owner_id)
|
||||
public static function getPermissionsConditionArrayByUserId(int $owner_id): array
|
||||
{
|
||||
$local_user = local_user();
|
||||
$remote_user = Session::getRemoteContactID($owner_id);
|
||||
|
@ -2643,7 +2671,7 @@ class Item
|
|||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public static function getPermissionsSQLByUserId(int $owner_id, string $table = '')
|
||||
public static function getPermissionsSQLByUserId(int $owner_id, string $table = ''): string
|
||||
{
|
||||
$local_user = local_user();
|
||||
$remote_user = Session::getRemoteContactID($owner_id);
|
||||
|
@ -2691,7 +2719,7 @@ class Item
|
|||
* @param \Friendica\Core\L10n $l10n
|
||||
* @return string
|
||||
*/
|
||||
public static function postType(array $item, \Friendica\Core\L10n $l10n)
|
||||
public static function postType(array $item, \Friendica\Core\L10n $l10n): string
|
||||
{
|
||||
if (!empty($item['event-id'])) {
|
||||
return $l10n->t('event');
|
||||
|
@ -2757,10 +2785,10 @@ class Item
|
|||
* Given an item array, convert the body element from bbcode to html and add smilie icons.
|
||||
* If attach is true, also add icons for item attachments.
|
||||
*
|
||||
* @param array $item
|
||||
* @param boolean $attach
|
||||
* @param boolean $is_preview
|
||||
* @param boolean $only_cache
|
||||
* @param array $item Record from item table
|
||||
* @param boolean $attach If true, add icons for item attachments as well
|
||||
* @param boolean $is_preview Whether this is a preview
|
||||
* @param boolean $only_cache Whether only cached HTML should be updated
|
||||
* @return string item body html
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
|
@ -2769,7 +2797,7 @@ class Item
|
|||
* @hook prepare_body ('item'=>item array, 'html'=>body string, 'is_preview'=>boolean, 'filter_reasons'=>string array) after first bbcode to html
|
||||
* @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author)
|
||||
*/
|
||||
public static function prepareBody(array &$item, $attach = false, $is_preview = false, $only_cache = false)
|
||||
public static function prepareBody(array &$item, bool $attach = false, bool $is_preview = false, bool $only_cache = false): string
|
||||
{
|
||||
$a = DI::app();
|
||||
Hook::callAll('prepare_body_init', $item);
|
||||
|
@ -2802,7 +2830,8 @@ class Item
|
|||
$shared_uri_id = 0;
|
||||
$shared_links = [];
|
||||
}
|
||||
$attachments = Post\Media::splitAttachments($item['uri-id'], $item['guid'] ?? '', $shared_links, $item['has-media']);
|
||||
|
||||
$attachments = Post\Media::splitAttachments($item['uri-id'], $item['guid'] ?? '', $shared_links, $item['has-media'] ?? false);
|
||||
$item['body'] = self::replaceVisualAttachments($attachments, $item['body'] ?? '');
|
||||
|
||||
$item['body'] = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", "\n", $item['body']);
|
||||
|
@ -2811,7 +2840,7 @@ class Item
|
|||
$s = $item["rendered-html"];
|
||||
|
||||
if ($only_cache) {
|
||||
return;
|
||||
return '';
|
||||
}
|
||||
|
||||
// Compile eventual content filter reasons
|
||||
|
@ -2891,7 +2920,7 @@ class Item
|
|||
* @param int $type
|
||||
* @return bool
|
||||
*/
|
||||
public static function containsLink(string $body, string $url, int $type = 0)
|
||||
public static function containsLink(string $body, string $url, int $type = 0): bool
|
||||
{
|
||||
// Make sure that for example site parameters aren't used when testing if the link is contained in the body
|
||||
$urlparts = parse_url($url);
|
||||
|
@ -2924,7 +2953,7 @@ class Item
|
|||
* @param string $body
|
||||
* @return string modified body
|
||||
*/
|
||||
private static function replaceVisualAttachments(array $attachments, string $body)
|
||||
private static function replaceVisualAttachments(array $attachments, string $body): string
|
||||
{
|
||||
DI::profiler()->startRecording('rendering');
|
||||
|
||||
|
@ -2955,7 +2984,7 @@ class Item
|
|||
* @param string $content
|
||||
* @return string modified content
|
||||
*/
|
||||
private static function addVisualAttachments(array $attachments, array $item, string $content, bool $shared)
|
||||
private static function addVisualAttachments(array $attachments, array $item, string $content, bool $shared): string
|
||||
{
|
||||
DI::profiler()->startRecording('rendering');
|
||||
$leading = '';
|
||||
|
@ -3047,7 +3076,7 @@ class Item
|
|||
* @param array $ignore_links A list of URLs to ignore
|
||||
* @return string modified content
|
||||
*/
|
||||
private static function addLinkAttachment(int $uriid, array $attachments, string $body, string $content, bool $shared, array $ignore_links)
|
||||
private static function addLinkAttachment(int $uriid, array $attachments, string $body, string $content, bool $shared, array $ignore_links): string
|
||||
{
|
||||
DI::profiler()->startRecording('rendering');
|
||||
// Don't show a preview when there is a visual attachment (audio or video)
|
||||
|
@ -3161,7 +3190,7 @@ class Item
|
|||
* @param string $content
|
||||
* @return string modified content
|
||||
*/
|
||||
private static function addNonVisualAttachments(array $attachments, array $item, string $content)
|
||||
private static function addNonVisualAttachments(array $attachments, array $item, string $content): string
|
||||
{
|
||||
DI::profiler()->startRecording('rendering');
|
||||
$trailing = '';
|
||||
|
@ -3193,7 +3222,7 @@ class Item
|
|||
return $content;
|
||||
}
|
||||
|
||||
private static function addQuestions(array $item, string $content)
|
||||
private static function addQuestions(array $item, string $content): string
|
||||
{
|
||||
DI::profiler()->startRecording('rendering');
|
||||
if (!empty($item['question-id'])) {
|
||||
|
@ -3244,7 +3273,7 @@ class Item
|
|||
* @return boolean|array False if item has not plink, otherwise array('href'=>plink url, 'title'=>translated title)
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getPlink($item)
|
||||
public static function getPlink(array $item)
|
||||
{
|
||||
if (!empty($item['plink']) && Network::isValidHttpUrl($item['plink'])) {
|
||||
$plink = $item['plink'];
|
||||
|
@ -3291,7 +3320,7 @@ class Item
|
|||
*
|
||||
* @return boolean "true" when it is a forum post
|
||||
*/
|
||||
public static function isForumPost(int $uri_id)
|
||||
public static function isForumPost(int $uri_id): bool
|
||||
{
|
||||
foreach (Tag::getByURIId($uri_id, [Tag::EXCLUSIVE_MENTION]) as $tag) {
|
||||
if (DBA::exists('contact', ['uid' => 0, 'nurl' => Strings::normaliseLink($tag['url']), 'contact-type' => Contact::TYPE_COMMUNITY])) {
|
||||
|
@ -3309,7 +3338,7 @@ class Item
|
|||
*
|
||||
* @return integer item id
|
||||
*/
|
||||
public static function searchByLink($uri, $uid = 0)
|
||||
public static function searchByLink(string $uri, int $uid = 0): int
|
||||
{
|
||||
$ssl_uri = str_replace('http://', 'https://', $uri);
|
||||
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
|
||||
|
@ -3334,7 +3363,7 @@ class Item
|
|||
*
|
||||
* @return string URI
|
||||
*/
|
||||
public static function getURIByLink(string $uri)
|
||||
public static function getURIByLink(string $uri): string
|
||||
{
|
||||
$ssl_uri = str_replace('http://', 'https://', $uri);
|
||||
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
|
||||
|
@ -3360,7 +3389,7 @@ class Item
|
|||
*
|
||||
* @return integer item id
|
||||
*/
|
||||
public static function fetchByLink(string $uri, int $uid = 0)
|
||||
public static function fetchByLink(string $uri, int $uid = 0): int
|
||||
{
|
||||
Logger::info('Trying to fetch link', ['uid' => $uid, 'uri' => $uri]);
|
||||
$item_id = self::searchByLink($uri, $uid);
|
||||
|
@ -3381,7 +3410,11 @@ class Item
|
|||
return is_numeric($hookData['item_id']) ? $hookData['item_id'] : 0;
|
||||
}
|
||||
|
||||
if ($fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri)) {
|
||||
$fetchQueue = new ActivityPub\FetchQueue();
|
||||
$fetched_uri = ActivityPub\Processor::fetchMissingActivity($fetchQueue, $uri);
|
||||
$fetchQueue->process();
|
||||
|
||||
if ($fetched_uri) {
|
||||
$item_id = self::searchByLink($fetched_uri, $uid);
|
||||
} else {
|
||||
$item_id = Diaspora::fetchByURL($uri);
|
||||
|
@ -3406,20 +3439,9 @@ class Item
|
|||
*
|
||||
* @return array with share information
|
||||
*/
|
||||
public static function getShareArray($item)
|
||||
public static function getShareArray(array $item): array
|
||||
{
|
||||
if (!preg_match("/(.*?)\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism", $item['body'], $matches)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$attribute_string = $matches[2];
|
||||
$attributes = ['comment' => trim($matches[1]), 'shared' => trim($matches[3])];
|
||||
foreach (['author', 'profile', 'avatar', 'guid', 'posted', 'link'] as $field) {
|
||||
if (preg_match("/$field=(['\"])(.+?)\\1/ism", $attribute_string, $matches)) {
|
||||
$attributes[$field] = trim(html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
}
|
||||
return $attributes;
|
||||
return BBCode::fetchShareAttributes($item['body']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3429,7 +3451,7 @@ class Item
|
|||
*
|
||||
* @return array item array with data from the original item
|
||||
*/
|
||||
public static function addShareDataFromOriginal(array $item)
|
||||
public static function addShareDataFromOriginal(array $item): array
|
||||
{
|
||||
$shared = self::getShareArray($item);
|
||||
if (empty($shared)) {
|
||||
|
@ -3490,7 +3512,7 @@ class Item
|
|||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected static function isAllowedByUser(array $item, int $user_id)
|
||||
protected static function isAllowedByUser(array $item, int $user_id): bool
|
||||
{
|
||||
if (!empty($item['author-id']) && Contact\User::isBlocked($item['author-id'], $user_id)) {
|
||||
Logger::notice('Author is blocked by user', ['author-link' => $item['author-link'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
|
||||
|
@ -3522,7 +3544,7 @@ class Item
|
|||
* @param array $item
|
||||
* @return string body
|
||||
*/
|
||||
public static function improveSharedDataInBody(array $item)
|
||||
public static function improveSharedDataInBody(array $item): string
|
||||
{
|
||||
$shared = BBCode::fetchShareAttributes($item['body']);
|
||||
if (empty($shared['link'])) {
|
||||
|
|
|
@ -30,7 +30,6 @@ class ItemURI
|
|||
* Insert an item-uri record and return its id
|
||||
*
|
||||
* @param array $fields Item-uri fields
|
||||
*
|
||||
* @return int|null item-uri id
|
||||
* @throws \Exception
|
||||
*/
|
||||
|
@ -61,12 +60,15 @@ class ItemURI
|
|||
* Searched for an id of a given uri. Adds it, if not existing yet.
|
||||
*
|
||||
* @param string $uri
|
||||
*
|
||||
* @return integer item-uri id
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getIdByURI($uri)
|
||||
public static function getIdByURI(string $uri): int
|
||||
{
|
||||
if (empty($uri)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If the URI gets too long we only take the first parts and hope for best
|
||||
$uri = substr($uri, 0, 255);
|
||||
|
||||
|
@ -82,11 +84,10 @@ class ItemURI
|
|||
* Searched for an id of a given guid.
|
||||
*
|
||||
* @param string $guid
|
||||
*
|
||||
* @return integer item-uri id
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getIdByGUID($guid)
|
||||
public static function getIdByGUID(string $guid): int
|
||||
{
|
||||
// If the GUID gets too long we only take the first parts and hope for best
|
||||
$guid = substr($guid, 0, 255);
|
||||
|
|
|
@ -45,7 +45,7 @@ class ParsedLogIterator implements \Iterator
|
|||
private $filters = [];
|
||||
|
||||
/** @var string search term */
|
||||
private $search = "";
|
||||
private $search = '';
|
||||
|
||||
|
||||
/**
|
||||
|
@ -60,7 +60,7 @@ class ParsedLogIterator implements \Iterator
|
|||
* @param string $filename File to open
|
||||
* @return $this
|
||||
*/
|
||||
public function open(string $filename)
|
||||
public function open(string $filename): ParsedLogIterator
|
||||
{
|
||||
$this->reader->open($filename);
|
||||
return $this;
|
||||
|
@ -70,7 +70,7 @@ class ParsedLogIterator implements \Iterator
|
|||
* @param int $limit Max num of lines to read
|
||||
* @return $this
|
||||
*/
|
||||
public function withLimit(int $limit)
|
||||
public function withLimit(int $limit): ParsedLogIterator
|
||||
{
|
||||
$this->limit = $limit;
|
||||
return $this;
|
||||
|
@ -80,7 +80,7 @@ class ParsedLogIterator implements \Iterator
|
|||
* @param array $filters filters per column
|
||||
* @return $this
|
||||
*/
|
||||
public function withFilters(array $filters)
|
||||
public function withFilters(array $filters): ParsedLogIterator
|
||||
{
|
||||
$this->filters = $filters;
|
||||
return $this;
|
||||
|
@ -90,7 +90,7 @@ class ParsedLogIterator implements \Iterator
|
|||
* @param string $search string to search to filter lines
|
||||
* @return $this
|
||||
*/
|
||||
public function withSearch(string $search)
|
||||
public function withSearch(string $search): ParsedLogIterator
|
||||
{
|
||||
$this->search = $search;
|
||||
return $this;
|
||||
|
@ -100,18 +100,19 @@ class ParsedLogIterator implements \Iterator
|
|||
* Check if parsed log line match filters.
|
||||
* Always match if no filters are set.
|
||||
*
|
||||
* @param ParsedLogLine $parsedlogline
|
||||
* @return bool
|
||||
* @param ParsedLogLine $parsedlogline ParsedLogLine instance
|
||||
* @return bool Wether the parse log line matches
|
||||
*/
|
||||
private function filter($parsedlogline)
|
||||
private function filter(ParsedLogLine $parsedlogline): bool
|
||||
{
|
||||
$match = true;
|
||||
foreach ($this->filters as $filter => $filtervalue) {
|
||||
switch ($filter) {
|
||||
case "level":
|
||||
case 'level':
|
||||
$match = $match && ($parsedlogline->level == strtoupper($filtervalue));
|
||||
break;
|
||||
case "context":
|
||||
|
||||
case 'context':
|
||||
$match = $match && ($parsedlogline->context == $filtervalue);
|
||||
break;
|
||||
}
|
||||
|
@ -126,9 +127,9 @@ class ParsedLogIterator implements \Iterator
|
|||
* @param ParsedLogLine $parsedlogline
|
||||
* @return bool
|
||||
*/
|
||||
private function search($parsedlogline)
|
||||
private function search(ParsedLogLine $parsedlogline): bool
|
||||
{
|
||||
if ($this->search != "") {
|
||||
if ($this->search != '') {
|
||||
return strstr($parsedlogline->logline, $this->search) !== false;
|
||||
}
|
||||
return true;
|
||||
|
@ -138,7 +139,6 @@ class ParsedLogIterator implements \Iterator
|
|||
* Read a line from reader and parse.
|
||||
* Returns null if limit is reached or the reader is invalid.
|
||||
*
|
||||
* @param ParsedLogLine $parsedlogline
|
||||
* @return ?ParsedLogLine
|
||||
*/
|
||||
private function read()
|
||||
|
@ -191,7 +191,7 @@ class ParsedLogIterator implements \Iterator
|
|||
* @see ReversedFileReader::key()
|
||||
* @return int
|
||||
*/
|
||||
public function key()
|
||||
public function key(): int
|
||||
{
|
||||
return $this->reader->key();
|
||||
}
|
||||
|
@ -213,8 +213,8 @@ class ParsedLogIterator implements \Iterator
|
|||
* @see Iterator::valid()
|
||||
* @return bool
|
||||
*/
|
||||
public function valid()
|
||||
public function valid(): bool
|
||||
{
|
||||
return ! is_null($this->value);
|
||||
return !is_null($this->value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class Mail
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function insert($msg, $notification = true)
|
||||
public static function insert(array $msg, bool $notification = true)
|
||||
{
|
||||
if (!isset($msg['reply'])) {
|
||||
$msg['reply'] = DBA::exists('mail', ['parent-uri' => $msg['parent-uri']]);
|
||||
|
@ -125,7 +125,7 @@ class Mail
|
|||
* @return int
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function send($recipient = 0, $body = '', $subject = '', $replyto = '')
|
||||
public static function send(int $recipient = 0, string $body = '', string $subject = '', string $replyto = ''): int
|
||||
{
|
||||
$a = DI::app();
|
||||
|
||||
|
@ -154,7 +154,7 @@ class Mail
|
|||
Photo::setPermissionFromBody($body, local_user(), $me['id'], '<' . $contact['id'] . '>', '', '', '');
|
||||
|
||||
$guid = System::createUUID();
|
||||
$uri = Item::newURI(local_user(), $guid);
|
||||
$uri = Item::newURI($guid);
|
||||
|
||||
$convid = 0;
|
||||
$reply = false;
|
||||
|
@ -255,7 +255,7 @@ class Mail
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function sendWall(array $recipient = [], $body = '', $subject = '', $replyto = '')
|
||||
public static function sendWall(array $recipient = [], string $body = '', string $subject = '', string $replyto = ''): int
|
||||
{
|
||||
if (!$recipient) {
|
||||
return -1;
|
||||
|
@ -266,7 +266,7 @@ class Mail
|
|||
}
|
||||
|
||||
$guid = System::createUUID();
|
||||
$uri = Item::newURI(local_user(), $guid);
|
||||
$uri = Item::newURI($guid);
|
||||
|
||||
$me = Contact::getByURL($replyto);
|
||||
if (!$me['name']) {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
namespace Friendica\Model;
|
||||
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use stdClass;
|
||||
|
@ -101,7 +102,7 @@ class Nodeinfo
|
|||
*
|
||||
* @return array with supported services
|
||||
*/
|
||||
public static function getServices()
|
||||
public static function getServices(): array
|
||||
{
|
||||
$services = [
|
||||
'inbound' => [],
|
||||
|
@ -156,9 +157,19 @@ class Nodeinfo
|
|||
return $services;
|
||||
}
|
||||
|
||||
public static function getOrganization($config)
|
||||
/**
|
||||
* Gathers organization information and returns it as an array
|
||||
*
|
||||
* @param IManageConfigValues $config Configuration instance
|
||||
* @return array Organization information
|
||||
*/
|
||||
public static function getOrganization(IManageConfigValues $config): array
|
||||
{
|
||||
$organization = ['name' => null, 'contact' => null, 'account' => null];
|
||||
$organization = [
|
||||
'name' => null,
|
||||
'contact' => null,
|
||||
'account' => null
|
||||
];
|
||||
|
||||
if (!empty($config->get('config', 'admin_email'))) {
|
||||
$adminList = explode(',', str_replace(' ', '', $config->get('config', 'admin_email')));
|
||||
|
|
|
@ -36,20 +36,19 @@ class OpenWebAuthToken
|
|||
* @param int $uid The user ID.
|
||||
* @param string $token
|
||||
* @param string $meta
|
||||
*
|
||||
* @return boolean
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function create($type, $uid, $token, $meta)
|
||||
public static function create(string $type, uid $uid, string $token, string $meta)
|
||||
{
|
||||
$fields = [
|
||||
"type" => $type,
|
||||
"uid" => $uid,
|
||||
"token" => $token,
|
||||
"meta" => $meta,
|
||||
"created" => DateTimeFormat::utcNow()
|
||||
'type' => $type,
|
||||
'uid' => $uid,
|
||||
'token' => $token,
|
||||
'meta' => $meta,
|
||||
'created' => DateTimeFormat::utcNow()
|
||||
];
|
||||
return DBA::insert("openwebauth-token", $fields);
|
||||
return DBA::insert('openwebauth-token', $fields);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,15 +61,15 @@ class OpenWebAuthToken
|
|||
* @return string|boolean The meta enry or false if not found.
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getMeta($type, $uid, $token)
|
||||
public static function getMeta(string $type, int $uid, string $token)
|
||||
{
|
||||
$condition = ["type" => $type, "uid" => $uid, "token" => $token];
|
||||
$condition = ['type' => $type, 'uid' => $uid, 'token' => $token];
|
||||
|
||||
$entry = DBA::selectFirst("openwebauth-token", ["id", "meta"], $condition);
|
||||
$entry = DBA::selectFirst('openwebauth-token', ['id', 'meta'], $condition);
|
||||
if (DBA::isResult($entry)) {
|
||||
DBA::delete("openwebauth-token", ["id" => $entry["id"]]);
|
||||
DBA::delete('openwebauth-token', ['id' => $entry['id']]);
|
||||
|
||||
return $entry["meta"];
|
||||
return $entry['meta'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -80,12 +79,13 @@ class OpenWebAuthToken
|
|||
*
|
||||
* @param string $type Verify type.
|
||||
* @param string $interval SQL compatible time interval
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function purge($type, $interval)
|
||||
public static function purge(string $type, string $interval)
|
||||
{
|
||||
$condition = ["`type` = ? AND `created` < ?", $type, DateTimeFormat::utcNow() . " - INTERVAL " . $interval];
|
||||
DBA::delete("openwebauth-token", $condition);
|
||||
$condition = ["`type` = ? AND `created` < ?", $type, DateTimeFormat::utcNow() . ' - INTERVAL ' . $interval];
|
||||
DBA::delete('openwebauth-token', $condition);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ class Photo
|
|||
$fields = self::getFields();
|
||||
}
|
||||
|
||||
return DBA::selectFirst("photo", $fields, $conditions, $params);
|
||||
return DBA::selectFirst('photo', $fields, $conditions, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,10 +110,10 @@ class Photo
|
|||
* @throws \Exception
|
||||
* @see \Friendica\Database\DBA::select
|
||||
*/
|
||||
public static function getPhotosForUser($uid, $resourceid, array $conditions = [], array $params = [])
|
||||
public static function getPhotosForUser(int $uid, string $resourceid, array $conditions = [], array $params = [])
|
||||
{
|
||||
$conditions["resource-id"] = $resourceid;
|
||||
$conditions["uid"] = $uid;
|
||||
$conditions['resource-id'] = $resourceid;
|
||||
$conditions['uid'] = $uid;
|
||||
|
||||
return self::selectToArray([], $conditions, $params);
|
||||
}
|
||||
|
@ -132,11 +132,11 @@ class Photo
|
|||
* @throws \Exception
|
||||
* @see \Friendica\Database\DBA::select
|
||||
*/
|
||||
public static function getPhotoForUser($uid, $resourceid, $scale = 0, array $conditions = [], array $params = [])
|
||||
public static function getPhotoForUser(int $uid, $resourceid, $scale = 0, array $conditions = [], array $params = [])
|
||||
{
|
||||
$conditions["resource-id"] = $resourceid;
|
||||
$conditions["uid"] = $uid;
|
||||
$conditions["scale"] = $scale;
|
||||
$conditions['resource-id'] = $resourceid;
|
||||
$conditions['uid'] = $uid;
|
||||
$conditions['scale'] = $scale;
|
||||
|
||||
return self::selectFirst([], $conditions, $params);
|
||||
}
|
||||
|
@ -156,19 +156,19 @@ class Photo
|
|||
*/
|
||||
public static function getPhoto(string $resourceid, int $scale = 0)
|
||||
{
|
||||
$r = self::selectFirst(["uid"], ["resource-id" => $resourceid]);
|
||||
$r = self::selectFirst(['uid'], ['resource-id' => $resourceid]);
|
||||
if (!DBA::isResult($r)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$uid = $r["uid"];
|
||||
$uid = $r['uid'];
|
||||
|
||||
$accessible = $uid ? (bool)DI::pConfig()->get($uid, 'system', 'accessible-photos', false) : false;
|
||||
|
||||
$sql_acl = Security::getPermissionsSQLByUserId($uid, $accessible);
|
||||
|
||||
$conditions = ["`resource-id` = ? AND `scale` <= ? " . $sql_acl, $resourceid, $scale];
|
||||
$params = ["order" => ["scale" => true]];
|
||||
$params = ['order' => ['scale' => true]];
|
||||
$photo = self::selectFirst([], $conditions, $params);
|
||||
|
||||
return $photo;
|
||||
|
@ -182,9 +182,9 @@ class Photo
|
|||
* @return boolean
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function exists(array $conditions)
|
||||
public static function exists(array $conditions): bool
|
||||
{
|
||||
return DBA::exists("photo", $conditions);
|
||||
return DBA::exists('photo', $conditions);
|
||||
}
|
||||
|
||||
|
||||
|
@ -193,7 +193,7 @@ class Photo
|
|||
*
|
||||
* @param array $photo Photo data. Needs at least 'id', 'type', 'backend-class', 'backend-ref'
|
||||
*
|
||||
* @return \Friendica\Object\Image
|
||||
* @return \Friendica\Object\Image|null Image object or null on error
|
||||
*/
|
||||
public static function getImageDataForPhoto(array $photo)
|
||||
{
|
||||
|
@ -248,11 +248,11 @@ class Photo
|
|||
* @return array field list
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function getFields()
|
||||
private static function getFields(): array
|
||||
{
|
||||
$allfields = DBStructure::definition(DI::app()->getBasePath(), false);
|
||||
$fields = array_keys($allfields["photo"]["fields"]);
|
||||
array_splice($fields, array_search("data", $fields), 1);
|
||||
$allfields = DI::dbaDefinition()->getAll();
|
||||
$fields = array_keys($allfields['photo']['fields']);
|
||||
array_splice($fields, array_search('data', $fields), 1);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
@ -265,14 +265,14 @@ class Photo
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createPhotoForSystemResource($filename, $mimetype = '')
|
||||
public static function createPhotoForSystemResource(string $filename, string $mimetype = ''): array
|
||||
{
|
||||
if (empty($mimetype)) {
|
||||
$mimetype = Images::guessTypeByExtension($filename);
|
||||
}
|
||||
|
||||
$fields = self::getFields();
|
||||
$values = array_fill(0, count($fields), "");
|
||||
$values = array_fill(0, count($fields), '');
|
||||
|
||||
$photo = array_combine($fields, $values);
|
||||
$photo['backend-class'] = SystemResource::NAME;
|
||||
|
@ -293,14 +293,14 @@ class Photo
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createPhotoForExternalResource($url, $uid = 0, $mimetype = '')
|
||||
public static function createPhotoForExternalResource(string $url, int $uid = 0, string $mimetype = ''): array
|
||||
{
|
||||
if (empty($mimetype)) {
|
||||
$mimetype = Images::guessTypeByExtension($url);
|
||||
}
|
||||
|
||||
$fields = self::getFields();
|
||||
$values = array_fill(0, count($fields), "");
|
||||
$values = array_fill(0, count($fields), '');
|
||||
|
||||
$photo = array_combine($fields, $values);
|
||||
$photo['backend-class'] = ExternalResource::NAME;
|
||||
|
@ -314,14 +314,14 @@ class Photo
|
|||
/**
|
||||
* store photo metadata in db and binary in default backend
|
||||
*
|
||||
* @param Image $Image Image object with data
|
||||
* @param Image $image Image object with data
|
||||
* @param integer $uid User ID
|
||||
* @param integer $cid Contact ID
|
||||
* @param integer $rid Resource ID
|
||||
* @param string $rid Resource ID
|
||||
* @param string $filename Filename
|
||||
* @param string $album Album name
|
||||
* @param integer $scale Scale
|
||||
* @param integer $profile Is a profile image? optional, default = 0
|
||||
* @param integer $type Photo type, optional, default: Photo::DEFAULT
|
||||
* @param string $allow_cid Permissions, allowed contacts. optional, default = ""
|
||||
* @param string $allow_gid Permissions, allowed groups. optional, default = ""
|
||||
* @param string $deny_cid Permissions, denied contacts.optional, default = ""
|
||||
|
@ -331,71 +331,71 @@ class Photo
|
|||
* @return boolean True on success
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function store(Image $Image, $uid, $cid, $rid, $filename, $album, $scale, $type = self::DEFAULT, $allow_cid = "", $allow_gid = "", $deny_cid = "", $deny_gid = "", $desc = "")
|
||||
public static function store(Image $image, int $uid, int $cid, string $rid, string $filename, string $album, int $scale, int $type = self::DEFAULT, string $allow_cid = '', string $allow_gid = '', string $deny_cid = '', string $deny_gid = '', string $desc = ''): bool
|
||||
{
|
||||
$photo = self::selectFirst(["guid"], ["`resource-id` = ? AND `guid` != ?", $rid, ""]);
|
||||
$photo = self::selectFirst(['guid'], ["`resource-id` = ? AND `guid` != ?", $rid, '']);
|
||||
if (DBA::isResult($photo)) {
|
||||
$guid = $photo["guid"];
|
||||
$guid = $photo['guid'];
|
||||
} else {
|
||||
$guid = System::createGUID();
|
||||
}
|
||||
|
||||
$existing_photo = self::selectFirst(["id", "created", "backend-class", "backend-ref"], ["resource-id" => $rid, "uid" => $uid, "contact-id" => $cid, "scale" => $scale]);
|
||||
$existing_photo = self::selectFirst(['id', 'created', 'backend-class', 'backend-ref'], ['resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale]);
|
||||
$created = DateTimeFormat::utcNow();
|
||||
if (DBA::isResult($existing_photo)) {
|
||||
$created = $existing_photo["created"];
|
||||
$created = $existing_photo['created'];
|
||||
}
|
||||
|
||||
// Get defined storage backend.
|
||||
// if no storage backend, we use old "data" column in photo table.
|
||||
// if is an existing photo, reuse same backend
|
||||
$data = "";
|
||||
$backend_ref = "";
|
||||
$storage = "";
|
||||
$data = '';
|
||||
$backend_ref = '';
|
||||
$storage = '';
|
||||
|
||||
try {
|
||||
if (DBA::isResult($existing_photo)) {
|
||||
$backend_ref = (string)$existing_photo["backend-ref"];
|
||||
$storage = DI::storageManager()->getWritableStorageByName($existing_photo["backend-class"] ?? '');
|
||||
$backend_ref = (string)$existing_photo['backend-ref'];
|
||||
$storage = DI::storageManager()->getWritableStorageByName($existing_photo['backend-class'] ?? '');
|
||||
} else {
|
||||
$storage = DI::storage();
|
||||
}
|
||||
$backend_ref = $storage->put($Image->asString(), $backend_ref);
|
||||
$backend_ref = $storage->put($image->asString(), $backend_ref);
|
||||
} catch (InvalidClassStorageException $storageException) {
|
||||
$data = $Image->asString();
|
||||
$data = $image->asString();
|
||||
}
|
||||
|
||||
$fields = [
|
||||
"uid" => $uid,
|
||||
"contact-id" => $cid,
|
||||
"guid" => $guid,
|
||||
"resource-id" => $rid,
|
||||
"hash" => md5($Image->asString()),
|
||||
"created" => $created,
|
||||
"edited" => DateTimeFormat::utcNow(),
|
||||
"filename" => basename($filename),
|
||||
"type" => $Image->getType(),
|
||||
"album" => $album,
|
||||
"height" => $Image->getHeight(),
|
||||
"width" => $Image->getWidth(),
|
||||
"datasize" => strlen($Image->asString()),
|
||||
"data" => $data,
|
||||
"scale" => $scale,
|
||||
"photo-type" => $type,
|
||||
"profile" => false,
|
||||
"allow_cid" => $allow_cid,
|
||||
"allow_gid" => $allow_gid,
|
||||
"deny_cid" => $deny_cid,
|
||||
"deny_gid" => $deny_gid,
|
||||
"desc" => $desc,
|
||||
"backend-class" => (string)$storage,
|
||||
"backend-ref" => $backend_ref
|
||||
'uid' => $uid,
|
||||
'contact-id' => $cid,
|
||||
'guid' => $guid,
|
||||
'resource-id' => $rid,
|
||||
'hash' => md5($image->asString()),
|
||||
'created' => $created,
|
||||
'edited' => DateTimeFormat::utcNow(),
|
||||
'filename' => basename($filename),
|
||||
'type' => $image->getType(),
|
||||
'album' => $album,
|
||||
'height' => $image->getHeight(),
|
||||
'width' => $image->getWidth(),
|
||||
'datasize' => strlen($image->asString()),
|
||||
'data' => $data,
|
||||
'scale' => $scale,
|
||||
'photo-type' => $type,
|
||||
'profile' => false,
|
||||
'allow_cid' => $allow_cid,
|
||||
'allow_gid' => $allow_gid,
|
||||
'deny_cid' => $deny_cid,
|
||||
'deny_gid' => $deny_gid,
|
||||
'desc' => $desc,
|
||||
'backend-class' => (string)$storage,
|
||||
'backend-ref' => $backend_ref
|
||||
];
|
||||
|
||||
if (DBA::isResult($existing_photo)) {
|
||||
$r = DBA::update("photo", $fields, ["id" => $existing_photo["id"]]);
|
||||
$r = DBA::update('photo', $fields, ['id' => $existing_photo['id']]);
|
||||
} else {
|
||||
$r = DBA::insert("photo", $fields);
|
||||
$r = DBA::insert('photo', $fields);
|
||||
}
|
||||
|
||||
return $r;
|
||||
|
@ -413,7 +413,7 @@ class Photo
|
|||
* @throws \Exception
|
||||
* @see \Friendica\Database\DBA::delete
|
||||
*/
|
||||
public static function delete(array $conditions, array $options = [])
|
||||
public static function delete(array $conditions, array $options = []): bool
|
||||
{
|
||||
// get photo to delete data info
|
||||
$photos = DBA::select('photo', ['id', 'backend-class', 'backend-ref'], $conditions);
|
||||
|
@ -423,7 +423,7 @@ class Photo
|
|||
$backend_class = DI::storageManager()->getWritableStorageByName($photo['backend-class'] ?? '');
|
||||
$backend_class->delete($photo['backend-ref'] ?? '');
|
||||
// Delete the photos after they had been deleted successfully
|
||||
DBA::delete("photo", ['id' => $photo['id']]);
|
||||
DBA::delete('photo', ['id' => $photo['id']]);
|
||||
} catch (InvalidClassStorageException $storageException) {
|
||||
DI::logger()->debug('Storage class not found.', ['conditions' => $conditions, 'exception' => $storageException]);
|
||||
} catch (ReferenceStorageException $referenceStorageException) {
|
||||
|
@ -433,34 +433,34 @@ class Photo
|
|||
|
||||
DBA::close($photos);
|
||||
|
||||
return DBA::delete("photo", $conditions, $options);
|
||||
return DBA::delete('photo', $conditions, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a photo
|
||||
*
|
||||
* @param array $fields Contains the fields that are updated
|
||||
* @param array $conditions Condition array with the key values
|
||||
* @param Image $img Image to update. Optional, default null.
|
||||
* @param array|boolean $old_fields Array with the old field values that are about to be replaced (true = update on duplicate)
|
||||
* @param array $fields Contains the fields that are updated
|
||||
* @param array $conditions Condition array with the key values
|
||||
* @param Image $image Image to update. Optional, default null.
|
||||
* @param array $old_fields Array with the old field values that are about to be replaced (true = update on duplicate)
|
||||
*
|
||||
* @return boolean Was the update successfull?
|
||||
*
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @see \Friendica\Database\DBA::update
|
||||
*/
|
||||
public static function update($fields, $conditions, Image $img = null, array $old_fields = [])
|
||||
public static function update(array $fields, array $conditions, Image $image = null, array $old_fields = []): bool
|
||||
{
|
||||
if (!is_null($img)) {
|
||||
if (!is_null($image)) {
|
||||
// get photo to update
|
||||
$photos = self::selectToArray(['backend-class', 'backend-ref'], $conditions);
|
||||
|
||||
foreach($photos as $photo) {
|
||||
try {
|
||||
$backend_class = DI::storageManager()->getWritableStorageByName($photo['backend-class'] ?? '');
|
||||
$fields["backend-ref"] = $backend_class->put($img->asString(), $photo['backend-ref']);
|
||||
$fields['backend-ref'] = $backend_class->put($image->asString(), $photo['backend-ref']);
|
||||
} catch (InvalidClassStorageException $storageException) {
|
||||
$fields["data"] = $img->asString();
|
||||
$fields['data'] = $image->asString();
|
||||
}
|
||||
}
|
||||
$fields['updated'] = DateTimeFormat::utcNow();
|
||||
|
@ -468,7 +468,7 @@ class Photo
|
|||
|
||||
$fields['edited'] = DateTimeFormat::utcNow();
|
||||
|
||||
return DBA::update("photo", $fields, $conditions, $old_fields);
|
||||
return DBA::update('photo', $fields, $conditions, $old_fields);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -476,20 +476,20 @@ class Photo
|
|||
* @param integer $uid user id
|
||||
* @param integer $cid contact id
|
||||
* @param boolean $quit_on_error optional, default false
|
||||
* @return array
|
||||
* @return array|bool Array on success, false on error
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function importProfilePhoto($image_url, $uid, $cid, $quit_on_error = false)
|
||||
public static function importProfilePhoto(string $image_url, int $uid, int $cid, bool $quit_on_error = false)
|
||||
{
|
||||
$thumb = "";
|
||||
$micro = "";
|
||||
$thumb = '';
|
||||
$micro = '';
|
||||
|
||||
$photo = DBA::selectFirst(
|
||||
"photo", ["resource-id"], ["uid" => $uid, "contact-id" => $cid, "scale" => 4, "photo-type" => self::CONTACT_AVATAR]
|
||||
'photo', ['resource-id'], ['uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'photo-type' => self::CONTACT_AVATAR]
|
||||
);
|
||||
if (!empty($photo['resource-id'])) {
|
||||
$resource_id = $photo["resource-id"];
|
||||
$resource_id = $photo['resource-id'];
|
||||
} else {
|
||||
$resource_id = self::newResource();
|
||||
}
|
||||
|
@ -507,66 +507,66 @@ class Photo
|
|||
$type = '';
|
||||
}
|
||||
|
||||
if ($quit_on_error && ($img_str == "")) {
|
||||
if ($quit_on_error && ($img_str == '')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = Images::getMimeTypeByData($img_str, $image_url, $type);
|
||||
|
||||
$Image = new Image($img_str, $type);
|
||||
if ($Image->isValid()) {
|
||||
$Image->scaleToSquare(300);
|
||||
$image = new Image($img_str, $type);
|
||||
if ($image->isValid()) {
|
||||
$image->scaleToSquare(300);
|
||||
|
||||
$filesize = strlen($Image->asString());
|
||||
$filesize = strlen($image->asString());
|
||||
$maximagesize = DI::config()->get('system', 'maximagesize');
|
||||
if (!empty($maximagesize) && ($filesize > $maximagesize)) {
|
||||
Logger::info('Avatar exceeds image limit', ['uid' => $uid, 'cid' => $cid, 'maximagesize' => $maximagesize, 'size' => $filesize, 'type' => $Image->getType()]);
|
||||
if ($Image->getType() == 'image/gif') {
|
||||
$Image->toStatic();
|
||||
$Image = new Image($Image->asString(), 'image/png');
|
||||
Logger::info('Avatar exceeds image limit', ['uid' => $uid, 'cid' => $cid, 'maximagesize' => $maximagesize, 'size' => $filesize, 'type' => $image->getType()]);
|
||||
if ($image->getType() == 'image/gif') {
|
||||
$image->toStatic();
|
||||
$image = new Image($image->asString(), 'image/png');
|
||||
|
||||
$filesize = strlen($Image->asString());
|
||||
Logger::info('Converted gif to a static png', ['uid' => $uid, 'cid' => $cid, 'size' => $filesize, 'type' => $Image->getType()]);
|
||||
$filesize = strlen($image->asString());
|
||||
Logger::info('Converted gif to a static png', ['uid' => $uid, 'cid' => $cid, 'size' => $filesize, 'type' => $image->getType()]);
|
||||
}
|
||||
if ($filesize > $maximagesize) {
|
||||
foreach ([160, 80] as $pixels) {
|
||||
if ($filesize > $maximagesize) {
|
||||
Logger::info('Resize', ['uid' => $uid, 'cid' => $cid, 'size' => $filesize, 'max' => $maximagesize, 'pixels' => $pixels, 'type' => $Image->getType()]);
|
||||
$Image->scaleDown($pixels);
|
||||
$filesize = strlen($Image->asString());
|
||||
Logger::info('Resize', ['uid' => $uid, 'cid' => $cid, 'size' => $filesize, 'max' => $maximagesize, 'pixels' => $pixels, 'type' => $image->getType()]);
|
||||
$image->scaleDown($pixels);
|
||||
$filesize = strlen($image->asString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Logger::info('Avatar is resized', ['uid' => $uid, 'cid' => $cid, 'size' => $filesize, 'type' => $Image->getType()]);
|
||||
Logger::info('Avatar is resized', ['uid' => $uid, 'cid' => $cid, 'size' => $filesize, 'type' => $image->getType()]);
|
||||
}
|
||||
|
||||
$r = self::store($Image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 4, self::CONTACT_AVATAR);
|
||||
$r = self::store($image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 4, self::CONTACT_AVATAR);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
}
|
||||
|
||||
$Image->scaleDown(80);
|
||||
$image->scaleDown(80);
|
||||
|
||||
$r = self::store($Image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 5, self::CONTACT_AVATAR);
|
||||
$r = self::store($image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 5, self::CONTACT_AVATAR);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
}
|
||||
|
||||
$Image->scaleDown(48);
|
||||
$image->scaleDown(48);
|
||||
|
||||
$r = self::store($Image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 6, self::CONTACT_AVATAR);
|
||||
$r = self::store($image, $uid, $cid, $resource_id, $filename, self::CONTACT_PHOTOS, 6, self::CONTACT_AVATAR);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
}
|
||||
|
||||
$suffix = "?ts=" . time();
|
||||
$suffix = '?ts=' . time();
|
||||
|
||||
$image_url = DI::baseUrl() . "/photo/" . $resource_id . "-4." . $Image->getExt() . $suffix;
|
||||
$thumb = DI::baseUrl() . "/photo/" . $resource_id . "-5." . $Image->getExt() . $suffix;
|
||||
$micro = DI::baseUrl() . "/photo/" . $resource_id . "-6." . $Image->getExt() . $suffix;
|
||||
$image_url = DI::baseUrl() . '/photo/' . $resource_id . '-4.' . $image->getExt() . $suffix;
|
||||
$thumb = DI::baseUrl() . '/photo/' . $resource_id . '-5.' . $image->getExt() . $suffix;
|
||||
$micro = DI::baseUrl() . '/photo/' . $resource_id . '-6.' . $image->getExt() . $suffix;
|
||||
} else {
|
||||
$photo_failure = true;
|
||||
}
|
||||
|
@ -586,35 +586,39 @@ class Photo
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a float that represents the GPS coordinate from EXIF data
|
||||
*
|
||||
* @param array $exifCoord coordinate
|
||||
* @param string $hemi hemi
|
||||
* @return float
|
||||
*/
|
||||
public static function getGps($exifCoord, $hemi)
|
||||
public static function getGps(array $exifCoord, string $hemi): float
|
||||
{
|
||||
$degrees = count($exifCoord) > 0 ? self::gps2Num($exifCoord[0]) : 0;
|
||||
$minutes = count($exifCoord) > 1 ? self::gps2Num($exifCoord[1]) : 0;
|
||||
$seconds = count($exifCoord) > 2 ? self::gps2Num($exifCoord[2]) : 0;
|
||||
|
||||
$flip = ($hemi == "W" || $hemi == "S") ? -1 : 1;
|
||||
$flip = ($hemi == 'W' || $hemi == 'S') ? -1 : 1;
|
||||
|
||||
return floatval($flip * ($degrees + ($minutes / 60) + ($seconds / 3600)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Change GPS to float number
|
||||
*
|
||||
* @param string $coordPart coordPart
|
||||
* @return float
|
||||
*/
|
||||
private static function gps2Num($coordPart)
|
||||
private static function gps2Num(string $coordPart): float
|
||||
{
|
||||
$parts = explode("/", $coordPart);
|
||||
$parts = explode('/', $coordPart);
|
||||
|
||||
if (count($parts) <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (count($parts) == 1) {
|
||||
return $parts[0];
|
||||
return (float)$parts[0];
|
||||
}
|
||||
|
||||
return floatval($parts[0]) / floatval($parts[1]);
|
||||
|
@ -631,17 +635,18 @@ class Photo
|
|||
* @return array Returns array of the photo albums
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function getAlbums($uid, $update = false)
|
||||
public static function getAlbums(int $uid, bool $update = false): array
|
||||
{
|
||||
$sql_extra = Security::getPermissionsSQLByUserId($uid);
|
||||
|
||||
$avatar_type = (local_user() && (local_user() == $uid)) ? self::USER_AVATAR : self::DEFAULT;
|
||||
$banner_type = (local_user() && (local_user() == $uid)) ? self::USER_BANNER : self::DEFAULT;
|
||||
|
||||
$key = "photo_albums:".$uid.":".local_user().":".remote_user();
|
||||
$key = 'photo_albums:' . $uid . ':' . local_user() . ':' . remote_user();
|
||||
$albums = DI::cache()->get($key);
|
||||
|
||||
if (is_null($albums) || $update) {
|
||||
if (!DI::config()->get("system", "no_count", false)) {
|
||||
if (!DI::config()->get('system', 'no_count', false)) {
|
||||
/// @todo This query needs to be renewed. It is really slow
|
||||
// At this time we just store the data in the cache
|
||||
$albums = DBA::toArray(DBA::p("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`, ANY_VALUE(`created`) AS `created`
|
||||
|
@ -674,19 +679,19 @@ class Photo
|
|||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function clearAlbumCache($uid)
|
||||
public static function clearAlbumCache(int $uid)
|
||||
{
|
||||
$key = "photo_albums:".$uid.":".local_user().":".remote_user();
|
||||
$key = 'photo_albums:' . $uid . ':' . local_user() . ':' . remote_user();
|
||||
DI::cache()->set($key, null, Duration::DAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique photo ID.
|
||||
*
|
||||
* @return string
|
||||
* @return string Resource GUID
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function newResource()
|
||||
public static function newResource(): string
|
||||
{
|
||||
return System::createGUID(32, false);
|
||||
}
|
||||
|
@ -697,7 +702,7 @@ class Photo
|
|||
* @param string $image_uri The URI of the photo
|
||||
* @return string The rid of the photo, or an empty string if the URI is not local
|
||||
*/
|
||||
public static function ridFromURI(string $image_uri)
|
||||
public static function ridFromURI(string $image_uri): string
|
||||
{
|
||||
if (!stristr($image_uri, DI::baseUrl() . '/photo/')) {
|
||||
return '';
|
||||
|
@ -809,7 +814,7 @@ class Photo
|
|||
* @param string $name Picture link
|
||||
* @return array
|
||||
*/
|
||||
public static function getResourceData(string $name):array
|
||||
public static function getResourceData(string $name): array
|
||||
{
|
||||
$base = DI::baseUrl()->get();
|
||||
|
||||
|
@ -840,8 +845,9 @@ class Photo
|
|||
* @return boolean
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function isLocal($name)
|
||||
public static function isLocal(string $name): bool
|
||||
{
|
||||
// @TODO Maybe a proper check here on true condition?
|
||||
return (bool)self::getIdForName($name);
|
||||
}
|
||||
|
||||
|
@ -851,7 +857,7 @@ class Photo
|
|||
* @param string $name Picture link
|
||||
* @return int
|
||||
*/
|
||||
public static function getIdForName($name)
|
||||
public static function getIdForName(string $name): int
|
||||
{
|
||||
$data = self::getResourceData($name);
|
||||
if (empty($data)) {
|
||||
|
@ -872,7 +878,7 @@ class Photo
|
|||
* @return boolean
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function isLocalPage($name)
|
||||
public static function isLocalPage(string $name): bool
|
||||
{
|
||||
$base = DI::baseUrl()->get();
|
||||
|
||||
|
@ -885,17 +891,23 @@ class Photo
|
|||
return DBA::exists('photo', ['resource-id' => $guid]);
|
||||
}
|
||||
|
||||
private static function fitImageSize($Image)
|
||||
/**
|
||||
* Tries to resize image to wanted maximum size
|
||||
*
|
||||
* @param Image $image Image instance
|
||||
* @return Image|null Image instance on success, null on error
|
||||
*/
|
||||
private static function fitImageSize(Image $image)
|
||||
{
|
||||
$max_length = DI::config()->get('system', 'max_image_length');
|
||||
if ($max_length > 0) {
|
||||
$Image->scaleDown($max_length);
|
||||
$image->scaleDown($max_length);
|
||||
Logger::info('File upload: Scaling picture to new size', ['max-length' => $max_length]);
|
||||
}
|
||||
|
||||
$filesize = strlen($Image->asString());
|
||||
$width = $Image->getWidth();
|
||||
$height = $Image->getHeight();
|
||||
$filesize = strlen($image->asString());
|
||||
$width = $image->getWidth();
|
||||
$height = $image->getHeight();
|
||||
|
||||
$maximagesize = DI::config()->get('system', 'maximagesize');
|
||||
|
||||
|
@ -904,10 +916,10 @@ class Photo
|
|||
foreach ([5120, 2560, 1280, 640] as $pixels) {
|
||||
if (($filesize > $maximagesize) && (max($width, $height) > $pixels)) {
|
||||
Logger::info('Resize', ['size' => $filesize, 'width' => $width, 'height' => $height, 'max' => $maximagesize, 'pixels' => $pixels]);
|
||||
$Image->scaleDown($pixels);
|
||||
$filesize = strlen($Image->asString());
|
||||
$width = $Image->getWidth();
|
||||
$height = $Image->getHeight();
|
||||
$image->scaleDown($pixels);
|
||||
$filesize = strlen($image->asString());
|
||||
$width = $image->getWidth();
|
||||
$height = $image->getHeight();
|
||||
}
|
||||
}
|
||||
if ($filesize > $maximagesize) {
|
||||
|
@ -916,10 +928,16 @@ class Photo
|
|||
}
|
||||
}
|
||||
|
||||
return $Image;
|
||||
return $image;
|
||||
}
|
||||
|
||||
private static function loadImageFromURL(string $image_url)
|
||||
/**
|
||||
* Fetches image from URL and returns an array with instance and local file name
|
||||
*
|
||||
* @param string $image_url URL to image
|
||||
* @return array With: 'image' and 'filename' fields or empty array on error
|
||||
*/
|
||||
private static function loadImageFromURL(string $image_url): array
|
||||
{
|
||||
$filename = basename($image_url);
|
||||
if (!empty($image_url)) {
|
||||
|
@ -939,17 +957,23 @@ class Photo
|
|||
|
||||
$type = Images::getMimeTypeByData($img_str, $image_url, $type);
|
||||
|
||||
$Image = new Image($img_str, $type);
|
||||
$image = new Image($img_str, $type);
|
||||
|
||||
$Image = self::fitImageSize($Image);
|
||||
if (empty($Image)) {
|
||||
$image = self::fitImageSize($image);
|
||||
if (empty($image)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return ['image' => $Image, 'filename' => $filename];
|
||||
return ['image' => $image, 'filename' => $filename];
|
||||
}
|
||||
|
||||
private static function uploadImage(array $files)
|
||||
/**
|
||||
* Inserts uploaded image into database and removes local temporary file
|
||||
*
|
||||
* @param array $files File array
|
||||
* @return array With 'image' for Image instance and 'filename' for local file name or empty array on error
|
||||
*/
|
||||
private static function uploadImage(array $files): array
|
||||
{
|
||||
Logger::info('starting new upload');
|
||||
|
||||
|
@ -1008,34 +1032,36 @@ class Photo
|
|||
Logger::info('File upload', ['src' => $src, 'filename' => $filename, 'size' => $filesize, 'type' => $filetype]);
|
||||
|
||||
$imagedata = @file_get_contents($src);
|
||||
$Image = new Image($imagedata, $filetype);
|
||||
if (!$Image->isValid()) {
|
||||
$image = new Image($imagedata, $filetype);
|
||||
if (!$image->isValid()) {
|
||||
Logger::notice('Image is unvalid', ['files' => $files]);
|
||||
return [];
|
||||
}
|
||||
|
||||
$Image->orient($src);
|
||||
$image->orient($src);
|
||||
@unlink($src);
|
||||
|
||||
$Image = self::fitImageSize($Image);
|
||||
if (empty($Image)) {
|
||||
$image = self::fitImageSize($image);
|
||||
if (empty($image)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return ['image' => $Image, 'filename' => $filename];
|
||||
return ['image' => $image, 'filename' => $filename];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles uploaded image and assigns it to given user id
|
||||
*
|
||||
* @param int $uid User ID
|
||||
* @param array $files uploaded file array
|
||||
* @param string $album
|
||||
* @param string $album Album name (optional)
|
||||
* @param string|null $allow_cid
|
||||
* @param string|null $allow_gid
|
||||
* @param string $deny_cid
|
||||
* @param string $deny_gid
|
||||
* @param string $desc
|
||||
* @param string $resource_id
|
||||
* @return array photo record
|
||||
* @param string $desc Description (optional)
|
||||
* @param string $resource_id GUID (optional)
|
||||
* @return array photo record or empty array on error
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function upload(int $uid, array $files, string $album = '', string $allow_cid = null, string $allow_gid = null, string $deny_cid = '', string $deny_gid = '', string $desc = '', string $resource_id = ''): array
|
||||
|
@ -1052,10 +1078,10 @@ class Photo
|
|||
return [];
|
||||
}
|
||||
|
||||
$Image = $data['image'];
|
||||
$image = $data['image'];
|
||||
$filename = $data['filename'];
|
||||
$width = $Image->getWidth();
|
||||
$height = $Image->getHeight();
|
||||
$width = $image->getWidth();
|
||||
$height = $image->getHeight();
|
||||
|
||||
$resource_id = $resource_id ?: self::newResource();
|
||||
$album = $album ?: DI::l10n()->t('Wall Photos');
|
||||
|
@ -1067,23 +1093,23 @@ class Photo
|
|||
|
||||
$smallest = 0;
|
||||
|
||||
$r = self::store($Image, $user['uid'], 0, $resource_id, $filename, $album, 0, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$r = self::store($image, $user['uid'], 0, $resource_id, $filename, $album, 0, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if (!$r) {
|
||||
Logger::notice('Photo could not be stored');
|
||||
return [];
|
||||
}
|
||||
|
||||
if ($width > 640 || $height > 640) {
|
||||
$Image->scaleDown(640);
|
||||
$r = self::store($Image, $user['uid'], 0, $resource_id, $filename, $album, 1, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$image->scaleDown(640);
|
||||
$r = self::store($image, $user['uid'], 0, $resource_id, $filename, $album, 1, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if ($r) {
|
||||
$smallest = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($width > 320 || $height > 320) {
|
||||
$Image->scaleDown(320);
|
||||
$r = self::store($Image, $user['uid'], 0, $resource_id, $filename, $album, 2, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
$image->scaleDown(320);
|
||||
$r = self::store($image, $user['uid'], 0, $resource_id, $filename, $album, 2, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
|
||||
if ($r && ($smallest == 0)) {
|
||||
$smallest = 2;
|
||||
}
|
||||
|
@ -1105,8 +1131,8 @@ class Photo
|
|||
$picture['height'] = $photo['height'];
|
||||
$picture['type'] = $photo['type'];
|
||||
$picture['albumpage'] = DI::baseUrl() . '/photos/' . $user['nickname'] . '/image/' . $resource_id;
|
||||
$picture['picture'] = DI::baseUrl() . '/photo/{$resource_id}-0.' . $Image->getExt();
|
||||
$picture['preview'] = DI::baseUrl() . '/photo/{$resource_id}-{$smallest}.' . $Image->getExt();
|
||||
$picture['picture'] = DI::baseUrl() . '/photo/{$resource_id}-0.' . $image->getExt();
|
||||
$picture['preview'] = DI::baseUrl() . '/photo/{$resource_id}-{$smallest}.' . $image->getExt();
|
||||
|
||||
Logger::info('upload done', ['picture' => $picture]);
|
||||
return $picture;
|
||||
|
@ -1139,10 +1165,10 @@ class Photo
|
|||
return '';
|
||||
}
|
||||
|
||||
$Image = $data['image'];
|
||||
$image = $data['image'];
|
||||
$filename = $data['filename'];
|
||||
$width = $Image->getWidth();
|
||||
$height = $Image->getHeight();
|
||||
$width = $image->getWidth();
|
||||
$height = $image->getHeight();
|
||||
|
||||
$resource_id = self::newResource();
|
||||
$album = DI::l10n()->t(self::PROFILE_PHOTOS);
|
||||
|
@ -1151,28 +1177,28 @@ class Photo
|
|||
logger::info('starting new profile image upload');
|
||||
|
||||
if ($width > 300 || $height > 300) {
|
||||
$Image->scaleDown(300);
|
||||
$image->scaleDown(300);
|
||||
}
|
||||
|
||||
$r = self::store($Image, $uid, 0, $resource_id, $filename, $album, 4, self::USER_AVATAR);
|
||||
$r = self::store($image, $uid, 0, $resource_id, $filename, $album, 4, self::USER_AVATAR);
|
||||
if (!$r) {
|
||||
logger::notice('profile image upload with scale 4 (300) failed');
|
||||
}
|
||||
|
||||
if ($width > 80 || $height > 80) {
|
||||
$Image->scaleDown(80);
|
||||
$image->scaleDown(80);
|
||||
}
|
||||
|
||||
$r = self::store($Image, $uid, 0, $resource_id, $filename, $album, 5, self::USER_AVATAR);
|
||||
$r = self::store($image, $uid, 0, $resource_id, $filename, $album, 5, self::USER_AVATAR);
|
||||
if (!$r) {
|
||||
logger::notice('profile image upload with scale 5 (80) failed');
|
||||
}
|
||||
|
||||
if ($width > 48 || $height > 48) {
|
||||
$Image->scaleDown(48);
|
||||
$image->scaleDown(48);
|
||||
}
|
||||
|
||||
$r = self::store($Image, $uid, 0, $resource_id, $filename, $album, 6, self::USER_AVATAR);
|
||||
$r = self::store($image, $uid, 0, $resource_id, $filename, $album, 6, self::USER_AVATAR);
|
||||
if (!$r) {
|
||||
logger::notice('profile image upload with scale 6 (48) failed');
|
||||
}
|
||||
|
@ -1217,19 +1243,19 @@ class Photo
|
|||
return '';
|
||||
}
|
||||
|
||||
$Image = $data['image'];
|
||||
$image = $data['image'];
|
||||
$filename = $data['filename'];
|
||||
$width = $Image->getWidth();
|
||||
$height = $Image->getHeight();
|
||||
$width = $image->getWidth();
|
||||
$height = $image->getHeight();
|
||||
|
||||
$resource_id = self::newResource();
|
||||
$album = DI::l10n()->t(self::BANNER_PHOTOS);
|
||||
|
||||
if ($width > 960) {
|
||||
$Image->scaleDown(960);
|
||||
$image->scaleDown(960);
|
||||
}
|
||||
|
||||
$r = self::store($Image, $uid, 0, $resource_id, $filename, $album, 3, self::USER_BANNER);
|
||||
$r = self::store($image, $uid, 0, $resource_id, $filename, $album, 3, self::USER_BANNER);
|
||||
if (!$r) {
|
||||
logger::notice('profile banner upload with scale 3 (960) failed');
|
||||
}
|
||||
|
@ -1247,3 +1273,4 @@ class Photo
|
|||
return $resource_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ use Friendica\Core\System;
|
|||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
use Friendica\Protocol\Activity;
|
||||
|
||||
class Post
|
||||
|
@ -39,13 +40,13 @@ class Post
|
|||
* @return int ID of inserted post
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function insert(int $uri_id, array $data = [])
|
||||
public static function insert(int $uri_id, array $data = []): int
|
||||
{
|
||||
if (empty($uri_id)) {
|
||||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post', $data);
|
||||
|
||||
// Additionally assign the key fields
|
||||
$fields['uri-id'] = $uri_id;
|
||||
|
@ -107,8 +108,10 @@ class Post
|
|||
* @param object $stmt statement object
|
||||
* @param bool $do_close
|
||||
* @return array Data array
|
||||
* @todo Find proper type-hint for $stmt and maybe avoid boolean
|
||||
*/
|
||||
public static function toArray($stmt, $do_close = true) {
|
||||
public static function toArray($stmt, bool $do_close = true)
|
||||
{
|
||||
if (is_bool($stmt)) {
|
||||
return $stmt;
|
||||
}
|
||||
|
@ -131,7 +134,8 @@ class Post
|
|||
* @return boolean Are there rows for that condition?
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function exists($condition) {
|
||||
public static function exists(array $condition): bool
|
||||
{
|
||||
return DBA::exists('post-user-view', $condition);
|
||||
}
|
||||
|
||||
|
@ -151,7 +155,7 @@ class Post
|
|||
* $count = Post::count($condition);
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function count(array $condition = [], array $params = [])
|
||||
public static function count(array $condition = [], array $params = []): int
|
||||
{
|
||||
return DBA::count('post-user-view', $condition, $params);
|
||||
}
|
||||
|
@ -172,7 +176,7 @@ class Post
|
|||
* $count = Post::count($condition);
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function countThread(array $condition = [], array $params = [])
|
||||
public static function countThread(array $condition = [], array $params = []): int
|
||||
{
|
||||
return DBA::count('post-thread-user-view', $condition, $params);
|
||||
}
|
||||
|
@ -193,7 +197,7 @@ class Post
|
|||
* $count = Post::count($condition);
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function countPosts(array $condition = [], array $params = [])
|
||||
public static function countPosts(array $condition = [], array $params = []): int
|
||||
{
|
||||
return DBA::count('post-view', $condition, $params);
|
||||
}
|
||||
|
@ -209,7 +213,7 @@ class Post
|
|||
* @throws \Exception
|
||||
* @see DBA::select
|
||||
*/
|
||||
public static function selectFirst(array $fields = [], array $condition = [], $params = [])
|
||||
public static function selectFirst(array $fields = [], array $condition = [], array $params = [])
|
||||
{
|
||||
$params['limit'] = 1;
|
||||
|
||||
|
@ -234,7 +238,7 @@ class Post
|
|||
* @throws \Exception
|
||||
* @see DBA::select
|
||||
*/
|
||||
public static function selectFirstPost(array $fields = [], array $condition = [], $params = [])
|
||||
public static function selectFirstPost(array $fields = [], array $condition = [], array $params = [])
|
||||
{
|
||||
$params['limit'] = 1;
|
||||
|
||||
|
@ -259,7 +263,7 @@ class Post
|
|||
* @throws \Exception
|
||||
* @see DBA::select
|
||||
*/
|
||||
public static function selectFirstThread(array $fields = [], array $condition = [], $params = [])
|
||||
public static function selectFirstThread(array $fields = [], array $condition = [], array $params = [])
|
||||
{
|
||||
$params['limit'] = 1;
|
||||
|
||||
|
@ -284,7 +288,7 @@ class Post
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function selectToArray(array $fields = [], array $condition = [], $params = [])
|
||||
public static function selectToArray(array $fields = [], array $condition = [], array $params = [])
|
||||
{
|
||||
$result = self::select($fields, $condition, $params);
|
||||
|
||||
|
@ -312,7 +316,7 @@ class Post
|
|||
* @return boolean|object
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function selectView(string $view, array $selected = [], array $condition = [], $params = [])
|
||||
private static function selectView(string $view, array $selected = [], array $condition = [], array $params = [])
|
||||
{
|
||||
if (empty($selected)) {
|
||||
$selected = array_merge(Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST);
|
||||
|
@ -337,7 +341,7 @@ class Post
|
|||
* @return boolean|object
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function select(array $selected = [], array $condition = [], $params = [])
|
||||
public static function select(array $selected = [], array $condition = [], array $params = [])
|
||||
{
|
||||
return self::selectView('post-user-view', $selected, $condition, $params);
|
||||
}
|
||||
|
@ -352,7 +356,7 @@ class Post
|
|||
* @return boolean|object
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function selectPosts(array $selected = [], array $condition = [], $params = [])
|
||||
public static function selectPosts(array $selected = [], array $condition = [], array $params = [])
|
||||
{
|
||||
return self::selectView('post-view', $selected, $condition, $params);
|
||||
}
|
||||
|
@ -367,7 +371,7 @@ class Post
|
|||
* @return boolean|object
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function selectThread(array $selected = [], array $condition = [], $params = [])
|
||||
public static function selectThread(array $selected = [], array $condition = [], array $params = [])
|
||||
{
|
||||
return self::selectView('post-thread-user-view', $selected, $condition, $params);
|
||||
}
|
||||
|
@ -384,7 +388,7 @@ class Post
|
|||
* @return boolean|object
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function selectViewForUser(string $view, $uid, array $selected = [], array $condition = [], $params = [])
|
||||
private static function selectViewForUser(string $view, int $uid, array $selected = [], array $condition = [], array $params = [])
|
||||
{
|
||||
if (empty($selected)) {
|
||||
$selected = Item::DISPLAY_FIELDLIST;
|
||||
|
@ -425,7 +429,7 @@ class Post
|
|||
* @return boolean|object
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function selectForUser($uid, array $selected = [], array $condition = [], $params = [])
|
||||
public static function selectForUser(int $uid, array $selected = [], array $condition = [], array $params = [])
|
||||
{
|
||||
return self::selectViewForUser('post-user-view', $uid, $selected, $condition, $params);
|
||||
}
|
||||
|
@ -441,7 +445,7 @@ class Post
|
|||
* @return boolean|object
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function selectPostsForUser($uid, array $selected = [], array $condition = [], $params = [])
|
||||
public static function selectPostsForUser(int $uid, array $selected = [], array $condition = [], array $params = [])
|
||||
{
|
||||
return self::selectViewForUser('post-view', $uid, $selected, $condition, $params);
|
||||
}
|
||||
|
@ -457,7 +461,7 @@ class Post
|
|||
* @return boolean|object
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function selectThreadForUser($uid, array $selected = [], array $condition = [], $params = [])
|
||||
public static function selectThreadForUser(int $uid, array $selected = [], array $condition = [], array $params = [])
|
||||
{
|
||||
return self::selectViewForUser('post-thread-user-view', $uid, $selected, $condition, $params);
|
||||
}
|
||||
|
@ -473,7 +477,7 @@ class Post
|
|||
* @throws \Exception
|
||||
* @see DBA::select
|
||||
*/
|
||||
public static function selectFirstForUser($uid, array $selected = [], array $condition = [], $params = [])
|
||||
public static function selectFirstForUser(int $uid, array $selected = [], array $condition = [], array $params = [])
|
||||
{
|
||||
$params['limit'] = 1;
|
||||
|
||||
|
@ -521,7 +525,7 @@ class Post
|
|||
// To ensure the data integrity we do it in an transaction
|
||||
DBA::transaction();
|
||||
|
||||
$update_fields = DBStructure::getFieldsForTable('post-user', $fields);
|
||||
$update_fields = DI::dbaDefinition()->truncateFieldsForTable('post-user', $fields);
|
||||
if (!empty($update_fields)) {
|
||||
$affected_count = 0;
|
||||
$posts = DBA::select('post-user-view', ['post-user-id'], $condition);
|
||||
|
@ -538,7 +542,7 @@ class Post
|
|||
$affected = $affected_count;
|
||||
}
|
||||
|
||||
$update_fields = DBStructure::getFieldsForTable('post-content', $fields);
|
||||
$update_fields = DI::dbaDefinition()->truncateFieldsForTable('post-content', $fields);
|
||||
if (!empty($update_fields)) {
|
||||
$affected_count = 0;
|
||||
$posts = DBA::select('post-user-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
|
||||
|
@ -555,7 +559,7 @@ class Post
|
|||
$affected = max($affected, $affected_count);
|
||||
}
|
||||
|
||||
$update_fields = DBStructure::getFieldsForTable('post', $fields);
|
||||
$update_fields = DI::dbaDefinition()->truncateFieldsForTable('post', $fields);
|
||||
if (!empty($update_fields)) {
|
||||
$affected_count = 0;
|
||||
$posts = DBA::select('post-user-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
|
||||
|
@ -589,7 +593,7 @@ class Post
|
|||
$affected = max($affected, $affected_count);
|
||||
}
|
||||
|
||||
$update_fields = DBStructure::getFieldsForTable('post-thread', $fields);
|
||||
$update_fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread', $fields);
|
||||
if (!empty($update_fields)) {
|
||||
$affected_count = 0;
|
||||
$posts = DBA::select('post-user-view', ['uri-id'], $thread_condition, ['group_by' => ['uri-id']]);
|
||||
|
@ -606,7 +610,7 @@ class Post
|
|||
$affected = max($affected, $affected_count);
|
||||
}
|
||||
|
||||
$update_fields = DBStructure::getFieldsForTable('post-thread-user', $fields);
|
||||
$update_fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread-user', $fields);
|
||||
if (!empty($update_fields)) {
|
||||
$affected_count = 0;
|
||||
$posts = DBA::select('post-user-view', ['post-user-id'], $thread_condition);
|
||||
|
@ -640,7 +644,7 @@ class Post
|
|||
* @return boolean was the delete successful?
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function delete(array $conditions, array $options = [])
|
||||
public static function delete(array $conditions, array $options = []): bool
|
||||
{
|
||||
return DBA::delete('post', $conditions, $options);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ use Friendica\Core\Protocol;
|
|||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
|
||||
class Content
|
||||
|
@ -44,7 +45,7 @@ class Content
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-content', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-content', $data);
|
||||
|
||||
// Additionally assign the key fields
|
||||
$fields['uri-id'] = $uri_id;
|
||||
|
@ -67,7 +68,7 @@ class Content
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-content', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-content', $data);
|
||||
|
||||
// Remove the key fields
|
||||
unset($fields['uri-id']);
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Friendica\Model\Post;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
|
||||
class History
|
||||
|
@ -37,7 +37,7 @@ class History
|
|||
*/
|
||||
public static function add(int $uri_id, array $item)
|
||||
{
|
||||
$allfields = DBStructure::definition('', false);
|
||||
$allfields = DI::dbaDefinition()->getAll();
|
||||
$fields = array_keys($allfields['post-history']['fields']);
|
||||
|
||||
$post = Post::selectFirstPost($fields, ['uri-id' => $uri_id]);
|
||||
|
@ -52,7 +52,7 @@ class History
|
|||
}
|
||||
|
||||
$update = false;
|
||||
$changed = DBStructure::getFieldsForTable('post-history', $item);
|
||||
$changed = DI::dbaDefinition()->truncateFieldsForTable('post-history', $item);
|
||||
unset($changed['uri-id']);
|
||||
unset($changed['edited']);
|
||||
foreach ($changed as $field => $content) {
|
||||
|
|
|
@ -40,36 +40,44 @@ class Link
|
|||
/**
|
||||
* Check if the link is stored
|
||||
*
|
||||
* @param int $uri_id
|
||||
* @param string $url
|
||||
* @return bool
|
||||
* @param int $uriId
|
||||
* @param string $url URL
|
||||
* @return bool Whether record has been found
|
||||
*/
|
||||
public static function exists(int $uri_id, string $url)
|
||||
public static function exists(int $uriId, string $url): bool
|
||||
{
|
||||
return DBA::exists('post-link', ['uri-id' => $uri_id, 'url' => $url]);
|
||||
return DBA::exists('post-link', ['uri-id' => $uriId, 'url' => $url]);
|
||||
}
|
||||
|
||||
public static function getByLink(int $uri_id, string $url, $size = '')
|
||||
/**
|
||||
* Returns URL by URI id and other URL
|
||||
*
|
||||
* @param int $uriId
|
||||
* @param string $url
|
||||
* @param string $size
|
||||
* @return string Found link URL + id on success, $url on failture
|
||||
*/
|
||||
public static function getByLink(int $uriId, string $url, string $size = ''): string
|
||||
{
|
||||
if (empty($uri_id) || empty($url) || Proxy::isLocalImage($url)) {
|
||||
if (empty($uriId) || empty($url) || Proxy::isLocalImage($url)) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
if (!in_array(parse_url($url, PHP_URL_SCHEME), ['http', 'https'])) {
|
||||
Logger::info('Bad URL, quitting', ['uri-id' => $uri_id, 'url' => $url, 'callstack' => System::callstack(20)]);
|
||||
Logger::info('Bad URL, quitting', ['uri-id' => $uriId, 'url' => $url, 'callstack' => System::callstack(20)]);
|
||||
return $url;
|
||||
}
|
||||
|
||||
$link = DBA::selectFirst('post-link', ['id'], ['uri-id' => $uri_id, 'url' => $url]);
|
||||
$link = DBA::selectFirst('post-link', ['id'], ['uri-id' => $uriId, 'url' => $url]);
|
||||
if (!empty($link['id'])) {
|
||||
$id = $link['id'];
|
||||
Logger::info('Found', ['id' => $id, 'uri-id' => $uri_id, 'url' => $url]);
|
||||
Logger::info('Found', ['id' => $id, 'uri-id' => $uriId, 'url' => $url]);
|
||||
} else {
|
||||
$mime = self::fetchMimeType($url);
|
||||
|
||||
DBA::insert('post-link', ['uri-id' => $uri_id, 'url' => $url, 'mimetype' => $mime], Database::INSERT_IGNORE);
|
||||
DBA::insert('post-link', ['uri-id' => $uriId, 'url' => $url, 'mimetype' => $mime], Database::INSERT_IGNORE);
|
||||
$id = DBA::lastInsertId();
|
||||
Logger::info('Inserted', ['id' => $id, 'uri-id' => $uri_id, 'url' => $url]);
|
||||
Logger::info('Inserted', ['id' => $id, 'uri-id' => $uriId, 'url' => $url]);
|
||||
}
|
||||
|
||||
if (empty($id)) {
|
||||
|
@ -81,15 +89,19 @@ class Link
|
|||
case Proxy::SIZE_MICRO:
|
||||
$url .= Proxy::PIXEL_MICRO . '/';
|
||||
break;
|
||||
|
||||
case Proxy::SIZE_THUMB:
|
||||
$url .= Proxy::PIXEL_THUMB . '/';
|
||||
break;
|
||||
|
||||
case Proxy::SIZE_SMALL:
|
||||
$url .= Proxy::PIXEL_SMALL . '/';
|
||||
break;
|
||||
|
||||
case Proxy::SIZE_MEDIUM:
|
||||
$url .= Proxy::PIXEL_MEDIUM . '/';
|
||||
break;
|
||||
|
||||
case Proxy::SIZE_LARGE:
|
||||
$url .= Proxy::PIXEL_LARGE . '/';
|
||||
break;
|
||||
|
@ -97,43 +109,50 @@ class Link
|
|||
return $url . $id;
|
||||
}
|
||||
|
||||
private static function fetchMimeType(string $url, string $accept = HttpClientAccept::DEFAULT)
|
||||
/**
|
||||
* Fetches MIME type by URL and Accept: header
|
||||
*
|
||||
* @param string $url URL to fetch
|
||||
* @param string $accept Comma-separated list of expected response MIME type(s)
|
||||
* @return string Discovered MIME type or empty string on failure
|
||||
*/
|
||||
private static function fetchMimeType(string $url, string $accept = HttpClientAccept::DEFAULT): string
|
||||
{
|
||||
$timeout = DI::config()->get('system', 'xrd_timeout');
|
||||
|
||||
$curlResult = DI::httpClient()->head($url, [HttpClientOptions::TIMEOUT => $timeout, HttpClientOptions::ACCEPT_CONTENT => $accept]);
|
||||
if ($curlResult->isSuccess()) {
|
||||
if (empty($media['mimetype'])) {
|
||||
return $curlResult->getHeader('Content-Type')[0] ?? '';
|
||||
}
|
||||
|
||||
if ($curlResult->isSuccess() && empty($media['mimetype'])) {
|
||||
return $curlResult->getHeader('Content-Type')[0] ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add external links and replace them in the body
|
||||
*
|
||||
* @param integer $uriid
|
||||
* @param string $body
|
||||
* @param integer $uriId
|
||||
* @param string $body Item body formatted with BBCodes
|
||||
* @return string Body with replaced links
|
||||
*/
|
||||
public static function insertFromBody(int $uriid, string $body)
|
||||
public static function insertFromBody(int $uriId, string $body): string
|
||||
{
|
||||
if (preg_match_all("/\[img\=([0-9]*)x([0-9]*)\](http.*?)\[\/img\]/ism", $body, $pictures, PREG_SET_ORDER)) {
|
||||
foreach ($pictures as $picture) {
|
||||
$body = str_replace($picture[3], self::getByLink($uriid, $picture[3]), $body);
|
||||
$body = str_replace($picture[3], self::getByLink($uriId, $picture[3]), $body);
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match_all("/\[img=(http[^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) {
|
||||
foreach ($pictures as $picture) {
|
||||
$body = str_replace($picture[1], self::getByLink($uriid, $picture[1]), $body);
|
||||
$body = str_replace($picture[1], self::getByLink($uriId, $picture[1]), $body);
|
||||
}
|
||||
}
|
||||
|
||||
if (preg_match_all("/\[img\](http[^\[\]]*)\[\/img\]/ism", $body, $pictures, PREG_SET_ORDER)) {
|
||||
foreach ($pictures as $picture) {
|
||||
$body = str_replace($picture[1], self::getByLink($uriid, $picture[1]), $body);
|
||||
$body = str_replace($picture[1], self::getByLink($uriId, $picture[1]), $body);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ class Media
|
|||
* @param array $media
|
||||
* @return array cleaned media array
|
||||
*/
|
||||
private static function unsetEmptyFields(array $media)
|
||||
private static function unsetEmptyFields(array $media): array
|
||||
{
|
||||
$fields = ['mimetype', 'height', 'width', 'size', 'preview', 'preview-height', 'preview-width', 'description'];
|
||||
foreach ($fields as $field) {
|
||||
|
@ -145,7 +145,7 @@ class Media
|
|||
* @param string $title
|
||||
* @return string "[attach]" element
|
||||
*/
|
||||
public static function getAttachElement(string $href, int $length, string $type, string $title = '')
|
||||
public static function getAttachElement(string $href, int $length, string $type, string $title = ''): string
|
||||
{
|
||||
$media = self::fetchAdditionalData(['type' => self::DOCUMENT, 'url' => $href,
|
||||
'size' => $length, 'mimetype' => $type, 'description' => $title]);
|
||||
|
@ -160,7 +160,7 @@ class Media
|
|||
* @param array $media
|
||||
* @return array media array with additional data
|
||||
*/
|
||||
public static function fetchAdditionalData(array $media)
|
||||
public static function fetchAdditionalData(array $media): array
|
||||
{
|
||||
if (Network::isLocalLink($media['url'])) {
|
||||
$media = self::fetchLocalData($media);
|
||||
|
@ -192,7 +192,7 @@ class Media
|
|||
|
||||
if (($media['type'] == self::IMAGE) || ($filetype == 'image')) {
|
||||
$imagedata = Images::getInfoFromURLCached($media['url']);
|
||||
if (!empty($imagedata)) {
|
||||
if ($imagedata) {
|
||||
$media['mimetype'] = $imagedata['mime'];
|
||||
$media['size'] = $imagedata['size'];
|
||||
$media['width'] = $imagedata[0];
|
||||
|
@ -202,7 +202,7 @@ class Media
|
|||
}
|
||||
if (!empty($media['preview'])) {
|
||||
$imagedata = Images::getInfoFromURLCached($media['preview']);
|
||||
if (!empty($imagedata)) {
|
||||
if ($imagedata) {
|
||||
$media['preview-width'] = $imagedata[0];
|
||||
$media['preview-height'] = $imagedata[1];
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ class Media
|
|||
* @param array $media
|
||||
* @return array media with added data
|
||||
*/
|
||||
private static function fetchLocalData(array $media)
|
||||
private static function fetchLocalData(array $media): array
|
||||
{
|
||||
if (!preg_match('|.*?/photo/(.*[a-fA-F0-9])\-(.*[0-9])\..*[\w]|', $media['url'] ?? '', $matches)) {
|
||||
return $media;
|
||||
|
@ -266,7 +266,7 @@ class Media
|
|||
* @param array $data
|
||||
* @return array data array with the detected type
|
||||
*/
|
||||
public static function addType(array $data)
|
||||
public static function addType(array $data): array
|
||||
{
|
||||
if (empty($data['mimetype'])) {
|
||||
Logger::info('No MimeType provided', ['media' => $data]);
|
||||
|
@ -318,7 +318,7 @@ class Media
|
|||
* @param string $preview Preview picture
|
||||
* @return boolean
|
||||
*/
|
||||
private static function isPictureLink(string $page, string $preview)
|
||||
private static function isPictureLink(string $page, string $preview): bool
|
||||
{
|
||||
return preg_match('#/photos/.*/image/#ism', $page) && preg_match('#/photo/.*-1\.#ism', $preview);
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ class Media
|
|||
* @param string $body
|
||||
* @return string Body without media links
|
||||
*/
|
||||
public static function insertFromBody(int $uriid, string $body)
|
||||
public static function insertFromBody(int $uriid, string $body): string
|
||||
{
|
||||
// Simplify image codes
|
||||
$unshared_body = $body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
|
||||
|
@ -413,6 +413,7 @@ class Media
|
|||
*
|
||||
* @param integer $uriid
|
||||
* @param string $body
|
||||
* @return void
|
||||
*/
|
||||
public static function insertFromRelevantUrl(int $uriid, string $body)
|
||||
{
|
||||
|
@ -448,6 +449,7 @@ class Media
|
|||
*
|
||||
* @param integer $uriid
|
||||
* @param string $body
|
||||
* @return void
|
||||
*/
|
||||
public static function insertFromAttachmentData(int $uriid, string $body)
|
||||
{
|
||||
|
@ -506,9 +508,9 @@ class Media
|
|||
/**
|
||||
* Retrieves the media attachments associated with the provided item ID.
|
||||
*
|
||||
* @param int $uri_id
|
||||
* @param array $types
|
||||
* @return array
|
||||
* @param int $uri_id URI id
|
||||
* @param array $types Media types
|
||||
* @return array|bool Array on success, false on error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getByURIId(int $uri_id, array $types = [])
|
||||
|
@ -525,12 +527,12 @@ class Media
|
|||
/**
|
||||
* Checks if media attachments are associated with the provided item ID.
|
||||
*
|
||||
* @param int $uri_id
|
||||
* @param array $types
|
||||
* @return array
|
||||
* @param int $uri_id URI id
|
||||
* @param array $types Media types
|
||||
* @return bool Whether media attachment exists
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function existsByURIId(int $uri_id, array $types = [])
|
||||
public static function existsByURIId(int $uri_id, array $types = []): bool
|
||||
{
|
||||
$condition = ['uri-id' => $uri_id];
|
||||
|
||||
|
@ -544,13 +546,13 @@ class Media
|
|||
/**
|
||||
* Split the attachment media in the three segments "visual", "link" and "additional"
|
||||
*
|
||||
* @param int $uri_id
|
||||
* @param string $guid
|
||||
* @param int $uri_id URI id
|
||||
* @param string $guid GUID
|
||||
* @param array $links list of links that shouldn't be added
|
||||
* @param bool $has_media
|
||||
* @return array attachments
|
||||
*/
|
||||
public static function splitAttachments(int $uri_id, string $guid = '', array $links = [], bool $has_media = true)
|
||||
public static function splitAttachments(int $uri_id, string $guid = '', array $links = [], bool $has_media = true): array
|
||||
{
|
||||
$attachments = ['visual' => [], 'link' => [], 'additional' => []];
|
||||
|
||||
|
@ -648,7 +650,7 @@ class Media
|
|||
* @param string $body
|
||||
* @return string body
|
||||
*/
|
||||
public static function addAttachmentsToBody(int $uriid, string $body = '')
|
||||
public static function addAttachmentsToBody(int $uriid, string $body = ''): string
|
||||
{
|
||||
if (empty($body)) {
|
||||
$item = Post::selectFirst(['body'], ['uri-id' => $uriid]);
|
||||
|
@ -701,7 +703,7 @@ class Media
|
|||
* @param string $size One of the Proxy::SIZE_* constants
|
||||
* @return string preview link
|
||||
*/
|
||||
public static function getPreviewUrlForId(int $id, string $size = ''):string
|
||||
public static function getPreviewUrlForId(int $id, string $size = ''): string
|
||||
{
|
||||
$url = DI::baseUrl() . '/photo/preview/';
|
||||
switch ($size) {
|
||||
|
@ -731,7 +733,7 @@ class Media
|
|||
* @param string $size One of the Proxy::SIZE_* constants
|
||||
* @return string media link
|
||||
*/
|
||||
public static function getUrlForId(int $id, string $size = ''):string
|
||||
public static function getUrlForId(int $id, string $size = ''): string
|
||||
{
|
||||
$url = DI::baseUrl() . '/photo/media/';
|
||||
switch ($size) {
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Friendica\Model\Post;
|
|||
use BadMethodCallException;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
|
||||
class Question
|
||||
{
|
||||
|
@ -42,7 +43,7 @@ class Question
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-question', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-question', $data);
|
||||
|
||||
// Remove the key fields
|
||||
unset($fields['uri-id']);
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Friendica\Model\Post;
|
|||
use BadMethodCallException;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
|
||||
class QuestionOption
|
||||
{
|
||||
|
@ -43,7 +44,7 @@ class QuestionOption
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-question-option', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-question-option', $data);
|
||||
|
||||
// Remove the key fields
|
||||
unset($fields['uri-id']);
|
||||
|
|
|
@ -25,6 +25,7 @@ use \BadMethodCallException;
|
|||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
|
||||
class Thread
|
||||
{
|
||||
|
@ -42,7 +43,7 @@ class Thread
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-thread', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread', $data);
|
||||
|
||||
// Additionally assign the key fields
|
||||
$fields['uri-id'] = $uri_id;
|
||||
|
@ -65,7 +66,7 @@ class Thread
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-thread', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread', $data);
|
||||
|
||||
// Remove the key fields
|
||||
unset($fields['uri-id']);
|
||||
|
|
|
@ -25,6 +25,7 @@ use \BadMethodCallException;
|
|||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
|
||||
class ThreadUser
|
||||
{
|
||||
|
@ -43,7 +44,7 @@ class ThreadUser
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-thread-user', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread-user', $data);
|
||||
|
||||
// Additionally assign the key fields
|
||||
$fields['uri-id'] = $uri_id;
|
||||
|
@ -68,7 +69,7 @@ class ThreadUser
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-thread-user', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-thread-user', $data);
|
||||
|
||||
// Remove the key fields
|
||||
unset($fields['uri-id']);
|
||||
|
|
|
@ -25,6 +25,7 @@ use Friendica\Database\DBA;
|
|||
use \BadMethodCallException;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\DI;
|
||||
|
||||
class User
|
||||
{
|
||||
|
@ -47,7 +48,7 @@ class User
|
|||
return false;
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-user', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-user', $data);
|
||||
|
||||
// Additionally assign the key fields
|
||||
$fields['uri-id'] = $uri_id;
|
||||
|
@ -81,7 +82,7 @@ class User
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-user', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-user', $data);
|
||||
|
||||
// Remove the key fields
|
||||
unset($fields['uri-id']);
|
||||
|
|
|
@ -67,7 +67,7 @@ class UserNotification
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-user-notification', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-user-notification', $data);
|
||||
|
||||
$fields['uri-id'] = $uri_id;
|
||||
$fields['uid'] = $uid;
|
||||
|
@ -91,7 +91,7 @@ class UserNotification
|
|||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post-user-notification', $data);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('post-user-notification', $data);
|
||||
|
||||
// Remove the key fields
|
||||
unset($fields['uri-id']);
|
||||
|
|
|
@ -54,10 +54,10 @@ class Profile
|
|||
*
|
||||
* @param integer User ID
|
||||
*
|
||||
* @return array Profile data
|
||||
* @return array|bool Profile data or false on error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getByUID($uid)
|
||||
public static function getByUID(int $uid)
|
||||
{
|
||||
return DBA::selectFirst('profile', [], ['uid' => $uid]);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class Profile
|
|||
* @param int $id The contact owner ID
|
||||
* @param array $fields The selected fields
|
||||
*
|
||||
* @return array Profile data for the ID
|
||||
* @return array|bool Profile data for the ID or false on error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getById(int $uid, int $id, array $fields = [])
|
||||
|
@ -81,7 +81,7 @@ class Profile
|
|||
* Returns profile data for the contact owner
|
||||
*
|
||||
* @param int $uid The User ID
|
||||
* @param array $fields The fields to retrieve
|
||||
* @param array|bool $fields The fields to retrieve or false on error
|
||||
*
|
||||
* @return array Array of profile data
|
||||
* @throws \Exception
|
||||
|
@ -94,9 +94,9 @@ class Profile
|
|||
/**
|
||||
* Update a profile entry and distribute the changes if needed
|
||||
*
|
||||
* @param array $fields
|
||||
* @param integer $uid
|
||||
* @return boolean
|
||||
* @param array $fields Profile fields to update
|
||||
* @param integer $uid User id
|
||||
* @return boolean Whether update was successful
|
||||
*/
|
||||
public static function update(array $fields, int $uid): bool
|
||||
{
|
||||
|
@ -136,8 +136,10 @@ class Profile
|
|||
|
||||
/**
|
||||
* Publish a changed profile
|
||||
* @param int $uid
|
||||
*
|
||||
* @param int $uid User id
|
||||
* @param bool $force Force publishing to the directory
|
||||
* @return void
|
||||
*/
|
||||
public static function publishUpdate(int $uid, bool $force = false)
|
||||
{
|
||||
|
@ -160,10 +162,9 @@ class Profile
|
|||
* Returns a formatted location string from the given profile array
|
||||
*
|
||||
* @param array $profile Profile array (Generated from the "profile" table)
|
||||
*
|
||||
* @return string Location string
|
||||
*/
|
||||
public static function formatLocation(array $profile)
|
||||
public static function formatLocation(array $profile): string
|
||||
{
|
||||
$location = '';
|
||||
|
||||
|
@ -237,7 +238,7 @@ class Profile
|
|||
|
||||
if (!local_user()) {
|
||||
$a->setCurrentTheme($profile['theme']);
|
||||
$a->setCurrentMobileTheme(DI::pConfig()->get($a->getProfileOwner(), 'system', 'mobile_theme'));
|
||||
$a->setCurrentMobileTheme(DI::pConfig()->get($a->getProfileOwner(), 'system', 'mobile_theme') ?? '');
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -34,9 +34,10 @@ class PushSubscriber
|
|||
*
|
||||
* @param integer $uid User ID
|
||||
* @param int $default_priority
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function publishFeed($uid, $default_priority = PRIORITY_HIGH)
|
||||
public static function publishFeed(int $uid, int $default_priority = PRIORITY_HIGH)
|
||||
{
|
||||
$condition = ['push' => 0, 'uid' => $uid];
|
||||
DBA::update('push_subscriber', ['push' => 1, 'next_try' => DBA::NULL_DATETIME], $condition);
|
||||
|
@ -48,9 +49,10 @@ class PushSubscriber
|
|||
* start workers to transmit the feed data
|
||||
*
|
||||
* @param int $default_priority
|
||||
* @return void
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function requeue($default_priority = PRIORITY_HIGH)
|
||||
public static function requeue(int $default_priority = PRIORITY_HIGH)
|
||||
{
|
||||
// We'll push to each subscriber that has push > 0,
|
||||
// i.e. there has been an update (set in notifier.php).
|
||||
|
@ -80,9 +82,10 @@ class PushSubscriber
|
|||
* @param string $hub_callback Callback address
|
||||
* @param string $hub_topic Feed topic
|
||||
* @param string $hub_secret Subscription secret
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function renew($uid, $nick, $subscribe, $hub_callback, $hub_topic, $hub_secret)
|
||||
public static function renew(int $uid, string $nick, int $subscribe, string $hub_callback, string $hub_topic, string $hub_secret)
|
||||
{
|
||||
// fetch the old subscription if it exists
|
||||
$subscriber = DBA::selectFirst('push_subscriber', ['last_update', 'push'], ['callback_url' => $hub_callback]);
|
||||
|
@ -119,9 +122,10 @@ class PushSubscriber
|
|||
* Delay the push subscriber
|
||||
*
|
||||
* @param integer $id Subscriber ID
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function delay($id)
|
||||
public static function delay(int $id)
|
||||
{
|
||||
$subscriber = DBA::selectFirst('push_subscriber', ['push', 'callback_url', 'renewed', 'nickname'], ['id' => $id]);
|
||||
if (!DBA::isResult($subscriber)) {
|
||||
|
@ -158,9 +162,10 @@ class PushSubscriber
|
|||
*
|
||||
* @param integer $id Subscriber ID
|
||||
* @param string $last_update Date of last transmitted item
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function reset($id, $last_update)
|
||||
public static function reset(int $id, string $last_update)
|
||||
{
|
||||
$subscriber = DBA::selectFirst('push_subscriber', ['callback_url', 'nickname'], ['id' => $id]);
|
||||
if (!DBA::isResult($subscriber)) {
|
||||
|
|
|
@ -34,13 +34,12 @@ class Register
|
|||
/**
|
||||
* Return the list of pending registrations
|
||||
*
|
||||
* @param int $start Start count (Default is 0)
|
||||
* @param int $start Start count (Default is 0)
|
||||
* @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE)
|
||||
*
|
||||
* @return array
|
||||
* @return array|bool Array on succes, false on failure
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getPending($start = 0, $count = Pager::ITEMS_PER_PAGE)
|
||||
public static function getPending(int $start = 0, int $count = Pager::ITEMS_PER_PAGE)
|
||||
{
|
||||
return DBA::selectToArray('pending-view', [], [], ['limit' => [$start, $count]]);
|
||||
}
|
||||
|
@ -50,8 +49,7 @@ class Register
|
|||
*
|
||||
* @param int $uid The user id
|
||||
*
|
||||
* @return array The pending user information
|
||||
*
|
||||
* @return array|bool Array on succes, false on failure
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getPendingForUser(int $uid)
|
||||
|
@ -65,7 +63,7 @@ class Register
|
|||
* @return int
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getPendingCount()
|
||||
public static function getPendingCount(): int
|
||||
{
|
||||
return DBA::count('pending-view', ['self' => true]);
|
||||
}
|
||||
|
@ -74,10 +72,10 @@ class Register
|
|||
* Returns the register record associated with the provided hash
|
||||
*
|
||||
* @param string $hash
|
||||
* @return array
|
||||
* @return array|bool Array on succes, false on failure
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getByHash($hash)
|
||||
public static function getByHash(string $hash)
|
||||
{
|
||||
return DBA::selectFirst('register', [], ['hash' => $hash]);
|
||||
}
|
||||
|
@ -89,7 +87,7 @@ class Register
|
|||
* @return boolean
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function existsByHash($hash)
|
||||
public static function existsByHash(string $hash): bool
|
||||
{
|
||||
return DBA::exists('register', ['hash' => $hash]);
|
||||
}
|
||||
|
@ -100,7 +98,7 @@ class Register
|
|||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createForInvitation()
|
||||
public static function createForInvitation(): string
|
||||
{
|
||||
$code = Strings::getRandomName(8) . random_int(1000, 9999);
|
||||
|
||||
|
@ -124,7 +122,7 @@ class Register
|
|||
* @return boolean
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createForApproval($uid, $language, $note = '')
|
||||
public static function createForApproval(int $uid, string $language, string $note = ''): bool
|
||||
{
|
||||
$hash = Strings::getRandomHex();
|
||||
|
||||
|
@ -151,7 +149,7 @@ class Register
|
|||
* @return boolean
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function deleteByHash($hash)
|
||||
public static function deleteByHash(string $hash): bool
|
||||
{
|
||||
return DBA::delete('register', ['hash' => $hash]);
|
||||
}
|
||||
|
|
|
@ -32,10 +32,9 @@ class Search
|
|||
* Returns the list of user defined tags (e.g. #Friendica)
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getUserTags()
|
||||
public static function getUserTags(): array
|
||||
{
|
||||
$termsStmt = DBA::p("SELECT DISTINCT(`term`) FROM `search`");
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ use Friendica\Core\Logger;
|
|||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Factory\Api\Mastodon\Notification as NotificationFactory;
|
||||
use Friendica\Navigation\Notifications\Entity;
|
||||
use Friendica\Object\Api\Mastodon\Notification;
|
||||
use Minishlink\WebPush\VAPID;
|
||||
|
@ -37,8 +38,7 @@ class Subscription
|
|||
* @param int $applicationid
|
||||
* @param int $uid
|
||||
* @param array $fields
|
||||
*
|
||||
* @return bool Does it exist?
|
||||
* @return array|bool Array on success, false on failure
|
||||
*/
|
||||
public static function select(int $applicationid, int $uid, array $fields = [])
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ class Subscription
|
|||
*
|
||||
* @return bool Does it exist?
|
||||
*/
|
||||
public static function exists(int $applicationid, int $uid)
|
||||
public static function exists(int $applicationid, int $uid): bool
|
||||
{
|
||||
return DBA::exists('subscription', ['application-id' => $applicationid, 'uid' => $uid]);
|
||||
}
|
||||
|
@ -64,10 +64,9 @@ class Subscription
|
|||
* @param int $applicationid
|
||||
* @param int $uid
|
||||
* @param array $fields subscription fields
|
||||
*
|
||||
* @return bool result of update
|
||||
*/
|
||||
public static function update(int $applicationid, int $uid, array $fields)
|
||||
public static function update(int $applicationid, int $uid, array $fields): bool
|
||||
{
|
||||
return DBA::update('subscription', $fields, ['application-id' => $applicationid, 'uid' => $uid]);
|
||||
}
|
||||
|
@ -76,10 +75,9 @@ class Subscription
|
|||
* Insert or replace a subscription record
|
||||
*
|
||||
* @param array $fields subscription fields
|
||||
*
|
||||
* @return bool result of replace
|
||||
*/
|
||||
public static function replace(array $fields)
|
||||
public static function replace(array $fields): bool
|
||||
{
|
||||
return DBA::replace('subscription', $fields);
|
||||
}
|
||||
|
@ -91,7 +89,7 @@ class Subscription
|
|||
* @param int $uid
|
||||
* @return bool
|
||||
*/
|
||||
public static function delete(int $applicationid, int $uid)
|
||||
public static function delete(int $applicationid, int $uid): bool
|
||||
{
|
||||
return DBA::delete('subscription', ['application-id' => $applicationid, 'uid' => $uid]);
|
||||
}
|
||||
|
@ -136,25 +134,25 @@ class Subscription
|
|||
/**
|
||||
* Prepare push notification
|
||||
*
|
||||
* @param int $nid
|
||||
* @param Notification $Notification
|
||||
* @return void
|
||||
*/
|
||||
public static function pushByNotification(Entity\Notification $Notification)
|
||||
public static function pushByNotification(Entity\Notification $notification)
|
||||
{
|
||||
$type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification);
|
||||
$type = NotificationFactory::getType($notification);
|
||||
|
||||
if (DI::notify()->NotifyOnDesktop($Notification, $type)) {
|
||||
DI::notify()->createFromNotification($Notification);
|
||||
if (DI::notify()->NotifyOnDesktop($notification, $type)) {
|
||||
DI::notify()->createFromNotification($notification);
|
||||
}
|
||||
|
||||
if (empty($type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$subscriptions = DBA::select('subscription', [], ['uid' => $Notification->uid, $type => true]);
|
||||
$subscriptions = DBA::select('subscription', [], ['uid' => $notification->uid, $type => true]);
|
||||
while ($subscription = DBA::fetch($subscriptions)) {
|
||||
Logger::info('Push notification', ['id' => $subscription['id'], 'uid' => $subscription['uid'], 'type' => $type]);
|
||||
Worker::add(PRIORITY_HIGH, 'PushSubscription', $subscription['id'], $Notification->id);
|
||||
Worker::add(PRIORITY_HIGH, 'PushSubscription', $subscription['id'], $notification->id);
|
||||
}
|
||||
DBA::close($subscriptions);
|
||||
}
|
||||
|
|
|
@ -73,13 +73,14 @@ class Tag
|
|||
/**
|
||||
* Store tag/mention elements
|
||||
*
|
||||
* @param integer $uriid
|
||||
* @param integer $type
|
||||
* @param string $name
|
||||
* @param string $url
|
||||
* @param integer $target
|
||||
* @param integer $uriId
|
||||
* @param integer $type Tag type
|
||||
* @param string $name Tag name
|
||||
* @param string $url Contact URL (optional)
|
||||
* @param integer $target Target (default: null)
|
||||
* @return void
|
||||
*/
|
||||
public static function store(int $uriid, int $type, string $name, string $url = '', int $target = null)
|
||||
public static function store(int $uriId, int $type, string $name, string $url = '', int $target = null)
|
||||
{
|
||||
if ($type == self::HASHTAG) {
|
||||
// Trim Unicode non-word characters
|
||||
|
@ -88,7 +89,7 @@ class Tag
|
|||
$tags = explode(self::TAG_CHARACTER[self::HASHTAG], $name);
|
||||
if (count($tags) > 1) {
|
||||
foreach ($tags as $tag) {
|
||||
self::store($uriid, $type, $tag, $url);
|
||||
self::store($uriId, $type, $tag, $url);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -142,7 +143,7 @@ class Tag
|
|||
}
|
||||
}
|
||||
|
||||
$fields = ['uri-id' => $uriid, 'type' => $type, 'tid' => $tagid, 'cid' => $cid];
|
||||
$fields = ['uri-id' => $uriId, 'type' => $type, 'tid' => $tagid, 'cid' => $cid];
|
||||
|
||||
if (in_array($type, [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION])) {
|
||||
$condition = $fields;
|
||||
|
@ -155,7 +156,7 @@ class Tag
|
|||
|
||||
DBA::insert('post-tag', $fields, Database::INSERT_IGNORE);
|
||||
|
||||
Logger::info('Stored tag/mention', ['uri-id' => $uriid, 'tag-id' => $tagid, 'contact-id' => $cid, 'name' => $name, 'type' => $type, 'callstack' => System::callstack(8)]);
|
||||
Logger::info('Stored tag/mention', ['uri-id' => $uriId, 'tag-id' => $tagid, 'contact-id' => $cid, 'name' => $name, 'type' => $type, 'callstack' => System::callstack(8)]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,14 +214,14 @@ class Tag
|
|||
}
|
||||
|
||||
/**
|
||||
* Get a tag id for a given tag name and url
|
||||
* Get a tag id for a given tag name and URL
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $name Name of tag
|
||||
* @param string $url
|
||||
* @param int $type
|
||||
* @return void
|
||||
* @param int $type Type of tag
|
||||
* @return int Tag id
|
||||
*/
|
||||
public static function getID(string $name, string $url = '', int $type = null)
|
||||
public static function getID(string $name, string $url = '', int $type = null): int
|
||||
{
|
||||
$fields = ['name' => substr($name, 0, 96), 'url' => $url];
|
||||
|
||||
|
@ -242,6 +243,9 @@ class Tag
|
|||
return $tid;
|
||||
}
|
||||
|
||||
// Also log type
|
||||
$fields['type'] = $type;
|
||||
|
||||
Logger::error('No tag id created', $fields);
|
||||
return 0;
|
||||
}
|
||||
|
@ -249,20 +253,21 @@ class Tag
|
|||
/**
|
||||
* Store tag/mention elements
|
||||
*
|
||||
* @param integer $uriid
|
||||
* @param integer $uriId
|
||||
* @param string $hash
|
||||
* @param string $name
|
||||
* @param string $url
|
||||
* @param boolean $probing
|
||||
* @param boolean $probing Whether probing is active
|
||||
* @return void
|
||||
*/
|
||||
public static function storeByHash(int $uriid, string $hash, string $name, string $url = '', $probing = true)
|
||||
public static function storeByHash(int $uriId, string $hash, string $name, string $url = '', bool $probing = true)
|
||||
{
|
||||
$type = self::getTypeForHash($hash);
|
||||
if ($type == self::UNKNOWN) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::store($uriid, $type, $name, $url, $probing);
|
||||
self::store($uriId, $type, $name, $url, $probing);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -273,7 +278,7 @@ class Tag
|
|||
*
|
||||
* @return array Tag list
|
||||
*/
|
||||
public static function getFromBody(string $body, string $tags = null)
|
||||
public static function getFromBody(string $body, string $tags = null): array
|
||||
{
|
||||
if (is_null($tags)) {
|
||||
$tags = self::TAG_CHARACTER[self::HASHTAG] . self::TAG_CHARACTER[self::MENTION] . self::TAG_CHARACTER[self::EXCLUSIVE_MENTION];
|
||||
|
@ -289,14 +294,15 @@ class Tag
|
|||
/**
|
||||
* Store tags and mentions from the body
|
||||
*
|
||||
* @param integer $uriid URI-Id
|
||||
* @param integer $uriId URI-Id
|
||||
* @param string $body Body of the post
|
||||
* @param string $tags Accepted tags
|
||||
* @param boolean $probing Perform a probing for contacts, adding them if needed
|
||||
* @return void
|
||||
*/
|
||||
public static function storeFromBody(int $uriid, string $body, string $tags = null, $probing = true)
|
||||
public static function storeFromBody(int $uriId, string $body, string $tags = null, bool $probing = true)
|
||||
{
|
||||
Logger::info('Check for tags', ['uri-id' => $uriid, 'hash' => $tags, 'callstack' => System::callstack()]);
|
||||
Logger::info('Check for tags', ['uri-id' => $uriId, 'hash' => $tags, 'callstack' => System::callstack()]);
|
||||
|
||||
if (is_null($tags)) {
|
||||
$tags = self::TAG_CHARACTER[self::HASHTAG] . self::TAG_CHARACTER[self::MENTION] . self::TAG_CHARACTER[self::EXCLUSIVE_MENTION];
|
||||
|
@ -312,13 +318,13 @@ class Tag
|
|||
}
|
||||
|
||||
foreach (self::getFromBody($body, $tags) as $tag) {
|
||||
self::storeByHash($uriid, $tag[1], $tag[3], $tag[2], $probing);
|
||||
self::storeByHash($uriId, $tag[1], $tag[3], $tag[2], $probing);
|
||||
}
|
||||
|
||||
// Search for hashtags in the shared body (but only if hashtags are wanted)
|
||||
if (!empty($share_body) && (strpos($tags, self::TAG_CHARACTER[self::HASHTAG]) !== false)) {
|
||||
foreach (self::getFromBody($share_body, self::TAG_CHARACTER[self::HASHTAG]) as $tag) {
|
||||
self::storeByHash($uriid, $tag[1], $tag[3], $tag[2], $probing);
|
||||
self::storeByHash($uriId, $tag[1], $tag[3], $tag[2], $probing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -328,50 +334,52 @@ class Tag
|
|||
* This function is needed in the intermediate phase.
|
||||
* Later we can call item::setHashtags in advance to have all tags converted.
|
||||
*
|
||||
* @param integer $uriid URI-Id
|
||||
* @param integer $uriId URI-Id
|
||||
* @param string $body Body of the post
|
||||
* @return void
|
||||
*/
|
||||
public static function storeRawTagsFromBody(int $uriid, string $body)
|
||||
public static function storeRawTagsFromBody(int $uriId, string $body)
|
||||
{
|
||||
Logger::info('Check for tags', ['uri-id' => $uriid, 'callstack' => System::callstack()]);
|
||||
Logger::info('Check for tags', ['uri-id' => $uriId, 'callstack' => System::callstack()]);
|
||||
|
||||
$result = BBCode::getTags($body);
|
||||
if (empty($result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::info('Found tags', ['uri-id' => $uriid, 'result' => $result]);
|
||||
Logger::info('Found tags', ['uri-id' => $uriId, 'result' => $result]);
|
||||
|
||||
foreach ($result as $tag) {
|
||||
if (substr($tag, 0, 1) != self::TAG_CHARACTER[self::HASHTAG]) {
|
||||
continue;
|
||||
}
|
||||
self::storeByHash($uriid, substr($tag, 0, 1), substr($tag, 1));
|
||||
self::storeByHash($uriId, substr($tag, 0, 1), substr($tag, 1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for stored hashtags and mentions for the given post
|
||||
*
|
||||
* @param integer $uriid
|
||||
* @param integer $uriId
|
||||
* @return bool
|
||||
*/
|
||||
public static function existsForPost(int $uriid)
|
||||
public static function existsForPost(int $uriId): bool
|
||||
{
|
||||
return DBA::exists('post-tag', ['uri-id' => $uriid, 'type' => [self::HASHTAG, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION]]);
|
||||
return DBA::exists('post-tag', ['uri-id' => $uriId, 'type' => [self::HASHTAG, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove tag/mention
|
||||
*
|
||||
* @param integer $uriid
|
||||
* @param integer $type
|
||||
* @param string $name
|
||||
* @param string $url
|
||||
* @param integer $uriId
|
||||
* @param integer $type Type
|
||||
* @param string $name Name
|
||||
* @param string $url URL
|
||||
* @return void
|
||||
*/
|
||||
public static function remove(int $uriid, int $type, string $name, string $url = '')
|
||||
public static function remove(int $uriId, int $type, string $name, string $url = '')
|
||||
{
|
||||
$condition = ['uri-id' => $uriid, 'type' => $type, 'url' => $url];
|
||||
$condition = ['uri-id' => $uriId, 'type' => $type, 'url' => $url];
|
||||
if ($type == self::HASHTAG) {
|
||||
$condition['name'] = $name;
|
||||
}
|
||||
|
@ -381,35 +389,36 @@ class Tag
|
|||
return;
|
||||
}
|
||||
|
||||
Logger::info('Removing tag/mention', ['uri-id' => $uriid, 'tid' => $tag['tid'], 'name' => $name, 'url' => $url, 'callstack' => System::callstack(8)]);
|
||||
DBA::delete('post-tag', ['uri-id' => $uriid, 'type' => $type, 'tid' => $tag['tid'], 'cid' => $tag['cid']]);
|
||||
Logger::info('Removing tag/mention', ['uri-id' => $uriId, 'tid' => $tag['tid'], 'name' => $name, 'url' => $url, 'callstack' => System::callstack(8)]);
|
||||
DBA::delete('post-tag', ['uri-id' => $uriId, 'type' => $type, 'tid' => $tag['tid'], 'cid' => $tag['cid']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove tag/mention
|
||||
*
|
||||
* @param integer $uriid
|
||||
* @param integer $uriId
|
||||
* @param string $hash
|
||||
* @param string $name
|
||||
* @param string $url
|
||||
* @return void
|
||||
*/
|
||||
public static function removeByHash(int $uriid, string $hash, string $name, string $url = '')
|
||||
public static function removeByHash(int $uriId, string $hash, string $name, string $url = '')
|
||||
{
|
||||
$type = self::getTypeForHash($hash);
|
||||
if ($type == self::UNKNOWN) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::remove($uriid, $type, $name, $url);
|
||||
self::remove($uriId, $type, $name, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type for the given hash
|
||||
*
|
||||
* @param string $hash
|
||||
* @return integer type
|
||||
* @return integer Tag type
|
||||
*/
|
||||
private static function getTypeForHash(string $hash)
|
||||
private static function getTypeForHash(string $hash): int
|
||||
{
|
||||
if ($hash == self::TAG_CHARACTER[self::MENTION]) {
|
||||
return self::MENTION;
|
||||
|
@ -427,22 +436,23 @@ class Tag
|
|||
/**
|
||||
* Create implicit mentions for a given post
|
||||
*
|
||||
* @param integer $uri_id
|
||||
* @param integer $parent_uri_id
|
||||
* @param integer $uriId
|
||||
* @param integer $parentUriId
|
||||
* @return void
|
||||
*/
|
||||
public static function createImplicitMentions(int $uri_id, int $parent_uri_id)
|
||||
public static function createImplicitMentions(int $uriId, int $parentUriId)
|
||||
{
|
||||
// Always mention the direct parent author
|
||||
$parent = Post::selectFirst(['author-link', 'author-name'], ['uri-id' => $parent_uri_id]);
|
||||
self::store($uri_id, self::IMPLICIT_MENTION, $parent['author-name'], $parent['author-link']);
|
||||
$parent = Post::selectFirst(['author-link', 'author-name'], ['uri-id' => $parentUriId]);
|
||||
self::store($uriId, self::IMPLICIT_MENTION, $parent['author-name'], $parent['author-link']);
|
||||
|
||||
if (DI::config()->get('system', 'disable_implicit_mentions')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tags = DBA::select('tag-view', ['name', 'url'], ['uri-id' => $parent_uri_id, 'type' => [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION]]);
|
||||
$tags = DBA::select('tag-view', ['name', 'url'], ['uri-id' => $parentUriId, 'type' => [self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION]]);
|
||||
while ($tag = DBA::fetch($tags)) {
|
||||
self::store($uri_id, self::IMPLICIT_MENTION, $tag['name'], $tag['url']);
|
||||
self::store($uriId, self::IMPLICIT_MENTION, $tag['name'], $tag['url']);
|
||||
}
|
||||
DBA::close($tags);
|
||||
}
|
||||
|
@ -450,30 +460,29 @@ class Tag
|
|||
/**
|
||||
* Retrieves the terms from the provided type(s) associated with the provided item ID.
|
||||
*
|
||||
* @param int $item_id
|
||||
* @param int|array $type
|
||||
* @return array
|
||||
* @param int $uriId
|
||||
* @param array $type Tag type(s)
|
||||
* @return array|bool Array on success, false on error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getByURIId(int $uri_id, array $type = [self::HASHTAG, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION])
|
||||
public static function getByURIId(int $uriId, array $type = [self::HASHTAG, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION])
|
||||
{
|
||||
$condition = ['uri-id' => $uri_id, 'type' => $type];
|
||||
$condition = ['uri-id' => $uriId, 'type' => $type];
|
||||
return DBA::selectToArray('tag-view', ['type', 'name', 'url', 'tag-type'], $condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string with all tags and mentions
|
||||
*
|
||||
* @param integer $uri_id
|
||||
* @param array $type
|
||||
* @param integer $uriId
|
||||
* @param array $type Tag type(s)
|
||||
* @return string tags and mentions
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getCSVByURIId(int $uri_id, array $type = [self::HASHTAG, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION])
|
||||
public static function getCSVByURIId(int $uriId, array $type = [self::HASHTAG, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION]): string
|
||||
{
|
||||
$tag_list = [];
|
||||
$tags = self::getByURIId($uri_id, $type);
|
||||
foreach ($tags as $tag) {
|
||||
foreach (self::getByURIId($uriId, $type) as $tag) {
|
||||
$tag_list[] = self::TAG_CHARACTER[$tag['type']] . '[url=' . $tag['url'] . ']' . $tag['name'] . '[/url]';
|
||||
}
|
||||
|
||||
|
@ -489,7 +498,7 @@ class Tag
|
|||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function populateFromItem(&$item)
|
||||
public static function populateFromItem(array &$item): array
|
||||
{
|
||||
$return = [
|
||||
'tags' => [],
|
||||
|
@ -498,7 +507,7 @@ class Tag
|
|||
'implicit_mentions' => [],
|
||||
];
|
||||
|
||||
$searchpath = DI::baseUrl() . "/search?tag=";
|
||||
$searchpath = DI::baseUrl() . '/search?tag=';
|
||||
|
||||
$taglist = DBA::select('tag-view', ['type', 'name', 'url', 'cid'],
|
||||
['uri-id' => $item['uri-id'], 'type' => [self::HASHTAG, self::MENTION, self::EXCLUSIVE_MENTION, self::IMPLICIT_MENTION]]);
|
||||
|
@ -519,6 +528,7 @@ class Tag
|
|||
$return['hashtags'][] = '<bdi>' . $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a></bdi>';
|
||||
$return['tags'][] = '<bdi>' . $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a></bdi>';
|
||||
break;
|
||||
|
||||
case self::MENTION:
|
||||
case self::EXCLUSIVE_MENTION:
|
||||
if (!empty($tag['cid'])) {
|
||||
|
@ -529,9 +539,13 @@ class Tag
|
|||
$return['mentions'][] = '<bdi>' . $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a></bdi>';
|
||||
$return['tags'][] = '<bdi>' . $prefix . '<a href="' . $tag['url'] . '" target="_blank" rel="noopener noreferrer">' . htmlspecialchars($tag['name']) . '</a></bdi>';
|
||||
break;
|
||||
|
||||
case self::IMPLICIT_MENTION:
|
||||
$return['implicit_mentions'][] = $prefix . $tag['name'];
|
||||
break;
|
||||
|
||||
default:
|
||||
Logger:warning('Unknown tag type found', $tag);
|
||||
}
|
||||
}
|
||||
DBA::close($taglist);
|
||||
|
@ -546,11 +560,13 @@ class Tag
|
|||
* @param integer $uid
|
||||
* @return integer number of posts
|
||||
*/
|
||||
public static function countByTag(string $search, int $uid = 0)
|
||||
public static function countByTag(string $search, int $uid = 0): int
|
||||
{
|
||||
$condition = ["`name` = ? AND (`uid` = ? OR (`uid` = ? AND NOT `global`))
|
||||
AND (`network` IN (?, ?, ?, ?) OR (`uid` = ? AND `uid` != ?))",
|
||||
$search, 0, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0];
|
||||
$search, 0, $uid,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0,
|
||||
];
|
||||
|
||||
return DBA::count('tag-search-view', $condition);
|
||||
}
|
||||
|
@ -558,18 +574,20 @@ class Tag
|
|||
/**
|
||||
* Search posts for given tag
|
||||
*
|
||||
* @param string $search
|
||||
* @param integer $uid
|
||||
* @param integer $start
|
||||
* @param integer $limit
|
||||
* @param string $search Tag to search for
|
||||
* @param integer $uid User Id
|
||||
* @param integer $start Starting record
|
||||
* @param integer $limit Maximum count of records
|
||||
* @param integer $last_uriid
|
||||
* @return array with URI-ID
|
||||
*/
|
||||
public static function getURIIdListByTag(string $search, int $uid = 0, int $start = 0, int $limit = 100, int $last_uriid = 0)
|
||||
public static function getURIIdListByTag(string $search, int $uid = 0, int $start = 0, int $limit = 100, int $last_uriid = 0): array
|
||||
{
|
||||
$condition = ["`name` = ? AND (`uid` = ? OR (`uid` = ? AND NOT `global`))
|
||||
AND (`network` IN (?, ?, ?, ?) OR (`uid` = ? AND `uid` != ?))",
|
||||
$search, 0, $uid, Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0];
|
||||
$search, 0, $uid,
|
||||
Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, $uid, 0,
|
||||
];
|
||||
|
||||
if (!empty($last_uriid)) {
|
||||
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $last_uriid]);
|
||||
|
@ -582,13 +600,13 @@ class Tag
|
|||
|
||||
$tags = DBA::select('tag-search-view', ['uri-id'], $condition, $params);
|
||||
|
||||
$uriids = [];
|
||||
$uriIds = [];
|
||||
while ($tag = DBA::fetch($tags)) {
|
||||
$uriids[] = $tag['uri-id'];
|
||||
$uriIds[] = $tag['uri-id'];
|
||||
}
|
||||
DBA::close($tags);
|
||||
|
||||
return $uriids;
|
||||
return $uriIds;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -599,7 +617,7 @@ class Tag
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getGlobalTrendingHashtags(int $period, $limit = 10)
|
||||
public static function getGlobalTrendingHashtags(int $period, $limit = 10): array
|
||||
{
|
||||
$tags = DI::cache()->get('global_trending_tags-' . $period . '-' . $limit);
|
||||
if (!empty($tags)) {
|
||||
|
@ -612,9 +630,9 @@ class Tag
|
|||
/**
|
||||
* Fetch the blocked tags as SQL
|
||||
*
|
||||
* @return string
|
||||
* @return string SQL for blocked tag names or empty string
|
||||
*/
|
||||
private static function getBlockedSQL()
|
||||
private static function getBlockedSQL(): string
|
||||
{
|
||||
$blocked_txt = DI::config()->get('system', 'blocked_tags');
|
||||
if (empty($blocked_txt)) {
|
||||
|
@ -623,7 +641,7 @@ class Tag
|
|||
|
||||
$blocked = explode(',', $blocked_txt);
|
||||
array_walk($blocked, function(&$value) { $value = "'" . DBA::escape(trim($value)) . "'";});
|
||||
return " AND NOT `name` IN (" . implode(',', $blocked) . ")";
|
||||
return ' AND NOT `name` IN (' . implode(',', $blocked) . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -634,12 +652,15 @@ class Tag
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function setGlobalTrendingHashtags(int $period, int $limit = 10)
|
||||
public static function setGlobalTrendingHashtags(int $period, int $limit = 10): array
|
||||
{
|
||||
// Get a uri-id that is at least X hours old.
|
||||
// We use the uri-id in the query for the hash tags since this is much faster
|
||||
/*
|
||||
* Get a uri-id that is at least X hours old.
|
||||
* We use the uri-id in the query for the hash tags since this is much faster
|
||||
*/
|
||||
$post = Post::selectFirstThread(['uri-id'], ["`uid` = ? AND `received` < ?", 0, DateTimeFormat::utc('now - ' . $period . ' hour')],
|
||||
['order' => ['received' => true]]);
|
||||
|
||||
if (empty($post['uri-id'])) {
|
||||
return [];
|
||||
}
|
||||
|
@ -650,7 +671,9 @@ class Tag
|
|||
FROM `tag-search-view`
|
||||
WHERE `private` = ? AND `uid` = ? AND `uri-id` > ? $block_sql
|
||||
GROUP BY `term` ORDER BY `authors` DESC, `score` DESC LIMIT ?",
|
||||
Item::PUBLIC, 0, $post['uri-id'], $limit);
|
||||
Item::PUBLIC, 0, $post['uri-id'],
|
||||
$limit
|
||||
);
|
||||
|
||||
if (DBA::isResult($tagsStmt)) {
|
||||
$tags = DBA::toArray($tagsStmt);
|
||||
|
@ -669,7 +692,7 @@ class Tag
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getLocalTrendingHashtags(int $period, $limit = 10)
|
||||
public static function getLocalTrendingHashtags(int $period, $limit = 10): array
|
||||
{
|
||||
$tags = DI::cache()->get('local_trending_tags-' . $period . '-' . $limit);
|
||||
if (!empty($tags)) {
|
||||
|
@ -687,7 +710,7 @@ class Tag
|
|||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function setLocalTrendingHashtags(int $period, int $limit = 10)
|
||||
public static function setLocalTrendingHashtags(int $period, int $limit = 10): array
|
||||
{
|
||||
// Get a uri-id that is at least X hours old.
|
||||
// We use the uri-id in the query for the hash tags since this is much faster
|
||||
|
@ -703,7 +726,9 @@ class Tag
|
|||
FROM `tag-search-view`
|
||||
WHERE `private` = ? AND `wall` AND `origin` AND `uri-id` > ? $block_sql
|
||||
GROUP BY `term` ORDER BY `authors` DESC, `score` DESC LIMIT ?",
|
||||
Item::PUBLIC, $post['uri-id'], $limit);
|
||||
Item::PUBLIC, $post['uri-id'],
|
||||
$limit
|
||||
);
|
||||
|
||||
if (DBA::isResult($tagsStmt)) {
|
||||
$tags = DBA::toArray($tagsStmt);
|
||||
|
@ -717,11 +742,11 @@ class Tag
|
|||
/**
|
||||
* Check if the provided tag is of one of the provided term types.
|
||||
*
|
||||
* @param string $tag
|
||||
* @param string $tag Tag name
|
||||
* @param int ...$types
|
||||
* @return bool
|
||||
*/
|
||||
public static function isType($tag, ...$types)
|
||||
public static function isType(string $tag, ...$types): bool
|
||||
{
|
||||
$tag_chars = [];
|
||||
foreach ($types as $type) {
|
||||
|
@ -739,7 +764,7 @@ class Tag
|
|||
* @param string $tag
|
||||
* @return array User list
|
||||
*/
|
||||
private static function getUIDListByTag(string $tag)
|
||||
private static function getUIDListByTag(string $tag): array
|
||||
{
|
||||
$uids = [];
|
||||
$searches = DBA::select('search', ['uid'], ['term' => $tag]);
|
||||
|
@ -754,13 +779,13 @@ class Tag
|
|||
/**
|
||||
* Fetch user who subscribed to the tags of the given item
|
||||
*
|
||||
* @param integer $uri_id
|
||||
* @param integer $uriId
|
||||
* @return array User list
|
||||
*/
|
||||
public static function getUIDListByURIId(int $uri_id)
|
||||
public static function getUIDListByURIId(int $uriId): array
|
||||
{
|
||||
$uids = [];
|
||||
$tags = self::getByURIId($uri_id, [self::HASHTAG]);
|
||||
$tags = self::getByURIId($uriId, [self::HASHTAG]);
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
$uids = array_merge($uids, self::getUIDListByTag(self::TAG_CHARACTER[self::HASHTAG] . $tag['name']));
|
||||
|
|
|
@ -117,16 +117,18 @@ class User
|
|||
switch ($accounttype) {
|
||||
case 'person':
|
||||
return User::ACCOUNT_TYPE_PERSON;
|
||||
|
||||
case 'organisation':
|
||||
return User::ACCOUNT_TYPE_ORGANISATION;
|
||||
|
||||
case 'news':
|
||||
return User::ACCOUNT_TYPE_NEWS;
|
||||
|
||||
case 'community':
|
||||
return User::ACCOUNT_TYPE_COMMUNITY;
|
||||
default:
|
||||
return null;
|
||||
break;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -134,7 +136,7 @@ class User
|
|||
*
|
||||
* @return array system account
|
||||
*/
|
||||
public static function getSystemAccount()
|
||||
public static function getSystemAccount(): array
|
||||
{
|
||||
$system = Contact::selectFirst([], ['self' => true, 'uid' => 0]);
|
||||
if (!DBA::isResult($system)) {
|
||||
|
@ -244,7 +246,7 @@ class User
|
|||
*
|
||||
* @return string actor account name
|
||||
*/
|
||||
public static function getActorName()
|
||||
public static function getActorName(): string
|
||||
{
|
||||
$system_actor_name = DI::config()->get('system', 'actor_name');
|
||||
if (!empty($system_actor_name)) {
|
||||
|
@ -278,7 +280,7 @@ class User
|
|||
* @return boolean
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function exists($uid)
|
||||
public static function exists(int $uid): bool
|
||||
{
|
||||
return DBA::exists('user', ['uid' => $uid]);
|
||||
}
|
||||
|
@ -289,7 +291,7 @@ class User
|
|||
* @return array|boolean User record if it exists, false otherwise
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getById($uid, array $fields = [])
|
||||
public static function getById(int $uid, array $fields = [])
|
||||
{
|
||||
return !empty($uid) ? DBA::selectFirst('user', $fields, ['uid' => $uid]) : [];
|
||||
}
|
||||
|
@ -321,7 +323,7 @@ class User
|
|||
* @return array|boolean User record if it exists, false otherwise
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getByNickname($nickname, array $fields = [])
|
||||
public static function getByNickname(string $nickname, array $fields = [])
|
||||
{
|
||||
return DBA::selectFirst('user', $fields, ['nickname' => $nickname]);
|
||||
}
|
||||
|
@ -334,7 +336,7 @@ class User
|
|||
* @return integer user id
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getIdForURL(string $url)
|
||||
public static function getIdForURL(string $url): int
|
||||
{
|
||||
// Avoid database queries when the local node hostname isn't even part of the url.
|
||||
if (!Contact::isLocal($url)) {
|
||||
|
@ -362,14 +364,12 @@ class User
|
|||
/**
|
||||
* Get a user based on its email
|
||||
*
|
||||
* @param string $email
|
||||
* @param array $fields
|
||||
*
|
||||
* @param string $email
|
||||
* @param array $fields
|
||||
* @return array|boolean User record if it exists, false otherwise
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getByEmail($email, array $fields = [])
|
||||
public static function getByEmail(string $email, array $fields = [])
|
||||
{
|
||||
return DBA::selectFirst('user', $fields, ['email' => $email]);
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ class User
|
|||
* @param array $fields
|
||||
* @return array user
|
||||
*/
|
||||
public static function getFirstAdmin(array $fields = [])
|
||||
public static function getFirstAdmin(array $fields = []) : array
|
||||
{
|
||||
if (!empty(DI::config()->get('config', 'admin_nickname'))) {
|
||||
return self::getByNickname(DI::config()->get('config', 'admin_nickname'), $fields);
|
||||
|
@ -469,7 +469,7 @@ class User
|
|||
* @return boolean|array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getOwnerDataByNick($nick)
|
||||
public static function getOwnerDataByNick(string $nick)
|
||||
{
|
||||
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $nick]);
|
||||
|
||||
|
@ -488,7 +488,7 @@ class User
|
|||
* @return int group id
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getDefaultGroup($uid)
|
||||
public static function getDefaultGroup(int $uid): int
|
||||
{
|
||||
$user = DBA::selectFirst('user', ['def_gid'], ['uid' => $uid]);
|
||||
if (DBA::isResult($user)) {
|
||||
|
@ -512,7 +512,7 @@ class User
|
|||
* @throws HTTPException\ForbiddenException
|
||||
* @throws HTTPException\NotFoundException
|
||||
*/
|
||||
public static function getIdFromPasswordAuthentication($user_info, $password, $third_party = false)
|
||||
public static function getIdFromPasswordAuthentication($user_info, string $password, bool $third_party = false): int
|
||||
{
|
||||
// Addons registered with the "authenticate" hook may create the user on the
|
||||
// fly. `getAuthenticationInfo` will fail if the user doesn't exist yet. If
|
||||
|
@ -580,7 +580,7 @@ class User
|
|||
* @return int User Id if authentication is successful
|
||||
* @throws HTTPException\ForbiddenException
|
||||
*/
|
||||
public static function getIdFromAuthenticateHooks($username, $password)
|
||||
public static function getIdFromAuthenticateHooks(string $username, string $password): int
|
||||
{
|
||||
$addon_auth = [
|
||||
'username' => $username,
|
||||
|
@ -613,7 +613,7 @@ class User
|
|||
* - User array with at least the uid and the hashed password
|
||||
*
|
||||
* @param mixed $user_info
|
||||
* @return array
|
||||
* @return array|null Null if not found/determined
|
||||
* @throws HTTPException\NotFoundException
|
||||
*/
|
||||
public static function getAuthenticationInfo($user_info)
|
||||
|
@ -671,7 +671,7 @@ class User
|
|||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function generateNewPassword()
|
||||
public static function generateNewPassword(): string
|
||||
{
|
||||
return ucfirst(Strings::getRandomName(8)) . random_int(1000, 9999);
|
||||
}
|
||||
|
@ -683,7 +683,7 @@ class User
|
|||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function isPasswordExposed($password)
|
||||
public static function isPasswordExposed(string $password): bool
|
||||
{
|
||||
$cache = new CacheItemPool();
|
||||
$cache->changeConfig([
|
||||
|
@ -712,7 +712,7 @@ class User
|
|||
* @param string $password
|
||||
* @return string
|
||||
*/
|
||||
private static function hashPasswordLegacy($password)
|
||||
private static function hashPasswordLegacy(string $password): string
|
||||
{
|
||||
return hash('whirlpool', $password);
|
||||
}
|
||||
|
@ -724,7 +724,7 @@ class User
|
|||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function hashPassword($password)
|
||||
public static function hashPassword(string $password): string
|
||||
{
|
||||
if (!trim($password)) {
|
||||
throw new Exception(DI::l10n()->t('Password can\'t be empty'));
|
||||
|
@ -741,7 +741,7 @@ class User
|
|||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function updatePassword($uid, $password)
|
||||
public static function updatePassword(int $uid, string $password): bool
|
||||
{
|
||||
$password = trim($password);
|
||||
|
||||
|
@ -771,7 +771,7 @@ class User
|
|||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function updatePasswordHashed($uid, $pasword_hashed)
|
||||
private static function updatePasswordHashed(int $uid, string $pasword_hashed): bool
|
||||
{
|
||||
$fields = [
|
||||
'password' => $pasword_hashed,
|
||||
|
@ -792,7 +792,7 @@ class User
|
|||
* @param string $nickname The nickname that should be checked
|
||||
* @return boolean True is the nickname is blocked on the node
|
||||
*/
|
||||
public static function isNicknameBlocked($nickname)
|
||||
public static function isNicknameBlocked(string $nickname): bool
|
||||
{
|
||||
$forbidden_nicknames = DI::config()->get('system', 'forbidden_nicknames', '');
|
||||
if (!empty($forbidden_nicknames)) {
|
||||
|
@ -829,7 +829,7 @@ class User
|
|||
* @return string avatar link
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getAvatarUrl(array $user, string $size = ''):string
|
||||
public static function getAvatarUrl(array $user, string $size = ''): string
|
||||
{
|
||||
if (empty($user['nickname'])) {
|
||||
DI::logger()->warning('Missing user nickname key', ['trace' => System::callstack(20)]);
|
||||
|
@ -871,7 +871,7 @@ class User
|
|||
* @return string banner link
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getBannerUrl(array $user):string
|
||||
public static function getBannerUrl(array $user): string
|
||||
{
|
||||
if (empty($user['nickname'])) {
|
||||
DI::logger()->warning('Missing user nickname key', ['trace' => System::callstack(20)]);
|
||||
|
@ -913,7 +913,7 @@ class User
|
|||
* @throws ImagickException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function create(array $data)
|
||||
public static function create(array $data): array
|
||||
{
|
||||
$return = ['user' => null, 'password' => ''];
|
||||
|
||||
|
@ -1164,32 +1164,32 @@ class User
|
|||
|
||||
$type = Images::getMimeTypeByData($img_str, $photo, $type);
|
||||
|
||||
$Image = new Image($img_str, $type);
|
||||
if ($Image->isValid()) {
|
||||
$Image->scaleToSquare(300);
|
||||
$image = new Image($img_str, $type);
|
||||
if ($image->isValid()) {
|
||||
$image->scaleToSquare(300);
|
||||
|
||||
$resource_id = Photo::newResource();
|
||||
|
||||
// Not using Photo::PROFILE_PHOTOS here, so that it is discovered as translateble string
|
||||
$profile_album = DI::l10n()->t('Profile Photos');
|
||||
|
||||
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 4);
|
||||
$r = Photo::store($image, $uid, 0, $resource_id, $filename, $profile_album, 4);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
}
|
||||
|
||||
$Image->scaleDown(80);
|
||||
$image->scaleDown(80);
|
||||
|
||||
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 5);
|
||||
$r = Photo::store($image, $uid, 0, $resource_id, $filename, $profile_album, 5);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
}
|
||||
|
||||
$Image->scaleDown(48);
|
||||
$image->scaleDown(48);
|
||||
|
||||
$r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 6);
|
||||
$r = Photo::store($image, $uid, 0, $resource_id, $filename, $profile_album, 6);
|
||||
|
||||
if ($r === false) {
|
||||
$photo_failure = true;
|
||||
|
@ -1255,7 +1255,7 @@ class User
|
|||
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function block(int $uid, bool $block = true)
|
||||
public static function block(int $uid, bool $block = true): bool
|
||||
{
|
||||
return DBA::update('user', ['blocked' => $block], ['uid' => $uid]);
|
||||
}
|
||||
|
@ -1270,7 +1270,7 @@ class User
|
|||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function allow(string $hash)
|
||||
public static function allow(string $hash): bool
|
||||
{
|
||||
$register = Register::getByHash($hash);
|
||||
if (!DBA::isResult($register)) {
|
||||
|
@ -1316,7 +1316,7 @@ class User
|
|||
* @return bool True, if the deny was successfull
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function deny(string $hash)
|
||||
public static function deny(string $hash): bool
|
||||
{
|
||||
$register = Register::getByHash($hash);
|
||||
if (!DBA::isResult($register)) {
|
||||
|
@ -1342,13 +1342,12 @@ class User
|
|||
* @param string $email The user's email address
|
||||
* @param string $nick The user's nick name
|
||||
* @param string $lang The user's language (default is english)
|
||||
*
|
||||
* @return bool True, if the user was created successfully
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws ErrorException
|
||||
* @throws ImagickException
|
||||
*/
|
||||
public static function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT)
|
||||
public static function createMinimal(string $name, string $email, string $nick, string $lang = L10n::DEFAULT): bool
|
||||
{
|
||||
if (empty($name) ||
|
||||
empty($email) ||
|
||||
|
@ -1418,7 +1417,7 @@ class User
|
|||
* @return NULL|boolean from notification() and email() inherited
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function sendRegisterPendingEmail($user, $sitename, $siteurl, $password)
|
||||
public static function sendRegisterPendingEmail(array $user, string $sitename, string $siteurl, string $password)
|
||||
{
|
||||
$body = Strings::deindent(DI::l10n()->t(
|
||||
'
|
||||
|
@ -1461,7 +1460,7 @@ class User
|
|||
* @return NULL|boolean from notification() and email() inherited
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function sendRegisterOpenEmail(L10n $l10n, $user, $sitename, $siteurl, $password)
|
||||
public static function sendRegisterOpenEmail(L10n $l10n, array $user, string $sitename, string $siteurl, string $password)
|
||||
{
|
||||
$preamble = Strings::deindent($l10n->t(
|
||||
'
|
||||
|
@ -1520,7 +1519,7 @@ class User
|
|||
* @return bool
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function remove(int $uid)
|
||||
public static function remove(int $uid): bool
|
||||
{
|
||||
if (empty($uid)) {
|
||||
return false;
|
||||
|
@ -1574,7 +1573,7 @@ class User
|
|||
* ]
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function identities($uid)
|
||||
public static function identities(int $uid): array
|
||||
{
|
||||
if (empty($uid)) {
|
||||
return [];
|
||||
|
@ -1646,7 +1645,7 @@ class User
|
|||
* @param int $uid
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasIdentities(int $uid):bool
|
||||
public static function hasIdentities(int $uid): bool
|
||||
{
|
||||
if (empty($uid)) {
|
||||
return false;
|
||||
|
@ -1679,7 +1678,7 @@ class User
|
|||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getStatistics()
|
||||
public static function getStatistics(): array
|
||||
{
|
||||
$statistics = [
|
||||
'total_users' => 0,
|
||||
|
@ -1731,11 +1730,10 @@ class User
|
|||
* @param string $type The type of users, which should get (all, bocked, removed)
|
||||
* @param string $order Order of the user list (Default is 'contact.name')
|
||||
* @param bool $descending Order direction (Default is ascending)
|
||||
*
|
||||
* @return array The list of the users
|
||||
* @return array|bool The list of the users
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getList($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'name', bool $descending = false)
|
||||
public static function getList(int $start = 0, int $count = Pager::ITEMS_PER_PAGE, string $type = 'all', string $order = 'name', bool $descending = false)
|
||||
{
|
||||
$param = ['limit' => [$start, $count], 'order' => [$order => $descending]];
|
||||
$condition = [];
|
||||
|
@ -1744,11 +1742,13 @@ class User
|
|||
$condition['account_removed'] = false;
|
||||
$condition['blocked'] = false;
|
||||
break;
|
||||
|
||||
case 'blocked':
|
||||
$condition['account_removed'] = false;
|
||||
$condition['blocked'] = true;
|
||||
$condition['verified'] = true;
|
||||
break;
|
||||
|
||||
case 'removed':
|
||||
$condition['account_removed'] = true;
|
||||
break;
|
||||
|
|
|
@ -52,12 +52,12 @@ class Cookie
|
|||
private $data;
|
||||
|
||||
/**
|
||||
* @param App\Request $request The current http request
|
||||
* @param IManageConfigValues $config
|
||||
* @param App\BaseURL $baseURL
|
||||
* @param array $SERVER The $_SERVER array
|
||||
* @param array $COOKIE The $_COOKIE array
|
||||
*/
|
||||
public function __construct(IManageConfigValues $config, App\BaseURL $baseURL, array $SERVER = [], array $COOKIE = [])
|
||||
public function __construct(App\Request $request, IManageConfigValues $config, App\BaseURL $baseURL, array $COOKIE = [])
|
||||
{
|
||||
$this->sslEnabled = $baseURL->getSSLPolicy() === App\BaseURL::SSL_POLICY_FULL;
|
||||
$this->sitePrivateKey = $config->get('system', 'site_prvkey');
|
||||
|
@ -66,7 +66,7 @@ class Cookie
|
|||
self::DEFAULT_EXPIRE);
|
||||
$this->lifetime = $authCookieDays * 24 * 60 * 60;
|
||||
|
||||
$this->remoteAddr = ($SERVER['REMOTE_ADDR'] ?? null) ?: '0.0.0.0';
|
||||
$this->remoteAddr = $request->getRemoteAddress();
|
||||
|
||||
$this->data = json_decode($COOKIE[self::NAME] ?? '[]', true) ?: [];
|
||||
}
|
||||
|
@ -124,6 +124,19 @@ class Cookie
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the cookie to a given data set
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reset(array $data): bool
|
||||
{
|
||||
return $this->clear() &&
|
||||
$this->setMultiple($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the Friendica cookie
|
||||
*/
|
||||
|
@ -131,7 +144,7 @@ class Cookie
|
|||
{
|
||||
$this->data = [];
|
||||
// make sure cookie is deleted on browser close, as a security measure
|
||||
return $this->setCookie( '', -3600, $this->sslEnabled);
|
||||
return $this->setCookie('', -3600, $this->sslEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,7 +174,7 @@ class Cookie
|
|||
*
|
||||
*/
|
||||
protected function setCookie(string $value = null, int $expire = null,
|
||||
bool $secure = null): bool
|
||||
bool $secure = null): bool
|
||||
{
|
||||
return setcookie(self::NAME, $value, $expire, self::PATH, self::DOMAIN, $secure, self::HTTPONLY);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class Verb
|
|||
* @return integer verb id
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getID(string $verb)
|
||||
public static function getID(string $verb): int
|
||||
{
|
||||
if (empty($verb)) {
|
||||
return 0;
|
||||
|
@ -56,7 +56,7 @@ class Verb
|
|||
* @param integer $id
|
||||
* @return string verb
|
||||
*/
|
||||
public static function getByID(int $id)
|
||||
public static function getByID(int $id): string
|
||||
{
|
||||
if (empty($id)) {
|
||||
return '';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue