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