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",
"spipu/html2pdf": "^5.0",
"symfony/finder": "^3.3",
"symfony/translation": "^3.2"
"symfony/translation": "^3.3"
},
"autoload": {
"psr-4": {

View File

@ -119,11 +119,12 @@ if (!empty($debugbarRenderer) && Auth::check()) {
echo $debugbarRenderer->renderHead();
}
$hide_sidebar = get_var('Nascondere la barra sinistra di default');
echo '
</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">';
if (Auth::check()) {
@ -141,7 +142,7 @@ if (Auth::check()) {
<div id="mini-loader" style="display:none;">
<div></div>
</div>
<!-- Loader senza overlay -->
<div id="tiny-loader" style="display:none;"></div>

View File

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

View File

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

View File

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

View File

@ -125,9 +125,9 @@ class Update
*/
public static function getUpdate()
{
if (!empty(self::getTodos())) {
return self::getTodos()[0];
}
$todos = self::getTodos();
return !empty($todos) ? $todos()[0] : null;
}
/**
@ -149,7 +149,9 @@ class Update
*/
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;
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')) {
/**
* Pluck an array of values from an array.