Fixed multiple issues caused by missing media thumbnails
authorMarcel Werk <burntime@woltlab.com>
Wed, 30 Nov 2016 16:18:53 +0000 (17:18 +0100)
committerMarcel Werk <burntime@woltlab.com>
Wed, 30 Nov 2016 16:18:53 +0000 (17:18 +0100)
com.woltlab.wcf/templates/article.tpl
com.woltlab.wcf/templates/articleListItems.tpl
com.woltlab.wcf/templates/boxArticleList.tpl
com.woltlab.wcf/templates/mediaEditor.tpl
wcfsetup/install/files/acp/templates/articleAdd.tpl
wcfsetup/install/files/acp/templates/boxAdd.tpl
wcfsetup/install/files/acp/templates/mediaEditor.tpl
wcfsetup/install/files/lib/data/media/Media.class.php

index 1ee8b7d21b08654e419524a74bea1ac92b10d8f9..b3879d46f02db2287e67fab54f9250d07693068d 100644 (file)
@@ -98,7 +98,7 @@
 
 {include file='header'}
 
-{if $articleContent->getImage()}
+{if $articleContent->getImage() && $articleContent->getImage()->hasThumbnail('large')}
        <section class="section">
                <figure class="articleImage" itemprop="image" itemscope itemtype="http://schema.org/ImageObject">
                        <div class="articleImageWrapper">{@$articleContent->getImage()->getThumbnailTag('large')}</div>
                        {foreach from=$relatedArticles item='relatedArticle'}
                                <li>
                                        <a href="{$relatedArticle->getLink()}">
-                                               {if $relatedArticle->getImage()}
+                                               {if $relatedArticle->getImage() && $relatedArticle->getImage()->hasThumbnail('tiny')}
                                                        <div class="box128">
                                                                <div class="articleListImage">{@$relatedArticle->getImage()->getThumbnailTag('tiny')}</div>
                                                {/if}
                                                                {@$relatedArticle->getFormattedTeaser()}
                                                        </div>
                                                </div>
-                                               
-                                               {if $relatedArticle->getImage()}
+                                                               
+                                               {if $relatedArticle->getImage() && $relatedArticle->getImage()->hasThumbnail('tiny')}
                                                        </div>
                                                {/if}
                                        </a>
index 242e623770f4c9f7147702a1c1558d6ef0687236..8c5cd741b449afc7bbb96f9ff22c03f267c425a6 100644 (file)
@@ -2,7 +2,7 @@
        {foreach from=$objects item='article'}
                <li>
                        <a href="{$article->getLink()}">
-                               {if $article->getImage()}
+                               {if $article->getImage() && $article->getImage()->hasThumbnail('tiny')}
                                        <div class="box128">
                                                <div class="articleListImage">{@$article->getImage()->getThumbnailTag('tiny')}</div>
                                {/if}
@@ -37,8 +37,8 @@
                                                        {@$article->getFormattedTeaser()}
                                                </div>
                                        </div>
-                                       
-                               {if $article->getImage()}
+                                               
+                               {if $article->getImage() && $article->getImage()->hasThumbnail('tiny')}
                                        </div>
                                {/if}
                        </a>
index 23c6494a08f6570487f7dfbbc7b39e18848cb3d9..3dfc32ca1c5c7304688ae412d6a31ffc410bc54f 100644 (file)
@@ -32,7 +32,7 @@
                {foreach from=$boxArticleList item=boxArticle}
                        <li>
                                <a href="{$boxArticle->getLink()}">
-                                       {if $boxArticle->getImage()}
+                                       {if $boxArticle->getImage() && $boxArticle->getImage()->hasThumbnail('small')}
                                                <div class="articleListImage">{@$boxArticle->getImage()->getThumbnailTag('small')}</div>
                                        {/if}
                                        
index 65f0fe0813472a04b4f379256626e966cc5d1719..08a73a573f07ee074f565a64adeec5f7ebbd959b 100644 (file)
@@ -1,4 +1,4 @@
-{if $media->isImage}
+{if $media->isImage && $media->hasThumbnail('small')}
        <div class="mediaThumbnail">
                {@$media->getThumbnailTag('small')}
        </div>
index c79ecbaf9a407baaa711c13a2c29ba1e7cd05112..3c308ac39e39be653718ed811dd1bf2f82517fcb 100644 (file)
                                        <dt><label for="image">{lang}wcf.acp.article.image{/lang}</label></dt>
                                        <dd>
                                                <div id="imageDisplay" class="selectedImagePreview">
-                                                       {if $images[0]|isset}
+                                                       {if $images[0]|isset && $images[0]->hasThumbnail('small')}
                                                                {@$images[0]->getThumbnailTag('small')}
                                                        {/if}
                                                </div>
                                                {/if}
                                        </dd>
                                </dl>
