From 2430ddd0b623501a497df50505081b64355c1ae7 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Mon, 22 Feb 2021 16:17:05 +0100 Subject: [PATCH] Correzioni JS per utilizzo nuovi controller --- assets/src/js/functions/functions.js | 7 +-- assets/src/js/functions/hooks.js | 84 ++++++++++++---------------- controller.php | 2 +- core.php | 40 +------------ editor.php | 2 +- include/top.php | 18 ++++++ src/Permissions.php | 2 +- 7 files changed, 60 insertions(+), 95 deletions(-) diff --git a/assets/src/js/functions/functions.js b/assets/src/js/functions/functions.js index 94099c1f6..12b440103 100755 --- a/assets/src/js/functions/functions.js +++ b/assets/src/js/functions/functions.js @@ -371,12 +371,9 @@ function getCookie(cname) { */ function renderMessages() { $.ajax({ - url: globals.rootdir + '/ajax.php', - type: 'get', + url: globals.urls.messages, + type: 'GET', dataType: 'JSON', - data: { - op: 'flash', - }, success: function (messages) { let info = messages.info ? messages.info : []; info.forEach(function (element) { diff --git a/assets/src/js/functions/hooks.js b/assets/src/js/functions/hooks.js index df3fa0902..e063b388d 100755 --- a/assets/src/js/functions/hooks.js +++ b/assets/src/js/functions/hooks.js @@ -21,14 +21,10 @@ */ function startHooks() { $.ajax({ - url: globals.rootdir + "/ajax.php", - type: "get", - data: { - op: "hooks", - }, - success: function (data) { - hooks = JSON.parse(data); - + url: globals.urls.hooks.list, + type: 'GET', + dataType: 'JSON', + success: function (hooks) { $("#hooks-header").text(globals.translations.hooksExecuting); $("#hooks-number").text(hooks.length); @@ -54,18 +50,15 @@ function startHooks() { * Richiama l'hook per l'esecuzione. * * @param hook + * @param init */ function startHook(hook, init) { $.ajax({ - url: globals.rootdir + "/ajax.php", - type: "get", - data: { - op: "hook-lock", - id: hook.id, - }, - success: function (data) { - var token = JSON.parse(data); - + url: globals.urls.hooks.lock + .replace('|id|', hook.id), + type: 'GET', + dataType: 'JSON', + success: function (token) { if (init) { hookCount("#hooks-counter"); @@ -75,7 +68,7 @@ function startHook(hook, init) { if (token) { executeHook(hook, token); } else { - var timeout = 10; + let timeout = 10; setTimeout(function () { startHook(hook); @@ -93,18 +86,15 @@ function startHook(hook, init) { */ function executeHook(hook, token) { $.ajax({ - url: globals.rootdir + "/ajax.php", - type: "get", - data: { - op: "hook-execute", - id: hook.id, - token: token, - }, - success: function (data) { - var result = JSON.parse(data); + url: globals.urls.hooks.execute + .replace('|id|', hook.id) + .replace('|token|', token), + type: 'GET', + dataType: 'JSON', + success: function (result) { updateHook(hook); - var timeout; + let timeout; if (result.execute) { startHook(hook); } else { @@ -122,23 +112,19 @@ function executeHook(hook, token) { * Aggiorna le informazioni dell'hook. * * @param hook - * @param init */ function updateHook(hook) { $.ajax({ - url: globals.rootdir + "/ajax.php", - type: "get", - data: { - op: "hook-response", - id: hook.id, - }, - success: function (data) { - var result = JSON.parse(data); + url: globals.urls.hooks.response + .replace('|id|', hook.id), + type: 'GET', + dataType: 'JSON', + success: function (result) { renderHook(hook, result); // Rimozione eventuale della rotella di caricamento - var counter = $("#hooks-counter").text(); - var number = $("#hooks > li").length; + let counter = $("#hooks-counter").text(); + let number = $("#hooks > li").length; if (number == 0) { $("#hooks-notified").html(''); @@ -153,7 +139,7 @@ function updateHook(hook) { if (counter == $("#hooks-number").text()) { $("#hooks-loading").hide(); - var hookMessage; + let hookMessage; if (number > 1) { hookMessage = globals.translations.hookMultiple.replace('_NUM_', number); } else if (number == 1) { @@ -174,8 +160,8 @@ function updateHook(hook) { function hookCount(id, value) { value = value ? value : 1; - var element = $(id); - var number = parseInt(element.text()); + let element = $(id); + let number = parseInt(element.text()); number = isNaN(number) ? 0 : number; number += value; @@ -187,16 +173,16 @@ function hookCount(id, value) { /** * Genera l'HTML per la visualizzazione degli hook. * - * @param element_id + * @param hook * @param result */ function renderHook(hook, result) { if (result.length == 0) return; - var element_id = "hook-" + hook.id; + let element_id = "hook-" + hook.id; // Inizializzazione - var element = $("#" + element_id); + let element = $("#" + element_id); if (element.length == 0) { $("#hooks").append('
  • '); @@ -211,12 +197,12 @@ function renderHook(hook, result) { } // Contenuto - var content = ' ' + result.message + ''; + let content = ' ' + result.message + ''; if (result.progress) { - var current = result.progress.current; - var total = result.progress.total; - var percentage = current / total * 100; + let current = result.progress.current; + let total = result.progress.total; + let percentage = current / total * 100; percentage = isNaN(percentage) ? 100 : percentage; percentage = Math.round(percentage * 100) / 100; diff --git a/controller.php b/controller.php index bd4eed5f7..942b7fb06 100755 --- a/controller.php +++ b/controller.php @@ -22,7 +22,7 @@ include_once __DIR__.'/core.php'; if (!empty($id_record) && !empty($id_module)) { redirect_legacy(base_url().'/editor.php?id_module='.$id_module.'&id_record='.$id_record); } elseif (empty($id_module)) { - redirect_legacy(base_url().'/index.php'); + redirect_legacy(base_url().'/'); } include_once AppLegacy::filepath('include|custom|', 'top.php'); diff --git a/core.php b/core.php index 8136aa9d9..3cd928219 100755 --- a/core.php +++ b/core.php @@ -44,16 +44,6 @@ ini_set('session.use_only_cookies', '1'); session_set_cookie_params(0, base_url(), null, isHTTPS(true)); session_start();*/ -// Lettura della configurazione -$config = AppLegacy::getConfig(); - -// Redirect al percorso HTTPS se impostato nella configurazione -if (!empty($config['redirectHTTPS']) && !isHTTPS(true)) { - header('HTTP/1.1 301 Moved Permanently'); - header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); - throw new \App\Exceptions\LegacyExitException(); -} - /* GESTIONE DEGLI ERRORI */ // Logger per la segnalazione degli errori $logger = new Monolog\Logger('Logs'); @@ -137,12 +127,6 @@ $handler->registerFatalHandler(Monolog\Logger::ERROR); $dbo = $database = database(); /* INTERNAZIONALIZZAZIONE */ -// Istanziamento del gestore delle traduzioni del progetto -$lang = !empty($config['lang']) ? $config['lang'] : (isset($_GET['lang']) ? $_GET['lang'] : null); -$formatter = !empty($config['formatter']) ? $config['formatter'] : []; -//$translator->addLocalePath(base_dir().'/locale'); -//$translator->addLocalePath(base_dir().'/modules/*/locale'); -//$translator->setLocale($lang, $formatter); // Individuazione di versione e revisione del progetto $version = Update::getVersion(); @@ -161,7 +145,7 @@ if (!$continue && getURLPath() != slashes(base_url().'/index.php') && !Permissio auth()->logout(); } - redirect_legacy(base_url().'/index.php'); + redirect_legacy(base_url().'/'); throw new \App\Exceptions\LegacyExitException(); } @@ -171,26 +155,6 @@ if (!$api_request) { // Impostazioni di Content-Type e Charset Header header('Content-Type: text/html; charset=UTF-8'); - // Controllo CSRF - if (empty($config['disableCSRF'])) { - //csrfProtector::init(); - } - - // Aggiunta del wrapper personalizzato per la generazione degli input - if (!empty($config['HTMLWrapper'])) { - HTMLBuilder\HTMLBuilder::setWrapper($config['HTMLWrapper']); - } - - // Aggiunta dei gestori personalizzati per la generazione degli input - foreach ((array) $config['HTMLHandlers'] as $key => $value) { - HTMLBuilder\HTMLBuilder::setHandler($key, $value); - } - - // Aggiunta dei gestori per componenti personalizzate - foreach ((array) $config['HTMLManagers'] as $key => $value) { - HTMLBuilder\HTMLBuilder::setManager($key, $value); - } - // Registrazione globale del template per gli input HTML ob_start(); @@ -200,7 +164,7 @@ if (!$api_request) { session(['errors' => isset($_SESSION['errors']) ? array_unique($_SESSION['errors']) : []]); // Impostazione del tema grafico di default - $theme = !empty($config['theme']) ? $config['theme'] : 'default'; + $theme = 'default'; if ($continue) { // Periodo di visualizzazione dei record diff --git a/editor.php b/editor.php index 063d69da6..6d0df7728 100755 --- a/editor.php +++ b/editor.php @@ -27,7 +27,7 @@ $read_only = $structure->permission == 'r'; if (empty($id_record) && !empty($id_module) && empty($id_plugin)) { redirect_legacy(base_url().'/controller.php?id_module='.$id_module); } elseif (empty($id_record) && empty($id_module) && empty($id_plugin)) { - redirect_legacy(base_url().'/index.php'); + redirect_legacy(base_url().'/'); } include_once AppLegacy::filepath('include|custom|', 'top.php'); diff --git a/include/top.php b/include/top.php index 3950f91e6..82be2d273 100755 --- a/include/top.php +++ b/include/top.php @@ -178,7 +178,9 @@ if (auth()->check()) { }, }, }; + globals = { + content_was_modified: false, rootdir: "'.base_url().'", js: "'.$paths['js'].'", css: "'.$paths['css'].'", @@ -235,12 +237,28 @@ if (auth()->check()) { dataload_page_buffer: '.setting('Lunghezza in pagine del buffer Datatables').', tempo_attesa_ricerche: '.setting('Tempo di attesa ricerche in secondi').', restrict_summables_to_selected: '.setting('Totali delle tabelle ristretti alla selezione').', + + urls: { + select: "'.route('ajax-select').'", + dataload: "'.route('ajax-dataload', ['module_id' => '|module_id|']).'", + dataload_plugin: "'.route('ajax-dataload', ['module_id' => '|module_id|', 'reference_id' => '|reference_id|']).'", + ajax_set: "'.route('ajax-session').'", + ajax_array_set: "'.route('ajax-session-array').'", + messages: "'.route('messages').'", + hooks: { + list: "'.route('hooks').'", + lock: "'.route('hook-lock', ['hook_id' => '|id|']).'", + execute: "'.route('hook-execute', ['hook_id' => '|id|', 'token' => '|token|']).'", + response: "'.route('hook-response', ['hook_id' => '|id|']).'", + } + } }; '; } else { echo '