Quick Search:

View

Revision:

Diff

Diff from 323 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 323 2005-12-05 00:48:23Z 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
290
116  * Hold the extra modules to load on the page
117  *
118  * @var array
119  * @access public
120  */
121
122     var $_extra_page_modules = array('before' => array(), 'after' => array());
123
124 /**
hpdl
322
125  * Setup the template class with the requested page module
126  *
127  * @param string $module The default page module to setup
128  * @return object
129  */
130
131     function &setup($module) {
132       $group = basename($_SERVER['PHP_SELF']);
133
134       if (($pos = strrpos($group, '.')) !== false) {
135         $group = substr($group, 0, $pos);
136       }
137
138       if (empty($_GET) === false) {
139         $first_array = array_slice($_GET, 0, 1);
140         $_module = tep_sanitize_string(basename(key($first_array)));
141
142         if (file_exists('includes/content/' . $group . '/' . $_module . '.php')) {
143           $module = $_module;
144         }
145       }
146
147       include('includes/content/' . $group . '/' . $module . '.php');
148
149       $_page_module_name = 'osC_' . ucfirst($group) . '_' . ucfirst($module);
150       $object = new $_page_module_name();
151
152       return $object;
153     }
154
155 /**
hpdl
125
156  * Returns the template name
157  *
158  * @access public
159  * @return string
160  */
161
162     function getTemplate() {
163       return $this->_template;
164     }
165
166 /**
hpdl
154
167  * Returns the page module name
168  *
169  * @access public
170  * @return string
171  */
172
173     function getModule() {
174       return $this->_module;
175     }
176
177 /**
hpdl
192
178  * Returns the page group name
179  *
180  * @access public
181  * @return string
182  */
183
184     function getGroup() {
185       return $this->_group;
186     }
187
188 /**
hpdl
125
189  * Returns the title of the page
190  *
191  * @access public
192  * @return string
193  */
194
195     function getPageTitle() {
196       return $this->_page_title;
197     }
198
199 /**
hpdl
248
200  * Returns the tags of the page separated by a comma
201  *
202  * @access public
203  * @return string
204  */
205
206     function getPageTags() {
207       $tag_string = '';
208
209       foreach ($this->_page_tags as $key => $values) {
210         $tag_string .= '<meta name="' . $key . '" content="' . implode(', ', $values) . '" />' . "\n";
211       }
212
213       return $tag_string . "\n";
214     }
215
hpdl
323
216     function getPageBoxes($group) {
217       static $osC_Boxes;
218
219       if (isset($osC_Boxes) === false) {
220         $osC_Boxes = new osC_Boxes();
221       }
222
223       return $osC_Boxes->getGroup($group);
224     }
225
hpdl
248
226 /**
hpdl
208
227  * Returns the image of the page
228  *
229  * @access public
230  * @return string
231  */
232
233     function getPageImage() {
234       return $this->_page_image;
235     }
236
237 /**
hpdl
125
238  * Returns the content filename of the page
239  *
240  * @access public
241  * @return string
242  */
243
244     function getPageContentsFilename() {
hpdl
157
245       return $this->_page_contents;
hpdl
125
246     }
247
248 /**
249  * Returns the javascript to link from or embedd to on the page
250  *
251  * @access public
252  * @return string
253  */
254
255     function getJavascript() {
256       if (!empty($this->_javascript_filenames)) {
257         echo $this->_getJavascriptFilenames();
258       }
259
260       if (!empty($this->_javascript_php_filenames)) {
261         $this->_getJavascriptPhpFilenames();
262       }
263
264       if (!empty($this->_javascript_blocks)) {
265         echo $this->_getJavascriptBlocks();
266       }
267     }
268
269 /**
270  * Checks to see if the page has a title set
271  *
272  * @access public
273  * @return boolean
274  */
275
276     function hasPageTitle() {
277       return !empty($this->_page_title);
278     }
279
280 /**
hpdl
248
281  * Checks to see if the page has a meta tag set
282  *
283  * @access public
284  * @return boolean
285  */
286
287     function hasPageTags() {
288       return !empty($this->_page_tags);
289     }
290
291 /**
hpdl
125
292  * Checks to see if the page has javascript to link to or embedd from
293  *
294  * @access public
295  * @return boolean
296  */
297
298     function hasJavascript() {
299       return (!empty($this->_javascript_filenames) || !empty($this->_javascript_php_filenames) || !empty($this->_javascript_blocks));
300     }
301
302 /**
303  * Sets the name of the template to use
304  *
305  * @param string $template The name of the template to set
306  * @access public
307  */
308
309     function setTemplate($template) {
310       $this->_template = $template;
311     }
312
313 /**
314  * Sets the title of the page
315  *
316  * @param string $title The title of the page to set to
317  * @access public
318  */
319
320     function setPageTitle($title) {
321       $this->_page_title = $title;
322     }
323
324 /**
hpdl
208
325  * Sets the image of the page
326  *
327  * @param string $image The image of the page to set to
328  * @access public
329  */
330
331     function setPageImage($image) {
332       $this->_page_image = $image;
333     }
334
335 /**
hpdl
125
336  * Sets the content of the page
337  *
338  * @param string $filename The content filename to include on the page
339  * @access public
340  */
341
342     function setPageContentsFilename($filename) {
343       $this->_page_contents_filename = $filename;
344     }
345
346 /**
hpdl
248
347  * Adds a tag to the meta keywords array
348  *
349  * @param string $key The keyword for the meta tag
350  * @param string $value The value for the meta tag using the key
351  * @access public
352  */
353
354     function addPageTags($key, $value) {
355       $this->_page_tags[$key][] = $value;
356     }
357
358 /**
hpdl
125
359  * Adds a javascript file to link to
360  *
361  * @param string $filename The javascript filename to link to
362  * @access public
363  */
364
365     function addJavascriptFilename($filename) {
366       $this->_javascript_filenames[] = $filename;
367     }
368
369 /**
370  * Adds a PHP based javascript file to embedd on the page
371  *
372  * @param string $filename The PHP based javascript filename to embedd
373  * @access public
374  */
375
376     function addJavascriptPhpFilename($filename) {
377       $this->_javascript_php_filenames[] = $filename;
378     }
379
380 /**
381  * Adds javascript logic to the page
382  *
383  * @param string $javascript The javascript block to add on the page
384  * @access public
385  */
386
387     function addJavascriptBlock($javascript) {
388       $this->_javascript_blocks[] = $javascript;
389     }
390
391 /**
hpdl
290
392  * Adds an extra module to load on the page, either before or after the page content
393  *
394  * @param object $class The class instance to initialize the extra module
395  * @param string $location Load the extra module "before" or "after" the page content
396  * @access public
397  */
398
399     function addContentModule($class, $location = 'before') {
400       if (isset($GLOBALS[$class])) {
401         $GLOBALS[$class]->contentModuleInitialize();
402         $this->_extra_page_modules[$location][] = $GLOBALS[$class]->getContentModule();
403       } elseif (isset($_SESSION[$class])) {
404         $_SESSION[$class]->contentModuleInitialize();
405         $this->_extra_page_modules[$location][] = $_SESSION[$class]->getContentModule();
406       }
407     }
408
409 /**
hpdl
125
410  * Returns the javascript filenames to link to on the page
411  *
412  * @access private
413  * @return string
414  */
415
416     function _getJavascriptFilenames() {
417       $js_files = '';
418
419       foreach ($this->_javascript_filenames as $filenames) {
420         $js_files .= '<script language="javascript" type="text/javascript" src="' . $filenames . '"></script>' . "\n";
421       }
422
423       return $js_files;
424     }
425
426 /**
427  * Returns the PHP javascript files to embedd on the page
428  *
429  * @access private
430  */
431
432     function _getJavascriptPhpFilenames() {
433       foreach ($this->_javascript_php_filenames as $filenames) {
434         include($filenames);
435       }
436     }
437
438 /**
439  * Returns javascript blocks to add to the page
440  *
441  * @access private
442  * @return string
443  */
444
445     function _getJavascriptBlocks() {
446       return implode("\n", $this->_javascript_blocks);
447     }
448   }
449 ?>