| 
<?php/*
 DynamicTemplate v1.1 - DynamicTemplate.php4 v1.1 2007/03/07
 
 This class enables you to insert the body of a web page into your website.
 More precisely, it wraps your website's look (or template) around the desired web page.
 
 Copyright (c) 2007 DAKEDO
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License along
 with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 designer:    DAKEDO, Online Shopping Mall
 url:        http://www.dakedo.com
 download:     http://www.dakedo.com/blogs/27/2007/02/blogger-integration.html
 email:        [email protected]
 */
 
 class DynamicTemplate {
 var $page, $globals;
 
 
 function DynamicTemplate() {
 }
 
 
 function loadTemplate($templateFile, $globals = array()) {
 $this->globals = $globals;
 $this->page = $this->load($templateFile);
 }
 
 
 function output() {
 //get the page to insert
 $file = $_GET['file'];
 
 if (isset($_GET['language'])) $language_code = $_GET['language'];
 else $language_code = '';
 
 $path = ($language_code!=''?$language_code . '/':'');
 
 //if the file doesn't exist, die
 if ( ($file != '') && (!file_exists($path . $file)) ) die("wrong file name!");
 
 $included_file = $this->get_File_To_Include($path, $file);
 
 if ($included_file === false) die("page not found!");
 
 $buffer = $this->load($included_file);
 
 $page_head = $this->getHead($buffer);
 
 $page_body = $this->getBody($buffer);
 
 unset($buffer);
 
 $this->mergeHead($page_head);
 
 $this->mergeBody($page_body);
 
 echo $this->page;
 }
 
 
 function load($file) {
 
 //globals that need to be defined in the template
 foreach ($this->globals as $global) eval("global \$" . $global . ";");
 
 //start output buffering
 ob_start();
 
 require $file;
 
 //get everything into a variable
 $buffer =  ob_get_contents();
 
 //stop the buffer output
 ob_end_clean();
 
 return $buffer;
 }
 
 
 function getBody($page) {
 $body_tag_pos = strpos($page, "<body");
 $body_tag_end_pos = strpos($page, ">", $body_tag_pos);
 $body_end_pos = strpos($page, "</body>");
 return substr($page, $body_tag_end_pos + 1, $body_end_pos - 1 - $body_tag_end_pos);
 }
 
 
 function getHead($page) {
 $head_pos = strpos($page, "<head>");
 $head_end_pos = strpos($page, "</head>");
 return substr($page, $head_pos + 6, $head_end_pos - 6 - $head_pos);
 }
 
 
 function mergeBody($page_body) {
 
 //insert the body of the page into the template
 $this->page = str_replace("<\$DynamicTemplateBody\$>", $page_body, $this->page);
 
 $this->processBody($page_body);
 
 //Copyright announcement (html comment, not visible on the web page of course)
 //This announcement complies with section 2c of the GNU General Public License (GPL) and thus can not be removed.
 $this->page = eregi_replace('(<body[^<^>]+>)',"\\1\r<!--\r"  . $this->copyright() . "\rDynamicTemplate V1.0\rCopyright (c) 2007 DAKEDO\rReleased under the GNU General Public License\rurl:           http://www.dakedo.com\rfree download: http://www.dakedo.com/blogs/27/2007/02/blogger-integration.html\r" . "-->\r" ,$this->page);
 }
 
 
 function mergeHead($page_head) {
 
 $this->page = str_replace("<head>", "<head>\r" . $page_head, $this->page);
 
 //p {...margin:0;...} (in the header)
 $this->page = eregi_replace('((p[ ]+\{[^}]*)margin:[0-9]+[;]*([^{]+\}))','\\2\\3',$this->page);
 
 //a:link {..text-decoration:underline;...}
 $this->page = eregi_replace('((a:(link|visited|hover|active)[ ]+\{[^}]*)text-decoration:underline[;]*([^{]+\}))','\\3\\4',$this->page);
 
 //remove body {..} so that there be no interference with mine
 $this->page = eregi_replace('(body[ ]*{[^{^}]+})','',$this->page);
 
 $this->processHead($page_head);
 }
 
 
 }
 ?>
 
 |