46 lines
No EOL
1.3 KiB
PHP
46 lines
No EOL
1.3 KiB
PHP
<?php
|
|
|
|
require_once("Database.class.php");
|
|
|
|
class Setting {
|
|
private $settingKey = "";
|
|
|
|
public function __construct($setting_key)
|
|
{
|
|
$this->settingKey = Database::escape_string($setting_key);
|
|
}
|
|
|
|
public function get($default="", $set=false)
|
|
{
|
|
$query = "SELECT `setting_value` FROM `settings` WHERE `setting_key` = '" . $this->settingKey . "';";
|
|
$result = Database::execute_query($query);
|
|
if ($result->num_rows == 1) {
|
|
return $result->fetch_assoc()["setting_value"];
|
|
} else {
|
|
if (!empty($default)) {
|
|
if ($set) {
|
|
$this->set($default);
|
|
}
|
|
return $default;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public function set($value)
|
|
{
|
|
$escaped_value = Database::escape_string($value);
|
|
|
|
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 . "');";
|
|
}
|
|
|
|
if (!Database::execute_query($query)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
} |