MyBB Community Forums

Full Version: Separate theme on a subdomain - some links point to the normal domain
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want to setup an theme only for a subdomain. In order so choose a theme based in the domain i changed the global.php and added the following lines.

if($_SERVER["SERVER_NAME"] == "m.theandroidblog.de")
{
    // test for the right Usergroup
       if($mybb->usergroup['canmodcp'] == 1)
    {
        // load mobile style
            $loadstyle = "tid='7'";
        // shorten the breadcrumb
            $mybb->settings['bbname_orig'] = "tab";
    }
 
     else{
   // use the normal theme
    $loadstyle = "tid='6'";
     }
    // set the bburl to the mobile subdomain
            $mybb->settings['bburl']= "http://m.theandroidblog.de";
} 


The theme is now only used when the visitor is on the subdomain (and for testing purpos has sufficient rights).

When using the mobile theme i encountered a realy annoying problem. Some links within the board don't work. Thats because mybb uses mybb->settings['bburl'] to build some of these link (search, breadcrumb, ...) Some of these links can be fixed by a plugin and a hook in the relevant php. Also i could change core-files in order to get the right link back. But i would like to keep the code-changes to a minimum. Because of that i set the bburl within the if to the mobile-subdomain and all links are working just fine. The only problem i discovered so far is the german messages.lang.php. If a user posts within the mobile version, the email-notification uses the mobile link. In order to avoid this problem i hardcoded the links in the german message-file and all is fine now.

Internal link are no problem. The get fixed with a plugin.


$plugins -> add_hook('parse_message','staymobile_fixlinks');

function staymobile_fixlinks($m){
if($_SERVER["SERVER_NAME"] == "m.theandroidblog.de")
{
   $m = preg_replace('|http://theandroidblog.de|i', 'http://m.theandroidblog.de', $m);
   $m = preg_replace('|object type="application/x-shockwave-flash" (.*?) value="http\://www\.youtube\.com/v/(.*?)"(.*?)object|smi', '<a href="http://www.youtube.com/watch?v=$2&feature=player_embedded">YouTube Video Link</a>', $m);

}
else
{   
    $m = preg_replace('|http://m.theandroidblog.de|i', 'http://theandroidblog.de', $m);
}

return $m;
} 


Right now, i wonder if i could encounter more problems in this direction and if there would be a more elegant way that gets the links right without setting the bburl. Did anyone else use this bburl methode for a subdomain and found other problems?
Thank you! This has helped me with creating a mobile-only version for my forum. One thing I will add though is the code for global.php should go above where global.php gets the theme from the database, otherwise it does nothing.

I'm also working on a way to replace all images in posts with a link. Here's what I'm using at the mo: http://drupal.org/node/92581