~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/php/phpBB3/style.php

Merge from new-dispatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
*
 
4
* @package phpBB3
 
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
 
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
require($phpbb_root_path . 'config.' . $phpEx);
 
18
 
 
19
if (version_compare(PHP_VERSION, '6.0.0-dev', '<'))
 
20
{
 
21
        set_magic_quotes_runtime(0);
 
22
}
 
23
 
 
24
// Load Extensions
 
25
if (!empty($load_extensions))
 
26
{
 
27
        $load_extensions = explode(',', $load_extensions);
 
28
 
 
29
        foreach ($load_extensions as $extension)
 
30
        {
 
31
                @dl(trim($extension));
 
32
        }
 
33
}
 
34
 
 
35
 
 
36
$sid = (isset($_GET['sid']) && !is_array($_GET['sid'])) ? htmlspecialchars($_GET['sid']) : '';
 
37
$id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
 
38
 
 
39
if (strspn($sid, 'abcdefABCDEF0123456789') !== strlen($sid))
 
40
{
 
41
        $sid = '';
 
42
}
 
43
 
 
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
 
48
// server a little
 
49
if ($id)
 
50
{
 
51
        if (empty($acm_type) || empty($dbms))
 
52
        {
 
53
                die('Hacking attempt');
 
54
        }
 
55
 
 
56
        // Include files
 
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);
 
61
 
 
62
        $db = new $sql_db();
 
63
        $cache = new cache();
 
64
 
 
65
        // Connect to DB
 
66
        if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false))
 
67
        {
 
68
                exit;
 
69
        }
 
70
        unset($dbpasswd);
 
71
 
 
72
        $config = $cache->obtain_config();
 
73
        $user = false;
 
74
 
 
75
        if ($sid)
 
76
        {
 
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);
 
84
        }
 
85
 
 
86
        $recompile = $config['load_tplcompile'];
 
87
        if (!$user)
 
88
        {
 
89
                $id                     = $config['default_style'];
 
90
                $recompile      = false;
 
91
                $user           = array('user_id' => ANONYMOUS);
 
92
        }
 
93
 
 
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);
 
103
 
 
104
        if (!$theme)
 
105
        {
 
106
                exit;
 
107
        }
 
108
 
 
109
        if ($user['user_id'] == ANONYMOUS)
 
110
        {
 
111
                $user['user_lang'] = $config['default_lang'];
 
112
        }
 
113
 
 
114
        $user_image_lang = (file_exists($phpbb_root_path . 'styles/' . $theme['imageset_path'] . '/imageset/' . $user['user_lang'])) ? $user['user_lang'] : $config['default_lang'];
 
115
 
 
116
        $sql = 'SELECT *
 
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);
 
121
 
 
122
        $img_array = array();
 
123
        while ($row = $db->sql_fetchrow($result))
 
124
        {
 
125
                $img_array[$row['image_name']] = $row;
 
126
        }
 
127
        $db->sql_freeresult($result);
 
128
 
 
129
        // gzip_compression
 
130
        if ($config['gzip_compress'])
 
131
        {
 
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'])) : '';
 
134
 
 
135
                if ($browser && strpos($browser, 'msie 6.0') === false && @extension_loaded('zlib') && !headers_sent())
 
136
                {
 
137
                        ob_start('ob_gzhandler');
 
138
                }
 
139
        }
 
140
 
 
141
        // Expire time of seven days if not recached
 
142
        $expire_time = 7*86400;
 
143
        $recache = false;
 
144
 
 
145
        // Re-cache stylesheet data if necessary
 
146
        if ($recompile || empty($theme['theme_data']))
 
147
        {
 
148
                $recache = (empty($theme['theme_data'])) ? true : false;
 
149
                $update_time = time();
 
150
 
 
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'))
 
153
                {
 
154
                        $recache = true;
 
155
                        $update_time = @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css');
 
156
                }
 
157
                else if (!$recache)
 
158
                {
 
159
                        $last_change = $theme['theme_mtime'];
 
160
                        $dir = @opendir("{$phpbb_root_path}styles/{$theme['theme_path']}/theme");
 
161
 
 
162
                        if ($dir)
 
163
                        {
 
164
                                while (($entry = readdir($dir)) !== false)
 
165
                                {
 
166
                                        if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime("{$phpbb_root_path}styles/{$theme['theme_path']}/theme/{$entry}"))
 
167
                                        {
 
168
                                                $recache = true;
 
169
                                                break;
 
170
                                        }
 
171
                                }
 
172
                                closedir($dir);
 
173
                        }
 
174
                }
 
