2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
/**
|
|
|
|
* Esegue il redirect.
|
|
|
|
*
|
|
|
|
* @param string $url
|
|
|
|
* @param string $type
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function redirect($url, $type = 'php')
|
|
|
|
{
|
|
|
|
switch ($type) {
|
|
|
|
case 'php':
|
|
|
|
header('Location: '.$url);
|
|
|
|
break;
|
|
|
|
case 'js':
|
|
|
|
echo '<script type="text/javascript">location.href="'.$url.'";</script>';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifica e corregge il nome di un file.
|
|
|
|
*
|
2018-03-19 15:30:16 +01:00
|
|
|
* @param string $filename
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function sanitizeFilename($filename)
|
|
|
|
{
|
|
|
|
$filename = str_replace(' ', '-', $filename);
|
|
|
|
$filename = preg_replace("/[^A-Za-z0-9_\-\.?!]/", '', $filename);
|
|
|
|
|
|
|
|
return $filename;
|
|
|
|
}
|
|
|
|
|
2017-09-11 17:49:03 +02:00
|
|
|
function delete($files)
|
2017-08-04 16:28:16 +02:00
|
|
|
{
|
2017-09-11 17:49:03 +02:00
|
|
|
// Filesystem Symfony
|
|
|
|
$fs = new Symfony\Component\Filesystem\Filesystem();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-11 17:49:03 +02:00
|
|
|
// Eliminazione
|
|
|
|
try {
|
|
|
|
$fs->remove($files);
|
|
|
|
} catch (Symfony\Component\Filesystem\Exception\IOException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-11 17:49:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function directory($path)
|
|
|
|
{
|
|
|
|
if (is_dir($path) && is_writable($path)) {
|
|
|
|
return true;
|
|
|
|
} elseif (!is_dir($path)) {
|
|
|
|
// Filesystem Symfony
|
|
|
|
$fs = new Symfony\Component\Filesystem\Filesystem();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-11 17:49:03 +02:00
|
|
|
// Tentativo di creazione
|
|
|
|
try {
|
|
|
|
$fs->mkdir($path);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} catch (Symfony\Component\Filesystem\Exception\IOException $e) {
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
2017-09-11 17:49:03 +02:00
|
|
|
|
|
|
|
return false;
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy a file, or recursively copy a folder and its contents.
|
|
|
|
*
|
|
|
|
* @author Aidan Lister <aidan@php.net>
|
|
|
|
*
|
|
|
|
* @version 1.0.1
|
|
|
|
*
|
|
|
|
* @see http://aidanlister.com/repos/v/function.copyr.php
|
|
|
|
*
|
2017-09-07 16:54:58 +02:00
|
|
|
* @param string $source
|
|
|
|
* Source path
|
|
|
|
* @param string $dest
|
|
|
|
* Destination path
|
2017-09-07 16:51:14 +02:00
|
|
|
* @param array|string $ignores
|
2017-09-07 16:54:58 +02:00
|
|
|
* Paths to ingore
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
|
|
|
* @return bool Returns TRUE on success, FALSE on failure
|
|
|
|
*/
|
2017-09-08 13:24:48 +02:00
|
|
|
function copyr($source, $destination, $ignores = [])
|
2017-08-04 16:28:16 +02:00
|
|
|
{
|
2017-09-08 13:24:48 +02:00
|
|
|
$finder = Symfony\Component\Finder\Finder::create()
|
|
|
|
->files()
|
|
|
|
->exclude((array) $ignores['dirs'])
|
|
|
|
->ignoreDotFiles(true)
|
|
|
|
->ignoreVCS(true)
|
|
|
|
->in($source);
|
2017-09-06 12:50:44 +02:00
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
foreach ((array) $ignores['files'] as $value) {
|
|
|
|
$finder->notName($value);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
2017-09-06 12:50:44 +02:00
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
foreach ($finder as $file) {
|
|
|
|
$filename = rtrim($destination, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file->getRelativePathname();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-11 17:49:03 +02:00
|
|
|
// Filesystem Symfony
|
|
|
|
$fs = new Symfony\Component\Filesystem\Filesystem();
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-11 17:49:03 +02:00
|
|
|
// Copia
|
|
|
|
try {
|
|
|
|
$fs->copy($file, $filename);
|
|
|
|
} catch (Symfony\Component\Filesystem\Exception\IOException $e) {
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Crea un file zip comprimendo ricorsivamente tutte le sottocartelle a partire da una cartella specificata.
|
2017-09-08 13:24:48 +02:00
|
|
|
* *.
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
2017-09-08 13:24:48 +02:00
|
|
|
* @param string $source
|
|
|
|
* @param string $destination
|
|
|
|
* @param array $ignores
|
2017-08-04 16:28:16 +02:00
|
|
|
*/
|
2017-09-08 13:24:48 +02:00
|
|
|
function create_zip($source, $destination, $ignores = [])
|
2017-08-04 16:28:16 +02:00
|
|
|
{
|
2017-09-08 13:24:48 +02:00
|
|
|
if (!extension_loaded('zip')) {
|
2017-09-04 12:02:29 +02:00
|
|
|
$_SESSION['errors'][] = tr('Estensione zip non supportata!');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$zip = new ZipArchive();
|
2017-09-06 12:50:44 +02:00
|
|
|
$result = $zip->open($destination, ZIPARCHIVE::CREATE);
|
|
|
|
if ($result === true && is_writable(dirname($destination))) {
|
2017-09-08 13:24:48 +02:00
|
|
|
$finder = Symfony\Component\Finder\Finder::create()
|
|
|
|
->files()
|
|
|
|
->exclude((array) $ignores['dirs'])
|
|
|
|
->ignoreDotFiles(true)
|
|
|
|
->ignoreVCS(true)
|
|
|
|
->in($source);
|
|
|
|
|
|
|
|
foreach ((array) $ignores['files'] as $value) {
|
|
|
|
$finder->notName($value);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
foreach ($finder as $file) {
|
|
|
|
$zip->addFile($file, $file->getRelativePathname());
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
$zip->close();
|
|
|
|
} else {
|
2017-09-04 12:02:29 +02:00
|
|
|
$_SESSION['errors'][] = tr("Errore durante la creazione dell'archivio!");
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
2017-09-06 12:50:44 +02:00
|
|
|
|
|
|
|
return $result === true;
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controllo dei file zip e gestione errori.
|
|
|
|
*
|
2018-03-19 15:30:16 +01:00
|
|
|
* @param string $zip_file
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
|
|
|
* @return string|bool
|
|
|
|
*/
|
|
|
|
function checkZip($zip_file)
|
|
|
|
{
|
|
|
|
$errno = zip_open($zip_file);
|
|
|
|
zip_close($errno);
|
|
|
|
|
|
|
|
if (!is_resource($errno)) {
|
|
|
|
// using constant name as a string to make this function PHP4 compatible
|
|
|
|
$errors = [
|
2017-09-04 12:02:29 +02:00
|
|
|
ZIPARCHIVE::ER_MULTIDISK => tr('archivi multi-disco non supportati'),
|
|
|
|
ZIPARCHIVE::ER_RENAME => tr('ridenominazione del file temporaneo fallita'),
|
|
|
|
ZIPARCHIVE::ER_CLOSE => tr('impossibile chiudere il file zip'),
|
|
|
|
ZIPARCHIVE::ER_SEEK => tr('errore durante la ricerca dei file'),
|
|
|
|
ZIPARCHIVE::ER_READ => tr('errore di lettura'),
|
|
|
|
ZIPARCHIVE::ER_WRITE => tr('errore di scrittura'),
|
|
|
|
ZIPARCHIVE::ER_CRC => tr('errore CRC'),
|
|
|
|
ZIPARCHIVE::ER_ZIPCLOSED => tr("l'archivio zip è stato chiuso"),
|
|
|
|
ZIPARCHIVE::ER_NOENT => tr('file non trovato'),
|
|
|
|
ZIPARCHIVE::ER_EXISTS => tr('il file esiste già'),
|
|
|
|
ZIPARCHIVE::ER_OPEN => tr('impossibile aprire il file'),
|
|
|
|
ZIPARCHIVE::ER_TMPOPEN => tr('impossibile creare il file temporaneo'),
|
|
|
|
ZIPARCHIVE::ER_ZLIB => tr('errore nella libreria Zlib'),
|
|
|
|
ZIPARCHIVE::ER_MEMORY => tr("fallimento nell'allocare memoria"),
|
|
|
|
ZIPARCHIVE::ER_CHANGED => tr('voce modificata'),
|
|
|
|
ZIPARCHIVE::ER_COMPNOTSUPP => tr('metodo di compressione non supportato'),
|
|
|
|
ZIPARCHIVE::ER_EOF => tr('fine del file non prevista'),
|
|
|
|
ZIPARCHIVE::ER_INVAL => tr('argomento non valido'),
|
|
|
|
ZIPARCHIVE::ER_NOZIP => tr('file zip non valido'),
|
|
|
|
ZIPARCHIVE::ER_INTERNAL => tr('errore interno'),
|
|
|
|
ZIPARCHIVE::ER_INCONS => tr('archivio zip inconsistente'),
|
|
|
|
ZIPARCHIVE::ER_REMOVE => tr('impossibile rimuovere la voce'),
|
|
|
|
ZIPARCHIVE::ER_DELETED => tr('voce eliminata'),
|
2017-08-04 16:28:16 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
if (isset($errors[$errno])) {
|
2017-09-04 12:02:29 +02:00
|
|
|
return tr('Errore').': '.$errors[$errno];
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Individua la differenza tra le date indicate.
|
|
|
|
* $interval può essere:
|
|
|
|
* yyyy - Number of full years
|
|
|
|
* q - Number of full quarters
|
|
|
|
* m - Number of full months
|
|
|
|
* y - Difference between day numbers
|
|
|
|
* (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
|
|
|
|
* d - Number of full days
|
|
|
|
* w - Number of full weekdays
|
|
|
|
* ww - Number of full weeks
|
|
|
|
* h - Number of full hours
|
|
|
|
* n - Number of full minutes
|
|
|
|
* s - Number of full seconds (default).
|
|
|
|
*
|
|
|
|
* @param unknown $interval
|
|
|
|
* @param unknown $datefrom
|
|
|
|
* @param unknown $dateto
|
|
|
|
* @param string $using_timestamps
|
|
|
|
*/
|
|
|
|
function datediff($interval, $datefrom, $dateto, $using_timestamps = false)
|
|
|
|
{
|
|
|
|
if (!$using_timestamps) {
|
|
|
|
$datefrom = strtotime($datefrom, 0);
|
|
|
|
$dateto = strtotime($dateto, 0);
|
|
|
|
}
|
|
|
|
$difference = $dateto - $datefrom; // Difference in seconds
|
|
|
|
switch ($interval) {
|
|
|
|
case 'yyyy': // Number of full years
|
|
|
|
$years_difference = floor($difference / 31536000);
|
|
|
|
if (mktime(date('H', $datefrom), date('i', $datefrom), date('s', $datefrom), date('n', $datefrom), date('j', $datefrom), date('Y', $datefrom) + $years_difference) > $dateto) {
|
|
|
|
--$years_difference;
|
|
|
|
}
|
|
|
|
if (mktime(date('H', $dateto), date('i', $dateto), date('s', $dateto), date('n', $dateto), date('j', $dateto), date('Y', $dateto) - ($years_difference + 1)) > $datefrom) {
|
|
|
|
++$years_difference;
|
|
|
|
}
|
|
|
|
$datediff = $years_difference;
|
|
|
|
break;
|
|
|
|
case 'q': // Number of full quarters
|
|
|
|
$quarters_difference = floor($difference / 8035200);
|
|
|
|
while (mktime(date('H', $datefrom), date('i', $datefrom), date('s', $datefrom), date('n', $datefrom) + ($quarters_difference * 3), date('j', $dateto), date('Y', $datefrom)) < $dateto) {
|
|
|
|
++$months_difference;
|
|
|
|
}
|
|
|
|
--$quarters_difference;
|
|
|
|
$datediff = $quarters_difference;
|
|
|
|
break;
|
|
|
|
case 'm': // Number of full months
|
|
|
|
$months_difference = floor($difference / 2678400);
|
|
|
|
while (mktime(date('H', $datefrom), date('i', $datefrom), date('s', $datefrom), date('n', $datefrom) + ($months_difference), date('j', $dateto), date('Y', $datefrom)) < $dateto) {
|
|
|
|
++$months_difference;
|
|
|
|
}
|
|
|
|
--$months_difference;
|
|
|
|
$datediff = $months_difference;
|
|
|
|
break;
|
|
|
|
case 'y': // Difference between day numbers
|
|
|
|
$datediff = date('z', $dateto) - date('z', $datefrom);
|
|
|
|
break;
|
|
|
|
case 'd': // Number of full days
|
|
|
|
$datediff = floor($difference / 86400);
|
|
|
|
break;
|
|
|
|
case 'w': // Number of full weekdays
|
|
|
|
$days_difference = floor($difference / 86400);
|
|
|
|
$weeks_difference = floor($days_difference / 7); // Complete weeks
|
|
|
|
$first_day = date('w', $datefrom);
|
|
|
|
$days_remainder = floor($days_difference % 7);
|
|
|
|
$odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
|
|
|
|
if ($odd_days > 7) { // Sunday
|
|
|
|
--$days_remainder;
|
|
|
|
}
|
|
|
|
if ($odd_days > 6) { // Saturday
|
|
|
|
--$days_remainder;
|
|
|
|
}
|
|
|
|
$datediff = ($weeks_difference * 5) + $days_remainder;
|
|
|
|
break;
|
|
|
|
case 'ww': // Number of full weeks
|
|
|
|
$datediff = floor($difference / 604800);
|
|
|
|
break;
|
|
|
|
case 'h': // Number of full hours
|
|
|
|
$datediff = floor($difference / 3600);
|
|
|
|
break;
|
|
|
|
case 'n': // Number of full minutes
|
|
|
|
$datediff = floor($difference / 60);
|
|
|
|
break;
|
|
|
|
default: // Number of full seconds (default)
|
|
|
|
$datediff = $difference;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $datediff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recupera informazioni sistema operativo dell'utente.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function getOS()
|
|
|
|
{
|
|
|
|
$os = [
|
|
|
|
'Windows NT 6.1' => 'Windows 7',
|
|
|
|
'Windows NT 6.0' => 'Windows Vista',
|
|
|
|
'Windows NT 5.1' => 'Windows XP',
|
|
|
|
'Windows NT 5.0' => 'Windows 2000',
|
|
|
|
'Windows NT 4.90' => 'Windows ME',
|
|
|
|
'Win95' => 'Windows 95',
|
|
|
|
'Win98' => 'Windows 98',
|
|
|
|
'Windows NT 5.2' => 'Windows NET',
|
|
|
|
'WinNT4.0' => 'Windows NT',
|
|
|
|
'Mac' => 'Mac',
|
|
|
|
'PPC' => 'Mac',
|
|
|
|
'Linux' => 'Linux',
|
|
|
|
'FreeBSD' => 'FreeBSD',
|
|
|
|
'SunOS' => 'SunOS',
|
|
|
|
'Irix' => 'Irix',
|
|
|
|
'BeOS' => 'BeOS',
|
|
|
|
'OS/2' => 'OS/2',
|
|
|
|
'AIX' => 'AIX',
|
|
|
|
];
|
2018-03-03 15:03:28 +01:00
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
foreach ($os as $key => $value) {
|
|
|
|
if (strpos($_SERVER['HTTP_USER_AGENT'], $key)) {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-04 12:02:29 +02:00
|
|
|
return tr('Altro');
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifica che il nome del file non sia già usato nella cartella inserita, nel qual caso aggiungo un suffisso.
|
|
|
|
*
|
2018-03-19 15:30:16 +01:00
|
|
|
* @param string $filename
|
|
|
|
* @param string $dir
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function unique_filename($filename, $dir)
|
|
|
|
{
|
|
|
|
$f = pathinfo($filename);
|
|
|
|
$suffix = 1;
|
|
|
|
while (file_exists($dir.'/'.$filename)) {
|
|
|
|
$filename = $f['filename'].'_'.$suffix.'.'.$f['extension'];
|
|
|
|
++$suffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Crea le thumbnails di $filename da dentro $dir e le salva in $dir.
|
|
|
|
*
|
2018-03-19 15:30:16 +01:00
|
|
|
* @param string $tmp
|
|
|
|
* @param string $filename
|
|
|
|
* @param string $dir
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function create_thumbnails($tmp, $filename, $dir)
|
|
|
|
{
|
|
|
|
$infos = pathinfo($filename);
|
|
|
|
$name = $infos['filename'];
|
|
|
|
$extension = strtolower($infos['extension']);
|
|
|
|
|
2017-09-11 17:49:03 +02:00
|
|
|
if (!directory($dir)) {
|
2017-08-04 16:28:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$driver = extension_loaded('gd') ? 'gd' : 'imagick';
|
|
|
|
Intervention\Image\ImageManagerStatic::configure(['driver' => $driver]);
|
|
|
|
|
|
|
|
$img = Intervention\Image\ImageManagerStatic::make($tmp);
|
|
|
|
|
|
|
|
$img->resize(600, null, function ($constraint) {
|
|
|
|
$constraint->aspectRatio();
|
|
|
|
});
|
|
|
|
$img->save(slashes($dir.'/'.$name.'.'.$extension));
|
|
|
|
|
|
|
|
$img->resize(250, null, function ($constraint) {
|
|
|
|
$constraint->aspectRatio();
|
|
|
|
});
|
|
|
|
$img->save(slashes($dir.'/'.$name.'_thumb250.'.$extension));
|
|
|
|
|
|
|
|
$img->resize(100, null, function ($constraint) {
|
|
|
|
$constraint->aspectRatio();
|
|
|
|
});
|
|
|
|
$img->save(slashes($dir.'/'.$name.'_thumb100.'.$extension));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ottiene l'indirizzo IP del client.
|
|
|
|
*
|
2018-03-19 15:30:16 +01:00
|
|
|
* @return string
|
2017-08-04 16:28:16 +02:00
|
|
|
*/
|
|
|
|
function get_client_ip()
|
|
|
|
{
|
|
|
|
$ipaddress = '';
|
2018-04-09 09:42:03 +02:00
|
|
|
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
|
|
|
|
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
|
|
|
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
|
|
|
} elseif (!empty($_SERVER['HTTP_X_FORWARDED'])) {
|
|
|
|
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
|
|
|
|
} elseif (!empty($_SERVER['HTTP_FORWARDED_FOR'])) {
|
|
|
|
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
|
|
|
|
} elseif (!empty($_SERVER['HTTP_FORWARDED'])) {
|
|
|
|
$ipaddress = $_SERVER['HTTP_FORWARDED'];
|
2018-04-09 09:42:03 +02:00
|
|
|
} elseif (!empty($_SERVER['REMOTE_ADDR']) AND $_SERVER['REMOTE_ADDR']!='127.0.0.1' ) {
|
2017-08-04 16:28:16 +02:00
|
|
|
$ipaddress = $_SERVER['REMOTE_ADDR'];
|
2018-04-09 09:42:03 +02:00
|
|
|
} elseif (!empty(getHostByName(getHostName()))){
|
|
|
|
$ipaddress = getHostByName(getHostName());
|
2017-08-04 16:28:16 +02:00
|
|
|
} else {
|
|
|
|
$ipaddress = 'UNKNOWN';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ipaddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Traduce il template semplificato in componenti HTML.
|
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
|
|
|
function translateTemplate()
|
|
|
|
{
|
|
|
|
global $id_module;
|
|
|
|
global $id_record;
|
|
|
|
global $id_plugin;
|
2017-09-18 16:55:19 +02:00
|
|
|
global $id_parent;
|
2017-09-15 16:37:19 +02:00
|
|
|
global $operations_log;
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
$template = ob_get_clean();
|
|
|
|
|
|
|
|
$template = \HTMLBuilder\HTMLBuilder::replace($template);
|
|
|
|
|
|
|
|
$template = str_replace('$id_module$', $id_module, $template);
|
|
|
|
$template = str_replace('$id_plugin$', $id_plugin, $template);
|
|
|
|
$template = str_replace('$id_record$', $id_record, $template);
|
2017-09-18 16:55:19 +02:00
|
|
|
$template = str_replace('$id_parent$', $id_parent, $template);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-15 15:52:40 +02:00
|
|
|
// Completamento delle informazioni estese sulle azioni dell'utente
|
2017-09-15 16:37:19 +02:00
|
|
|
if (Auth::check() && !empty($operations_log) && !empty($_SESSION['infos'])) {
|
2017-09-15 15:52:40 +02:00
|
|
|
$user = Auth::user();
|
2017-09-15 16:37:19 +02:00
|
|
|
$logger = Monolog\Registry::getInstance('logs');
|
2017-09-15 15:52:40 +02:00
|
|
|
|
|
|
|
foreach ($_SESSION['infos'] as $value) {
|
2017-09-15 16:37:19 +02:00
|
|
|
$logger->info($value.PHP_EOL.json_encode([
|
2017-09-15 15:52:40 +02:00
|
|
|
'user' => $user['username'],
|
2017-09-15 16:37:19 +02:00
|
|
|
]));
|
2017-09-15 15:52:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Annullo le notifiche (AJAX)
|
|
|
|
if (isAjaxRequest()) {
|
|
|
|
unset($_SESSION['infos']);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $template;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sostituisce la prima occorenza di una determinata stringa.
|
|
|
|
*
|
|
|
|
* @param string $str_pattern
|
|
|
|
* @param string $str_replacement
|
|
|
|
* @param string $string
|
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function str_replace_once($str_pattern, $str_replacement, $string)
|
|
|
|
{
|
|
|
|
if (strpos($string, $str_pattern) !== false) {
|
|
|
|
$occurrence = strpos($string, $str_pattern);
|
|
|
|
|
|
|
|
return substr_replace($string, $str_replacement, strpos($string, $str_pattern), strlen($str_pattern));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-09 09:42:03 +02:00
|
|
|
* Restituisce il percorso del filesystem in modo indipendente dal sistema operativo.
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
|
|
|
* @param string $string Percorso da correggere
|
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function slashes($string)
|
|
|
|
{
|
|
|
|
return str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $string);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepara il parametro inserito per l'inserimento in una query SQL.
|
|
|
|
* Attenzione: protezione di base contro SQL Injection.
|
|
|
|
*
|
|
|
|
* @param string $parameter
|
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function prepare($parameter)
|
|
|
|
{
|
|
|
|
return p($parameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepara il parametro inserito per l'inserimento in una query SQL.
|
|
|
|
* Attenzione: protezione di base contro SQL Injection.
|
|
|
|
*
|
|
|
|
* @param string $parameter
|
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function p($parameter)
|
|
|
|
{
|
|
|
|
return Database::getConnection()->prepare($parameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restituisce la traduzione del messaggio inserito.
|
|
|
|
*
|
|
|
|
* @param string $string
|
|
|
|
* @param array $parameters
|
|
|
|
* @param string $domain
|
|
|
|
* @param string $locale
|
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-09-10 14:35:41 +02:00
|
|
|
function tr($string, $parameters = [], $operations = [])
|
2017-08-04 16:28:16 +02:00
|
|
|
{
|
2017-09-10 14:35:41 +02:00
|
|
|
return Translator::translate($string, $parameters, $operations);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2017-09-10 14:35:41 +02:00
|
|
|
// Retrocompatibilità (con la funzione gettext)
|
2017-08-04 16:28:16 +02:00
|
|
|
if (!function_exists('_')) {
|
2017-09-10 14:35:41 +02:00
|
|
|
function _($string, $parameters = [], $operations = [])
|
2017-08-04 16:28:16 +02:00
|
|
|
{
|
2017-09-10 14:35:41 +02:00
|
|
|
return tr($string, $parameters, $operations);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Legge il valore di un'impostazione dalla tabella zz_settings.
|
|
|
|
* Se descrizione = 1 e il tipo è 'query=' mi restituisce il valore del campo descrizione della query.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param string $sezione
|
|
|
|
* @param string $descrizione
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function get_var($nome, $sezione = null, $descrizione = false, $again = false)
|
|
|
|
{
|
|
|
|
return Settings::get($nome, $sezione, $descrizione, $again);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-09 09:42:03 +02:00
|
|
|
* Restituisce il contenuto sanitarizzato dell'input dell'utente.
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
2018-04-09 09:42:03 +02:00
|
|
|
* @param string $param Nome del parametro
|
2017-08-04 16:28:16 +02:00
|
|
|
* @param string $rule Regola di filtraggio
|
2018-04-09 09:42:03 +02:00
|
|
|
* @param string $method Posizione del parametro (post o get)
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-09-04 12:12:48 +02:00
|
|
|
function filter($param, $method = null)
|
2017-08-04 16:28:16 +02:00
|
|
|
{
|
|
|
|
return Filter::getValue($param, $method = null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-09 09:42:03 +02:00
|
|
|
* Restituisce il contenuto sanitarizzato dell'input dell'utente.
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
2018-04-09 09:42:03 +02:00
|
|
|
* @param string $param Nome del parametro
|
2017-08-04 16:28:16 +02:00
|
|
|
* @param string $rule Regola di filtraggio
|
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function post($param, $rule = 'text')
|
|
|
|
{
|
|
|
|
return Filter::getValue($param, 'post');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-09 09:42:03 +02:00
|
|
|
* Restituisce il contenuto sanitarizzato dell'input dell'utente.
|
2017-08-04 16:28:16 +02:00
|
|
|
*
|
2018-04-09 09:42:03 +02:00
|
|
|
* @param string $param Nome del parametro
|
2017-08-04 16:28:16 +02:00
|
|
|
* @param string $rule Regola di filtraggio
|
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function get($param, $rule = 'text')
|
|
|
|
{
|
|
|
|
return Filter::getValue($param, 'get');
|
|
|
|
}
|
|
|
|
|
2017-09-04 12:12:48 +02:00
|
|
|
/**
|
|
|
|
* Controlla se è in corso una richiesta AJAX generata dal progetto.
|
|
|
|
*
|
2017-09-15 09:48:56 +02:00
|
|
|
* @since 2.3
|
|
|
|
*
|
2017-09-04 12:12:48 +02:00
|
|
|
* @return bool
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
function isAjaxRequest()
|
|
|
|
{
|
|
|
|
return \Whoops\Util\Misc::isAjaxRequest() && filter('ajax') !== null;
|
|
|
|
}
|
|
|
|
|
2017-09-04 12:12:48 +02:00
|
|
|
/**
|
|
|
|
* Esegue una somma precisa tra due interi/array.
|
|
|
|
*
|
|
|
|
* @param array|float $first
|
|
|
|
* @param array|float $second
|
|
|
|
* @param int $decimals
|
|
|
|
*
|
2017-09-15 09:48:56 +02:00
|
|
|
* @since 2.3
|
|
|
|
*
|
2017-09-04 12:12:48 +02:00
|
|
|
* @return float
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
function sum($first, $second = null, $decimals = null)
|
|
|
|
{
|
|
|
|
$first = (array) $first;
|
|
|
|
$second = (array) $second;
|
|
|
|
|
|
|
|
$array = array_merge($first, $second);
|
|
|
|
|
|
|
|
$result = 0;
|
|
|
|
|
|
|
|
if (!is_numeric($decimals)) {
|
2017-09-21 10:01:07 +02:00
|
|
|
$decimals = is_numeric($decimals) ? $decimals : Translator::getFormatter()->getPrecision();
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$bcadd = function_exists('bcadd');
|
|
|
|
|
|
|
|
foreach ($array as $value) {
|
2018-01-05 17:23:17 +01:00
|
|
|
$value = round($value, $decimals);
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
if ($bcadd) {
|
|
|
|
$result = bcadd($result, $value, $decimals);
|
|
|
|
} else {
|
2018-01-05 17:23:17 +01:00
|
|
|
$result += $value;
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-13 11:15:31 +02:00
|
|
|
return floatval($result);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2017-09-15 09:48:56 +02:00
|
|
|
/**
|
|
|
|
* Effettua le operazioni automatiche di redirect tra le pagine.
|
|
|
|
*
|
|
|
|
* @param int $id_module
|
|
|
|
* @param int $id_record
|
|
|
|
*
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
2017-09-08 13:24:48 +02:00
|
|
|
function redirectOperation($id_module, $id_record)
|
2017-09-07 16:54:58 +02:00
|
|
|
{
|
2017-09-07 16:51:14 +02:00
|
|
|
$backto = filter('backto');
|
2017-09-15 16:37:19 +02:00
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
// Scelta del redirect dopo un submit
|
|
|
|
if (!empty($backto)) {
|
|
|
|
$hash = filter('hash');
|
|
|
|
$hash = !starts_with($hash, '#') ? '#'.$hash : $hash;
|
2017-09-15 16:37:19 +02:00
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
if ($backto == 'record-edit') {
|
|
|
|
redirect(ROOTDIR.'/editor.php?id_module='.$id_module.'&id_record='.$id_record.$hash);
|
|
|
|
} elseif ($backto == 'record-list') {
|
|
|
|
redirect(ROOTDIR.'/controller.php?id_module='.$id_module.$hash);
|
|
|
|
}
|
2017-09-15 16:37:19 +02:00
|
|
|
|
|
|
|
exit();
|
2017-09-07 16:51:14 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-15 09:48:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Predispone un testo per l'inserimento all'interno di un attributo HTML.
|
|
|
|
*
|
|
|
|
* @param string $string
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function prepareToField($string)
|
|
|
|
{
|
|
|
|
return str_replace('"', '"', $string);
|
|
|
|
}
|
2017-09-15 16:52:59 +02:00
|
|
|
|
2017-11-14 17:42:09 +01:00
|
|
|
/**
|
2017-12-22 10:39:17 +01:00
|
|
|
* Restituisce se l'user-agent (browser web) è una versione mobile.
|
2017-11-14 17:42:09 +01:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-12-22 10:39:17 +01:00
|
|
|
function isMobile()
|
|
|
|
{
|
|
|
|
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER['HTTP_USER_AGENT']);
|
2017-11-14 17:42:09 +01:00
|
|
|
}
|
2017-12-22 11:44:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Restituisce il percorso derivante dal file in esecuzione.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function getURLPath()
|
|
|
|
{
|
|
|
|
$path = $_SERVER['SCRIPT_FILENAME'];
|
2018-01-03 13:24:04 +01:00
|
|
|
$prefix = rtrim($_SERVER['DOCUMENT_ROOT'], '/\\');
|
2017-12-22 11:44:27 +01:00
|
|
|
|
|
|
|
if (substr($path, 0, strlen($prefix)) == $prefix) {
|
|
|
|
$path = substr($path, strlen($prefix));
|
2017-12-31 16:00:23 +01:00
|
|
|
} else {
|
|
|
|
$path = str_replace(DOCROOT, ROOTDIR, $path);
|
2017-12-22 11:44:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return slashes($path);
|
|
|
|
}
|