2020-08-02 12:07:03 +00:00
|
|
|
<?php
|
|
|
|
|
2020-08-05 05:51:29 +00:00
|
|
|
require_once("Connection.class.php");
|
2020-08-02 12:07:03 +00:00
|
|
|
|
|
|
|
class Setting {
|
2020-08-05 05:51:29 +00:00
|
|
|
private $connection = null;
|
2020-08-02 12:07:03 +00:00
|
|
|
private $settingKey = "";
|
|
|
|
|
|
|
|
public function __construct($setting_key)
|
|
|
|
{
|
2020-08-05 05:51:29 +00:00
|
|
|
$this->connection = new Connection();
|
|
|
|
$this->settingKey = $this->connection->escape($setting_key);
|
2020-08-02 12:07:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function get($default="")
|
|
|
|
{
|
|
|
|
$query = "SELECT `setting_value` FROM `settings` WHERE `setting_key` = '" . $this->settingKey . "';";
|
2020-08-05 05:51:29 +00:00
|
|
|
$result = $this->connection->query($query);
|
2020-08-02 12:07:03 +00:00
|
|
|
if ($result->num_rows == 1) {
|
|
|
|
return $result->fetch_assoc()["setting_key"];
|
|
|
|
} else {
|
|
|
|
if (!empty($default)) {
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function set($value)
|
|
|
|
{
|
2020-08-05 05:51:29 +00:00
|
|
|
$escaped_value = $this->connection->escape($value);
|
2020-08-02 12:07:03 +00:00
|
|
|
|
|
|
|
if ($this->get()) {
|
|
|
|
$query = "UPDATE `settings` SET `setting_value` = '" . $escaped_value . "' WHERE `setting_key` = '" . $this->settingKey . "';";
|
|
|
|
} else {
|
|
|
|
$query = "INSERT INTO `settings` (`setting_key`, `setting_value`) VALUES ('". $this->settingKey . "', '" . $escaped_value . "');";
|
|
|
|
}
|
|
|
|
|
2020-08-05 05:51:29 +00:00
|
|
|
if (!$this->connection->query($query)) {
|
|
|
|
return false;
|
2020-08-02 12:07:03 +00:00
|
|
|
}
|
2020-08-05 05:51:29 +00:00
|
|
|
|
|
|
|
return true;
|
2020-08-02 12:07:03 +00:00
|
|
|
}
|
|
|
|
}
|