Quick Search:

View

Revision:

Diff

Diff from 331 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/template.php

Annotated File View

hpdl
125
1 <?php
2 /*
hpdl
156
3   $Id: template.php 331 2005-12-06 03:28:58Z hpdl $
hpdl
125
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2005 osCommerce
9
10   Released under the GNU General Public License
11 */
12
13 /**
14  * The osC_Template class defines or adds elements to the page output such as the page title, page content, and javascript blocks
15  */
16
17   class osC_Template {
18
19 /**
20  * Holds the template name value
21  *
22  * @var string
23  * @access private
24  */
25
26     var $_template = 'default';
27
28 /**
hpdl
154
29  * Holds the title of the page module
30  *
31  * @var string
32  * @access private
33  */
34
35     var $_module;
36
37 /**
hpdl
192
38  * Holds the group name of the page
39  *
40  * @var string
41  * @access private
42  */
43
44     var $_group;
45
46 /**
hpdl
125
47  * Holds the title of the page
48  *
49  * @var string
50  * @access private
51  */
52
53     var $_page_title;
54
55 /**
hpdl
208
56  * Holds the image of the page
57  *
58  * @var string
59  * @access private
60  */
61
62     var $_page_image;
63
64 /**
hpdl
125
65  * Holds the filename of the content to be added to the page
66  *
67  * @var string
68  * @access private
69  */
70
hpdl
157
71     var $_page_contents;
hpdl
125
72
73 /**
hpdl
248
74  * Holds the meta tags of the page
75  *
76  * @var array
77  * @access private
78  */
79
80     var $_page_tags = array('generator' => array('osCommerce, Open Source E-Commerce Solutions'));
81
82 /**
hpdl
125
83  * Holds javascript filenames to be included in the page
84  *
85  * The javascript files must be plain javascript files without any PHP logic, and are linked to from the page
86  *
87  * @var array
88  * @access private
89  */
90
91     var $_javascript_filenames = array('includes/general.js');
92
93 /**
94  * Holds javascript PHP filenames to be included in the page
95  *
96  * The javascript PHP filenames can consist of PHP logic to produce valid javascript syntax, and is embedded in the page
97  *
98  * @var array
99  * @access private
100  */
101
102     var $_javascript_php_filenames = array();
103
104 /**
105  * Holds blocks of javascript syntax to embedd into the page
106  *
107  * Each block must contain its relevant <script> and </script> tags
108  *
109  * @var array
110  * @access private
111  */
112
113     var $_javascript_blocks = array();
114
115 /**
hpdl
322
116  * Setup the template class with the requested page module
117  *
118  * @param string $module The default page module to setup
119  * @return object
120  */
121
122     function &setup($module) {
123       $group = basename($_SERVER['PHP_SELF']);
124
125       if (($pos = strrpos($group, '.')) !== false) {
126         $group = substr($group, 0, $pos);
127       }
128
129       if (empty($_GET) === false) {
130         $first_array = array_slice($_GET, 0, 1);
131         $_module = tep_sanitize_string(basename(key($first_array)));
132
133         if (file_exists('includes/content/' . $group . '/' . $_module . '.php')) {
134           $module = $_module;
135         }
136       }
137
138       include('includes/content/' . $group . '/' . $module . '.php');
139
140       $_page_module_name = 'osC_' . ucfirst($group) . '_' . ucfirst($module);
141       $object = new $_page_module_name();
142
143       return $object;
144     }
145
146 /**
hpdl
125
147  * Returns the template name
148  *
149  * @access public
150  * @return string
151  */
152
153     function getTemplate() {
154       return $this->_template;
155     }
156
157 /**
hpdl
154
158  * Returns the page module name
159  *
160  * @access public
161  * @return string
162  */
163
164     function getModule() {
165       return $this->_module;
166     }
167
168 /**
hpdl
192
169  * Returns the page group name
170  *
171  * @access public
172  * @return string
173  */
174
175     function getGroup() {
176       return $this->_group;
177     }
178
179 /**
hpdl
125
180  * Returns the title of the page
181  *
182  * @access public
183  * @return string
184  */
185
186     function getPageTitle() {
187       return $this->_page_title;
188     }
189
190 /**
hpdl
248
191  * Returns the tags of the page separated by a comma
192  *
193  * @access public
194  * @return string
195  */
196
197     function getPageTags() {
198       $tag_string = '';
199
200       foreach ($this->_page_tags as $key => $values) {
201         $tag_string .= '<meta name="' . $key . '" content="' . implode(', ', $values) . '" />' . "\n";
202       }
203
204       return $tag_string . "\n";
205     }
206
hpdl
324
207 /**
208  * Return the boxes assigned to the page content
209  *
210  * @param string $group The group name of boxes to include that the template has provided
211  * @return array
212  */
213
hpdl
323
214     function getPageBoxes($group) {
215       static $osC_Boxes;
216
217       if (isset($osC_Boxes) === false) {
hpdl
331
218         $osC_Boxes = new osC_Boxes('boxes');
hpdl
323
219       }
220
221       return $osC_Boxes->getGroup($group);
222     }
223
hpdl
248
224 /**
hpdl
331
225  * Return the modules assigned to the page content
226  *
227  * @param string $group The group name of modules to include that the template has provided
228  * @return array
229  */
230
231     function getPageModulesContent($group) {
232       static $osC_Boxes;
233
234       if (isset($osC_Boxes) === false) {
235         $osC_Boxes = new osC_Boxes('content');
236       }
237
238       return $osC_Boxes->getGroup($group);
239     }
240
241 /**
hpdl
208
242  * Returns the image of the page
243  *
244  * @access public
245  * @return string
246  */
247
248     function getPageImage() {
249       return $this->_page_image;
250     }
251
252 /**
hpdl
125
253  * Returns the content filename of the page
254  *
255  * @access public
256  * @return string
257  */
258
259     function getPageContentsFilename() {
hpdl
157
260       return $this->_page_contents;
hpdl
125
261     }
262
263 /**
264  * Returns the javascript to link from or embedd to on the page
265  *
266  * @access public
267  * @return string
268  */
269
270     function getJavascript() {
271       if (!empty($this->_javascript_filenames)) {
272         echo $this->_getJavascriptFilenames();
273       }
274
275       if (!empty($this->_javascript_php_filenames)) {
276         $this->_getJavascriptPhpFilenames();
277       }
278
279       if (!empty($this->_javascript_blocks)) {
280         echo $this->_getJavascriptBlocks();
281       }
282     }
283
284 /**
285  * Checks to see if the page has a title set
286  *
287  * @access public
288  * @return boolean
289  */
290
291     function hasPageTitle() {
292       return !empty($this->_page_title);
293     }
294
295 /**
hpdl
248
296  * Checks to see if the page has a meta tag set
297  *
298  * @access public
299  * @return boolean
300  */
301
302     function hasPageTags() {
303       return !empty($this->_page_tags);
304     }
305
306 /**
hpdl
125
307  * Checks to see if the page has javascript to link to or embedd from
308  *
309  * @access public
310  * @return boolean
311  */
312
313     function hasJavascript() {
314       return (!empty($this->_javascript_filenames) || !empty($this->_javascript_php_filenames) || !empty($this->_javascript_blocks));
315     }
316
317 /**
318  * Sets the name of the template to use
319  *
320  * @param string $template The name of the template to set
321  * @access public
322  */
323
324     function setTemplate($template) {
325       $this->_template = $template;
326     }
327
328 /**
329  * Sets the title of the page
330  *
331  * @param string $title The title of the page to set to
332  * @access public
333  */
334
335     function setPageTitle($title) {
336       $this->_page_title = $title;
337     }
338
339 /**
hpdl
208
340  * Sets the image of the page
341  *
342  * @param string $image The image of the page to set to
343  * @access public
344  */
345
346     function setPageImage($image) {
347       $this->_page_image = $image;
348     }
349
350 /**
hpdl
125
351  * Sets the content of the page
352  *
353  * @param string $filename The content filename to include on the page
354  * @access public
355  */
356
357     function setPageContentsFilename($filename) {
358       $this->_page_contents_filename = $filename;
359     }
360
361 /**
hpdl
248
362  * Adds a tag to the meta keywords array
363  *
364  * @param string $key The keyword for the meta tag
365  * @param string $value The value for the meta tag using the key
366  * @access public
367  */
368
369     function addPageTags($key, $value) {
370       $this->_page_tags[$key][] = $value;
371     }
372
373 /**
hpdl
125
374  * Adds a javascript file to link to
375  *
376  * @param string $filename The javascript filename to link to
377  * @access public
378  */
379
380     function addJavascriptFilename($filename) {
381       $this->_javascript_filenames[] = $filename;
382     }
383
384 /**
385  * Adds a PHP based javascript file to embedd on the page
386  *
387  * @param string $filename The PHP based javascript filename to embedd
388  * @access public
389  */
390
391     function addJavascriptPhpFilename($filename) {
392       $this->_javascript_php_filenames[] = $filename;
393     }
394
395 /**
396  * Adds javascript logic to the page
397  *
398  * @param string $javascript The javascript block to add on the page
399  * @access public
400  */
401
402     function addJavascriptBlock($javascript) {
403       $this->_javascript_blocks[] = $javascript;
404     }
405
406 /**
407  * Returns the javascript filenames to link to on the page
408  *
409  * @access private
410  * @return string
411  */
412
413     function _getJavascriptFilenames() {
414       $js_files = '';
415
416       foreach ($this->_javascript_filenames as $filenames) {
417         $js_files .= '<script language="javascript" type="text/javascript" src="' . $filenames . '"></script>' . "\n";
418       }
419
420       return $js_files;
421     }
422
423 /**
424  * Returns the PHP javascript files to embedd on the page
425  *
426  * @access private
427  */
428
429     function _getJavascriptPhpFilenames() {
430       foreach ($this->_javascript_php_filenames as $filenames) {
431         include($filenames);
432       }
433     }
434
435 /**
436  * Returns javascript blocks to add to the page
437  *
438  * @access private
439  * @return string
440  */
441
442     function _getJavascriptBlocks() {
443       return implode("\n", $this->_javascript_blocks);
444     }
445   }
446 ?>