Merge branch 'develop' into qlo-php-smarty

This commit is contained in:
Rohit Jain
2021-10-14 18:03:36 +05:30
committed by GitHub
1052 changed files with 87638 additions and 45426 deletions

View File

@@ -104,65 +104,7 @@ class ToolsCore
}
}
if (function_exists('mcrypt_create_iv')) {
$bytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
if ($bytes !== false && strlen($bytes) === $length) {
return $bytes;
}
}
// Else try to get $length bytes of entropy.
// Thanks to Zend
$result = '';
$entropy = '';
$msec_per_round = 400;
$bits_per_round = 2;
$total = $length;
$hash_length = 20;
while (strlen($result) < $length) {
$bytes = ($total > $hash_length) ? $hash_length : $total;
$total -= $bytes;
for ($i=1; $i < 3; $i++) {
$t1 = microtime(true);
$seed = mt_rand();
for ($j=1; $j < 50; $j++) {
$seed = sha1($seed);
}
$t2 = microtime(true);
$entropy .= $t1 . $t2;
}
$div = (int) (($t2 - $t1) * 1000000);
if ($div <= 0) {
$div = 400;
}
$rounds = (int) ($msec_per_round * 50 / $div);
$iter = $bytes * (int) (ceil(8 / $bits_per_round));
for ($i = 0; $i < $iter; $i ++) {
$t1 = microtime();
$seed = sha1(mt_rand());
for ($j = 0; $j < $rounds; $j++) {
$seed = sha1($seed);
}
$t2 = microtime();
$entropy .= $t1 . $t2;
}
$result .= sha1($entropy, true);
}
return substr($result, 0, $length);
return false;
}
public static function strReplaceFirst($search, $replace, $subject, $cur = 0)
@@ -1071,7 +1013,7 @@ class ToolsCore
echo '
<script type="text/javascript">
console.'.$type.'('.Tools::jsonEncode($object).');
console.'.$type.'('.json_encode($object).');
</script>
';
}
@@ -1827,10 +1769,10 @@ class ToolsCore
return Tools::strtoupper(Tools::substr($str, 0, 1)).Tools::substr($str, 1);
}
public static function ucwords($str)
public static function ucwords($str, $encoding = 'utf-8')
{
if (function_exists('mb_convert_case')) {
return mb_convert_case($str, MB_CASE_TITLE);
return mb_convert_case($str, MB_CASE_TITLE, $encoding);
}
return ucwords(Tools::strtolower($str));
}
@@ -2665,19 +2607,15 @@ exit;
/**
* jsonDecode convert json string to php array / object
*
* @param string $json
* @param string $data
* @param bool $assoc (since 1.4.2.4) if true, convert to associativ array
* @return array
*/
public static function jsonDecode($json, $assoc = false)
public static function jsonDecode($data, $assoc = false, $depth = 512, $options = 0
)
{
if (function_exists('json_decode')) {
return json_decode($json, $assoc);
} else {
include_once(_PS_TOOL_DIR_.'json/json.php');
$pear_json = new Services_JSON(($assoc) ? SERVICES_JSON_LOOSE_TYPE : 0);
return $pear_json->decode($json);
}
Tools::displayAsDeprecated();
return json_decode($data, $assoc, $depth, $options);
}
/**
@@ -2686,15 +2624,15 @@ exit;
* @param array $data
* @return string json
*/
public static function jsonEncode($data)
public static function jsonEncode($data, $options = 0, $depth = 512)
{
if (function_exists('json_encode')) {
return json_encode($data);
} else {
include_once(_PS_TOOL_DIR_.'json/json.php');
$pear_json = new Services_JSON();
return $pear_json->encode($data);
Tools::displayAsDeprecated();
if (PHP_VERSION_ID < 50500) { /* PHP version < 5.5.0 */
return json_encode($data, $options);
}
return json_encode($data, $options, $depth);
}
/**
@@ -2859,14 +2797,9 @@ exit;
*/
public static function ZipTest($from_file)
{
if (class_exists('ZipArchive', false)) {
$zip = new ZipArchive();
return ($zip->open($from_file, ZIPARCHIVE::CHECKCONS) === true);
} else {
require_once(_PS_ROOT_DIR_.'/tools/pclzip/pclzip.lib.php');
$zip = new PclZip($from_file);
return ($zip->privCheckFormat() === true);
}
$zip = new ZipArchive();
return ($zip->open($from_file, ZipArchive::CHECKCONS) === true);
}
public static function getSafeModeStatus()
@@ -2886,23 +2819,12 @@ exit;
if (!file_exists($to_dir)) {
mkdir($to_dir, 0777);
}
if (class_exists('ZipArchive', false)) {
$zip = new ZipArchive();
if ($zip->open($from_file) === true && $zip->extractTo($to_dir) && $zip->close()) {
return true;
}
return false;
} else {
require_once(_PS_ROOT_DIR_.'/tools/pclzip/pclzip.lib.php');
$zip = new PclZip($from_file);
$list = $zip->extract(PCLZIP_OPT_PATH, $to_dir, PCLZIP_OPT_REPLACE_NEWER);
foreach ($list as $file) {
if ($file['status'] != 'ok' && $file['status'] != 'already_a_directory') {
return false;
}
}
$zip = new ZipArchive();
if ($zip->open($from_file) === true && $zip->extractTo($to_dir) && $zip->close()) {
return true;
}
return false;
}
public static function chmodr($path, $filemode)
@@ -3631,8 +3553,6 @@ exit;
public static function purifyHTML($html, $uri_unescape = null, $allow_style = false)
{
require_once(_PS_TOOL_DIR_.'htmlpurifier/HTMLPurifier.standalone.php');
static $use_html_purifier = null;
static $purifier = null;