]> _ Git - cubist_cms-back.git/commitdiff
Avoid errors while fetching alt text when no image is set or image isn't found. Also...
authorStephen Cameron <stephen@cubedesigners.com>
Mon, 6 Jul 2020 17:59:11 +0000 (19:59 +0200)
committerStephen Cameron <stephen@cubedesigners.com>
Mon, 6 Jul 2020 17:59:11 +0000 (19:59 +0200)
src/app/Magic/Models/CubistMagicAbstractModel.php
src/app/Middleware/LocaleSelector.php

index 86f86d8d3aa83dd2daec20fabe68a9c703be0785..04a9402628611b1d7867c0900e369c5a9457e5a5 100644 (file)
@@ -574,9 +574,15 @@ class CubistMagicAbstractModel extends Model implements HasMedia
         return $this->getMedia($c);
     }
 
-    public function getFirstMediaAlt($collection, $default = '')
+    public function getFirstMediaAlt($collection = 'default', $default = '')
     {
-        return $this->getFirstMedia($collection)->getCustomProperty('alt') ?? $default;
+        $media = $this->getFirstMedia($collection);
+        if (!$media) return $default;
+
+        $alt = $media->getCustomProperty('alt');
+        if (!$alt) return $default;
+
+        return $alt;
     }
 
     public function getAttribute($key)
index f5af9cc4746fa36bacb07375b7bc85ba02e64f24..69f8f9aab6017a525adabb841666f91cdcdbae94 100644 (file)
@@ -32,9 +32,23 @@ class LocaleSelector extends CubistMiddleware
             $domain = $this->_getDomainByLocale(Locale::getLocaleData($defaultLocale));
             // redirect to default locale
             if (null === $domain) {
-                abort(401);
+                // This should only happen in development but it is really hard to debug without a helpful message...
+                abort(401, 'Domain not found. Ensure APP_ENV is correct and domain exists in database (cubist_locales)');
             }
-            $protocol = $_SERVER['HTTPS'] ? 'https://' : 'http://';
+
+            // Determine if connection is secure, supporting proxies
+            // Ref: https://stackoverflow.com/a/16076965
+            $is_secure = false;
+            if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
+                $is_secure = true;
+            } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])
+                        && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'
+                        || !empty($_SERVER['HTTP_X_FORWARDED_SSL'])
+                        && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
+                $is_secure = true;
+            }
+            $protocol = $is_secure ? 'https://' : 'http://';
+
             $url = $protocol . $domain;
             return redirect($url);
         }