|
From: <ree...@us...> - 2007-08-30 11:55:25
|
Revision: 25
http://thevr.svn.sourceforge.net/thevr/?rev=25&view=rev
Author: reekingofrandom
Date: 2007-08-30 04:55:26 -0700 (Thu, 30 Aug 2007)
Log Message:
-----------
ReekingofRandomness - Commented out the temporary addition at the end of common.php
-Added the install Script
Modified Paths:
--------------
mods/pms/trunk/common.php
Added Paths:
-----------
mods/pms/trunk/thevr_pms_install.php
Modified: mods/pms/trunk/common.php
===================================================================
--- mods/pms/trunk/common.php 2007-08-30 11:52:24 UTC (rev 24)
+++ mods/pms/trunk/common.php 2007-08-30 11:55:26 UTC (rev 25)
@@ -1,10 +1,10 @@
<?php
-/**
+/**
*
* @package phpBB3
* @version $Id: common.php,v 1.205 2007/08/13 12:14:05 acydburn Exp $
-* @copyright (c) 2005 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @copyright (c) 2005 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
* Minimum Requirement: PHP 4.3.3
*/
@@ -206,14 +206,14 @@
while ($i <= $bits)
{
$domains[$i] = $domain_bits[$bits - $i] . '.' . $domains[$i - 1];
-
+
$i++;
}
$sql = 'SELECT s.*, su.domain
FROM ' . SITES_TABLE . ' s INNER JOIN ' . SITE_URL_TABLE . ' su ON s.site_id = su.site_id
WHERE su.domain IN ';
-
+$notfirst = false;
foreach ($domains AS $key => $value)
{
$sql .= ($notfirst == false) ? '(': ', ';
@@ -245,7 +245,7 @@
'site_domain' => $domain,
'site_file' => $filename,
'site_vars' => $vars)
-
+
);
}
//Fetch site specific config data:
@@ -263,4 +263,19 @@
}
/***** END *****/
+/* Temporary addition until cookies are sorted:
+ if (strpos($domain, 'thevr.co.uk') == false AND $domain != 'thevr.co.uk')
+ {
+ $sql = 'SELECT su.domain
+ FROM ' . SITE_URL_TABLE . " AS su
+ WHERE su.site_id = '" . $config['site_id'] . "'
+ AND su.domain LIKE '%thevr.co.uk'
+ LIMIT 1";
+ $result = $db->sql_query($sql);
+ $row = $db->sql_fetchrow($result);
+
+ header('Location: http://' . $row['domain'] . $_SERVER['REQUEST_URI']);
+ }
+*/
+
?>
\ No newline at end of file
Added: mods/pms/trunk/thevr_pms_install.php
===================================================================
--- mods/pms/trunk/thevr_pms_install.php (rev 0)
+++ mods/pms/trunk/thevr_pms_install.php 2007-08-30 11:55:26 UTC (rev 25)
@@ -0,0 +1,305 @@
+<?php
+/**
+*
+* @package phpBB3
+* @version $Id: thevr_install.php
+* @copyright (c) 2005 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @ignore
+*/
+define('IN_PHPBB', true);
+$phpbb_root_path = './';
+$phpEx = substr(strrchr(__FILE__, '.'), 1);
+include($phpbb_root_path . 'common.' . $phpEx);
+
+$mode = request_var('mode','');
+if($auth->acl_gets('acl_a_server'))
+{
+ trigger_error('You are nto permitted to install this modification');
+}
+
+switch ($mode)
+{
+ case 'install':
+ //Install
+ /* _site_config */
+ $sql = "CREATE TABLE `" . $table_prefix . "site_config` (
+ `config_name` varchar(255) character set latin1 collate latin1_general_ci NOT NULL,
+ `config_value` varchar(255) character set latin1 collate latin1_general_ci NOT NULL,
+ `is_dynamic` tinyint(1) NOT NULL,
+ `site_id` mediumint(4) NOT NULL,
+ `overide` tinyint(1) NOT NULL
+ )";
+
+ if($db->sql_query($sql))
+ {
+ $success[] = 'site_config';
+ }
+ else
+ {
+ define('ERROR',true);
+ }
+
+ /* _site_urls */
+ $sql = "CREATE TABLE `" . $table_prefix . "site_urls` (
+ `id` mediumint(8) NOT NULL auto_increment,
+ `site_id` mediumint(4) NOT NULL,
+ `domain` varchar(255) character set utf8 collate utf8_bin NOT NULL,
+ PRIMARY KEY (`id`)
+ )";
+
+ if($db->sql_query($sql))
+ {
+ $success[] = 'site_urls';
+ }
+ else
+ {
+ define('ERROR',true);
+ }
+
+ /* _sites */
+
+ $sql = "CREATE TABLE `" . $table_prefix . "sites` (
+ `site_id` mediumint(4) NOT NULL auto_increment,
+ `name` varchar(255) character set utf8 collate utf8_bin NOT NULL,
+ `description` varchar(255) character set utf8 collate utf8_bin NOT NULL,
+ `group_id` mediumint(8) NOT NULL default '1',
+ `home` varchar(255) character set utf8 collate utf8_bin NOT NULL default 'index.php',
+ `default_style` tinyint(4) NOT NULL default '1',
+ PRIMARY KEY (`site_id`)
+ )";
+
+ if($db->sql_query($sql))
+ {
+ $success[] = 'sites';
+ }
+ else
+ {
+ define('ERROR',true);
+ }
+
+
+ if(defined('ERROR'))
+ {
+ foreach($success as $i => $table)
+ {
+ $sql = "DROP TABLE " . $table_prefix . $table . " ";
+ @$db->sql_query($sql);
+ }
+
+ trigger_error('TheVR Mod :: Failed to create tables');
+ }
+
+ //Create Permissions
+ $sql = "INSERT INTO `phpbb_acl_options` ( `auth_option_id` , `auth_option` , `is_global` , `is_local` , `founder_only` ) VALUES ( NULL , 'a_sites_a', '1', '0', '0' ),
+ ( NULL , 'a_sites_e', '1', '0', '0' ),
+ ( NULL , 'a_sites_d', '1', '0', '0' ),
+ ( NULL , 'a_sites_ug', '1', '0', '0' ),
+ ( NULL , 'a_sites_f', '1', '0', '0' )";
+
+ if(!$db->sql_query($sql))
+ {
+ define('ERROR',true);
+ }
+
+ if(defined('ERROR'))
+ {
+ trigger_error('TheVR Mod :: Failed to create permissions');
+
+ foreach($success as $i => $table)
+ {
+ $sql = "DROP TABLE " . $table_prefix . $table . " ";
+ @$db->sql_query($sql);
+ }
+ }
+
+ //Update forums table
+ $sql = "ALTER TABLE `phpbb_forums` ADD `site_id` MEDIUMINT( 4 ) NOT NULL DEFAULT '0';";
+
+ if(!$db->sql_query($sql))
+ {
+ define('ERROR',true);
+ }
+
+ if(defined('ERROR'))
+ {
+ trigger_error('TheVR Mod :: Failed to alter forums table');
+
+ foreach($success as $i => $table)
+ {
+ $sql = "DROP TABLE " . $table_prefix . $table . " ";
+ @$db->sql_query($sql);
+ }
+ }
+
+ //Put initial data into table.
+ $data = array( 'name' => $config['sitename'],
+ 'domain' => $config['server_name'],
+ 'desc' => $config['site_desc'],
+ 'group_id' => '',
+ 'home' => '',
+ 'style' => $config['default_style']);
+
+ add_site($data);
+
+ trigger_error('TheVR Mod :: Successful Installation');
+
+ break;
+ case 'update':
+ $vers = request_var('v','');
+ switch ($vers)
+ {
+ case '':
+ default:
+ break;
+ }
+ break;
+ case 'view':
+ echo "<h1>View Changes</h1><br />";
+ echo "CREATE TABLE `" . $table_prefix . "site_config` (
+ <br /> `config_name` varchar(255) character set latin1 collate latin1_general_ci NOT NULL,
+ <br /> `config_value` varchar(255) character set latin1 collate latin1_general_ci NOT NULL,
+ <br /> `is_dynamic` tinyint(1) NOT NULL,
+ <br /> `site_id` mediumint(4) NOT NULL,
+ <br /> `overide` tinyint(1) NOT NULL
+ <br />)";
+ echo " <br /><br /> ";
+ echo "CREATE TABLE `" . $table_prefix . "site_urls` (
+ <br /> `id` mediumint(8) NOT NULL auto_increment,
+ <br /> `site_id` mediumint(4) NOT NULL,
+ <br /> `domain` varchar(255) character set utf8 collate utf8_bin NOT NULL,
+ <br />PRIMARY KEY (`id`))";
+ echo " <br /><br /> ";
+ echo " CREATE TABLE `" . $table_prefix . "sites` (
+ <br /> `site_id` mediumint(4) NOT NULL auto_increment,
+ <br /> `name` varchar(255) character set utf8 collate utf8_bin NOT NULL,
+ <br /> `description` varchar(255) character set utf8 collate utf8_bin NOT NULL,
+ <br /> `group_id` mediumint(8) NOT NULL default '1',
+ <br /> `home` varchar(255) character set utf8 collate utf8_bin NOT NULL default 'index.php',
+ <br /> `default_style` tinyint(4) NOT NULL default '1',
+ <br />PRIMARY KEY (`site_id`))";
+ echo " <br /><br /> ";
+ echo " INSERT INTO `phpbb_acl_options` ( `auth_option_id` , `auth_option` , `is_global` , `is_local` , `founder_only` ) VALUES ( NULL , 'a_sites_a', '1', '0', '0' );<br />
+ <br />INSERT INTO `phpbb_acl_options` ( `auth_option_id` , `auth_option` , `is_global` , `is_local` , `founder_only` ) VALUES ( NULL , 'a_sites_e', '1', '0', '0' );<br />
+ <br />INSERT INTO `phpbb_acl_options` ( `auth_option_id` , `auth_option` , `is_global` , `is_local` , `founder_only` ) VALUES ( NULL , 'a_sites_d', '1', '0', '0' );<br />
+ <br />INSERT INTO `phpbb_acl_options` ( `auth_option_id` , `auth_option` , `is_global` , `is_local` , `founder_only` ) VALUES ( NULL , 'a_sites_ug', '1', '0', '0' );<br />
+ <br />INSERT INTO `phpbb_acl_options` ( `auth_option_id` , `auth_option` , `is_global` , `is_local` , `founder_only` ) VALUES ( NULL , 'a_sites_f', '1', '0', '0' );";
+ echo " <br /><br /> ";
+ echo " ALTER TABLE `phpbb_forums` ADD `site_id` MEDIUMINT( 4 ) NOT NULL DEFAULT '0';";
+ break;
+ default:
+ echo "<h1>TheVR Pseudo Multi-Site (PMS) Mod </h1><br />";
+ echo "<a href=\"thevr_pms_install.php?mode=install\">Fresh Install</a>
+ <br />
+ <br />
+ <b>Upgrade From:</b>
+ <br />
+ <ul>
+ <li>...</li>
+ </ul>
+ <br />
+ <a href=\"thevr_pms_install.php?mode=view\">View Changes</a>";
+ break;
+
+}
+
+//Functions
+
+function add_url($data)
+{
+ global $db, $user, $table_prefix;
+
+ if (!is_array($data))
+ {
+ trigger_error($user->lang['VAR_NOT_ARRAY'], E_USER_WARNING);
+ }
+
+ //Check if domain already exists.
+ $sql = 'SELECT * FROM '. $table_prefix . 'site_urls WHERE domain=\''.$data['domain'].'\'';
+ $result = $db->sql_query($sql);
+ if (sizeof($db->sql_fetchrowset($result)) > 0)
+ {
+ trigger_error($user->lang['DUPLI_DOMAIN']);
+ }
+
+ $siteurl_ins = array ( 'site_id' => $data['site_id'],
+ 'domain' => $data['domain'] );
+
+ if( !$db->sql_query('INSERT INTO '. $table_prefix . 'site_urls '.$db->sql_build_array('INSERT',$siteurl_ins)))
+ {
+ trigger_error($user->lang['SITE_URL_ADD_FAIL']);
+ }
+ else
+ {
+ return true;
+ }
+}
+
+
+function add_site($data)
+{
+ global $db, $user, $table_prefix, $phpbb_root_path;
+
+ include($phpbb_root_path . 'includes/functions_user.php');
+
+ if (!is_array($data))
+ {
+ trigger_error($user->lang['VAR_NOT_ARRAY'], E_USER_WARNING);
+ }
+
+ if ( $data['domain'] == '' )
+ {
+ trigger_error($user->lang['NO_DOMAIN_SUPPLIED']);
+ }
+
+ //Check if the name or domain name already exist.
+ $sql = 'SELECT * FROM '. $table_prefix . 'sites WHERE name=\''.$data['name'].'\'';
+ $result = $db->sql_query($sql);
+ if (sizeof($db->sql_fetchrowset($result)) > 0)
+ {
+ trigger_error($user->lang['DUPLI_NAME']);
+ }
+
+ //Vars for group creation:
+ $g_type = 'GROUP_CLOSED';
+ $g_name = 'registered_'.preg_replace('/\s\s+/','_',$data['name']);
+ $g_desc = 'The members of '.$data['name'];
+ $g_att = array('group_legend' => 0);
+
+
+ if (group_create($group_id,$g_type,$g_name,$g_desc,$g_att))
+ {
+ trigger_error($user->lang['GRP_ADD_FAIL']);
+ }
+ else
+ {
+ $sql = 'SELECT * FROM '.GROUPS_TABLE.' WHERE group_name=\'registered_'.$data['name'].'\'';
+ $data['group_id'] = $db->sql_fetchfield('group_id',0,$db->sql_query($sql));
+
+ $site_ins = array ( 'name' => $data['name'],
+ 'description' => $data['desc'],
+ 'group_id' => $data['group_id'],
+ 'home' => $data['home'],
+ 'default_style' => $data['style'] );
+
+ //Insert into sites table.
+ if( !$db->sql_query('INSERT INTO '. $table_prefix .'sites '.$db->sql_build_array('INSERT',$site_ins)))
+ {
+ trigger_error($user->lang['SITE_ADD_FAIL']);
+ }
+
+ $sql = 'SELECT * FROM '. $table_prefix .'sites WHERE name=\''.$data['name'].'\'';
+ $data['site_id'] = $db->sql_fetchfield('site_id',0,$db->sql_query($sql));
+
+ if(add_url($data))
+ {
+ return $data['site_id'];
+ }
+
+ }
+}
+?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|