175
        }
 
176
 
 
177
        if ($recache)
 
178
        {
 
179
                include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx);
 
180
 
 
181
                $theme['theme_data'] = acp_styles::db_theme_data($theme);
 
182
                $theme['theme_mtime'] = $update_time;
 
183
 
 
184
                // Save CSS contents
 
185
                $sql_ary = array(
 
186
                        'theme_mtime'   => $theme['theme_mtime'],
 
187
                        'theme_data'    => $theme['theme_data']
 
188
                );
 
189
 
 
190
                $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
 
191
                        WHERE theme_id = $id";
 
192
                $db->sql_query($sql);
 
193
 
 
194
                $cache->destroy('sql', STYLES_THEME_TABLE);
 
195
        }
 
196
 
 
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))
 
199
        {
 
200
                header('Expires: 0');
 
201
        }
 
202
        else
 
203
        {
 
204
                header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $expire_time));
 
205
        }
 
206
 
 
207
        header('Content-type: text/css; charset=UTF-8');
 
208
 
 
209
        // Parse Theme Data
 
210
        $replace = array(
 
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']
 
217
        );
 
218
 
 
219
        $theme['theme_data'] = str_replace(array_keys($replace), array_values($replace), $theme['theme_data']);
 
220
 
 
221
        $matches = array();
 
222
        preg_match_all('#\{IMG_([A-Za-z0-9_]*?)_(WIDTH|HEIGHT|SRC)\}#', $theme['theme_data'], $matches);
 
223
 
 
224
        $imgs = $find = $replace = array();
 
225
        if (isset($matches[0]) && sizeof($matches[0]))
 
226
        {
 
227
                foreach ($matches[1] as $i => $img)
 
228
                {
 
229
                        $img = strtolower($img);
 
230
                        $find[] = $matches[0][$i];
 
231
 
 
232
                        if (!isset($img_array[$img]))
 
233
                        {
 
234
                                $replace[] = '';
 
235
                                continue;
 
236
                        }
 
237
 
 
238
                        if (!isset($imgs[$img]))
 
239
                        {
 
240
                                $img_data = &$img_array[$img];
 
241
                                $imgsrc = ($img_data['image_lang'] ? $img_data['image_lang'] . '/' : '') . $img_data['image_filename'];
 
242
                                $imgs[$img] = array(
 
243
                                        'src'           => $phpbb_root_path . 'styles/' . $theme['imageset_path'] . '/imageset/' . $imgsrc,
 
244
                                        'width'         => $img_data['image_width'],
 
245
                                        'height'        => $img_data['image_height'],
 
246
                                );
 
247
                        }
 
248
 
 
249
                        switch ($matches[2][$i])
 
250
                        {
 
251
                                case 'SRC':
 
252
                                        $replace[] = $imgs[$img]['src'];
 
253
                                break;
 
254
                                
 
255
                                case 'WIDTH':
 
256
                                        $replace[] = $imgs[$img]['width'];
 
257
                                break;
 
258
        
 
259
                                case 'HEIGHT':
 
260
                                        $replace[] = $imgs[$img]['height'];
 
261
                                break;
 
262
 
 
263
                                default:
 
264
                                        continue;
 
265
                        }
 
266
                }
 
267
 
 
268
                if (sizeof($find))
 
269
                {
 
270
                        $theme['theme_data'] = str_replace($find, $replace, $theme['theme_data']);
 
271
                }
 
272
        }
 
273
 
 
274
        echo $theme['theme_data'];
 
275
 
 
276
        if (!empty($cache))
 
277
        {
 
278
                $cache->unload();
 
279
        }
 
280
        $db->sql_close();
 
281
}
 
282
 
 
283
exit;
 
284
 
 
285
?>
 
 
b'\\ No newline at end of file'