Project

General

Profile

« Previous | Next » 

Revision 1683

Added by darkviper over 12 years ago

changed class Database into a Singleton-Class
added forgotten 'static' keyword in ModLanguage
removed version control from sm2 - include.php

View differences:

branches/2.8.x/CHANGELOG
12 12
===============================================================================
13 13

  
14 14
03 May-2012 Build 1682 Werner v.d.Decken(DarkViper)
15
! changed class Database into a Singleton-Class
16
# added forgotten 'static' keyword in ModLanguage
17
# removed version control from sm2 - include.php
18
03 May-2012 Build 1682 Werner v.d.Decken(DarkViper)
15 19
! some little corrections ModLanguage/Database/initialize.php
16 20
03 May-2012 Build 1681 Werner v.d.Decken(DarkViper)
17 21
! reorganisation of default theme of oage-settings
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.3');
54
if(!defined('REVISION')) define('REVISION', '1682');
54
if(!defined('REVISION')) define('REVISION', '1683');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/framework/initialize.php
91 91
	date_default_timezone_set('UTC');
92 92
	// Create database class
93 93
	$sSqlUrl = DB_TYPE.'://'.DB_USERNAME.':'.DB_PASSWORD.'@'.DB_HOST.'/'.DB_NAME;
94
	$database = new Database($sSqlUrl);
94
	$database = Database::getInstance();
95
	$database->doConnect($sSqlUrl);
95 96
	// disable all kind of magic_quotes
96 97
	if(get_magic_quotes_gpc() || get_magic_quotes_runtime()) {
97 98
		@ini_set('magic_quotes_sybase', 0);
branches/2.8.x/wb/framework/Database.php
29 29
/* -------------------------------------------------------- */
30 30
define('DATABASE_CLASS_LOADED', true);
31 31

  
32
class Database {
33 32

  
34
//	$sdb = 'mysql://user:password@demo.de:3306/datenbank';
33
class Database extends DatabaseX {
34
	
35
	private static $_oInstance = array();
36
/* prevent from public instancing */
37
	protected function  __construct() {}
38
/* prevent from cloning */
39
	private function __clone() {}
40
/**
41
 * get a valid instance of this class
42
 * @param string $sIdentifier selector for several different instances
43
 * @return object
44
 */
45
	public static function getInstance($sIdentifier = 'core') {
46
		if( !isset(self::$_oInstance[$sIdentifier])) {
47
            $c = __CLASS__;
48
            self::$_oInstance[$sIdentifier] = new $c;
49
		}
50
		return self::$_oInstance[$sIdentifier];
51
	}
52
}
35 53

  
54

  
55
class DatabaseX {
56

  
36 57
	private $_db_handle = null; // readonly from outside
37 58
	private $_scheme    = 'mysql';
38 59
	private $_hostname  = 'localhost';
......
48 69
	private $message    = array();
49 70
	private $iQueryCount= 0;
50 71

  
51

  
52
	// Set DB_URL
53
	function __construct($url = '') {
72
/* prevent from public instancing */
73
	protected function __construct() {}
74
/* prevent from cloning */
75
	private function __clone() {}
76
	
77
/**
78
 * Connect to the database
79
 * @param string $url
80
 * @return bool
81
 *
82
 * Example for SQL-Url:  'mysql://user:password@demo.de[:3306]/datenbank'
83
 */
84
	public function doConnect($url = '') {
54 85
		if($url != '') {
55 86
			$aIni = parse_url($url);
56 87
			$this->_scheme   = isset($aIni['scheme']) ? $aIni['scheme'] : 'mysql';
......
63 94
		}else {
64 95
			throw new RuntimeException('Missing parameter: unable to connect database');
65 96
		}
66
		// Connect to database
67
		$this->connect();
68
	}
69
	
70
	// Connect to the database
71
	function connect() {
72 97
		$this->_db_handle = mysql_connect($this->_hostname.$this->_hostport,
73 98
		                                  $this->_username,
74 99
		                                  $this->_password);
branches/2.8.x/wb/framework/ModLanguage.php
28 28
 * get a valid instance of this class
29 29
 * @return object
30 30
 */
31
	public function getInstance() {
31
	static public function getInstance() {
32 32
		if( is_null(self::$_oInstance) ) {
33 33
            $c = __CLASS__;
34 34
            self::$_oInstance = new $c;
branches/2.8.x/wb/modules/show_menu2/include.php
535 535
        // is called (i.e. where the database is loaded) then the info won't
536 536
        // exist anyhow.
537 537
        $fields  = '`parent`,`page_id`,`menu_title`,`page_title`,`link`,`target`,';
538
		$fields .= '`level`,`visibility`,`viewing_groups`';
539
        if (version_compare(WB_VERSION, '2.7', '>=')) { // WB 2.7+
540
            $fields .= ',`viewing_users`';
541
        }
542
		if(version_compare(WB_VERSION, '2.8.4', '>=')) {
543
            $fields .= ',`menu_icon_0`,`menu_icon_1`,`page_icon`,`tooltip`';
544
		}
538
		$fields .= '`level`,`visibility`,`viewing_groups`,`viewing_users`,';
539
		$fields .= '`menu_icon_0`,`menu_icon_1`,`page_icon`,`tooltip`';
545 540
        if ($flags & SM2_ALLINFO) {
546 541
            $fields = '*';
547 542
        }

Also available in: Unified diff