PHP includes in header.tpl

Posted by ra 
Re: PHP includes in header.tpl
July 22, 2006 10:28AM
> because the template file is cached in ./tmp dir, so one has to point to the file to include with a relative path since there.

wrong, its included in the phorum-files, which means that it needs to be relative to the phorum-directory.

for the other stuff I don't get what you are saying. if you are overwriting variables used in the templates than it breaks. all the includes and phorum-code itself runs in the same namespace and not inside functions.


Thomas Seifert
Re: PHP includes in header.tpl
July 22, 2006 10:37AM
I would like it should be this way, but I didn't arrive to include through a relative path to the phorum-directory. Each time I get an error message "no such file in ./tmp/header-cached-file in line x" or something like this.

About the variables issue I am not so sure as I haven't included through a relative path, but in a http-path inclusion, I couldn't acces my external-header variables.
Re: PHP includes in header.tpl
July 22, 2006 10:51AM
http-path inclusion is simply a no-no.
it can only include the *executed* code this way, not the code in the files itself.
therefore you will never see any variables in there.

yeah, no such file in /tmp/header... is correct as its include in this file.
but it still remains, it needs to be relative to the phorum-directory (not the template-directory and not the tmp-directory) and I'm completely sure about it as I'm doing this each day.


Thomas Seifert
Re: PHP includes in header.tpl
July 22, 2006 01:33PM
Fine! Thanks a lot, it saved me some heavy parsing I was doing to pass the forum-header-data before sending the forum pages to the screen. Indeed I was trying to include relative to the template-directory. The inclusion relative to the phorum directory works very well.

>> You said : "and phorum-code itself runs in the same namespace and not inside functions"

That is true if not in portable-mode. While embedded through portable, in potable/phorum.php there is a function phorum_namespace which includes any phorum page. As this function is all what is doing, I had to slightly modify it so portable code doesn't uses it any more and this way I have acces to all my external variables.

if(file_exists("./$page.php")){
    phorum_namespace($page);
}

// create a namespace for Phorum
function phorum_namespace($page)
{
    global $PHORUM;  // globalize the $PHORUM array
    include_once("./$page.php");
}

became

if(file_exists("./$page.php")){
    include_once("./$page.php");
}

It seems to work with no further problems but do you think this breaks the phorum core code ?
Re: PHP includes in header.tpl
July 22, 2006 02:19PM
I don't think this will cause problems. The reason for putting this into its own namespace, is to prevent collisions with the code that is around the portable Phorum. If your system and Phorum do not share variable names, you're safe.

What is crippled in your setup, is that you print a header and footer at all time from your portable script. I told you before that this will cause problems, but you still seem to do this. When doing this, you will seriously break file.php and rss.php functionality. I suggest that you put a very clear marker in header.tpl and footer.tpl, so you can replace those markers from your portable code with your site's header and footer HTML code. This way, you won't show a header if Phorum doesn't show one either.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: PHP includes in header.tpl
July 23, 2006 02:44AM
Maurice, You didn't undesrtand me at all. It is because I agree with you on the best way to embedd phorum (through phorum header/footer templates) that I came to look for a solution to my inclusion problem. I was embedded phorum in portal script (myheader - include phorum - my footer) because I could not include myheader/footer in the phorum templates. See above my first message about the inclusion path wich was resolved after Thomas' explanations. And now everything is working as you say, I had just to make this little change to potable/phorum.php, otherwise I haad to globalise all my external variables in the phorum_namespace function. So don't worry any more. Thanks to you two. Next step, I'll try your BBcode/smileys module to see if now it works without the path corrections that I had to do in order to make it work. This is an other discussion that we'll continue in its appropiatie tree at the modules forum.
Re: PHP includes in header.tpl
July 23, 2006 05:35AM
I think in return that you don't understand me at all. I know that your header and footer cannot go into the forum templates for some reason, but that will make you run into problems that you can prevent. What I suggest is to use something like <!-- show header --> and <!-- show footer --> in respectively the header and footer template of Phorum. Since you already buffer the output and use a callback function to fix some stuff in Phorum's output, you could as well take out your header and footer outside the buffer and print those in the callback if needed. As pseudo code:
start buffer
  run phorum
end buffer and run callback function

function callback {
   do your modifications on $buffer

   if ($buffer contains "<!-- show header -->") 
      print your header

   print $buffer

   if ($buffer contains "<!-- show footer -->") 
      print your footer
}


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: PHP includes in header.tpl
July 23, 2006 06:38AM
I agree it's more clear this way, I didn't thought about pseudocode as a manner to include the entire myheader/footer, but it is nearly what I was doing with a callback function to (preg)replace the phorum header metatags to myheader headzone. But there is no further need of this as, after the fix of the inclusion path, I can now include properly myheader/footer in the phorum-header-template.

Of course once a problem resolved, it leads to another one: as I deleted the phorum_namespace function (see above) and I'm working to an integration with Authentication (your script System for embedding Phorum in other applications), I meet problems with common names variable "$user" wich is used as well by phorum as by my site. The way I see to bypass this problem is either rename all occurences in phorum of $user to $phorum_user or do the same thing in all around my site and rename $user to $mysite_user. Neither one is satisfactory. Do you see something better ?



Edited 1 time(s). Last edit at 07/23/2006 08:28AM by milos.
Sorry, only registered users may post in this forum.

Click here to login