cvs: qaweb /preview/include freeTemplate.class.php functions.php

From: Date: Sun, 21 Oct 2001 01:21:33 +0000
Subject: cvs: qaweb /preview/include freeTemplate.class.php functions.php
Groups: php.qa 
Request: Send a blank email to php-qa+get-3722@lists.php.net to get a copy of this message
bate Sat Oct 20 21:21:33 2001 EDT Added files: /qaweb/preview/include freeTemplate.class.php functions.php Log: Added required Function/Class Index: qaweb/preview/include/freeTemplate.class.php +++ qaweb/preview/include/freeTemplate.class.php <? class freeTemplate { var $templateContent = ""; var $templateLoop = array(); function queryDB ($querystring){ global $db_host, $db_port, $db_user, $db_pass, $db_name; $db = @mysql_connect($db_host.":".$db_port, $db_user, $db_pass) or die(); if ($db) { @mysql_select_db($db_name,$db); $result = @mysql_query($querystring); @mysql_close($db); return $result; } return false; } //queryDB function assignTemplate($filename, $type = 0) { $buffer = ""; if ($type==0 || empty($type)) { if (!@is_file($filename)) { return false; } $this->templateContent = @fread(fopen($filename, "r"), filesize($filename)); return true; } elseif ($type==1 && !empty($filename)) { $result = $this->queryDB("SELECT * FROM $template_table WHERE template_name='$templatename' LIMIT 0,1"); if (mysql_num_rows($result) != NULL) { $buffer_ar = @mysql_fetch_array($result, MYSQL_ASSOC); $buffer = $buffer_ar["template_content"]; mysql_free_result($result); return $buffer; } } return false; } //assignTemplate function printTemplate() { echo $this -> templateContent; return true; } // printTemplate function findLoop($loopname) { if (is_array($loopname)) { for ($x=0; $x<count($loopname); $x++) { eregi("\<!--".strtolower($loopname[$x])."--\>(.*)\<!--\/".strtolower($loopname[$x])."--\>", $this->templateContent, $hits); if (count($hits)==0) { return false; } else { $this->templateLoop[strtolower($loopname[$x])][0] = $hits[0]; $this->templateLoop[strtolower($loopname[$x])][1] = $hits[1]; $this->templateLoop[strtolower($loopname[$x])][2] = ""; } } } else { eregi("\<!--".strtolower($loopname)."--\>(.*)\<!--\/".strtolower($loopname)."--\>", $this->templateContent, $hits); if (count($hits)==0) { return false; } else { $this->templateLoop[strtolower($loopname)][0] = $hits[0]; $this->templateLoop[strtolower($loopname)][1] = $hits[1]; $this->templateLoop[strtolower($loopname)][2] = ""; } } return true; } // findLoop function replaceLoop($loopname) { if (is_array($loopname)) { for ($x=0; $x<count($loopname); $x++) { $this->templateContent = str_replace($this->templateLoop[strtolower($loopname[$x])][0], $this->templateLoop[strtolower($loopname[$x])][2] , $this->templateContent); } } else { $this->templateContent = str_replace($this->templateLoop[strtolower($loopname)][0], $this->templateLoop[strtolower($loopname)][2] , $this->templateContent); } return true; } // replaceLoop function addLoop($loopname) { $this->templateLoop[strtolower($loopname)][2] .= $this->templateLoop[strtolower($loopname)][1]; return true; } // addLoop function parseLoop($oldstring, $newstring = "", $loopname) { $this->templateLoop[strtolower($loopname)][2] = str_replace($oldstring, $newstring, $this->templateLoop[strtolower($loopname)][2]); return true; } // parseLoop function replaceVar($oldstring, $newstring = "") { $this->templateContent = str_replace($oldstring, $newstring, $this->templateContent); return true; } } ?> Index: qaweb/preview/include/functions.php +++ qaweb/preview/include/functions.php <?php /* (c)'2001 by Marco Kaiser (bate@php.net) and the PHP Group */ /* Read an Learn. Any Questions so ask. */ $default_placeholder = array(0 => array("[%TITLE%]", "PHP-QAT: Quality Assurance Team"), 1 => array("[%CURRENT_DATE%]", date("l, F d, Y", time())), 2 => array("[%SITE_UPDATE%]", date("D M d H:i:s Y T", filectime($SCRIPT_FILENAME))) ); $template_array = array("home" => "templates/tmpl_home.html", "projects" => "templates/tmpl_projects.html", "links" => "templates/tmpl_links.html", "members" => "templates/tmpl_members.html", "howtohelp" => "templates/tmpl_howtohelp.html", ); function replace_default(&$class) { foreach ($GLOBALS["default_placeholder"] as $key) { $class->replaceVar($key[0], $key[1]); } return true; } function make_link($string, $text = "") { } ?>

« previous php.qa (#3722) next »