File: SpotPage_Abs.php

package info (click to toggle)
spotweb 20130826%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,132 kB
  • ctags: 11,281
  • sloc: php: 31,367; xml: 1,009; sh: 148; makefile: 83
file content (125 lines) | stat: -rwxr-xr-x 4,091 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
abstract class SpotPage_Abs {
	protected $_db;
	protected $_settings;
	protected $_pageTitle;
	protected $_currentSession;
	protected $_spotSec;
	protected $_tplHelper;

	protected $_templatePaths;
	
	function __construct(SpotDb $db, SpotSettings $settings, $currentSession) {
		$this->_db = $db;
		$this->_settings = $settings;
		$this->_currentSession = $currentSession;
		$this->_spotSec = $currentSession['security'];
		$this->_tplHelper = $this->getTplHelper(array());

		/*
		 * Create a list of paths where to look for template files in
		 * the correct (last template first) order
		 */
		$this->_templatePaths = array('/usr/share/spotweb/templates/' . $currentSession['active_tpl'] . '/');
		foreach($this->_tplHelper->getParentTemplates() as $parentTemplate) {
			$this->_templatePaths[] = '/usr/share/spotweb/templates/' . $parentTemplate . '/';
		} # foreach
	} # ctor

	/* 
	 * Standaard mogen paginas niet gecached worden 
	 * om invalid cached informatie te voorkomen. Kan overriden worden
	 * per pagina
	 */
	function sendExpireHeaders($preventCaching) {
		if ($preventCaching) {
			Header("Cache-Control: private, post-check=1, pre-check=2, max-age=1, must-revalidate");
			Header("Expires: Mon, 12 Jul 2000 01:00:00 GMT");
		} else {
			# stuur een expires header zodat dit een jaar of 10 geldig is
			Header("Cache-Control: public");
			Header("Expires: " . gmdate("D, d M Y H:i:s", (time() + (86400 * 3650))) . " GMT");
			Header("Pragma: ");
		} # if
	} # sendExpireHeaders
	
	/*
	 * Stuur een content header, dit zorgt er voor dat de browser
	 * eventuele content sneller kan parsen
	 */
	function sendContentTypeHeader($type) {
		switch($type) {
			case 'xml'		: Header("Content-Type: text/xml; charset=utf-8"); break;
			case 'rss'		: Header("Content-Type: application/rss+xml; charset=utf-8"); break;
			case 'json'		: Header("Content-Type: application/json; charset=utf-8"); break;
			case 'css'		: Header("Content-Type: text/css; charset=utf-8"); break;
			case 'js'		: Header("Content-Type: application/javascript; charset=utf-8"); break;
			case 'ico'		: Header("Content-Type: image/x-icon"); break;
			
			default 		: Header("Content-Type: text/html; charset=utf-8"); break;
		} # switch
		
	} # sendContentTypeHeader

	
	# Geef the tpl helper terug
	private function getTplHelper($params) {
		$tplName = $this->_currentSession['active_tpl'];

		$className = 'SpotTemplateHelper_' . ucfirst($tplName);
		$tplHelper = new $className($this->_settings, $this->_currentSession, $this->_db, $params);

		return $tplHelper;
	} # getTplHelper
		
	
	/*
	 * Display de template
	 */
	function template($tpl, $params = array()) {
		SpotTiming::start(__FUNCTION__ . ':' . $tpl);
		
		extract($params, EXTR_REFS);
		$settings = $this->_settings;
		$pagetitle = $this->_pageTitle;
		
		# update the template helper variables
		$this->_tplHelper->setParams($params);
		
		# Expose some variables to the template script in its local scope
		$tplHelper = $this->_tplHelper;
		$currentSession = $this->_currentSession;
		$spotSec = $this->_currentSession['security'];

		# send any expire headers
		$this->sendExpireHeaders(true);
		$this->sendContentTypeHeader('html');
		
		# and include the template
		foreach($this->_templatePaths as $tplPath) {
			if (file_exists($tplPath . $tpl . '.inc.php')) {
				require_once($tplPath . $tpl . '.inc.php');

				break;
			} # if
		} # foreach
		SpotTiming::stop(__FUNCTION__ . ':' . $tpl, array($params));
	} # template
	
	/*
	 * Daadwerkelijk renderen van de pagina -- implementatie specifiek
	 */
	abstract function render();
	
	/*
	 * Renderen van een permission denied pagina, kan overridden worden door een implementatie
	 * specifieke renderer
	 */
	function permissionDenied($exception, $page, $http_referer) {
		$this->template('permdenied',
							array('exception' => $exception,
								  'page' => $page,
								  'http_referer' => $http_referer));
	} # permissionDenied
	
} # SpotPage_Abs