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

