Firefox PHP

Docs doesn't say how templates are called?

Posted by tobefound 
Docs doesn't say how templates are called?
January 28, 2010 09:34AM
Hi,

I read the dev docs for templating and it says:

"An example: if Phorum wants to display the "header" template, it will first search for header.php in the template directory. If that file does not exist, it will use header.tpl instead."

If I want to tell Phorum not to include the header template, then how to proceed? Cause I'd hate to see if Phorum forces me to use templates by fixed names and conventions?

I was hoping there was a starting template from which all the other templates were called. At least for the header and footer part anyway.

/T
Re: Docs doesn't say how templates are called?
January 28, 2010 09:42AM
No, thats fixed. The template names used internally can't be changed.


Thomas Seifert
Re: Docs doesn't say how templates are called?
January 28, 2010 11:15AM
I think your use case is a bit / very unclear to me. Why would you hate Phorum forcing you into using certain template names? How else would it work in your opinion? Use a config file that says "header: myspecialheader" to provide a mapping of some sort? That would be strange, but it sounds like that is what you are asking for.

If you do not want to include the header template, then why exactly would you want to do that? We have cases like that too, like when we send an attachment file to the browser or when providing the javascript or CSS code. For those cases, it makes sense. When outputting standard forum pages, it does not really make sense to me to not include the header.

If you want to not output some header data in some special (or maybe any) case, then you can tweak the header template to do that. We'd be glad to advice you on what the options are, but only a remark about you hating Phorum for forcing you into something does not really help us in finding out what it is that you are after.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Docs doesn't say how templates are called?
January 28, 2010 02:26PM
I'm not hating Phorum. :) Phorum rocks so far apart from some undocumented aspects!

I'm used to getting a quick code base overview - therefore I was hoping to see the template entrypoint with all its conditional branches as to make it easier for me to see what I must integrate and not.

The impression I have so far is that Phorum has not been designed to be implemented/integrated as a component of an already existing webpage. Rather, it acts as the core/only component of a website and in many cases this is as it should.

From the community and the code base I understand efforts have been made to accomodate the post-integration need but I was kind of hoping it was extremely portable/pluggable. As it is now, things could end up very hacky. A typical use case for what I'm after in this case would be:

Language: PHP
//index.php - could be the entrypoint of a very able PHP framework like CodeIgniter or //the entrypoint of a solid full-fledged website   include(';my_header.php';); include(';my_top.php';); include(';my_content.php';); include(';my_footer.php';);

Instead of including the standard my_content "template" I would like to fill this gap with Phorum. Now, simply outputting whatever comes from the domain.com/phorum url gives me header-aches if you see what I mean. :) And to me this must be a very common use case but I could not find any docs on how to do it. Sure, I can strip the header and footer from the templates my self, but then again, I don't know what code is required or not.

Also, just to further illuminate things: in the template folder I have files called index_new.tpl and index_classic.tpl. When to use which for what? It's a cumbersome job having to go through all the templates just to see if they match my current webpage (when traversing all possible action/links on the phorum). An entrypoint or a "map" describing the loaded templates would have helped. Just my $0.05.

