$uriids[] = $item['uri-id'];
- if (!$this->item->visibleActivity($item)) {
+ if (!$this->item->isVisibleActivity($item)) {
continue;
}
continue;
}
- if (!$this->item->visibleActivity($item)) {
+ if (!$this->item->isVisibleActivity($item)) {
continue;
}
* ]
* ]
*/
- public function determineCategoriesTerms(array $item, int $uid = 0)
+ public function determineCategoriesTerms(array $item, int $uid = 0): array
{
$categories = [];
$folders = [];
* This function removes the tag $tag from the text $body and replaces it with
* 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 string $tag the tag to replace
- * @param string $network The network of the post
+ * @param string $body the text to replace the tag in
+ * @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;
/**
* 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));
$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;
}
$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)) {
$B = '';
}
- if ($Bphoto != "" && !empty($Blink)) {
+ if ($Bphoto != '' && !empty($Blink)) {
$Bphoto = '[url=' . Contact::magicLink($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
}
$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)) {
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']) {
$post_type = $this->l10n->t('status');
}
break;
+
default:
if ($obj['resource-id']) {
$post_type = $this->l10n->t('photo');
$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);
}
if ($network == Protocol::DFRN) {
- $menu[$this->l10n->t("Poke")] = $poke_link;
+ $menu[$this->l10n->t('Poke')] = $poke_link;
}
if ((($cid == 0) || ($rel == Contact::FOLLOWER)) &&
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;
- }
-
- return true;
+ $item['uid'] == local_user())
+ );
}
- 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'] = '';
*
* @param string $item
*/
- public static function setSelected($item)
+ public static function setSelected(string $item)
{
self::$selected[$item] = 'selected';
}
* @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>';
*
* @return array
*/
- public static function getAppMenu()
+ public static function getAppMenu(): array
{
if (is_null(self::$app_menu)) {
self::populateAppMenu();
/**
* Fills the apps static variable with apps that require a menu
+ *
+ * @return void
*/
private static function populateAppMenu()
{
*/
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));
* @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, '\'"');
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;
}
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;
}
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);
}
* 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));
}
$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;
}
* @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;
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));
* @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';
* @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'";
* @param DOMNode $node
* @return string
*/
- private static function getInnerHTML(DOMNode $node)
+ private static function getInnerHTML(DOMNode $node): string
{
$innerHTML = '';
$children = $node->childNodes;
* @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');
* @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);
* @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);
* @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);
* @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("#(?:
*
* Guesses the page number from the GET parameter 'page'.
*
- * @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 L10n $l10n
+ * @param string $queryString The query string of the current page
+ * @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;
/**
* 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);
}
/**
* Returns the number of items per page
*
- * @return integer
+ * @return int
*/
- public function getItemsPerPage()
+ public function getItemsPerPage(): int
{
return $this->itemsPerPage;
}
*
* @return int
*/
- public function getPage()
+ public function getPage(): int
{
return $this->page;
}
/**
* 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));
}
/**
* 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);
}
/**
*
* @param string $queryString
*/
- public function setQueryString($queryString)
+ public function setQueryString(string $queryString)
{
$stripped = preg_replace('/([&?]page=[0-9]*)/', '', $queryString);
* @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']);
* @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 = [
'<3',
*
* @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));
}
* @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();
* @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')))
*
* @return string base64 encoded string
*/
- private static function encode($m)
+ private static function encode(string $m): string
{
return '<' . $m[1] . '>' . Strings::base64UrlEncode($m[2]) . '</' . $m[1] . '>';
}
* @return string base64 decoded string
* @throws \Exception
*/
- private static function decode($m)
+ private static function decode(string $m): string
{
return '<' . $m[1] . '>' . Strings::base64UrlDecode($m[2]) . '</' . $m[1] . '>';
}
*
* @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];
* @return string
* @throws \Exception
*/
- public static function contactRels($baseurl, $selected = '')
+ public static function contactRels(string $baseurl, string $selected = ''): string
{
if (!local_user()) {
return '';
* @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 '';
*
* @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 '';
* @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 '';
*
* @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 '';
* @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 '';
* @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 = '';
* @param int $accounttype Acount type
* @return string
*/
- public static function accounttypes(string $base, $accounttype)
+ public static function accounttypes(string $base, int $accounttype): string
{
$accounts = [
['ref' => 'person', 'name' => DI::l10n()->t('Persons')],
// 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;
}