source: forum/style.php@ 651

Last change on this file since 651 was 651, checked in by aleg, 15 years ago

Změněná cesta k GM a Char logům pro realmy 4 a 7.

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