1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-06-05 22:09:38 +02:00

Miglioramento della gestione delle funzioni

Miglioramento delle condizioni di aggiunta delle funzioni PHP dentro al file lib/util.php, con miglioramento della documentazione in lib/functions.php.
This commit is contained in:
Thomas Zilio
2017-09-04 12:12:48 +02:00
parent bf254b227b
commit 548639673a
2 changed files with 137 additions and 116 deletions

View File

@@ -742,6 +742,7 @@ function tr($string, $parameters = [], $domain = null, $locale = null)
return Translator::translate($string, $parameters, $domain, $locale); return Translator::translate($string, $parameters, $domain, $locale);
} }
// Retrocompatibilità
if (!function_exists('_')) { if (!function_exists('_')) {
function _($string, $parameters = [], $domain = null, $locale = null) function _($string, $parameters = [], $domain = null, $locale = null)
{ {
@@ -775,7 +776,7 @@ function get_var($nome, $sezione = null, $descrizione = false, $again = false)
* *
* @return string * @return string
*/ */
function filter($param, $rule = 'text', $method = null) function filter($param, $method = null)
{ {
return Filter::getValue($param, $method = null); return Filter::getValue($param, $method = null);
} }
@@ -810,11 +811,25 @@ function get($param, $rule = 'text')
return Filter::getValue($param, 'get'); return Filter::getValue($param, 'get');
} }
/**
* Controlla se è in corso una richiesta AJAX generata dal progetto.
*
* @return bool
*/
function isAjaxRequest() function isAjaxRequest()
{ {
return \Whoops\Util\Misc::isAjaxRequest() && filter('ajax') !== null; return \Whoops\Util\Misc::isAjaxRequest() && filter('ajax') !== null;
} }
/**
* Esegue una somma precisa tra due interi/array.
*
* @param array|float $first
* @param array|float $second
* @param int $decimals
*
* @return float
*/
function sum($first, $second = null, $decimals = null) function sum($first, $second = null, $decimals = null)
{ {
$first = (array) $first; $first = (array) $first;

View File

@@ -302,7 +302,8 @@ if (!function_exists('isHTTPS')) {
} }
} }
/** if (!function_exists('color_darken')) {
/**
* Scurisce un determinato colore. * Scurisce un determinato colore.
* *
* @param unknown $color * @param unknown $color
@@ -310,8 +311,8 @@ if (!function_exists('isHTTPS')) {
* *
* @return string * @return string
*/ */
function color_darken($color, $dif = 20) function color_darken($color, $dif = 20)
{ {
$color = str_replace('#', '', $color); $color = str_replace('#', '', $color);
if (strlen($color) != 6) { if (strlen($color) != 6) {
return '000000'; return '000000';
@@ -324,9 +325,11 @@ function color_darken($color, $dif = 20)
} }
return '#'.$rgb; return '#'.$rgb;
}
} }
/** if (!function_exists('color_inverse')) {
/**
* Inverte il colore inserito. * Inverte il colore inserito.
* *
* @see http://www.splitbrain.org/blog/2008-09/18-calculating_color_contrast_with_php * @see http://www.splitbrain.org/blog/2008-09/18-calculating_color_contrast_with_php
@@ -335,8 +338,8 @@ function color_darken($color, $dif = 20)
* *
* @return string * @return string
*/ */
function color_inverse($start_colour) function color_inverse($start_colour)
{ {
$R1 = hexdec(substr($start_colour, 1, 2)); $R1 = hexdec(substr($start_colour, 1, 2));
$G1 = hexdec(substr($start_colour, 3, 2)); $G1 = hexdec(substr($start_colour, 3, 2));
$B1 = hexdec(substr($start_colour, 5, 2)); $B1 = hexdec(substr($start_colour, 5, 2));
@@ -355,9 +358,11 @@ function color_inverse($start_colour)
} else { } else {
return '#000'; return '#000';
} }
}
} }
/** if (!function_exists('readSQLFile')) {
/**
* Restituisce l'insieme delle query presente nel file specificato. * Restituisce l'insieme delle query presente nel file specificato.
* *
* @param string $filename Percorso per il file * @param string $filename Percorso per il file
@@ -367,8 +372,8 @@ function color_inverse($start_colour)
* *
* @return array * @return array
*/ */
function readSQLFile($filename, $delimiter = ';') function readSQLFile($filename, $delimiter = ';')
{ {
$inString = false; $inString = false;
$escChar = false; $escChar = false;
$query = ''; $query = '';
@@ -419,4 +424,5 @@ function readSQLFile($filename, $delimiter = ';')
} while (next($sqlRows) !== false); } while (next($sqlRows) !== false);
return $queryLine; return $queryLine;
}
} }