Merge pull request #11699 from Quix0r/rewrites/type-hints-001

Type-hints added, method renamed
This commit is contained in:
Hypolite Petovan 2022-06-30 12:25:20 -04:00 committed by GitHub
commit ef5d178e00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 290 additions and 231 deletions

View file

@ -83,7 +83,7 @@ function editpost_content(App $a)
Hook::callAll('jot_tool', $jotplugins);
$tpl = Renderer::getMarkupTemplate("jot.tpl");
$tpl = Renderer::getMarkupTemplate('jot.tpl');
$o .= Renderer::replaceMacros($tpl, [
'$is_edit' => true,
'$return_path' => '/display/' . $item['guid'],

View file

@ -130,6 +130,9 @@ class BoundariesPager extends Pager
return Renderer::replaceMacros($tpl, ['pager' => $data]);
}
/**
* Unsupported method, must be type-compatible
*/
public function renderFull(int $itemCount): string
{
throw new \BadMethodCallException();

View file

@ -582,7 +582,7 @@ class Conversation
$uriids[] = $item['uri-id'];
if (!$this->item->visibleActivity($item)) {
if (!$this->item->isVisibleActivity($item)) {
continue;
}
@ -745,7 +745,7 @@ class Conversation
continue;
}
if (!$this->item->visibleActivity($item)) {
if (!$this->item->isVisibleActivity($item)) {
continue;
}

View file

@ -85,7 +85,7 @@ class Item
* ]
* ]
*/
public function determineCategoriesTerms(array $item, int $uid = 0)
public function determineCategoriesTerms(array $item, int $uid = 0): array
{
$categories = [];
$folders = [];
@ -142,15 +142,15 @@ class Item
* the appropriate link.
*
* @param string $body the text to replace the tag in
* @param integer $profile_uid the user id to replace the tag for (0 = anyone)
* @param int $profile_uid the user id to replace the tag for (0 = anyone)
* @param string $tag the tag to replace
* @param string $network The network of the post
*
* @return array|bool ['replaced' => $replaced, 'contact' => $contact];
* @return array|bool ['replaced' => $replaced, 'contact' => $contact] or "false" on if already replaced
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function replaceTag(&$body, $profile_uid, $tag, $network = '')
public static function replaceTag(string &$body, int $profile_uid, string $tag, string $network = '')
{
$replaced = false;
@ -244,16 +244,17 @@ class Item
/**
* Render actions localized
*
* @param $item
* @param array $item
* @return void
* @throws ImagickException
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function localize(&$item)
public function localize(array &$item)
{
$this->profiler->startRecording('rendering');
/// @todo The following functionality needs to be cleaned up.
if (!empty($item['verb'])) {
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
$xmlhead = '<?xml version="1.0" encoding="UTF-8" ?>';
if (stristr($item['verb'], Activity::POKE)) {
$verb = urldecode(substr($item['verb'], strpos($item['verb'],'#') + 1));
@ -261,7 +262,7 @@ class Item
$this->profiler->stopRecording();
return;
}
if ($item['object-type'] == "" || $item['object-type'] !== Activity\ObjectType::PERSON) {
if ($item['object-type'] == '' || $item['object-type'] !== Activity\ObjectType::PERSON) {
$this->profiler->stopRecording();
return;
}
@ -270,18 +271,22 @@ class Item
$Bname = $obj->title;
$Blink = $obj->id;
$Bphoto = "";
$Bphoto = '';
foreach ($obj->link as $l) {
$atts = $l->attributes();
switch ($atts['rel']) {
case "alternate": $Blink = $atts['href'];
case "photo": $Bphoto = $atts['href'];
case 'alternate': $Blink = $atts['href'];
case 'photo': $Bphoto = $atts['href'];
}
}
$author = ['uid' => 0, 'id' => $item['author-id'],
'network' => $item['author-network'], 'url' => $item['author-link']];
$author = [
'uid' => 0,
'id' => $item['author-id'],
'network' => $item['author-network'],
'url' => $item['author-link'],
];
$A = '[url=' . Contact::magicLinkByContact($author) . ']' . $item['author-name'] . '[/url]';
if (!empty($Blink)) {
@ -290,7 +295,7 @@ class Item
$B = '';
}
if ($Bphoto != "" && !empty($Blink)) {
if ($Bphoto != '' && !empty($Blink)) {
$Bphoto = '[url=' . Contact::magicLink($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
}
@ -305,9 +310,7 @@ class Item
$txt = str_replace($poked_t, $this->l10n->t($verb), $txt);
// then do the sprintf on the translation string
$item['body'] = sprintf($txt, $A, $B) . "\n\n\n" . $Bphoto;
}
if ($this->activity->match($item['verb'], Activity::TAG)) {
@ -319,12 +322,20 @@ class Item
return;
}
$author_arr = ['uid' => 0, 'id' => $item['author-id'],
'network' => $item['author-network'], 'url' => $item['author-link']];
$author_arr = [
'uid' => 0,
'id' => $item['author-id'],
'network' => $item['author-network'],
'url' => $item['author-link'],
];
$author = '[url=' . Contact::magicLinkByContact($author_arr) . ']' . $item['author-name'] . '[/url]';
$author_arr = ['uid' => 0, 'id' => $obj['author-id'],
'network' => $obj['author-network'], 'url' => $obj['author-link']];
$author_arr = [
'uid' => 0,
'id' => $obj['author-id'],
'network' => $obj['author-network'],
'url' => $obj['author-link'],
];
$objauthor = '[url=' . Contact::magicLinkByContact($author_arr) . ']' . $obj['author-name'] . '[/url]';
switch ($obj['verb']) {
@ -337,6 +348,7 @@ class Item
$post_type = $this->l10n->t('status');
}
break;
default:
if ($obj['resource-id']) {
$post_type = $this->l10n->t('photo');
@ -360,25 +372,29 @@ class Item
$this->profiler->stopRecording();
}
public function photoMenu($item, string $formSecurityToken)
/**
* Renders photo menu based on item
*
* @param array $item
* @param string $formSecurityToken
* @return string
*/
public function photoMenu(array $item, string $formSecurityToken): string
{
$this->profiler->startRecording('rendering');
$sub_link = '';
$poke_link = '';
$contact_url = '';
$pm_url = '';
$status_link = '';
$photos_link = '';
$posts_link = '';
$block_link = '';
$ignore_link = '';
$sub_link = $poke_link = $contact_url = $pm_url = $status_link = '';
$photos_link = $posts_link = $block_link = $ignore_link = '';
if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
$sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;';
}
$author = ['uid' => 0, 'id' => $item['author-id'],
'network' => $item['author-network'], 'url' => $item['author-link']];
$author = [
'uid' => 0,
'id' => $item['author-id'],
'network' => $item['author-network'],
'url' => $item['author-link'],
];
$profile_link = Contact::magicLinkByContact($author, $item['author-link']);
$sparkle = (strpos($profile_link, 'redir/') === 0);
@ -435,7 +451,7 @@ class Item
}
if ($network == Protocol::DFRN) {
$menu[$this->l10n->t("Poke")] = $poke_link;
$menu[$this->l10n->t('Poke')] = $poke_link;
}
if ((($cid == 0) || ($rel == Contact::FOLLOWER)) &&
@ -465,24 +481,28 @@ class Item
return $o;
}
public function visibleActivity($item) {
/**
* Checks if the activity is visible to current user
*
* @param array $item Activity item
* @return bool Whether the item is visible to the user
*/
public function isVisibleActivity(array $item): bool
{
// Empty verb or hidden?
if (empty($item['verb']) || $this->activity->isHidden($item['verb'])) {
return false;
}
// @TODO below if() block can be rewritten to a single line: $isVisible = allConditionsHere;
if ($this->activity->match($item['verb'], Activity::FOLLOW) &&
// Check conditions
return (!($this->activity->match($item['verb'], Activity::FOLLOW) &&
$item['object-type'] === Activity\ObjectType::NOTE &&
empty($item['self']) &&
$item['uid'] == local_user()) {
return false;
$item['uid'] == local_user())
);
}
return true;
}
public function expandTags(array $item, bool $setPermissions = false)
public function expandTags(array $item, bool $setPermissions = false): array
{
// Look for any tags and linkify them
$item['inform'] = '';

View file

@ -62,7 +62,7 @@ class Nav
*
* @param string $item
*/
public static function setSelected($item)
public static function setSelected(string $item)
{
self::$selected[$item] = 'selected';
}
@ -74,7 +74,7 @@ class Nav
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function build(App $a)
public static function build(App $a): string
{
// Placeholder div for popup panel
$nav = '<div id="panel" style="display: none;"></div>';
@ -106,7 +106,7 @@ class Nav
*
* @return array
*/
public static function getAppMenu()
public static function getAppMenu(): array
{
if (is_null(self::$app_menu)) {
self::populateAppMenu();
@ -117,6 +117,8 @@ class Nav
/**
* Fills the apps static variable with apps that require a menu
*
* @return void
*/
private static function populateAppMenu()
{

View file

@ -49,7 +49,13 @@ use Friendica\Util\Strings;
*/
class OEmbed
{
public static function replaceCallback($matches)
/**
* Callback for fetching URL, checking allowance and returning formatted HTML
*
* @param array $matches
* @return string Formatted HTML
*/
public static function replaceCallback(array $matches): string
{
$embedurl = $matches[1];
$j = self::fetchURL($embedurl, !self::isAllowedURL($embedurl));
@ -68,7 +74,7 @@ class OEmbed
* @return \Friendica\Object\OEmbed
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function fetchURL($embedurl, bool $no_rich_type = false, bool $use_parseurl = true)
public static function fetchURL(string $embedurl, bool $no_rich_type = false, bool $use_parseurl = true): \Friendica\Object\OEmbed
{
$embedurl = trim($embedurl, '\'"');
@ -209,12 +215,18 @@ class OEmbed
return $oembed;
}
private static function formatObject(\Friendica\Object\OEmbed $oembed)
/**
* Returns a formatted string from OEmbed object
*
* @param \Friendica\Object\OEmbed $oembed
* @return string
*/
private static function formatObject(\Friendica\Object\OEmbed $oembed): string
{
$ret = '<div class="oembed ' . $oembed->type . '">';
switch ($oembed->type) {
case "video":
case 'video':
if ($oembed->thumbnail_url) {
$tw = (isset($oembed->thumbnail_width) && intval($oembed->thumbnail_width)) ? $oembed->thumbnail_width : 200;
$th = (isset($oembed->thumbnail_height) && intval($oembed->thumbnail_height)) ? $oembed->thumbnail_height : 180;
@ -236,14 +248,14 @@ class OEmbed
}
break;
case "photo":
case 'photo':
$ret .= '<img width="' . $oembed->width . '" src="' . Proxy::proxifyUrl($oembed->url) . '">';
break;
case "link":
case 'link':
break;
case "rich":
case 'rich':
$ret .= Proxy::proxifyHtml($oembed->html);
break;
}
@ -292,9 +304,15 @@ class OEmbed
return str_replace("\n", "", $ret);
}
public static function BBCode2HTML($text)
/**
* Converts BBCode to HTML code
*
* @param string $text
* @return string
*/
public static function BBCode2HTML(string $text): string
{
$stopoembed = DI::config()->get("system", "no_oembed");
$stopoembed = DI::config()->get('system', 'no_oembed');
if ($stopoembed == true) {
return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "<!-- oembed $1 --><i>" . DI::l10n()->t('Embedding disabled') . " : $1</i><!-- /oembed $1 -->", $text);
}
@ -305,14 +323,13 @@ class OEmbed
* Find <span class='oembed'>..<a href='url' rel='oembed'>..</a></span>
* and replace it with [embed]url[/embed]
*
* @param $text
* @param string $text
* @return string
*/
public static function HTML2BBCode($text)
public static function HTML2BBCode(string $text): string
{
// start parser only if 'oembed' is in text
if (strpos($text, "oembed")) {
if (strpos($text, 'oembed')) {
// convert non ascii chars to html entities
$html_text = mb_convert_encoding($text, 'HTML-ENTITIES', mb_detect_encoding($text));
@ -323,17 +340,17 @@ class OEmbed
}
$xpath = new DOMXPath($dom);
$xattr = self::buildXPath("class", "oembed");
$xattr = self::buildXPath('class', 'oembed');
$entries = $xpath->query("//div[$xattr]");
$xattr = "@rel='oembed'"; //oe_build_xpath("rel","oembed");
foreach ($entries as $e) {
$href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue;
if (!is_null($href)) {
$e->parentNode->replaceChild(new DOMText("[embed]" . $href . "[/embed]"), $e);
$e->parentNode->replaceChild(new DOMText('[embed]' . $href . '[/embed]'), $e);
}
}
return self::getInnerHTML($dom->getElementsByTagName("body")->item(0));
return self::getInnerHTML($dom->getElementsByTagName('body')->item(0));
} else {
return $text;
}
@ -346,7 +363,7 @@ class OEmbed
* @return boolean
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function isAllowedURL($url)
public static function isAllowedURL(string $url): bool
{
if (!DI::config()->get('system', 'no_oembed_rich_content')) {
return true;
@ -367,7 +384,14 @@ class OEmbed
return Network::isDomainAllowed($domain, $allowed);
}
public static function getHTML($url, $title = null)
/**
* Returns a formmated HTML code from given URL and sets optional title
*
* @param string $url URL to fetch
* @param string $title Optional title (default: what comes from OEmbed object)
* @return string Formatted HTML
*/
public static function getHTML(string $url, string $title = '')
{
$o = self::fetchURL($url, !self::isAllowedURL($url));
@ -401,12 +425,12 @@ class OEmbed
* @param string $src Original remote URL to embed
* @param string $width
* @param string $height
* @return string formatted HTML
* @return string Formatted HTML
*
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @see oembed_format_object()
*/
private static function iframe($src, $width, $height)
private static function iframe(string $src, string $width, string $height): string
{
if (!$height || strstr($height, '%')) {
$height = '200';
@ -427,7 +451,7 @@ class OEmbed
* @param string $value Value to search in a space-separated list
* @return string
*/
private static function buildXPath($attr, $value)
private static function buildXPath(string $attr, $value): string
{
// https://www.westhoffswelt.de/blog/2009/6/9/select-html-elements-with-more-than-one-css-class-using-xpath
return "contains(normalize-space(@$attr), ' $value ') or substring(normalize-space(@$attr), 1, string-length('$value') + 1) = '$value ' or substring(normalize-space(@$attr), string-length(@$attr) - string-length('$value')) = ' $value' or @$attr = '$value'";
@ -439,7 +463,7 @@ class OEmbed
* @param DOMNode $node
* @return string
*/
private static function getInnerHTML(DOMNode $node)
private static function getInnerHTML(DOMNode $node): string
{
$innerHTML = '';
$children = $node->childNodes;

View file

@ -64,7 +64,7 @@ class PageInfo
* @return string
* @throws HTTPException\InternalServerErrorException
*/
public static function appendDataToBody(string $body, array $data, bool $no_photos = false)
public static function appendDataToBody(string $body, array $data, bool $no_photos = false): string
{
// Only one [attachment] tag per body is allowed
$existingAttachmentPos = strpos($body, '[attachment');
@ -90,7 +90,7 @@ class PageInfo
* @return string
* @throws HTTPException\InternalServerErrorException
*/
public static function getFooterFromUrl(string $url, bool $no_photos = false, string $photo = '', bool $keywords = false, string $keyword_denylist = '')
public static function getFooterFromUrl(string $url, bool $no_photos = false, string $photo = '', bool $keywords = false, string $keyword_denylist = ''): string
{
$data = self::queryUrl($url, $photo, $keywords, $keyword_denylist);
@ -103,7 +103,7 @@ class PageInfo
* @return string
* @throws HTTPException\InternalServerErrorException
*/
public static function getFooterFromData(array $data, bool $no_photos = false)
public static function getFooterFromData(array $data, bool $no_photos = false): string
{
Hook::callAll('page_info_data', $data);
@ -220,7 +220,7 @@ class PageInfo
* @return array
* @throws HTTPException\InternalServerErrorException
*/
public static function getTagsFromUrl(string $url, string $photo = '', string $keyword_denylist = '')
public static function getTagsFromUrl(string $url, string $photo = '', string $keyword_denylist = ''): array
{
$data = self::queryUrl($url, $photo, true, $keyword_denylist);
@ -282,7 +282,7 @@ class PageInfo
* @param string $url
* @return string
*/
protected static function stripTrailingUrlFromBody(string $body, string $url)
protected static function stripTrailingUrlFromBody(string $body, string $url): string
{
$quotedUrl = preg_quote($url, '#');
$body = preg_replace_callback("#(?:

View file

@ -50,9 +50,9 @@ class Pager
*
* @param L10n $l10n
* @param string $queryString The query string of the current page
* @param integer $itemsPerPage An optional number of items per page to override the default value
* @param int $itemsPerPage An optional number of items per page to override the default value
*/
public function __construct(L10n $l10n, $queryString, $itemsPerPage = 50)
public function __construct(L10n $l10n, string $queryString, int $itemsPerPage = 50)
{
$this->l10n = $l10n;
@ -64,9 +64,9 @@ class Pager
/**
* Returns the start offset for a LIMIT clause. Starts at 0.
*
* @return integer
* @return int
*/
public function getStart()
public function getStart(): int
{
return max(0, ($this->page * $this->itemsPerPage) - $this->itemsPerPage);
}
@ -74,9 +74,9 @@ class Pager
/**
* Returns the number of items per page
*
* @return integer
* @return int
*/
public function getItemsPerPage()
public function getItemsPerPage(): int
{
return $this->itemsPerPage;
}
@ -86,7 +86,7 @@ class Pager
*
* @return int
*/
public function getPage()
public function getPage(): int
{
return $this->page;
}
@ -108,9 +108,9 @@ class Pager
/**
* Sets the number of items per page, 1 minimum.
*
* @param integer $itemsPerPage
* @param int $itemsPerPage
*/
public function setItemsPerPage($itemsPerPage)
public function setItemsPerPage(int $itemsPerPage)
{
$this->itemsPerPage = max(1, intval($itemsPerPage));
}
@ -118,11 +118,11 @@ class Pager
/**
* Sets the current page number. Starts at 1.
*
* @param integer $page
* @param int $page
*/
public function setPage($page)
public function setPage(int $page)
{
$this->page = max(1, intval($page));
$this->page = max(1, $page);
}
/**
@ -132,7 +132,7 @@ class Pager
*
* @param string $queryString
*/
public function setQueryString($queryString)
public function setQueryString(string $queryString)
{
$stripped = preg_replace('/([&?]page=[0-9]*)/', '', $queryString);

View file

@ -39,10 +39,9 @@ class Smilies
* @param array $b Array of emoticons
* @param string $smiley The text smilie
* @param string $representation The replacement
*
* @return void
*/
public static function add(&$b, $smiley, $representation)
public static function add(array &$b, string $smiley, string $representation)
{
$found = array_search($smiley, $b['texts']);
@ -66,7 +65,7 @@ class Smilies
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @hook smilie ('texts' => smilies texts array, 'icons' => smilies html array)
*/
public static function getList()
public static function getList(): array
{
$texts = [
'&lt;3',
@ -169,7 +168,7 @@ class Smilies
*
* @return string $subject with all substrings in the $search array replaced by the values in the $replace array
*/
private static function strOrigReplace($search, $replace, $subject)
private static function strOrigReplace(array $search, array $replace, string $subject): string
{
return strtr($subject, array_combine($search, $replace));
}
@ -191,7 +190,7 @@ class Smilies
* @return string HTML Output of the Smilie
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function replace($s, $no_images = false)
public static function replace(string $s, bool $no_images = false): string
{
$smilies = self::getList();
@ -211,7 +210,7 @@ class Smilies
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function replaceFromArray($text, array $smilies, $no_images = false)
public static function replaceFromArray(string $text, array $smilies, bool $no_images = false): string
{
if (intval(DI::config()->get('system', 'no_smilies'))
|| (local_user() && intval(DI::pConfig()->get(local_user(), 'system', 'no_smilies')))
@ -244,22 +243,24 @@ class Smilies
}
/**
* @param string $m string
* Encodes smiley match array to BASE64 string
*
* @param array $m Match array
* @return string base64 encoded string
*/
private static function encode($m)
private static function encode(array $m): string
{
return '<' . $m[1] . '>' . Strings::base64UrlEncode($m[2]) . '</' . $m[1] . '>';
}
/**
* @param string $m string
* Decodes a previously BASE64-encoded match array to a string
*
* @param array $m Matches array
* @return string base64 decoded string
* @throws \Exception
*/
private static function decode($m)
private static function decode(array $m): string
{
return '<' . $m[1] . '>' . Strings::base64UrlDecode($m[2]) . '</' . $m[1] . '>';
}
@ -269,12 +270,10 @@ class Smilies
* expand <3333 to the correct number of hearts
*
* @param string $x string
*
* @return string HTML Output
*
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function pregHeart($x)
private static function pregHeart(string $x): string
{
if (strlen($x[1]) == 1) {
return $x[0];

View file

@ -81,7 +81,7 @@ class BBCode
* 'description' -> Description of the attachment
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function getOldAttachmentData($body)
private static function getOldAttachmentData(string $body): array
{
$post = [];
@ -152,7 +152,7 @@ class BBCode
* 'description' -> Description of the attachment
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getAttachmentData($body)
public static function getAttachmentData(string $body): array
{
DI::profiler()->startRecording('rendering');
$data = [
@ -187,26 +187,31 @@ class BBCode
case 'publisher_name':
$data['provider_name'] = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
break;
case 'publisher_url':
$data['provider_url'] = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
break;
case 'author_name':
$data['author_name'] = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
if ($data['provider_name'] == $data['author_name']) {
$data['author_name'] = '';
}
break;
case 'author_url':
$data['author_url'] = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
if ($data['provider_url'] == $data['author_url']) {
$data['author_url'] = '';
}
break;
case 'title':
$value = self::convert(html_entity_decode($value, ENT_QUOTES, 'UTF-8'), false, true);
$value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
$value = str_replace(['[', ']'], ['&#91;', '&#93;'], $value);
$data['title'] = $value;
default:
$data[$field] = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
break;
@ -241,7 +246,7 @@ class BBCode
return $data;
}
public static function getAttachedData($body, $item = [])
public static function getAttachedData(string $body, array $item = []): array
{
/*
- text:
@ -303,7 +308,7 @@ class BBCode
// Workaround:
// Sometimes photo posts to the own album are not detected at the start.
// So we seem to cannot use the cache for these cases. That's strange.
if (($data['type'] != 'photo') && strstr($pictures[0][1], "/photos/")) {
if (($data['type'] != 'photo') && strstr($pictures[0][1], '/photos/')) {
$data = ParseUrl::getSiteinfo($pictures[0][1]);
}
@ -390,7 +395,7 @@ class BBCode
}
if (!isset($post['type'])) {
$post['type'] = "text";
$post['type'] = 'text';
$post['text'] = trim($body);
}
@ -422,7 +427,7 @@ class BBCode
*
* @return string with replaced body
*/
public static function removeAttachment($body, $no_link_desc = false)
public static function removeAttachment(string $body, bool $no_link_desc = false): string
{
return preg_replace_callback("/\s*\[attachment (.*?)\](.*?)\[\/attachment\]\s*/ism",
function ($match) use ($body, $no_link_desc) {
@ -442,12 +447,12 @@ class BBCode
/**
* Converts a BBCode text into plaintext
*
* @param $text
* @param string $text
* @param bool $keep_urls Whether to keep URLs in the resulting plaintext
*
* @return string
*/
public static function toPlaintext($text, $keep_urls = true)
public static function toPlaintext(string $text, bool $keep_urls = true): string
{
DI::profiler()->startRecording('rendering');
// Remove pictures in advance to avoid unneeded proxy calls
@ -463,7 +468,7 @@ class BBCode
return $naked_text;
}
private static function proxyUrl($image, $simplehtml = self::INTERNAL, $uriid = 0, $size = '')
private static function proxyUrl(string $image, int $simplehtml = self::INTERNAL, int $uriid = 0, string $size = ''): string
{
// Only send proxied pictures to API and for internal display
if (!in_array($simplehtml, [self::INTERNAL, self::API])) {
@ -483,7 +488,7 @@ class BBCode
* @param string $srctext The body with images
* @return string The body with possibly scaled images
*/
public static function scaleExternalImages(string $srctext)
public static function scaleExternalImages(string $srctext): string
{
DI::profiler()->startRecording('rendering');
$s = $srctext;
@ -551,7 +556,7 @@ class BBCode
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function limitBodySize($body)
public static function limitBodySize(string $body): string
{
DI::profiler()->startRecording('rendering');
$maxlen = DI::config()->get('config', 'max_import_size', 0);
@ -646,7 +651,7 @@ class BBCode
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function convertAttachment($text, $simplehtml = self::INTERNAL, $tryoembed = true, array $data = [], $uriid = 0)
public static function convertAttachment(string $text, int $simplehtml = self::INTERNAL, bool $tryoembed = true, array $data = [], int $uriid = 0): string
{
DI::profiler()->startRecording('rendering');
$data = $data ?: self::getAttachmentData($text);
@ -659,10 +664,10 @@ class BBCode
$data['title'] = strip_tags($data['title']);
$data['title'] = str_replace(['http://', 'https://'], '', $data['title']);
} else {
$data['title'] = null;
$data['title'] = '';
}
if (((strpos($data['text'], "[img=") !== false) || (strpos($data['text'], "[img]") !== false) || DI::config()->get('system', 'always_show_preview')) && !empty($data['image'])) {
if (((strpos($data['text'], '[img=') !== false) || (strpos($data['text'], '[img]') !== false) || DI::config()->get('system', 'always_show_preview')) && !empty($data['image'])) {
$data['preview'] = $data['image'];
$data['image'] = '';
}
@ -716,14 +721,14 @@ class BBCode
return trim(($data['text'] ?? '') . ' ' . $return . ' ' . ($data['after'] ?? ''));
}
public static function removeShareInformation($Text, $plaintext = false, $nolink = false)
public static function removeShareInformation(string $text, bool $plaintext = false, bool $nolink = false): string
{
DI::profiler()->startRecording('rendering');
$data = self::getAttachmentData($Text);
$data = self::getAttachmentData($text);
if (!$data) {
DI::profiler()->stopRecording();
return $Text;
return $text;
} elseif ($nolink) {
DI::profiler()->stopRecording();
return $data['text'] . ($data['after'] ?? '');
@ -767,7 +772,7 @@ class BBCode
* @param array $match Array with the matching values
* @return string reformatted link including HTML codes
*/
private static function convertUrlForActivityPubCallback($match)
private static function convertUrlForActivityPubCallback(array $match): string
{
$url = $match[1];
@ -789,10 +794,9 @@ class BBCode
* @param string $url URL that is about to be reformatted
* @return string reformatted link including HTML codes
*/
private static function convertUrlForActivityPub($url)
private static function convertUrlForActivityPub(string $url): string
{
$html = '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>';
return sprintf($html, $url, self::getStyledURL($url));
return sprintf('<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>', $url, self::getStyledURL($url));
}
/**
@ -801,7 +805,7 @@ class BBCode
* @param string $url URL that is about to be reformatted
* @return string reformatted link
*/
private static function getStyledURL($url)
private static function getStyledURL(string $url): string
{
$parts = parse_url($url);
$scheme = $parts['scheme'] . '://';
@ -818,8 +822,11 @@ class BBCode
* [noparse][i]italic[/i][/noparse] turns into
* [noparse][ i ]italic[ /i ][/noparse],
* to hide them from parser.
*
* @param array $match
* @return string
*/
private static function escapeNoparseCallback($match)
private static function escapeNoparseCallback(array $match): string
{
$whole_match = $match[0];
$captured = $match[1];
@ -832,8 +839,11 @@ class BBCode
* The previously spacefied [noparse][ i ]italic[ /i ][/noparse],
* now turns back and the [noparse] tags are trimed
* returning [i]italic[/i]
*
* @param array $match
* @return string
*/
private static function unescapeNoparseCallback($match)
private static function unescapeNoparseCallback(array $match): string
{
$captured = $match[1];
$unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured);
@ -849,7 +859,7 @@ class BBCode
* @param int $occurrences Number of first occurrences to skip
* @return boolean|array
*/
public static function getTagPosition($text, $name, $occurrences = 0)
public static function getTagPosition(string $text, string $name, int $occurrences = 0)
{
DI::profiler()->startRecording('rendering');
if ($occurrences < 0) {
@ -913,7 +923,7 @@ class BBCode
* @param string $text Text to search
* @return string
*/
public static function pregReplaceInTag($pattern, $replace, $name, $text)
public static function pregReplaceInTag(string $pattern, string $replace, string $name, string $text): string
{
DI::profiler()->startRecording('rendering');
$occurrences = 0;
@ -936,7 +946,7 @@ class BBCode
return $text;
}
private static function extractImagesFromItemBody($body)
private static function extractImagesFromItemBody(string $body): array
{
$saved_image = [];
$orig_body = $body;
@ -977,7 +987,7 @@ class BBCode
return ['body' => $new_body, 'images' => $saved_image];
}
private static function interpolateSavedImagesIntoItemBody($uriid, $body, array $images)
private static function interpolateSavedImagesIntoItemBody(int $uriid, string $body, array $images): string
{
$newbody = $body;
@ -1062,7 +1072,7 @@ class BBCode
* @param callable $callback
* @return string The BBCode string with all [share] blocks replaced
*/
public static function convertShare($text, callable $callback, int $uriid = 0)
public static function convertShare(string $text, callable $callback, int $uriid = 0): string
{
DI::profiler()->startRecording('rendering');
$return = preg_replace_callback(
@ -1146,7 +1156,7 @@ class BBCode
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function convertShareCallback(array $attributes, array $author_contact, $content, $is_quote_share, $simplehtml)
private static function convertShareCallback(array $attributes, array $author_contact, string $content, bool $is_quote_share, int $simplehtml): string
{
DI::profiler()->startRecording('rendering');
$mention = $attributes['author'] . ' (' . ($author_contact['addr'] ?? '') . ')';
@ -1215,7 +1225,7 @@ class BBCode
return $text;
}
private static function removePictureLinksCallback($match)
private static function removePictureLinksCallback(array $match): string
{
$cache_key = 'remove:' . $match[1];
$text = DI::cache()->get($cache_key);
@ -1229,9 +1239,9 @@ class BBCode
}
if (substr($mimetype, 0, 6) == 'image/') {
$text = "[url=" . $match[1] . ']' . $match[1] . "[/url]";
$text = '[url=' . $match[1] . ']' . $match[1] . '[/url]';
} else {
$text = "[url=" . $match[2] . ']' . $match[2] . "[/url]";
$text = '[url=' . $match[2] . ']' . $match[2] . '[/url]';
// if its not a picture then look if its a page that contains a picture link
$body = DI::httpClient()->fetch($match[1], HttpClientAccept::HTML, 0);
@ -1243,7 +1253,7 @@ class BBCode
$doc = new DOMDocument();
@$doc->loadHTML($body);
$xpath = new DOMXPath($doc);
$list = $xpath->query("//meta[@name]");
$list = $xpath->query('//meta[@name]');
foreach ($list as $node) {
$attr = [];
@ -1331,7 +1341,7 @@ class BBCode
$doc = new DOMDocument();
@$doc->loadHTML($body);
$xpath = new DOMXPath($doc);
$list = $xpath->query("//meta[@name]");
$list = $xpath->query('//meta[@name]');
foreach ($list as $node) {
$attr = [];
if ($node->attributes->length) {
@ -1503,10 +1513,10 @@ class BBCode
* $match[1] = $url
* $match[2] = $title or absent
*/
$try_oembed_callback = function ($match)
$try_oembed_callback = function (array $match)
{
$url = $match[1];
$title = $match[2] ?? null;
$title = $match[2] ?? '';
try {
$return = OEmbed::getHTML($url, $title);
@ -1829,7 +1839,7 @@ class BBCode
$text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br><img src="' .DI::baseUrl() . '/images/lock_icon.gif" alt="' . DI::l10n()->t('Encrypted content') . '" title="' . DI::l10n()->t('Encrypted content') . '" /><br>', $text);
$text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism", '<br><img src="' .DI::baseUrl() . '/images/lock_icon.gif" alt="' . DI::l10n()->t('Encrypted content') . '" title="' . '$1' . ' ' . DI::l10n()->t('Encrypted content') . '" /><br>', $text);
//$Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism", '<br><img src="' .DI::baseUrl() . '/images/lock_icon.gif" alt="' . DI::l10n()->t('Encrypted content') . '" title="' . '$1' . ' ' . DI::l10n()->t('Encrypted content') . '" /><br>', $Text);
//$text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism", '<br><img src="' .DI::baseUrl() . '/images/lock_icon.gif" alt="' . DI::l10n()->t('Encrypted content') . '" title="' . '$1' . ' ' . DI::l10n()->t('Encrypted content') . '" /><br>', $text);
// Simplify "video" element
$text = preg_replace('(\[video[^\]]*?\ssrc\s?=\s?([^\s\]]+)[^\]]*?\].*?\[/video\])ism', '[video]$1[/video]', $text);
@ -1957,7 +1967,7 @@ class BBCode
if (in_array($simple_html, [self::OSTATUS, self::TWITTER])) {
$text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", "self::expandLinksCallback", $text);
//$Text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $Text);
//$text = preg_replace("/[^#@!]\[url\=([^\]]*)\](.*?)\[\/url\]/ism", ' $2 [url]$1[/url]', $text);
$text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", ' $2 [url]$1[/url]', $text);
}
@ -2242,7 +2252,7 @@ class BBCode
$tagline .= '#' . $tag . ' ';
}
}
$text = $text . " " . $tagline;
$text = $text . ' ' . $tagline;
}
} else {
$text = self::convert($text, false, self::CONNECTORS);
@ -2287,7 +2297,6 @@ class BBCode
* Returns array of tags found, or empty array.
*
* @param string $string Post content
*
* @return array List of tag and person names
*/
public static function getTags(string $string): array
@ -2356,7 +2365,7 @@ class BBCode
public static function expandTags(string $body): string
{
return preg_replace_callback("/(?<=\W|^)([!#@])([^\^ \x0D\x0A,;:?'\"]*[^\^ \x0D\x0A,;:?!'\".])/",
function ($match) {
function (array $match) {
switch ($match[1]) {
case '!':
case '@':
@ -2367,6 +2376,7 @@ class BBCode
return $match[1] . $match[2];
}
break;
case '#':
default:
return $match[1] . '[url=' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]';
@ -2480,7 +2490,6 @@ class BBCode
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @see ParseUrl::getSiteinfoCached
*
*/
public static function embedURL(string $url, bool $tryAttachment = true, string $title = null, string $description = null, string $tags = null): string
{

View file

@ -225,7 +225,7 @@ class Widget
* @return string
* @throws \Exception
*/
public static function contactRels($baseurl, $selected = '')
public static function contactRels(string $baseurl, string $selected = ''): string
{
if (!local_user()) {
return '';
@ -256,7 +256,7 @@ class Widget
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function networks($baseurl, $selected = '')
public static function networks(string $baseurl, string $selected = ''): string
{
if (!local_user()) {
return '';
@ -294,10 +294,10 @@ class Widget
*
* @param string $baseurl baseurl
* @param string $selected optional, default empty
* @return string|void
* @return string
* @throws \Exception
*/
public static function fileAs($baseurl, $selected = '')
public static function fileAs(string $baseurl, string $selected = ''): string
{
if (!local_user()) {
return '';
@ -325,10 +325,10 @@ class Widget
* @param int $uid Id of the user owning the categories
* @param string $baseurl Base page URL
* @param string $selected Selected category
* @return string|void
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function categories(int $uid, string $baseurl, string $selected = '')
public static function categories(int $uid, string $baseurl, string $selected = ''): string
{
if (!Feature::isEnabled($uid, 'categories')) {
return '';
@ -355,11 +355,11 @@ class Widget
*
* @param int $uid Viewed profile user ID
* @param string $nickname Viewed profile user nickname
* @return string|void
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function commonFriendsVisitor(int $uid, string $nickname)
public static function commonFriendsVisitor(int $uid, string $nickname): string
{
if (local_user() == $uid) {
return '';
@ -416,7 +416,7 @@ class Widget
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function tagCloud(int $uid, int $limit = 50)
public static function tagCloud(int $uid, int $limit = 50): string
{
if (empty($uid)) {
return '';
@ -441,7 +441,7 @@ class Widget
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function postedByYear(string $url, int $uid, bool $wall)
public static function postedByYear(string $url, int $uid, bool $wall): string
{
$o = '';
@ -512,10 +512,10 @@ class Widget
* The account type value is added as a parameter to the url
*
* @param string $base Basepath
* @param int $accounttype Acount type
* @param string $accounttype Account type
* @return string
*/
public static function accounttypes(string $base, $accounttype)
public static function accountTypes(string $base, string $accounttype): string
{
$accounts = [
['ref' => 'person', 'name' => DI::l10n()->t('Persons')],

View file

@ -41,7 +41,7 @@ class Update
* @param string $basePath The base path of this application
* @param boolean $via_worker Is the check run via the worker?
* @param App\Mode $mode The current app mode
*
* @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function check(string $basePath, bool $via_worker, App\Mode $mode)
@ -73,7 +73,7 @@ class Update
}
// The postupdate has to completed version 1288 for the new post views to take over
$postupdate = DI::config()->get("system", "post_update_version", NEW_TABLE_STRUCTURE_VERSION);
$postupdate = DI::config()->get('system', 'post_update_version', NEW_TABLE_STRUCTURE_VERSION);
if ($postupdate < NEW_TABLE_STRUCTURE_VERSION) {
$error = DI::l10n()->t('Updates from postupdate version %s are not supported. Please update at least to version 2021.01 and wait until the postupdate finished version 1383.', $postupdate);
if (DI::mode()->getExecutor() == Mode::INDEX) {
@ -85,9 +85,11 @@ class Update
if ($build < DB_UPDATE_VERSION) {
if ($via_worker) {
// Calling the database update directly via the worker enables us to perform database changes to the workerqueue table itself.
// This is a fallback, since normally the database update will be performed by a worker job.
// This worker job doesn't work for changes to the "workerqueue" table itself.
/*
* Calling the database update directly via the worker enables us to perform database changes to the workerqueue table itself.
* This is a fallback, since normally the database update will be performed by a worker job.
* This worker job doesn't work for changes to the "workerqueue" table itself.
*/
self::run($basePath);
} else {
Worker::add(PRIORITY_CRITICAL, 'DBUpdate');
@ -103,11 +105,10 @@ class Update
* @param bool $override Overrides any running/stuck updates
* @param bool $verbose Run the Update-Check verbose
* @param bool $sendMail Sends a Mail to the administrator in case of success/failure
*
* @return string Empty string if the update is successful, error messages otherwise
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function run(string $basePath, bool $force = false, bool $override = false, bool $verbose = false, bool $sendMail = true)
public static function run(string $basePath, bool $force = false, bool $override = false, bool $verbose = false, bool $sendMail = true): string
{
// In force mode, we release the dbupdate lock first
// Necessary in case of an stuck update
@ -228,11 +229,10 @@ class Update
* @param int $version the DB version number of the function
* @param string $prefix the prefix of the function (update, pre_update)
* @param bool $sendMail whether to send emails on success/failure
* @return bool true, if the update function worked
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function runUpdateFunction(int $version, string $prefix, bool $sendMail = true)
public static function runUpdateFunction(int $version, string $prefix, bool $sendMail = true): bool
{
$funcname = $prefix . '_' . $version;
@ -284,6 +284,7 @@ class Update
*
* @param int $update_id number of failed update
* @param string $error_message error message
* @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function updateFailed(int $update_id, string $error_message) {

View file

@ -73,7 +73,7 @@ class DBStructure
*/
public static function dropTables(bool $execute)
{
$postupdate = DI::config()->get("system", "post_update_version", PostUpdate::VERSION);
$postupdate = DI::config()->get('system', 'post_update_version', PostUpdate::VERSION);
if ($postupdate < PostUpdate::VERSION) {
echo DI::l10n()->t('The post update is at version %d, it has to be at %d to safely drop the tables.', $postupdate, PostUpdate::VERSION);
return;

View file

@ -538,7 +538,7 @@ class PostUpdate
private static function update1347()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1347) {
if (DI::config()->get('system', 'post_update_version') >= 1347) {
return true;
}
@ -547,7 +547,7 @@ class PostUpdate
return true;
}
$id = DI::config()->get("system", "post_update_version_1347_id", 0);
$id = DI::config()->get('system', 'post_update_version_1347_id', 0);
Logger::info('Start', ['item' => $id]);
@ -582,12 +582,12 @@ class PostUpdate
}
DBA::close($items);
DI::config()->set("system", "post_update_version_1347_id", $id);
DI::config()->set('system', 'post_update_version_1347_id', $id);
Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
if ($start_id == $id) {
DI::config()->set("system", "post_update_version", 1347);
DI::config()->set('system', 'post_update_version', 1347);
Logger::info('Done');
return true;
}
@ -605,11 +605,11 @@ class PostUpdate
private static function update1348()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1348) {
if (DI::config()->get('system', 'post_update_version') >= 1348) {
return true;
}
$id = DI::config()->get("system", "post_update_version_1348_id", 0);
$id = DI::config()->get('system', 'post_update_version_1348_id', 0);
Logger::info('Start', ['contact' => $id]);
@ -635,12 +635,12 @@ class PostUpdate
}
DBA::close($contacts);
DI::config()->set("system", "post_update_version_1348_id", $id);
DI::config()->set('system', 'post_update_version_1348_id', $id);
Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
if ($start_id == $id) {
DI::config()->set("system", "post_update_version", 1348);
DI::config()->set('system', 'post_update_version', 1348);
Logger::info('Done');
return true;
}
@ -658,11 +658,11 @@ class PostUpdate
private static function update1349()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1349) {
if (DI::config()->get('system', 'post_update_version') >= 1349) {
return true;
}
$id = DI::config()->get("system", "post_update_version_1349_id", '');
$id = DI::config()->get('system', 'post_update_version_1349_id', '');
Logger::info('Start', ['apcontact' => $id]);
@ -688,12 +688,12 @@ class PostUpdate
}
DBA::close($apcontacts);
DI::config()->set("system", "post_update_version_1349_id", $id);
DI::config()->set('system', 'post_update_version_1349_id', $id);
Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
if ($start_id == $id) {
DI::config()->set("system", "post_update_version", 1349);
DI::config()->set('system', 'post_update_version', 1349);
Logger::info('Done');
return true;
}
@ -711,7 +711,7 @@ class PostUpdate
private static function update1383()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1383) {
if (DI::config()->get('system', 'post_update_version') >= 1383) {
return true;
}
@ -737,7 +737,7 @@ class PostUpdate
}
DBA::close($photos);
DI::config()->set("system", "post_update_version", 1383);
DI::config()->set('system', 'post_update_version', 1383);
Logger::info('Done', ['deleted' => $deleted]);
return true;
}
@ -752,7 +752,7 @@ class PostUpdate
private static function update1384()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1384) {
if (DI::config()->get('system', 'post_update_version') >= 1384) {
return true;
}
@ -782,7 +782,7 @@ class PostUpdate
Logger::info('Processed', ['rows' => $rows]);
if ($rows <= 100) {
DI::config()->set("system", "post_update_version", 1384);
DI::config()->set('system', 'post_update_version', 1384);
Logger::info('Done');
return true;
}
@ -800,12 +800,12 @@ class PostUpdate
private static function update1400()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1400) {
if (DI::config()->get('system', 'post_update_version') >= 1400) {
return true;
}
if (!DBStructure::existsTable('item')) {
DI::config()->set("system", "post_update_version", 1400);
DI::config()->set('system', 'post_update_version', 1400);
return true;
}
@ -829,7 +829,7 @@ class PostUpdate
Logger::info('Processed', ['rows' => $rows]);
if ($rows <= 100) {
DI::config()->set("system", "post_update_version", 1400);
DI::config()->set('system', 'post_update_version', 1400);
Logger::info('Done');
return true;
}
@ -847,7 +847,7 @@ class PostUpdate
private static function update1424()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1424) {
if (DI::config()->get('system', 'post_update_version') >= 1424) {
return true;
}
@ -871,7 +871,7 @@ class PostUpdate
Logger::info('Processed', ['rows' => $rows]);
if ($rows <= 100) {
DI::config()->set("system", "post_update_version", 1424);
DI::config()->set('system', 'post_update_version', 1424);
Logger::info('Done');
return true;
}
@ -889,7 +889,7 @@ class PostUpdate
private static function update1425()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1425) {
if (DI::config()->get('system', 'post_update_version') >= 1425) {
return true;
}
@ -918,7 +918,7 @@ class PostUpdate
Logger::info('Processed', ['rows' => $rows]);
if ($rows <= 100) {
DI::config()->set("system", "post_update_version", 1425);
DI::config()->set('system', 'post_update_version', 1425);
Logger::info('Done');
return true;
}
@ -936,7 +936,7 @@ class PostUpdate
private static function update1426()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1426) {
if (DI::config()->get('system', 'post_update_version') >= 1426) {
return true;
}
@ -965,7 +965,7 @@ class PostUpdate
Logger::info('Processed', ['rows' => $rows]);
if ($rows <= 100) {
DI::config()->set("system", "post_update_version", 1426);
DI::config()->set('system', 'post_update_version', 1426);
Logger::info('Done');
return true;
}
@ -983,7 +983,7 @@ class PostUpdate
private static function update1427()
{
// Was the script completed?
if (DI::config()->get("system", "post_update_version") >= 1427) {
if (DI::config()->get('system', 'post_update_version') >= 1427) {
return true;
}
@ -1012,7 +1012,7 @@ class PostUpdate
Logger::info('Processed', ['rows' => $rows]);
if ($rows <= 100) {
DI::config()->set("system", "post_update_version", 1427);
DI::config()->set('system', 'post_update_version', 1427);
Logger::info('Done');
return true;
}

View file

@ -474,7 +474,6 @@ 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): bool
@ -556,7 +555,6 @@ 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
@ -597,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]);
@ -620,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]);
@ -678,11 +675,11 @@ class Contact
* Updates the self-contact for the provided user id
*
* @param int $uid
* @param boolean $update_avatar Force the avatar update
* @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',
@ -795,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]);
@ -822,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
*/
@ -851,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
*/
@ -878,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
*/
@ -925,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)
@ -978,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)
@ -1025,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 = '';
@ -1168,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;
@ -1312,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;
@ -1352,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;
@ -1378,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;
@ -1406,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);
}
@ -1422,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)) {

View file

@ -586,6 +586,8 @@ class Photo
}
/**
* Returns a float that represents the GPS coordinate from EXIF data
*
* @param array $exifCoord coordinate
* @param string $hemi hemi
* @return float

View file

@ -186,7 +186,7 @@ class Contact extends BaseModule
$follow_widget = Widget::follow();
}
$account_widget = Widget::accounttypes($_SERVER['REQUEST_URI'], $accounttype);
$account_widget = Widget::accountTypes($_SERVER['REQUEST_URI'], $accounttype);
$networks_widget = Widget::networks($_SERVER['REQUEST_URI'], $nets);
$rel_widget = Widget::contactRels($_SERVER['REQUEST_URI'], $rel);
$groups_widget = Widget::groups($_SERVER['REQUEST_URI'], $group);

View file

@ -141,7 +141,7 @@ class Contacts extends BaseModule
'$paginate' => $pager->renderFull($total),
]);
DI::page()['aside'] .= Widget::accounttypes($_SERVER['REQUEST_URI'], $accounttype);
DI::page()['aside'] .= Widget::accountTypes($_SERVER['REQUEST_URI'], $accounttype);
return $o;
}

View file

@ -90,7 +90,7 @@ class Community extends BaseModule
Nav::setSelected('community');
DI::page()['aside'] .= Widget::accounttypes('community/' . self::$content, self::$accountTypeString);
DI::page()['aside'] .= Widget::accountTypes('community/' . self::$content, self::$accountTypeString);
if (local_user() && DI::config()->get('system', 'community_no_sharer')) {
$path = self::$content;

View file

@ -86,13 +86,13 @@ class Network extends BaseModule
$module = 'network';
DI::page()['aside'] .= Widget::accounttypes($module, self::$accountTypeString);
DI::page()['aside'] .= Widget::accountTypes($module, self::$accountTypeString);
DI::page()['aside'] .= Group::sidebarWidget($module, $module . '/group', 'standard', self::$groupId);
DI::page()['aside'] .= ForumManager::widget($module . '/forum', local_user(), self::$forumContactId);
DI::page()['aside'] .= Widget::postedByYear($module . '/archive', local_user(), false);
DI::page()['aside'] .= Widget::networks($module, !self::$forumContactId ? self::$network : '');
DI::page()['aside'] .= Widget\SavedSearches::getHTML(DI::args()->getQueryString());
DI::page()['aside'] .= Widget::fileAs('filed', null);
DI::page()['aside'] .= Widget::fileAs('filed', '');
$arr = ['query' => DI::args()->getQueryString()];
Hook::callAll('network_content_init', $arr);

View file

@ -258,7 +258,7 @@ class Photo extends BaseModule
return MPhoto::getPhoto($matches[1], $matches[2]);
}
return MPhoto::createPhotoForExternalResource($url, (int)local_user(), $media['mimetype']);
return MPhoto::createPhotoForExternalResource($url, (int)local_user(), $media['mimetype'] ?? '');
case 'media':
$media = DBA::selectFirst('post-media', ['url', 'mimetype', 'uri-id'], ['id' => $id, 'type' => Post\Media::IMAGE]);
if (empty($media)) {
@ -276,7 +276,7 @@ class Photo extends BaseModule
return false;
}
return MPhoto::createPhotoForExternalResource($link['url'], (int)local_user(), $link['mimetype']);
return MPhoto::createPhotoForExternalResource($link['url'], (int)local_user(), $link['mimetype'] ?? '');
case 'contact':
$fields = ['uid', 'uri-id', 'url', 'nurl', 'avatar', 'photo', 'xmpp', 'addr', 'network', 'failed', 'updated'];
$contact = Contact::getById($id, $fields);

View file

@ -106,7 +106,7 @@ class Post
// Only add will be displayed
if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
continue;
} elseif (!DI::contentItem()->visibleActivity($item)) {
} elseif (!DI::contentItem()->isVisibleActivity($item)) {
continue;
}

View file

@ -981,7 +981,7 @@ function update_1429()
return Update::FAILED;
}
DI::config()->set("system", "post_update_version", 1423);
DI::config()->set('system', 'post_update_version', 1423);
return Update::SUCCESS;
}