Quick Search:

View

Revision:

Diff

Diff from 324 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 324 2005-12-05 02:18:32Z 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
324
216 /**
217  * Return the boxes assigned to the page content
218  *
219  * @param string $group The group name of boxes to include that the template has provided
220  * @return array
221  */
222
hpdl
323
223     function getPageBoxes($group) {
224       static $osC_Boxes;
225
226       if (isset($osC_Boxes) === false) {
227         $osC_Boxes = new osC_Boxes();
228       }
229
230       return $osC_Boxes->getGroup($group);
231     }
232
hpdl
248
233 /**
hpdl
208
234  * Returns the image of the page
235  *
236  * @access public
237  * @return string
238  */
239
240     function getPageImage() {
241       return $this->_page_image;
242     }
243
244 /**
hpdl
125
245  * Returns the content filename of the page
246  *
247  * @access public
248  * @return string
249  */
250
251     function getPageContentsFilename() {
hpdl
157
252       return $this->_page_contents;
hpdl
125
253     }
254
255 /**
256  * Returns the javascript to link from or embedd to on the page
257  *
258  * @access public
259  * @return string
260  */
261
262     function getJavascript() {
263       if (!empty($this->_javascript_filenames)) {
264         echo $this->_getJavascriptFilenames();
265       }
266
267       if (!empty($this->_javascript_php_filenames)) {
268         $this->_getJavascriptPhpFilenames();
269       }
270
271       if (!empty($this->_javascript_blocks)) {
272         echo $this->_getJavascriptBlocks();
273       }
274     }
275
276 /**
277  * Checks to see if the page has a title set
278  *
279  * @access public
280  * @return boolean
281  */
282
283     function hasPageTitle() {
284       return !empty($this->_page_title);
285     }
286
287 /**
hpdl
248
288  * Checks to see if the page has a meta tag set
289  *
290  * @access public
291  * @return boolean
292  */
293
294     function hasPageTags() {
295       return !empty($this->_page_tags);
296     }
297
298 /**
hpdl
125
299  * Checks to see if the page has javascript to link to or embedd from
300  *
301  * @access public
302  * @return boolean
303  */
304
305     function hasJavascript() {
306       return (!empty($this->_javascript_filenames) || !empty($this->_javascript_php_filenames) || !empty($this->_javascript_blocks));
307     }
308
309 /**
310  * Sets the name of the template to use
311  *
312  * @param string $template The name of the template to set
313  * @access public
314  */
315
316     function setTemplate($template) {
317       $this->_template = $template;
318     }
319
320 /**
321  * Sets the title of the page
322  *
323  * @param string $title The title of the page to set to
324  * @access public
325  */
326
327     function setPageTitle($title) {
328       $this->_page_title = $title;
329     }
330
331 /**
hpdl
208
332  * Sets the image of the page
333  *
334  * @param string $image The image of the page to set to
335  * @access public
336  */
337
338     function setPageImage($image) {
339       $this->_page_image = $image;
340     }
341
342 /**
hpdl
125
343  * Sets the content of the page
344  *
345  * @param string $filename The content filename to include on the page
346  * @access public
347  */
348
349     function setPageContentsFilename($filename) {
350       $this->_page_contents_filename = $filename;
351     }
352
353 /**
hpdl
248
354  * Adds a tag to the meta keywords array
355  *
356  * @param string $key The keyword for the meta tag
357  * @param string $value The value for the meta tag using the key
358  * @access public
359  */
360
361     function addPageTags($key, $value) {
362       $this->_page_tags[$key][] = $value;
363     }
364
365 /**
hpdl
125
366  * Adds a javascript file to link to
367  *
368  * @param string $filename The javascript filename to link to
369  * @access public
370  */
371
372     function addJavascriptFilename($filename) {
373       $this->_javascript_filenames[] = $filename;
374     }
375
376 /**
377  * Adds a PHP based javascript file to embedd on the page
378  *
379  * @param string $filename The PHP based javascript filename to embedd
380  * @access public
381  */
382
383     function addJavascriptPhpFilename($filename) {
384       $this->_javascript_php_filenames[] = $filename;
385     }
386
387 /**
388  * Adds javascript logic to the page
389  *
390  * @param string $javascript The javascript block to add on the page
391  * @access public
392  */
393
394     function addJavascriptBlock($javascript) {
395       $this->_javascript_blocks[] = $javascript;
396     }
397
398 /**
hpdl
290
399  * Adds an extra module to load on the page, either before or after the page content
400  *
401  * @param object $class The class instance to initialize the extra module
402  * @param string $location Load the extra module "before" or "after" the page content
403  * @access public
404  */
405
406     function addContentModule($class, $location = 'before') {
407       if (isset($GLOBALS[$class])) {
408         $GLOBALS[$class]->contentModuleInitialize();
409         $this->_extra_page_modules[$location][] = $GLOBALS[$class]->getContentModule();
410       } elseif (isset($_SESSION[$class])) {
411         $_SESSION[$class]->contentModuleInitialize();
412         $this->_extra_page_modules[$location][] = $_SESSION[$class]->getContentModule();
413       }
414     }
415
416 /**
hpdl
125
417  * Returns the javascript filenames to link to on the page
418  *
419  * @access private
420  * @return string
421  */
422
423     function _getJavascriptFilenames() {
424       $js_files = '';
425
426       foreach ($this->_javascript_filenames as $filenames) {
427         $js_files .= '<script language="javascript" type="text/javascript" src="' . $filenames . '"></script>' . "\n";
428       }
429
430       return $js_files;
431     }
432
433 /**
434  * Returns the PHP javascript files to embedd on the page
435  *
436  * @access private
437  */
438
439     function _getJavascriptPhpFilenames() {
440       foreach ($this->_javascript_php_filenames as $filenames) {
441         include($filenames);
442       }
443     }
444
445 /**
446  * Returns javascript blocks to add to the page
447  *
448  * @access private
449  * @return string
450  */
451
452     function _getJavascriptBlocks() {
453       return implode("\n", $this->_javascript_blocks);
454     }
455   }
456 ?>