1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
|
<?php
class tpl {
var $templates = array();
var $subvariablepackid = 0;
var $templatefolders = array();
var $imagefolders = array();
var $images = array();
/* constuctor */
function tpl($templatepackid=0,$subvariablepackid=1,$prefix="") {
global $db, $n;
$this->subvariablepackid = $subvariablepackid;
if(!$templatepackid) $this->templatefolders[] = $prefix."templates";
$result = $db->query("SELECT * FROM bb".$n."_templatepacks");
while($row = $db->fetch_array($result)) $templatepacks[$row['templatepackid']] = $row;
while($templatepackid != 0) {
$this->templatefolders[] = $prefix.$templatepacks[$templatepackid]['templatefolder'];
if($templatepacks[$templatepackid]['parent_templatepackid']==-1) {
$this->templatefolders[] = $prefix."templates";
break;
}
else $templatepackid = $templatepacks[$templatepackid]['parent_templatepackid'];
}
$result = $db->query("SELECT * FROM bb".$n."_subvariablepacks LEFT JOIN bb".$n."_subvariables USING (subvariablepackid) WHERE variable = '{imagefolder}'");
while($row = $db->fetch_array($result)) $subvariablepacks[$row['subvariablepackid']] = $row;
$varlist = "''";
while($subvariablepackid != 0) {
$this->imagefolders[] = $subvariablepacks[$subvariablepackid]['substitute'];
$subvariablepackid = $subvariablepacks[$subvariablepackid]['parent_subvariablepackid'];
}
}
/* get template */
function get($templatename) {
if(!isset($this->templates[$templatename])) {
if( for ($j=0;$j<count($this->templatefolders);$j++) {
if(file_exists($this->templatefolders[$j]."/$templatename.tpl")) {
$this->templates[$templatename]=str_replace("\"","\\\"",implode("",file($this->templatefolders[$j]."/$templatename.tpl")));
break;
}
}
}
return $this->templates[$templatename];
}
/* print template */
function output($template) {
headers::send();
$template = $this->replacevars($template);
print($template);
}
/* replace vars */
function replacevars($template) {
global $db, $n, $pmpopup, $PHP_SELF;
$hash="";
if(strstr($template,"<title>")) {
$hash = md5(uniqid(microtime()));
$x = strpos($template,"<title>");
$y = strpos($template,"</title>");
$temp = substr($template,$x,$y-$x+8);
$template = substr($template,0,$x) . $hash . substr($template,$y+8);
}
preg_match_all("/(\{imagefolder\})\/([^\"\?\&]*\.(gif|jpg|jpeg|bmp|png))/siU", $template, $matches);
for($j=0; $j<count($matches[0]); $j++) {
if(!isset($this->images[$matches[2][$j]])) {
for ($k=0;$k<count($this->imagefolders);$k++) {
if(file_exists($this->imagefolders[$k]."/".$matches[2][$j])) {
$this->images[$matches[2][$j]] = $this->imagefolders[$k]."/".$matches[2][$j];
break;
}
}
}
$tmp = $matches[1][$j]."/".$matches[2][$j];
$template = str_replace($tmp,$this->images[$matches[2][$j]],$template);
}
$result = $db->query("SELECT variable,substitute FROM bb".$n."_subvariables WHERE subvariablepackid = '".$this->subvariablepackid."'");
while($row = $db->fetch_array($result)) {
if(isset($row['variable']) && $row['variable'] && isset($row['substitute'])
&& $row['substitute']) {
switch($row['variable']) {
case "<body":
$template = $this->str_replace($row['variable'],$row['substitute'],$template); break;
case "{css}":
$template = $this->str_replace($row['variable'],$row['substitute'],$template); break;
case "{cssfile}":
$template = $this->str_replace($row['variable'],$row['substitute'],$template); break;
case "{imagelogo}":
$template = $this->str_replace($row['variable'],$row['substitute'],$template); break;
case "{!DOCTYPE}":
$template = $this->str_replace($row['variable'],$row['substitute'],$template); break;
case "{imagefolder}": break;
default:
$template = str_replace($row['variable'],$row['substitute'],$template);
}
}
}
if($hash!="") $template = str_replace($hash,$temp,$template);
return $template;
}
function str_replace($search,$replace,$text) {
if(strstr($text,$search)) {
$x = strpos($text,$search);
return substr($text,0,$x) . $replace . substr($text,$x+strlen($search));
}
else return $text;
}
}
?> |