Quick Search:

View

Revision:

Diff

Diff from 593 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 593 2006-07-03 09:07:11Z 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
hpdl
351
26     var $_template;
hpdl
125
27
28 /**
hpdl
351
29  * Holds the template ID value
30  *
31  * @var int
32  * @access private
33  */
34
35     var $_template_id;
36
37 /**
hpdl
154
38  * Holds the title of the page module
39  *
40  * @var string
41  * @access private
42  */
43
44     var $_module;
45
46 /**
hpdl
192
47  * Holds the group name of the page
48  *
49  * @var string
50  * @access private
51  */
52
53     var $_group;
54
55 /**
hpdl
125
56  * Holds the title of the page
57  *
58  * @var string
59  * @access private
60  */
61
62     var $_page_title;
63
64 /**
hpdl
208
65  * Holds the image of the page
66  *
67  * @var string
68  * @access private
69  */
70
71     var $_page_image;
72
73 /**
hpdl
125
74  * Holds the filename of the content to be added to the page
75  *
76  * @var string
77  * @access private
78  */
79
hpdl
157
80     var $_page_contents;
hpdl
125
81
82 /**
hpdl
248
83  * Holds the meta tags of the page
84  *
85  * @var array
86  * @access private
87  */
88
89     var $_page_tags = array('generator' => array('osCommerce, Open Source E-Commerce Solutions'));
90
91 /**
hpdl
125
92  * Holds javascript filenames to be included in the page
93  *
94  * The javascript files must be plain javascript files without any PHP logic, and are linked to from the page
95  *
96  * @var array
97  * @access private
98  */
99
100     var $_javascript_filenames = array('includes/general.js');
101
102 /**
103  * Holds javascript PHP filenames to be included in the page
104  *
105  * The javascript PHP filenames can consist of PHP logic to produce valid javascript syntax, and is embedded in the page
106  *
107  * @var array
108  * @access private
109  */
110
111     var $_javascript_php_filenames = array();
112
113 /**
114  * Holds blocks of javascript syntax to embedd into the page
115  *
116  * Each block must contain its relevant <script> and </script> tags
117  *
118  * @var array
119  * @access private
120  */
121
122     var $_javascript_blocks = array();
123
124 /**
hpdl
593
125  * Defines if the requested page has a header
126  *
127  * @var boolean
128  * @access private
129  */
130
131     var $_has_header = true;
132
133 /**
134  * Defines if the requested page has a footer
135  *
136  * @var boolean
137  * @access private
138  */
139
140     var $_has_footer = true;
141
142 /**
143  * Defines if the requested page has box modules
144  *
145  * @var boolean
146  * @access private
147  */
148
149     var $_has_box_modules = true;
150
151 /**
152  * Defines if the requested page has content modules
153  *
154  * @var boolean
155  * @access private
156  */
157
158     var $_has_content_modules = true;
159
160 /**
161  * Defines if the requested page should display any debug messages
162  *
163  * @var boolean
164  * @access private
165  */
166
167     var $_show_debug_messages = true;
168
169 /**
hpdl
322
170  * Setup the template class with the requested page module
171  *
172  * @param string $module The default page module to setup
173  * @return object
174  */
175
176     function &setup($module) {
177       $group = basename($_SERVER['PHP_SELF']);
178
179       if (($pos = strrpos($group, '.')) !== false) {
180         $group = substr($group, 0, $pos);
181       }
182
183       if (empty($_GET) === false) {
184         $first_array = array_slice($_GET, 0, 1);
185         $_module = tep_sanitize_string(basename(key($first_array)));
186
187         if (file_exists('includes/content/' . $group . '/' . $_module . '.php')) {
188           $module = $_module;
189         }
190       }
191
192       include('includes/content/' . $group . '/' . $module . '.php');
193
194       $_page_module_name = 'osC_' . ucfirst($group) . '_' . ucfirst($module);
195       $object = new $_page_module_name();
196
197       return $object;
198     }
199
200 /**
hpdl
351
201  * Returns the template ID
202  *
203  * @access public
204  * @return int
205  */
206
207     function getID() {
208       if (isset($this->_template) === false) {
hpdl
353
209         $this->set();
hpdl
351
210       }
211
212       return $this->_template_id;
213     }
214
215 /**
hpdl
125
216  * Returns the template name
217  *
218  * @access public
219  * @return string
220  */
221
hpdl
352
222     function getCode() {
hpdl
351
223       if (isset($this->_template) === false) {
hpdl
353
224         $this->set();
hpdl
351
225       }
226
hpdl
125
227       return $this->_template;
228     }
229
230 /**
hpdl
154
231  * Returns the page module name
232  *
233  * @access public
234  * @return string
235  */
236
237     function getModule() {
238       return $this->_module;
239     }
240
241 /**
hpdl
192
242  * Returns the page group name
243  *
244  * @access public
245  * @return string
246  */
247
248     function getGroup() {
249       return $this->_group;
250     }
251
252 /**
hpdl
125
253  * Returns the title of the page
254  *
255  * @access public
256  * @return string
257  */
258
259     function getPageTitle() {
260       return $this->_page_title;
261     }
262
263 /**
hpdl
248
264  * Returns the tags of the page separated by a comma
265  *
266  * @access public
267  * @return string
268  */
269
270     function getPageTags() {
271       $tag_string = '';
272
273       foreach ($this->_page_tags as $key => $values) {
274         $tag_string .= '<meta name="' . $key . '" content="' . implode(', ', $values) . '" />' . "\n";
275       }
276
277       return $tag_string . "\n";
278     }
279
hpdl
324
280 /**
hpdl
333
281  * Return the box modules assigned to the page
hpdl
324
282  *
hpdl
333
283  * @param string $group The group name of box modules to include that the template has provided
hpdl
324
284  * @return array
285  */
286
hpdl
333
287     function getBoxModules($group) {
288       if (isset($this->osC_Modules_Boxes) === false) {
289         $this->osC_Modules_Boxes = new osC_Modules('boxes');
hpdl
323
290       }
291
hpdl
333
292       return $this->osC_Modules_Boxes->getGroup($group);
hpdl
323
293     }
294
hpdl
248
295 /**
hpdl
333
296  * Return the content modules assigned to the page
hpdl
331
297  *
hpdl
333
298  * @param string $group The group name of content modules to include that the template has provided
hpdl
331
299  * @return array
300  */
301
hpdl
333
302     function getContentModules($group) {
303       if (isset($this->osC_Modules_Content) === false) {
304         $this->osC_Modules_Content = new osC_Modules('content');
hpdl
331
305       }
306
hpdl
333
307       return $this->osC_Modules_Content->getGroup($group);
hpdl
331
308     }
309
310 /**
hpdl
208
311  * Returns the image of the page
312  *
313  * @access public
314  * @return string
315  */
316
317     function getPageImage() {
318       return $this->_page_image;
319     }
320
321 /**
hpdl
125
322  * Returns the content filename of the page
323  *
324  * @access public
325  * @return string
326  */
327
328     function getPageContentsFilename() {
hpdl
157
329       return $this->_page_contents;
hpdl
125
330     }
331
332 /**
333  * Returns the javascript to link from or embedd to on the page
334  *
335  * @access public
336  * @return string
337  */
338
339     function getJavascript() {
340       if (!empty($this->_javascript_filenames)) {
341         echo $this->_getJavascriptFilenames();
342       }
343
344       if (!empty($this->_javascript_php_filenames)) {
345         $this->_getJavascriptPhpFilenames();
346       }
347
348       if (!empty($this->_javascript_blocks)) {
349         echo $this->_getJavascriptBlocks();
350       }
351     }
352
353 /**
hpdl
356
354  * Return all templates in an array
355  *
356  * @access public
357  * @return array
358  */
359
360     function &getTemplates() {
361       global $osC_Database;
362
363       $templates = array();
364
365       $Qtemplates = $osC_Database->query('select id, code, title from :table_templates');
366       $Qtemplates->bindTable(':table_templates', TABLE_TEMPLATES);
367       $Qtemplates->setCache('templates');
368       $Qtemplates->execute();
369
370       while ($Qtemplates->next()) {
371         $templates [] = $Qtemplates->toArray();
372       }
373
374       $Qtemplates->freeResult();
375
376       return $templates;
377     }
378
379 /**
hpdl
125
380  * Checks to see if the page has a title set
381  *
382  * @access public
383  * @return boolean
384  */
385
386     function hasPageTitle() {
387       return !empty($this->_page_title);
388     }
389
390 /**
hpdl
248
391  * Checks to see if the page has a meta tag set
392  *
393  * @access public
394  * @return boolean
395  */
396
397     function hasPageTags() {
398       return !empty($this->_page_tags);
399     }
400
401 /**
hpdl
125
402  * Checks to see if the page has javascript to link to or embedd from
403  *
404  * @access public
405  * @return boolean
406  */
407
408     function hasJavascript() {
409       return (!empty($this->_javascript_filenames) || !empty($this->_javascript_php_filenames) || !empty($this->_javascript_blocks));
410     }
411
412 /**
hpdl
593
413  * Checks to see if the page has a footer defined
414  *
415  * @access public
416  * @return boolean
417  */
418
419     function hasPageFooter() {
420       return $this->_has_footer;
421     }
422
423 /**
424  * Checks to see if the page has a header defined
425  *
426  * @access public
427  * @return boolean
428  */
429
430     function hasPageHeader() {
431       return $this->_has_header;
432     }
433
434 /**
435  * Checks to see if the page has content modules defined
436  *
437  * @access public
438  * @return boolean
439  */
440
441     function hasPageContentModules() {
442       return $this->_has_content_modules;
443     }
444
445 /**
446  * Checks to see if the page has box modules defined
447  *
448  * @access public
449  * @return boolean
450  */
451
452     function hasPageBoxModules() {
453       return $this->_has_box_modules;
454     }
455
456 /**
457  * Checks to see if the page show display debug messages
458  *
459  * @access public
460  * @return boolean
461  */
462
463     function showDebugMessages() {
464       return $this->_show_debug_messages;
465     }
466
467 /**
hpdl
351
468  * Sets the template to use
hpdl
125
469  *
470  * @access public
471  */
472
hpdl
353
473     function set() {
hpdl
351
474       global $osC_Database;
475
476       if ( (isset($_SESSION['template']) === false) || (isset($_GET['template']) && !empty($_GET['template'])) ) {
hpdl
356
477         $set_template = (isset($_GET['template']) && !empty($_GET['template'])) ? $_GET['template'] : DEFAULT_TEMPLATE;
hpdl
351
478
479         $data = array();
480         $data_default = array();
481
hpdl
356
482         foreach ($this->getTemplates() as $template) {
483           if ($template['code'] == DEFAULT_TEMPLATE) {
484             $data_default = array('id' => $template['id'], 'code' => $template['code']);
485           } elseif ($template['code'] == $set_template) {
486             $data = array('id' => $template['id'], 'code' => $template['code']);
hpdl
351
487           }
488         }
489
490         if (empty($data)) {
491           $data =& $data_default;
492         }
493
494         $_SESSION['template'] =& $data;
495       }
496
497       $this->_template_id =& $_SESSION['template']['id'];
498       $this->_template =& $_SESSION['template']['code'];
hpdl
125
499     }
500
501 /**
502  * Sets the title of the page
503  *
504  * @param string $title The title of the page to set to
505  * @access public
506  */
507
508     function setPageTitle($title) {
509       $this->_page_title = $title;
510     }
511
512 /**
hpdl
208
513  * Sets the image of the page
514  *
515  * @param string $image The image of the page to set to
516  * @access public
517  */
518
519     function setPageImage($image) {
520       $this->_page_image = $image;
521     }
522
523 /**
hpdl
125
524  * Sets the content of the page
525  *
526  * @param string $filename The content filename to include on the page
527  * @access public
528  */
529
530     function setPageContentsFilename($filename) {
531       $this->_page_contents_filename = $filename;
532     }
533
534 /**
hpdl
248
535  * Adds a tag to the meta keywords array
536  *
537  * @param string $key The keyword for the meta tag
538  * @param string $value The value for the meta tag using the key
539  * @access public
540  */
541
542     function addPageTags($key, $value) {
543       $this->_page_tags[$key][] = $value;
544     }
545
546 /**
hpdl
125
547  * Adds a javascript file to link to
548  *
549  * @param string $filename The javascript filename to link to
550  * @access public
551  */
552
553     function addJavascriptFilename($filename) {
554       $this->_javascript_filenames[] = $filename;
555     }
556
557 /**
558  * Adds a PHP based javascript file to embedd on the page
559  *
560  * @param string $filename The PHP based javascript filename to embedd
561  * @access public
562  */
563
564     function addJavascriptPhpFilename($filename) {
565       $this->_javascript_php_filenames[] = $filename;
566     }
567
568 /**
569  * Adds javascript logic to the page
570  *
571  * @param string $javascript The javascript block to add on the page
572  * @access public
573  */
574
575     function addJavascriptBlock($javascript) {
576       $this->_javascript_blocks[] = $javascript;
577     }
578
579 /**
580  * Returns the javascript filenames to link to on the page
581  *
582  * @access private
583  * @return string
584  */
585
586     function _getJavascriptFilenames() {
587       $js_files = '';
588
589       foreach ($this->_javascript_filenames as $filenames) {
590         $js_files .= '<script language="javascript" type="text/javascript" src="' . $filenames . '"></script>' . "\n";
591       }
592
593       return $js_files;
594     }
595
596 /**
597  * Returns the PHP javascript files to embedd on the page
598  *
599  * @access private
600  */
601
602     function _getJavascriptPhpFilenames() {
603       foreach ($this->_javascript_php_filenames as $filenames) {
604         include($filenames);
605       }
606     }
607
608 /**
609  * Returns javascript blocks to add to the page
610  *
611  * @access private
612  * @return string
613  */
614
615     function _getJavascriptBlocks() {
616       return implode("\n", $this->_javascript_blocks);
617     }
618   }
619 ?>