Fallback to base64-encoded favicon for multiple domain setups
authorAlexander Ebert <ebert@woltlab.com>
Fri, 28 Nov 2014 00:50:02 +0000 (01:50 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 28 Nov 2014 00:50:02 +0000 (01:50 +0100)
Favico.js uses a <canvas> to draw the badge, but this will fail if the accessed domain is foo.example.com and the favicon was served from bar.example.com. This is caused by the fact that the <canvas> is considered tainted once an external image has been loaded and thus refuses to export the resulting image.

Roughly 99.99% of all setups use only a single domain, thus there is absolutely no change in this case. This change adresses potentially issues when running a multiple-domain setup.

com.woltlab.wcf/templates/headInclude.tpl
wcfsetup/install/files/lib/system/WCF.class.php

index 93e2c6b905be1ea5fdd8ca6fbfc615e48ceaf49c..f6695c669e4b480346e3989de8e0741a7929a3fc 100644 (file)
@@ -23,7 +23,7 @@
 {event name='stylesheets'}
 
 <!-- Icons -->
-<link rel="icon" href="{@$__wcf->getPath()}images/favicon.ico" type="image/x-icon" />
+<link rel="icon" href="{@$__wcf->getFavicon()}" type="image/x-icon" />
 <link rel="apple-touch-icon" href="{@$__wcf->getPath()}images/apple-touch-icon.png" />
 
 <script data-relocate="true">
index 31d024eeeb45b261e64d61e0dd5eace962bfcf69..213351318b0ac78fd5818cca86b99d5160c517ce 100644 (file)
@@ -822,6 +822,26 @@ class WCF {
                return substr(sha1(preg_replace('~^https~', 'http', self::getPath())), 0, 8);
        }
        
+       /**
+        * Returns the favicon URL or a base64 encoded image.
+        * 
+        * @return      string
+        */
+       public function getFavicon() {
+               $activeApplication = ApplicationHandler::getInstance()->getActiveApplication();
+               $primaryApplication = ApplicationHandler::getInstance()->getPrimaryApplication();
+               
+               if ($activeApplication->domainName != $primaryApplication->domainName) {
+                       if (file_exists(WCF_DIR.'images/favicon.ico')) {
+                               $favicon = file_get_contents(WCF_DIR.'images/favicon.ico');
+                               
+                               return 'data:image/x-icon;base64,' . base64_encode($favicon);
+                       }
+               }
+               
+               return WCF::getPath() . 'images/favicon.ico';
+       }
+       
        /**
         * Initialises the cronjobs.
         */