Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/Stylist/Html/ThemeHtmlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ public function image($url, $alt = null, $attributes = array(), $secure = null)
}

/**
* Returns the theme's public URI location. This is not a full URL. If you wish
* for a full URL, simply add the site's URL configuration to this path.
* Checks if HTTPS / HTTP and returns full URL.
*
* @param string $file
* @return string
*/
public function url($file = '')
{
if ($this->isSecure()) {
return secure_url($this->assetUrl($file));
}

return url($this->assetUrl($file));
}

Expand Down Expand Up @@ -130,4 +133,22 @@ protected function assetUrl($url)

return $url;
}

protected function isSecure(){

if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
return true;
}

if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) {
return true;
}

// AWS Load Balancer
if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) && $_SERVER['HTTP_X_FORWARDED_PORT']??'' == 443) {
return true;
}

return false;
}
}