aboutsummaryrefslogtreecommitdiffstats
path: root/htdocs/application/controllers/Theme_assets.php
blob: a6d084fbc4c0f89d1cf19600109c626e407d7c02 (plain) (blame)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/**
 * Class and Function List:
 * Function list:
 * - __construct()
 * - css()
 * - fonts()
 * - images()
 * - js()
 * - _expires_header()
 * Classes list:
 * - Theme_assets extends CI_Controller
 */

class Theme_assets extends CI_Controller
{
	
	function __construct() 
	{
		parent::__construct();
		$this->theme = config_item('theme');
	}
	
	function css() 
	{
		$css_file = $this->uri->segment(4);
		$css_file = basename($css_file); // Fix LFI Vulnerability

		
		if ($css_file == 'fonts') 
		{
			$font_file = $this->uri->segment(5);
			$font_file = basename($font_file);

			//file path
			$file_path = 'themes/' . $this->theme . '/css/fonts/' . $font_file;
			
			if (!file_exists($file_path)) 
			{
				return false;
			}
			$path_parts = pathinfo(dirname(dirname(dirname(__FILE__))) . '/' . $file_path);
			
			if ($path_parts['extension'] == "woff") 
			{
				header('Content-type: application/font-woff');
			}
			
			if ($path_parts['extension'] == "eot") 
			{
				header('Content-type: application/vnd.ms-fontobject');
			}
			
			if ($path_parts['extension'] == "ttf" || $path_parts['extension'] == "ttc") 
			{
				header('Content-type: application/x-font-ttf');
			}
			
			if ($path_parts['extension'] == "otf") 
			{
				header('Content-type: font/opentype');
			}
			
			if ($path_parts['extension'] == "svg") 
			{
				header('Content-type: image/svg+xml');
			}
			
			if ($path_parts['extension'] == "svgz") 
			{
				header("Content-Encoding: gzip");
				header('Content-type: image/svg+xml');
			}

			//send
			$this->_expires_header(1);
			readfile($file_path);
		}
		else
		{

			//file path
			$file_path = 'themes/' . $this->theme . '/css/' . $css_file;

			//fallback to default css if view in theme not found
			
			if (!file_exists($file_path)) 
			{
				$file_path = 'themes/default/css/' . $css_file;
			}

			// Double checking file
			
			if (!file_exists($file_path)) 
			{
				return false;
			}

			//send
			header('Content-type: text/css');
			$this->_expires_header(1);
			readfile($file_path);
		}
	}
	
	function fonts() 
	{
		$font_file = $this->uri->segment(4);

		//file path
		$file_path = 'themes/' . $this->theme . '/fonts/' . $font_file;

		//no fallback to default, since default has no such fonts
		//since no fallbcack, there is no doucle checking for file

		
		if (!file_exists($file_path)) 
		{
			return false;
		}

		//send
		$path_parts = pathinfo(dirname(dirname(dirname(__FILE__))) . '/' . $file_path);
		
		if ($path_parts['extension'] == "woff") 
		{
			header('Content-type: application/font-woff');
		}
		
		if ($path_parts['extension'] == "eot") 
		{
			header('Content-type: application/vnd.ms-fontobject');
		}
		
		if ($path_parts['extension'] == "ttf" || $path_parts['extension'] == "ttc") 
		{
			header('Content-type: application/x-font-ttf');
		}
		
		if ($path_parts['extension'] == "otf") 
		{
			header('Content-type: font/opentype');
		}
		
		if ($path_parts['extension'] == "svg") 
		{
			header('Content-type: image/svg+xml');
		}
		
		if ($path_parts['extension'] == "svgz") 
		{
			header("Content-Encoding: gzip");
			header('Content-type: image/svg+xml');
		}
		$this->_expires_header(1);
		readfile($file_path);
	}
	
	function images() 
	{
		$image_file = $this->uri->segment(4);
		$image_file = basename($image_file);

		//file path
		$file_path = 'themes/' . $this->theme . '/images/' . $image_file;

		//fallback to default css if view in theme not found
		
		if (!file_exists($file_path)) 
		{
			$file_path = 'themes/default/images/' . $image_file;
		}

		// double checking file
		
		if (!file_exists($file_path)) 
		{
			return false;
		}

		//send
		$size = getimagesize($file_path);
		header('Content-type: ' . $size['mime']);
		$this->_expires_header(30);
		readfile($file_path);
	}
	
	function js() 
	{

		//get js
		$segments = $this->uri->segment_array();
		array_shift($segments);
		array_shift($segments);
		array_shift($segments);
		$js_file = implode('/', $segments);
		$js_file = str_replace('../', '', $js_file);

		//file path
		$file_path = 'themes/' . $this->theme . '/js/' . $js_file;

		//fallback to default js if js in theme not found
		
		if (!file_exists($file_path)) 
		{
			$file_path = 'themes/default/js/' . $js_file;
		}

		// return empty string if not found, to not mess up existing JS
		
		if (!file_exists($file_path)) 
		{
			header('HTTP/1.1 404 Not Found');
			return '';
		}

		//send
		header('Content-Type: application/x-javascript; charset=utf-8');
		$this->_expires_header(30);
		readfile($file_path);
	}
	private 
	function _expires_header($days) 
	{
		header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 60 * 60 * 24 * $days));
	}
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy