bebeboutik/override/classes/Tools.php
Marion Muszynski 33cd9f3d08 continuation
2017-03-09 11:37:44 +01:00

133 lines
4.9 KiB
PHP
Executable File

<?php
class Tools extends ToolsCore {
public static function getShopDomain($http=FALSE, $entities=FALSE) {
global $site_version;
if(!($domain = (isset($site_version)
? str_replace('bebeboutik.com', 'bebeboutik.'.$site_version, Configuration::get(_PS_MOBILE_? 'PS_MOBILE_DOMAIN': (_PS_OPEN_SHOP_? 'PS_OPEN_SHOP_DOMAIN': 'PS_SHOP_DOMAIN')))
: Configuration::get(_PS_MOBILE_? 'PS_MOBILE_DOMAIN': (_PS_OPEN_SHOP_? 'PS_OPEN_SHOP_DOMAIN': 'PS_SHOP_DOMAIN'))
))) {
$domain = self::getHttpHost();
}
if($entities) {
$domain = htmlspecialchars($domain, ENT_COMPAT, 'UTF-8');
}
if($http) {
$domain = (($_SERVER['SERVER_PORT'] == _PS_SSL_PORT_ || !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PORT'] == '443') || Configuration::get('PS_SSL_ENABLED'))? 'https://': 'http://').$domain;
}
return $domain;
// if(!($domain = Configuration::get( _PS_MOBILE_ ? 'PS_MOBILE_DOMAIN' : 'PS_SHOP_DOMAIN'))) {
// $domain = self::getHttpHost();
// }
// if($entities) {
// $domain = htmlspecialchars($domain, ENT_COMPAT, 'UTF-8');
// }
// if($http) {
// $domain = (($_SERVER['SERVER_PORT'] == _PS_SSL_PORT_ || !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' || Configuration::get('PS_SSL_ENABLED'))? 'https://': 'http://').$domain;
// }
// return $domain;
}
public static function getShopDomainSsl($http=FALSE, $entities=FALSE) {
global $site_version;
if(!($domain = (isset($site_version)
? str_replace('bebeboutik.com', 'bebeboutik.'.$site_version, Configuration::get(_PS_MOBILE_? 'PS_MOBILE_DOMAIN': (_PS_OPEN_SHOP_? 'PS_OPEN_SHOP_DOMAIN': 'PS_SHOP_DOMAIN')))
: Configuration::get(_PS_MOBILE_? 'PS_MOBILE_DOMAIN': (_PS_OPEN_SHOP_? 'PS_OPEN_SHOP_DOMAIN': 'PS_SHOP_DOMAIN'))
))) {
$domain = self::getHttpHost();
}
if($entities) {
$domain = htmlspecialchars($domain, ENT_COMPAT, 'UTF-8');
}
if($http) {
$domain = (($_SERVER['SERVER_PORT'] == _PS_SSL_PORT_ || !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PORT'] == '443') || Configuration::get('PS_SSL_ENABLED'))? 'https://': 'http://').$domain;
}
return $domain;
// } else {
// if(!($domain = Configuration::get( _PS_MOBILE_ ? 'PS_MOBILE_DOMAIN' : 'PS_SHOP_DOMAIN_SSL'))) {
// $domain = self::getHttpHost();
// }
// if($entities) {
// $domain = htmlspecialchars($domain, ENT_COMPAT, 'UTF-8');
// }
// if($http) {
// $domain = (($_SERVER['SERVER_PORT'] == _PS_SSL_PORT_ || !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' || Configuration::get('PS_SSL_ENABLED'))? 'https://': 'http://').$domain;
// }
// return $domain;
// }
}
public static function getProtocol($use_ssl=NULL) {
return (!is_null($use_ssl) && $use_ssl || $_SERVER['SERVER_PORT'] == _PS_SSL_PORT_ || !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PORT'] == '443') || Configuration::get('PS_SSL_ENABLED')? 'https://': 'http://');
}
public static function setCookieLanguage() {
global $cookie;
/* If language does not exist or is disabled, erase it */
if($cookie->id_lang) {
$lang = new Language((int)$cookie->id_lang);
if(!Validate::isLoadedObject($lang)) {
$cookie->id_lang = NULL;
}
}
/* If language file not present, you must use default language file */
if(!$cookie->id_lang OR !Validate::isUnsignedId($cookie->id_lang))
$cookie->id_lang = (int) Configuration::get('PS_LANG_DEFAULT');
$iso = Language::getIsoById((int) $cookie->id_lang);
@include_once(_PS_THEME_DIR_.'lang/'.$iso.'.php');
return $iso;
}
public static function addCSS($css_uri, $css_media_type = 'all')
{
global $css_files;
if (is_array($css_uri))
{
foreach ($css_uri as $file => $media_type){
self::addCSS(self::getShopDomain(true).$file, $media_type);
}
return true;
}
//overriding of modules css files
$different = 0;
$override_path = str_replace(__PS_BASE_URI__.'modules/', _PS_ROOT_DIR_.'/themes/'._THEME_NAME_.'/css/modules/', $css_uri, $different);
if ($different && file_exists($override_path))
$css_uri = str_replace(__PS_BASE_URI__.'modules/', __PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/modules/', $css_uri, $different);
else
{
// remove PS_BASE_URI on _PS_ROOT_DIR_ for the following
$url_data = parse_url($css_uri);
$file_uri = _PS_ROOT_DIR_.self::str_replace_once(__PS_BASE_URI__, DIRECTORY_SEPARATOR, $url_data['path']);
// check if css files exists
if (!file_exists($file_uri))
return true;
}
// detect mass add
$css_uri = array(self::getShopDomain(true).$css_uri => $css_media_type);
// adding file to the big array...
if (is_array($css_files))
$css_files = array_merge($css_files, $css_uri);
else
$css_files = $css_uri;
return true;
}
}