* @return array
* @throws \Exception
*/
- public static function getById(int $gid)
+ public static function getById(int $gid): array
{
$return = [];
* @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);
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)) {
* @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');
}
/**
- * @param int $uid user
+ * Returns an array of sugguested 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;
// 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)]);
* @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);
}
* @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)
* @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`)
* @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)
* @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`)
* @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)
/**
* 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 Fields
+ * @param array $condition Conditions
+ * @return void
+ * @throws PDOException
+ * @throws Exception
*/
public static function updateByContactUpdate(array $fields, array $condition)
{
* @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)) {
* @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)) {
* @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)) {
*
* @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)) {
* @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)) {
*
* @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;
* @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)) {
*
* @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)) {
private $filters = [];
/** @var string search term */
- private $search = "";
+ private $search = '';
/**
$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;
}
*/
private function search(ParsedLogLine $parsedlogline): bool
{
- if ($this->search != "") {
+ if ($this->search != '') {
return strstr($parsedlogline->logline, $this->search) !== false;
}
return true;
* 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()
* @see ReversedFileReader::key()
* @return int
*/
- public function key()
+ public function key(): int
{
return $this->reader->key();
}
* @see Iterator::valid()
* @return bool
*/
- public function valid()
+ public function valid(): bool
{
- return ! is_null($this->value);
+ return !is_null($this->value);
}
}
* @return string The text for the next steps
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- private function whatNext()
+ private function whatNext(): string
{
$baseurl = $this->baseUrl->get();
return
* @param string $cat The category of the setting
* @param string $key The key of the setting
* @param null|string $default The default value
+ * @return void
*/
private function checkSetting(Cache $configCache, array $post, string $cat, string $key, ?string $default = null)
{
$exception = new HTTPException\ServiceUnavailableException($reason);
- header($_SERVER["SERVER_PROTOCOL"] . ' ' . $exception->getCode() . ' ' . DI::l10n()->t('System down for maintenance'));
+ header($_SERVER['SERVER_PROTOCOL'] . ' ' . $exception->getCode() . ' ' . DI::l10n()->t('System down for maintenance'));
$tpl = Renderer::getMarkupTemplate('exception.tpl');
$profile_fields = ['about', 'locality', 'region', 'postal-code', 'country-name', 'xmpp', 'matrix'];
foreach ($profile_fields as $field) {
if (!empty($owner[$field])) {
- $json_info["$field"] = $owner[$field];
+ $json_info[$field] = $owner[$field];
}
}
* @param int $uriId
* @return string
*/
- private function fetchReceivers(int $uriId):string
+ private function fetchReceivers(int $uriId): string
{
$own_url = '';
$uid = local_user();
{
$totalstamp = microtime(true);
- if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
- header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
- if (!empty($_SERVER["HTTP_IF_NONE_MATCH"])) {
- header("Etag: " . $_SERVER["HTTP_IF_NONE_MATCH"]);
+ if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
+ header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
+ if (!empty($_SERVER['HTTP_IF_NONE_MATCH'])) {
+ header('Etag: ' . $_SERVER['HTTP_IF_NONE_MATCH']);
}
- header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
- header("Cache-Control: max-age=31536000");
- if (function_exists("header_remove")) {
- header_remove("Last-Modified");
- header_remove("Expires");
- header_remove("Cache-Control");
+ header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT');
+ header('Cache-Control: max-age=31536000');
+ if (function_exists('header_remove')) {
+ header_remove('Last-Modified');
+ header_remove('Expires');
+ header_remove('Cache-Control');
}
throw new NotModifiedException();
}
} else {
$photoid = pathinfo($this->parameters['name'], PATHINFO_FILENAME);
$scale = 0;
- if (substr($photoid, -2, 1) == "-") {
+ if (substr($photoid, -2, 1) == '-') {
$scale = intval(substr($photoid, -1, 1));
$photoid = substr($photoid, 0, -2);
}
throw new HTTPException\NotFoundException();
}
- $cacheable = ($photo["allow_cid"] . $photo["allow_gid"] . $photo["deny_cid"] . $photo["deny_gid"] === "") && (isset($photo["cacheable"]) ? $photo["cacheable"] : true);
+ $cacheable = ($photo['allow_cid'] . $photo['allow_gid'] . $photo['deny_cid'] . $photo['deny_gid'] === '') && (isset($photo['cacheable']) ? $photo['cacheable'] : true);
$stamp = microtime(true);
}
// if customsize is set and image is not a gif, resize it
- if ($photo['type'] !== "image/gif" && $customsize > 0 && $customsize <= Proxy::PIXEL_THUMB && $square_resize) {
+ if ($photo['type'] !== 'image/gif' && $customsize > 0 && $customsize <= Proxy::PIXEL_THUMB && $square_resize) {
$img = new Image($imgdata, $photo['type']);
$img->scaleToSquare($customsize);
$imgdata = $img->asString();
- } elseif ($photo['type'] !== "image/gif" && $customsize > 0) {
+ } elseif ($photo['type'] !== 'image/gif' && $customsize > 0) {
$img = new Image($imgdata, $photo['type']);
$img->scaleDown($customsize);
$imgdata = $img->asString();
}
- if (function_exists("header_remove")) {
- header_remove("Pragma");
- header_remove("pragma");
+ if (function_exists('header_remove')) {
+ header_remove('Pragma');
+ header_remove('pragma');
}
- header("Content-type: " . $photo['type']);
+ header('Content-type: ' . $photo['type']);
$stamp = microtime(true);
if (!$cacheable) {
// it is a private photo that they have no permission to view.
// tell the browser not to cache it, in case they authenticate
// and subsequently have permission to see it
- header("Cache-Control: no-store, no-cache, must-revalidate");
+ header('Cache-Control: no-store, no-cache, must-revalidate');
} else {
$md5 = $photo['hash'] ?: md5($imgdata);
- header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
+ header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
header("Etag: \"{$md5}\"");
- header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
- header("Cache-Control: max-age=31536000");
+ header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT');
+ header('Cache-Control: max-age=31536000');
}
$checksum = microtime(true) - $stamp;
throw new \Friendica\Network\HTTPException\NotFoundException();
}
- if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
- header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
- if (!empty($_SERVER["HTTP_IF_NONE_MATCH"])) {
- header("Etag: " . $_SERVER["HTTP_IF_NONE_MATCH"]);
+ if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
+ header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
+ if (!empty($_SERVER['HTTP_IF_NONE_MATCH'])) {
+ header('Etag: ' . $_SERVER['HTTP_IF_NONE_MATCH']);
}
- header("Expires: " . gmdate("D, d M Y H:i:s", time() + (31536000)) . " GMT");
- header("Cache-Control: max-age=31536000");
- if (function_exists("header_remove")) {
- header_remove("Last-Modified");
- header_remove("Expires");
- header_remove("Cache-Control");
+ header('Expires: ' . gmdate('D, d M Y H:i:s', time() + (31536000)) . ' GMT');
+ header('Cache-Control: max-age=31536000');
+ if (function_exists('header_remove')) {
+ header_remove('Last-Modified');
+ header_remove('Expires');
+ header_remove('Cache-Control');
}
throw new NotModifiedException();
}
* ]
* @throws \Exception
*/
- private function getRequestInfo()
+ private function getRequestInfo(): array
{
$size = ProxyUtils::PIXEL_LARGE;
$sizetype = '';
* Output the image with cache headers
*
* @param Image $img
+ * @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function responseImageHttpCache(Image $img)