Initial support for option caching and htaccess

This commit is contained in:
Matteo Gheza 2020-09-26 14:33:33 +02:00
parent 69eb83fcfb
commit 0e0300f9ea
3 changed files with 67 additions and 3 deletions

5
.gitignore vendored
View File

@ -511,4 +511,7 @@ config.old.php
*password*
custom-*.*
custom-*.*
*.log
*.txt

39
server/.htaccess Normal file
View File

@ -0,0 +1,39 @@
<IfModule mod_php4.c>
php_flag display_errors Off
</IfModule>
<IfModule mod_php5.c>
php_flag display_errors Off
</IfModule>
<IfModule mod_php7.c>
php_flag display_errors Off
</IfModule>
<IfModule mod_autoindex.c>
Options -Indexes
</IfModule>
<IfModule mod_headers.c>
Header unset X-Powered-By
Header unset X-Pingback
Header unset SERVER
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|DELETE|TRACK) [NC]
RewriteRule ^(.*)$ - [F,L]
</IfModule>
<FilesMatch "(config|config.old|config-sample|core|ui)\.php">
Order Deny,Allow
Deny from all
</FilesMatch>
<FilesMatch "\.(log|txt)$">
Order Allow,Deny
Deny from all
</FilesMatch>
ServerSignature Off

View File

@ -171,6 +171,9 @@ class database{
public $connection = null;
public $query = null;
public $stmt = null;
public $load_from_file = true;
public $options = [];
public $options_cache_file = null;
public function connect(){
try {
@ -196,6 +199,20 @@ class database{
if($this->isOptionsEmpty()){
header('Location: install/install.php');
}
$file_infos = pathinfo(array_reverse(debug_backtrace())[0]['file']);
if(strpos($file_infos['dirname'], 'risorse') !== false) {
$this->options_cache_file = "../../options.txt";
} else {
$this->options_cache_file = "options.txt";
}
if($this->load_from_file){
if(file_exists($this->options_cache_file)){
$this->options = unserialize(file_get_contents($this->options_cache_file), ['allowed_classes' => false]);
} else {
$this->options = $this->exec("SELECT * FROM `%PREFIX%_options` WHERE `enabled` = 1", true);
file_put_contents($this->options_cache_file, serialize( $this->options ));
}
}
}
public function close(){
@ -246,8 +263,13 @@ class database{
if(defined($name)){
return constant($name);
} else {
$option = $this->exec("SELECT `value` FROM `%PREFIX%_options` WHERE `name` = :name AND `enabled` = 1;", true, [":name" => $name]);
return empty($option) ? "" : $option[0]["value"];
//$option = $this->exec("SELECT `value` FROM `%PREFIX%_options` WHERE `name` = :name AND `enabled` = 1;", true, [":name" => $name]);
//return empty($option) ? "" : $option[0]["value"];
foreach($this->options as $option){
if($name == $option["name"]){
return empty($option["value"]) ? "" : $option["value"];
}
}
}
}