00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 class ThemeEngine
00022 {
00023 var $theme;
00024 var $template;
00025
00026 function ThemeEngine()
00027 {
00028 global $config;
00029
00030 $this->theme = $config->option("theme");
00031 }
00032
00033 function loadTemplate($template)
00034 {
00035 $tpl = $this->theme."/templates/$template.php";
00036
00037 if (file_exists($tpl))
00038 {
00039 require_once "$tpl";
00040 return $template;
00041 }
00042 else
00043 {
00044 return deverror("Unable to open template <b>$tpl</b>!");
00045 }
00046 }
00047
00048
00059 function loadTemplateNew($template)
00060 {
00061 $tpl = $this->theme."/templates/$template.tpl";
00062
00063 if (file_exists($tpl))
00064 {
00065 $file = file($tpl);
00066 foreach ($file as $ln => $line)
00067 {
00068 $this->template[] = trim($line);
00069 }
00070 return null;
00071 }
00072 else
00073 {
00074 return translate("Template $template doesn't exists!");
00075 }
00076 }
00077
00078
00079
00080 function applyTemplate($items, $tags)
00081 {
00082 if (!is_array($this->template) || !is_array($items) || !is_array($tags))
00083 {
00084 return null;
00085 }
00086
00087
00088 $rowloop = false;
00089 $itemloop = null;
00090
00091
00092 for ($l = 0; $l < count($this->template); $l++)
00093 {
00094 $line = $this->template[$l];
00095
00096 if ($line == "<@row_begin>")
00097 {
00098 $rowloop = true;
00099 continue;
00100 }
00101 if ($line == "<@row_end>")
00102 {
00103 $rowloop = false;
00104
00105
00106 }
00107 if ($rowloop)
00108 {
00109 $itemloop[] = $line;
00110 }
00111 }
00112
00113
00114 $rowloop = false;
00115 for ($l = 0; $l < count($this->template); $l++)
00116 {
00117 $line = $this->template[$l];
00118 if ($line == "<@row_begin>")
00119 {
00120 $rowloop = true;
00121 continue;
00122 }
00123 if ($line == "<@row_end>")
00124 {
00125 $rowloop = false;
00126 continue;
00127 }
00128 if ($rowloop)
00129 {
00130 if (!$itemsdone)
00131 {
00132 print "DG: Row loop on line $l<br />";
00133
00134 foreach ($tags as $tag)
00135 {
00136 $search[] = "/<@$tag>/";
00137 }
00138
00139 for ($i = 0; $i < count($items); $i++)
00140 {
00141 print "DG: Item $i<br />";
00142 print dprint($items[$i]);
00143 $block = null;
00144
00145 $count = preg_match('/\<@item\>/', implode("\n", $itemloop), $match);
00146 print "$count<br />";
00147 for ($c = 0; $c < $count; $c++)
00148 {
00149
00150 $replace = $items[$l];
00151
00152
00153 $block .= preg_replace($search, $replace, $itemloop, 1);
00154 $l++;
00155 }
00156 $buf .= $block;
00157 }
00158 $itemsdone = true;
00159 }
00160 }
00161 else
00162 {
00163 $buf .= $line;
00164 }
00165 }
00166 print htmlentities($buf);
00167 }
00168
00169 }
00170 ?>