2018-09-10 14:53:00 +08:00
|
|
|
<?php
|
|
|
|
class Option {
|
|
|
|
|
|
|
|
public $options;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$db = Config::MySQL();
|
|
|
|
$conn = mysqli_connect($db['host'], $db['user'], $db['pass'], $db['name'], $db['port']);
|
2018-10-19 18:39:25 +08:00
|
|
|
mysqli_query($conn, "set names 'utf8mb4'");
|
2018-09-10 14:53:00 +08:00
|
|
|
$rs = mysqli_query($conn, "SELECT * FROM `{$db['name']}`.`option`");
|
|
|
|
while($rw = mysqli_fetch_row($rs)) {
|
|
|
|
$this->options[$rw[1]] = $rw[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOption($name) {
|
|
|
|
if(preg_match("/^[A-Za-z0-9\-\_]+$/", $name)) {
|
|
|
|
if(isset($this->options[$name])) {
|
|
|
|
return $this->options[$name];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 18:39:25 +08:00
|
|
|
public function saveConfig($SiteName, $Description, $Theme, $Lang) {
|
2018-09-10 14:53:00 +08:00
|
|
|
$db = Config::MySQL();
|
|
|
|
$conn = mysqli_connect($db['host'], $db['user'], $db['pass'], $db['name'], $db['port']);
|
2018-10-19 18:39:25 +08:00
|
|
|
mysqli_query($conn, "set names 'utf8mb4'");
|
2018-09-10 14:53:00 +08:00
|
|
|
mysqli_query($conn, "UPDATE `{$db['name']}`.`option` SET `value`='{$SiteName}' WHERE `key`='SiteName'");
|
|
|
|
mysqli_query($conn, "UPDATE `{$db['name']}`.`option` SET `value`='{$Description}' WHERE `key`='Description'");
|
|
|
|
mysqli_query($conn, "UPDATE `{$db['name']}`.`option` SET `value`='{$Theme}' WHERE `key`='Theme'");
|
2018-10-19 18:39:25 +08:00
|
|
|
mysqli_query($conn, "UPDATE `{$db['name']}`.`option` SET `value`='{$Lang}' WHERE `key`='Lang'");
|
2018-09-10 14:53:00 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateOption($key, $value) {
|
|
|
|
$db = Config::MySQL();
|
|
|
|
$conn = mysqli_connect($db['host'], $db['user'], $db['pass'], $db['name'], $db['port']);
|
2018-10-19 18:39:25 +08:00
|
|
|
mysqli_query($conn, "set names 'utf8mb4'");
|
2018-09-10 14:53:00 +08:00
|
|
|
mysqli_query($conn, "UPDATE `{$db['name']}`.`option` SET `value`='{$value}' WHERE `key`='{$key}'");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|