]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post/Media.php
Only attach images
[friendica.git] / src / Model / Post / Media.php
index 2b17614e89b1ce54ae4c425433d049138c8be149..ce00b205c5deaba28e0cb2461f8bc6bb090ea0e5 100644 (file)
@@ -85,6 +85,7 @@ class Media
                }
 
                $media = self::unsetEmptyFields($media);
+               $media = DI::dbaDefinition()->truncateFieldsForTable('post-media', $media);
 
                // We are storing as fast as possible to avoid duplicated network requests
                // when fetching additional information for pictures and other content.
@@ -94,6 +95,7 @@ class Media
 
                $media = self::fetchAdditionalData($media);
                $media = self::unsetEmptyFields($media);
+               $media = DI::dbaDefinition()->truncateFieldsForTable('post-media', $media);
 
                if (array_diff_assoc($media, $stored)) {
                        $result = DBA::insert('post-media', $media, Database::INSERT_UPDATE);
@@ -192,7 +194,7 @@ class Media
 
                if (($media['type'] == self::IMAGE) || ($filetype == 'image')) {
                        $imagedata = Images::getInfoFromURLCached($media['url']);
-                       if (!empty($imagedata)) {
+                       if ($imagedata) {
                                $media['mimetype'] = $imagedata['mime'];
                                $media['size'] = $imagedata['size'];
                                $media['width'] = $imagedata[0];
@@ -202,7 +204,7 @@ class Media
                        }
                        if (!empty($media['preview'])) {
                                $imagedata = Images::getInfoFromURLCached($media['preview']);
-                               if (!empty($imagedata)) {
+                               if ($imagedata) {
                                        $media['preview-width'] = $imagedata[0];
                                        $media['preview-height'] = $imagedata[1];
                                }
@@ -646,11 +648,13 @@ class Media
        /**
         * Add media attachments to the body
         *
-        * @param int $uriid
+        * @param int    $uriid
         * @param string $body
+        * @param array  $types
+        *
         * @return string body
         */
-       public static function addAttachmentsToBody(int $uriid, string $body = ''): string
+       public static function addAttachmentsToBody(int $uriid, string $body = '', array $types = [self::IMAGE, self::AUDIO, self::VIDEO]): string
        {
                if (empty($body)) {
                        $item = Post::selectFirst(['body'], ['uri-id' => $uriid]);
@@ -663,7 +667,7 @@ class Media
 
                $body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body);
 
-               foreach (self::getByURIId($uriid, [self::IMAGE, self::AUDIO, self::VIDEO]) as $media) {
+               foreach (self::getByURIId($uriid, $types) as $media) {
                        if (Item::containsLink($body, $media['preview'] ?? $media['url'], $media['type'])) {
                                continue;
                        }