5
* @version $Id: style.php,v 1.51 2007/08/19 15:58:31 acydburn Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
define('IN_PHPBB', true);
15
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
16
$phpEx = substr(strrchr(__FILE__, '.'), 1);
17
require($phpbb_root_path . 'config.' . $phpEx);
19
if (version_compare(PHP_VERSION, '6.0.0-dev', '<'))
21
set_magic_quotes_runtime(0);
25
if (!empty($load_extensions))
27
$load_extensions = explode(',', $load_extensions);
29
foreach ($load_extensions as $extension)
31
@dl(trim($extension));
36
$sid = (isset($_GET['sid']) && !is_array($_GET['sid'])) ? htmlspecialchars($_GET['sid']) : '';
37
$id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
39
if (strspn($sid, 'abcdefABCDEF0123456789') !== strlen($sid))
44
// This is a simple script to grab and output the requested CSS data stored in the DB
45
// We include a session_id check to try and limit 3rd party linking ... unless they
46
// happen to have a current session it will output nothing. We will also cache the
47
// resulting CSS data for five minutes ... anything to reduce the load on the SQL
51
if (empty($acm_type) || empty($dbms))
53
die('Hacking attempt');
57
require($phpbb_root_path . 'includes/acm/acm_' . $acm_type . '.' . $phpEx);
58
require($phpbb_root_path . 'includes/cache.' . $phpEx);
59
require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx);
60
require($phpbb_root_path . 'includes/constants.' . $phpEx);
66
if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false))
72
$config = $cache->obtain_config();
77
$sql = 'SELECT u.user_id, u.user_lang
78
FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u
79
WHERE s.session_id = '" . $db->sql_escape($sid) . "'
80
AND s.session_user_id = u.user_id";
81
$result = $db->sql_query($sql);
82
$user = $db->sql_fetchrow($result);
83
$db->sql_freeresult($result);
86
$recompile = $config['load_tplcompile'];
89
$id = $config['default_style'];
91
$user = array('user_id' => ANONYMOUS);
94
$sql = 'SELECT s.style_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, i.*, t.template_path
95
FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . ' i
96
WHERE s.style_id = ' . $id . '
97
AND t.template_id = s.template_id
98
AND c.theme_id = s.theme_id
99
AND i.imageset_id = s.imageset_id';
100
$result = $db->sql_query($sql, 300);
101
$theme = $db->sql_fetchrow($result);
102
$db->sql_freeresult($result);
109
if ($user['user_id'] == ANONYMOUS)
111
$user['user_lang'] = $config['default_lang'];
114
$user_image_lang = (file_exists($phpbb_root_path . 'styles/' . $theme['imageset_path'] . '/imageset/' . $user['user_lang'])) ? $user['user_lang'] : $config['default_lang'];
117
FROM ' . STYLES_IMAGESET_DATA_TABLE . '
118
WHERE imageset_id = ' . $theme['imageset_id'] . "
119
AND image_lang IN ('" . $db->sql_escape($user_image_lang) . "', '')";
120
$result = $db->sql_query($sql, 3600);
122
$img_array = array();
123
while ($row = $db->sql_fetchrow($result))
125
$img_array[$row['image_name']] = $row;
127
$db->sql_freeresult($result);
130
if ($config['gzip_compress'])
132
// IE6 is not able to compress the style (do not ask us why!)
133
$browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? strtolower(htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT'])) : '';
135
if ($browser && strpos($browser, 'msie 6.0') === false && @extension_loaded('zlib') && !headers_sent())
137
ob_start('ob_gzhandler');
141
// Expire time of seven days if not recached
142
$expire_time = 7*86400;
145
// Re-cache stylesheet data if necessary
146
if ($recompile || empty($theme['theme_data']))
148
$recache = (empty($theme['theme_data'])) ? true : false;
149
$update_time = time();
151
// We test for stylesheet.css because it is faster and most likely the only file changed on common themes
152
if (!$recache && $theme['theme_mtime'] < @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'))
155
$update_time = @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css');
159
$last_change = $theme['theme_mtime'];
160
$dir = @opendir("{$phpbb_root_path}styles/{$theme['theme_path']}/theme");
164
while (($entry = readdir($dir)) !== false)
166
if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime("{$phpbb_root_path}styles/{$theme['theme_path']}/theme/{$entry}"))
179
include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx);
181
$theme['theme_data'] = acp_styles::db_theme_data($theme);
182
$theme['theme_mtime'] = $update_time;
186
'theme_mtime' => $theme['theme_mtime'],
187
'theme_data' => $theme['theme_data']
190
$sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
191
WHERE theme_id = $id";
192
$db->sql_query($sql);
194
$cache->destroy('sql', STYLES_THEME_TABLE);
197
// Only set the expire time if the theme changed data is older than 30 minutes - to cope with changes from the ACP
198
if ($recache || $theme['theme_mtime'] > (time() - 1800))
200
header('Expires: 0');
204
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $expire_time));
207
header('Content-type: text/css; charset=UTF-8');
211
'{T_THEME_PATH}' => "{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme',
212
'{T_TEMPLATE_PATH}' => "{$phpbb_root_path}styles/" . $theme['template_path'] . '/template',
213
'{T_IMAGESET_PATH}' => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset',
214
'{T_IMAGESET_LANG_PATH}' => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset/' . $user_image_lang,
215
'{T_STYLESHEET_NAME}' => $theme['theme_name'],
216
'{S_USER_LANG}' => $user['user_lang']
219
$theme['theme_data'] = str_replace(array_keys($replace), array_values($replace), $theme['theme_data']);
222
preg_match_all('#\{IMG_([A-Za-z0-9_]*?)_(WIDTH|HEIGHT|SRC)\}#', $theme['theme_data'], $matches);
224
$imgs = $find = $replace = array();
225
if (isset($matches[0]) && sizeof($matches[0]))
227
foreach ($matches[1] as $i => $img)
229
$img = strtolower($img);
230
$find[] = $matches[0][$i];
232
if (!isset($img_array[$img]))
238
if (!isset($imgs[$img]))
240
$img_data = &$img_array[$img];
241
$imgsrc = ($img_data['image_lang'] ? $img_data['image_lang'] . '/' : '') . $img_data['image_filename'];
243
'src' => $phpbb_root_path . 'styles/' . $theme['imageset_path'] . '/imageset/' . $imgsrc,
244
'width' => $img_data['image_width'],
245
'height' => $img_data['image_height'],
249
switch ($matches[2][$i])
252
$replace[] = $imgs[$img]['src'];
256
$replace[] = $imgs[$img]['width'];
260
$replace[] = $imgs[$img]['height'];
270
$theme['theme_data'] = str_replace($find, $replace, $theme['theme_data']);
274
echo $theme['theme_data'];
b'\\ No newline at end of file'