diff options
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/acm/acm_main.php | 45 | ||||
-rw-r--r-- | phpBB/includes/bbcode.php | 16 | ||||
-rw-r--r-- | phpBB/includes/functions.php | 57 | ||||
-rw-r--r-- | phpBB/includes/functions_display.php | 12 | ||||
-rw-r--r-- | phpBB/includes/session.php | 82 | ||||
-rw-r--r-- | phpBB/includes/template.php | 27 |
6 files changed, 140 insertions, 99 deletions
diff --git a/phpBB/includes/acm/acm_main.php b/phpBB/includes/acm/acm_main.php index 27c59ea7c4..91a50f75fb 100644 --- a/phpBB/includes/acm/acm_main.php +++ b/phpBB/includes/acm/acm_main.php @@ -305,6 +305,51 @@ class cache extends acm return; } + /** + * Obtain cfg file data + */ + function obtain_cfg_items($theme) + { + global $config, $phpbb_root_path; + + $parsed_items = array( + 'theme' => array(), + 'template' => array(), + 'imageset' => array() + ); + + foreach ($parsed_items as $key => $parsed_array) + { + $parsed_array = ($this->exists('_' . $key . '_cfg')) ? $this->get('_' . $key . '_cfg') : array(); + + $reparse = false; + $filename = $phpbb_root_path . 'styles/' . $theme[$key . '_path'] . '/' . $key . '/' . $key . '.cfg'; + + if (!file_exists($filename)) + { + continue; + } + + if (!isset($parsed_array[$theme[$key . '_id']]) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']))) + { + $reparse = true; + } + + // Re-parse cfg file + if ($reparse) + { + $parsed_array = parse_cfg_file($filename); + $parsed_array['filetime'] = @filemtime($filename); + + $this->put('_' . $key . '_cfg', $parsed_array); + } + + $parsed_items[$key] = &$parsed_array; + } + + return $parsed_items; + } + } ?>
\ No newline at end of file diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index a550bd40c3..ab0d742ede 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -103,20 +103,8 @@ class bbcode if (empty($this->template_filename)) { - $style = 'primary'; - if (!empty($user->theme['secondary'])) - { - // If the primary style has custom templates for BBCodes then we'll make sure - // the bbcode.html file is present, otherwise we'll use the secondary style - - if ($this->bbcode_bitfield & $user->theme['primary']['bbcode_bitfield']) - { - $style = (file_exists($phpbb_root_path . 'styles/' . $user->theme['primary']['template_path'] . '/template/bbcode.html')) ? 'primary' : 'secondary'; - } - } - - $this->template_bitfield = $user->theme[$style]['bbcode_bitfield']; - $this->template_filename = $phpbb_root_path . 'styles/' . $user->theme[$style]['template_path'] . '/template/bbcode.html'; + $this->template_bitfield = $user->theme['bbcode_bitfield']; + $this->template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/bbcode.html'; } $sql = ''; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 8cf6efa657..8570ff2eed 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -897,7 +897,7 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add { global $template, $user; - $seperator = $user->theme['primary']['pagination_sep']; + $seperator = $user->theme['pagination_sep']; $total_pages = ceil($num_items/$per_page); @@ -1479,6 +1479,47 @@ function build_hidden_fields($field_ary) } /** +* Parse cfg file +*/ +function parse_cfg_file($filename) +{ + $parsed_items = array(); + + $lines = file($filename); + + foreach ($lines as $line) + { + $line = trim($line); + + if (!$line || $line{0} == '#' || ($delim_pos = strpos($line, '=')) === false) + { + continue; + } + + // Determine first occurrence, since in values the equal sign is allowed + $key = strtolower(trim(substr($line, 0, $delim_pos))); + $value = trim(substr($line, $delim_pos + 1)); + + if (in_array($value, array('off', 'false', '0'))) + { + $value = false; + } + else if (in_array($value, array('on', 'true', '1'))) + { + $value = true; + } + else if (($value{0} == "'" && $value{sizeof($value)-1} == "'") || ($value{0} == '"' && $value{sizeof($value)-1} == '"')) + { + $value = substr($value, 1, sizeof($value)-2); + } + + $parsed_items[$key] = $value; + } + + return $parsed_items; +} + +/** * Error and message handler, call with trigger_error if reqd */ function msg_handler($errno, $msg_text, $errfile, $errline) @@ -1863,19 +1904,19 @@ function page_header($page_title = '') 'S_DISPLAY_MEMBERLIST' => (isset($auth)) ? $auth->acl_get('u_viewprofile') : 0, 'S_NEW_PM' => ($s_privmsg_new) ? 1 : 0, - 'T_THEME_PATH' => "{$phpbb_root_path}styles/" . $user->theme['primary']['theme_path'] . '/theme', - 'T_TEMPLATE_PATH' => "{$phpbb_root_path}styles/" . $user->theme['primary']['template_path'] . '/template', - 'T_IMAGESET_PATH' => "{$phpbb_root_path}styles/" . $user->theme['primary']['imageset_path'] . '/imageset', - 'T_IMAGESET_LANG_PATH' => "{$phpbb_root_path}styles/" . $user->theme['primary']['imageset_path'] . '/imageset/' . $user->data['user_lang'], + 'T_THEME_PATH' => "{$phpbb_root_path}styles/" . $user->theme['theme_path'] . '/theme', + 'T_TEMPLATE_PATH' => "{$phpbb_root_path}styles/" . $user->theme['template_path'] . '/template', + 'T_IMAGESET_PATH' => "{$phpbb_root_path}styles/" . $user->theme['imageset_path'] . '/imageset', + 'T_IMAGESET_LANG_PATH' => "{$phpbb_root_path}styles/" . $user->theme['imageset_path'] . '/imageset/' . $user->data['user_lang'], 'T_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/", 'T_AVATAR_PATH' => "{$phpbb_root_path}{$config['avatar_path']}/", 'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/", 'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/", 'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/", 'T_UPLOAD_PATH' => "{$phpbb_root_path}{$config['upload_path']}/", - 'T_STYLESHEET_LINK' => (!$user->theme['primary']['theme_storedb']) ? "{$phpbb_root_path}styles/" . $user->theme['primary']['theme_path'] . '/theme/stylesheet.css' : "{$phpbb_root_path}style.$phpEx?sid=$user->session_id&id=" . $user->theme['primary']['style_id'], - 'T_STYLESHEET_NAME' => $user->theme['primary']['theme_name'], - 'T_THEME_DATA' => (!$user->theme['primary']['theme_storedb']) ? '' : $user->theme['primary']['theme_data']) + 'T_STYLESHEET_LINK' => (!$user->theme['theme_storedb']) ? "{$phpbb_root_path}styles/" . $user->theme['theme_path'] . '/theme/stylesheet.css' : "{$phpbb_root_path}style.$phpEx?sid=$user->session_id&id=" . $user->theme['style_id'], + 'T_STYLESHEET_NAME' => $user->theme['theme_name'], + 'T_THEME_DATA' => (!$user->theme['theme_storedb']) ? '' : $user->theme['theme_data']) ); if ($config['send_encoding']) diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index adb838f371..15f48e10b4 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -507,7 +507,7 @@ function topic_generate_pagination($replies, $url) } else if ($times < $total_pages) { - $pagination .= $user->theme['primary']['pagination_sep']; + $pagination .= $user->theme['pagination_sep']; } $times++; } @@ -674,15 +674,7 @@ function display_attachments($forum_id, $blockname, &$attachment_data, &$update_ { $attachment_tpl = array(); - // Generate Template - $style = 'primary'; - - if (!empty($user->theme['secondary'])) - { - $style = (file_exists($phpbb_root_path . 'styles/' . $user->theme['primary']['template_path'] . '/template/attachment.html')) ? 'primary' : 'secondary'; - } - - $template_filename = $phpbb_root_path . 'styles/' . $user->theme[$style]['template_path'] . '/template/attachment.html'; + $template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/attachment.html'; if (!($fp = @fopen($template_filename, 'rb'))) { trigger_error('Could not load template file "' . $template_filename . '"'); diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 3788299fba..92a8f9d380 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -702,7 +702,7 @@ class user extends session function setup($lang_set = false, $style = false) { - global $db, $template, $config, $auth, $phpEx, $phpbb_root_path; + global $db, $template, $config, $auth, $phpEx, $phpbb_root_path, $cache; if ($this->data['user_id'] != ANONYMOUS) { @@ -773,72 +773,62 @@ class user extends session $style = ($style) ? $style : ((!$config['override_user_style'] && $this->data['user_id'] != ANONYMOUS) ? $this->data['user_style'] : $config['default_style']); } - // TODO: DISTINCT making problems with DBMS not able to distinct TEXT fields, test grouping - switch (SQL_LAYER) - { - case 'mssql': - case 'mssql_odbc': - $sql = 'SELECT s.style_id, t.*, c.*, i.* - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TPL_TABLE . ' t, ' . STYLES_CSS_TABLE . ' c, ' . STYLES_IMAGE_TABLE . " i - WHERE s.style_id IN ($style, " . $config['default_style'] . ') - AND t.template_id = s.template_id - AND c.theme_id = s.theme_id - AND i.imageset_id = s.imageset_id - GROUP BY s.style_id'; - break; - - default: - $sql = 'SELECT s.style_id, t.*, c.*, i.* - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TPL_TABLE . ' t, ' . STYLES_CSS_TABLE . ' c, ' . STYLES_IMAGE_TABLE . " i - WHERE s.style_id IN ($style, " . $config['default_style'] . ') - AND t.template_id = s.template_id - AND c.theme_id = s.theme_id - AND i.imageset_id = s.imageset_id - GROUP BY s.style_id'; - break; - } + $sql = 'SELECT s.style_id, t.*, c.*, i.* + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TPL_TABLE . ' t, ' . STYLES_CSS_TABLE . ' c, ' . STYLES_IMAGE_TABLE . " i + WHERE s.style_id = $style + 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, 3600); + $this->theme = $db->sql_fetchrow($result); + $db->sql_freeresult($result); - if (!($row = $db->sql_fetchrow($result))) + if (!$this->theme) { trigger_error('Could not get style data'); } - $this->theme = ($row2 = $db->sql_fetchrow($result)) ? array( - ($style == $row['style_id']) ? 'primary' : 'secondary' => $row, - ($style == $row2['style_id']) ? 'primary' : 'secondary' => $row2) : array('primary' => $row); - $db->sql_freeresult($result); + // Now parse the cfg file and cache it + $parsed_items = $cache->obtain_cfg_items($this->theme); + + // We are only interested in the theme configuration for now + $parsed_items = $parsed_items['theme']; - unset($row); - unset($row2); + $check_for = array( + 'parse_css_file' => (int) 0, + 'pagination_sep' => (string) ', ' + ); - // Add to template database - foreach (array_keys($this->theme) as $style_priority) + foreach ($check_for as $key => $default_value) { - $this->theme[$style_priority]['pagination_sep'] = ', '; + $this->theme[$key] = (isset($parsed_items[$key]) && $parsed_items[$key]) ? $parsed_items[$key] : $default_value; + settype($this->theme[$key], gettype($default_value)); + + if (is_string($default_value)) + { + $this->theme[$key] = htmlspecialchars($this->theme[$key]); + } } - // TEMP - $this->theme['primary']['parse_css_file'] = false; - if (!$this->theme['primary']['theme_storedb'] && $this->theme['primary']['parse_css_file']) + if (!$this->theme['theme_storedb'] && $this->theme['parse_css_file']) { - $this->theme['primary']['theme_storedb'] = 1; + $this->theme['theme_storedb'] = 1; $sql_ary = array( - 'theme_data' => implode('', file("{$phpbb_root_path}styles/" . $this->theme['primary']['theme_path'] . '/theme/stylesheet.css')), + 'theme_data' => implode('', file("{$phpbb_root_path}styles/" . $this->theme['theme_path'] . '/theme/stylesheet.css')), 'theme_mtime' => time(), 'theme_storedb' => 1 ); $db->sql_query('UPDATE ' . STYLES_CSS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE theme_id = ' . $this->theme['primary']['theme_id']); + WHERE theme_id = ' . $this->theme['theme_id']); unset($sql_ary); } $template->set_template(); - $this->img_lang = (file_exists($phpbb_root_path . 'styles/' . $this->theme['primary']['imageset_path'] . '/imageset/' . $this->lang_name)) ? $this->lang_name : $config['default_lang']; + $this->img_lang = (file_exists($phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . $this->lang_name)) ? $this->lang_name : $config['default_lang']; // Is board disabled and user not an admin or moderator? // TODO @@ -1015,7 +1005,7 @@ class user extends session if (empty($imgs[$img . $suffix]) || $width !== false) { - if (!isset($this->theme['primary'][$img]) || !$this->theme['primary'][$img]) + if (!isset($this->theme[$img]) || !$this->theme[$img]) { // Do not fill the image to let designers decide what to do if the image is empty $imgs[$img . $suffix] = ''; @@ -1024,11 +1014,11 @@ class user extends session if ($width === false) { - list($imgsrc, $height, $width) = explode('*', $this->theme['primary'][$img]); + list($imgsrc, $height, $width) = explode('*', $this->theme[$img]); } else { - list($imgsrc, $height) = explode('*', $this->theme['primary'][$img]); + list($imgsrc, $height) = explode('*', $this->theme[$img]); } if ($suffix !== '') @@ -1036,7 +1026,7 @@ class user extends session $imgsrc = str_replace('{SUFFIX}', $suffix, $imgsrc); } - $imgs[$img . $suffix]['src'] = $phpbb_root_path . 'styles/' . $this->theme['primary']['imageset_path'] . '/imageset/' . str_replace('{LANG}', $this->img_lang, $imgsrc); + $imgs[$img . $suffix]['src'] = $phpbb_root_path . 'styles/' . $this->theme['imageset_path'] . '/imageset/' . str_replace('{LANG}', $this->img_lang, $imgsrc); $imgs[$img . $suffix]['width'] = $width; $imgs[$img . $suffix]['height'] = $height; } diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index 85ac7d581e..595e2fa436 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -38,7 +38,6 @@ class template var $_tpldata = array(); // Root dir and hash of filenames for each template handle. - var $tpl = ''; var $root = ''; var $cachepath = ''; var $files = array(); @@ -61,17 +60,10 @@ class template { global $phpbb_root_path, $config, $user; - if (file_exists($phpbb_root_path . 'styles/' . $user->theme['primary']['template_path'] . '/template')) + if (file_exists($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template')) { - $this->tpl = 'primary'; - $this->root = $phpbb_root_path . 'styles/' . $user->theme['primary']['template_path']. '/template'; - $this->cachepath = $phpbb_root_path . 'cache/tpl_' . $user->theme['primary']['template_path'] . '_'; - } - else - { - $this->tpl = 'secondary'; - $this->root = $phpbb_root_path . 'styles/' . $user->theme['secondary']['template_path']. '/template'; - $this->cachepath = $phpbb_root_path . 'cache/tpl_' . $user->theme['secondary']['template_path'] . '_'; + $this->root = $phpbb_root_path . 'styles/' . $user->theme['template_path']. '/template'; + $this->cachepath = $phpbb_root_path . 'cache/tpl_' . $user->theme['template_path'] . '_'; } $this->static_lang = $static_lang; @@ -87,7 +79,6 @@ class template { global $phpbb_root_path; - $this->tpl = 'primary'; $this->root = $template_path; $this->cachepath = $phpbb_root_path . 'cache/ctpl_' . $template_name . '_'; @@ -207,16 +198,10 @@ class template trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR); } - if (!file_exists($this->files[$handle]) && !empty($user->theme['secondary'])) - { - $this->tpl = 'secondary'; - $this->files[$handle] = $phpbb_root_path . 'styles/' . $user->theme['secondary']['template_path'] . '/template/' . $this->filename[$handle]; - } - - if ($user->theme[$this->tpl]['template_storedb']) + if ($user->theme['template_storedb']) { $sql = 'SELECT * FROM ' . STYLES_TPLDATA_TABLE . ' - WHERE template_id = ' . $user->theme[$this->tpl]['template_id'] . " + WHERE template_id = ' . $user->theme['template_id'] . " AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "' OR template_included LIKE '%" . $db->sql_escape($this->filename[$handle]) . ":%')"; $result = $db->sql_query($sql); @@ -225,7 +210,7 @@ class template { do { - if ($row['template_mtime'] < filemtime($phpbb_root_path . 'styles/' . $user->theme[$this->tpl]['template_path'] . '/template/' . $row['template_filename'])) + if ($row['template_mtime'] < filemtime($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/' . $row['template_filename'])) { if ($row['template_filename'] == $this->filename[$handle]) { |