1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2025-02-16 19:40:44 +01:00

Fix per PHP 5.4

Risoluzione di alcune problematiche relative all'inizializzazione del progetto con PHP 5.4 (test su Altervista).
This commit is contained in:
Thomas Zilio 2017-09-10 18:29:51 +02:00
parent 9c5625c3bb
commit b7eb048210
7 changed files with 41 additions and 76 deletions

View File

@ -36,7 +36,7 @@
"phpmailer/phpmailer": "^5.2", "phpmailer/phpmailer": "^5.2",
"spipu/html2pdf": "^5.0", "spipu/html2pdf": "^5.0",
"symfony/finder": "^3.3", "symfony/finder": "^3.3",
"symfony/translation": "^3.2" "symfony/translation": "^3.3"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@ -119,11 +119,12 @@ if (!empty($debugbarRenderer) && Auth::check()) {
echo $debugbarRenderer->renderHead(); echo $debugbarRenderer->renderHead();
} }
$hide_sidebar = get_var('Nascondere la barra sinistra di default');
echo ' echo '
</head> </head>
<body class="skin-'.$theme.(!empty(get_var('Nascondere la barra sinistra di default')) ? ' sidebar-collapse' : '').(!Auth::check() ? ' hold-transition login-page' : '').'"> <body class="skin-'.$theme.(!empty($hide_sidebar) ? ' sidebar-collapse' : '').(!Auth::check() ? ' hold-transition login-page' : '').'">
<div class="wrapper">'; <div class="wrapper">';
if (Auth::check()) { if (Auth::check()) {
@ -141,7 +142,7 @@ if (Auth::check()) {
<div id="mini-loader" style="display:none;"> <div id="mini-loader" style="display:none;">
<div></div> <div></div>
</div> </div>
<!-- Loader senza overlay --> <!-- Loader senza overlay -->
<div id="tiny-loader" style="display:none;"></div> <div id="tiny-loader" style="display:none;"></div>

View File

@ -61,8 +61,9 @@ class Filter
*/ */
public static function post($property) public static function post($property)
{ {
if (!empty(self::getPOST()) && isset(self::getPOST()[$property])) { $post = self::getPOST();
return self::getPOST()[$property]; if (!empty($post) && isset($post[$property])) {
return $post[$property];
} }
} }
@ -89,8 +90,9 @@ class Filter
*/ */
public static function get($property) public static function get($property)
{ {
if (!empty(self::getGET()) && isset(self::getGET()[$property])) { $get = self::getGET();
return self::getGET()[$property]; if (!empty($get) && isset($get[$property])) {
return $get[$property];
} }
} }
@ -111,7 +113,7 @@ class Filter
} else { } else {
$output = trim(self::getPurifier()->purify($input)); $output = trim(self::getPurifier()->purify($input));
if (!empty($output) && !empty(Translator::getLocaleFormatter())) { if (!empty($output)) {
if (Translator::getLocaleFormatter()->isNumber($output)) { if (Translator::getLocaleFormatter()->isNumber($output)) {
$output = Translator::numberToEnglish($output); $output = Translator::numberToEnglish($output);
} elseif (Translator::getLocaleFormatter()->isTimestamp($output)) { } elseif (Translator::getLocaleFormatter()->isTimestamp($output)) {

View File

@ -22,8 +22,9 @@ class FileLoader extends \Symfony\Component\Translation\Loader\FileLoader
$result = []; $result = [];
$extension = strtolower(pathinfo($resource, PATHINFO_EXTENSION)); $extension = strtolower(pathinfo($resource, PATHINFO_EXTENSION));
if (!empty($extension) && $extension != 'po' && !empty($this->getLoader($extension))) { $loader = $this->getLoader($extension);
$result = $this->getLoader($extension)->loadResource($resource); if (!empty($extension) && $extension != 'po' && !empty($loader)) {
$result = $loader->loadResource($resource);
if (!empty($this->include_filename)) { if (!empty($this->include_filename)) {
$result = array_combine( $result = array_combine(

View File

@ -22,22 +22,14 @@ class Translator extends Util\Singleton
public function __construct($default_locale = 'it', $fallback_locales = ['it']) public function __construct($default_locale = 'it', $fallback_locales = ['it'])
{ {
if (!empty($instance)) { $translator = new Symfony\Component\Translation\Translator($default_locale);
throw new Exception(); $this->locale = $default_locale;
} $translator->setFallbackLocales($fallback_locales);
if (version_compare(PHP_VERSION, '5.5.9') >= 0) { // Imposta la classe per il caricamento
$translator = new Symfony\Component\Translation\Translator($default_locale); $translator->addLoader('default', new Intl\FileLoader());
$this->locale = $default_locale;
$translator->setFallbackLocales($fallback_locales);
// Imposta la classe per il caricamento $this->translator = $translator;
$translator->addLoader('default', new Intl\FileLoader());
$this->translator = $translator;
}
$instance = $this;
} }
/** /**
@ -60,24 +52,22 @@ class Translator extends Util\Singleton
*/ */
protected function addLocales($path) protected function addLocales($path)
{ {
if (!empty($this->translator)) { // Individua i linguaggi disponibili
// Individua i linguaggi disponibili $dirs = glob($path.DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR);
$dirs = glob($path.DIRECTORY_SEPARATOR.'*', GLOB_ONLYDIR); foreach ($dirs as $dir) {
foreach ($dirs as $dir) { $this->addLocale(basename($dir));
$this->addLocale(basename($dir)); }
}
// Aggiunge le singole traduzioni // Aggiunge le singole traduzioni
foreach ($this->locales as $lang) { foreach ($this->locales as $lang) {
$done = []; $done = [];
$files = glob($path.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.'*.*'); $files = glob($path.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.'*.*');
foreach ($files as $file) { foreach ($files as $file) {
if (!in_array(basename($file), $done)) { if (!in_array(basename($file), $done)) {
$this->translator->addResource('default', $file, $lang); $this->translator->addResource('default', $file, $lang);
$done[] = basename($file); $done[] = basename($file);
}
} }
} }
} }
@ -125,9 +115,7 @@ class Translator extends Util\Singleton
public function setLocale($locale) public function setLocale($locale)
{ {
if (!empty($locale) && $this->isLocaleAvailable($locale)) { if (!empty($locale) && $this->isLocaleAvailable($locale)) {
if (!empty($this->translator)) { $this->translator->setLocale($locale);
$this->translator->setLocale($locale);
}
$this->locale = $locale; $this->locale = $locale;
} }
} }
@ -164,14 +152,7 @@ class Translator extends Util\Singleton
*/ */
public static function translate($string, $parameters = [], $operations = []) public static function translate($string, $parameters = [], $operations = [])
{ {
$translator = self::getInstance()->getTranslator(); $result = self::getInstance()->getTranslator()->trans($string, $parameters);
$result = !empty($translator) ? $translator->trans($string, $parameters) : $string;
// Sostituzione di default nel caso il traduttore non sia supportato
if (empty($translator)) {
$result = str_replace(array_keys($operations), array_values($operations), $result);
}
// Operazioni aggiuntive sul risultato // Operazioni aggiuntive sul risultato
if (!empty($operations)) { if (!empty($operations)) {

View File

@ -125,9 +125,9 @@ class Update
*/ */
public static function getUpdate() public static function getUpdate()
{ {
if (!empty(self::getTodos())) { $todos = self::getTodos();
return self::getTodos()[0];
} return !empty($todos) ? $todos()[0] : null;
} }
/** /**
@ -149,7 +149,9 @@ class Update
*/ */
public static function isUpdateAvailable() public static function isUpdateAvailable()
{ {
return !empty(self::getTodos()); $todos = self::getTodos();
return !empty($todos);
} }
/** /**

View File

@ -2,28 +2,6 @@
use Stringy\Stringy as S; use Stringy\Stringy as S;
if (!function_exists('parse_ini_string')) {
/**
* Simulazione di "parse_ini_string".
*
* @param unknown $ini
* @param string $process_sections
* @param unknown $scanner_mode
*/
function parse_ini_string($ini, $process_sections = false, $scanner_mode = null)
{
// Generate a temporary file.
$tempname = tempnam('/tmp', 'ini');
$fp = fopen($tempname, 'w');
fwrite($fp, $ini);
$ini = parse_ini_file($tempname, !empty($process_sections));
fclose($fp);
@unlink($tempname);
return $ini;
}
}
if (!function_exists('array_column')) { if (!function_exists('array_column')) {
/** /**
* Pluck an array of values from an array. * Pluck an array of values from an array.