File: /home/assibfaf/assignmentghostwriter.com/prox-functions.php
<?php
/**
* @package Proxim
* @author Davison Pro <davisonpro.coder@gmail.com | https://davisonpro.dev>
* @copyright 2019 Proxim
* @version 1.0.0
* @since File available since Release 1.0.0
*/
use Proxim\Util\ArrayUtils;
use Proxim\Smarty\SmartyLazyRegister;
use Proxim\Tools;
/**
* Sanitize data which will be injected into SQL query
*
* @param string $string SQL data which will be injected into SQL query
* @param bool $htmlOK Does data contain HTML code ? (optional)
* @return string Sanitized data
*/
function pSQL($string, $htmlOK = false)
{
return Db::getInstance()->escape($string, $htmlOK);
}
function bqSQL($string)
{
return str_replace('`', '\`', pSQL($string));
}
function smartyRegisterFunction($smarty, $type, $function, $params, $lazy = true, $initial_lazy_register = null)
{
if (!in_array($type, array('function', 'modifier', 'block'))) {
return false;
}
// lazy is better if the function is not called on every page
if ($lazy) {
if (null !== $initial_lazy_register && $initial_lazy_register->isRegistered($params)) {
return;
}
$lazy_register = SmartyLazyRegister::getInstance($smarty);
if ($lazy_register->isRegistered($params)) {
return;
}
$lazy_register->register($params);
if (is_array($params)) {
$params = $params[1];
}
// SmartyLazyRegister allows to only load external class when they are needed
$smarty->registerPlugin($type, $function, array($lazy_register, $params));
} else {
$smarty->registerPlugin($type, $function, $params);
}
}
function smartyClassname($classname)
{
$classname = Tools::replaceAccentedChars(strtolower($classname));
$classname = preg_replace('/[^A-Za-z0-9]/', '-', $classname);
$classname = preg_replace('/[-]+/', '-', $classname);
return $classname;
}
function smartyClassnames(array $classnames)
{
$enabled_classes = array();
foreach ($classnames as $key => $classname ) {
$enabled_classes[] = smartyClassname($classname);
}
return implode(' ', $enabled_classes);
}
function fix_strtolower($str)
{
if (function_exists('mb_strtoupper')) {
return mb_strtolower($str);
} else {
return strtolower($str);
}
}
function fix_filename($str, $transliteration)
{
if ($transliteration) {
if (function_exists('transliterator_transliterate')) {
$str = transliterator_transliterate('Accents-Any', $str);
} else {
$str = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $str);
}
$str = preg_replace("/[^a-zA-Z0-9\.\[\]_| -]/", '', $str);
}
$str=str_replace(array('"', "'", "/", "\\"), "", $str);
$str=strip_tags($str);
// Empty or incorrectly transliterated filename.
// Here is a point: a good file UNKNOWN_LANGUAGE.jpg could become .jpg in previous code.
// So we add that default 'file' name to fix that issue.
if (strpos($str, '.') === 0) {
$str = 'file'.$str;
}
return trim($str);
}
function toFixed($number, $decimals = 2) {
return number_format($number, $decimals, '.', "");
}
function formatPrice($value, $options = array()) {
$currency = (array) ArrayUtils::get($options, 'currency');
$fixed = (int) ArrayUtils::get($options, 'fixed', 2);
$symbol = ArrayUtils::get($currency, 'symbol', "$");
$rate = (float) ArrayUtils::get($currency, 'rate', 1);
$isInverted = (bool) ArrayUtils::get($currency, 'isInverted', false);
$price = $isInverted ? $value / $rate : $value * $rate;
return is_numeric($value) && is_finite($value) ? $value < 0 ? "–" : "" . $symbol . toFixed(abs($price), $fixed) : "N/A";
}
/**
* validExtension
*
* @param string $extension
* @param array $allowed_extensions
* @return boolean
*/
function validExtension($extension, $allowed_extensions) {
$extensions = explode(',', $allowed_extensions);
foreach ($extensions as $key => $value) {
$extensions[$key] = strtolower(trim($value));
}
if(is_array($extensions) && in_array($extension, $extensions)) {
return true;
}
return false;
}
function formatBytes($bytes, $precision = 2) {
$units = array('B', 'KB', 'MB', 'GB', 'TB');
$bytes = max($bytes, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
$pow = min($pow, count($units) - 1);
$bytes /= pow(1024, $pow);
return round($bytes, $precision) . ' ' . $units[$pow];
}