PhpDig.net

PhpDig.net (http://www.phpdig.net/forum/index.php)
-   Mod Submissions (http://www.phpdig.net/forum/forumdisplay.php?f=24)
-   -   Apache includes in a template (http://www.phpdig.net/forum/showthread.php?t=1011)

sgreen 06-17-2004 03:44 PM

Apache includes in a template
 
Here is a quick mod that lets me put server-side includes in a template file -- it emulates the Apache <!--#include virtual= ... --> directives in server-parsed HTML files.

For example, In a template file I can put:

<phpdig:inclucde virtual="/foo.html" />
to include a file containing a block of html
or
<phpdig:inclucde virtual="/cgi-bin/bar.pl" />
to include the output of a cgi program, in this case the output of a perl script named bar.pl. I haven't tried it, but I assume that you could include php output the same way.


Here is the mod to libs\function_phpdig_form.php that makes it work:

Change the lines:

PHP Code:

       if ($in_loop == 0) {
           print 
phpdigParseTags($line,$t_strings);
       } 

to:

PHP Code:

       if ($in_loop == 0) {
           if (
ereg('^[ ]*<phpdig:inclucde[ ]+virtual[ ]*=[ ]*[\"\']([^\"\\']+)["\'][ ]*/>(.*)', $line, $regs)) {
               virtual($regs[1]);
               $line = $regs[2];
               }
           print phpdigParseTags($line,$t_strings);
       } 

Note that the code above probably word-wrapped here, the ereg call with the big ugly regular expression should be all on one line. Also, I seem to be fighting the BBS software that displays these posts -- it dropped some of my \ charcters -- the middle part uf the expresion should look like [\"\ ']([^\"\ ']+)[\"\ '] but without the blanks before the single quotes.

This method only works on sites where php's virtual() function works -- that means only on Apache servers, and they must be running php as a plugin, not as a cgi program.

This mod has worked for me on:
Win/XP + Apache 2.0.45 + Php 4.3.7
FreeBSD + Apache 1.3.27 + Php 4.3.4

If you don't provide a rooted path to the included file, its path will be relative to $relative_script_path.

My implementation has some restrictions that could probably be fixed by someone with a better understanding of php and the PhpDig code:

The <phpdig:inclucde ...> tag must be at the start of line, nothing but blanks should precede it.

It can't go inside a <phpdig:results> loop.

Thanks to everyone involved with PhpDig; it looks like it will be a great addition to my website. I'd appreciate any feedback or corrections for the mod.

Regards,
Steve Green


All times are GMT -8. The time now is 03:53 PM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.