diff --git a/public_html/templates/post.tpl b/public_html/templates/post.tpl index cfa933dd..b2d7a255 100644 --- a/public_html/templates/post.tpl +++ b/public_html/templates/post.tpl @@ -11,7 +11,7 @@ <% } else if (post.contentType == 'flash') { %> @@ -22,7 +22,7 @@ <% } else if (post.contentType == 'video') { %> - + Your browser doesn't support HTML5 videos. diff --git a/src/Controllers/ViewProxies/PostViewProxy.php b/src/Controllers/ViewProxies/PostViewProxy.php index 237f4bbc..b2c63108 100644 --- a/src/Controllers/ViewProxies/PostViewProxy.php +++ b/src/Controllers/ViewProxies/PostViewProxy.php @@ -16,6 +16,7 @@ class PostViewProxy extends AbstractViewProxy $result->safety = \Szurubooru\Helpers\EnumHelper::postSafetyToString($post->getSafety()); $result->contentType = \Szurubooru\Helpers\EnumHelper::postTypeToString($post->getContentType()); $result->contentChecksum = $post->getContentChecksum(); + $result->contentMimeType = $post->getContentMimeType(); $result->source = $post->getSource(); $result->imageWidth = $post->getImageWidth(); $result->imageHeight = $post->getImageHeight(); diff --git a/src/Dao/EntityConverters/PostEntityConverter.php b/src/Dao/EntityConverters/PostEntityConverter.php index 4feebfde..07133907 100644 --- a/src/Dao/EntityConverters/PostEntityConverter.php +++ b/src/Dao/EntityConverters/PostEntityConverter.php @@ -15,6 +15,7 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv 'safety' => $entity->getSafety(), 'contentType' => $entity->getContentType(), 'contentChecksum' => $entity->getContentChecksum(), + 'contentMimeType' => $entity->getContentMimeType(), 'source' => $entity->getSource(), 'imageWidth' => $entity->getImageWidth(), 'imageHeight' => $entity->getImageHeight(), @@ -33,6 +34,7 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv $entity->setSafety(intval($array['safety'])); $entity->setContentType(intval($array['contentType'])); $entity->setContentChecksum($array['contentChecksum']); + $entity->setContentMimeType($array['contentMimeType']); $entity->setSource($array['source']); $entity->setImageWidth($array['imageWidth']); $entity->setImageHeight($array['imageHeight']); diff --git a/src/Entities/Post.php b/src/Entities/Post.php index eda44e71..3e1f8bf5 100644 --- a/src/Entities/Post.php +++ b/src/Entities/Post.php @@ -19,6 +19,7 @@ final class Post extends Entity protected $safety; protected $contentType; protected $contentChecksum; + protected $contentMimeType; protected $source; protected $imageWidth; protected $imageHeight; @@ -112,6 +113,16 @@ final class Post extends Entity $this->contentChecksum = $contentChecksum; } + public function getContentMimeType() + { + return $this->contentMimeType; + } + + public function setContentMimeType($contentMimeType) + { + $this->contentMimeType = $contentMimeType; + } + public function getSource() { return $this->source; diff --git a/src/Services/PostService.php b/src/Services/PostService.php index 03f0d436..b070a2b9 100644 --- a/src/Services/PostService.php +++ b/src/Services/PostService.php @@ -131,6 +131,7 @@ class PostService throw new \DomainException('Upload is too big.'); $mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($content); + $post->setContentMimeType($mime); if (\Szurubooru\Helpers\MimeHelper::isFlash($mime)) $post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_FLASH); diff --git a/src/Upgrades/Upgrade04.php b/src/Upgrades/Upgrade04.php new file mode 100644 index 00000000..80c36357 --- /dev/null +++ b/src/Upgrades/Upgrade04.php @@ -0,0 +1,34 @@ +postService = $postService; + $this->fileService = $fileService; + } + + public function run(\Szurubooru\DatabaseConnection $databaseConnection) + { + $databaseConnection->getPDO()->exec('ALTER TABLE "posts" ADD COLUMN contentMimeType TEXT DEFAULT NULL'); + + $postDao = new \Szurubooru\Dao\PostDao($databaseConnection); + $posts = $postDao->findAll(); + foreach ($posts as $post) + { + if ($post->getContentType() !== \Szurubooru\Entities\Post::POST_TYPE_YOUTUBE) + { + $fullPath = $this->fileService->getFullPath($this->postService->getPostContentPath($post)); + $mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromFile($fullPath); + $post->setContentMimeType($mime); + $postDao->save($post); + } + } + } +} diff --git a/src/di.php b/src/di.php index 9ba7b4d7..24fcf343 100644 --- a/src/di.php +++ b/src/di.php @@ -19,6 +19,7 @@ return [ $container->get(\Szurubooru\Upgrades\Upgrade01::class), $container->get(\Szurubooru\Upgrades\Upgrade02::class), $container->get(\Szurubooru\Upgrades\Upgrade03::class), + $container->get(\Szurubooru\Upgrades\Upgrade04::class), ]; }),