PDA

View Full Version : One user/post database, multiple sites


ChrisHasenpflug
04-21-2005, 06:08 AM
Hi folks,

I'm going to be converting to vB for a network of sites. All of these sites will use their own design and marketing tactics. However, they all use the same database. Same users, same forums/subforums, same posts. Only difference is the templates and the content in their CMS.

I'm currently working through this in a dev enviroment and its not as easy as I had hoped (we currently do this with UBB just fine).

First thing, when setting up the second site I couldn't go through the install since the tables were already created. But I was able to login and view the posts since the DB was setup for site 1.

Problem 1: site2 has the title of site1. This is (I assume) because the site name is actually stored in the database. Uh oh! This won't do at all, how do I get around that?

Problem 2: Templates are stored in the database. Any changes to site2 will be reflected on site1 and viceaversa.

How do I make this possible?? Thoughts?? I'm and experienced php & mySQL programmer, but I haven't sat down with the vB code yet to hack through it. Hopeful somebody can give me some pointers!

Thanks in advance!

Marco van Herwaarden
04-21-2005, 07:11 AM
If i understand you correctly, then this can not be done easily and would even be against your license agreement, unless you would buy a seperate license for each site.

ChrisHasenpflug
04-21-2005, 07:14 AM
We would indeed have seperate licenses for each site.

Brad
04-21-2005, 07:39 AM
Use a table prefix if both forums are to be in the same database. The reason board two acts like board one is the php files are using board one's tables.

Marco van Herwaarden
04-21-2005, 07:44 AM
Ok, let me try to get things clear. From what i understand you want:
- 1 Board, ie. 1 database with users, forums and posts.
- Different domains all leading to this same Board. Depending on the domain you want to present a different style and frontpage.

Just making some educated guess now, because i never tried it but i think you could modify vB to do the following (would need some work):
- Setup 1 Board
- Add styles for each subdomain
- Create an additional table linking domains to styleid's
- Check the domain/style on each page load and set accordingly.
- Create a table to hold the Titles for each domain and use that to override the default Sitename
- The changes needed to a CMS would depends on which CMS you choose to use.

You will probably need to add some caching to prevent performance going down.

ChrisHasenpflug
04-21-2005, 07:45 AM
Use a table prefix if both forums are to be in the same database. The reason board two acts like board one is the php files are using board one's tables.

But I don't want them to act seperatly. I want the users and the posts to replicate across multiple sites.

Same content, different design/style.

Marco van Herwaarden
04-21-2005, 07:47 AM
PS There will be more caveats in this then i have now mentioned.

ChrisHasenpflug
04-21-2005, 07:51 AM
Ok, let me try to get things clear. From what i understand you want:
- 1 Board, ie. 1 database with users, forums and posts.
- Different domains all leading to this same Board. Depending on the domain you want to present a different style and frontpage.

Just making some educated guess now, because i never tried it but i think you could modify vB to do the following (would need some work):
- Setup 1 Board
- Add styles for each subdomain
- Create an additional table linking domains to styleid's
- Check the domain/style on each page load and set accordingly.
- Create a table to hold the Titles for each domain and use that to override the default Sitename
- The changes needed to a CMS would depends on which CMS you choose to use.

You will probably need to add some caching to prevent performance going down.

Marco, thank you for your response. An interesting approach indeed. I think it may work out well.

I'm curious where in the vB code I would check for the domain and set the templates/styles to use.

I find it quite interesting that this situation seems to be more difficult in vB, a more advanced BBS, then it was in UBB, a highly inferior product.

PS There will be more caveats in this then i have now mentioned.

What comes to mind?? I don't expect a full evaluation, but I'm just curious as to what initally comes to mind.

Marco van Herwaarden
04-21-2005, 08:14 AM
Some things that would come into my mind are:
- With multiple boards licenses, you would normally use seperate forumhome directories, each with their own software (php-files) installed, containing their own licensenumber. Licensenumber is also used to hash the password set in the cookie for the domain. So would be a difficult decission which way to go: single software directory (you still should have bought the licenses) or multiple. This would also effect the way hacks are installed, the same for all?
- Cookie handling in General
- How to keep this manageable.
- How to setup the CMS
- Handling 1 user who is browsing more then 1 site at the same time.
- ...

I am sure all could be solved, but it might need some serious coding.

Marco van Herwaarden
04-21-2005, 08:15 AM
I'm curious where in the vB code I would check for the domain and set the templates/styles to use.
At a very high level so you can do this with less coding and still can be sure ti works everywhere. Somewhere in global.php or init.php i would say.

