$def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', array( 'src' => 'URI', 'type' => 'Text', 'width' => 'Length', 'height' => 'Length', 'poster' => 'URI', 'preload' => 'Enum#auto,metadata,none', 'controls' => 'Bool', )); $def->addElement('source', 'Block', 'Flow', 'Common', array( 'src' => 'URI', 'type' => 'Text', )); if ($allow_style) { $def->addElement('style', 'Block', 'Flow', 'Common', array('type' => 'Text')); } } $purifier = new HTMLPurifier($config); } if (_PS_MAGIC_QUOTES_GPC_) { $html = stripslashes($html); } $html = $purifier->purify($html); if (_PS_MAGIC_QUOTES_GPC_) { $html = addslashes($html); } } return $html; } /** * Check if a constant was already defined * @param string $constant Constant name * @param mixed $value Default value to set if not defined */ public static function safeDefine($constant, $value) { if (!defined($constant)) { define($constant, $value); } } /** * Spread an amount on lines, adjusting the $column field, * with the biggest adjustments going to the rows having the * highest $sort_column. * * E.g.: * * $rows = [['a' => 5.1], ['a' => 8.2]]; * * spreadAmount(0.3, 1, $rows, 'a'); * * => $rows is [['a' => 8.4], ['a' => 5.2]] * * @param $amount float The amount to spread across the rows * @param $precision int Rounding precision * 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 $column string The column on which to perform adjustments */ public static function spreadAmount($amount, $precision, &$rows, $column) { if (!is_array($rows) || empty($rows)) { return; } $sort_function = create_function('$a, $b', "return \$b['$column'] > \$a['$column'] ? 1 : -1;"); uasort($rows, $sort_function); $unit = pow(10, $precision); $int_amount = (int)round($unit * $amount); $remainder = $int_amount % count($rows); $amount_to_spread = ($int_amount - $remainder) / count($rows) / $unit; $sign = ($amount >= 0 ? 1 : -1); $position = 0; foreach ($rows as &$row) { $adjustment_factor = $amount_to_spread; if ($position < abs($remainder)) { $adjustment_factor += $sign * 1 / $unit; } $row[$column] += $adjustment_factor; ++$position; } unset($row); } /** * Replaces elements from passed arrays into the first array recursively * @param array $base The array in which elements are replaced. * @param array $replacements The array from which elements will be extracted. */ public static function arrayReplaceRecursive($base, $replacements) { if (function_exists('array_replace_recursive')) { return array_replace_recursive($base, $replacements); } foreach (array_slice(func_get_args(), 1) as $replacements) { $bref_stack = array(&$base); $head_stack = array($replacements); do { end($bref_stack); $bref = &$bref_stack[key($bref_stack)]; $head = array_pop($head_stack); unset($bref_stack[key($bref_stack)]); foreach (array_keys($head) as $key) { if (isset($key, $bref) && is_array($bref[$key]) && is_array($head[$key])) { $bref_stack[] = &$bref[$key]; $head_stack[] = $head[$key]; } else { $bref[$key] = $head[$key]; } } } while (count($head_stack)); } return $base; } } /** * Compare 2 prices to sort products * * @param float $a * @param float $b * @return int */ /* Externalized because of a bug in PHP 5.1.6 when inside an object */ function cmpPriceAsc($a, $b) { if ((float)$a['price_tmp'] < (float)$b['price_tmp']) { return (-1); } elseif ((float)$a['price_tmp'] > (float)$b['price_tmp']) { return (1); } return 0; } function cmpPriceDesc($a, $b) { if ((float)$a['price_tmp'] < (float)$b['price_tmp']) { return 1; } elseif ((float)$a['price_tmp'] > (float)$b['price_tmp']) { return -1; } return 0; }