From 1106aed2f6bc7a8976109b1fab6d0bd786070563 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Wed, 31 Dec 2008 13:36:06 +0000 Subject: [PATCH] oi... index page looks good... git-svn-id: file:///svn/phpbb/trunk@9246 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/classes/template.php | 6 -- phpBB/includes/classes/template_compile.php | 41 ++++++++---- phpBB/includes/functions.php | 6 +- phpBB/style.php | 74 +++++---------------- 4 files changed, 48 insertions(+), 79 deletions(-) diff --git a/phpBB/includes/classes/template.php b/phpBB/includes/classes/template.php index 167f33f3e8..f574f4d9fb 100644 --- a/phpBB/includes/classes/template.php +++ b/phpBB/includes/classes/template.php @@ -180,9 +180,6 @@ class phpbb_template $_rootref = &$this->_rootref; $_lang = &phpbb::$user->lang; - // These _are_ used the included files. - $_tpldata; $_rootref; $_lang; - if (($filename = $this->_tpl_load($handle)) !== false) { ($include_once) ? include_once($filename) : include($filename); @@ -497,9 +494,6 @@ class phpbb_template $_rootref = &$this->_rootref; $_lang = &phpbb::$user->lang; - // These _are_ used the included files. - $_tpldata; $_rootref; $_lang; - if ($filename) { include($filename); diff --git a/phpBB/includes/classes/template_compile.php b/phpBB/includes/classes/template_compile.php index b8fc662208..a5ead08b35 100644 --- a/phpBB/includes/classes/template_compile.php +++ b/phpBB/includes/classes/template_compile.php @@ -17,11 +17,10 @@ if (!defined('IN_PHPBB')) } /** - * The template filter that does the actual compilation - * @see template_compile - * @package phpBB3 - * - */ +* The template filter that does the actual compilation +* @see template_compile +* @package phpBB3 +*/ class phpbb_template_filter extends php_user_filter { /** @@ -184,25 +183,33 @@ class phpbb_template_filter extends php_user_filter $text_blocks = str_replace($var_val[0], $new, $text_blocks); } + // Handle special language tags L_ and LA_ + $this->compile_language_tags($text_blocks); + // This will handle the remaining root-level varrefs + $text_blocks = preg_replace('#\{([a-z0-9\-_]*)\}#is', "", $text_blocks); + $text_blocks = preg_replace('#\{\$([a-z0-9\-_]*)\}#is', "", $text_blocks); + + return $text_blocks; + } + + /** + * Handlse special language tags L_ and LA_ + */ + private function compile_language_tags(&$text_blocks) + { // transform vars prefixed by L_ into their language variable pendant if nothing is set within the tpldata array if (strpos($text_blocks, '{L_') !== false) { - $text_blocks = preg_replace('#\{L_([a-z0-9\-_]*)\}#is', "", $text_blocks); + $text_blocks = preg_replace('#\{L_([a-z0-9\-_]*)\}#is', "", $text_blocks); } // Handle addslashed language variables prefixed with LA_ // If a template variable already exist, it will be used in favor of it... if (strpos($text_blocks, '{LA_') !== false) { - $text_blocks = preg_replace('#\{LA_([a-z0-9\-_]*)\}#is', "", $text_blocks); + $text_blocks = preg_replace('#\{LA_([a-z0-9\-_]*)\}#is', "", $text_blocks); } - - // Handle remaining varrefs - $text_blocks = preg_replace('#\{([a-z0-9\-_]*)\}#is', "", $text_blocks); - $text_blocks = preg_replace('#\{\$([a-z0-9\-_]*)\}#is', "", $text_blocks); - - return $text_blocks; } /** @@ -508,7 +515,13 @@ class phpbb_template_filter extends php_user_filter private function compile_tag_if($tag_args, $elseif) { $tokens = $this->compile_expression($tag_args); - return (($elseif) ? '} else if (' : 'if (') . (implode(' ', $tokens) . ') { '); + + // @todo We suppress notices within IF statements until we find a way to correctly check them + $tpl = ($elseif) ? '} else if (@(' : 'if (@('; + $tpl .= implode(' ', $tokens); + $tpl .= ')) { '; + + return $tpl; } /** diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 9ca0424791..0b9b714c14 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2575,7 +2575,7 @@ function page_header($page_title = '', $display_online_list = true) 'T_ICONS_PATH' => PHPBB_ROOT_PATH . phpbb::$config['icons_path'] . '/', 'T_RANKS_PATH' => PHPBB_ROOT_PATH . phpbb::$config['ranks_path'] . '/', 'T_UPLOAD_PATH' => PHPBB_ROOT_PATH . phpbb::$config['upload_path'] . '/', - 'T_STYLESHEET_LINK' => (!phpbb::$user->theme['theme_storedb']) ? PHPBB_ROOT_PATH . 'styles/' . phpbb::$user->theme['theme_path'] . '/theme/stylesheet.css' : phpbb::$url->get(PHPBB_ROOT_PATH . 'style.' . PHP_EXT . '?sid=' . phpbb::$user->session_id . '&id=' . phpbb::$user->theme['style_id'] . '&lang=' . phpbb::$user->data['user_lang']), //PHPBB_ROOT_PATH . "store/{$user->theme['theme_id']}_{$user->theme['imageset_id']}_{$user->lang_name}.css" + 'T_STYLESHEET_LINK' => (!phpbb::$user->theme['theme_storedb']) ? PHPBB_ROOT_PATH . 'styles/' . phpbb::$user->theme['theme_path'] . '/theme/stylesheet.css' : phpbb::$url->get(PHPBB_ROOT_PATH . 'style.' . PHP_EXT . '?id=' . phpbb::$user->theme['style_id'] . '&lang=' . phpbb::$user->data['user_lang']), //PHPBB_ROOT_PATH . "store/{$user->theme['theme_id']}_{$user->theme['imageset_id']}_{$user->lang_name}.css" 'T_STYLESHEET_NAME' => phpbb::$user->theme['theme_name'], 'SITE_LOGO_IMG' => phpbb::$user->img('site_logo'), @@ -2712,9 +2712,9 @@ function garbage_collection() function exit_handler() { // needs to be run prior to the hook - if (request::super_globals_disabled()) + if (phpbb_request::super_globals_disabled()) { - request::enable_super_globals(); + phpbb_request::enable_super_globals(); } // As a pre-caution... some setups display a blank page if the flush() is not there. diff --git a/phpBB/style.php b/phpBB/style.php index b83693b5fc..ec8c788128 100644 --- a/phpBB/style.php +++ b/phpBB/style.php @@ -15,19 +15,10 @@ define('IN_PHPBB', true); if (!defined('PHPBB_ROOT_PATH')) define('PHPBB_ROOT_PATH', './'); if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1)); -$sid = (isset($_GET['sid']) && !is_array($_GET['sid'])) ? htmlspecialchars($_GET['sid']) : ''; $id = (isset($_GET['id'])) ? intval($_GET['id']) : 0; -if (strspn($sid, 'abcdefABCDEF0123456789') !== strlen($sid)) -{ - $sid = ''; -} - // This is a simple script to grab and output the requested CSS data stored in the DB -// We include a session_id check to try and limit 3rd party linking ... unless they -// happen to have a current session it will output nothing. We will also cache the -// resulting CSS data for five minutes ... anything to reduce the load on the SQL -// server a little +// We cache the resulting CSS data for five minutes if (!$id) { exit; @@ -35,36 +26,15 @@ if (!$id) include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT); -$user = false; - -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 = phpbb::$config['load_tplcompile']; -if (!$user) -{ - $id = phpbb::$config['default_style']; - $recompile = false; - $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 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'; -$result = $db->sql_query($sql, 300); -$theme = $db->sql_fetchrow($result); -$db->sql_freeresult($result); +$result = phpbb::$db->sql_query($sql, 300); +$theme = phpbb::$db->sql_fetchrow($result); +phpbb::$db->sql_freeresult($result); if (!$theme) { @@ -72,34 +42,27 @@ if (!$theme) exit_handler(); } -if ($user['user_id'] == ANONYMOUS) -{ - $user['user_lang'] = phpbb::$config['default_lang']; -} - -$user_image_lang = (file_exists(PHPBB_ROOT_PATH . 'styles/' . $theme['imageset_path'] . '/imageset/' . $user['user_lang'])) ? $user['user_lang'] : phpbb::$config['default_lang']; +$user_lang = basename(request_var('lang', phpbb::$config['default_lang'])); +$user_image_lang = (file_exists(PHPBB_ROOT_PATH . 'styles/' . $theme['imageset_path'] . '/imageset/' . $user_lang)) ? $user_lang : phpbb::$config['default_lang']; $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); + AND image_lang IN ('" . phpbb::$db->sql_escape($user_image_lang) . "', '')"; +$result = phpbb::$db->sql_query($sql, 3600); $img_array = array(); -while ($row = $db->sql_fetchrow($result)) +while ($row = phpbb::$db->sql_fetchrow($result)) { $img_array[$row['image_name']] = $row; } -$db->sql_freeresult($result); +phpbb::$db->sql_freeresult($result); // gzip_compression if (phpbb::$config['gzip_compress']) { - // IE6 is not able to compress the style (do not ask us why!) - $browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? strtolower(htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT'])) : ''; - - if ($browser && strpos($browser, 'msie 6.0') === false && @extension_loaded('zlib') && !headers_sent()) + if (strpos(strtolower(phpbb::$user->system['browser']), 'msie 6.0') === false && @extension_loaded('zlib') && !headers_sent()) { ob_start('ob_gzhandler'); } @@ -110,7 +73,7 @@ $expire_time = 7 * 86400; $recache = false; // Re-cache stylesheet data if necessary -if ($recompile || empty($theme['theme_data'])) +if (phpbb::$config['load_tplcompile'] || empty($theme['theme_data'])) { $recache = (empty($theme['theme_data'])) ? true : false; $update_time = time(); @@ -141,11 +104,12 @@ if ($recompile || empty($theme['theme_data'])) } } +// We store new data within database if ($recache) { if (!class_exists('acp_styles')) { - include(PHPBB_ROOT_PATH . 'includes/acp/acp_styles.' . PHP_EXT); + include PHPBB_ROOT_PATH . 'modules/acp/acp_styles.' . PHP_EXT; } $theme['theme_data'] = acp_styles::db_theme_data($theme); @@ -157,11 +121,7 @@ if ($recache) 'theme_data' => $theme['theme_data'] ); - // @TODO: rewrite with the new param db functions - $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE theme_id = {$theme['theme_id']}"; - $db->sql_query($sql); - + phpbb::$db->sql_handle_data('UPDATE', STYLES_THEME_TABLE, $sql_ary, 'theme_id = ' . $theme['theme_id']); phpbb::$acm->destroy_sql(STYLES_THEME_TABLE); } @@ -184,11 +144,12 @@ $replace = array( '{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'] + '{S_USER_LANG}' => $user_lang, ); $theme['theme_data'] = str_replace(array_keys($replace), array_values($replace), $theme['theme_data']); +// Replace IMG_*_WIDTH/HEIGHT/SRC tags $matches = array(); preg_match_all('#\{IMG_([A-Za-z0-9_]*?)_(WIDTH|HEIGHT|SRC)\}#', $theme['theme_data'], $matches); @@ -210,6 +171,7 @@ if (isset($matches[0]) && sizeof($matches[0])) { $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'],