Brad
04-21-2005, 05:25 PM
I misunderstood your post sorry...

The problem marco brought up with cookies is easy to solve, just use the same copy of php files for both forums, as long as you have a license for each this won't matter.

Exactly how much of the forum do you want to change between sites? If you simply want the style to change it is not hard to do as long as cookies don't become a problem. To avoid the cookie problem I would just set two durring login (once for each domain).

With some code modification you can pull it off, but it all depends on how far you want to go with it. :)

ChrisHasenpflug
04-21-2005, 07:42 PM
Cookies won't be a problem as the users really only login to one URL. They know the others exist, but they don't frequent them. Only visit their home site.

Mods would most likely be the same across all instances as well.

Its really just the style (header/footer/css) that would change between sites. Thoughts on what/where to make modifications?

Additionally we're looking at using vBadvanced CMPS for our CMS/front page. Each site would have its own blocks/content on their front page, independant of the other sites. Any ideas on how that would work out?

Thanks for the help and assistance guys. Very much appreciated.

Marco van Herwaarden
04-21-2005, 08:45 PM
I already gave some suggestions on where to put the code for the style change.

Sorry but i am not the best to answer your CMS questions.

ChrisHasenpflug
04-22-2005, 07:57 AM
Okay Marco, thanks a lot for your help :) Just trying to get more input. I will certainly work off of what you have given me!

Brad
04-22-2005, 09:44 AM
Cookies won't be a problem as the users really only login to one URL. They know the others exist, but they don't frequent them. Only visit their home site.

Mods would most likely be the same across all instances as well.

Its really just the style (header/footer/css) that would change between sites. Thoughts on what/where to make modifications?

Additionally we're looking at using vBadvanced CMPS for our CMS/front page. Each site would have its own blocks/content on their front page, independant of the other sites. Any ideas on how that would work out?

Thanks for the help and assistance guys. Very much appreciated.
The best way to do the styles is to make modifications to global.php Baiscly you will look for which domain the user is on and inject a custom styleid based on that. Then you modify each style in the admincp to your liking, simple and easy :)

If you are confused let me know and I'll post some examples for you.

The CMS I am not sure about, as I do not run one. I recall it begin able to spawn multiple pages from one file (unlike the old portals) but I could be wrong, best to ask someone that uses the hack.

ChrisHasenpflug
04-22-2005, 08:22 PM
Hey Brad, thank you for your offer to help out!!

I have started to try and make changes on my own. But I am certainly missing something :)

I'm working locally with apache set to respond to two host names, vbsite1 and vbsite2. They point to the same files.

The following code has been added to global.php at line 269

// overwrite styles for specific sites
$sitestyles = array(
'vbsite1' => 1,
'vbsite2' => 2,);

$hostname = $HTTP_SERVER_VARS['HTTP_HOST'];

if(array_key_exists($hostname, $sitestyles))
{
$styleid = $sitestyles["$hostname"];
}

That appeared to me to be the last place styleid is checked before setting up the templates. However, for some reason its not working as intended. I'm getting the Default Template for all sites, regardless.

Now I can to and do $styleid = 2; after my if and it works. So I would think something is wrong with my if....well, I run the code segment on its own outside of vB and it echos the proper name just fine.

//styletest.php
$styleid = 0;

$sitestyles = array(
'vbsite1' => 1,
'vbsite2' => 2,);

$hostname = $HTTP_SERVER_VARS['HTTP_HOST'];

if(array_key_exists($hostname, $sitestyles))
{
$styleid = $sitestyles["$hostname"];
}

echo $styleid;

That works as expected.

Thanks for your help!!

Marco van Herwaarden
04-22-2005, 08:29 PM
If you do an echo of the styleid in the global, is it set correct?

I think you must write the new styleid to the cookie, or add "?styleid=$styleid" to the sessionurl.

Brad
04-22-2005, 08:49 PM
Styles are set multiple times within global.php/init.php based on the settings or if you are in a forum or on the front page. Let me do a little poking and i'll post back. :)

Brad
04-22-2005, 08:56 PM
Ok in global.php find:

// figure out the chosen style settings
$codestyleid = 0;

Under that add:

// switch style based on domain
$sitestyles = array(
'vbsite1' => 1,
'vbsite2' => 2);

$hostname = $_SERVER['HTTP_HOST'];

if(array_key_exists($hostname, $sitestyles))
{
$codestyleid = $sitestyles[$hostname];
}
// end hack

Then find:

