skip to main content

kiesler.at
You are NOT logged in. ( login | New Account Signup | Forgot Your Password? ) Why log in?

Theme-choosing for anonymous users
updated by rck, 2004-10-26

So you want to show your phpWebSite themes to anonymous viewers as well? That's not possible out of the box, as Layout, the module which is responsible for Themes, supports only logged in users. Well, it's possible now, some hours hacking later...

                     
1 | 2

Where to look

Actually, the process as such is rather straight forward. First, we modify the dispatcher of layout. In index.php (found in mod/layout), add something like the following near the very top, after the nullification of content and title.

1 if(isset($_REQUEST["theme"])) {
2         if($_REQUEST["theme"]=="emotions")
3                 $_SESSION["OBJ_layout"]->overrideLayout("Emotions");
4         else
5         if($_REQUEST["theme"]=="polar")
6                 $_SESSION["OBJ_layout"]->overrideLayout("Polar");
7         exit();
8 }

yes, you are limited to the themes you enter here. And that's good that way, as I don't check, wether a chosen Theme exists. And: You can limit the themes that are available to anonymous users.

By the way, you could change $_REQUEST to $_POST, if you were to support only submitted post-forms. Or to $_GET, if you were to support only get parameters, the one that can follow a url with ?parameter=value.

Our workhorse

The dispatcher of course delegates the work to someone else. To the overrideLayout() method, which is still to be written. Let's include it somewhere in Layout.php, preferrably above initializeLayout(). In fact, initializeLayout() does "more of the same", a couple of checks for example. I've skipped them, you might want to include them.

1 /**
2  * override Layout...
3  * like initializeLayout, but works for anonymous Users
4  * as well. Sets the current theme for the current session
5  *
6  */
7 
8 function overrideLayout($theme) {
9 
10         /* registered users will be
11            treated differently */
12 
13         if($_SESSION['OBJ_user']->user_id>0)
14                 $_SESSION["OBJ_user"]->setUserVar("theme",
15                         $theme, NULL, "layout");
16 
17         list($result) =
18                 $GLOBALS["core"]->sqlSelect("mod_layout_config");
19         PHPWS_Template::refreshTemplate("layout");
20 
21         $this->ordered_list     = $this->themeVarList = NULL;
22         $this->row_col          = $this->content_array = NULL;
23         $this->current_theme    = $theme;
24 
25         $this->theme_dir        = PHPWS_HOME_DIR . "themes/$theme/";
26         $this->box_dir          = $this->theme_dir . "boxstyles/";
27         $this->theme_address    = "themes/$theme/";
28         $this->box_address      = $this->theme_address . "boxstyles/";
29 
30         header("location:.");
31   }

                     
1 | 2
Where to look
Showing off



RSSComments - Make a comment
The comments are owned by the poster. We are not responsible for its content.
RSSAll Articles
2008, 2007, 2006, 2005, 2004