-                       {elseif $action == 'edit' && $images[0]|isset}
+                       {elseif $action == 'edit' && $images[0]|isset && $images[0]->hasThumbnail('small')}
                                <dl>
                                        <dt>{lang}wcf.acp.article.image{/lang}</dt>
                                        <dd>
                                                                <dt><label for="image{@$availableLanguage->languageID}">{lang}wcf.acp.article.image{/lang}</label></dt>
                                                                <dd>
                                                                        <div id="imageDisplay{@$availableLanguage->languageID}">
-                                                                               {if $images[$availableLanguage->languageID]|isset}
+                                                                               {if $images[$availableLanguage->languageID]|isset && $images[$availableLanguage->languageID]->hasThumbnail('small')}
                                                                                        {@$images[$availableLanguage->languageID]->getThumbnailTag('small')}
                                                                                {/if}
                                                                        </div>
                                                                        {/if}
                                                                </dd>
                                                        </dl>
-                                               {elseif $action == 'edit' && $images[$availableLanguage->languageID]|isset}
+                                               {elseif $action == 'edit' && $images[$availableLanguage->languageID]|isset && $images[$availableLanguage->languageID]->hasThumbnail('small')}
                                                        <dl>
                                                                <dt>{lang}wcf.acp.article.image{/lang}</dt>
                                                                <dd>
index 493234589ce8d24da52e1b926a04a69fdf8eec86..5cca3ea98f9e638e971914f8ec06a100a69331f3 100644 (file)
                                                        <dt><label for="image">{lang}wcf.acp.box.image{/lang}</label></dt>
                                                        <dd>
                                                                <div id="imageDisplay" class="selectedImagePreview">
-                                                                       {if $images[0]|isset}
+                                                                       {if $images[0]|isset && $images[0]->hasThumbnail('small')}
                                                                                {@$images[0]->getThumbnailTag('small')}
                                                                        {/if}
                                                                </div>
                                                                {/if}
                                                        </dd>
                                                </dl>
-                                       {elseif $action == 'edit' && $images[0]|isset}
+                                       {elseif $action == 'edit' && $images[0]|isset && $images[0]->hasThumbnail('small')}
                                                <dl>
                                                        <dt>{lang}wcf.acp.box.image{/lang}</dt>
                                                        <dd>
                                                                                        <dt><label for="image{@$availableLanguage->languageID}">{lang}wcf.acp.box.image{/lang}</label></dt>
                                                                                        <dd>
                                                                                                <div id="imageDisplay{@$availableLanguage->languageID}" class="selectedImagePreview">
-                                                                                                       {if $images[$availableLanguage->languageID]|isset}
+                                                                                                       {if $images[$availableLanguage->languageID]|isset && $images[$availableLanguage->languageID]->hasThumbnail('small')}
                                                                                                                {@$images[$availableLanguage->languageID]->getThumbnailTag('small')}
                                                                                                        {/if}
                                                                                                </div>
                                                                                                {/if}
                                                                                        </dd>
                                                                                </dl>
-                                                                       {elseif $action == 'edit' && $images[$availableLanguage->languageID]|isset}
+                                                                       {elseif $action == 'edit' && $images[$availableLanguage->languageID]|isset && $images[$availableLanguage->languageID]->hasThumbnail('small')}
                                                                                <dl>
                                                                                        <dt>{lang}wcf.acp.box.image{/lang}</dt>
                                                                                        <dd>
index 576bb515e86cfdf940d722299e44dc1fafb9715c..dfe759a1e9f68e5e3164d2798a23bba791085baa 100644 (file)
@@ -1,4 +1,4 @@
-{if $media->isImage}
+{if $media->isImage && $media->hasThumbnail('small')}
        <div class="mediaThumbnail">
                {@$media->getThumbnailTag('small')}
        </div>
index 819440a7dc9e2184d556b9ac12c7dfac1de9d998..e1ff1b1b97a2ec81802ced40396cbe3f683c2770 100644 (file)
@@ -207,6 +207,29 @@ class Media extends DatabaseObject implements ILinkableObject, IRouteController,
                return WCF::getSession()->getPermission('admin.content.cms.canManageMedia') || SimpleAclResolver::getInstance()->canAccess('com.woltlab.wcf.media', $this->mediaID);
        }
        
+       /**
+        * Returns true if a thumbnail version with the given size is available.
+        *
+        * @param       string          $size
+        * @return      boolean
+        * @throws      \InvalidArgumentException
+        */
+       public function hasThumbnail($size) {
+               if (!isset(self::$thumbnailSizes[$size])) {
+                       throw new \InvalidArgumentException("Unknown thumbnail size '".$size."'");
+               }
+               
+               if ($this->{$size.'ThumbnailType'}) {
+                       return true;
+               }
+               
+               if ($this->width <= self::$thumbnailSizes[$size]['width'] && $this->height <= self::$thumbnailSizes[$size]['height']) {
+                       return true;
+               }
+               
+               return false;
+       }
+       
        /**
         * Returns the storage path of the media files.
         *