DB force language, typo, HTMLPurifier tmp, tracy

This commit is contained in:
Matteo Gheza 2020-12-31 00:03:19 +01:00
parent c650e561cf
commit 23b5573234
8 changed files with 37 additions and 30 deletions

View File

@ -124,6 +124,7 @@ class tools
public function sanitize($string, $htmlAllowed=false, $htmlPurifierOptions=[])
{
$this->profiler_start("Sanitize");
$htmlAllowed=false; //TODO: fix HTMLPurifier_Config
if($htmlAllowed) {
$config = HTMLPurifier_Config::createDefault();
foreach ($htmlPurifierOptions as $key => $value) {
@ -157,6 +158,18 @@ class tools
Profiler::finish($name);
}
}
public function ajax_page_response($response){
$json_response = json_encode($response);
$response_data = substr(crc32($json_response), 0, 10);
header("data: ".$response_data);
header("Content-type: application/json");
if(isset($_GET["old_data"]) && $_GET["old_data"] !== $response_data){
print($json_response);
} else {
print("{}");
}
}
}
class database
@ -273,6 +286,7 @@ class database
return empty($option["value"]) ? false : $option["value"];
}
}
return false;
}
}
@ -667,11 +681,13 @@ class translations
}
}
public function __construct()
public function __construct($force_language)
{
$this->client_languages = $this->client_languages();
if(isset($_COOKIE["forceLanguage"]) && in_array($_COOKIE["forceLanguage"], $this->loaded_languages)){
$this->language = $_COOKIE["forceLanguage"];
} else if($force_language && in_array($force_language, $this->loaded_languages)){
$this->language = $force_language;
} else {
foreach($this->client_languages as $language){
if(in_array($language, $this->loaded_languages) && $this->language == null) {
@ -722,7 +738,7 @@ function init_class($enableDebugger=true, $headers=true)
$database = new database();
$tools = new tools($database->getOption("check_cf_ip"), $enableDebugger);
$user = new user($database, $tools);
$translations = new translations();
$translations = new translations($database->getOption("force_language"));
}
if($headers) {
$csp = "default-src 'self' data: *.tile.openstreetmap.org nominatim.openstreetmap.org; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' data: *.tile.openstreetmap.org; object-src; style-src 'self' 'unsafe-inline'; require-trusted-types-for 'style';";
@ -736,14 +752,15 @@ function init_class($enableDebugger=true, $headers=true)
}
//var_dump($user);
//exit();
if($enableDebugger) {
if($user->requireRole(Role::DEVELOPER)) {
Debugger::enable(Debugger::DEVELOPMENT, __DIR__ . '/error-log');
Profiler::enable();
Debugger::getBar()->addPanel(new Netpromotion\Profiler\Adapter\TracyBarAdapter());
} else {
Debugger::enable(Debugger::PRODUCTION, __DIR__ . '/error-log');
}
if($user->requireRole(Role::DEVELOPER)) {
Debugger::enable(Debugger::DEVELOPMENT, __DIR__ . '/error-log');
if($enableDebugger) Profiler::enable();
Debugger::getBar()->addPanel(new Netpromotion\Profiler\Adapter\TracyBarAdapter());
} else {
Debugger::enable(Debugger::PRODUCTION, __DIR__ . '/error-log');
}
if(!$enableDebugger) {
Debugger::$showBar = false;
}
bdump(get_included_files());
bdump($translations->loaded_translations);

View File

@ -474,7 +474,8 @@ function initOptions($name, $visible, $developer, $password, $report_email, $own
'service_remove' => 1,
'training_edit' => 1,
'training_remove' => 1,
'use_location_picker' => 1
'use_location_picker' => 1,
'force_language' => 0
];
$query = "";
foreach ($options as $key => $value) {

View File

@ -46,7 +46,7 @@ foreach($risultato as $row){
!empty($row['phone_number']) ? "<a href='https://api.whatsapp.com/send?phone=".$row['phone_number']."&text=ALLERTA IN CORSO.%20Mettiti%20in%20contatto%20con%20$name_encoded'><i class='fa fa-whatsapp' style='color:green'></i></a>" : "",
$row['services'],
$row['availability_minutes'],
"<a href='user_details.php?user=".$row['id']."'><p>".t("Altri dettagli", false)."</p></a>"
//"<a href='user_details.php?user=".$row['id']."'><p>".t("Altri dettagli", false)."</p></a>" TODO: fix "Other" page
];
} else {
$name = $user->nameById($row["id"]);
@ -61,13 +61,5 @@ foreach($risultato as $row){
}
}
}
$json_response = json_encode($response);
$response_data = substr(base64_encode($json_response), 0, 5);
header("data: ".$response_data);
header("Content-type: application/json");
if(isset($_GET["old_data"]) && $_GET["old_data"] !== $response_data){
print($json_response);
} else {
print("{}");
}
$tools->ajax_page_response($response);
?>

View File

@ -29,6 +29,5 @@ foreach($risultato as $row){
];
}
}
header("Content-type: application/json");
print(json_encode($response));
$tools->ajax_page_response($response);
?>

View File

@ -36,6 +36,5 @@ foreach($risultato as $row){
$database->getOption("service_remove") ? "<a class='pjax_disable' href='edit_service.php?delete&id={$row['id']}&increment={$row['increment']}'><i style='font-size: 40px' class='fa fa-trash'></i></a>" : null
];
}
header("Content-type: application/json");
print(json_encode($response));
$tools->ajax_page_response($response);
?>

View File

@ -28,6 +28,5 @@ foreach($risultato as $row){
$database->getOption("training_remove") ? "<a class='pjax_disable' href='edit_training.php?delete&id={$row['id']}&increment={$row['increment']}'><i style='font-size: 40px' class='fa fa-trash'></i></a>" : null
];
}
header("Content-type: application/json");
print(json_encode($response));
$tools->ajax_page_response($response);
?>

View File

@ -70,7 +70,7 @@
<th>{{ 'Write'|t }}</th>
<th>{{ 'Services'|t }}</th>
<th>{{ 'Availability Minutes'|t }}</th>
<th>{{ 'Other'|t }}</th>
<!-- <th>{{ 'Other'|t }}</th> TODO: fix "Other" page -->
{% endif %}
</tr>
</thead>
@ -84,7 +84,7 @@
<br><br>
<p style="text-align: center;">
<a id='add' href="edit_user.php?add">{{ 'Add user'|t }}</a>
<a class='pjax_disable' id='add' href="edit_user.php?add">{{ 'Add user'|t }}</a>
</p>
<br>
<br>

View File

@ -39,7 +39,7 @@ return [
"Availability Minutes" => "Minuti di Disponibilità",
"This month" => "Questo mese",
"Call" => "Chiama",
"Write" => "scrivi",
"Write" => "Scrivi",
"Other" => "Altro",
"Others infos" => "Altri dettagli",
"Add user" => "Aggiungi utente",