Skip to content

Commit

Permalink
multisite done!
Browse files Browse the repository at this point in the history
  • Loading branch information
devconquer committed Mar 18, 2011
1 parent fcc26bf commit 5a3dfc0
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config-sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* The base MySQL settings of OSClass
*/
define('MULTISITE', 1);
define('MULTISITE', 0);

/** MySQL database name for OSClass */
define('DB_NAME', 'database_name');
Expand Down
25 changes: 22 additions & 3 deletions oc-includes/osclass/classes/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/
abstract class DAO {
protected $conn ;
protected $metadata_conn ;

/**
* Make a new instance of the DAO from its name.
Expand All @@ -47,12 +48,21 @@ public static function load($entityName)
}

public function __construct() {
$this->conn = getConnection(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, DEBUG_LEVEL);
//echo "#@". osc_db_host() . osc_db_user() . osc_db_password() . osc_db_name() . DEBUG_LEVEL . "@#" ;
$this->conn = getConnection(osc_db_host(), osc_db_user(), osc_db_password(), osc_db_name(), DEBUG_LEVEL) ;
}

public function createMetadataConnection() {
$this->metadata_conn = getConnection(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, DEBUG_LEVEL) ;
}

public function getConnection() {
return $this->conn;
}
return $this->conn ;
}

public function getMetadataConnection() {
return $this->metadata_conn ;
}

/*
* @return Array returns 0 if 'asc' or 1 if 'desc'
Expand Down Expand Up @@ -122,6 +132,15 @@ public function findByPrimaryKey($pk) {
);
}

/**
* @return only for metadata.
*/
public function findByPrimaryKeyInMetadataDB($pk) {
return $this->metadata_conn->osc_dbFetchResult("SELECT * FROM %s WHERE s_site = '%s'",
$this->getTableName(), $pk
);
}

/**
* Deletes a row with the id passed by parameter.
*/
Expand Down
3 changes: 2 additions & 1 deletion oc-includes/osclass/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ function print_debug() {
* @param string datatabase name
*/
function osc_dbConnect() {
$this->db = @new mysqli($this->dbHost, $this->dbUser, $this->dbPassword, $this->dbName);
//echo "#" , $this->dbHost, $this->dbUser, $this->dbPassword, $this->dbName ;
$this->db = new mysqli($this->dbHost, $this->dbUser, $this->dbPassword, $this->dbName);
if ($this->db->connect_error) {
$this->debug('Error connecting to \'' . $this->dbName . '\' (' . $this->db->connect_errno . ': ' . $this->db->connect_error . ')', false) ;
}
Expand Down
48 changes: 48 additions & 0 deletions oc-includes/osclass/helpers/hDatabaseInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* OSCLass – software for creating and publishing online classified
* advertising platforms
*
* Copyright (C) 2010 OSCLASS
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

function osc_db_name() {
return getSiteInfo('s_db_name', DB_NAME) ;
}

function osc_db_host() {
return getSiteInfo('s_db_host', DB_HOST) ;
}

function osc_db_user() {
return getSiteInfo('s_db_user', DB_USER) ;
}

function osc_db_password() {
return getSiteInfo('s_db_password', DB_PASSWORD) ;
}

//PRIVATE FUNCTION FOR GETTING NO BOOLEAN INFORMATION (if there was a class :P)
function getSiteInfo($key, $default_value) {
if (MULTISITE) {
$_P = SiteInfo::newInstance() ;
return($_P->get($key, $section)) ;
}

return $default_value ;
}
?>
2 changes: 1 addition & 1 deletion oc-includes/osclass/install-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function create_config_file($dbname, $username, $password, $dbhost, $tableprefix
/**
* The base MySQL settings of OSClass
*/
define('MULTISITE', 1);
define('MULTISITE', 0);
/** MySQL database name for OSClass */
define('DB_NAME', '$dbname');
Expand Down
55 changes: 55 additions & 0 deletions oc-includes/osclass/model/SiteInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/*
* OSCLass – software for creating and publishing online classified
* advertising platforms
*
* Copyright (C) 2010 OSCLASS
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

class SiteInfo extends DAO
{
private static $instance ;
private $site_info ;

public static function newInstance() {
if(!self::$instance instanceof self) {
self::$instance = new self ;
}
return self::$instance ;
}

public function __construct() {
$this->createMetadataConnection() ;
$this->toArray() ;
}

public function getTableName() {
return 'tbl_sites' ;
}

public function toArray() {
$domain = $_SERVER['HTTP_HOST'] ;
$this->site_info = $this->findByPrimaryKeyInMetadataDB($domain) ;
}

public function get($key) {
if (!isset($this->site_info[$key])) {
return '' ;
}
return ($this->site_info[$key]) ;
}
}

3 changes: 2 additions & 1 deletion oc-load.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
require_once ABS_PATH . 'config.php';
require_once ABS_PATH . 'oc-includes/osclass/db.php';
require_once ABS_PATH . 'oc-includes/osclass/classes/DAO.php';
require_once ABS_PATH . 'oc-includes/osclass/model/SiteInfo.php';
require_once ABS_PATH . 'oc-includes/osclass/helpers/hDatabaseInfo.php';
require_once ABS_PATH . 'oc-includes/osclass/model/Preference.php';
require_once ABS_PATH . 'oc-includes/osclass/helpers/hPreference.php';
require_once ABS_PATH . 'oc-includes/osclass/helpers/hDefines.php';
Expand Down Expand Up @@ -74,7 +76,6 @@
require_once LIB_PATH . 'osclass/locales.php';
require_once LIB_PATH . 'osclass/plugins.php';
require_once ABS_PATH . 'oc-includes/osclass/helpers/hPlugins.php';
//require_once LIB_PATH . 'osclass/validations.php'; xxx: to be deleted
require_once LIB_PATH . 'osclass/ItemActions.php';
require_once LIB_PATH . 'osclass/model/Admin.php';
require_once LIB_PATH . 'osclass/model/Alerts.php';
Expand Down

0 comments on commit 5a3dfc0

Please sign in to comment.