1 | <?php
|
---|
2 | /**
|
---|
3 | *
|
---|
4 | * @package phpBB3
|
---|
5 | * @version $Id$
|
---|
6 | * @copyright (c) 2005 phpBB Group
|
---|
7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * @ignore
|
---|
13 | */
|
---|
14 | define('IN_PHPBB', true);
|
---|
15 | $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
|
---|
16 | $phpEx = substr(strrchr(__FILE__, '.'), 1);
|
---|
17 |
|
---|
18 | // Report all errors, except notices and deprecation messages
|
---|
19 | if (!defined('E_DEPRECATED'))
|
---|
20 | {
|
---|
21 | define('E_DEPRECATED', 8192);
|
---|
22 | }
|
---|
23 | error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
|
---|
24 |
|
---|
25 | require($phpbb_root_path . 'config.' . $phpEx);
|
---|
26 |
|
---|
27 | if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type))
|
---|
28 | {
|
---|
29 | exit;
|
---|
30 | }
|
---|
31 |
|
---|
32 | if (version_compare(PHP_VERSION, '6.0.0-dev', '<'))
|
---|
33 | {
|
---|
34 | @set_magic_quotes_runtime(0);
|
---|
35 | }
|
---|
36 |
|
---|
37 | // Load Extensions
|
---|
38 | if (!empty($load_extensions) && function_exists('dl'))
|
---|
39 | {
|
---|
40 | $load_extensions = explode(',', $load_extensions);
|
---|
41 |
|
---|
42 | foreach ($load_extensions as $extension)
|
---|
43 | {
|
---|
44 | @dl(trim($extension));
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | $sid = (isset($_GET['sid']) && !is_array($_GET['sid'])) ? htmlspecialchars($_GET['sid']) : '';
|
---|
50 | $id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
|
---|
51 |
|
---|
52 | if (strspn($sid, 'abcdefABCDEF0123456789') !== strlen($sid))
|
---|
53 | {
|
---|
54 | $sid = '';
|
---|
55 | }
|
---|
56 |
|
---|
57 | // This is a simple script to grab and output the requested CSS data stored in the DB
|
---|
58 | // We include a session_id check to try and limit 3rd party linking ... unless they
|
---|
59 | // happen to have a current session it will output nothing. We will also cache the
|
---|
60 | // resulting CSS data for five minutes ... anything to reduce the load on the SQL
|
---|
61 | // server a little
|
---|
62 | if ($id)
|
---|
63 | {
|
---|
64 | // Include files
|
---|
65 | require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
|
---|
66 | require($phpbb_root_path . 'includes/cache.' . $phpEx);
|
---|
67 | require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
|
---|
68 | require($phpbb_root_path . 'includes/constants.' . $phpEx);
|
---|
69 | require($phpbb_root_path . 'includes/functions.' . $phpEx);
|
---|
70 |
|
---|
71 | $db = new $sql_db();
|
---|
72 | $cache = new cache();
|
---|
73 |
|
---|
74 | // Connect to DB
|
---|
75 | if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false))
|
---|
76 | {
|
---|
77 | exit;
|
---|
78 | }
|
---|
79 | unset($dbpasswd);
|
---|
80 |
|
---|
81 | $config = $cache->obtain_config();
|
---|
82 | $user = false;
|
---|
83 |
|
---|
84 | if ($sid)
|
---|
85 | {
|
---|
86 | $sql = 'SELECT u.user_id, u.user_lang
|
---|
87 | FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u
|
---|
88 | WHERE s.session_id = '" . $db->sql_escape($sid) . "'
|
---|
89 | AND s.session_user_id = u.user_id";
|
---|
90 | $result = $db->sql_query($sql);
|
---|
91 | $user = $db->sql_fetchrow($result);
|
---|
92 | $db->sql_freeresult($result);
|
---|
93 | }
|
---|
94 |
|
---|
95 | $recompile = $config['load_tplcompile'];
|
---|
96 | if (!$user)
|
---|
97 | {
|
---|
98 | $id = ($id) ? $id : $config['default_style'];
|
---|
99 | // Commented out because calls do not always include the SID anymore
|
---|
100 | // $recompile = false;
|
---|
101 | $user = array('user_id' => ANONYMOUS);
|
---|
102 | }
|
---|
103 |
|
---|
104 | $sql = 'SELECT s.style_id, c.theme_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, i.*, t.template_path
|
---|
105 | FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . ' i
|
---|
106 | WHERE s.style_id = ' . $id . '
|
---|
107 | AND t.template_id = s.template_id
|
---|
108 | AND c.theme_id = s.theme_id
|
---|
109 | AND i.imageset_id = s.imageset_id';
|
---|
110 | $result = $db->sql_query($sql, 300);
|
---|
111 | $theme = $db->sql_fetchrow($result);
|
---|
112 | $db->sql_freeresult($result);
|
---|
113 |
|
---|
114 | if (!$theme)
|
---|
115 | {
|
---|
116 | exit;
|
---|
117 | }
|
---|
118 |
|
---|
119 | if ($user['user_id'] == ANONYMOUS)
|
---|
120 | {
|
---|
121 | $user['user_lang'] = $config['default_lang'];
|
---|
122 | }
|
---|
123 |
|
---|
124 | $user_image_lang = (file_exists($phpbb_root_path . 'styles/' . $theme['imageset_path'] . '/imageset/' . $user['user_lang'])) ? $user['user_lang'] : $config['default_lang'];
|
---|
125 |
|
---|
126 | // Same query in session.php
|
---|
127 | $sql = 'SELECT *
|
---|
128 | FROM ' . STYLES_IMAGESET_DATA_TABLE . '
|
---|
129 | WHERE imageset_id = ' . $theme['imageset_id'] . "
|
---|
130 | AND image_filename <> ''
|
---|
131 | AND image_lang IN ('" . $db->sql_escape($user_image_lang) . "', '')";
|
---|
132 | $result = $db->sql_query($sql, 3600);
|
---|
133 |
|
---|
134 | $img_array = array();
|
---|
135 | while ($row = $db->sql_fetchrow($result))
|
---|
136 | {
|
---|
137 | $img_array[$row['image_name']] = $row;
|
---|
138 | }
|
---|
139 | $db->sql_freeresult($result);
|
---|
140 |
|
---|
141 | // gzip_compression
|
---|
142 | if ($config['gzip_compress'])
|
---|
143 | {
|
---|
144 | // IE6 is not able to compress the style (do not ask us why!)
|
---|
145 | $browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? strtolower(htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT'])) : '';
|
---|
146 |
|
---|
147 | if ($browser && strpos($browser, 'msie 6.0') === false && @extension_loaded('zlib') && !headers_sent())
|
---|
148 | {
|
---|
149 | ob_start('ob_gzhandler');
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | // Expire time of seven days if not recached
|
---|
154 | $expire_time = 7*86400;
|
---|
155 | $recache = false;
|
---|
156 |
|
---|
157 | // Re-cache stylesheet data if necessary
|
---|
158 | if ($recompile || empty($theme['theme_data']))
|
---|
159 | {
|
---|
160 | $recache = (empty($theme['theme_data'])) ? true : false;
|
---|
161 | $update_time = time();
|
---|
162 |
|
---|
163 | // We test for stylesheet.css because it is faster and most likely the only file changed on common themes
|
---|
164 | if (!$recache && $theme['theme_mtime'] < @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'))
|
---|
165 | {
|
---|
166 | $recache = true;
|
---|
167 | $update_time = @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css');
|
---|
168 | }
|
---|
169 | else if (!$recache)
|
---|
170 | {
|
---|
171 | $last_change = $theme['theme_mtime'];
|
---|
172 | $dir = @opendir("{$phpbb_root_path}styles/{$theme['theme_path']}/theme");
|
---|
173 |
|
---|
174 | if ($dir)
|
---|
175 | {
|
---|
176 | while (($entry = readdir($dir)) !== false)
|
---|
177 | {
|
---|
178 | if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime("{$phpbb_root_path}styles/{$theme['theme_path']}/theme/{$entry}"))
|
---|
179 | {
|
---|
180 | $recache = true;
|
---|
181 | break;
|
---|
182 | }
|
---|
183 | }
|
---|
184 | closedir($dir);
|
---|
185 | }
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | if ($recache)
|
---|
190 | {
|
---|
191 | include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx);
|
---|
192 |
|
---|
193 | $theme['theme_data'] = acp_styles::db_theme_data($theme);
|
---|
194 | $theme['theme_mtime'] = $update_time;
|
---|
195 |
|
---|
196 | // Save CSS contents
|
---|
197 | $sql_ary = array(
|
---|
198 | 'theme_mtime' => $theme['theme_mtime'],
|
---|
199 | 'theme_data' => $theme['theme_data']
|
---|
200 | );
|
---|
201 |
|
---|
202 | $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
|
---|
203 | WHERE theme_id = {$theme['theme_id']}";
|
---|
204 | $db->sql_query($sql);
|
---|
205 |
|
---|
206 | $cache->destroy('sql', STYLES_THEME_TABLE);
|
---|
207 | }
|
---|
208 |
|
---|
209 | // Only set the expire time if the theme changed data is older than 30 minutes - to cope with changes from the ACP
|
---|
210 | if ($recache || $theme['theme_mtime'] > (time() - 1800))
|
---|
211 | {
|
---|
212 | header('Expires: 0');
|
---|
213 | }
|
---|
214 | else
|
---|
215 | {
|
---|
216 | header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $expire_time));
|
---|
217 | }
|
---|
218 |
|
---|
219 | header('Content-type: text/css; charset=UTF-8');
|
---|
220 |
|
---|
221 | // Parse Theme Data
|
---|
222 | $replace = array(
|
---|
223 | '{T_THEME_PATH}' => "{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme',
|
---|
224 | '{T_TEMPLATE_PATH}' => "{$phpbb_root_path}styles/" . $theme['template_path'] . '/template',
|
---|
225 | '{T_IMAGESET_PATH}' => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset',
|
---|
226 | '{T_IMAGESET_LANG_PATH}' => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset/' . $user_image_lang,
|
---|
227 | '{T_STYLESHEET_NAME}' => $theme['theme_name'],
|
---|
228 | '{S_USER_LANG}' => $user['user_lang']
|
---|
229 | );
|
---|
230 |
|
---|
231 | $theme['theme_data'] = str_replace(array_keys($replace), array_values($replace), $theme['theme_data']);
|
---|
232 |
|
---|
233 | $matches = array();
|
---|
234 | preg_match_all('#\{IMG_([A-Za-z0-9_]*?)_(WIDTH|HEIGHT|SRC)\}#', $theme['theme_data'], $matches);
|
---|
235 |
|
---|
236 | $imgs = $find = $replace = array();
|
---|
237 | if (isset($matches[0]) && sizeof($matches[0]))
|
---|
238 | {
|
---|
239 | foreach ($matches[1] as $i => $img)
|
---|
240 | {
|
---|
241 | $img = strtolower($img);
|
---|
242 | $find[] = $matches[0][$i];
|
---|
243 |
|
---|
244 | if (!isset($img_array[$img]))
|
---|
245 | {
|
---|
246 | $replace[] = '';
|
---|
247 | continue;
|
---|
248 | }
|
---|
249 |
|
---|
250 | if (!isset($imgs[$img]))
|
---|
251 | {
|
---|
252 | $img_data = &$img_array[$img];
|
---|
253 | $imgsrc = ($img_data['image_lang'] ? $img_data['image_lang'] . '/' : '') . $img_data['image_filename'];
|
---|
254 | $imgs[$img] = array(
|
---|
255 | 'src' => $phpbb_root_path . 'styles/' . $theme['imageset_path'] . '/imageset/' . $imgsrc,
|
---|
256 | 'width' => $img_data['image_width'],
|
---|
257 | 'height' => $img_data['image_height'],
|
---|
258 | );
|
---|
259 | }
|
---|
260 |
|
---|
261 | switch ($matches[2][$i])
|
---|
262 | {
|
---|
263 | case 'SRC':
|
---|
264 | $replace[] = $imgs[$img]['src'];
|
---|
265 | break;
|
---|
266 |
|
---|
267 | case 'WIDTH':
|
---|
268 | $replace[] = $imgs[$img]['width'];
|
---|
269 | break;
|
---|
270 |
|
---|
271 | case 'HEIGHT':
|
---|
272 | $replace[] = $imgs[$img]['height'];
|
---|
273 | break;
|
---|
274 |
|
---|
275 | default:
|
---|
276 | continue;
|
---|
277 | }
|
---|
278 | }
|
---|
279 |
|
---|
280 | if (sizeof($find))
|
---|
281 | {
|
---|
282 | $theme['theme_data'] = str_replace($find, $replace, $theme['theme_data']);
|
---|
283 | }
|
---|
284 | }
|
---|
285 |
|
---|
286 | echo $theme['theme_data'];
|
---|
287 |
|
---|
288 | if (!empty($cache))
|
---|
289 | {
|
---|
290 | $cache->unload();
|
---|
291 | }
|
---|
292 | $db->sql_close();
|
---|
293 | }
|
---|
294 |
|
---|
295 | exit;
|
---|
296 |
|
---|
297 | ?>
|
---|