summary refs log tree commit diff stats
path: root/includes/template.php
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2008-11-19 17:27:03 -0500
committerStarla Insigna <hatkirby@fourisland.com>2008-11-19 17:27:03 -0500
commit24503e3abe705acde2df159aeae61be0d009f92e (patch)
tree8debbd53dcd0db2f5934c5e2af4e697e3787781d /includes/template.php
downloadfourisland-24503e3abe705acde2df159aeae61be0d009f92e.tar.gz
fourisland-24503e3abe705acde2df159aeae61be0d009f92e.tar.bz2
fourisland-24503e3abe705acde2df159aeae61be0d009f92e.zip
Imported sources
Diffstat (limited to 'includes/template.php')
-rw-r--r--includes/template.php164
1 files changed, 164 insertions, 0 deletions
diff --git a/includes/template.php b/includes/template.php new file mode 100644 index 0000000..d777475 --- /dev/null +++ b/includes/template.php
@@ -0,0 +1,164 @@
1<?php
2/*
3 444444444
4 4::::::::4
5 4:::::::::4
6 4::::44::::4
7 4::::4 4::::4 Four Island
8 4::::4 4::::4
9 4::::4 4::::4 Written and maintained by Starla Insigna
104::::444444::::444
114::::::::::::::::4 includes/template.php
124444444444:::::444
13 4::::4 Please do not use, reproduce or steal the
14 4::::4 contents of this file without explicit
15 4::::4 permission from Hatkirby.
16 44::::::44
17 4::::::::4
18 4444444444
19*/
20
21if (!defined('S_INCLUDE_FILE')) {define('S_INCLUDE_FILE',1);}
22
23require('headerproc.php');
24
25class FITemplate
26{
27
28 var $file;
29 var $tags;
30 var $blocks;
31 var $refs;
32
33 function FITemplate($filename)
34 {
35 $tfn = 'theme/' . $filename . '.tpl';
36 if (file_exists($tfn))
37 {
38 $this->file = $tfn;
39 } else {
40 throw new Exception($tfn . ' does not exist');
41 }
42 }
43
44 function add($name, $value)
45 {
46 $this->tags[$name] = $value;
47 }
48
49 function adds($tagarr)
50 {
51 foreach ($tagarr as $name => $value)
52 {
53 $this->add($name,$value);
54 }
55 }
56
57 function adds_block($block, $tagarr)
58 {
59 if (!isset($this->blocks[$block]))
60 {
61 $this->blocks[$block] = array('count' => 1);
62 }
63 foreach ($tagarr as $name => $value)
64 {
65 $this->blocks[$block][$this->blocks[$block]['count']][$name] = $value;
66 }
67 $this->blocks[$block]['count']++;
68 }
69
70 function add_ref($id, $block, $tagarr)
71 {
72 $this->adds_block($block,$tagarr);
73 $this->refs[$id] = &$this->blocks[$block][$this->blocks[$block]['count']-1];//'$this->blocks[\'' . $block . '\'][' . ($this->blocks[$block]['count']-1) . ']';
74 }
75
76 function adds_ref($id, $tagarr)
77 {
78 foreach ($tagarr as $name => $value)
79 {
80 $this->refs[$id][$name] = $value;
81 }
82 }
83 function adds_ref_sub($id, $block, $tagarr)
84 {
85 if (!isset($this->refs[$id][$block]))
86 {
87 $this->refs[$id][$block] = array('count' => 1);
88 }
89 foreach ($tagarr as $name => $value)
90 {
91 $this->refs[$id][$block][$this->refs[$id][$block]['count']][$name] = $value;
92 }
93 $this->refs[$id][$block]['count']++;
94 }
95
96 function display()
97 {
98 $template = file_get_contents($this->file);
99 while (preg_match('/<!--INCLUDE ([^>]*)-->/',$template) == 1)
100 {
101 preg_match('/<!--INCLUDE ([^>]*)-->/',$template,$mat);
102 $fname = $mat[1];
103 $itmp = new FITemplate($fname);
104 $template = str_replace('<!--INCLUDE ' . $fname . '-->',file_get_contents($itmp->file),$template);
105 }
106 if (isset($this->tags))
107 {
108 foreach ($this->tags as $name => $value)
109 {
110 $template = str_replace('<!--' . $name . '-->',$value,$template);
111 }
112 }
113 if (isset($this->blocks))
114 {
115 foreach ($this->blocks as $bname => $block)
116 {
117 $this->parseBlock($template, $bname, $block);
118 }
119 }
120 while (preg_match('/<!--BEGIN ([^>]*)-->/',$template) == 1)
121 {
122 preg_match('/<!--BEGIN ([^>]*)-->/',$template,$mat);
123 $bname = $mat[1];
124 $start = strpos($template,'<!--BEGIN ' . $bname . '-->');
125 $end = strpos($template,'<!--END ' . $bname . '-->');
126 $template = str_replace(substr($template,$start,$end-$start+strlen($bname)+11),'',$template);
127 }
128 $template = preg_replace('/<!--([^>]*)-->/','',$template);
129
130 echo($template);
131 }
132
133 function parseBlock(&$template, $bname, $block)
134 {
135 while (strpos($template,'<!--BEGIN ' . $bname . '-->') !== FALSE)
136 {
137 $start = strpos($template,'<!--BEGIN ' . $bname . '-->');
138 $end = strpos($template,'<!--END ' . $bname . '-->');
139 $gencont = substr($template,$start+strlen($bname)+13,$end-$start-strlen($bname)-13);
140 $blockcont = '';
141 foreach ($block as $lname => $blocktags)
142 {
143 if ($lname != 'count')
144 {
145 $scrcont = $gencont;
146 foreach ($blocktags as $name => $value)
147 {
148 if (!is_array($value))
149 {
150 $scrcont = str_replace('<!--' . $bname . '.' . $name . '-->',$value,$scrcont);
151 } else {
152 $this->parseBlock($scrcont, $bname . '.' . $name, $value);
153 }
154 }
155 $blockcont .= $scrcont;
156 }
157 }
158 $template = str_replace(substr($template,$start,$end-$start+strlen($bname)+11),$blockcont,$template);
159 }
160 }
161
162}
163
164?>