]> git.mxchange.org Git - friendica.git/blobdiff - include/bbcode.php
Merge pull request #4365 from MrPetovan/task/4116-add-autoload-to-library
[friendica.git] / include / bbcode.php
index 7fa6d05f89713d86e7d3b52e642f32172259764e..20631818a2503fbe8167130edd644e1cccd6a41b 100644 (file)
@@ -1,18 +1,22 @@
 <?php
-
+/**
+ * @file include/bbcode.php
+ */
 use Friendica\App;
 use Friendica\Content\Smilies;
 use Friendica\Content\OEmbed;
+use Friendica\Content\Text\BBCode;
 use Friendica\Core\Addon;
 use Friendica\Core\Cache;
+use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Config;
 use Friendica\Model\Contact;
 use Friendica\Util\Map;
+use Friendica\Util\Network;
 
 require_once 'include/event.php';
 require_once 'mod/proxy.php';
-require_once 'include/plaintext.php';
 
 function bb_PictureCacheExt($matches) {
        if (strpos($matches[3], "data:image/") === 0) {
@@ -54,7 +58,7 @@ function bb_map_location($match) {
  */
 function bb_attachment($return, $simplehtml = false, $tryoembed = true)
 {
-       $data = get_attachment_data($return);
+       $data = BBCode::getAttachmentData($return);
        if (!$data) {
                return $return;
        }
@@ -103,7 +107,7 @@ function bb_attachment($return, $simplehtml = false, $tryoembed = true)
                        }
 
                        if ($data["type"] == "link") {
-                               $return .= sprintf('<h5><a href="%s">%s</a></h5>', $data['url'], parse_url($data['url'], PHP_URL_HOST));
+                               $return .= sprintf('<sup><a href="%s">%s</a></sup>', $data['url'], parse_url($data['url'], PHP_URL_HOST));
                        }
 
                        if ($simplehtml != 4) {
@@ -117,7 +121,7 @@ function bb_attachment($return, $simplehtml = false, $tryoembed = true)
 
 function bb_remove_share_information($Text, $plaintext = false, $nolink = false) {
 
-       $data = get_attachment_data($Text);
+       $data = BBCode::getAttachmentData($Text);
 
        if (!$data) {
                return $Text;
@@ -685,7 +689,7 @@ function GetProfileUsername($profile, $username, $compact = false, $getnetwork =
                $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile);
                if ($StatusnetUser != $profile) {
                        /// @TODO Some hosts run on https, not just http and sometimes http is disabled, let's support both here
-                       $UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser);
+                       $UserData = Network::fetchUrl("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser);
                        $user = json_decode($UserData);
                        if ($user) {
                                if ($getnetwork) {
@@ -744,9 +748,7 @@ function bb_RemovePictureLinks($match) {
                        $text = "[url=".$match[2]."]".$match[2]."[/url]";
 
                        // if its not a picture then look if its a page that contains a picture link
-                       require_once("include/network.php");
-
-                       $body = fetch_url($match[1]);
+                       $body = Network::fetchUrl($match[1]);
 
                        $doc = new DOMDocument();
                        @$doc->loadHTML($body);
@@ -801,9 +803,7 @@ function bb_CleanPictureLinksSub($match) {
                        $text = "[img]".$match[2]."[/img]";
 
                        // if its not a picture then look if its a page that contains a picture link
-                       require_once("include/network.php");
-
-                       $body = fetch_url($match[1]);
+                       $body = Network::fetchUrl($match[1]);
 
                        $doc = new DOMDocument();
                        @$doc->loadHTML($body);
@@ -997,8 +997,9 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
        if ((!$tryoembed || $simplehtml) && !in_array($simplehtml, [3, 7])) {
                $Text = preg_replace("/([#@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $Text);
        } elseif ($simplehtml == 3) {
+               // The ! is converted to @ since Diaspora only understands the @
                $Text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
-                       '$1<a href="$2">$3</a>',
+                       '@<a href="$2">$3</a>',
                        $Text);
        } elseif ($simplehtml == 7) {
                $Text = preg_replace("/([@!])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
@@ -1046,7 +1047,10 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
        $Text = preg_replace($expression, System::baseUrl()."/display/$1", $Text);
 
        $Text = preg_replace("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
-                               '$1<a href="$2" class="tag" title="$3">$3</a>', $Text);
+                               '$1<a href="' . System::baseUrl() . '/search?tag=$3" class="tag" title="$3">$3</a>', $Text);
+
+       $Text = preg_replace("/\[url\=([$URLSearchString]*)\]#(.*?)\[\/url\]/ism",
+                               '#<a href="' . System::baseUrl() . '/search?tag=$2" class="tag" title="$2">$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);