If there is a way to accomplish this forum inclusion in an existing webpage (and I'm sure there is), please advise. And thanks for taking the time to respond! Much appreciated.

/T
Re: Docs doesn't say how templates are called?
January 28, 2010 05:16PM
You cannot simply leave the header out of the code, since that is also where javascript code, CSS code and things like page redirects are loaded. When leaving out the header, the body will end up very broken. I have once written a Phorum 5.2 based integration module, that used special templates for this, where is was possible to pass on things like the CSS and javascript to the container CMS / framework to eventually put it in the page output at the correct places. I get your idea, but things like this make it more complicated. For an idea of what is needed, you could lookup the embed_phorum module and look at the code.

As for a template description: there is none in the documentation (yet), but some effort was done. Maybe you find this wiki page useful: [trac.phorum.org]


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Docs doesn't say how templates are called?
January 28, 2010 05:42PM
There are a number of different ways that phorum can be incorporated into other websites and which method is best is determined somewhat by the software that you are using and the amount of flexibility that it gives you. The "Look and Feel" are incorporated in the header.tpl, footer.tpl and css.tpl templates, so these are the ones that most people would need to change to get a similar look to the rest of their site. The various index templates are there to produce the "classic" view like phorum 3 versus a "cleaner" look of the new index (one or the other is picked from the admin pages). If you want to further change how things look on individual pages, then some other templates might need to be modified (The source for the generated html pages will have comments on where the individual templates begin and end for easier tracking down where things need to be changed)

For integrating, the main thing you have to worry about in the header.tpl file is what to do with the head section (between head tags). If your main program takes care of generating this portion of the output page, you can remove these lines of code from the header.tpl - but you might have to add the phorum info to your head section. The footer.tpl basically handles putting the closing tags on the output page.

In my setup, I use the portable wrapper to embed phorum in the website.
Re: Docs doesn't say how templates are called?
February 02, 2010 08:00AM
@DavidVB:

Just curious, how did you find out about the portable wrapper in the first place?

@all:

I've managed to modify the header and footer templates to my liking and its look-and-feel now correspond to my website's.

What I've done is this:

Access to my subpages: domain.com/folder/<subpages>

Phorum has been placed here: domain.com/phorum

This means I simply run the phorum the way it was installed (with some admin changes of course) and it also means that there is no direct integration (besides changing the header and footer templates).

Now, when a user of my website wants to login, which can take place in any subpage as I have my login form in my header file, I would like to login the user to the phorum system as well, all in one go.

The API docs (http://www.phorum.org/docs/html/api/__examplesource/exsource_s_phorum5-docs_include_api_examples_user_login.php_7f899d2ceefd744ae047286ae7cff51e.html) suggests this:
if (!defined('PHORUM')) return;
 
require_once("./include/api/base.php");
require_once("./include/api/user.php");
 
// Check the username and password.
$user_id = phorum_api_user_authenticate(
    PHORUM_FORUM_SESSION,     // for a standard front end forum session
    "username",               // the username to check
    "password"                // the password to check
);

if (!$user_id) die("Username or password incorrect!\n");
 
// Make the authenticated user the active user for Phorum. This is all
// that is needed to tell Phorum that this user is logged in.
$set_active = phorum_api_user_set_active_user(
    PHORUM_FORUM_SESSION,     // for a standard front end forum session
    $user_id,                 // the user_id that has to be the active user
    PHORUM_FLAG_SESSION_ST    // jumpstart the short term session
);

if (!$set_active) die("Setting user_id $user_id as the active user failed!\n");
 
// Create a session for the active user, so the user will be remembered
// on subsequent requests.
phorum_api_user_session_create(
    PHORUM_FORUM_SESSION,     // for a standard front end forum session
    PHORUM_SESSID_RESET_LOGIN // reset session ids for which that is
);                            // appropriate at login time

Question 1: is that all it takes to authenticate a phorum user from an external page? No need to load common.php or anything? If so, that's great!

Question 2: If possible, it would be great if I didn't have to maintain duplicate user tables just focusing on authentication on my existing system and simply update the session table in phorum db? Is that possible?

/T
Re: Docs doesn't say how templates are called?
February 02, 2010 08:20AM
1) If you want to authenticate the user and pass on that user to Phorum, then this is not the way. The user_session_restore hook is perfect and designed for that task.

2) No, Phorum needs the user table to contain the available users. There's more than only session data (e.g. user settings).


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Docs doesn't say how templates are called?
February 02, 2010 08:27AM
Thx, I'll look #1 up.
Re: Docs doesn't say how templates are called?
February 02, 2010 02:54PM
The portable wrapper was something we used in Phorum 3 and I was stubborn enough to keep using that.

Quote

Question 2: If possible, it would be great if I didn't have to maintain duplicate user tables just focusing on authentication on my existing system and simply update the session table in phorum db? Is that possible?

If all you are doing with your user table is to authenticate the user, it would be simpler to just use phorum for all the registration/login actions. There is an authenticate user program that would allow your other pages to check and see if someone is logged in. If you need to store additional information, you can add custom fields for the phorum user.
Sorry, only registered users may post in this forum.

Click here to login