mirror of
https://github.com/friendica/friendica
synced 2024-09-14 13:07:48 +02:00
Merge pull request #11677 from Quix0r/rewrites/type-hints-doc-001
Rewrites/type hints doc 001
This commit is contained in:
commit
d322e9288b
9
boot.php
9
boot.php
|
@ -87,8 +87,8 @@ define('PRIORITIES', [PRIORITY_CRITICAL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORIT
|
|||
/* @}*/
|
||||
|
||||
// Normally this constant is defined - but not if "pcntl" isn't installed
|
||||
if (!defined("SIGTERM")) {
|
||||
define("SIGTERM", 15);
|
||||
if (!defined('SIGTERM')) {
|
||||
define('SIGTERM', 15);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,6 +117,7 @@ function local_user()
|
|||
if (!empty($_SESSION['authenticated']) && !empty($_SESSION['uid'])) {
|
||||
return intval($_SESSION['uid']);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -169,7 +170,7 @@ function remote_user()
|
|||
*
|
||||
* @param string $s - Text of notice
|
||||
*/
|
||||
function notice($s)
|
||||
function notice(string $s)
|
||||
{
|
||||
if (empty($_SESSION)) {
|
||||
return;
|
||||
|
@ -189,7 +190,7 @@ function notice($s)
|
|||
*
|
||||
* @param string $s - Text of notice
|
||||
*/
|
||||
function info($s)
|
||||
function info(string $s)
|
||||
{
|
||||
if (empty($_SESSION)) {
|
||||
return;
|
||||
|
|
|
@ -1761,7 +1761,6 @@ class Database
|
|||
* Checks if $array is a filled array with at least one entry.
|
||||
*
|
||||
* @param mixed $array A filled array with at least one entry
|
||||
*
|
||||
* @return boolean Whether $array is a filled array or an object with rows
|
||||
*/
|
||||
public function isResult($array): bool
|
||||
|
@ -1842,6 +1841,7 @@ class Database
|
|||
$upds = implode(', ', $upd);
|
||||
|
||||
$r = $this->e(sprintf("UPDATE %s SET %s;", DBA::quoteIdentifier($table), $upds));
|
||||
|
||||
if (!$this->isResult($r)) {
|
||||
throw new \RuntimeException("Failed updating `$table`: " . $this->errorMessage());
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -82,11 +82,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 +106,7 @@ class User
|
|||
DBA::close($contacts);
|
||||
}
|
||||
|
||||
DBA::commit();
|
||||
DBA::commit();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,9 +138,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 +171,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)) {
|
||||
|
@ -208,9 +209,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 +231,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)) {
|
||||
|
@ -271,9 +272,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 +290,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;
|
||||
|
@ -318,9 +319,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 +337,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)) {
|
||||
|
|
|
@ -683,7 +683,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
|
||||
|
|
|
@ -45,7 +45,7 @@ class ParsedLogIterator implements \Iterator
|
|||
private $filters = [];
|
||||
|
||||
/** @var string search term */
|
||||
private $search = "";
|
||||
private $search = '';
|
||||
|
||||
|
||||
/**
|
||||
|
@ -108,10 +108,11 @@ class ParsedLogIterator implements \Iterator
|
|||
$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;
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ class ParsedLogIterator implements \Iterator
|
|||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ class OpenWebAuthToken
|
|||
* @param int $uid The user ID.
|
||||
* @param string $token
|
||||
* @param string $meta
|
||||
*
|
||||
* @return boolean
|
||||
* @throws \Exception
|
||||
*/
|
||||
|
@ -80,6 +79,7 @@ class OpenWebAuthToken
|
|||
*
|
||||
* @param string $type Verify type.
|
||||
* @param string $interval SQL compatible time interval
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function purge(string $type, string $interval)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -162,7 +162,6 @@ 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): string
|
||||
|
|
|
@ -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,14 +73,14 @@ class Tag
|
|||
/**
|
||||
* Store tag/mention elements
|
||||
*
|
||||
* @param integer $uriid URI id
|
||||
* @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
|
||||
|
@ -89,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;
|
||||
}
|
||||
|
@ -143,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;
|
||||
|
@ -156,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)]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,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];
|
||||
|
||||
|
@ -243,6 +243,9 @@ class Tag
|
|||
return $tid;
|
||||
}
|
||||
|
||||
// Also log type
|
||||
$fields['type'] = $type;
|
||||
|
||||
Logger::error('No tag id created', $fields);
|
||||
return 0;
|
||||
}
|
||||
|
@ -250,21 +253,21 @@ class Tag
|
|||
/**
|
||||
* Store tag/mention elements
|
||||
*
|
||||
* @param integer $uriid URI id
|
||||
* @param string $hash Hash
|
||||
* @param string $name Name
|
||||
* @param string $url URL
|
||||
* @param integer $uriId
|
||||
* @param string $hash
|
||||
* @param string $name
|
||||
* @param string $url
|
||||
* @param boolean $probing Whether probing is active
|
||||
* @return void
|
||||
*/
|
||||
public static function storeByHash(int $uriid, string $hash, string $name, string $url = '', bool $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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -275,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];
|
||||
|
@ -291,15 +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, bool $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];
|
||||
|
@ -315,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -331,52 +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 URI id
|
||||
* @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;
|
||||
}
|
||||
|
@ -386,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;
|
||||
|
@ -432,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);
|
||||
}
|
||||
|
@ -455,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]';
|
||||
}
|
||||
|
||||
|
@ -494,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' => [],
|
||||
|
@ -503,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]]);
|
||||
|
@ -524,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'])) {
|
||||
|
@ -534,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);
|
||||
|
@ -551,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);
|
||||
}
|
||||
|
@ -563,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]);
|
||||
|
@ -587,13 +600,13 @@ class Tag
|
|||
|
||||
$tags = DBA::select('tag-search-view', |