]> git.mxchange.org Git - friendica.git/commitdiff
Moved "limitBodySize"
authorMichael <heluecht@pirati.ca>
Sun, 28 Jan 2018 17:36:37 +0000 (17:36 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 28 Jan 2018 17:36:37 +0000 (17:36 +0000)
src/Content/Text/BBCode.php
src/Model/Item.php
src/Protocol/DFRN.php
src/Worker/OnePoll.php

index ce6b252218e64b6da789bd9fca03c3bf533c7ef7..6feafdf854a51f1b4d42eb75b7d65d6a0fbdb331 100644 (file)
@@ -549,4 +549,91 @@ class BBCode
                $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8');
                return $s;
        }
+
+       /**
+        * The purpose of this function is to apply system message length limits to
+        * imported messages without including any embedded photos in the length
+        *
+        * @brief Truncates imported message body string length to max_import_size
+        * @param string $body
+        * @return string
+        */
+       public static function limitBodySize($body)
+       {
+               $maxlen = get_max_import_size();
+
+               // If the length of the body, including the embedded images, is smaller
+               // than the maximum, then don't waste time looking for the images
+               if ($maxlen && (strlen($body) > $maxlen)) {
+
+                       logger('the total body length exceeds the limit', LOGGER_DEBUG);
+
+                       $orig_body = $body;
+                       $new_body = '';
+                       $textlen = 0;
+
+                       $img_start = strpos($orig_body, '[img');
+                       $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+                       $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+                       while (($img_st_close !== false) && ($img_end !== false)) {
+
+                               $img_st_close++; // make it point to AFTER the closing bracket
+                               $img_end += $img_start;
+                               $img_end += strlen('[/img]');
+
+                               if (!strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
+                                       // This is an embedded image
+
+                                       if (($textlen + $img_start) > $maxlen) {
+                                               if ($textlen < $maxlen) {
+                                                       logger('the limit happens before an embedded image', LOGGER_DEBUG);
+                                                       $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
+                                                       $textlen = $maxlen;
+                                               }
+                                       } else {
+                                               $new_body = $new_body . substr($orig_body, 0, $img_start);
+                                               $textlen += $img_start;
+                                       }
+
+                                       $new_body = $new_body . substr($orig_body, $img_start, $img_end - $img_start);
+                               } else {
+
+                                       if (($textlen + $img_end) > $maxlen) {
+                                               if ($textlen < $maxlen) {
+                                                       logger('the limit happens before the end of a non-embedded image', LOGGER_DEBUG);
+                                                       $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
+                                                       $textlen = $maxlen;
+                                               }
+                                       } else {
+                                               $new_body = $new_body . substr($orig_body, 0, $img_end);
+                                               $textlen += $img_end;
+                                       }
+                               }
+                               $orig_body = substr($orig_body, $img_end);
+
+                               if ($orig_body === false) {
+                                       // in case the body ends on a closing image tag
+                                       $orig_body = '';
+                               }
+
+                               $img_start = strpos($orig_body, '[img');
+                               $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
+                               $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
+                       }
+
+                       if (($textlen + strlen($orig_body)) > $maxlen) {
+                               if ($textlen < $maxlen) {
+                                       logger('the limit happens after the end of the last image', LOGGER_DEBUG);
+                                       $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
+                               }
+                       } else {
+                               logger('the text size with embedded images extracted did not violate the limit', LOGGER_DEBUG);
+                               $new_body = $new_body . $orig_body;
+                       }
+
+                       return $new_body;
+               } else {
+                       return $body;
+               }
+       }
 }
index ebdbbd41cf57d8c54a57efc752d622128de1b619..98ffd89ff1b9f888b63459b454f3c8119be4b701 100644 (file)
@@ -1067,93 +1067,6 @@ class Item
                }
        }
 
