Quick Search:

View

Revision:

Diff

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