Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

multisite done!

  • Loading branch information...
commit 5a3dfc0d915f89abee41ba468e08175ce891415b 1 parent fcc26bf
devconquer authored
2  config-sample.php
View
@@ -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');
25 oc-includes/osclass/classes/DAO.php
View
@@ -33,6 +33,7 @@
*/
abstract class DAO {
protected $conn ;
+ protected $metadata_conn ;
/**
* Make a new instance of the DAO from its name.
@@ -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'
@@ -123,6 +133,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.
*/
public function deleteByPrimaryKey($id) {
3  oc-includes/osclass/db.php
View
@@ -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) ;
}
48 oc-includes/osclass/helpers/hDatabaseInfo.php
View
@@ -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  oc-includes/osclass/install-functions.php
View
@@ -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');
55 oc-includes/osclass/model/SiteInfo.php
View
@@ -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  oc-load.php
View
@@ -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';
@@ -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';
Please sign in to comment.
Something went wrong with that request. Please try again.