-       /**
-        * The purpose of this function is to apply system message length limits to
-        * imported messages without including any embedded photos in the length
-        *
-        * @brief Truncates imported message body string length to max_import_size
-        * @param string $body
-        * @return string
-        */
-       public static function limitBodySize($body)
-       {
-               $maxlen = get_max_import_size();
-
-               // If the length of the body, including the embedded images, is smaller
-               // than the maximum, then don't waste time looking for the images
-               if ($maxlen && (strlen($body) > $maxlen)) {
-
-                       logger('the total body length exceeds the limit', LOGGER_DEBUG);
-
-                       $orig_body = $body;
-                       $new_body = '';
-                       $textlen = 0;
-
-                       $img_start = strpos($orig_body, '[img');
-                       $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
-                       $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
-                       while (($img_st_close !== false) && ($img_end !== false)) {
-
-                               $img_st_close++; // make it point to AFTER the closing bracket
-                               $img_end += $img_start;
-                               $img_end += strlen('[/img]');
-
-                               if (!strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
-                                       // This is an embedded image
-
-                                       if (($textlen + $img_start) > $maxlen) {
-                                               if ($textlen < $maxlen) {
-                                                       logger('the limit happens before an embedded image', LOGGER_DEBUG);
-                                                       $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
-                                                       $textlen = $maxlen;
-                                               }
-                                       } else {
-                                               $new_body = $new_body . substr($orig_body, 0, $img_start);
-                                               $textlen += $img_start;
-                                       }
-
-                                       $new_body = $new_body . substr($orig_body, $img_start, $img_end - $img_start);
-                               } else {
-
-                                       if (($textlen + $img_end) > $maxlen) {
-                                               if ($textlen < $maxlen) {
-                                                       logger('the limit happens before the end of a non-embedded image', LOGGER_DEBUG);
-                                                       $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
-                                                       $textlen = $maxlen;
-                                               }
-                                       } else {
-                                               $new_body = $new_body . substr($orig_body, 0, $img_end);
-                                               $textlen += $img_end;
-                                       }
-                               }
-                               $orig_body = substr($orig_body, $img_end);
-
-                               if ($orig_body === false) {
-                                       // in case the body ends on a closing image tag
-                                       $orig_body = '';
-                               }
-
-                               $img_start = strpos($orig_body, '[img');
-                               $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
-                               $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
-                       }
-
-                       if (($textlen + strlen($orig_body)) > $maxlen) {
-                               if ($textlen < $maxlen) {
-                                       logger('the limit happens after the end of the last image', LOGGER_DEBUG);
-                                       $new_body = $new_body . substr($orig_body, 0, $maxlen - $textlen);
-                               }
-                       } else {
-                               logger('the text size with embedded images extracted did not violate the limit', LOGGER_DEBUG);
-                               $new_body = $new_body . $orig_body;
-                       }
-
-                       return $new_body;
-               } else {
-                       return $body;
-               }
-       }
-
        private static function setHashtags(&$item)
        {
 
index 22a7ecb611ff16578405a86cd800db9dc0f35346..6a839813712f14093e28a718bed47e753d28d7c6 100644 (file)
@@ -28,6 +28,7 @@ use Friendica\Protocol\OStatus;
 use Friendica\Util\Crypto;
 use Friendica\Util\Network;
 use Friendica\Util\XML;
+use Friendica\Content\Text\BBCode;
 
 use dba;
 use DOMDocument;
@@ -2449,7 +2450,7 @@ class DFRN
                // make sure nobody is trying to sneak some html tags by us
                $item["body"] = notags(base64url_decode($item["body"]));
 
-               $item["body"] = Item::limitBodySize($item["body"]);
+               $item["body"] = BBCode::limitBodySize($item["body"]);
 
                /// @todo Do we really need this check for HTML elements? (It was copied from the old function)
                if ((strpos($item['body'], '<') !== false) && (strpos($item['body'], '>') !== false)) {
index 29ab4e758f309c772eb688aba4dc61eeb393efd3..c83c69f7aed3a49f04ee3a950e686dd2c1ca705b 100644 (file)
@@ -9,6 +9,7 @@ use Friendica\Core\PConfig;
 use Friendica\Database\DBM;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
+use Friendica\Content\Text\BBCode;
 use Friendica\Protocol\Email;
 use Friendica\Protocol\PortableContact;
 use Friendica\Util\Network;
@@ -488,7 +489,7 @@ class OnePoll
                                                                continue;
                                                        }
                                                        $datarray['body'] = escape_tags($r['body']);
-                                                       $datarray['body'] = Item::limitBodySize($datarray['body']);
+                                                       $datarray['body'] = BBCode::limitBodySize($datarray['body']);
 
                                                        logger("Mail: Importing ".$msg_uid." for ".$mailconf['user']);