// automatically query $getpost, $threadinfo & $foruminfo if $threadid exists
if ($_REQUEST['postid'] AND $postinfo = verify_id('post', $_REQUEST['postid'], 0, 1))
{
$getpost = $postinfo; // Not needed other than to maintain newreply.php for now.
$postid = $postinfo['postid'];
$_REQUEST['threadid'] = $postinfo['threadid'];

}

// automatically query $threadinfo & $foruminfo if $threadid exists
if ($_REQUEST['threadid'] AND $threadinfo = verify_id('thread', $_REQUEST['threadid'], 0, 1))
{
$threadid = $threadinfo['threadid'];
$forumid = $threadinfo['forumid'];
if ($forumid)
{
$foruminfo = fetch_foruminfo($threadinfo['forumid']);
if (($foruminfo['styleoverride'] == 1 OR $bbuserinfo['styleid'] == 0) AND !defined('BYPASS_STYLE_OVERRIDE'))
{
$codestyleid = $foruminfo['styleid'];
}
}
}
// automatically query $foruminfo if $forumid exists
else if ($_REQUEST['forumid'])
{
$foruminfo = verify_id('forum', $_REQUEST['forumid'], 0, 1);
$forumid = $foruminfo['forumid'];
if (($foruminfo['styleoverride'] == 1 OR $bbuserinfo['styleid'] == 0) AND !defined('BYPASS_STYLE_OVERRIDE'))
{
$codestyleid = $foruminfo['styleid'];
}
}
// automatically query forum for style info if $pollid exists
else if ($_REQUEST['pollid'])
{
$pollid = intval($_REQUEST['pollid']);
$getforum = $DB_site->query_first("SELECT forum.forumid, styleid, ((options & $_FORUMOPTIONS[styleoverride]) != 0) AS styleoverride FROM " . TABLE_PREFIX . "forum AS forum, " . TABLE_PREFIX . "thread AS thread WHERE forum.forumid = thread.forumid AND pollid = $pollid");
if (($getforum['styleoverride'] == 1 OR $bbuserinfo['styleid'] == 0) AND !defined('BYPASS_STYLE_OVERRIDE'))
{
$codestyleid = $getforum['styleid'];
}
unset($getforum);
}

Replace with (commented out version of code to disable it, this basicly prevents styles set in forums from overriding the one set by the domain)

/*
// automatically query $getpost, $threadinfo & $foruminfo if $threadid exists
if ($_REQUEST['postid'] AND $postinfo = verify_id('post', $_REQUEST['postid'], 0, 1))
{
$getpost = $postinfo; // Not needed other than to maintain newreply.php for now.
$postid = $postinfo['postid'];
$_REQUEST['threadid'] = $postinfo['threadid'];

}

// automatically query $threadinfo & $foruminfo if $threadid exists
if ($_REQUEST['threadid'] AND $threadinfo = verify_id('thread', $_REQUEST['threadid'], 0, 1))
{
$threadid = $threadinfo['threadid'];
$forumid = $threadinfo['forumid'];
if ($forumid)
{
$foruminfo = fetch_foruminfo($threadinfo['forumid']);
if (($foruminfo['styleoverride'] == 1 OR $bbuserinfo['styleid'] == 0) AND !defined('BYPASS_STYLE_OVERRIDE'))
{
$codestyleid = $foruminfo['styleid'];
}
}
}
// automatically query $foruminfo if $forumid exists
else if ($_REQUEST['forumid'])
{
$foruminfo = verify_id('forum', $_REQUEST['forumid'], 0, 1);
$forumid = $foruminfo['forumid'];
if (($foruminfo['styleoverride'] == 1 OR $bbuserinfo['styleid'] == 0) AND !defined('BYPASS_STYLE_OVERRIDE'))
{
$codestyleid = $foruminfo['styleid'];
}
}
// automatically query forum for style info if $pollid exists
else if ($_REQUEST['pollid'])
{
$pollid = intval($_REQUEST['pollid']);
$getforum = $DB_site->query_first("SELECT forum.forumid, styleid, ((options & $_FORUMOPTIONS[styleoverride]) != 0) AS styleoverride FROM " . TABLE_PREFIX . "forum AS forum, " . TABLE_PREFIX . "thread AS thread WHERE forum.forumid = thread.forumid AND pollid = $pollid");
if (($getforum['styleoverride'] == 1 OR $bbuserinfo['styleid'] == 0) AND !defined('BYPASS_STYLE_OVERRIDE'))
{
$codestyleid = $getforum['styleid'];
}
unset($getforum);
}
*/

Then find

// style specified in user profile
$styleid = $bbuserinfo['styleid'];

Replace with (this disables users from selecting a style via their profile)

// style specified in user profile
// $styleid = $bbuserinfo['styleid'];

That should do it.. :)