X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FContent%2FText%2FBBCode.php;h=a8b5ec2025546e7ffa0e694597d2f38524ccd8b1;hb=5e2cbce9b6efce2baaed69b6aad1537a51bdae9d;hp=cb375dcd21e7686b7018512f92ed3d2451a2dcf7;hpb=42a3610a796b31c9956cb650d3b13075e241b26f;p=friendica.git
diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php
index cb375dcd21..a8b5ec2025 100644
--- a/src/Content/Text/BBCode.php
+++ b/src/Content/Text/BBCode.php
@@ -11,9 +11,9 @@ use Exception;
use Friendica\BaseObject;
use Friendica\Content\OEmbed;
use Friendica\Content\Smilies;
-use Friendica\Core\Addon;
use Friendica\Core\Cache;
use Friendica\Core\Config;
+use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
@@ -37,13 +37,14 @@ class BBCode extends BaseObject
*
* @param string $body Message body
* @return array
- * 'type' -> Message type ("link", "video", "photo")
- * 'text' -> Text before the shared message
- * 'after' -> Text after the shared message
- * 'image' -> Preview image of the message
- * 'url' -> Url to the attached message
- * 'title' -> Title of the attachment
- * 'description' -> Description of the attachment
+ * 'type' -> Message type ("link", "video", "photo")
+ * 'text' -> Text before the shared message
+ * 'after' -> Text after the shared message
+ * 'image' -> Preview image of the message
+ * 'url' -> Url to the attached message
+ * 'title' -> Title of the attachment
+ * 'description' -> Description of the attachment
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function getOldAttachmentData($body)
{
@@ -108,13 +109,14 @@ class BBCode extends BaseObject
*
* @param string $body Message body
* @return array
- * 'type' -> Message type ("link", "video", "photo")
- * 'text' -> Text before the shared message
- * 'after' -> Text after the shared message
- * 'image' -> Preview image of the message
- * 'url' -> Url to the attached message
- * 'title' -> Title of the attachment
- * 'description' -> Description of the attachment
+ * 'type' -> Message type ("link", "video", "photo")
+ * 'text' -> Text before the shared message
+ * 'after' -> Text after the shared message
+ * 'image' -> Preview image of the message
+ * 'url' -> Url to the attached message
+ * 'title' -> Title of the attachment
+ * 'description' -> Description of the attachment
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function getAttachmentData($body)
{
@@ -130,12 +132,12 @@ class BBCode extends BaseObject
$type = "";
preg_match("/type='(.*?)'/ism", $attributes, $matches);
- if (x($matches, 1)) {
+ if (!empty($matches[1])) {
$type = strtolower($matches[1]);
}
preg_match('/type="(.*?)"/ism', $attributes, $matches);
- if (x($matches, 1)) {
+ if (!empty($matches[1])) {
$type = strtolower($matches[1]);
}
@@ -153,12 +155,12 @@ class BBCode extends BaseObject
$url = "";
preg_match("/url='(.*?)'/ism", $attributes, $matches);
- if (x($matches, 1)) {
+ if (!empty($matches[1])) {
$url = $matches[1];
}
preg_match('/url="(.*?)"/ism', $attributes, $matches);
- if (x($matches, 1)) {
+ if (!empty($matches[1])) {
$url = $matches[1];
}
@@ -168,12 +170,12 @@ class BBCode extends BaseObject
$title = "";
preg_match("/title='(.*?)'/ism", $attributes, $matches);
- if (x($matches, 1)) {
+ if (!empty($matches[1])) {
$title = $matches[1];
}
preg_match('/title="(.*?)"/ism', $attributes, $matches);
- if (x($matches, 1)) {
+ if (!empty($matches[1])) {
$title = $matches[1];
}
@@ -186,12 +188,12 @@ class BBCode extends BaseObject
$image = "";
preg_match("/image='(.*?)'/ism", $attributes, $matches);
- if (x($matches, 1)) {
+ if (!empty($matches[1])) {
$image = $matches[1];
}
preg_match('/image="(.*?)"/ism', $attributes, $matches);
- if (x($matches, 1)) {
+ if (!empty($matches[1])) {
$image = $matches[1];
}
@@ -201,12 +203,12 @@ class BBCode extends BaseObject
$preview = "";
preg_match("/preview='(.*?)'/ism", $attributes, $matches);
- if (x($matches, 1)) {
+ if (!empty($matches[1])) {
$preview = $matches[1];
}
preg_match('/preview="(.*?)"/ism', $attributes, $matches);
- if (x($matches, 1)) {
+ if (!empty($matches[1])) {
$preview = $matches[1];
}
@@ -234,7 +236,7 @@ class BBCode extends BaseObject
*/
$has_title = !empty($item['title']);
- $plink = (!empty($item['plink']) ? $item['plink'] : '');
+ $plink = defaults($item, 'plink', '');
$post = self::getAttachmentData($body);
// if nothing is found, it maybe having an image.
@@ -345,6 +347,7 @@ class BBCode extends BaseObject
/**
* @brief Converts a BBCode text into plaintext
*
+ * @param $text
* @param bool $keep_urls Whether to keep URLs in the resulting plaintext
*
* @return string
@@ -446,6 +449,7 @@ class BBCode extends BaseObject
* @brief Truncates imported message body string length to max_import_size
* @param string $body
* @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function limitBodySize($body)
{
@@ -532,10 +536,11 @@ class BBCode extends BaseObject
* Note: Can produce a [bookmark] tag in the returned string
*
* @brief Processes [attachment] tags
- * @param string $return
+ * @param string $return
* @param bool|int $simplehtml
- * @param bool $tryoembed
+ * @param bool $tryoembed
* @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function convertAttachment($return, $simplehtml = false, $tryoembed = true)
{
@@ -626,7 +631,7 @@ class BBCode extends BaseObject
$data["title"] = $data["url"];
}
- if (($data["text"] == "") && ($data["title"] != "") && ($data["url"] == "")) {
+ if (empty($data["text"]) && !empty($data["title"]) && empty($data["url"])) {
return $data["title"] . $data["after"];
}
@@ -777,10 +782,10 @@ class BBCode extends BaseObject
/**
* Performs a preg_replace within the boundaries of all named BBCode tags in a text
*
- * @param type $pattern Preg pattern string
- * @param type $replace Preg replace string
- * @param type $name BBCode tag name
- * @param type $text Text to search
+ * @param string $pattern Preg pattern string
+ * @param string $replace Preg replace string
+ * @param string $name BBCode tag name
+ * @param string $text Text to search
* @return string
*/
public static function pregReplaceInTag($pattern, $replace, $name, $text)
@@ -930,6 +935,7 @@ class BBCode extends BaseObject
* @param boolean $is_quote_share Whether there is content before the [share] block
* @param integer $simplehtml Mysterious integer value depending on the target network/formatting style
* @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function convertShareCallback(array $attributes, array $author_contact, $content, $is_quote_share, $simplehtml)
{
@@ -1142,8 +1148,9 @@ class BBCode extends BaseObject
* @param int $simple_html
* @param bool $for_plaintext
* @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function convert($text, $try_oembed = true, $simple_html = false, $for_plaintext = false)
+ public static function convert($text, $try_oembed = true, $simple_html = 0, $for_plaintext = false)
{
$a = self::getApp();
@@ -1171,7 +1178,7 @@ class BBCode extends BaseObject
// Extracting multi-line code blocks before the whitespace processing
$codeblocks = [];
- $text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#is",
+ $text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#ism",
function ($matches) use (&$codeblocks) {
$return = $matches[0];
if (strpos($matches[2], "\n") !== false) {
@@ -1286,7 +1293,7 @@ class BBCode extends BaseObject
$text);
} elseif ($simple_html == 7) {
$text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
- '$1$3',
+ '$1$3',
$text);
} elseif (!$simple_html) {
$text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
@@ -1354,6 +1361,12 @@ class BBCode extends BaseObject
. '';
}, $text);
+ // We need no target="_blank" for local links
+ // convert links start with System::baseUrl() as local link without the target="_blank" attribute
+ $escapedBaseUrl = preg_quote(System::baseUrl(), '/');
+ $text = preg_replace("/\[url\](".$escapedBaseUrl."[$URLSearchString]*)\[\/url\]/ism", '$1', $text);
+ $text = preg_replace("/\[url\=(".$escapedBaseUrl."[$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $text);
+
$text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '$1', $text);
$text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$2', $text);
@@ -1662,7 +1675,7 @@ class BBCode extends BaseObject
// Summary (e.g. title) is required, earlier revisions only required description (in addition to
// start which is always required). Allow desc with a missing summary for compatibility.
- if ((x($ev, 'desc') || x($ev, 'summary')) && x($ev, 'start')) {
+ if ((!empty($ev['desc']) || !empty($ev['summary'])) && !empty($ev['start'])) {
$sub = Event::getHTML($ev, $simple_html);
$text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism", '', $text);
@@ -1676,7 +1689,7 @@ class BBCode extends BaseObject
// Replace non graphical smilies for external posts
if ($simple_html) {
- $text = Smilies::replace($text, false, true);
+ $text = Smilies::replace($text);
}
// Unhide all [noparse] contained bbtags unspacefying them
@@ -1730,7 +1743,7 @@ class BBCode extends BaseObject
// Clean up the HTML by loading and saving the HTML with the DOM.
// Bad structured html can break a whole page.
- // For performance reasons do it only with ativated item cache or at export.
+ // For performance reasons do it only with activated item cache or at export.
if (!$try_oembed || (get_itemcachepath() != "")) {
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
@@ -1756,7 +1769,7 @@ class BBCode extends BaseObject
//$Text = str_replace('