ATutor

Learning Management Tools







Pages:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15


Theme based on urldomain code


  • 2008-10-07 11:23:56

    Theme based on urldomain code

    So, I needed to have a theme based on the ulr, as we have different clients using different urls and they each want a different template...naturally. The modifications are pretty simple and only require you have the ServerName set in your web server config file for each url and to change 3 ATutor files and create one new one:

    New file) include/set_theme_by_url.inc.php Sample contents:

    session_start();
    if(!$_SESSION['prefs']){
    $_SESSION['prefs']=array();
    }

    switch($_SERVER['SERVER_NAME']){
    case "flintstones.mydomain.com":
    $_SESSION['prefs']['PREF_THEME']="flintstones";
    $_SESSION['prefs']['not_default_theme']=1;
    define('SITE_NAME',"Flintstones Training");
    break;
    default:
    $_SESSION['prefs']['PREF_THEME']="jetsons";
    $_SESSION['prefs']['not_default_theme']=1;
    define('SITE_NAME',"Jetsons Training");
    break;
    }

    1) include/config.inc.php, at the very bottom, add:
    include("set_theme_by_url.inc.php");

    2) include/vitals.inc.php, add the same as above right after the session_start() call on or about line 97

    3) include/header.inc.php, add the same as above on or about line 45 (after the three savant calls) and change

    $savant->assign('base_tmpl_path', $_SERVER['HTTP_HOST']);

    to:

    if($_SESSION['prefs']['not_default_theme']==1){
    $savant->assign('base_tmpl_path', $_base_path . '/themes/'. $_SESSION['prefs']['PREF_THEME']);
    }else{
    $savant->assign('base_tmpl_path', $_SERVER['HTTP_HOST']);
    }

    Then, at the bottom where it says:

    $savant->display('themes/'. $_SESSION['prefs']['PREF_THEME'] .'/include/header.tmpl.php');

    change that to:

    if(substr_count($_SERVER["REQUEST_URI"],"/")>1){//then it's a subdir
    $savant->display('include/header.tmpl.php');
    }else{
    $savant->display('themes/'. $_SESSION['prefs']['PREF_THEME'] .'/include/header.tmpl.php');
    }


    I think that's it. I call define('SITE_NAME') in the new include file, so it's invoked before the same call in vitals.inc.php and won't get reset. Now the site theme will be constant, regardless of course theme, etc.

    Let me know if anyone has any questions or suggestions to make it better.

  • 2008-10-07 12:10:19

    Re: Theme based on url/domain code

    Hi there!

    A quick scan through your code:
    1. You shouldn't need to include your custom file into three separate files; include/vitals.inc.php alone should suffice as every other file in ATutor loads it at the very beginning. It may be a corollary of the #3 issue below.
    2. I'd probably be saving directly to $_SESSION['not_default_theme'] since the $_SESSION['prefs'] array is per-user settings.
    3. The third chunk is doubtful: I don't see right on the spot what does it do. Looks like the second replacement is largely undoing what the first one has done. I would need to see the code to understand what you're doing there.
    4. Purely programming style issue: set 'not_default_theme' to FALSE before that switch statement and if there's match, set it to TRUE. You're using it as a flag, so it should be a boolean type. And setting it to FALSE saves you from ever-growing number of "unset variable" warnings in a log.

    Again, that's a quick scan, I didn't see it in work or the code it's supposed to be implanted to.

    I'd suggest you to repost this change to the http://atutor.no blog -- there's a bunch of similar changes there which, due to the peculiar nature of the problems they solve, won't probably go into the ATutor trunk but are quite interesting by themselves.

  • 2008-10-07 12:39:11

    Re: Theme based on url/domain code

    Hi,

    thanks for the feedback.

    I didn't think I'd need to include the file in 3 places, either, but it seemed like I did have to. Spent a bit more time looking at it, though, and found that I don't need the include in all three files if I change the two lines in vitals.inc.php that say:

    $_SESSION['prefs']['PREF_THEME'] = $default_theme['dir_name'];

    to:

    if(!$_SESSION['prefs']['PREF_THEME']){$_SESSION['prefs']['PREF_THEME'] = $default_theme['dir_name'];}

    With that change, I can take out the includes in the other files.

    Good catch on the boolean flag. Setting it to false first...missed it in my haste to get it working before a client demo.

    Since we won't have user-set themes, I set the theme in the prefs array, as that was where I saw the theme set and referred to in the bulk of the code.

    The third chunk fixes include paths when in a subdir. Didn't figure I'd need that, either. When removed, the layout is broken.

    I'll look at the atutor.no blog. Didn't know it existed.

    Thanks,
    Mike