From 830c3f4047d0718ed398c38d4640cc0f1fe77a7f Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 3 Sep 2011 23:50:00 +0300 Subject: [feature/remove-imagesets] Adjustments to php files Removing imagesets. Adjustments to php files PHPBB3-10336 --- phpBB/style.php | 90 +++------------------------------------------------------ 1 file changed, 4 insertions(+), 86 deletions(-) (limited to 'phpBB/style.php') diff --git a/phpBB/style.php b/phpBB/style.php index eaab4544bc..22788ece94 100644 --- a/phpBB/style.php +++ b/phpBB/style.php @@ -111,12 +111,11 @@ if ($id) $user = array('user_id' => ANONYMOUS); } - $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 + $sql = 'SELECT s.style_id, c.theme_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, t.template_path + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c 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'; + AND c.theme_id = s.theme_id'; $result = $db->sql_query($sql, 300); $theme = $db->sql_fetchrow($result); $db->sql_freeresult($result); @@ -131,23 +130,6 @@ if ($id) $user['user_lang'] = $config['default_lang']; } - $user_image_lang = (file_exists($phpbb_root_path . 'styles/' . $theme['imageset_path'] . '/imageset/' . $user['user_lang'])) ? $user['user_lang'] : $config['default_lang']; - - // Same query in session.php - $sql = 'SELECT * - FROM ' . STYLES_IMAGESET_DATA_TABLE . ' - WHERE imageset_id = ' . $theme['imageset_id'] . " - AND image_filename <> '' - AND image_lang IN ('" . $db->sql_escape($user_image_lang) . "', '')"; - $result = $db->sql_query($sql, 3600); - - $img_array = array(); - while ($row = $db->sql_fetchrow($result)) - { - $img_array[$row['image_name']] = $row; - } - $db->sql_freeresult($result); - // gzip_compression if ($config['gzip_compress']) { @@ -228,71 +210,7 @@ if ($id) header('Content-type: text/css; charset=UTF-8'); - // Parse Theme Data - $replace = array( - '{T_THEME_PATH}' => "{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme', - '{T_TEMPLATE_PATH}' => "{$phpbb_root_path}styles/" . $theme['template_path'] . '/template', - '{T_IMAGESET_PATH}' => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset', - '{T_IMAGESET_LANG_PATH}' => "{$phpbb_root_path}styles/" . $theme['imageset_path'] . '/imageset/' . $user_image_lang, - '{T_STYLESHEET_NAME}' => $theme['theme_name'], - '{S_USER_LANG}' => $user['user_lang'] - ); - - $theme['theme_data'] = str_replace(array_keys($replace), array_values($replace), $theme['theme_data']); - - $matches = array(); - preg_match_all('#\{IMG_([A-Za-z0-9_]*?)_(WIDTH|HEIGHT|SRC)\}#', $theme['theme_data'], $matches); - - $imgs = $find = $replace = array(); - if (isset($matches[0]) && sizeof($matches[0])) - { - foreach ($matches[1] as $i => $img) - { - $img = strtolower($img); - $find[] = $matches[0][$i]; - - if (!isset($img_array[$img])) - { - $replace[] = ''; - continue; - } - - if (!isset($imgs[$img])) - { - $img_data = &$img_array[$img]; - $imgsrc = ($img_data['image_lang'] ? $img_data['image_lang'] . '/' : '') . $img_data['image_filename']; - $imgs[$img] = array( - 'src' => $phpbb_root_path . 'styles/' . $theme['imageset_path'] . '/imageset/' . $imgsrc, - 'width' => $img_data['image_width'], - 'height' => $img_data['image_height'], - ); - } - - switch ($matches[2][$i]) - { - case 'SRC': - $replace[] = $imgs[$img]['src']; - break; - - case 'WIDTH': - $replace[] = $imgs[$img]['width']; - break; - - case 'HEIGHT': - $replace[] = $imgs[$img]['height']; - break; - - default: - continue; - } - } - - if (sizeof($find)) - { - $theme['theme_data'] = str_replace($find, $replace, $theme['theme_data']); - } - } - + // Echo Theme Data echo $theme['theme_data']; if (!empty($cache)) -- cgit v1.2.1 From 934a9da313fd6af6986b5320314a2859a1526a1b Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 20:00:21 +0100 Subject: [feature/remove-db-styles] Remove style.php DB storage. Removed all use of the DB for serving/caching the theme from style.php, acp_style no longer stores the theme modified time either. As a consequence currently all stylesheets will be served through style.php (with no caching) until imagesets are removed [PHPBB3-10336], then they can we served as static files by HTTPd. PHPBB3-9741 --- phpBB/style.php | 66 ++++----------------------------------------------------- 1 file changed, 4 insertions(+), 62 deletions(-) (limited to 'phpBB/style.php') diff --git a/phpBB/style.php b/phpBB/style.php index 7f7b71d753..c84713f267 100644 --- a/phpBB/style.php +++ b/phpBB/style.php @@ -112,7 +112,7 @@ if ($id) $user = array('user_id' => ANONYMOUS); } - $sql = 'SELECT s.style_id, c.theme_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, t.template_path + $sql = 'SELECT s.style_id, c.theme_id, c.theme_path, c.theme_name, t.template_path FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c WHERE s.style_id = ' . $id . ' AND t.template_id = s.template_id @@ -145,70 +145,12 @@ if ($id) // Expire time of seven days if not recached $expire_time = 7*86400; - $recache = false; - // Re-cache stylesheet data if necessary - if ($recompile || empty($theme['theme_data'])) - { - $recache = (empty($theme['theme_data'])) ? true : false; - $update_time = time(); - - // We test for stylesheet.css because it is faster and most likely the only file changed on common themes - if (!$recache && $theme['theme_mtime'] < @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css')) - { - $recache = true; - $update_time = @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'); - } - else if (!$recache) - { - $last_change = $theme['theme_mtime']; - $dir = @opendir("{$phpbb_root_path}styles/{$theme['theme_path']}/theme"); - - if ($dir) - { - while (($entry = readdir($dir)) !== false) - { - if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime("{$phpbb_root_path}styles/{$theme['theme_path']}/theme/{$entry}")) - { - $recache = true; - break; - } - } - closedir($dir); - } - } - } - - if ($recache) - { - include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx); + include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx); - $theme['theme_data'] = acp_styles::db_theme_data($theme); - $theme['theme_mtime'] = $update_time; - - // Save CSS contents - $sql_ary = array( - 'theme_mtime' => $theme['theme_mtime'], - 'theme_data' => $theme['theme_data'] - ); - - $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE theme_id = {$theme['theme_id']}"; - $db->sql_query($sql); - - $cache->destroy('sql', STYLES_THEME_TABLE); - } - - // Only set the expire time if the theme changed data is older than 30 minutes - to cope with changes from the ACP - if ($recache || $theme['theme_mtime'] > (time() - 1800)) - { - header('Expires: 0'); - } - else - { - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $expire_time)); - } + $theme['theme_data'] = acp_styles::db_theme_data($theme); + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $expire_time)); header('Content-type: text/css; charset=UTF-8'); // Echo Theme Data -- cgit v1.2.1 From c184fb86c9c6fb6a9dfdb731e785a145069a33ab Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 23:12:07 +0100 Subject: [feature/remove-db-styles] Removed style.php! Finally sanity has arrived! No more delivering CSS through PHP. Better 3 years late than never. PHPBB3-9741 --- phpBB/style.php | 164 -------------------------------------------------------- 1 file changed, 164 deletions(-) delete mode 100644 phpBB/style.php (limited to 'phpBB/style.php') diff --git a/phpBB/style.php b/phpBB/style.php deleted file mode 100644 index c84713f267..0000000000 --- a/phpBB/style.php +++ /dev/null @@ -1,164 +0,0 @@ -register(); - - // set up caching - $cache_factory = new phpbb_cache_factory($acm_type); - $cache = $cache_factory->get_service(); - $class_loader->set_cache($cache->get_driver()); - - $request = new phpbb_request(); - $db = new $sql_db(); - - // make sure request_var uses this request instance - request_var('', 0, false, false, $request); // "dependency injection" for a function - - // Connect to DB - if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false)) - { - exit; - } - unset($dbpasswd); - - $config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE); - set_config(null, null, null, $config); - set_config_count(null, null, null, $config); - - $user = false; - - // try to get a session ID from REQUEST array - $sid = request_var('sid', ''); - - if (!$sid) - { - // if that failed, then look in the cookies - $sid = request_var($config['cookie_name'] . '_sid', '', false, true); - } - - if (strspn($sid, 'abcdefABCDEF0123456789') !== strlen($sid)) - { - $sid = ''; - } - - if ($sid) - { - $sql = 'SELECT u.user_id, u.user_lang - FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u - WHERE s.session_id = '" . $db->sql_escape($sid) . "' - AND s.session_user_id = u.user_id"; - $result = $db->sql_query($sql); - $user = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - } - - $recompile = $config['load_tplcompile']; - if (!$user) - { - $id = ($id) ? $id : $config['default_style']; -// Commented out because calls do not always include the SID anymore -// $recompile = false; - $user = array('user_id' => ANONYMOUS); - } - - $sql = 'SELECT s.style_id, c.theme_id, c.theme_path, c.theme_name, t.template_path - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c - WHERE s.style_id = ' . $id . ' - AND t.template_id = s.template_id - AND c.theme_id = s.theme_id'; - $result = $db->sql_query($sql, 300); - $theme = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$theme) - { - exit; - } - - if ($user['user_id'] == ANONYMOUS) - { - $user['user_lang'] = $config['default_lang']; - } - - // gzip_compression - if ($config['gzip_compress']) - { - // IE6 is not able to compress the style (do not ask us why!) - $browser = strtolower($request->header('User-Agent')); - - if ($browser && strpos($browser, 'msie 6.0') === false && @extension_loaded('zlib') && !headers_sent()) - { - ob_start('ob_gzhandler'); - } - } - - // Expire time of seven days if not recached - $expire_time = 7*86400; - - include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx); - - $theme['theme_data'] = acp_styles::db_theme_data($theme); - - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $expire_time)); - header('Content-type: text/css; charset=UTF-8'); - - // Echo Theme Data - echo $theme['theme_data']; - - if (!empty($cache)) - { - $cache->unload(); - } - $db->sql_close(); -} -- cgit v1.2.1