V1.4.0 released: Upsell feature, New Product Page, New Stats Module, Security fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2015 PrestaShop
|
||||
* 2007-2017 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -18,14 +18,16 @@
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2015 PrestaShop SA
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2017 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
class ToolsCore
|
||||
{
|
||||
const CACERT_LOCATION = 'https://curl.haxx.se/ca/cacert.pem';
|
||||
|
||||
protected static $file_exists_cache = array();
|
||||
protected static $_forceCompile;
|
||||
protected static $_caching;
|
||||
@@ -575,16 +577,19 @@ class ToolsCore
|
||||
|
||||
public static function getCountry($address = null)
|
||||
{
|
||||
if ($id_country = Tools::getValue('id_country')); elseif (isset($address) && isset($address->id_country) && $address->id_country) {
|
||||
$id_country = $address->id_country;
|
||||
} elseif (Configuration::get('PS_DETECT_COUNTRY') && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
preg_match('#(?<=-)\w\w|\w\w(?!-)#', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $array);
|
||||
if (is_array($array) && isset($array[0]) && Validate::isLanguageIsoCode($array[0])) {
|
||||
$id_country = (int)Country::getByIso($array[0], true);
|
||||
}
|
||||
}
|
||||
$id_country = (int)Tools::getValue('id_country');
|
||||
if ($id_country && Validate::isInt($id_country)) {
|
||||
return (int)$id_country;
|
||||
} elseif (!$id_country && isset($address) && isset($address->id_country) && $address->id_country) {
|
||||
$id_country = (int)$address->id_country;
|
||||
} elseif (Configuration::get('PS_DETECT_COUNTRY') && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
|
||||
preg_match('#(?<=-)\w\w|\w\w(?!-)#', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $array);
|
||||
if (is_array($array) && isset($array[0]) && Validate::isLanguageIsoCode($array[0])) {
|
||||
$id_country = (int)Country::getByIso($array[0], true);
|
||||
}
|
||||
}
|
||||
if (!isset($id_country) || !$id_country) {
|
||||
$id_country = Configuration::get('PS_COUNTRY_DEFAULT');
|
||||
$id_country = (int)Configuration::get('PS_COUNTRY_DEFAULT');
|
||||
}
|
||||
return (int)$id_country;
|
||||
}
|
||||
@@ -617,9 +622,9 @@ class ToolsCore
|
||||
return $currency;
|
||||
} else {
|
||||
// get currency from context
|
||||
$currency = Shop::getEntityIds('currency', Context::getContext()->shop->id, true, true);
|
||||
if (isset($currency[0]) && $currency[0]['id_currency']) {
|
||||
$cookie->id_currency = $currency[0]['id_currency'];
|
||||
$currentCurrency = Shop::getEntityIds('currency', Context::getContext()->shop->id, true, true);
|
||||
if (isset($currentCurrency[0]) && $currentCurrency[0]['id_currency']) {
|
||||
$cookie->id_currency = $currentCurrency[0]['id_currency'];
|
||||
return Currency::getCurrencyInstance((int)$cookie->id_currency);
|
||||
}
|
||||
}
|
||||
@@ -633,6 +638,7 @@ class ToolsCore
|
||||
* @param float $price Product price
|
||||
* @param object|array $currency Current currency (object, id_currency, NULL => context currency)
|
||||
* @return string Price correctly formated (sign, decimal separator...)
|
||||
* if you modify this function, don't forget to modify the Javascript function formatCurrency (in tools.js)
|
||||
*/
|
||||
public static function displayPrice($price, $currency = null, $no_utf8 = false, Context $context = null)
|
||||
{
|
||||
@@ -644,9 +650,7 @@ class ToolsCore
|
||||
}
|
||||
if ($currency === null) {
|
||||
$currency = $context->currency;
|
||||
}
|
||||
// if you modified this function, don't forget to modify the Javascript function formatCurrency (in tools.js)
|
||||
elseif (is_int($currency)) {
|
||||
} elseif (is_int($currency)) {
|
||||
$currency = Currency::getCurrencyInstance((int)$currency);
|
||||
}
|
||||
|
||||
@@ -813,9 +817,9 @@ class ToolsCore
|
||||
* @param Currency $currency_from if null we used the default currency
|
||||
* @param Currency $currency_to if null we used the default currency
|
||||
*/
|
||||
public static function convertPriceFull($amount, Currency $currency_from = null, Currency $currency_to = null)
|
||||
public static function convertPriceFull($amount, Currency $currency_from = null, Currency $currency_to = null, $round = true)
|
||||
{
|
||||
if ($currency_from === $currency_to) {
|
||||
if ($currency_from == $currency_to) {
|
||||
return $amount;
|
||||
}
|
||||
|
||||
@@ -836,7 +840,10 @@ class ToolsCore
|
||||
// Convert to new currency
|
||||
$amount *= $currency_to->conversion_rate;
|
||||
}
|
||||
return Tools::ps_round($amount, _PS_PRICE_COMPUTE_PRECISION_);
|
||||
if ($round) {
|
||||
$amount = Tools::ps_round($amount, _PS_PRICE_COMPUTE_PRECISION_);
|
||||
}
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2039,20 +2046,52 @@ class ToolsCore
|
||||
return file_exists($filename);
|
||||
}
|
||||
|
||||
public static function file_get_contents($url, $use_include_path = false, $stream_context = null, $curl_timeout = 5)
|
||||
public static function refreshCACertFile()
|
||||
{
|
||||
if ($stream_context == null && preg_match('/^https?:\/\//', $url)) {
|
||||
$stream_context = @stream_context_create(array('http' => array('timeout' => $curl_timeout)));
|
||||
if ((time() - @filemtime(_PS_CACHE_CA_CERT_FILE_) > 1296000)) {
|
||||
$stream_context = @stream_context_create(
|
||||
array(
|
||||
'http' => array('timeout' => 3),
|
||||
'ssl' => array(
|
||||
'cafile' => _PS_CACHE_CA_CERT_FILE_,
|
||||
)
|
||||
)
|
||||
);
|
||||
$ca_cert_content = @file_get_contents(Tools::CACERT_LOCATION, false, $stream_context);
|
||||
|
||||
if (
|
||||
preg_match('/(.*-----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----){50}$/Uims', $ca_cert_content) &&
|
||||
substr(rtrim($ca_cert_content), -1) == '-'
|
||||
) {
|
||||
file_put_contents(_PS_CACHE_CA_CERT_FILE_, $ca_cert_content);
|
||||
}
|
||||
}
|
||||
if (in_array(ini_get('allow_url_fopen'), array('On', 'on', '1')) || !preg_match('/^https?:\/\//', $url)) {
|
||||
return @file_get_contents($url, $use_include_path, $stream_context);
|
||||
} elseif (function_exists('curl_init')) {
|
||||
}
|
||||
|
||||
public static function file_get_contents($url, $use_include_path = false, $stream_context = null, $curl_timeout = 5, $fallback = false)
|
||||
{
|
||||
$is_local_file = !preg_match('/^https?:\/\//', $url);
|
||||
if ($stream_context == null && !$is_local_file) {
|
||||
$stream_context = @stream_context_create(array('http' => array('timeout' => $curl_timeout), 'ssl' => array('verify_peer' => true)));
|
||||
}
|
||||
|
||||
if (in_array(ini_get('allow_url_fopen'), array('On', 'on', '1')) || $is_local_file) {
|
||||
$content = @file_get_contents($url, $use_include_path, $stream_context);
|
||||
if (!in_array($content, array('', false)) || $is_local_file || !$fallback) {
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
if (function_exists('curl_init')) {
|
||||
Tools::refreshCACertFile();
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $curl_timeout);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
|
||||
curl_setopt($curl, CURLOPT_CAINFO, _PS_CACHE_CA_CERT_FILE_);
|
||||
if ($stream_context != null) {
|
||||
$opts = stream_context_get_options($stream_context);
|
||||
if (isset($opts['http']['method']) && Tools::strtolower($opts['http']['method']) == 'post') {
|
||||
@@ -2370,8 +2409,7 @@ class ToolsCore
|
||||
|
||||
fwrite($write_fd, "RewriteEngine on\n");
|
||||
|
||||
if (
|
||||
!$medias && Configuration::getMultiShopValues('PS_MEDIA_SERVER_1')
|
||||
if (!$medias && Configuration::getMultiShopValues('PS_MEDIA_SERVER_1')
|
||||
&& Configuration::getMultiShopValues('PS_MEDIA_SERVER_2')
|
||||
&& Configuration::getMultiShopValues('PS_MEDIA_SERVER_3')
|
||||
) {
|
||||
@@ -2505,10 +2543,11 @@ class ToolsCore
|
||||
fwrite($write_fd, "AddType application/vnd.ms-fontobject .eot\n");
|
||||
fwrite($write_fd, "AddType font/ttf .ttf\n");
|
||||
fwrite($write_fd, "AddType font/otf .otf\n");
|
||||
fwrite($write_fd, "AddType font/woff2 .woff2\n");
|
||||
fwrite($write_fd, "AddType application/x-font-woff .woff\n");
|
||||
fwrite($write_fd, "<IfModule mod_headers.c>
|
||||
<FilesMatch \"\.(ttf|ttc|otf|eot|woff|svg)$\">
|
||||
Header add Access-Control-Allow-Origin \"*\"
|
||||
<FilesMatch \"\.(ttf|ttc|otf|eot|woff|woff2|svg)$\">
|
||||
Header set Access-Control-Allow-Origin \"*\"
|
||||
</FilesMatch>
|
||||
</IfModule>\n\n");
|
||||
|
||||
@@ -2528,6 +2567,7 @@ class ToolsCore
|
||||
ExpiresByType image/vnd.microsoft.icon \"access plus 1 year\"
|
||||
ExpiresByType application/font-woff \"access plus 1 year\"
|
||||
ExpiresByType application/x-font-woff \"access plus 1 year\"
|
||||
ExpiresByType font/woff2 \"access plus 1 year\"
|
||||
ExpiresByType application/vnd.ms-fontobject \"access plus 1 year\"
|
||||
ExpiresByType font/opentype \"access plus 1 year\"
|
||||
ExpiresByType font/ttf \"access plus 1 year\"
|
||||
@@ -2542,7 +2582,7 @@ class ToolsCore
|
||||
FileETag none
|
||||
<IfModule mod_deflate.c>
|
||||
<IfModule mod_filter.c>
|
||||
AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/x-javascript font/ttf application/x-font-ttf font/otf application/x-font-otf font/opentype
|
||||
AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/x-javascript font/ttf application/x-font-ttf font/otf application/x-font-otf font/opentype image/svg+xml
|
||||
</IfModule>
|
||||
</IfModule>\n\n";
|
||||
fwrite($write_fd, $cache_control);
|
||||
@@ -2898,7 +2938,7 @@ exit;
|
||||
public static function getProductsOrder($type, $value = null, $prefix = false)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'by' :
|
||||
case 'by':
|
||||
$list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference');
|
||||
$value = (is_null($value) || $value === false || $value === '') ? (int)Configuration::get('PS_PRODUCTS_ORDER_BY') : $value;
|
||||
$value = (isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'position');
|
||||
@@ -2919,7 +2959,7 @@ exit;
|
||||
return $order_by_prefix.$value;
|
||||
break;
|
||||
|
||||
case 'way' :
|
||||
case 'way':
|
||||
$value = (is_null($value) || $value === false || $value === '') ? (int)Configuration::get('PS_PRODUCTS_ORDER_WAY') : $value;
|
||||
$list = array(0 => 'asc', 1 => 'desc');
|
||||
return ((isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'asc'));
|
||||
@@ -3058,8 +3098,7 @@ exit;
|
||||
// Change template dir if called from the BackOffice
|
||||
$current_template_dir = Context::getContext()->smarty->getTemplateDir();
|
||||
Context::getContext()->smarty->setTemplateDir(_PS_THEME_DIR_);
|
||||
Tools::clearCache(null, 'product-list-colors.tpl',
|
||||
($id_product ? 'productlist_colors|'.(int)$id_product.'|'.(int)Context::getContext()->shop->id : 'productlist_colors'));
|
||||
Tools::clearCache(null, _PS_THEME_DIR_.'product-list-colors.tpl', Product::getColorsListCacheId((int)$id_product, false));
|
||||
Context::getContext()->smarty->setTemplateDir($current_template_dir);
|
||||
}
|
||||
|
||||
@@ -3635,9 +3674,7 @@ exit;
|
||||
'type' => 'Text',
|
||||
));
|
||||
if ($allow_style) {
|
||||
$def->addElement('style', 'Block', 'Flow', 'Common', array(
|
||||
'type' => 'Text',
|
||||
));
|
||||
$def->addElement('style', 'Block', 'Flow', 'Common', array('type' => 'Text'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3687,7 +3724,7 @@ exit;
|
||||
* e.g. if $amount is 1, $precision is 0 and $rows = [['a' => 2], ['a' => 1]]
|
||||
* then the resulting $rows will be [['a' => 3], ['a' => 1]]
|
||||
* But if $precision were 1, then the resulting $rows would be [['a' => 2.5], ['a' => 1.5]]
|
||||
* @param &$rows array An array, associative or not, containing arrays that have at least $column and $sort_column fields
|
||||
* @param &$rows array An array, associative or not, containing arrays that have at least $column and $sort_column fields
|
||||
* @param $column string The column on which to perform adjustments
|
||||
*/
|
||||
public static function spreadAmount($amount, $precision, &$rows, $column)
|
||||
|
||||
Reference in New Issue
Block a user