1
0
Fork 0

Merge remote-tracking branch 'upstream/develop' into private

This commit is contained in:
Michael 2020-03-02 15:05:00 +00:00
commit 72c198990e
60 changed files with 985 additions and 637 deletions

View file

@ -57,7 +57,7 @@ class BoundariesPager extends Pager
$this->last_item_id = $last_item_id;
$parsed = parse_url($this->getBaseQueryString());
if ($parsed) {
if (!empty($parsed['query'])) {
parse_str($parsed['query'], $queryParameters);
$this->first_page = !($queryParameters['since_id'] ?? null) && !($queryParameters['max_id'] ?? null);

View file

@ -30,10 +30,13 @@ use Friendica\Util\Strings;
*/
class Pager
{
/** @var int Default count of items per page */
const ITEMS_PER_PAGE = 50;
/** @var integer */
private $page = 1;
/** @var integer */
protected $itemsPerPage = 50;
protected $itemsPerPage = self::ITEMS_PER_PAGE;
/** @var string */
protected $baseQueryString = '';

View file

@ -634,12 +634,12 @@ class BBCode
if (!empty($data['title']) && !empty($data['url'])) {
if (!empty($data['image']) && empty($data['text']) && ($data['type'] == 'photo')) {
$return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data['url'], self::proxyUrl($data['image'], $simplehtml), $data['title']);
$return .= sprintf('<a href="%s" target="_blank" rel="noopener noreferrer"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data['url'], self::proxyUrl($data['image'], $simplehtml), $data['title']);
} else {
if (!empty($data['image'])) {
$return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data['url'], self::proxyUrl($data['image'], $simplehtml), $data['title']);
$return .= sprintf('<a href="%s" target="_blank" rel="noopener noreferrer"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data['url'], self::proxyUrl($data['image'], $simplehtml), $data['title']);
} elseif (!empty($data['preview'])) {
$return .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data['url'], self::proxyUrl($data['preview'], $simplehtml), $data['title']);
$return .= sprintf('<a href="%s" target="_blank" rel="noopener noreferrer"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data['url'], self::proxyUrl($data['preview'], $simplehtml), $data['title']);
}
$return .= sprintf('<h4><a href="%s">%s</a></h4>', $data['url'], $data['title']);
}
@ -732,7 +732,7 @@ class BBCode
*/
private static function convertUrlForActivityPub($url)
{
$html = '<a href="%s" target="_blank">%s</a>';
$html = '<a href="%s" target="_blank" rel="noopener noreferrer">%s</a>';
return sprintf($html, $url, self::getStyledURL($url));
}
@ -1039,7 +1039,7 @@ class BBCode
break;
case 4:
$headline = '<p><b>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8');
$headline .= DI::l10n()->t('<a href="%1$s" target="_blank">%2$s</a> %3$s', $attributes['link'], $mention, $attributes['posted']);
$headline .= DI::l10n()->t('<a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s</a> %3$s', $attributes['link'], $mention, $attributes['posted']);
$headline .= ':</b></p>' . "\n";
$text = ($is_quote_share? '<hr />' : '') . $headline . '<blockquote class="shared_content">' . trim($content) . '</blockquote>' . "\n";
@ -1637,9 +1637,9 @@ class BBCode
$text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", $try_oembed_callback, $text);
} else {
$text = preg_replace("/\[video\](.*?)\[\/video\]/ism",
'<a href="$1" target="_blank">$1</a>', $text);
'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $text);
$text = preg_replace("/\[audio\](.*?)\[\/audio\]/ism",
'<a href="$1" target="_blank">$1</a>', $text);
'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $text);
}
// html5 video and audio
@ -1666,7 +1666,7 @@ class BBCode
$text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '<iframe width="' . $a->videowidth . '" height="' . $a->videoheight . '" src="https://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $text);
} else {
$text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism",
'<a href="https://www.youtube.com/watch?v=$1" target="_blank">https://www.youtube.com/watch?v=$1</a>', $text);
'<a href="https://www.youtube.com/watch?v=$1" target="_blank" rel="noopener noreferrer">https://www.youtube.com/watch?v=$1</a>', $text);
}
if ($try_oembed) {
@ -1681,7 +1681,7 @@ class BBCode
$text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '<iframe width="' . $a->videowidth . '" height="' . $a->videoheight . '" src="https://player.vimeo.com/video/$1" frameborder="0" ></iframe>', $text);
} else {
$text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism",
'<a href="https://vimeo.com/$1" target="_blank">https://vimeo.com/$1</a>', $text);
'<a href="https://vimeo.com/$1" target="_blank" rel="noopener noreferrer">https://vimeo.com/$1</a>', $text);
}
// oembed tag
@ -1802,17 +1802,17 @@ class BBCode
. '</a>';
}, $text);
// We need no target="_blank" for local links
// convert links start with DI::baseUrl() as local link without the target="_blank" attribute
// We need no target="_blank" rel="noopener noreferrer" for local links
// convert links start with DI::baseUrl() as local link without the target="_blank" rel="noopener noreferrer" attribute
$escapedBaseUrl = preg_quote(DI::baseUrl(), '/');
$text = preg_replace("/\[url\](".$escapedBaseUrl.".*?)\[\/url\]/ism", '<a href="$1">$1</a>', $text);
$text = preg_replace("/\[url\=(".$escapedBaseUrl.".*?)\](.*?)\[\/url\]/ism", '<a href="$1">$2</a>', $text);
$text = preg_replace("/\[url\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank">$1</a>', $text);
$text = preg_replace("/\[url\=(.*?)\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $text);
$text = preg_replace("/\[url\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $text);
$text = preg_replace("/\[url\=(.*?)\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>', $text);
// Red compatibility, though the link can't be authenticated on Friendica
$text = preg_replace("/\[zrl\=(.*?)\](.*?)\[\/zrl\]/ism", '<a href="$1" target="_blank">$2</a>', $text);
$text = preg_replace("/\[zrl\=(.*?)\](.*?)\[\/zrl\]/ism", '<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>', $text);
// we may need to restrict this further if it picks up too many strays
@ -2005,8 +2005,6 @@ class BBCode
*/
public static function toMarkdown($text, $for_diaspora = true)
{
$a = DI::app();
$original_text = $text;
// Since Diaspora is creating a summary for links, this function removes them before posting

View file

@ -943,7 +943,7 @@ class HTML
*/
public static function toLink($s)
{
$s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\'\%\$\!\+]*)/", ' <a href="$1" target="_blank">$1</a>', $s);
$s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\'\%\$\!\+]*)/", ' <a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $s);
$s = preg_replace("/\<(.*?)(src|href)=(.*?)\&amp\;(.*?)\>/ism", '<$1$2=$3&$4>', $s);
return $s;
}

View file

@ -53,6 +53,8 @@ class Markdown
return $url;
};
$text = self::convertDiasporaMentionsToHtml($text);
$html = $MarkdownParser->transform($text);
DI::profiler()->saveTimestamp($stamp1, "parser", System::callstack());
@ -61,35 +63,42 @@ class Markdown
}
/**
* Callback function to replace a Diaspora style mention in a mention for Friendica
* Replace Diaspora-style mentions in a text since they trip the Markdown parser autolinker.
*
* @param array $match Matching values for the callback
* [1] = mention type (@ or !)
* [2] = name (optional)
* [3] = address
* @return string Replaced mention
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
* @param string $text
* @return string
*/
private static function diasporaMention2BBCodeCallback($match)
private static function convertDiasporaMentionsToHtml(string $text)
{
if ($match[3] == '') {
return;
}
return preg_replace_callback(
'/([@!]){(?:([^}]+?); ?)?([^} ]+)}/',
/*
* Matching values for the callback
* [1] = mention type (@ or !)
* [2] = name (optional)
* [3] = profile URL
*/
function ($matches) {
if ($matches[3] == '') {
return '';
}
$data = Contact::getDetailsByAddr($match[3]);
$data = Contact::getDetailsByAddr($matches[3]);
if (empty($data)) {
return;
}
if (empty($data)) {
return '';
}
$name = $match[2];
$name = $matches[2];
if ($name == '') {
$name = $data['name'];
}
if ($name == '') {
$name = $data['name'];
}
return $match[1] . '[url=' . $data['url'] . ']' . $name . '[/url]';
return $matches[1] . '<a href="' . $data['url'] . '">' . $name . '</a>';
},
$text
);
}
/*
@ -110,9 +119,6 @@ class Markdown
$s = self::convert($s);
$regexp = "/([@!])\{(?:([^\}]+?); ?)?([^\} ]+)\}/";
$s = preg_replace_callback($regexp, ['self', 'diasporaMention2BBCodeCallback'], $s);
$s = HTML::toBBCode($s);
// protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands