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;
*
* @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)
{
*
* @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)
{
/**
* @brief Converts a BBCode text into plaintext
*
+ * @param $text
* @param bool $keep_urls Whether to keep URLs in the resulting plaintext
*
* @return string
* @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)
{
* 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)
{
$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"];
}
/**
* 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)
* @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)
{
* @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();
. '</a>';
}, $text);
+ // We need no target="_blank" for local links
+ // convert links start with System::baseUrl() as local link
+ $escapedBaseUrl = str_replace('://', '\:\/\/', System::baseUrl());
+ $text = preg_replace("/\[url\]($escapedBaseUrl)([$URLSearchString]*)\[\/url\]/ism", '<a href="$1$2">$1$2</a>', $text);
+ $text = preg_replace("/\[url\=($escapedBaseUrl)([$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1$2">$3</a>', $text);
+ // convert links that start with / as local link
+ $text = preg_replace("/\[url\](\/[$URLSearchString]*)\[\/url\]/ism", '<a href="'.System::baseUrl().'$1">$1</a>', $text);
+ $text = preg_replace("/\[url\=(\/[$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="'.System::baseUrl().'$1">$2</a>', $text);
+
$text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$1</a>', $text);
$text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $text);
// 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
//$Text = str_replace('<br /><li>', '<li>', $Text);
//$Text = str_replace('<br /><ul', '<ul ', $Text);
- Addon::callHooks('bbcode', $text);
+ Hook::callAll('bbcode', $text);
return trim($text);
}
* @brief Callback function to replace a Friendica style mention in a mention for Diaspora
*
* @param array $match Matching values for the callback
+ * [1] = Mention type (! or @)
+ * [2] = Name
+ * [3] = Address
* @return string Replaced mention
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
*/
private static function bbCodeMention2DiasporaCallback($match)
{
return $match[0];
}
- $mention = '@{' . $match[2] . '; ' . $contact['addr'] . '}';
+ $mention = $match[1] . '{' . $match[2] . '; ' . $contact['addr'] . '}';
return $mention;
}
* @param string $text
* @param bool $for_diaspora Diaspora requires more changes than Libertree
* @return string
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function toMarkdown($text, $for_diaspora = true)
{
if ($for_diaspora) {
$url_search_string = "^\[\]";
$text = preg_replace_callback(
- "/([@]\[(.*?)\])\(([$url_search_string]*?)\)/ism",
+ "/([@!])\[(.*?)\]\(([$url_search_string]*?)\)/ism",
['self', 'bbCodeMention2DiasporaCallback'],
$text
);
}
- Addon::callHooks('bb2diaspora', $text);
+ Hook::callAll('bb2diaspora', $text);
return $text;
}