Help with website - why code like this?

Status
Not open for further replies.

ButtermilkJack

New Member
I've been given a site to maintain and after looking through the code it all looks very strange to me. Just wondering if anyone could enlighten me as to the pros of using code like this. I've never seen a site built this way before?

First of all, every page on the site is made up of a basic php template file using only includes. For example...

<?
ob_start();
?>

%%HEADER%%
<table border=0 align=center cellpadding=5 width=100% cellspacing=0>
<tr>
<td height=35 class='body'>Office Furniture</td>
</tr>
<tr>
<td class='ref'>%%OFFICEFURNITURE%%</td>
</tr>
</table>
%%FOOTER%%

<?
$template = ob_get_contents();
ob_end_clean();

include "includes/Header.inc.php";
include "includes/OfficeFurniture.inc.php";
include "includes/Menu.inc.php";
include "includes/Footer.inc.php";

echo $template;

?>
So, every page has 2 files. One is the php template, and the other is the php content (or include). I've seen this type of set-up before, but the includes are quite strange themselves (to me anyway) in that each line of code is preceeded with '$TEXT .='. Why would simple html be coded in this way if that's all they want to 'include'?

<?
$TEXT = "";
$TEXT .= "<table border=0 cellpadding=2 width=100% cellspacing=0>\n";
$TEXT .= " <tr>\n";
$TEXT .= " <td valign=top width=35%>\n";
...
 

Forbairt

Teaching / Designing / Developing
ok ... to me the

Code:
$TEXT = "";

looks a bit strange

Are there any files that get specific things done to the $TEXT ? ... that is returned ?

If not it looks like another case of a self taught php scripter :D ... (is also guilty of some atrocities in his time ... hopefully a few years+ ago) :D
 

louie

New Member
They look like .tpl template files to me or there is a str_replace function somwhere in the code.
 

ButtermilkJack

New Member
They look like .tpl template files to me or there is a str_replace function somwhere in the code.
Yes, there is reference to str_replace at the bottom of the include file...
$template = str_replace("%%OFFICEFURNITURE%%", $TEXT, $template);
The top snippet of code above is the full code for the template file, which is .php, and the include file (also .php) is all html apart from that line above?
 

louie

New Member
so it is a template and is using str_replace to change the text from the buffer
PHP:
$template = ob_get_contents();
 

ButtermilkJack

New Member
What would be the reason for this? My experience doesn't extend beyong basic html/css so I can't see why use the extra code for a few lines of html. Is there an advantage?
 

louie

New Member
Whoever design that website tried to make use of templates to make it easier to update certain part without editing all the pages, but it is way out of date and it is similar to include or required php function.
 

Forbairt

Teaching / Designing / Developing
Basically ... you have a header and a footer lets say ...

Now you want to have custom Meta content in your description / keywords ... but you won't know what that is .. until the main body of your content ...

Doing it this way ...

You basically create the whole page .. then go back and do a string replace ...

It means lets say 1 database query .. instead of a database query at the very start ... then potentially another one further down .. having to fix up custom header / footers and so on

That'd be my take on it at any rate

I've rarely put this type of thing into operation I'm unaware of the overheads on a bigger site.
 

ButtermilkJack

New Member
Yeah, when I initially looked at the code I thought it was some way of pulling content from a db or something. But then I noticed they were using php includes, and that all the content was in an 'includes' folder in the root, so I couldn't understand what seemed like duplication to me.

Anyhow, if it's an outdated practice I won't worry about trying to get to grips with it :)

Thanks folks!
 
Status
Not open for further replies.
Top