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