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)
$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);
}