]> git.mxchange.org Git - friendica.git/commitdiff
Add new Content\BBCode::toPlaintext()
authorHypolite Petovan <mrpetovan@gmail.com>
Sat, 21 Apr 2018 08:10:25 +0000 (04:10 -0400)
committerHypolite Petovan <mrpetovan@gmail.com>
Sat, 21 Apr 2018 08:10:25 +0000 (04:10 -0400)
src/Content/Text/BBCode.php

index e22306fc8dec5466aab6489dd5be2cdecddf76b6..96c8eceb70f97b0c7d07b6dd68296be31caf6b1b 100644 (file)
@@ -342,6 +342,23 @@ class BBCode extends BaseObject
                return $post;
        }
 
+       /**
+        * @brief Converts a BBCode text into plaintext
+        *
+        * @param bool $keep_urls Whether to keep URLs in the resulting plaintext
+        *
+        * @return string
+        */
+       public static function toPlaintext($text, $keep_urls = true)
+       {
+               $naked_text = preg_replace('/\[(.+?)\]/','', $text);
+               if (!$keep_urls) {
+                       $naked_text = preg_replace('#https?\://[^\s<]+[^\s\.\)]#i', '', $naked_text);
+               }
+
+               return $naked_text;
+       }
+
        public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false)
        {
                // Suppress "view full size"