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