|
<?php defined('SYSPATH') or die('No direct script access.');
|
|
|
|
class Settings
|
|
{
|
|
private static $db = NULL;
|
|
|
|
// variable for cache
|
|
private static $cache = array();
|
|
|
|
// setting up default value of some variables
|
|
|
|
private static $title = 'FreeNetIS';
|
|
private static $db_schema_version = 0;
|
|
private static $currency = 'CZK';
|
|
private static $self_registration = 1;
|
|
private static $use_javascript = 1;
|
|
private static $index_page = 1;
|
|
private static $email_default_email = 'no-reply@freenetis.org';
|
|
private static $upload_directory = 'upload';
|
|
private static $upload_remove_spaces = 1;
|
|
private static $upload_create_directories = 1;
|
|
|
|
// email settings
|
|
private static $email_driver = 'native';
|
|
private static $email_port = 25;
|
|
|
|
// ulogd settings
|
|
|
|
private static $ulogd_enabled = 1;
|
|
|
|
// time of last update of ulogd
|
|
private static $ulogd_update_last = 0;
|
|
|
|
// interval of updating of ulogd (in seconds), default 1800s = 30 minutes
|
|
private static $ulogd_update_interval = 1800;
|
|
|
|
// count of the most traffic-active members to find, default 10% of members
|
|
private static $ulogd_active_count = '10%';
|
|
|
|
// type of traffic of members to find, default download traffic
|
|
private static $ulogd_active_type = 'download';
|
|
|
|
private static $allowed_subnets_enabled = 1;
|
|
|
|
// time of last update of allowed subnets
|
|
private static $allowed_subnets_update_last = 0;
|
|
|
|
// interval of updating of allowed subnets, default 60s
|
|
private static $allowed_subnets_update_interval = 60;
|
|
|
|
// default count of allowed subnets
|
|
private static $allowed_subnets_default_count = 1;
|
|
|
|
/**
|
|
* @author Michal Kliment
|
|
* Function to get value from settings by given key
|
|
* @param string $key Key of settings to find
|
|
* @return string Value from settings
|
|
*/
|
|
public static function get($key, $cache = TRUE)
|
|
{
|
|
// not connected? connect!
|
|
if (!self::$db)
|
|
self::$db = new Config_Model();
|
|
|
|
// if cache is enabled, return it from it
|
|
if ($cache && isset (self::$cache[$key]))
|
|
return self::$cache[$key];
|
|
|
|
try // try if query return exception, for example config table doesn't exist
|
|
{
|
|
$value = self::$db->get_value_from_name($key);
|
|
}
|
|
catch (Kohana_Database_Exception $e)
|
|
{
|
|
$value = '';
|
|
}
|
|
|
|
// if we find not-null value, return it
|
|
if ($value!='')
|
|
self::$cache[$key] = $value;
|
|
// else return property
|
|
else if (isset(self::$$key))
|
|
self::$cache[$key] = self::$$key;
|
|
else
|
|
// in worst return value from config (from config.php)
|
|
self::$cache[$key] = Config::get($key);
|
|
|
|
return self::$cache[$key];
|
|
}
|
|
|
|
/**
|
|
* @author Michal Kliment
|
|
* Function to set up given value to given key
|
|
* @param string $key Key to set up
|
|
* @param string $value Value to set up to key
|
|
* @return boolean
|
|
*/
|
|
public static function set($key, $value)
|
|
{
|
|
// not connected? connect!
|
|
if (!self::$db)
|
|
self::$db = new Config_Model();
|
|
|
|
try // try if query return exception, for example config table doesn't exist
|
|
{
|
|
$exists = self::$db->check_exist_variable($key);
|
|
}
|
|
catch (Kohana_Database_Exception $e)
|
|
{
|
|
// database error, end
|
|
return False;
|
|
}
|
|
|
|
// key already exists, update it
|
|
if ($exists)
|
|
{
|
|
return self::$db->update_variable($key, $value);
|
|
}
|
|
// key doesn't exist, create it
|
|
else
|
|
{
|
|
return self::$db->insert_variable($key, $value);
|
|
}
|
|
}
|
|
|
|
|
|
}
|