]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/ItemContent.php
Fix: unknown variable
[friendica.git] / src / Model / ItemContent.php
index fe256d3e76f6b81f8f73f2dfc0e10c7b8d01fdcc..8805f5b2556a2e0e94a2940ab35881b83291889b 100644 (file)
@@ -6,18 +6,14 @@
 
 namespace Friendica\Model;
 
-use Friendica\BaseObject;
 use Friendica\Content\Text;
-use Friendica\Core\PConfig;
+use Friendica\Core\Protocol;
+use Friendica\DI;
 
-require_once 'boot.php';
-require_once 'include/items.php';
-require_once 'include/text.php';
-
-class ItemContent extends BaseObject
+class ItemContent
 {
        /**
-        * @brief Convert a message into plaintext for connectors to other networks
+        * Convert a message into plaintext for connectors to other networks
         *
         * @param array  $item           The message array that is about to be posted
         * @param int    $limit          The maximum number of characters when posting to that network
@@ -25,9 +21,10 @@ class ItemContent extends BaseObject
         * @param int    $htmlmode       This controls the behavior of the BBCode conversion
         * @param string $target_network Name of the network where the post should go to.
         *
-        * @see \Friendica\Content\Text\BBCode::getAttachedData
-        *
         * @return array Same array structure than \Friendica\Content\Text\BBCode::getAttachedData
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @see   \Friendica\Content\Text\BBCode::getAttachedData
+        *
         */
        public static function getPlaintextPost($item, $limit = 0, $includedlinks = false, $htmlmode = 2, $target_network = '')
        {
@@ -68,14 +65,13 @@ class ItemContent extends BaseObject
                } else {// Try to guess the correct target network
                        switch ($htmlmode) {
                                case 8:
-                                       $abstract = Text\BBCode::getAbstract($item['body'], NETWORK_TWITTER);
+                                       $abstract = Text\BBCode::getAbstract($item['body'], Protocol::TWITTER);
                                        break;
+
                                case 7:
-                                       $abstract = Text\BBCode::getAbstract($item['body'], NETWORK_STATUSNET);
-                                       break;
-                               case 6:
-                                       $abstract = Text\BBCode::getAbstract($item['body'], NETWORK_APPNET);
+                                       $abstract = Text\BBCode::getAbstract($item['body'], Protocol::STATUSNET);
                                        break;
+
                                default: // We don't know the exact target.
                                        // We fetch an abstract since there is a posting limit.
                                        if ($limit > 0) {
@@ -93,7 +89,7 @@ class ItemContent extends BaseObject
                        }
                }
 
-               $html = Text\BBCode::convert($post['text'] . $post['after'], false, $htmlmode);
+               $html = Text\BBCode::convert($post['text'] . ($post['after'] ?? ''), false, $htmlmode);
                $msg = Text\HTML::toPlaintext($html, 0, true);
                $msg = trim(html_entity_decode($msg, ENT_QUOTES, 'UTF-8'));
 
@@ -102,7 +98,7 @@ class ItemContent extends BaseObject
                        if ($post['type'] == 'link') {
                                $link = $post['url'];
                        } elseif ($post['type'] == 'text') {
-                               $link = $post['url'];
+                               $link = $post['url'] ?? '';
                        } elseif ($post['type'] == 'video') {
                                $link = $post['url'];
                        } elseif ($post['type'] == 'photo') {
@@ -160,10 +156,9 @@ class ItemContent extends BaseObject
                                } elseif (!isset($post['url'])) {
                                        $limit = $limit - 23;
                                        $post['url'] = $item['plink'];
-                                       // Which purpose has this line? It is now uncommented, but left as a reminder
-                                       //} elseif (strpos($b['body'], '[share') !== false) {
-                                       //      $post['url'] = $b['plink'];
-                               } elseif (PConfig::get($item['uid'], 'system', 'no_intelligent_shortening')) {
+                               } elseif (strpos($item['body'], '[share') !== false) {
+                                       $post['url'] = $item['plink'];
+                               } elseif (DI::pConfig()->get($item['uid'], 'system', 'no_intelligent_shortening')) {
                                        $post['url'] = $item['plink'];
                                }
                                $msg = Text\Plaintext::shorten($msg, $limit);