hpdl
|
125
|
1
|
<?php
|
|
2
|
/*
|
hpdl
|
156
|
3
|
$Id: template.php 353 2005-12-19 11:59:56Z 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
|
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
|
351
|
156
|
* Returns the template ID
|
|
157
|
*
|
|
158
|
* @access public
|
|
159
|
* @return int
|
|
160
|
*/
|
|
161
|
|
|
162
|
function getID() {
|
|
163
|
if (isset($this->_template) === false) {
|
hpdl
|
353
|
164
|
$this->set();
|
hpdl
|
351
|
165
|
}
|
|
166
|
|
|
167
|
return $this->_template_id;
|
|
168
|
}
|
|
169
|
|
|
170
|
/**
|
hpdl
|
125
|
171
|
* Returns the template name
|
|
172
|
*
|
|
173
|
* @access public
|
|
174
|
* @return string
|
|
175
|
*/
|
|
176
|
|
hpdl
|
352
|
177
|
function getCode() {
|
hpdl
|
351
|
178
|
if (isset($this->_template) === false) {
|
hpdl
|
353
|
179
|
$this->set();
|
hpdl
|
351
|
180
|
}
|
|
181
|
|
hpdl
|
125
|
182
|
return $this->_template;
|
|
183
|
}
|
|
184
|
|
|
185
|
/**
|
hpdl
|
154
|
186
|
* Returns the page module name
|
|
187
|
*
|
|
188
|
* @access public
|
|
189
|
* @return string
|
|
190
|
*/
|
|
191
|
|
|
192
|
function getModule() {
|
|
193
|
return $this->_module;
|
|
194
|
}
|
|
195
|
|
|
196
|
/**
|
hpdl
|
192
|
197
|
* Returns the page group name
|
|
198
|
*
|
|
199
|
* @access public
|
|
200
|
* @return string
|
|
201
|
*/
|
|
202
|
|
|
203
|
function getGroup() {
|
|
204
|
return $this->_group;
|
|
205
|
}
|
|
206
|
|
|
207
|
/**
|
hpdl
|
125
|
208
|
* Returns the title of the page
|
|
209
|
*
|
|
210
|
* @access public
|
|
211
|
* @return string
|
|
212
|
*/
|
|
213
|
|
|
214
|
function getPageTitle() {
|
|
215
|
return $this->_page_title;
|
|
216
|
}
|
|
217
|
|
|
218
|
/**
|
hpdl
|
248
|
219
|
* Returns the tags of the page separated by a comma
|
|
220
|
*
|
|
221
|
* @access public
|
|
222
|
* @return string
|
|
223
|
*/
|
|
224
|
|
|
225
|
function getPageTags() {
|
|
226
|
$tag_string = '';
|
|
227
|
|
|
228
|
foreach ($this->_page_tags as $key => $values) {
|
|
229
|
$tag_string .= '<meta name="' . $key . '" content="' . implode(', ', $values) . '" />' . "\n";
|
|
230
|
}
|
|
231
|
|
|
232
|
return $tag_string . "\n";
|
|
233
|
}
|
|
234
|
|
hpdl
|
324
|
235
|
/**
|
hpdl
|
333
|
236
|
* Return the box modules assigned to the page
|
hpdl
|
324
|
237
|
*
|
hpdl
|
333
|
238
|
* @param string $group The group name of box modules to include that the template has provided
|
hpdl
|
324
|
239
|
* @return array
|
|
240
|
*/
|
|
241
|
|
hpdl
|
333
|
242
|
function getBoxModules($group) {
|
|
243
|
if (isset($this->osC_Modules_Boxes) === false) {
|
|
244
|
$this->osC_Modules_Boxes = new osC_Modules('boxes');
|
hpdl
|
323
|
245
|
}
|
|
246
|
|
hpdl
|
333
|
247
|
return $this->osC_Modules_Boxes->getGroup($group);
|
hpdl
|
323
|
248
|
}
|
|
249
|
|
hpdl
|
248
|
250
|
/**
|
hpdl
|
333
|
251
|
* Return the content modules assigned to the page
|
hpdl
|
331
|
252
|
*
|
hpdl
|
333
|
253
|
* @param string $group The group name of content modules to include that the template has provided
|
hpdl
|
331
|
254
|
* @return array
|
|
255
|
*/
|
|
256
|
|
hpdl
|
333
|
257
|
function getContentModules($group) {
|
|
258
|
if (isset($this->osC_Modules_Content) === false) {
|
|
259
|
$this->osC_Modules_Content = new osC_Modules('content');
|
hpdl
|
331
|
260
|
}
|
|
261
|
|
hpdl
|
333
|
262
|
return $this->osC_Modules_Content->getGroup($group);
|
hpdl
|
331
|
263
|
}
|
|
264
|
|
|
265
|
/**
|
hpdl
|
208
|
266
|
* Returns the image of the page
|
|
267
|
*
|
|
268
|
* @access public
|
|
269
|
* @return string
|
|
270
|
*/
|
|
271
|
|
|
272
|
function getPageImage() {
|
|
273
|
return $this->_page_image;
|
|
274
|
}
|
|
275
|
|
|
276
|
/**
|
hpdl
|
125
|
277
|
* Returns the content filename of the page
|
|
278
|
*
|
|
279
|
* @access public
|
|
280
|
* @return string
|
|
281
|
*/
|
|
282
|
|
|
283
|
function getPageContentsFilename() {
|
hpdl
|
157
|
284
|
return $this->_page_contents;
|
hpdl
|
125
|
285
|
}
|
|
286
|
|
|
287
|
/**
|
|
288
|
* Returns the javascript to link from or embedd to on the page
|
|
289
|
*
|
|
290
|
* @access public
|
|
291
|
* @return string
|
|
292
|
*/
|
|
293
|
|
|
294
|
function getJavascript() {
|
|
295
|
if (!empty($this->_javascript_filenames)) {
|
|
296
|
echo $this->_getJavascriptFilenames();
|
|
297
|
}
|
|
298
|
|
|
299
|
if (!empty($this->_javascript_php_filenames)) {
|
|
300
|
$this->_getJavascriptPhpFilenames();
|
|
301
|
}
|
|
302
|
|
|
303
|
if (!empty($this->_javascript_blocks)) {
|
|
304
|
echo $this->_getJavascriptBlocks();
|
|
305
|
}
|
|
306
|
}
|
|
307
|
|
|
308
|
/**
|
|
309
|
* Checks to see if the page has a title set
|
|
310
|
*
|
|
311
|
* @access public
|
|
312
|
* @return boolean
|
|
313
|
*/
|
|
314
|
|
|
315
|
function hasPageTitle() {
|
|
316
|
return !empty($this->_page_title);
|
|
317
|
}
|
|
318
|
|
|
319
|
/**
|
hpdl
|
248
|
320
|
* Checks to see if the page has a meta tag set
|
|
321
|
*
|
|
322
|
* @access public
|
|
323
|
* @return boolean
|
|
324
|
*/
|
|
325
|
|
|
326
|
function hasPageTags() {
|
|
327
|
return !empty($this->_page_tags);
|
|
328
|
}
|
|
329
|
|
|
330
|
/**
|
hpdl
|
125
|
331
|
* Checks to see if the page has javascript to link to or embedd from
|
|
332
|
*
|
|
333
|
* @access public
|
|
334
|
* @return boolean
|
|
335
|
*/
|
|
336
|
|
|
337
|
function hasJavascript() {
|
|
338
|
return (!empty($this->_javascript_filenames) || !empty($this->_javascript_php_filenames) || !empty($this->_javascript_blocks));
|
|
339
|
}
|
|
340
|
|
|
341
|
/**
|
hpdl
|
351
|
342
|
* Sets the template to use
|
hpdl
|
125
|
343
|
*
|
|
344
|
* @access public
|
|
345
|
*/
|
|
346
|
|
hpdl
|
353
|
347
|
function set() {
|
hpdl
|
351
|
348
|
global $osC_Database;
|
|
349
|
|
|
350
|
if ( (isset($_SESSION['template']) === false) || (isset($_GET['template']) && !empty($_GET['template'])) ) {
|
|
351
|
$Qtemplates = $osC_Database->query('select id, code from :table_templates');
|
|
352
|
$Qtemplates->bindTable(':table_templates', TABLE_TEMPLATES);
|
|
353
|
$Qtemplates->setCache('templates');
|
|
354
|
$Qtemplates->execute();
|
|
355
|
|
|
356
|
$template = (isset($_GET['template']) && !empty($_GET['template'])) ? $_GET['template'] : DEFAULT_TEMPLATE;
|
|
357
|
|
|
358
|
$data = array();
|
|
359
|
$data_default = array();
|
|
360
|
|
|
361
|
while ($Qtemplates->next()) {
|
|
362
|
if ($Qtemplates->value('code') == DEFAULT_TEMPLATE) {
|
|
363
|
$data_default = array('id' => $Qtemplates->valueInt('id'), 'code' => $Qtemplates->value('code'));
|
|
364
|
} elseif ($Qtemplates->value('code') == $template) {
|
|
365
|
$data = array('id' => $Qtemplates->valueInt('id'), 'code' => $Qtemplates->value('code'));
|
|
366
|
}
|
|
367
|
}
|
|
368
|
|
|
369
|
$Qtemplates->freeResult();
|
|
370
|
|
|
371
|
if (empty($data)) {
|
|
372
|
$data =& $data_default;
|
|
373
|
}
|
|
374
|
|
|
375
|
$_SESSION['template'] =& $data;
|
|
376
|
}
|
|
377
|
|
|
378
|
$this->_template_id =& $_SESSION['template']['id'];
|
|
379
|
$this->_template =& $_SESSION['template']['code'];
|
hpdl
|
125
|
380
|
}
|
|
381
|
|
|
382
|
/**
|
|
383
|
* Sets the title of the page
|
|
384
|
*
|
|
385
|
* @param string $title The title of the page to set to
|
|
386
|
* @access public
|
|
387
|
*/
|
|
388
|
|
|
389
|
function setPageTitle($title) {
|
|
390
|
$this->_page_title = $title;
|
|
391
|
}
|
|
392
|
|
|
393
|
/**
|
hpdl
|
208
|
394
|
* Sets the image of the page
|
|
395
|
*
|
|
396
|
* @param string $image The image of the page to set to
|
|
397
|
* @access public
|
|
398
|
*/
|
|
399
|
|
|
400
|
function setPageImage($image) {
|
|
401
|
$this->_page_image = $image;
|
|
402
|
}
|
|
403
|
|
|
404
|
/**
|
hpdl
|
125
|
405
|
* Sets the content of the page
|
|
406
|
*
|
|
407
|
* @param string $filename The content filename to include on the page
|
|
408
|
* @access public
|
|
409
|
*/
|
|
410
|
|
|
411
|
function setPageContentsFilename($filename) {
|
|
412
|
$this->_page_contents_filename = $filename;
|
|
413
|
}
|
|
414
|
|
|
415
|
/**
|
hpdl
|
248
|
416
|
* Adds a tag to the meta keywords array
|
|
417
|
*
|
|
418
|
* @param string $key The keyword for the meta tag
|
|
419
|
* @param string $value The value for the meta tag using the key
|
|
420
|
* @access public
|
|
421
|
*/
|
|
422
|
|
|
423
|
function addPageTags($key, $value) {
|
|
424
|
$this->_page_tags[$key][] = $value;
|
|
425
|
}
|
|
426
|
|
|
427
|
/**
|
hpdl
|
125
|
428
|
* Adds a javascript file to link to
|
|
429
|
*
|
|
430
|
* @param string $filename The javascript filename to link to
|
|
431
|
* @access public
|
|
432
|
*/
|
|
433
|
|
|
434
|
function addJavascriptFilename($filename) {
|
|
435
|
$this->_javascript_filenames[] = $filename;
|
|
436
|
}
|
|
437
|
|
|
438
|
/**
|
|
439
|
* Adds a PHP based javascript file to embedd on the page
|
|
440
|
*
|
|
441
|
* @param string $filename The PHP based javascript filename to embedd
|
|
442
|
* @access public
|
|
443
|
*/
|
|
444
|
|
|
445
|
function addJavascriptPhpFilename($filename) {
|
|
446
|
$this->_javascript_php_filenames[] = $filename;
|
|
447
|
}
|
|
448
|
|
|
449
|
/**
|
|
450
|
* Adds javascript logic to the page
|
|
451
|
*
|
|
452
|
* @param string $javascript The javascript block to add on the page
|
|
453
|
* @access public
|
|
454
|
*/
|
|
455
|
|
|
456
|
function addJavascriptBlock($javascript) {
|
|
457
|
$this->_javascript_blocks[] = $javascript;
|
|
458
|
}
|
|
459
|
|
|
460
|
/**
|
|
461
|
* Returns the javascript filenames to link to on the page
|
|
462
|
*
|
|
463
|
* @access private
|
|
464
|
* @return string
|
|
465
|
*/
|
|
466
|
|
|
467
|
function _getJavascriptFilenames() {
|
|
468
|
$js_files = '';
|
|
469
|
|
|
470
|
foreach ($this->_javascript_filenames as $filenames) {
|
|
471
|
$js_files .= '<script language="javascript" type="text/javascript" src="' . $filenames . '"></script>' . "\n";
|
|
472
|
}
|
|
473
|
|
|
474
|
return $js_files;
|
|
475
|
}
|
|
476
|
|
|
477
|
/**
|
|
478
|
* Returns the PHP javascript files to embedd on the page
|
|
479
|
*
|
|
480
|
* @access private
|
|
481
|
*/
|
|
482
|
|
|
483
|
function _getJavascriptPhpFilenames() {
|
|
484
|
foreach ($this->_javascript_php_filenames as $filenames) {
|
|
485
|
include($filenames);
|
|
486
|
}
|
|
487
|
}
|
|
488
|
|
|
489
|
/**
|
|
490
|
* Returns javascript blocks to add to the page
|
|
491
|
*
|
|
492
|
* @access private
|
|
493
|
* @return string
|
|
494
|
*/
|
|
495
|
|
|
496
|
function _getJavascriptBlocks() {
|
|
497
|
return implode("\n", $this->_javascript_blocks);
|
|
498
|
}
|
|
499
|
}
|
|
500
|
?>
|