mirror of
				https://github.com/Mibew/design.git
				synced 2025-11-04 12:25:19 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			169 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			169 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
/*
 | 
						|
 * Copyright 2005-2013 the original author or authors.
 | 
						|
 *
 | 
						|
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
						|
 * you may not use this file except in compliance with the License.
 | 
						|
 * You may obtain a copy of the License at
 | 
						|
 *
 | 
						|
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
						|
 *
 | 
						|
 * Unless required by applicable law or agreed to in writing, software
 | 
						|
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
						|
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
						|
 * See the License for the specific language governing permissions and
 | 
						|
 * limitations under the License.
 | 
						|
 */
 | 
						|
 | 
						|
/**
 | 
						|
 * Encapsulates work with system settings.
 | 
						|
 */
 | 
						|
Class Settings {
 | 
						|
 | 
						|
	/**
 | 
						|
	 * An instance of Settings class
 | 
						|
	 * @var Settings
 | 
						|
	 */
 | 
						|
	protected static $instance = null;
 | 
						|
 | 
						|
	/**
 | 
						|
	 * Array of settings
 | 
						|
	 * @var array
 | 
						|
	 */
 | 
						|
	protected $settings = array();
 | 
						|
 | 
						|
	/**
 | 
						|
	 * Array of settings stored in database
 | 
						|
	 * @var array
 | 
						|
	 */
 | 
						|
	protected $settingsInDb = array();
 | 
						|
 | 
						|
	/**
 | 
						|
	 * Returns an instance of Settings class
 | 
						|
	 * @return Settings
 | 
						|
	 */
 | 
						|
	protected static function getInstance(){
 | 
						|
		if (self::$instance === null) {
 | 
						|
			self::$instance = new self();
 | 
						|
		}
 | 
						|
		return self::$instance;
 | 
						|
	}
 | 
						|
 | 
						|
	/**
 | 
						|
	 * Settings class constructor. Set default values and load setting from database.
 | 
						|
	 * @global $home_locale Specifies home locale. Defined in libs/config.php
 | 
						|
	 */
 | 
						|
	protected function __construct() {
 | 
						|
		global $home_locale;
 | 
						|
		// Set default values
 | 
						|
		$this->settings = array(
 | 
						|
			'dbversion' => 0,
 | 
						|
			'featuresversion' => 0,
 | 
						|
			'title' => 'Your Company',
 | 
						|
			'hosturl' => 'http://mibew.org',
 | 
						|
			'logo' => '',
 | 
						|
			'usernamepattern' => '{name}',
 | 
						|
			'chatstyle' => 'default',
 | 
						|
			'invitationstyle' => 'default',
 | 
						|
			'chattitle' => 'Live Support',
 | 
						|
			'geolink' => 'http://api.hostip.info/get_html.php?ip={ip}',
 | 
						|
			'geolinkparams' => 'width=440,height=100,toolbar=0,scrollbars=0,location=0,status=1,menubar=0,resizable=1',
 | 
						|
			'max_uploaded_file_size' => 100000,
 | 
						|
			'max_connections_from_one_host' => 10,
 | 
						|
			'thread_lifetime' => 600,
 | 
						|
 | 
						|
			'email' => '', /* inbox for left messages */
 | 
						|
			'left_messages_locale' => $home_locale,
 | 
						|
			'sendmessagekey' => 'center',
 | 
						|
 | 
						|
			'enableban' => '0',
 | 
						|
			'enablessl' => '0',
 | 
						|
			'forcessl' => '0',
 | 
						|
			'usercanchangename' => '1',
 | 
						|
			'enablegroups' => '0',
 | 
						|
			'enablegroupsisolation' => '0',
 | 
						|
			'enablestatistics' => '1',
 | 
						|
			'enabletracking' => '0',
 | 
						|
			'enablepresurvey' => '1',
 | 
						|
			'surveyaskmail' => '0',
 | 
						|
			'surveyaskgroup' => '1',
 | 
						|
			'surveyaskmessage' => '0',
 | 
						|
			'enablepopupnotification' => '0',
 | 
						|
			'showonlineoperators' => '0',
 | 
						|
			'enablecaptcha' => '0',
 | 
						|
 | 
						|
			'online_timeout' => 30, /* Timeout (in seconds) when online operator becomes offline */
 | 
						|
			'updatefrequency_operator' => 2,
 | 
						|
			'updatefrequency_chat' => 2,
 | 
						|
			'updatefrequency_oldchat' => 7,
 | 
						|
 | 
						|
			'updatefrequency_tracking' => 10,
 | 
						|
			'visitors_limit' => 20, /* Number of visitors to look over */
 | 
						|
			'invitation_lifetime' => 60, /* Lifetime for invitation to chat */
 | 
						|
			'tracking_lifetime' => 600, /* Time to store tracked old visitors' data */
 | 
						|
		);
 | 
						|
 | 
						|
		// Load values from database
 | 
						|
		$db = Database::getInstance();
 | 
						|
		$rows = $db->query(
 | 
						|
			"select vckey,vcvalue from {chatconfig}",
 | 
						|
			NULL,
 | 
						|
			array('return_rows' => Database::RETURN_ALL_ROWS)
 | 
						|
		);
 | 
						|
 | 
						|
		foreach ($rows as $row) {
 | 
						|
			$name = $row['vckey'];
 | 
						|
			$this->settings[$name] = $row['vcvalue'];
 | 
						|
			$this->settingsInDb[$name] = true;
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	/**
 | 
						|
	 * Get setting value.
 | 
						|
	 *
 | 
						|
	 * @param string $name Variable's name
 | 
						|
	 * @return mixed
 | 
						|
	 */
 | 
						|
	public static function get($name) {
 | 
						|
		$instance = self::getInstance();
 | 
						|
		return $instance->settings[$name];
 | 
						|
	}
 | 
						|
 | 
						|
	/**
 | 
						|
	 * Set setting value.
 | 
						|
	 *
 | 
						|
	 * @param string $name Variables's name
 | 
						|
	 * @param mixed $value Variable's value
 | 
						|
	 */
 | 
						|
	public static function set($name, $value) {
 | 
						|
		$instance = self::getInstance();
 | 
						|
		$instance->settings[$name] = $value;
 | 
						|
	}
 | 
						|
 | 
						|
	/**
 | 
						|
	 * Updates settings in database.
 | 
						|
	 */
 | 
						|
	public static function update() {
 | 
						|
		$instance = self::getInstance();
 | 
						|
		$db = Database::getInstance();
 | 
						|
		foreach ($instance->settings as $key => $value) {
 | 
						|
			if (!isset($instance->settingsInDb[$key])) {
 | 
						|
				$db->query(
 | 
						|
					"insert into {chatconfig} (vckey) values (?)",
 | 
						|
					array($key)
 | 
						|
				);
 | 
						|
			}
 | 
						|
			$db->query(
 | 
						|
				"update {chatconfig} set vcvalue=? where vckey=?",
 | 
						|
				array($value, $key)
 | 
						|
			);
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	/**
 | 
						|
	 * Implementation of destructor
 | 
						|
	 */
 | 
						|
	public function __destruct() {}
 | 
						|
}
 | 
						|
 | 
						|
?>
 |