]> git.mxchange.org Git - friendica.git/commitdiff
Create Plaintext class
authorAdam Magness <adam.magness@gmail.com>
Sat, 27 Jan 2018 01:26:49 +0000 (20:26 -0500)
committerAdam Magness <adam.magness@gmail.com>
Sat, 27 Jan 2018 01:26:49 +0000 (20:26 -0500)
create class and move shorten method

src/Content/Text/BBCode.php
src/Content/Text/Plaintext.php [new file with mode: 0644]

index b4a310683388ae5d758e095fb164f82eff169908..9162316d72444498f781fc4d535d7bce98527f45 100644 (file)
@@ -5,6 +5,7 @@
 namespace Friendica\Content\Text;
 
 use Friendica\App;
+use Friendica\Content\Text\Plaintext;
 use Friendica\Core\PConfig;
 use Friendica\Object\Image;
 use Friendica\Util\ParseUrl;
@@ -320,35 +321,6 @@ class BBCode
                return $post;
        }
 
-       /**
-        * Shortens message
-        *
-        * @param type $msg
-        * @param type $limit
-        * @return type
-        *
-        * @todo For Twitter URLs aren't shortened, but they have to be calculated as if.
-        */
-       public static function shortenMsg($msg, $limit)
-       {
-               $lines = explode("\n", $msg);
-               $msg = "";
-               $recycle = html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8');
-               $ellipsis = html_entity_decode("&#x2026;", ENT_QUOTES, 'UTF-8');
-               foreach ($lines as $row => $line) {
-                       if (iconv_strlen(trim($msg . "\n" . $line), "UTF-8") <= $limit) {
-                               $msg = trim($msg . "\n" . $line);
-                       } elseif (($msg == "") || (($row == 1) && (substr($msg, 0, 4) == $recycle))) {
-                               // Is the new message empty by now or is it a reshared message?
-                               $msg = iconv_substr(iconv_substr(trim($msg . "\n" . $line), 0, $limit, "UTF-8"), 0, -3, "UTF-8") . $ellipsis;
-                       } else {
-                               break;
-                       }
-               }
-
-               return $msg;
-       }
-
        /**
         * @brief Convert a message into plaintext for connectors to other networks
         *
@@ -496,7 +468,7 @@ class BBCode
                                } elseif (PConfig::get($b["uid"], "system", "no_intelligent_shortening")) {
                                        $post["url"] = $b["plink"];
                                }
-                               $msg = self::shortenMsg($msg, $limit);
+                               $msg = Plaintext::shorten($msg, $limit);
                        }
                }
 
diff --git a/src/Content/Text/Plaintext.php b/src/Content/Text/Plaintext.php
new file mode 100644 (file)
index 0000000..eb17fd0
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+/**
+ * @file src/Content/Text/Plaintext.php
+ */
+namespace Friendica\Content\Text;
+
+class Plaintext
+{
+       /**
+        * Shortens message
+        *
+        * @param type $msg
+        * @param type $limit
+        * @return type
+        *
+        * @todo For Twitter URLs aren't shortened, but they have to be calculated as if.
+        */
+       public static function shorten($msg, $limit)
+       {
+               $lines = explode("\n", $msg);
+               $msg = "";
+               $recycle = html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8');
+               $ellipsis = html_entity_decode("&#x2026;", ENT_QUOTES, 'UTF-8');
+               foreach ($lines as $row => $line) {
+                       if (iconv_strlen(trim($msg . "\n" . $line), "UTF-8") <= $limit) {
+                               $msg = trim($msg . "\n" . $line);
+                       } elseif (($msg == "") || (($row == 1) && (substr($msg, 0, 4) == $recycle))) {
+                               // Is the new message empty by now or is it a reshared message?
+                               $msg = iconv_substr(iconv_substr(trim($msg . "\n" . $line), 0, $limit, "UTF-8"), 0, -3, "UTF-8") . $ellipsis;
+                       } else {
+                               break;
+                       }
+               }
+
+               return $msg;
+       }
+}