From 8ec737e9c4d36711b09250df72492a8f89e7bfb1 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 5 Jul 2011 19:38:15 -0400 Subject: [ticket/10250] Destroy cached md5 hash of site_logo on refreshing an imageset PHPBB3-10250 --- phpBB/includes/acp/acp_styles.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 37cf8d1f72..3bc8c86500 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -510,6 +510,7 @@ parse_css_file = {PARSE_CSS_FILE} $db->sql_transaction('commit'); $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); + $cache->destroy('imageset_site_logo_md5'); add_log('admin', 'LOG_IMAGESET_REFRESHED', $imageset_row['imageset_name']); trigger_error($user->lang['IMAGESET_REFRESHED'] . adm_back_link($this->u_action)); -- cgit v1.2.1 From 98590201d862ad75e24971a8817a06fa66466f77 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 3 Sep 2011 18:57:16 +0300 Subject: [feature/remove-imagesets] Changing admin control panel styles module Removing imagesets. Changing admin control panel styles module PHPBB3-10336 --- phpBB/includes/acp/acp_styles.php | 818 ++------------------------------------ 1 file changed, 27 insertions(+), 791 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 18a90fb8e8..82878cfadb 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -26,8 +26,6 @@ class acp_styles var $style_cfg; var $template_cfg; var $theme_cfg; - var $imageset_cfg; - var $imageset_keys; function main($id, $mode) { @@ -58,7 +56,7 @@ class acp_styles $style_id = request_var('id', 0); // Fill the configuration variables - $this->style_cfg = $this->template_cfg = $this->theme_cfg = $this->imageset_cfg = ' + $this->style_cfg = $this->template_cfg = $this->theme_cfg = ' # # phpBB {MODE} configuration file # @@ -81,19 +79,6 @@ class acp_styles name = {NAME} copyright = {COPYRIGHT} version = {VERSION} -'; - - $this->theme_cfg .= ' -# Some configuration options - -# -# You have to turn this option on if you want to use the -# path template variables ({T_IMAGESET_PATH} for example) within -# your css file. -# This is mostly the case if you want to use language specific -# images within your css file. -# -parse_css_file = {PARSE_CSS_FILE} '; $this->template_cfg .= ' @@ -105,33 +90,6 @@ parse_css_file = {PARSE_CSS_FILE} # Templates cannot inherit from inheriting templates. #'; - $this->imageset_keys = array( - 'logos' => array( - 'site_logo', - ), - 'buttons' => array( - 'icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply', - ), - 'icons' => array( - 'icon_post_target', 'icon_post_target_unread', 'icon_topic_attach', 'icon_topic_latest', 'icon_topic_newest', 'icon_topic_reported', 'icon_topic_unapproved', 'icon_friend', 'icon_foe', - ), - 'forums' => array( - 'forum_link', 'forum_read', 'forum_read_locked', 'forum_read_subforum', 'forum_unread', 'forum_unread_locked', 'forum_unread_subforum', 'subforum_read', 'subforum_unread' - ), - 'folders' => array( - 'topic_moved', 'topic_read', 'topic_read_mine', 'topic_read_hot', 'topic_read_hot_mine', 'topic_read_locked', 'topic_read_locked_mine', 'topic_unread', 'topic_unread_mine', 'topic_unread_hot', 'topic_unread_hot_mine', 'topic_unread_locked', 'topic_unread_locked_mine', 'sticky_read', 'sticky_read_mine', 'sticky_read_locked', 'sticky_read_locked_mine', 'sticky_unread', 'sticky_unread_mine', 'sticky_unread_locked', 'sticky_unread_locked_mine', 'announce_read', 'announce_read_mine', 'announce_read_locked', 'announce_read_locked_mine', 'announce_unread', 'announce_unread_mine', 'announce_unread_locked', 'announce_unread_locked_mine', 'global_read', 'global_read_mine', 'global_read_locked', 'global_read_locked_mine', 'global_unread', 'global_unread_mine', 'global_unread_locked', 'global_unread_locked_mine', 'pm_read', 'pm_unread', - ), - 'polls' => array( - 'poll_left', 'poll_center', 'poll_right', - ), - 'ui' => array( - 'upload_bar', - ), - 'user' => array( - 'user_icon1', 'user_icon2', 'user_icon3', 'user_icon4', 'user_icon5', 'user_icon6', 'user_icon7', 'user_icon8', 'user_icon9', 'user_icon10', - ), - ); - // Execute overall actions switch ($action) { @@ -174,8 +132,6 @@ parse_css_file = {PARSE_CSS_FILE} { switch ($mode) { - case 'imageset': - return $this->edit_imageset($style_id); case 'template': return $this->edit_template($style_id); case 'theme': @@ -355,7 +311,8 @@ parse_css_file = {PARSE_CSS_FILE} // Save CSS contents $sql_ary = array( 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), - 'theme_data' => $this->db_theme_data($theme_row) + 'theme_data' => '', + 'theme_storedb' => 0 ); $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " @@ -382,153 +339,6 @@ parse_css_file = {PARSE_CSS_FILE} $this->frontend('theme', array('edit', 'details'), array('refresh', 'export', 'delete')); break; - - case 'imageset': - - switch ($action) - { - case 'refresh': - - $sql = 'SELECT * - FROM ' . STYLES_IMAGESET_TABLE . " - WHERE imageset_id = $style_id"; - $result = $db->sql_query($sql); - $imageset_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$imageset_row) - { - trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (confirm_box(true)) - { - $sql_ary = array(); - - $imageset_definitions = array(); - foreach ($this->imageset_keys as $topic => $key_array) - { - $imageset_definitions = array_merge($imageset_definitions, $key_array); - } - - $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/imageset.cfg"); - - $db->sql_transaction('begin'); - - $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' - WHERE imageset_id = ' . $style_id; - $result = $db->sql_query($sql); - - foreach ($cfg_data_imageset as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($image_name, 'img_') === 0 && $image_filename) - { - $image_name = substr($image_name, 4); - if (in_array($image_name, $imageset_definitions)) - { - $sql_ary[] = array( - 'image_name' => (string) $image_name, - 'image_filename' => (string) $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $style_id, - 'image_lang' => '', - ); - } - } - } - - $sql = 'SELECT lang_dir - FROM ' . LANG_TABLE; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - if (@file_exists("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg")) - { - $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset_row['imageset_path']}/imageset/{$row['lang_dir']}/imageset.cfg"); - foreach ($cfg_data_imageset_data as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($image_name, 'img_') === 0 && $image_filename) - { - $image_name = substr($image_name, 4); - if (in_array($image_name, $imageset_definitions)) - { - $sql_ary[] = array( - 'image_name' => (string) $image_name, - 'image_filename' => (string) $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $style_id, - 'image_lang' => (string) $row['lang_dir'], - ); - } - } - } - } - } - $db->sql_freeresult($result); - - $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); - - $db->sql_transaction('commit'); - - $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); - $cache->destroy('imageset_site_logo_md5'); - - add_log('admin', 'LOG_IMAGESET_REFRESHED', $imageset_row['imageset_name']); - trigger_error($user->lang['IMAGESET_REFRESHED'] . adm_back_link($this->u_action)); - } - else - { - confirm_box(false, $user->lang['CONFIRM_IMAGESET_REFRESH'], build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'action' => $action, - 'id' => $style_id - ))); - } - break; - } - - $this->frontend('imageset', array('edit', 'details'), array('refresh', 'export', 'delete')); - break; } } @@ -567,10 +377,6 @@ parse_css_file = {PARSE_CSS_FILE} case 'theme': $sql_from = STYLES_THEME_TABLE; break; - - case 'imageset': - $sql_from = STYLES_IMAGESET_TABLE; - break; } $l_prefix = strtoupper($mode); @@ -1297,284 +1103,7 @@ parse_css_file = {PARSE_CSS_FILE} } /** - * Edit imagesets - * - * @param int $imageset_id specifies which imageset is being edited - */ - function edit_imageset($imageset_id) - { - global $db, $user, $phpbb_root_path, $cache, $template; - - $this->page_title = 'EDIT_IMAGESET'; - - if (!$imageset_id) - { - trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $update = (isset($_POST['update'])) ? true : false; - - $imgname = request_var('imgname', 'site_logo'); - $imgname = preg_replace('#[^a-z0-9\-+_]#i', '', $imgname); - $sql_extra = $imgnamelang = ''; - - $sql = 'SELECT imageset_path, imageset_name - FROM ' . STYLES_IMAGESET_TABLE . " - WHERE imageset_id = $imageset_id"; - $result = $db->sql_query($sql); - $imageset_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$imageset_row) - { - trigger_error($user->lang['NO_IMAGESET'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $imageset_path = $imageset_row['imageset_path']; - $imageset_name = $imageset_row['imageset_name']; - - if (strpos($imgname, '-') !== false) - { - list($imgname, $imgnamelang) = explode('-', $imgname); - $sql_extra = " AND image_lang IN ('" . $db->sql_escape($imgnamelang) . "', '')"; - } - - $sql = 'SELECT image_filename, image_width, image_height, image_lang, image_id - FROM ' . STYLES_IMAGESET_DATA_TABLE . " - WHERE imageset_id = $imageset_id - AND image_name = '" . $db->sql_escape($imgname) . "'$sql_extra"; - $result = $db->sql_query($sql); - $imageset_data_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - $image_filename = $imageset_data_row['image_filename']; - $image_width = $imageset_data_row['image_width']; - $image_height = $imageset_data_row['image_height']; - $image_lang = $imageset_data_row['image_lang']; - $image_id = $imageset_data_row['image_id']; - $imgsize = ($imageset_data_row['image_width'] && $imageset_data_row['image_height']) ? 1 : 0; - - // Check to see whether the selected image exists in the table - $valid_name = ($update) ? false : true; - - foreach ($this->imageset_keys as $category => $img_ary) - { - if (in_array($imgname, $img_ary)) - { - $valid_name = true; - break; - } - } - - if ($update && isset($_POST['imgpath']) && $valid_name) - { - // If imgwidth and imgheight are non-zero grab the actual size - // from the image itself ... we ignore width settings for the poll center image - $imgwidth = request_var('imgwidth', 0); - $imgheight = request_var('imgheight', 0); - $imgsize = request_var('imgsize', 0); - $imgpath = request_var('imgpath', ''); - $imgpath = str_replace('..', '.', $imgpath); - - // If no dimensions selected, we reset width and height to 0 ;) - if (!$imgsize) - { - $imgwidth = $imgheight = 0; - } - - $imglang = ''; - - if ($imgpath && !file_exists("{$phpbb_root_path}styles/$imageset_path/imageset/$imgpath")) - { - trigger_error($user->lang['NO_IMAGE_ERROR'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Determine width/height. If dimensions included and no width/height given, we detect them automatically... - if ($imgsize && $imgpath) - { - if (!$imgwidth || !$imgheight) - { - list($imgwidth_file, $imgheight_file) = getimagesize("{$phpbb_root_path}styles/$imageset_path/imageset/$imgpath"); - $imgwidth = ($imgwidth) ? $imgwidth : $imgwidth_file; - $imgheight = ($imgheight) ? $imgheight : $imgheight_file; - } - $imgwidth = ($imgname != 'poll_center') ? (int) $imgwidth : 0; - $imgheight = (int) $imgheight; - } - - if (strpos($imgpath, '/') !== false) - { - list($imglang, $imgfilename) = explode('/', $imgpath); - } - else - { - $imgfilename = $imgpath; - } - - $sql_ary = array( - 'image_filename' => (string) $imgfilename, - 'image_width' => (int) $imgwidth, - 'image_height' => (int) $imgheight, - 'image_lang' => (string) $imglang, - ); - - // already exists - if ($imageset_data_row) - { - $sql = 'UPDATE ' . STYLES_IMAGESET_DATA_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE image_id = $image_id"; - $db->sql_query($sql); - } - // does not exist - else if (!$imageset_data_row) - { - $sql_ary['image_name'] = $imgname; - $sql_ary['imageset_id'] = (int) $imageset_id; - $db->sql_query('INSERT INTO ' . STYLES_IMAGESET_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); - } - - $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); - - add_log('admin', 'LOG_IMAGESET_EDIT', $imageset_name); - - $template->assign_var('SUCCESS', true); - - $image_filename = $imgfilename; - $image_width = $imgwidth; - $image_height = $imgheight; - $image_lang = $imglang; - } - - $imglang = ''; - $imagesetlist = array('nolang' => array(), 'lang' => array()); - $langs = array(); - - $dir = "{$phpbb_root_path}styles/$imageset_path/imageset"; - $dp = @opendir($dir); - - if ($dp) - { - while (($file = readdir($dp)) !== false) - { - if ($file[0] != '.' && strtoupper($file) != 'CVS' && !is_file($dir . '/' . $file) && !is_link($dir . '/' . $file)) - { - $langs[] = $file; - } - else if (preg_match('#\.(?:gif|jpg|png)$#', $file)) - { - $imagesetlist['nolang'][] = $file; - } - } - - if ($sql_extra) - { - $dp2 = @opendir("$dir/$imgnamelang"); - - if ($dp2) - { - while (($file2 = readdir($dp2)) !== false) - { - if (preg_match('#\.(?:gif|jpg|png)$#', $file2)) - { - $imagesetlist['lang'][] = "$imgnamelang/$file2"; - } - } - closedir($dp2); - } - } - closedir($dp); - } - - // Generate list of image options - $img_options = ''; - foreach ($this->imageset_keys as $category => $img_ary) - { - $template->assign_block_vars('category', array( - 'NAME' => $user->lang['IMG_CAT_' . strtoupper($category)] - )); - - foreach ($img_ary as $img) - { - if ($category == 'buttons') - { - foreach ($langs as $language) - { - $template->assign_block_vars('category.images', array( - 'SELECTED' => ($img == $imgname && $language == $imgnamelang), - 'VALUE' => $img . '-' . $language, - 'TEXT' => $user->lang['IMG_' . strtoupper($img)] . ' [ ' . $language . ' ]' - )); - } - } - else - { - $template->assign_block_vars('category.images', array( - 'SELECTED' => ($img == $imgname), - 'VALUE' => $img, - 'TEXT' => (($category == 'custom') ? $img : $user->lang['IMG_' . strtoupper($img)]) - )); - } - } - } - - // Make sure the list of possible images is sorted alphabetically - sort($imagesetlist['lang']); - sort($imagesetlist['nolang']); - - $image_found = false; - $img_val = ''; - foreach ($imagesetlist as $type => $img_ary) - { - if ($type !== 'lang' || $sql_extra) - { - $template->assign_block_vars('imagesetlist', array( - 'TYPE' => ($type == 'lang') - )); - } - - foreach ($img_ary as $img) - { - $imgtext = preg_replace('/^([^\/]+\/)/', '', $img); - $selected = (!empty($imgname) && strpos($image_filename, $imgtext) !== false); - if ($selected) - { - $image_found = true; - $img_val = htmlspecialchars($img); - } - $template->assign_block_vars('imagesetlist.images', array( - 'SELECTED' => $selected, - 'TEXT' => $imgtext, - 'VALUE' => htmlspecialchars($img) - )); - } - } - - $imgsize_bool = (!empty($imgname) && $image_width && $image_height) ? true : false; - $image_request = '../styles/' . $imageset_path . '/imageset/' . ($image_lang ? $imgnamelang . '/' : '') . $image_filename; - - $template->assign_vars(array( - 'S_EDIT_IMAGESET' => true, - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'IMAGE_OPTIONS' => $img_options, - 'IMAGE_SIZE' => $image_width, - 'IMAGE_HEIGHT' => $image_height, - 'IMAGE_REQUEST' => (empty($image_filename)) ? 'images/no_image.png' : $image_request, - 'U_ACTION' => $this->u_action . "&action=edit&id=$imageset_id", - 'U_BACK' => $this->u_action, - 'NAME' => $imageset_name, - 'A_NAME' => addslashes($imageset_name), - 'PATH' => $imageset_path, - 'A_PATH' => addslashes($imageset_path), - 'ERROR' => !$valid_name, - 'IMG_SRC' => ($image_found) ? '../styles/' . $imageset_path . '/imageset/' . $img_val : 'images/no_image.png', - 'IMAGE_SELECT' => $image_found - )); - } - - /** - * Remove style/template/theme/imageset + * Remove style/template/theme */ function remove($mode, $style_id) { @@ -1588,7 +1117,7 @@ parse_css_file = {PARSE_CSS_FILE} { case 'style': $sql_from = STYLES_TABLE; - $sql_select = 'style_id, style_name, template_id, theme_id, imageset_id'; + $sql_select = 'style_id, style_name, template_id, theme_id'; $sql_where = 'AND style_active = 1'; break; @@ -1601,11 +1130,6 @@ parse_css_file = {PARSE_CSS_FILE} $sql_from = STYLES_THEME_TABLE; $sql_select = 'theme_id, theme_name, theme_path, theme_storedb'; break; - - case 'imageset': - $sql_from = STYLES_IMAGESET_TABLE; - $sql_select = 'imageset_id, imageset_name, imageset_path'; - break; } if ($mode === 'template' && ($conflicts = $this->check_inheritance($mode, $style_id))) @@ -1658,7 +1182,7 @@ parse_css_file = {PARSE_CSS_FILE} } // Remove the components - $components = array('template', 'theme', 'imageset'); + $components = array('template', 'theme'); foreach ($components as $component) { $new_id = request_var('new_' . $component . '_id', 0); @@ -1707,7 +1231,7 @@ parse_css_file = {PARSE_CSS_FILE} } /** - * Remove template/theme/imageset entry from the database + * Remove template/theme entry from the database */ function remove_component($component, $component_id, $new_id, $style_id = false) { @@ -1731,13 +1255,6 @@ parse_css_file = {PARSE_CSS_FILE} return; } - if ($component == 'imageset') - { - $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . " - WHERE imageset_id = $component_id"; - $db->sql_query($sql); - } - switch ($component) { case 'template': @@ -1747,10 +1264,6 @@ parse_css_file = {PARSE_CSS_FILE} case 'theme': $sql_from = STYLES_THEME_TABLE; break; - - case 'imageset': - $sql_from = STYLES_IMAGESET_TABLE;; - break; } $sql = "DELETE FROM $sql_from @@ -1764,7 +1277,7 @@ parse_css_file = {PARSE_CSS_FILE} } /** - * Display the options which can be used to replace a style/template/theme/imageset + * Display the options which can be used to replace a style/template/theme */ function display_component_options($component, $component_id, $style_row = false, $style_id = false) { @@ -1792,10 +1305,6 @@ parse_css_file = {PARSE_CSS_FILE} case 'theme': $sql_from = STYLES_THEME_TABLE; break; - - case 'imageset': - $sql_from = STYLES_IMAGESET_TABLE; - break; } $s_options = ''; @@ -1844,7 +1353,7 @@ parse_css_file = {PARSE_CSS_FILE} $template->assign_var('S_REPLACE_OPTIONS', $s_options); if ($component == 'style') { - $components = array('template', 'theme', 'imageset'); + $components = array('template', 'theme'); foreach ($components as $component) { $this->display_component_options($component, $style_row[$component . '_id'], false, $component_id, true); @@ -1906,7 +1415,6 @@ parse_css_file = {PARSE_CSS_FILE} $inc_template = request_var('inc_template', 0); $inc_theme = request_var('inc_theme', 0); - $inc_imageset = request_var('inc_imageset', 0); $store = request_var('store', 0); $format = request_var('format', ''); @@ -1932,7 +1440,7 @@ parse_css_file = {PARSE_CSS_FILE} switch ($mode) { case 'style': - if ($update && ($inc_template + $inc_theme + $inc_imageset) < 1) + if ($update && ($inc_template + $inc_theme) < 1) { $error[] = $user->lang['STYLE_ERR_MORE_ELEMENTS']; } @@ -1942,9 +1450,8 @@ parse_css_file = {PARSE_CSS_FILE} $sql_select = 's.style_id, s.style_name, s.style_copyright'; $sql_select .= ($inc_template) ? ', t.*' : ', t.template_name'; $sql_select .= ($inc_theme) ? ', c.*' : ', c.theme_name'; - $sql_select .= ($inc_imageset) ? ', i.*' : ', i.imageset_name'; - $sql_from = STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c, ' . STYLES_IMAGESET_TABLE . ' i'; - $sql_where = "s.style_id = $style_id AND t.template_id = s.template_id AND c.theme_id = s.theme_id AND i.imageset_id = s.imageset_id"; + $sql_from = STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c'; + $sql_where = "s.style_id = $style_id AND t.template_id = s.template_id AND c.theme_id = s.theme_id"; $l_prefix = 'STYLE'; break; @@ -1968,16 +1475,6 @@ parse_css_file = {PARSE_CSS_FILE} $l_prefix = 'THEME'; break; - - case 'imageset': - $name = 'imageset_name'; - - $sql_select = '*'; - $sql_from = STYLES_IMAGESET_TABLE; - $sql_where = "imageset_id = $style_id"; - - $l_prefix = 'IMAGESET'; - break; } if ($update && !sizeof($error)) @@ -1994,7 +1491,7 @@ parse_css_file = {PARSE_CSS_FILE} trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); } - $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_storedb', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_storedb', 'theme_mtime', 'theme_data', 'imageset_id', 'imageset_name', 'imageset_path', 'imageset_copyright'); + $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_storedb', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_storedb', 'theme_mtime', 'theme_data'); foreach ($var_ary as $var) { @@ -2012,7 +1509,6 @@ parse_css_file = {PARSE_CSS_FILE} $style_cfg .= (!$inc_template) ? "\nrequired_template = {$style_row['template_name']}" : ''; $style_cfg .= (!$inc_theme) ? "\nrequired_theme = {$style_row['theme_name']}" : ''; - $style_cfg .= (!$inc_imageset) ? "\nrequired_imageset = {$style_row['imageset_name']}" : ''; $data[] = array( 'src' => $style_cfg, @@ -2087,13 +1583,6 @@ parse_css_file = {PARSE_CSS_FILE} $items = $cache->obtain_cfg_items($style_row); $items = $items['theme']; - if (!isset($items['parse_css_file'])) - { - $items['parse_css_file'] = 'off'; - } - - $theme_cfg = str_replace(array('{PARSE_CSS_FILE}'), array($items['parse_css_file']), $theme_cfg); - $files[] = array( 'src' => "styles/{$style_row['theme_path']}/theme/", 'prefix-' => "styles/{$style_row['theme_path']}/", @@ -2108,6 +1597,7 @@ parse_css_file = {PARSE_CSS_FILE} if ($style_row['theme_storedb']) { + $style_row['theme_data'] = str_replace("styles/{$style_row['theme_path']}/theme/", './', $style_row['theme_data']); $data[] = array( 'src' => $style_row['theme_data'], 'prefix' => 'theme/stylesheet.css' @@ -2117,100 +1607,6 @@ parse_css_file = {PARSE_CSS_FILE} unset($items, $theme_cfg); } - // Export imageset core code - if ($mode == 'imageset' || $inc_imageset) - { - $imageset_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['imageset_name'], $style_row['imageset_copyright'], $config['version']), $this->imageset_cfg); - - $imageset_main = array(); - - $sql = 'SELECT image_filename, image_name, image_height, image_width - FROM ' . STYLES_IMAGESET_DATA_TABLE . " - WHERE imageset_id = $style_id - AND image_lang = ''"; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $imageset_main[$row['image_name']] = $row['image_filename'] . ($row['image_height'] ? '*' . $row['image_height']: '') . ($row['image_width'] ? '*' . $row['image_width']: ''); - } - $db->sql_freeresult($result); - - foreach ($this->imageset_keys as $topic => $key_array) - { - foreach ($key_array as $key) - { - if (isset($imageset_main[$key])) - { - $imageset_cfg .= "\nimg_" . $key . ' = ' . str_replace("styles/{$style_row['imageset_path']}/imageset/", '{PATH}', $imageset_main[$key]); - } - } - } - - $files[] = array( - 'src' => "styles/{$style_row['imageset_path']}/imageset/", - 'prefix-' => "styles/{$style_row['imageset_path']}/", - 'prefix+' => false, - 'exclude' => 'imageset.cfg' - ); - - $data[] = array( - 'src' => trim($imageset_cfg), - 'prefix' => 'imageset/imageset.cfg' - ); - - end($data); - - $imageset_root = "{$phpbb_root_path}styles/{$style_row['imageset_path']}/imageset/"; - - if ($dh = @opendir($imageset_root)) - { - while (($fname = readdir($dh)) !== false) - { - if ($fname[0] != '.' && $fname != 'CVS' && is_dir("$imageset_root$fname")) - { - $files[key($files)]['exclude'] .= ',' . $fname . '/imageset.cfg'; - } - } - closedir($dh); - } - - $imageset_lang = array(); - - $sql = 'SELECT image_filename, image_name, image_height, image_width, image_lang - FROM ' . STYLES_IMAGESET_DATA_TABLE . " - WHERE imageset_id = $style_id - AND image_lang <> ''"; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $imageset_lang[$row['image_lang']][$row['image_name']] = $row['image_filename'] . ($row['image_height'] ? '*' . $row['image_height']: '') . ($row['image_width'] ? '*' . $row['image_width']: ''); - } - $db->sql_freeresult($result); - - foreach ($imageset_lang as $lang => $imageset_localized) - { - $imageset_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['imageset_name'], $style_row['imageset_copyright'], $config['version']), $this->imageset_cfg); - - foreach ($this->imageset_keys as $topic => $key_array) - { - foreach ($key_array as $key) - { - if (isset($imageset_localized[$key])) - { - $imageset_cfg .= "\nimg_" . $key . ' = ' . str_replace("styles/{$style_row['imageset_path']}/imageset/", '{PATH}', $imageset_localized[$key]); - } - } - } - - $data[] = array( - 'src' => trim($imageset_cfg), - 'prefix' => 'imageset/' . $lang . '/imageset.cfg' - ); - } - - unset($imageset_cfg); - } - switch ($format) { case 'tar': @@ -2335,7 +1731,7 @@ parse_css_file = {PARSE_CSS_FILE} $l_type = strtoupper($mode); $error = array(); - $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE, 'imageset' => STYLES_IMAGESET_TABLE); + $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE); switch ($mode) { @@ -2350,10 +1746,6 @@ parse_css_file = {PARSE_CSS_FILE} case 'theme': $sql_from = STYLES_THEME_TABLE; break; - - case 'imageset': - $sql_from = STYLES_IMAGESET_TABLE; - break; } $sql = "SELECT * @@ -2377,7 +1769,6 @@ parse_css_file = {PARSE_CSS_FILE} $template_id = request_var('template_id', 0); $theme_id = request_var('theme_id', 0); - $imageset_id = request_var('imageset_id', 0); $style_active = request_var('style_active', 0); $style_default = request_var('style_default', 0); @@ -2397,7 +1788,7 @@ parse_css_file = {PARSE_CSS_FILE} $conflict = $db->sql_fetchrow($result); $db->sql_freeresult($result); - if ($mode == 'style' && (!$template_id || !$theme_id || !$imageset_id)) + if ($mode == 'style' && (!$template_id || !$theme_id)) { $error[] = $user->lang['STYLE_ERR_NO_IDS']; } @@ -2426,12 +1817,6 @@ parse_css_file = {PARSE_CSS_FILE} if ($mode == 'theme') { $cfg = parse_cfg_file("{$phpbb_root_path}styles/" . $style_row["{$mode}_path"] . "/theme/theme.cfg"); - - if (isset($cfg['parse_css_file']) && $cfg['parse_css_file'] && !$store_db) - { - $error[] = $user->lang['EDIT_THEME_STORE_PARSED']; - $store_db = 1; - } } } @@ -2455,7 +1840,6 @@ parse_css_file = {PARSE_CSS_FILE} $style_row = array_merge($style_row, array( 'template_id' => $template_id, 'theme_id' => $theme_id, - 'imageset_id' => $imageset_id, 'style_active' => $style_active, $mode . '_storedb' => $store_db, $mode . '_name' => $name, @@ -2478,14 +1862,10 @@ parse_css_file = {PARSE_CSS_FILE} $sql_ary += array( 'template_id' => (int) $template_id, 'theme_id' => (int) $theme_id, - 'imageset_id' => (int) $imageset_id, 'style_active' => (int) $style_active, ); break; - case 'imageset': - break; - case 'theme': if ($style_row['theme_storedb'] != $store_db) @@ -2619,7 +1999,6 @@ parse_css_file = {PARSE_CSS_FILE} 'S_STYLE' => ($mode == 'style') ? true : false, 'S_TEMPLATE' => ($mode == 'template') ? true : false, 'S_THEME' => ($mode == 'theme') ? true : false, - 'S_IMAGESET' => ($mode == 'imageset') ? true : false, 'S_STORE_DB' => (isset($style_row[$mode . '_storedb'])) ? $style_row[$mode . '_storedb'] : 0, 'S_STORE_DB_DISABLED' => (isset($style_row[$mode . '_inherits_id'])) ? $style_row[$mode . '_inherits_id'] : 0, 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, @@ -2628,7 +2007,6 @@ parse_css_file = {PARSE_CSS_FILE} 'S_TEMPLATE_OPTIONS' => ($mode == 'style') ? $template_options : '', 'S_THEME_OPTIONS' => ($mode == 'style') ? $theme_options : '', - 'S_IMAGESET_OPTIONS' => ($mode == 'style') ? $imageset_options : '', 'U_ACTION' => $this->u_action . '&action=details&id=' . $style_id, 'U_BACK' => $this->u_action, @@ -2876,7 +2254,7 @@ parse_css_file = {PARSE_CSS_FILE} } /** - * Install Style/Template/Theme/Imageset + * Install Style/Template/Theme */ function install($mode) { @@ -2886,7 +2264,7 @@ parse_css_file = {PARSE_CSS_FILE} $error = $installcfg = $style_row = array(); $root_path = $cfg_file = ''; - $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE, 'imageset' => STYLES_IMAGESET_TABLE); + $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE); $install_path = request_var('path', ''); $update = (isset($_POST['update'])) ? true : false; @@ -2932,7 +2310,6 @@ parse_css_file = {PARSE_CSS_FILE} $reqd_template = (isset($installcfg['required_template'])) ? $installcfg['required_template'] : false; $reqd_theme = (isset($installcfg['required_theme'])) ? $installcfg['required_theme'] : false; - $reqd_imageset = (isset($installcfg['required_imageset'])) ? $installcfg['required_imageset'] : false; // Check to see if each element is already installed, if it is grab the id foreach ($element_ary as $element => $table) @@ -2958,7 +2335,7 @@ parse_css_file = {PARSE_CSS_FILE} $cfg_contents = parse_cfg_file($cfg_file); // Merge only specific things. We may need them later. - foreach (array('inherit_from', 'parse_css_file') as $key) + foreach (array('inherit_from') as $key) { if (!empty($cfg_contents[$key]) && !isset($installcfg[$key])) { @@ -2977,10 +2354,6 @@ parse_css_file = {PARSE_CSS_FILE} case 'theme': $this->test_installed('theme', $error, $root_path, false, $style_row['theme_id'], $style_row['theme_name'], $style_row['theme_copyright']); break; - - case 'imageset': - $this->test_installed('imageset', $error, $root_path, false, $style_row['imageset_id'], $style_row['imageset_name'], $style_row['imageset_copyright']); - break; } } else @@ -3002,7 +2375,7 @@ parse_css_file = {PARSE_CSS_FILE} ${$element . '_root_path'} = (${'reqd_' . $element}) ? $phpbb_root_path . 'styles/' . ${'reqd_' . $element} . '/' : false; ${$element . '_path'} = (${'reqd_' . $element}) ? ${'reqd_' . $element} : false; } - $this->install_style($error, 'install', $root_path, $style_row['style_id'], $style_row['style_name'], $install_path, $style_row['style_copyright'], $style_row['style_active'], $style_row['style_default'], $style_row, $template_root_path, $template_path, $theme_root_path, $theme_path, $imageset_root_path, $imageset_path); + $this->install_style($error, 'install', $root_path, $style_row['style_id'], $style_row['style_name'], $install_path, $style_row['style_copyright'], $style_row['style_active'], $style_row['style_default'], $style_row, $template_root_path, $template_path, $theme_root_path, $theme_path); } else { @@ -3047,8 +2420,7 @@ parse_css_file = {PARSE_CSS_FILE} 'NAME' => $style_row[$mode . '_name'], 'COPYRIGHT' => $style_row[$mode . '_copyright'], 'TEMPLATE_NAME' => ($mode == 'style') ? $style_row['template_name'] : '', - 'THEME_NAME' => ($mode == 'style') ? $style_row['theme_name'] : '', - 'IMAGESET_NAME' => ($mode == 'style') ? $style_row['imageset_name'] : '') + 'THEME_NAME' => ($mode == 'style') ? $style_row['theme_name'] : '') ); } @@ -3060,7 +2432,7 @@ parse_css_file = {PARSE_CSS_FILE} global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template; $l_type = strtoupper($mode); - $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE, 'imageset' => STYLES_IMAGESET_TABLE); + $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE); $error = array(); $style_row = array( @@ -3068,7 +2440,6 @@ parse_css_file = {PARSE_CSS_FILE} $mode . '_copyright' => utf8_normalize_nfc(request_var('copyright', '', true)), 'template_id' => 0, 'theme_id' => 0, - 'imageset_id' => 0, 'store_db' => request_var('store_db', 0), 'style_active' => request_var('style_active', 1), 'style_default' => request_var('style_default', 0), @@ -3082,7 +2453,7 @@ parse_css_file = {PARSE_CSS_FILE} switch ($mode) { case 'style': - $sql_select = 'template_id, theme_id, imageset_id'; + $sql_select = 'template_id, theme_id'; $sql_from = STYLES_TABLE; break; @@ -3095,11 +2466,6 @@ parse_css_file = {PARSE_CSS_FILE} $sql_select = 'theme_id'; $sql_from = STYLES_THEME_TABLE; break; - - case 'imageset': - $sql_select = 'imageset_id'; - $sql_from = STYLES_IMAGESET_TABLE; - break; } $sql = "SELECT $sql_select @@ -3118,7 +2484,6 @@ parse_css_file = {PARSE_CSS_FILE} { $style_row['template_id'] = (isset($row['template_id'])) ? $row['template_id'] : $style_row['template_id']; $style_row['theme_id'] = (isset($row['theme_id'])) ? $row['theme_id'] : $style_row['theme_id']; - $style_row['imageset_id'] = (isset($row['imageset_id'])) ? $row['imageset_id'] : $style_row['imageset_id']; } } @@ -3126,9 +2491,8 @@ parse_css_file = {PARSE_CSS_FILE} { $style_row['template_id'] = request_var('template_id', $style_row['template_id']); $style_row['theme_id'] = request_var('theme_id', $style_row['theme_id']); - $style_row['imageset_id'] = request_var('imageset_id', $style_row['imageset_id']); - if ($mode == 'style' && (!$style_row['template_id'] || !$style_row['theme_id'] || !$style_row['imageset_id'])) + if ($mode == 'style' && (!$style_row['template_id'] || !$style_row['theme_id'])) { $error[] = $user->lang['STYLE_ERR_NO_IDS']; } @@ -3188,7 +2552,6 @@ parse_css_file = {PARSE_CSS_FILE} 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, 'S_TEMPLATE_OPTIONS' => ($mode == 'style') ? $template_options : '', 'S_THEME_OPTIONS' => ($mode == 'style') ? $theme_options : '', - 'S_IMAGESET_OPTIONS' => ($mode == 'style') ? $imageset_options : '', 'U_ACTION' => $this->u_action . '&action=add&basis=' . $basis, 'U_BACK' => $this->u_action, @@ -3210,7 +2573,6 @@ parse_css_file = {PARSE_CSS_FILE} $reqd_template = (isset($installcfg['required_template'])) ? $installcfg['required_template'] : false; $reqd_theme = (isset($installcfg['required_theme'])) ? $installcfg['required_theme'] : false; - $reqd_imageset = (isset($installcfg['required_imageset'])) ? $installcfg['required_imageset'] : false; // Check to see if each element is already installed, if it is grab the id foreach ($element_ary as $element => $table) @@ -3237,10 +2599,6 @@ parse_css_file = {PARSE_CSS_FILE} case 'theme': $sql_from = STYLES_THEME_TABLE; break; - - case 'imageset': - $sql_from = STYLES_IMAGESET_TABLE; - break; } $l_element = strtoupper($element); @@ -3279,11 +2637,11 @@ parse_css_file = {PARSE_CSS_FILE} /** * Install/Add style */ - function install_style(&$error, $action, $root_path, &$id, $name, $path, $copyright, $active, $default, &$style_row, $template_root_path = false, $template_path = false, $theme_root_path = false, $theme_path = false, $imageset_root_path = false, $imageset_path = false) + function install_style(&$error, $action, $root_path, &$id, $name, $path, $copyright, $active, $default, &$style_row, $template_root_path = false, $template_path = false, $theme_root_path = false, $theme_path = false) { global $config, $db, $user; - $element_ary = array('template', 'theme', 'imageset'); + $element_ary = array('template', 'theme'); if (!$name) { @@ -3329,7 +2687,7 @@ parse_css_file = {PARSE_CSS_FILE} } } - if (!$style_row['template_id'] || !$style_row['theme_id'] || !$style_row['imageset_id']) + if (!$style_row['template_id'] || !$style_row['theme_id']) { $error[] = $user->lang['STYLE_ERR_NO_IDS']; } @@ -3347,7 +2705,6 @@ parse_css_file = {PARSE_CSS_FILE} 'style_active' => (int) $active, 'template_id' => (int) $style_row['template_id'], 'theme_id' => (int) $style_row['theme_id'], - 'imageset_id' => (int) $style_row['imageset_id'], ); $sql = 'INSERT INTO ' . STYLES_TABLE . ' @@ -3390,10 +2747,6 @@ parse_css_file = {PARSE_CSS_FILE} case 'theme': $sql_from = STYLES_THEME_TABLE; break; - - case 'imageset': - $sql_from = STYLES_IMAGESET_TABLE; - break; } $l_type = strtoupper($mode); @@ -3516,21 +2869,12 @@ parse_css_file = {PARSE_CSS_FILE} case 'theme': // We are only interested in the theme configuration for now - if (isset($cfg_data['parse_css_file']) && $cfg_data['parse_css_file']) - { - $store_db = 1; - } - $sql_ary += array( 'theme_storedb' => $store_db, 'theme_data' => ($store_db) ? $this->db_theme_data($sql_ary, false, $root_path) : '', 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/$path/theme/stylesheet.css") ); break; - - // all the heavy lifting is done later - case 'imageset': - break; } $db->sql_transaction('begin'); @@ -3546,106 +2890,6 @@ parse_css_file = {PARSE_CSS_FILE} $filelist = filelist("{$root_path}template", '', 'html'); $this->store_templates('insert', $id, $path, $filelist); } - else if ($mode == 'imageset') - { - $cfg_data = parse_cfg_file("$root_path$mode/imageset.cfg"); - - $imageset_definitions = array(); - foreach ($this->imageset_keys as $topic => $key_array) - { - $imageset_definitions = array_merge($imageset_definitions, $key_array); - } - - foreach ($cfg_data as $key => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($key, 'img_') === 0 && $image_filename) - { - $key = substr($key, 4); - if (in_array($key, $imageset_definitions)) - { - $sql_ary = array( - 'image_name' => $key, - 'image_filename' => str_replace('{PATH}', "styles/$path/imageset/", trim($image_filename)), - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $id, - 'image_lang' => '', - ); - $db->sql_query('INSERT INTO ' . STYLES_IMAGESET_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); - } - } - } - unset($cfg_data); - - $sql = 'SELECT lang_dir - FROM ' . LANG_TABLE; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - if (@file_exists("$root_path$mode/{$row['lang_dir']}/imageset.cfg")) - { - $cfg_data_imageset_data = parse_cfg_file("$root_path$mode/{$row['lang_dir']}/imageset.cfg"); - foreach ($cfg_data_imageset_data as $image_name => $value) - { - if (strpos($value, '*') !== false) - { - if (substr($value, -1, 1) === '*') - { - list($image_filename, $image_height) = explode('*', $value); - $image_width = 0; - } - else - { - list($image_filename, $image_height, $image_width) = explode('*', $value); - } - } - else - { - $image_filename = $value; - $image_height = $image_width = 0; - } - - if (strpos($image_name, 'img_') === 0 && $image_filename) - { - $image_name = substr($image_name, 4); - if (in_array($image_name, $imageset_definitions)) - { - $sql_ary = array( - 'image_name' => $image_name, - 'image_filename' => $image_filename, - 'image_height' => (int) $image_height, - 'image_width' => (int) $image_width, - 'imageset_id' => (int) $id, - 'image_lang' => $row['lang_dir'], - ); - $db->sql_query('INSERT INTO ' . STYLES_IMAGESET_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); - } - } - } - unset($cfg_data_imageset_data); - } - } - $db->sql_freeresult($result); - } $db->sql_transaction('commit'); @@ -3679,10 +2923,6 @@ parse_css_file = {PARSE_CSS_FILE} case 'theme': $sql_from = STYLES_THEME_TABLE; break; - - case 'imageset': - $sql_from = STYLES_IMAGESET_TABLE; - break; } $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path @@ -3735,10 +2975,6 @@ parse_css_file = {PARSE_CSS_FILE} case 'theme': $sql_from = STYLES_THEME_TABLE; break; - - case 'imageset': - $sql_from = STYLES_IMAGESET_TABLE; - break; } $sql = "SELECT {$mode}_inherits_id -- cgit v1.2.1 From 9e4349e7faac65403de02fd090a837fee92b764a Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 4 Sep 2008 11:39:25 +0000 Subject: [feature/remove-db-styles] Removed database storage of style components. The bulk of database storage of templates is removed, rendering template stored in the database as useless. Theme database storage is reduced to a skeleton for full removal soon. This commit was cherry picked from the old feature/ascraeus-experiment branch the old commit hash is 0dbe7e3b6cd450342d3c566eb2caf36ca1b5db8e. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 376 +++----------------------------------- 1 file changed, 27 insertions(+), 349 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 82878cfadb..8bd75c6ab9 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -207,7 +207,7 @@ version = {VERSION} switch ($action) { - // Refresh template data stored in db and clear cache + // Clear cache case 'refresh': $sql = 'SELECT * @@ -224,49 +224,13 @@ version = {VERSION} if (confirm_box(true)) { - $template_refreshed = ''; - - // Only refresh database if the template is stored in the database - if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) - { - $filelist = array('' => array()); - - $sql = 'SELECT template_filename, template_mtime - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $style_id"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { -// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) -// { - // get folder info from the filename - if (($slash_pos = strrpos($row['template_filename'], '/')) === false) - { - $filelist[''][] = $row['template_filename']; - } - else - { - $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1); - } -// } - } - $db->sql_freeresult($result); - - $this->store_templates('update', $style_id, $template_row['template_path'], $filelist); - unset($filelist); - - $template_refreshed = $user->lang['TEMPLATE_REFRESHED'] . '
'; - add_log('admin', 'LOG_TEMPLATE_REFRESHED', $template_row['template_name']); - } - $this->clear_template_cache($template_row); - trigger_error($template_refreshed . $user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action)); + trigger_error($user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action)); } else { - confirm_box(false, ($template_row['template_storedb']) ? $user->lang['CONFIRM_TEMPLATE_REFRESH'] : $user->lang['CONFIRM_TEMPLATE_CLEAR_CACHE'], build_hidden_fields(array( + confirm_box(false, $user->lang['CONFIRM_TEMPLATE_CLEAR_CACHE'], build_hidden_fields(array( 'i' => $id, 'mode' => $mode, 'action' => $action, @@ -526,7 +490,7 @@ version = {VERSION} $template_file = preg_replace('#\.{2,}#', '.', $template_file); // Retrieve some information about the template - $sql = 'SELECT template_storedb, template_path, template_name + $sql = 'SELECT template_path, template_name FROM ' . STYLES_TEMPLATE_TABLE . " WHERE template_id = $template_id"; $result = $db->sql_query($sql); @@ -554,8 +518,8 @@ version = {VERSION} $file = "{$phpbb_root_path}styles/{$template_info['template_path']}/template/$template_file"; $additional = ''; - // If the template is stored on the filesystem try to write the file else store it in the database - if (!$safe_mode && !$template_info['template_storedb'] && file_exists($file) && phpbb_is_writable($file)) + // Try to write the file + if (!$safe_mode && file_exists($file) && phpbb_is_writable($file)) { if (!($fp = @fopen($file, 'wb'))) { @@ -567,32 +531,8 @@ version = {VERSION} } else { - $db->sql_transaction('begin'); - - // If it's not stored in the db yet, then update the template setting and store all template files in the db - if (!$template_info['template_storedb']) - { - if ($super = $this->get_super('template', $template_id)) - { - $this->store_in_db('template', $super['template_id']); - } - else - { - $this->store_in_db('template', $template_id); - } - - add_log('admin', 'LOG_TEMPLATE_EDIT_DETAILS', $template_info['template_name']); - $additional .= '
' . $user->lang['EDIT_TEMPLATE_STORED_DB']; - } - - // Update the template_data table entry for this template file - $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . " - SET template_data = '" . $db->sql_escape($template_data) . "', template_mtime = " . time() . " - WHERE template_id = $template_id - AND template_filename = '" . $db->sql_escape($template_file) . "'"; - $db->sql_query($sql); - - $db->sql_transaction('commit'); + // @todo + trigger_error('Cannot write template file.', E_USER_ERROR); } // destroy the cached version of the template (filename without extension) @@ -605,52 +545,17 @@ version = {VERSION} } // Generate a category array containing template filenames - if (!$template_info['template_storedb']) - { - $template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template"; + $template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template"; - $filelist = filelist($template_path, '', 'html'); - $filelist[''] = array_diff($filelist[''], array('bbcode.html')); + $filelist = filelist($template_path, '', 'html'); + $filelist[''] = array_diff($filelist[''], array('bbcode.html')); - if ($template_file) - { - if (!file_exists($template_path . "/$template_file") || !($template_data = file_get_contents($template_path . "/$template_file"))) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - } - else + if ($template_file) { - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $template_id"; - $result = $db->sql_query($sql); - - $filelist = array('' => array()); - while ($row = $db->sql_fetchrow($result)) + if (!file_exists($template_path . "/$template_file") || !($template_data = file_get_contents($template_path . "/$template_file"))) { - $file_info = pathinfo($row['template_filename']); - - if (($file_info['basename'] != 'bbcode') && ($file_info['extension'] == 'html')) - { - if (($file_info['dirname'] == '.') || empty($file_info['dirname'])) - { - $filelist[''][] = $row['template_filename']; - } - else - { - $filelist[$file_info['dirname'] . '/'][] = $file_info['basename']; - } - } - - if ($row['template_filename'] == $template_file) - { - $template_data = $row['template_data']; - } + trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); } - $db->sql_freeresult($result); - unset($file_info); } if (empty($filelist[''])) @@ -821,35 +726,6 @@ version = {VERSION} adm_page_footer(); } - $filemtime = array(); - if ($template_row['template_storedb']) - { - $ids = array(); - if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id']) - { - $ids[] = $template_row['template_inherits_id']; - } - $ids[] = $template_row['template_id']; - - $filemtime = array(); - $file_template_db = array(); - - foreach ($ids as $id) - { - $sql = 'SELECT template_filename, template_mtime - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $id"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $filemtime[$row['template_filename']] = $row['template_mtime']; - $file_template_db[$row['template_filename']] = $id; - } - $db->sql_freeresult($result); - } - } - // Get a list of cached template files and then retrieve additional information about them $file_ary = $this->template_cache_filelist($template_row['template_path']); @@ -905,10 +781,9 @@ version = {VERSION} 'FILENAME' => $file, 'FILENAME_PATH' => $file_tpl, 'FILESIZE' => get_formatted_filesize(filesize("{$phpbb_root_path}cache/$filename")), - 'MODIFIED' => $user->format_date((!$template_row['template_storedb']) ? filemtime($file_tpl) : $filemtime[$file . '.html'])) - ); + 'MODIFIED' => $user->format_date(filemtime($file_tpl)), + )); } - unset($filemtime); $template->assign_vars(array( 'S_CACHE' => true, @@ -1123,7 +998,7 @@ version = {VERSION} case 'template': $sql_from = STYLES_TEMPLATE_TABLE; - $sql_select = 'template_id, template_name, template_path, template_storedb'; + $sql_select = 'template_id, template_name, template_path'; break; case 'theme': @@ -1491,7 +1366,7 @@ version = {VERSION} trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); } - $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_storedb', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_storedb', 'theme_mtime', 'theme_data'); + $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_storedb', 'theme_mtime', 'theme_data'); foreach ($var_ary as $var) { @@ -1546,31 +1421,12 @@ version = {VERSION} ); // This is potentially nasty memory-wise ... - if (!$style_row['template_storedb']) - { - $files[] = array( - 'src' => "styles/{$style_row['template_path']}/template/", - 'prefix-' => "styles/{$style_row['template_path']}/", - 'prefix+' => false, - 'exclude' => 'template.cfg' - ); - } - else - { - $sql = 'SELECT template_filename, template_data - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = {$style_row['template_id']}"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $data[] = array( - 'src' => $row['template_data'], - 'prefix' => 'template/' . $row['template_filename'] - ); - } - $db->sql_freeresult($result); - } + $files[] = array( + 'src' => "styles/{$style_row['template_path']}/template/", + 'prefix-' => "styles/{$style_row['template_path']}/", + 'prefix+' => false, + 'exclude' => 'template.cfg' + ); unset($template_cfg); } @@ -1772,7 +1628,6 @@ version = {VERSION} $style_active = request_var('style_active', 0); $style_default = request_var('style_default', 0); - $store_db = request_var('store_db', 0); // If the admin selected the style to be the default style, but forgot to activate it... we will do it for him if ($style_default) @@ -1803,23 +1658,6 @@ version = {VERSION} $error[] = $user->lang[$l_type . '_ERR_STYLE_NAME']; } - if ($mode === 'theme' || $mode === 'template') - { - // a rather elaborate check we have to do here once to avoid trouble later - $check = "{$phpbb_root_path}styles/" . $style_row["{$mode}_path"] . (($mode === 'theme') ? '/theme/stylesheet.css' : '/template'); - if (($style_row["{$mode}_storedb"] != $store_db) && !$store_db && ($safe_mode || !phpbb_is_writable($check))) - { - $error[] = $user->lang['EDIT_' . strtoupper($mode) . '_STORED_DB']; - $store_db = 1; - } - - // themes which have to be parsed have to go into db - if ($mode == 'theme') - { - $cfg = parse_cfg_file("{$phpbb_root_path}styles/" . $style_row["{$mode}_path"] . "/theme/theme.cfg"); - } - } - if (!sizeof($error)) { // Check length settings @@ -1841,7 +1679,6 @@ version = {VERSION} 'template_id' => $template_id, 'theme_id' => $theme_id, 'style_active' => $style_active, - $mode . '_storedb' => $store_db, $mode . '_name' => $name, $mode . '_copyright' => $copyright) ); @@ -1867,72 +1704,9 @@ version = {VERSION} break; case 'theme': - - if ($style_row['theme_storedb'] != $store_db) - { - $theme_data = ''; - - if (!$style_row['theme_storedb']) - { - $theme_data = $this->db_theme_data($style_row); - } - else if (!$store_db && !$safe_mode && phpbb_is_writable("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css")) - { - $store_db = 1; - $theme_data = $style_row['theme_data']; - - if ($fp = @fopen("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css", 'wb')) - { - $store_db = (@fwrite($fp, str_replace("styles/{$style_row['theme_path']}/theme/", './', $theme_data))) ? 0 : 1; - } - fclose($fp); - } - - $sql_ary += array( - 'theme_mtime' => ($store_db) ? filemtime("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css") : 0, - 'theme_storedb' => $store_db, - 'theme_data' => ($store_db) ? $theme_data : '', - ); - } break; case 'template': - - if ($style_row['template_storedb'] != $store_db) - { - if ($super = $this->get_super($mode, $style_row['template_id'])) - { - $error[] = (sprintf($user->lang["{$l_type}_INHERITS"], $super['template_name'])); - $sql_ary = array(); - } - else - { - if (!$store_db && !$safe_mode && phpbb_is_writable("{$phpbb_root_path}styles/{$style_row['template_path']}/template")) - { - $err = $this->store_in_fs('template', $style_row['template_id']); - if ($err) - { - $error += $err; - } - } - else if ($store_db) - { - $this->store_in_db('template', $style_row['template_id']); - } - else - { - // We no longer store within the db, but are also not able to update the file structure - // Since the admin want to switch this, we adhere to his decision. But we also need to remove the cache - $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $style_id"; - $db->sql_query($sql); - } - - $sql_ary += array( - 'template_storedb' => $store_db, - ); - } - } break; } @@ -1999,8 +1773,6 @@ version = {VERSION} 'S_STYLE' => ($mode == 'style') ? true : false, 'S_TEMPLATE' => ($mode == 'template') ? true : false, 'S_THEME' => ($mode == 'theme') ? true : false, - 'S_STORE_DB' => (isset($style_row[$mode . '_storedb'])) ? $style_row[$mode . '_storedb'] : 0, - 'S_STORE_DB_DISABLED' => (isset($style_row[$mode . '_inherits_id'])) ? $style_row[$mode . '_inherits_id'] : 0, 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, 'S_SUPERTEMPLATE' => (isset($style_row[$mode . '_inherits_id']) && $style_row[$mode . '_inherits_id']) ? $super['template_name'] : 0, @@ -2101,84 +1873,6 @@ version = {VERSION} return str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); } - /** - * Store template files into db - */ - function store_templates($mode, $style_id, $template_path, $filelist) - { - global $phpbb_root_path, $phpEx, $db; - - $template_path = $template_path . '/template/'; - $includes = array(); - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - if (!($fp = @fopen("{$phpbb_root_path}styles/$template_path$pathfile$file", 'r'))) - { - trigger_error("Could not open {$phpbb_root_path}styles/$template_path$pathfile$file", E_USER_ERROR); - } - - $filesize = filesize("{$phpbb_root_path}styles/$template_path$pathfile$file"); - - if ($filesize) - { - $template_data = fread($fp, $filesize); - } - - fclose($fp); - - if (!$filesize) - { - // File is empty - continue; - } - - if (preg_match_all('##is', $template_data, $matches)) - { - foreach ($matches[1] as $match) - { - $includes[trim($match)][] = $file; - } - } - } - } - - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - // Skip index. - if (strpos($file, 'index.') === 0) - { - continue; - } - - // We could do this using extended inserts ... but that could be one - // heck of a lot of data ... - $sql_ary = array( - 'template_id' => (int) $style_id, - 'template_filename' => "$pathfile$file", - 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '', - 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/$template_path$pathfile$file"), - 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/$template_path$pathfile$file"), - ); - - if ($mode == 'insert') - { - $sql = 'INSERT INTO ' . STYLES_TEMPLATE_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); - } - else - { - $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE template_id = $style_id - AND template_filename = '" . $db->sql_escape("$pathfile$file") . "'"; - } - $db->sql_query($sql); - } - } - } - /** * Returns an array containing all template filenames for one template that are currently cached. * @@ -2361,7 +2055,6 @@ version = {VERSION} trigger_error($user->lang['NO_' . $l_type] . adm_back_link($this->u_action), E_USER_WARNING); } - $style_row['store_db'] = request_var('store_db', 0); $style_row['style_active'] = request_var('style_active', 1); $style_row['style_default'] = request_var('style_default', 0); @@ -2379,15 +2072,14 @@ version = {VERSION} } else { - $style_row['store_db'] = $this->install_element($mode, $error, 'install', $root_path, $style_row[$mode . '_id'], $style_row[$mode . '_name'], $install_path, $style_row[$mode . '_copyright'], $style_row['store_db']); + $this->install_element($mode, $error, 'install', $root_path, $style_row[$mode . '_id'], $style_row[$mode . '_name'], $install_path, $style_row[$mode . '_copyright']); } if (!sizeof($error)) { $cache->destroy('sql', STYLES_TABLE); - $message = ($style_row['store_db']) ? '_ADDED_DB' : '_ADDED'; - trigger_error($user->lang[$l_type . $message] . adm_back_link($this->u_action)); + trigger_error($user->lang[$l_type . '_ADDED'] . adm_back_link($this->u_action)); } } @@ -2403,7 +2095,6 @@ version = {VERSION} 'S_SUPERTEMPLATE' => (isset($installcfg['inherit_from'])) ? $installcfg['inherit_from'] : '', 'S_THEME' => ($mode == 'theme') ? true : false, - 'S_STORE_DB' => (isset($style_row[$mode . '_storedb'])) ? $style_row[$mode . '_storedb'] : 0, 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, @@ -2440,7 +2131,6 @@ version = {VERSION} $mode . '_copyright' => utf8_normalize_nfc(request_var('copyright', '', true)), 'template_id' => 0, 'theme_id' => 0, - 'store_db' => request_var('store_db', 0), 'style_active' => request_var('style_active', 1), 'style_default' => request_var('style_default', 0), ); @@ -2512,8 +2202,7 @@ version = {VERSION} { $cache->destroy('sql', STYLES_TABLE); - $message = ($style_row['store_db']) ? '_ADDED_DB' : '_ADDED'; - trigger_error($user->lang[$l_type . $message] . adm_back_link($this->u_action)); + trigger_error($user->lang[$l_type . '_ADDED'] . adm_back_link($this->u_action)); } } @@ -2547,7 +2236,6 @@ version = {VERSION} 'S_THEME' => ($mode == 'theme') ? true : false, 'S_BASIS' => ($basis) ? true : false, - 'S_STORE_DB' => (isset($style_row['storedb'])) ? $style_row['storedb'] : 0, 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, 'S_TEMPLATE_OPTIONS' => ($mode == 'style') ? $template_options : '', @@ -2853,10 +2541,6 @@ version = {VERSION} $sql_ary['bbcode_bitfield'] = $this->template_bitfield; } - // We set a pre-defined bitfield here which we may use further in 3.2 - $sql_ary += array( - 'template_storedb' => $store_db, - ); if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from']) { $sql_ary += array( @@ -2885,12 +2569,6 @@ version = {VERSION} $id = $db->sql_nextid(); - if ($mode == 'template' && $store_db) - { - $filelist = filelist("{$root_path}template", '', 'html'); - $this->store_templates('insert', $id, $path, $filelist); - } - $db->sql_transaction('commit'); $log = ($store_db) ? 'LOG_' . $l_type . '_ADD_DB' : 'LOG_' . $l_type . '_ADD_FS'; -- cgit v1.2.1 From 23415170cb8e8c923c540bca84345bfb8f9e92c3 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 18:04:18 +0100 Subject: [feature/remove-db-styles] Removing unused methods from acp_style. These got left behind in 6854d47. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 176 -------------------------------------- 1 file changed, 176 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 8bd75c6ab9..7ab2061141 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -2684,180 +2684,4 @@ version = {VERSION} return false; } - - /** - * Moves a template set and its subtemplates to the database - * - * @access public - * @param string $mode The component to move - only template is supported - * @param int $id The template id - */ - function store_in_db($mode, $id) - { - global $db, $user; - - $error = array(); - $l_type = strtoupper($mode); - if ($super = $this->get_super($mode, $id)) - { - $error[] = (sprintf($user->lang["{$l_type}_INHERITS"], $super['template_name'])); - return $error; - } - - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path - FROM " . STYLES_TEMPLATE_TABLE . ' - WHERE template_id = ' . (int) $id; - - $result = $db->sql_query_limit($sql, 1); - if ($row = $db->sql_fetchrow($result)) - { - $db->sql_freeresult($result); - $subs = $this->check_inheritance($mode, $id); - - $this->_store_in_db($mode, $id, $row["{$mode}_path"]); - if ($subs && sizeof($subs)) - { - foreach ($subs as $sub_id => $sub) - { - if ($err = $this->_store_in_db($mode, $sub["{$mode}_id"], $sub["{$mode}_path"])) - { - $error[] = $err; - } - } - } - } - if (sizeof($error)) - { - return $error; - } - - return false; - } - - /** - * Moves a template set to the database - * - * @access private - * @param string $mode The component to move - only template is supported - * @param int $id The template id - * @param string $path TThe path to the template files - */ - function _store_in_db($mode, $id, $path) - { - global $phpbb_root_path, $db; - - $filelist = filelist("{$phpbb_root_path}styles/{$path}/template", '', 'html'); - $this->store_templates('insert', $id, $path, $filelist); - - // Okay, we do the query here -shouldn't be triggered often. - $sql = 'UPDATE ' . STYLES_TEMPLATE_TABLE . ' - SET template_storedb = 1 - WHERE template_id = ' . $id; - $db->sql_query($sql); - } - - /** - * Moves a template set and its subtemplates to the filesystem - * - * @access public - * @param string $mode The component to move - only template is supported - * @param int $id The template id - */ - function store_in_fs($mode, $id) - { - global $db, $user; - - $error = array(); - $l_type = strtoupper($mode); - if ($super = $this->get_super($mode, $id)) - { - $error[] = (sprintf($user->lang["{$l_type}_INHERITS"], $super['template_name'])); - return($error); - } - - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path - FROM " . STYLES_TEMPLATE_TABLE . ' - WHERE template_id = ' . (int) $id; - - $result = $db->sql_query_limit($sql, 1); - if ($row = $db->sql_fetchrow($result)) - { - $db->sql_freeresult($result); - if (!sizeof($error)) - { - $subs = $this->check_inheritance($mode, $id); - - $this->_store_in_fs($mode, $id, $row["{$mode}_path"]); - - if ($subs && sizeof($subs)) - { - foreach ($subs as $sub_id => $sub) - { - $this->_store_in_fs($mode, $sub["{$mode}_id"], $sub["{$mode}_path"]); - } - } - } - if (sizeof($error)) - { - $this->store_in_db($id, $mode); - return $error; - } - } - return false; - } - - /** - * Moves a template set to the filesystem - * - * @access private - * @param string $mode The component to move - only template is supported - * @param int $id The template id - * @param string $path The path to the template - */ - function _store_in_fs($mode, $id, $path) - { - global $phpbb_root_path, $db, $user, $safe_mode; - - $store_db = 0; - $error = array(); - if (!$safe_mode && phpbb_is_writable("{$phpbb_root_path}styles/{$path}/template")) - { - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $id"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - if (!($fp = @fopen("{$phpbb_root_path}styles/{$path}/template/" . $row['template_filename'], 'wb'))) - { - $store_db = 1; - $error[] = $user->lang['EDIT_TEMPLATE_STORED_DB']; - break; - } - - fwrite($fp, $row['template_data']); - fclose($fp); - } - $db->sql_freeresult($result); - - if (!$store_db) - { - $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $id"; - $db->sql_query($sql); - } - } - if (sizeof($error)) - { - return $error; - } - $sql = 'UPDATE ' . STYLES_TEMPLATE_TABLE . ' - SET template_storedb = 0 - WHERE template_id = ' . $id; - $db->sql_query($sql); - - return false; - } - } -- cgit v1.2.1 From ad11565ace0ef60bd98b2e368aeeffa67b6b1f49 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 18:46:45 +0100 Subject: [feature/remove-db-styles] Missed a few template DB bits in acp_styles. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 7ab2061141..389bbee483 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -748,30 +748,10 @@ version = {VERSION} $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_path']}/template/$tpl_file.html"; $inherited = false; - if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id']) + if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id'] && !file_exists($file_tpl)) { - if (!$template_row['template_storedb']) - { - if (!file_exists($file_tpl)) - { - $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/$tpl_file.html"; - $inherited = true; - } - } - else - { - if ($file_template_db[$file . '.html'] == $template_row['template_inherits_id']) - { - $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/$tpl_file.html"; - $inherited = true; - } - } - } - - // Correct the filename if it is stored in database and the file is in a subfolder. - if ($template_row['template_storedb']) - { - $file = str_replace('.', '/', $file); + $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/$tpl_file.html"; + $inherited = true; } $template->assign_block_vars('file', array( -- cgit v1.2.1 From c2d6c613d3992f243477fe291e53f8bdb029999c Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 19:25:21 +0100 Subject: [feature/remove-db-styles] ACP has forgotten how to store themes in the DB. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 142 ++++++-------------------------------- 1 file changed, 22 insertions(+), 120 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 389bbee483..c4c01fbc44 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -245,63 +245,7 @@ version = {VERSION} break; case 'theme': - - switch ($action) - { - // Refresh theme data stored in the database - case 'refresh': - - $sql = 'SELECT * - FROM ' . STYLES_THEME_TABLE . " - WHERE theme_id = $style_id"; - $result = $db->sql_query($sql); - $theme_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$theme_row) - { - trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (!$theme_row['theme_storedb']) - { - trigger_error($user->lang['THEME_ERR_REFRESH_FS'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (confirm_box(true)) - { - if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) - { - // Save CSS contents - $sql_ary = array( - 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), - 'theme_data' => '', - 'theme_storedb' => 0 - ); - - $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE theme_id = $style_id"; - $db->sql_query($sql); - - $cache->destroy('sql', STYLES_THEME_TABLE); - - add_log('admin', 'LOG_THEME_REFRESHED', $theme_row['theme_name']); - trigger_error($user->lang['THEME_REFRESHED'] . adm_back_link($this->u_action)); - } - } - else - { - confirm_box(false, $user->lang['CONFIRM_THEME_REFRESH'], build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'action' => $action, - 'id' => $style_id - ))); - } - break; - } - - $this->frontend('theme', array('edit', 'details'), array('refresh', 'export', 'delete')); + $this->frontend('theme', array('edit', 'details'), array('export', 'delete')); break; } } @@ -797,7 +741,7 @@ version = {VERSION} $theme_file = str_replace('..', '.', $theme_file); // Retrieve some information about the theme - $sql = 'SELECT theme_storedb, theme_path, theme_name, theme_data + $sql = 'SELECT theme_path, theme_name FROM ' . STYLES_THEME_TABLE . " WHERE theme_id = $theme_id"; $result = $db->sql_query($sql); @@ -816,8 +760,7 @@ version = {VERSION} $additional = ''; $message = $user->lang['THEME_UPDATED']; - // If the theme is stored on the filesystem try to write the file else store it in the database - if (!$safe_mode && !$theme_info['theme_storedb'] && file_exists($file) && phpbb_is_writable($file)) + if (!$safe_mode && file_exists($file) && phpbb_is_writable($file)) { if (!($fp = @fopen($file, 'wb'))) { @@ -828,51 +771,28 @@ version = {VERSION} } else { - // Write stylesheet to db - $sql_ary = array( - 'theme_mtime' => time(), - 'theme_storedb' => 1, - 'theme_data' => $this->db_theme_data($theme_info, $theme_data), - ); - $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE theme_id = ' . $theme_id; - $db->sql_query($sql); - - $cache->destroy('sql', STYLES_THEME_TABLE); - - // notify the user if the theme was not stored in the db before his modification - if (!$theme_info['theme_storedb']) - { - add_log('admin', 'LOG_THEME_EDIT_DETAILS', $theme_info['theme_name']); - $message .= '
' . $user->lang['EDIT_THEME_STORED_DB']; - } + // @todo Proper error + trigger_error('Cannot write to theme file.', E_USER_ERROR); } + $cache->destroy('sql', STYLES_THEME_TABLE); - add_log('admin', (!$theme_info['theme_storedb']) ? 'LOG_THEME_EDIT_FILE' : 'LOG_THEME_EDIT', $theme_info['theme_name'], (!$theme_info['theme_storedb']) ? $theme_file : ''); + add_log('admin', 'LOG_THEME_EDIT_FILE', $theme_info['theme_name'], $theme_file); trigger_error($message . adm_back_link($this->u_action . "&action=edit&id=$theme_id&template_file=$theme_file&text_rows=$text_rows")); } // Generate a category array containing theme filenames - if (!$theme_info['theme_storedb']) - { - $theme_path = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme"; + $theme_path = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme"; - $filelist = filelist($theme_path, '', 'css'); + $filelist = filelist($theme_path, '', 'css'); - if ($theme_file) + if ($theme_file) + { + if (!file_exists($theme_path . "/$theme_file") || !($theme_data = file_get_contents($theme_path . "/$theme_file"))) { - if (!file_exists($theme_path . "/$theme_file") || !($theme_data = file_get_contents($theme_path . "/$theme_file"))) - { - trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); - } + trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); } } - else - { - $theme_data = &$theme_info['theme_data']; - } // Now create the categories $filelist_cats[''] = array(); @@ -935,7 +855,6 @@ version = {VERSION} $template->assign_vars(array( 'S_EDIT_THEME' => true, 'S_HIDDEN_FIELDS' => build_hidden_fields(array('template_file' => $theme_file)), - 'S_THEME_IN_DB' => $theme_info['theme_storedb'], 'S_TEMPLATES' => $tpl_options, 'U_ACTION' => $this->u_action . "&action=edit&id=$theme_id&text_rows=$text_rows", @@ -953,8 +872,8 @@ version = {VERSION} 'SELECTED_TEMPLATE' => $theme_info['theme_name'], 'TEMPLATE_FILE' => $theme_file, 'TEMPLATE_DATA' => utf8_htmlspecialchars($theme_data), - 'TEXT_ROWS' => $text_rows) - ); + 'TEXT_ROWS' => $text_rows, + )); } /** @@ -983,7 +902,7 @@ version = {VERSION} case 'theme': $sql_from = STYLES_THEME_TABLE; - $sql_select = 'theme_id, theme_name, theme_path, theme_storedb'; + $sql_select = 'theme_id, theme_name, theme_path'; break; } @@ -1346,7 +1265,7 @@ version = {VERSION} trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); } - $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_storedb', 'theme_mtime', 'theme_data'); + $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_mtime'); foreach ($var_ary as $var) { @@ -1423,23 +1342,14 @@ version = {VERSION} 'src' => "styles/{$style_row['theme_path']}/theme/", 'prefix-' => "styles/{$style_row['theme_path']}/", 'prefix+' => false, - 'exclude' => ($style_row['theme_storedb']) ? 'stylesheet.css,theme.cfg' : 'theme.cfg' + 'exclude' => 'theme.cfg', ); $data[] = array( 'src' => $theme_cfg, - 'prefix' => 'theme/theme.cfg' + 'prefix' => 'theme/theme.cfg', ); - if ($style_row['theme_storedb']) - { - $style_row['theme_data'] = str_replace("styles/{$style_row['theme_path']}/theme/", './', $style_row['theme_data']); - $data[] = array( - 'src' => $style_row['theme_data'], - 'prefix' => 'theme/stylesheet.css' - ); - } - unset($items, $theme_cfg); } @@ -2399,7 +2309,7 @@ version = {VERSION} /** * Install/add an element, doing various checks as we go */ - function install_element($mode, &$error, $action, $root_path, &$id, $name, $path, $copyright, $store_db = 0) + function install_element($mode, &$error, $action, $root_path, &$id, $name, $path, $copyright) { global $phpbb_root_path, $db, $user; @@ -2466,7 +2376,7 @@ version = {VERSION} $select_bf = ''; } - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path, {$mode}_storedb $select_bf + $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path, $select_bf FROM $sql_from WHERE {$mode}_name = '" . $db->sql_escape($cfg_data['inherit_from']) . "' AND {$mode}_inherits_id = 0"; @@ -2482,8 +2392,6 @@ version = {VERSION} $inherit_id = $row["{$mode}_id"]; $inherit_path = $row["{$mode}_path"]; $inherit_bf = ($mode === 'template') ? $row["bbcode_bitfield"] : false; - $cfg_data['store_db'] = $row["{$mode}_storedb"]; - $store_db = $row["{$mode}_storedb"]; } } else @@ -2534,8 +2442,6 @@ version = {VERSION} // We are only interested in the theme configuration for now $sql_ary += array( - 'theme_storedb' => $store_db, - 'theme_data' => ($store_db) ? $this->db_theme_data($sql_ary, false, $root_path) : '', 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/$path/theme/stylesheet.css") ); break; @@ -2551,11 +2457,7 @@ version = {VERSION} $db->sql_transaction('commit'); - $log = ($store_db) ? 'LOG_' . $l_type . '_ADD_DB' : 'LOG_' . $l_type . '_ADD_FS'; - add_log('admin', $log, $name); - - // Return store_db in case it had to be altered - return $store_db; + add_log('admin', 'LOG_' . $l_type . '_ADD_FS', $name); } /** -- 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/includes/acp/acp_styles.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index c4c01fbc44..388f340e07 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -1265,7 +1265,7 @@ version = {VERSION} trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); } - $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_mtime'); + $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright'); foreach ($var_ary as $var) { @@ -2439,11 +2439,6 @@ version = {VERSION} break; case 'theme': - // We are only interested in the theme configuration for now - - $sql_ary += array( - 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/$path/theme/stylesheet.css") - ); break; } -- cgit v1.2.1 From 6d24a7191f2f4ba0b4cb8c079dfa0a78c3dc3ef0 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 22:18:06 +0100 Subject: [feature/remove-db-styles] Add error if template/theme file is unwritable. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 54 ++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 29 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 388f340e07..be442c96d9 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -446,6 +446,14 @@ version = {VERSION} trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); } + // Get the filesystem location of the current file + $file = "{$phpbb_root_path}styles/{$template_info['template_path']}/template/$template_file"; + + if ($template_file && ($safe_mode || !is_file($file) || !phpbb_is_writable($file))) + { + trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING); + } + if ($save_changes && !check_form_key('acp_styles')) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); @@ -458,26 +466,16 @@ version = {VERSION} // save changes to the template if the user submitted any if ($save_changes && $template_file) { - // Get the filesystem location of the current file - $file = "{$phpbb_root_path}styles/{$template_info['template_path']}/template/$template_file"; $additional = ''; // Try to write the file - if (!$safe_mode && file_exists($file) && phpbb_is_writable($file)) - { - if (!($fp = @fopen($file, 'wb'))) - { - // File exists and is writeable, but still not able to be written to - trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING); - } - fwrite($fp, $template_data); - fclose($fp); - } - else + if (!($fp = @fopen($file, 'wb'))) { - // @todo - trigger_error('Cannot write template file.', E_USER_ERROR); + // File exists and is writeable, but still not able to be written to + trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING); } + fwrite($fp, $template_data); + fclose($fp); // destroy the cached version of the template (filename without extension) $this->clear_template_cache($template_info, array(substr($template_file, 0, -5))); @@ -752,28 +750,26 @@ version = {VERSION} } $db->sql_freeresult($result); + // Get the filesystem location of the current file + $file = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme/$theme_file"; + + if ($theme_file && ($safe_mode || !is_file($file) || !phpbb_is_writable($file))) + { + trigger_error(sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action), E_USER_WARNING); + } + // save changes to the theme if the user submitted any if ($save_changes) { - // Get the filesystem location of the current file - $file = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme/$theme_file"; $additional = ''; $message = $user->lang['THEME_UPDATED']; - if (!$safe_mode && file_exists($file) && phpbb_is_writable($file)) - { - if (!($fp = @fopen($file, 'wb'))) - { - trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); - } - fwrite($fp, $theme_data); - fclose($fp); - } - else + if (!($fp = @fopen($file, 'wb'))) { - // @todo Proper error - trigger_error('Cannot write to theme file.', E_USER_ERROR); + trigger_error(sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action), E_USER_WARNING); } + fwrite($fp, $theme_data); + fclose($fp); $cache->destroy('sql', STYLES_THEME_TABLE); add_log('admin', 'LOG_THEME_EDIT_FILE', $theme_info['theme_name'], $theme_file); -- cgit v1.2.1 From ee994b2968492e5d4cf461ba2d2fa8c79a22e295 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 23:01:55 +0100 Subject: [feature/remove-db-styles] Rework filesystem permission checks from 6d24a71. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 70 +++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 18 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index be442c96d9..360534d03a 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -447,11 +447,29 @@ version = {VERSION} } // Get the filesystem location of the current file - $file = "{$phpbb_root_path}styles/{$template_info['template_path']}/template/$template_file"; + $template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template"; + $file = "$template_path/$template_file"; - if ($template_file && ($safe_mode || !is_file($file) || !phpbb_is_writable($file))) + if ($template_file) { - trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING); + $l_not_writable = sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action); + + if ($safe_mode) + { + trigger_error($l_not_writable, E_USER_WARNING); + } + + if (file_exists($file) && is_file($file) && is_readable($file)) + { + if (!phpbb_is_writable($file)) + { + trigger_error($l_not_writable, E_USER_WARNING); + } + } + else + { + trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); + } } if ($save_changes && !check_form_key('acp_styles')) @@ -466,13 +484,11 @@ version = {VERSION} // save changes to the template if the user submitted any if ($save_changes && $template_file) { - $additional = ''; - // Try to write the file if (!($fp = @fopen($file, 'wb'))) { // File exists and is writeable, but still not able to be written to - trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($l_not_writable, E_USER_WARNING); } fwrite($fp, $template_data); fclose($fp); @@ -483,18 +499,19 @@ version = {VERSION} $cache->destroy('sql', STYLES_TABLE); add_log('admin', 'LOG_TEMPLATE_EDIT', $template_info['template_name'], $template_file); - trigger_error($user->lang['TEMPLATE_FILE_UPDATED'] . $additional . adm_back_link($this->u_action . "&action=edit&id=$template_id&text_rows=$text_rows&template_file=$template_file")); + trigger_error($user->lang['TEMPLATE_FILE_UPDATED'] . adm_back_link($this->u_action . "&action=edit&id=$template_id&text_rows=$text_rows&template_file=$template_file")); } // Generate a category array containing template filenames - $template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template"; $filelist = filelist($template_path, '', 'html'); $filelist[''] = array_diff($filelist[''], array('bbcode.html')); if ($template_file) { - if (!file_exists($template_path . "/$template_file") || !($template_data = file_get_contents($template_path . "/$template_file"))) + $template_data = file_get_contents($file); + + if (!$template_data) { trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); } @@ -751,22 +768,39 @@ version = {VERSION} $db->sql_freeresult($result); // Get the filesystem location of the current file - $file = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme/$theme_file"; + $theme_path = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme"; + $file = "$theme_path/$theme_file"; - if ($theme_file && ($safe_mode || !is_file($file) || !phpbb_is_writable($file))) + if ($theme_file) { - trigger_error(sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action), E_USER_WARNING); + $l_not_writable = sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action); + + if ($safe_mode) + { + trigger_error($l_not_writable, E_USER_WARNING); + } + + if (file_exists($file) && is_file($file) && is_readable($file)) + { + if (!phpbb_is_writable($file)) + { + trigger_error($l_not_writable, E_USER_WARNING); + } + } + else + { + trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); + } } // save changes to the theme if the user submitted any - if ($save_changes) + if ($save_changes && $theme_file) { - $additional = ''; $message = $user->lang['THEME_UPDATED']; if (!($fp = @fopen($file, 'wb'))) { - trigger_error(sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($l_not_writable, E_USER_WARNING); } fwrite($fp, $theme_data); fclose($fp); @@ -778,13 +812,13 @@ version = {VERSION} } // Generate a category array containing theme filenames - $theme_path = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme"; - $filelist = filelist($theme_path, '', 'css'); if ($theme_file) { - if (!file_exists($theme_path . "/$theme_file") || !($theme_data = file_get_contents($theme_path . "/$theme_file"))) + $theme_data = file_get_contents($file); + + if (!$theme_data) { trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); } -- cgit v1.2.1 From 7b7a56dc4a5f70f8e7ced66fef210e9591bbd929 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 23:15:30 +0100 Subject: [feature/remove-db-styles] Remove forgotten template variables. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 6 ------ 1 file changed, 6 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 360534d03a..fc9acbbcb8 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -1706,8 +1706,6 @@ version = {VERSION} 'L_TITLE' => $user->lang[$this->page_title], 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], 'L_NAME' => $user->lang[$l_type . '_NAME'], - 'L_LOCATION' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION'] : '', - 'L_LOCATION_EXPLAIN' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION_EXPLAIN'] : '', 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', 'NAME' => $style_row[$mode . '_name'], @@ -2024,8 +2022,6 @@ version = {VERSION} 'L_TITLE' => $user->lang[$this->page_title], 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], 'L_NAME' => $user->lang[$l_type . '_NAME'], - 'L_LOCATION' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION'] : '', - 'L_LOCATION_EXPLAIN' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION_EXPLAIN'] : '', 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', 'NAME' => $style_row[$mode . '_name'], @@ -2167,8 +2163,6 @@ version = {VERSION} 'L_TITLE' => $user->lang[$this->page_title], 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], 'L_NAME' => $user->lang[$l_type . '_NAME'], - 'L_LOCATION' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION'] : '', - 'L_LOCATION_EXPLAIN' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION_EXPLAIN'] : '', 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', 'NAME' => $style_row[$mode . '_name'], -- cgit v1.2.1 From cd4958f72c249b9254f7038432cbe7a390dd93bf Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 15 Dec 2011 14:44:09 +0200 Subject: [ticket/10507] Sort styles in acp Sort styles by name in admin control panel PHPBB3-10507 --- phpBB/includes/acp/acp_styles.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 3bc8c86500..38f4c57bd8 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -540,6 +540,7 @@ parse_css_file = {PARSE_CSS_FILE} global $user, $template, $db, $config, $phpbb_root_path, $phpEx; $sql_from = ''; + $sql_sort = 'LOWER(' . $mode . '_name)'; $style_count = array(); switch ($mode) @@ -571,6 +572,9 @@ parse_css_file = {PARSE_CSS_FILE} case 'imageset': $sql_from = STYLES_IMAGESET_TABLE; break; + + default: + trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); } $l_prefix = strtoupper($mode); @@ -594,7 +598,8 @@ parse_css_file = {PARSE_CSS_FILE} ); $sql = "SELECT * - FROM $sql_from"; + FROM $sql_from + ORDER BY $sql_sort ASC"; $result = $db->sql_query($sql); $installed = array(); -- cgit v1.2.1 From a3e8d3b00b4f43be8dd0a4c109eacb51677e53e2 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Dec 2011 13:22:04 +0000 Subject: [ticket/10463] removed extra comma in malformed query in acp_styles.php PHPBB3-10463 --- phpBB/includes/acp/acp_styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index fc9acbbcb8..c480021507 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -2400,7 +2400,7 @@ version = {VERSION} $select_bf = ''; } - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path, $select_bf + $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path $select_bf FROM $sql_from WHERE {$mode}_name = '" . $db->sql_escape($cfg_data['inherit_from']) . "' AND {$mode}_inherits_id = 0"; -- cgit v1.2.1 From 0cfa843677eaac952df910c19df345452680d2ce Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Dec 2011 23:17:16 +0100 Subject: [ticket/10531] Disallow deleting of the last style Regression from PHPBB3-9675 commit 0e02f5cb0b7f615f1eadd6606a89bfd1b28f0d0d PHPBB3-9675 PHPBB3-10531 --- phpBB/includes/acp/acp_styles.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 3bc8c86500..5300265686 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -1634,6 +1634,13 @@ parse_css_file = {PARSE_CSS_FILE} trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); } + $s_only_component = $this->display_component_options($mode, $style_row[$mode . '_id'], $style_row); + + if ($s_only_component) + { + trigger_error($user->lang['ONLY_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); + } + if ($update) { if ($mode == 'style') @@ -1678,8 +1685,6 @@ parse_css_file = {PARSE_CSS_FILE} trigger_error($user->lang[$message] . adm_back_link($this->u_action)); } - $this->display_component_options($mode, $style_row[$mode . '_id'], $style_row); - $this->page_title = 'DELETE_' . $l_prefix; $template->assign_vars(array( @@ -1765,11 +1770,14 @@ parse_css_file = {PARSE_CSS_FILE} /** * Display the options which can be used to replace a style/template/theme/imageset + * + * @return boolean Returns true if the component is the only component and can not be deleted. */ function display_component_options($component, $component_id, $style_row = false, $style_id = false) { global $db, $template, $user; + $is_only_component = true; $component_in_use = array(); if ($component != 'style') { @@ -1801,6 +1809,9 @@ parse_css_file = {PARSE_CSS_FILE} $s_options = ''; if (($component != 'style') && empty($component_in_use)) { + // If it is not in use, there must be another component + $is_only_component = false; + $sql = "SELECT {$component}_id, {$component}_name FROM $sql_from WHERE {$component}_id = {$component_id}"; @@ -1824,6 +1835,7 @@ parse_css_file = {PARSE_CSS_FILE} { if ($row[$component . '_id'] != $component_id) { + $is_only_component = false; $s_options .= ''; } else if ($component != 'style') @@ -1851,6 +1863,8 @@ parse_css_file = {PARSE_CSS_FILE} } } } + + return $is_only_component; } /** -- cgit v1.2.1 From 7a04c9048c110f0bd21ea3e9e869e17b408d640e Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 31 Dec 2011 13:32:52 +0000 Subject: [ticket/9916] Updating header license and removing Version $Id$ PHPBB3-9916 --- phpBB/includes/acp/acp_styles.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index b31d7763aa..a38254838c 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -2,9 +2,8 @@ /** * * @package acp -* @version $Id$ * @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From 656a8ece6f2d52d35dfecb4a27c3709379583f48 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 31 Dec 2011 13:32:52 +0000 Subject: [ticket/9916] Updating header license and removing Version $Id$ PHPBB3-9916 --- phpBB/includes/acp/acp_styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 4f6b22fa14..f8a3b8e47e 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -61,7 +61,7 @@ class acp_styles # # @package phpBB3 # @copyright (c) 2005 phpBB Group -# @license http://opensource.org/licenses/gpl-license.php GNU Public License +# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 # # # At the left is the name, please do not change this -- cgit v1.2.1 From 23363efaaacd2bec39a51c27db51a2777e7a4c21 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Mon, 2 Jan 2012 21:07:40 +0200 Subject: [ticket/10563] Show deactivated styles below active styles in acp Separates active and deactivated styles in styles list in acp PHPBB3-10563 --- phpBB/includes/acp/acp_styles.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index e25061d6f0..5a7902755e 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -547,6 +547,7 @@ parse_css_file = {PARSE_CSS_FILE} { case 'style': $sql_from = STYLES_TABLE; + $sql_sort = 'style_active DESC, ' . $sql_sort; $sql = 'SELECT user_style, COUNT(user_style) AS style_count FROM ' . USERS_TABLE . ' @@ -635,6 +636,8 @@ parse_css_file = {PARSE_CSS_FILE} 'NAME' => $row[$mode . '_name'], 'STYLE_COUNT' => ($mode == 'style' && isset($style_count[$row['style_id']])) ? $style_count[$row['style_id']] : 0, + + 'S_INACTIVE' => ($mode == 'style' && !$row['style_active']) ? true : false, ) ); } -- cgit v1.2.1 From 326ff46ef7812f9f725e680e5202364c6b25bb4b Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Fri, 3 Feb 2012 16:19:42 +0200 Subject: [ticket/10616] Add template inheritance to exported template Add template inheritance when exporting template.cfg PHPBB3-10616 --- phpBB/includes/acp/acp_styles.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 5a7902755e..d7b0484af8 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -99,11 +99,11 @@ parse_css_file = {PARSE_CSS_FILE} $this->template_cfg .= ' # Some configuration options -# -# You can use this function to inherit templates from another template. -# The template of the given name has to be installed. -# Templates cannot inherit from inheriting templates. -#'; +# Template inheritance +# See http://blog.phpbb.com/2008/07/31/templating-just-got-easier/ +# Set value to empty or this template name to ignore template inheritance. +inherit_from = {INHERIT_FROM} +'; $this->imageset_keys = array( 'logos' => array( @@ -2047,9 +2047,7 @@ parse_css_file = {PARSE_CSS_FILE} // Export template core code if ($mode == 'template' || $inc_template) { - $template_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['template_name'], $style_row['template_copyright'], $config['version']), $this->template_cfg); - - $use_template_name = ''; + $use_template_name = $style_row['template_name']; // Add the inherit from variable, depending on it's use... if ($style_row['template_inherits_id']) @@ -2063,7 +2061,8 @@ parse_css_file = {PARSE_CSS_FILE} $db->sql_freeresult($result); } - $template_cfg .= ($use_template_name) ? "\ninherit_from = $use_template_name" : "\n#inherit_from = "; + $template_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}', '{INHERIT_FROM}'), array($mode, $style_row['template_name'], $style_row['template_copyright'], $config['version'], $use_template_name), $this->template_cfg); + $template_cfg .= "\n\nbbcode_bitfield = {$style_row['bbcode_bitfield']}"; $data[] = array( -- cgit v1.2.1 From e35a20f957342a320a7c11b0cee1b94025848813 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 14 Mar 2012 23:47:57 +0200 Subject: [feature/merging-style-components] New acp_styles New acp_styles, completely rewritten PHPBB3-10632 --- phpBB/includes/acp/acp_styles.php | 3295 +++++++++++-------------------------- 1 file changed, 999 insertions(+), 2296 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 7b449d3b35..acd010b77e 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -21,2588 +21,1291 @@ if (!defined('IN_PHPBB')) class acp_styles { var $u_action; + var $u_base_action; + var $s_hidden_fields; + var $mode; + var $styles_path; + var $styles_path_absolute = 'styles'; - var $style_cfg; - var $template_cfg; - var $theme_cfg; - - function main($id, $mode) - { - global $db, $user, $auth, $template, $cache; - global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; - - // Hardcoded template bitfield to add for new templates - $bitfield = new bitfield(); - $bitfield->set(0); - $bitfield->set(1); - $bitfield->set(2); - $bitfield->set(3); - $bitfield->set(4); - $bitfield->set(8); - $bitfield->set(9); - $bitfield->set(11); - $bitfield->set(12); - $this->template_bitfield = $bitfield->get_base64(); - unset($bitfield); - - $user->add_lang('acp/styles'); - - $this->tpl_name = 'acp_styles'; - $this->page_title = 'ACP_CAT_STYLES'; - - $action = request_var('action', ''); - $action = (isset($_POST['add'])) ? 'add' : $action; - $style_id = request_var('id', 0); - - // Fill the configuration variables - $this->style_cfg = $this->template_cfg = $this->theme_cfg = ' -# -# phpBB {MODE} configuration file -# -# @package phpBB3 -# @copyright (c) 2005 phpBB Group -# @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 -# -# -# At the left is the name, please do not change this -# At the right the value is entered -# For on/off options the valid values are on, off, 1, 0, true and false -# -# Values get trimmed, if you want to add a space in front or at the end of -# the value, then enclose the value with single or double quotes. -# Single and double quotes do not need to be escaped. -# -# - -# General Information about this {MODE} -name = {NAME} -copyright = {COPYRIGHT} -version = {VERSION} -'; - - $this->template_cfg .= ' -# Some configuration options - -# Template inheritance -# See http://blog.phpbb.com/2008/07/31/templating-just-got-easier/ -# Set value to empty or this template name to ignore template inheritance. -inherit_from = {INHERIT_FROM} -'; - - // Execute overall actions - switch ($action) - { - case 'delete': - if ($style_id) - { - $this->remove($mode, $style_id); - return; - } - break; - - case 'export': - if ($style_id) - { - $this->export($mode, $style_id); - return; - } - break; - - case 'install': - $this->install($mode); - return; - break; - - case 'add': - $this->add($mode); - return; - break; - - case 'details': - if ($style_id) - { - $this->details($mode, $style_id); - return; - } - break; - - case 'edit': - if ($style_id) - { - switch ($mode) - { - case 'template': - return $this->edit_template($style_id); - case 'theme': - return $this->edit_theme($style_id); - } - } - break; - - case 'cache': - if ($style_id) - { - switch ($mode) - { - case 'template': - return $this->template_cache($style_id); - } - } - break; - } - - switch ($mode) - { - case 'style': - - switch ($action) - { - case 'activate': - case 'deactivate': - - if ($style_id == $config['default_style']) - { - trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (($action == 'deactivate' && confirm_box(true)) || $action == 'activate') - { - $sql = 'UPDATE ' . STYLES_TABLE . ' - SET style_active = ' . (($action == 'activate') ? 1 : 0) . ' - WHERE style_id = ' . $style_id; - $db->sql_query($sql); - - // Set style to default for any member using deactivated style - if ($action == 'deactivate') - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_style = ' . $config['default_style'] . " - WHERE user_style = $style_id"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET forum_style = 0 - WHERE forum_style = ' . $style_id; - $db->sql_query($sql); - } - } - else if ($action == 'deactivate') - { - $s_hidden_fields = array( - 'i' => $id, - 'mode' => $mode, - 'action' => $action, - 'style_id' => $style_id, - ); - confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields)); - } - break; - } - - $this->frontend('style', array('details'), array('export', 'delete')); - break; - - case 'template': - - switch ($action) - { - // Clear cache - case 'refresh': - - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE template_id = $style_id"; - $result = $db->sql_query($sql); - $template_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$template_row) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if (confirm_box(true)) - { - $this->clear_template_cache($template_row); - - trigger_error($user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action)); - } - else - { - confirm_box(false, $user->lang['CONFIRM_TEMPLATE_CLEAR_CACHE'], build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'action' => $action, - 'id' => $style_id - ))); - } - - break; - } - - $this->frontend('template', array('edit', 'cache', 'details'), array('refresh', 'export', 'delete')); - break; - - case 'theme': - $this->frontend('theme', array('edit', 'details'), array('export', 'delete')); - break; - } - } - - /** - * Build Frontend with supplied options - */ - function frontend($mode, $options, $actions) - { - global $user, $template, $db, $config, $phpbb_root_path, $phpEx; - - $sql_from = ''; - $sql_sort = 'LOWER(' . $mode . '_name)'; - $style_count = array(); - - switch ($mode) - { - case 'style': - $sql_from = STYLES_TABLE; - $sql_sort = 'style_active DESC, ' . $sql_sort; - - $sql = 'SELECT user_style, COUNT(user_style) AS style_count - FROM ' . USERS_TABLE . ' - GROUP BY user_style'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $style_count[$row['user_style']] = $row['style_count']; - } - $db->sql_freeresult($result); - - break; - - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - - default: - trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $l_prefix = strtoupper($mode); - - $this->page_title = 'ACP_' . $l_prefix . 'S'; - - $template->assign_vars(array( - 'S_FRONTEND' => true, - 'S_STYLE' => ($mode == 'style') ? true : false, - - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_prefix . '_NAME'], - 'L_INSTALLED' => $user->lang['INSTALLED_' . $l_prefix], - 'L_UNINSTALLED' => $user->lang['UNINSTALLED_' . $l_prefix], - 'L_NO_UNINSTALLED' => $user->lang['NO_UNINSTALLED_' . $l_prefix], - 'L_CREATE' => $user->lang['CREATE_' . $l_prefix], - - 'U_ACTION' => $this->u_action, - ) - ); - - $sql = "SELECT * - FROM $sql_from - ORDER BY $sql_sort ASC"; - $result = $db->sql_query($sql); - - $installed = array(); - - $basis_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - $installed[] = $row[$mode . '_name']; - $basis_options .= ''; - - $stylevis = ($mode == 'style' && !$row['style_active']) ? 'activate' : 'deactivate'; - - $s_options = array(); - foreach ($options as $option) - { - $s_options[] = '' . $user->lang[strtoupper($option)] . ''; - } - - $s_actions = array(); - foreach ($actions as $option) - { - $s_actions[] = '' . $user->lang[strtoupper($option)] . ''; - } - - $template->assign_block_vars('installed', array( - 'S_DEFAULT_STYLE' => ($mode == 'style' && $row['style_id'] == $config['default_style']) ? true : false, - 'U_EDIT' => $this->u_action . '&action=' . (($mode == 'style') ? 'details' : 'edit') . '&id=' . $row[$mode . '_id'], - 'U_STYLE_ACT_DEACT' => $this->u_action . '&action=' . $stylevis . '&id=' . $row[$mode . '_id'], - 'L_STYLE_ACT_DEACT' => $user->lang['STYLE_' . strtoupper($stylevis)], - 'S_OPTIONS' => implode(' | ', $s_options), - 'S_ACTIONS' => implode(' | ', $s_actions), - 'U_PREVIEW' => ($mode == 'style') ? append_sid("{$phpbb_root_path}index.$phpEx", "$mode=" . $row[$mode . '_id']) : '', - - 'NAME' => $row[$mode . '_name'], - 'STYLE_COUNT' => ($mode == 'style' && isset($style_count[$row['style_id']])) ? $style_count[$row['style_id']] : 0, - - 'S_INACTIVE' => ($mode == 'style' && !$row['style_active']) ? true : false, - ) - ); - } - $db->sql_freeresult($result); - - // Grab uninstalled items - $new_ary = $cfg = array(); - - $dp = @opendir("{$phpbb_root_path}styles"); - - if ($dp) - { - while (($file = readdir($dp)) !== false) - { - if ($file[0] == '.' || !is_dir($phpbb_root_path . 'styles/' . $file)) - { - continue; - } - - $subpath = ($mode != 'style') ? "$mode/" : ''; - if (file_exists("{$phpbb_root_path}styles/$file/$subpath$mode.cfg")) - { - if ($cfg = file("{$phpbb_root_path}styles/$file/$subpath$mode.cfg")) - { - $items = parse_cfg_file('', $cfg); - $name = (isset($items['name'])) ? trim($items['name']) : false; - - if ($name && !in_array($name, $installed)) - { - $new_ary[] = array( - 'path' => $file, - 'name' => $name, - 'copyright' => $items['copyright'], - ); - } - } - } - } - closedir($dp); - } - - unset($installed); - - if (sizeof($new_ary)) - { - foreach ($new_ary as $cfg) - { - $template->assign_block_vars('uninstalled', array( - 'NAME' => $cfg['name'], - 'COPYRIGHT' => $cfg['copyright'], - 'U_INSTALL' => $this->u_action . '&action=install&path=' . urlencode($cfg['path'])) - ); - } - } - unset($new_ary); - - $template->assign_vars(array( - 'S_BASIS_OPTIONS' => $basis_options) - ); - - } - - /** - * Provides a template editor which allows saving changes to template files on the filesystem or in the database. - * - * @param int $template_id specifies which template set is being edited - */ - function edit_template($template_id) - { - global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template, $safe_mode; - - if (defined('PHPBB_DISABLE_ACP_EDITOR')) - { - trigger_error($user->lang['EDITOR_DISABLED'] . adm_back_link($this->u_action)); - } - - $this->page_title = 'EDIT_TEMPLATE'; - - $filelist = $filelist_cats = array(); - - $template_data = utf8_normalize_nfc(request_var('template_data', '', true)); - $template_data = htmlspecialchars_decode($template_data); - $template_file = utf8_normalize_nfc(request_var('template_file', '', true)); - $text_rows = max(5, min(999, request_var('text_rows', 20))); - $save_changes = (isset($_POST['save'])) ? true : false; - - // make sure template_file path doesn't go upwards - $template_file = preg_replace('#\.{2,}#', '.', $template_file); - - // Retrieve some information about the template - $sql = 'SELECT template_path, template_name - FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE template_id = $template_id"; - $result = $db->sql_query($sql); - $template_info = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$template_info) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Get the filesystem location of the current file - $template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template"; - $file = "$template_path/$template_file"; - - if ($template_file) - { - $l_not_writable = sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action); - - if ($safe_mode) - { - trigger_error($l_not_writable, E_USER_WARNING); - } - - if (file_exists($file) && is_file($file) && is_readable($file)) - { - if (!phpbb_is_writable($file)) - { - trigger_error($l_not_writable, E_USER_WARNING); - } - } - else - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - - if ($save_changes && !check_form_key('acp_styles')) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); - } - else if (!$save_changes) - { - add_form_key('acp_styles'); - } - - // save changes to the template if the user submitted any - if ($save_changes && $template_file) - { - // Try to write the file - if (!($fp = @fopen($file, 'wb'))) - { - // File exists and is writeable, but still not able to be written to - trigger_error($l_not_writable, E_USER_WARNING); - } - fwrite($fp, $template_data); - fclose($fp); - - // destroy the cached version of the template (filename without extension) - $this->clear_template_cache($template_info, array(substr($template_file, 0, -5))); - - $cache->destroy('sql', STYLES_TABLE); - - add_log('admin', 'LOG_TEMPLATE_EDIT', $template_info['template_name'], $template_file); - trigger_error($user->lang['TEMPLATE_FILE_UPDATED'] . adm_back_link($this->u_action . "&action=edit&id=$template_id&text_rows=$text_rows&template_file=$template_file")); - } - - // Generate a category array containing template filenames - - $filelist = filelist($template_path, '', 'html'); - $filelist[''] = array_diff($filelist[''], array('bbcode.html')); - - if ($template_file) - { - $template_data = file_get_contents($file); - - if (!$template_data) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - - if (empty($filelist[''])) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Now create the categories - $filelist_cats[''] = array(); - foreach ($filelist as $pathfile => $file_ary) - { - // Use the directory name as category name - if (!empty($pathfile)) - { - $filelist_cats[$pathfile] = array(); - foreach ($file_ary as $file) - { - $filelist_cats[$pathfile][$pathfile . $file] = $file; - } - } - // or if it's in the main category use the word before the first underscore to group files - else - { - $cats = array(); - foreach ($file_ary as $file) - { - $cats[] = substr($file, 0, strpos($file, '_')); - $filelist_cats[substr($file, 0, strpos($file, '_'))][$file] = $file; - } - - $cats = array_values(array_unique($cats)); - - // we don't need any single element categories so put them into the misc '' category - for ($i = 0, $n = sizeof($cats); $i < $n; $i++) - { - if (sizeof($filelist_cats[$cats[$i]]) == 1 && $cats[$i] !== '') - { - $filelist_cats[''][key($filelist_cats[$cats[$i]])] = current($filelist_cats[$cats[$i]]); - unset($filelist_cats[$cats[$i]]); - } - } - unset($cats); - } - } - unset($filelist); - - // Generate list of categorised template files - $tpl_options = ''; - ksort($filelist_cats); - foreach ($filelist_cats as $category => $tpl_ary) - { - ksort($tpl_ary); - - if (!empty($category)) - { - $tpl_options .= ''; - } - - foreach ($tpl_ary as $filename => $file) - { - $selected = ($template_file == $filename) ? ' selected="selected"' : ''; - $tpl_options .= ''; - } - } - - $template->assign_vars(array( - 'S_EDIT_TEMPLATE' => true, - 'S_HIDDEN_FIELDS' => build_hidden_fields(array('template_file' => $template_file)), - 'S_TEMPLATES' => $tpl_options, - - 'U_ACTION' => $this->u_action . "&action=edit&id=$template_id&text_rows=$text_rows", - 'U_BACK' => $this->u_action, - - 'L_EDIT' => $user->lang['EDIT_TEMPLATE'], - 'L_EDIT_EXPLAIN' => $user->lang['EDIT_TEMPLATE_EXPLAIN'], - 'L_EDITOR' => $user->lang['TEMPLATE_EDITOR'], - 'L_EDITOR_HEIGHT' => $user->lang['TEMPLATE_EDITOR_HEIGHT'], - 'L_FILE' => $user->lang['TEMPLATE_FILE'], - 'L_SELECT' => $user->lang['SELECT_TEMPLATE'], - 'L_SELECTED' => $user->lang['SELECTED_TEMPLATE'], - 'L_SELECTED_FILE' => $user->lang['SELECTED_TEMPLATE_FILE'], - - 'SELECTED_TEMPLATE' => $template_info['template_name'], - 'TEMPLATE_FILE' => $template_file, - 'TEMPLATE_DATA' => utf8_htmlspecialchars($template_data), - 'TEXT_ROWS' => $text_rows) - ); - } - - /** - * Allows the admin to view cached versions of template files and clear single template cache files - * - * @param int $template_id specifies which template's cache is shown - */ - function template_cache($template_id) - { - global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template; - - $source = str_replace('/', '.', request_var('source', '')); - $file_ary = array_diff(request_var('delete', array('')), array('')); - $submit = isset($_POST['submit']) ? true : false; - - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE template_id = $template_id"; - $result = $db->sql_query($sql); - $template_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$template_row) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // User wants to delete one or more files ... - if ($submit && $file_ary) - { - $this->clear_template_cache($template_row, $file_ary); - trigger_error($user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action . "&action=cache&id=$template_id")); - } - - $cache_prefix = 'tpl_' . str_replace('_', '-', $template_row['template_path']); - - // Someone wants to see the cached source ... so we'll highlight it, - // add line numbers and indent it appropriately. This could be nasty - // on larger source files ... - if ($source && file_exists("{$phpbb_root_path}cache/{$cache_prefix}_$source.html.$phpEx")) - { - adm_page_header($user->lang['TEMPLATE_CACHE']); - - $template->set_filenames(array( - 'body' => 'viewsource.html') - ); - - $template->assign_vars(array( - 'FILENAME' => str_replace('.', '/', $source) . '.html') - ); - - $code = str_replace(array("\r\n", "\r"), array("\n", "\n"), file_get_contents("{$phpbb_root_path}cache/{$cache_prefix}_$source.html.$phpEx")); - - $conf = array('highlight.bg', 'highlight.comment', 'highlight.default', 'highlight.html', 'highlight.keyword', 'highlight.string'); - foreach ($conf as $ini_var) - { - @ini_set($ini_var, str_replace('highlight.', 'syntax', $ini_var)); - } - - $marker = 'MARKER' . time(); - $code = highlight_string(str_replace("\n", $marker, $code), true); - $code = str_replace($marker, "\n", $code); - $str_from = array('', '', '','[', ']', '.', ':'); - $str_to = array('', '', '', '[', ']', '.', ':'); - - $code = str_replace($str_from, $str_to, $code); - $code = preg_replace('#^()\n?(.*?)\n?()$#ism', '$1$2$3', $code); - $code = substr($code, strlen('')); - $code = substr($code, 0, -1 * strlen('')); - $code = explode("\n", $code); - - foreach ($code as $key => $line) - { - $template->assign_block_vars('source', array( - 'LINENUM' => $key + 1, - 'LINE' => preg_replace('#([^ ;]) ([^ &])#', '$1 $2', $line)) - ); - unset($code[$key]); - } - - adm_page_footer(); - } - - // Get a list of cached template files and then retrieve additional information about them - $file_ary = $this->template_cache_filelist($template_row['template_path']); - - foreach ($file_ary as $file) - { - $file = str_replace('/', '.', $file); - - // perform some dirty guessing to get the path right. - // We assume that three dots in a row were '../' - $tpl_file = str_replace('.', '/', $file); - $tpl_file = str_replace('///', '../', $tpl_file); - - $filename = "{$cache_prefix}_$file.html.$phpEx"; - - if (!file_exists("{$phpbb_root_path}cache/$filename")) - { - continue; - } - - $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_path']}/template/$tpl_file.html"; - $inherited = false; - - if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id'] && !file_exists($file_tpl)) - { - $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/$tpl_file.html"; - $inherited = true; - } - - $template->assign_block_vars('file', array( - 'U_VIEWSOURCE' => $this->u_action . "&action=cache&id=$template_id&source=$file", - - 'CACHED' => $user->format_date(filemtime("{$phpbb_root_path}cache/$filename")), - 'FILENAME' => $file, - 'FILENAME_PATH' => $file_tpl, - 'FILESIZE' => get_formatted_filesize(filesize("{$phpbb_root_path}cache/$filename")), - 'MODIFIED' => $user->format_date(filemtime($file_tpl)), - )); - } - - $template->assign_vars(array( - 'S_CACHE' => true, - 'S_TEMPLATE' => true, - - 'U_ACTION' => $this->u_action . "&action=cache&id=$template_id", - 'U_BACK' => $this->u_action) - ); - } - - /** - * Provides a css editor and a basic easier to use stylesheet editing tool for less experienced (or lazy) users - * - * @param int $theme_id specifies which theme is being edited - */ - function edit_theme($theme_id) - { - global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template, $safe_mode; - - $this->page_title = 'EDIT_THEME'; - - $filelist = $filelist_cats = array(); - - $theme_data = utf8_normalize_nfc(request_var('template_data', '', true)); - $theme_data = htmlspecialchars_decode($theme_data); - $theme_file = utf8_normalize_nfc(request_var('template_file', '', true)); - $text_rows = max(5, min(999, request_var('text_rows', 20))); - $save_changes = (isset($_POST['save'])) ? true : false; - - // make sure theme_file path doesn't go upwards - $theme_file = str_replace('..', '.', $theme_file); - - // Retrieve some information about the theme - $sql = 'SELECT theme_path, theme_name - FROM ' . STYLES_THEME_TABLE . " - WHERE theme_id = $theme_id"; - $result = $db->sql_query($sql); - - if (!($theme_info = $db->sql_fetchrow($result))) - { - trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); - } - $db->sql_freeresult($result); - - // Get the filesystem location of the current file - $theme_path = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme"; - $file = "$theme_path/$theme_file"; - - if ($theme_file) - { - $l_not_writable = sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action); - - if ($safe_mode) - { - trigger_error($l_not_writable, E_USER_WARNING); - } - - if (file_exists($file) && is_file($file) && is_readable($file)) - { - if (!phpbb_is_writable($file)) - { - trigger_error($l_not_writable, E_USER_WARNING); - } - } - else - { - trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - - // save changes to the theme if the user submitted any - if ($save_changes && $theme_file) - { - $message = $user->lang['THEME_UPDATED']; - - if (!($fp = @fopen($file, 'wb'))) - { - trigger_error($l_not_writable, E_USER_WARNING); - } - fwrite($fp, $theme_data); - fclose($fp); - - $cache->destroy('sql', STYLES_THEME_TABLE); - add_log('admin', 'LOG_THEME_EDIT_FILE', $theme_info['theme_name'], $theme_file); - - trigger_error($message . adm_back_link($this->u_action . "&action=edit&id=$theme_id&template_file=$theme_file&text_rows=$text_rows")); - } - - // Generate a category array containing theme filenames - $filelist = filelist($theme_path, '', 'css'); - - if ($theme_file) - { - $theme_data = file_get_contents($file); - - if (!$theme_data) - { - trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - - // Now create the categories - $filelist_cats[''] = array(); - foreach ($filelist as $pathfile => $file_ary) - { - // Use the directory name as category name - if (!empty($pathfile)) - { - $filelist_cats[$pathfile] = array(); - foreach ($file_ary as $file) - { - $filelist_cats[$pathfile][$pathfile . $file] = $file; - } - } - // or if it's in the main category use the word before the first underscore to group files - else - { - $cats = array(); - foreach ($file_ary as $file) - { - $cats[] = substr($file, 0, strpos($file, '_')); - $filelist_cats[substr($file, 0, strpos($file, '_'))][$file] = $file; - } - - $cats = array_values(array_unique($cats)); - - // we don't need any single element categories so put them into the misc '' category - for ($i = 0, $n = sizeof($cats); $i < $n; $i++) - { - if (sizeof($filelist_cats[$cats[$i]]) == 1 && $cats[$i] !== '') - { - $filelist_cats[''][key($filelist_cats[$cats[$i]])] = current($filelist_cats[$cats[$i]]); - unset($filelist_cats[$cats[$i]]); - } - } - unset($cats); - } - } - unset($filelist); - - // Generate list of categorised theme files - $tpl_options = ''; - ksort($filelist_cats); - foreach ($filelist_cats as $category => $tpl_ary) - { - ksort($tpl_ary); - - if (!empty($category)) - { - $tpl_options .= ''; - } - - foreach ($tpl_ary as $filename => $file) - { - $selected = ($theme_file == $filename) ? ' selected="selected"' : ''; - $tpl_options .= ''; - } - } + function main($id, $mode) + { + global $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request; - $template->assign_vars(array( - 'S_EDIT_THEME' => true, - 'S_HIDDEN_FIELDS' => build_hidden_fields(array('template_file' => $theme_file)), - 'S_TEMPLATES' => $tpl_options, - - 'U_ACTION' => $this->u_action . "&action=edit&id=$theme_id&text_rows=$text_rows", - 'U_BACK' => $this->u_action, - - 'L_EDIT' => $user->lang['EDIT_THEME'], - 'L_EDIT_EXPLAIN' => $user->lang['EDIT_THEME_EXPLAIN'], - 'L_EDITOR' => $user->lang['THEME_EDITOR'], - 'L_EDITOR_HEIGHT' => $user->lang['THEME_EDITOR_HEIGHT'], - 'L_FILE' => $user->lang['THEME_FILE'], - 'L_SELECT' => $user->lang['SELECT_THEME'], - 'L_SELECTED' => $user->lang['SELECTED_THEME'], - 'L_SELECTED_FILE' => $user->lang['SELECTED_THEME_FILE'], - - 'SELECTED_TEMPLATE' => $theme_info['theme_name'], - 'TEMPLATE_FILE' => $theme_file, - 'TEMPLATE_DATA' => utf8_htmlspecialchars($theme_data), - 'TEXT_ROWS' => $text_rows, - )); - } + $this->styles_path = $phpbb_root_path . $this->styles_path_absolute . '/'; - /** - * Remove style/template/theme - */ - function remove($mode, $style_id) - { - global $db, $template, $user, $phpbb_root_path, $cache, $config; + $this->u_base_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$id}"); + $this->s_hidden_fields = array( + 'mode' => $mode, + ); - $new_id = request_var('new_id', 0); - $update = (isset($_POST['update'])) ? true : false; - $sql_where = ''; + $user->add_lang('acp/styles'); - switch ($mode) - { - case 'style': - $sql_from = STYLES_TABLE; - $sql_select = 'style_id, style_name, template_id, theme_id'; - $sql_where = 'AND style_active = 1'; - break; - - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - $sql_select = 'template_id, template_name, template_path'; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - $sql_select = 'theme_id, theme_name, theme_path'; - break; - } + $this->tpl_name = 'acp_styles'; + $this->page_title = 'ACP_CAT_STYLES'; + $this->mode = $mode; - if ($mode === 'template' && ($conflicts = $this->check_inheritance($mode, $style_id))) + $action = $request->variable('action', ''); + $post_actions = array('install', 'activate', 'deactivate', 'delete'); + foreach ($post_actions as $key) { - $l_type = strtoupper($mode); - $msg = $user->lang[$l_type . '_DELETE_DEPENDENT']; - foreach ($conflicts as $id => $values) + if (isset($_POST[$key])) { - $msg .= '
' . $values['template_name']; + $action = $key; } - - trigger_error($msg . adm_back_link($this->u_action), E_USER_WARNING); - } - - $l_prefix = strtoupper($mode); - - $sql = "SELECT $sql_select - FROM $sql_from - WHERE {$mode}_id = $style_id"; - $result = $db->sql_query($sql); - $style_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$style_row) - { - trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); } - - $s_only_component = $this->display_component_options($mode, $style_row[$mode . '_id'], $style_row); - - if ($s_only_component) - { - trigger_error($user->lang['ONLY_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); - } - - if ($update) + if ($action != '') { - if ($mode == 'style') - { - $sql = "DELETE FROM $sql_from - WHERE {$mode}_id = $style_id"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . USERS_TABLE . " - SET user_style = $new_id - WHERE user_style = $style_id"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . FORUMS_TABLE . " - SET forum_style = $new_id - WHERE forum_style = $style_id"; - $db->sql_query($sql); - - if ($style_id == $config['default_style']) - { - set_config('default_style', $new_id); - } - - // Remove the components - $components = array('template', 'theme'); - foreach ($components as $component) - { - $new_id = request_var('new_' . $component . '_id', 0); - $component_id = $style_row[$component . '_id']; - $this->remove_component($component, $component_id, $new_id, $style_id); - } - } - else - { - $this->remove_component($mode, $style_id, $new_id); - } - - $cache->destroy('sql', STYLES_TABLE); - - add_log('admin', 'LOG_' . $l_prefix . '_DELETE', $style_row[$mode . '_name']); - $message = ($mode != 'style') ? $l_prefix . '_DELETED_FS' : $l_prefix . '_DELETED'; - trigger_error($user->lang[$message] . adm_back_link($this->u_action)); + $this->s_hidden_fields['action'] = $action; } - $this->page_title = 'DELETE_' . $l_prefix; - $template->assign_vars(array( - 'S_DELETE' => true, - - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_prefix . '_NAME'], - 'L_REPLACE' => $user->lang['REPLACE_' . $l_prefix], - 'L_REPLACE_EXPLAIN' => $user->lang['REPLACE_' . $l_prefix . '_EXPLAIN'], - - 'U_ACTION' => $this->u_action . "&action=delete&id=$style_id", - 'U_BACK' => $this->u_action, - - 'NAME' => $style_row[$mode . '_name'], + 'U_ACTION' => $this->u_base_action, + 'S_HIDDEN_FIELDS' => build_hidden_fields($this->s_hidden_fields) ) ); - - if ($mode == 'style') + + // Execute actions + switch ($action) { - $template->assign_vars(array( - 'S_DELETE_STYLE' => true, - )); + case 'install': + $this->action_install(); + return; + case 'delete': + $this->action_delete(); + return; + case 'activate': + $this->action_activate(); + return; + case 'deactivate': + $this->action_deactivate(); + return; + case 'details': + $this->action_details(); + return; + default: + $this->frontend(); } } - + /** - * Remove template/theme entry from the database + * Main page */ - function remove_component($component, $component_id, $new_id, $style_id = false) + function frontend() { - global $db; - - if (($new_id == 0) || ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id)))) - { - // We can not delete the template, as the user wants to keep the component or an other template is inheriting from this one. - return; - } - - $component_in_use = array(); - if ($component != 'style') - { - $component_in_use = $this->component_in_use($component, $component_id, $style_id); - } - - if (($new_id == -1) && !empty($component_in_use)) - { - // We can not delete the component, as it is still in use - return; - } - - switch ($component) + // Check mode + switch ($this->mode) { - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; + case 'style': + $this->welcome_message('ACP_STYLES', 'ACP_STYLES_EXPLAIN'); + $this->show_installed(); + return; + case 'install': + $this->welcome_message('INSTALL_STYLES', 'INSTALL_STYLES_EXPLAIN'); + $this->show_available(); + return; + case 'cache': + $this->action_cache(); + return; } - - $sql = "DELETE FROM $sql_from - WHERE {$component}_id = $component_id"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . STYLES_TABLE . " - SET {$component}_id = $new_id - WHERE {$component}_id = $component_id"; - $db->sql_query($sql); + global $user; + trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); } - + /** - * Display the options which can be used to replace a style/template/theme - * - * @return boolean Returns true if the component is the only component and can not be deleted. + * Purge cache */ - function display_component_options($component, $component_id, $style_row = false, $style_id = false) + function action_cache() { - global $db, $template, $user; - - $is_only_component = true; - $component_in_use = array(); - if ($component != 'style') - { - $component_in_use = $this->component_in_use($component, $component_id, $style_id); - } + global $cache, $auth, $user; + + $cache->purge(); - $sql_where = ''; - switch ($component) - { - case 'style': - $sql_from = STYLES_TABLE; - $sql_where = 'WHERE style_active = 1'; - break; - - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - $sql_where = 'WHERE template_inherits_id <> ' . $component_id; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } + // Clear permissions + $auth->acl_clear_prefetch(); + cache_moderators(); - $s_options = ''; - if (($component != 'style') && empty($component_in_use)) - { - // If it is not in use, there must be another component - $is_only_component = false; - - $sql = "SELECT {$component}_id, {$component}_name - FROM $sql_from - WHERE {$component}_id = {$component_id}"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - $s_options .= ''; - $s_options .= ''; - } - else - { - $sql = "SELECT {$component}_id, {$component}_name - FROM $sql_from - $sql_where - ORDER BY {$component}_name ASC"; - $result = $db->sql_query($sql); - - $s_keep_option = $s_options = ''; - while ($row = $db->sql_fetchrow($result)) - { - if ($row[$component . '_id'] != $component_id) - { - $is_only_component = false; - $s_options .= ''; - } - else if ($component != 'style') + add_log('admin', 'LOG_PURGE_CACHE'); + + trigger_error($user->lang['PURGED_CACHE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); + } + + /** + * Install style(s) + */ + function action_install() + { + global $user; + + // Get list of styles to install + $dirs = $this->request_vars('dir', '', true); + + // Get list of styles that can be installed + $styles = $this->find_available(false); + + // Install each style + $messages = array(); + $installed_names = array(); + $installed_dirs = array(); + $last_installed = false; + foreach ($dirs as $dir) + { + $found = false; + foreach ($styles as &$style) + { + // Check if: + // 1. Directory matches directory we are looking for + // 2. Style is not installed yet + // 3. Style with same name or directory hasn't been installed already within this function + if ($style['style_path'] == $dir && empty($style['_installed']) && !in_array($style['style_path'], $installed_dirs) && !in_array($style['style_name'], $installed_names)) { - $s_keep_option = ''; + // Install style + $style['style_active'] = 1; + $style['style_id'] = $this->install_style($style); + $style['_installed'] = true; + $found = true; + $last_installed = $style['style_id']; + $installed_names[] = $style['style_name']; + $installed_dirs[] = $style['style_path']; + $messages[] = sprintf($user->lang['STYLE_INSTALLED'], htmlspecialchars($style['style_name'])); } } - $db->sql_freeresult($result); - $s_options = $s_keep_option . $s_options; + if (!$found) + { + $messages[] = sprintf($user->lang['STYLE_NOT_INSTALLED'], htmlspecialchars($dir)); + } } - - if (!$style_row) + + // Show message + if (!count($messages)) { - $template->assign_var('S_REPLACE_' . strtoupper($component) . '_OPTIONS', $s_options); + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } - else + $message = implode('
', $messages); + if (count($messages) == 1 && $last_installed !== false) { - $template->assign_var('S_REPLACE_OPTIONS', $s_options); - if ($component == 'style') - { - $components = array('template', 'theme'); - foreach ($components as $component) - { - $this->display_component_options($component, $style_row[$component . '_id'], false, $component_id, true); - } - } + $message .= '

' . sprintf($user->lang['STYLE_INSTALLED_EDIT_DETAILS'], $this->u_base_action . '&mode=style&action=details&id=' . $last_installed); } - - return $is_only_component; + $message .= '

' . sprintf($user->lang['STYLE_INSTALLED_RETURN_STYLES'], $this->u_base_action . '&mode=style'); + $message .= '

' . sprintf($user->lang['STYLE_INSTALLED_RETURN_UNINSTALLED'], $this->u_base_action . '&mode=install'); + trigger_error($message, E_USER_NOTICE); } - + /** - * Check whether the component is still used by another style or component + * Confirm styles deletion */ - function component_in_use($component, $component_id, $style_id = false) + function action_delete() { - global $db; - - $component_in_use = array(); - - if ($style_id) - { - $sql = 'SELECT style_id, style_name - FROM ' . STYLES_TABLE . " - WHERE {$component}_id = {$component_id} - AND style_id <> {$style_id} - ORDER BY style_name ASC"; - } - else - { - $sql = 'SELECT style_id, style_name - FROM ' . STYLES_TABLE . " - WHERE {$component}_id = {$component_id} - ORDER BY style_name ASC"; - } - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $component_in_use[] = $row['style_name']; - } - $db->sql_freeresult($result); - - if ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id))) - { - foreach ($conflicts as $temp_id => $conflict_data) - { - $component_in_use[] = $conflict_data['template_name']; - } + global $user, $config, $template, $request; + + // Get list of styles to delete + $ids = $this->request_vars('id', 0, true); + + // Check if confirmation box was submitted + if (confirm_box(true)) + { + // Delete + $this->action_delete_confirmed($ids, $request->variable('confirm_delete_files', false)); + return; } - - return $component_in_use; + + // Confirm box + $s_hidden = build_hidden_fields(array( + 'action' => 'delete', + 'ids' => $ids + )); + $template->assign_var('S_CONFIRM_DELETE', true); + confirm_box(false, $user->lang['CONFIRM_DELETE_STYLES'], $s_hidden, 'acp_styles.html'); + + // Canceled - show styles list + $this->frontend(); } /** - * Export style or style elements + * Delete styles(s) + * + * @param array $ids List of style IDs + * @param bool $delete_files If true, script will attempt to remove files for selected styles */ - function export($mode, $style_id) + function action_delete_confirmed($ids, $delete_files) { - global $db, $template, $user, $phpbb_root_path, $cache, $phpEx, $config; - - $update = (isset($_POST['update'])) ? true : false; - - $inc_template = request_var('inc_template', 0); - $inc_theme = request_var('inc_theme', 0); - $store = request_var('store', 0); - $format = request_var('format', ''); - - $error = array(); - $methods = array('tar'); - - $available_methods = array('tar.gz' => 'zlib', 'tar.bz2' => 'bz2', 'zip' => 'zlib'); - foreach ($available_methods as $type => $module) - { - if (!@extension_loaded($module)) - { - continue; - } - - $methods[] = $type; - } - - if (!in_array($format, $methods)) - { - $format = 'tar'; - } - - switch ($mode) - { - case 'style': - if ($update && ($inc_template + $inc_theme) < 1) - { - $error[] = $user->lang['STYLE_ERR_MORE_ELEMENTS']; - } - - $name = 'style_name'; - - $sql_select = 's.style_id, s.style_name, s.style_copyright'; - $sql_select .= ($inc_template) ? ', t.*' : ', t.template_name'; - $sql_select .= ($inc_theme) ? ', c.*' : ', c.theme_name'; - $sql_from = STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c'; - $sql_where = "s.style_id = $style_id AND t.template_id = s.template_id AND c.theme_id = s.theme_id"; - - $l_prefix = 'STYLE'; - break; - - case 'template': - $name = 'template_name'; + global $db, $user, $cache; - $sql_select = '*'; - $sql_from = STYLES_TEMPLATE_TABLE; - $sql_where = "template_id = $style_id"; + $default = $config['default_style']; + $deleted = array(); + $messages = array(); - $l_prefix = 'TEMPLATE'; - break; - - case 'theme': - $name = 'theme_name'; - - $sql_select = '*'; - $sql_from = STYLES_THEME_TABLE; - $sql_where = "theme_id = $style_id"; - - $l_prefix = 'THEME'; - break; - } - - if ($update && !sizeof($error)) + // Check styles list + foreach ($ids as $id) { - $sql = "SELECT $sql_select - FROM $sql_from - WHERE $sql_where"; - $result = $db->sql_query($sql); - $style_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$style_row) - { - trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright'); - - foreach ($var_ary as $var) - { - if (!isset($style_row[$var])) - { - $style_row[$var] = ''; - } - } - - $files = $data = array(); - - if ($mode == 'style') - { - $style_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['style_name'], $style_row['style_copyright'], $config['version']), $this->style_cfg); - - $style_cfg .= (!$inc_template) ? "\nrequired_template = {$style_row['template_name']}" : ''; - $style_cfg .= (!$inc_theme) ? "\nrequired_theme = {$style_row['theme_name']}" : ''; - - $data[] = array( - 'src' => $style_cfg, - 'prefix' => 'style.cfg' - ); - - unset($style_cfg); - } - - // Export template core code - if ($mode == 'template' || $inc_template) - { - $use_template_name = $style_row['template_name']; - - // Add the inherit from variable, depending on it's use... - if ($style_row['template_inherits_id']) - { - // Get the template name - $sql = 'SELECT template_name - FROM ' . STYLES_TEMPLATE_TABLE . ' - WHERE template_id = ' . (int) $style_row['template_inherits_id']; - $result = $db->sql_query($sql); - $use_template_name = (string) $db->sql_fetchfield('template_name'); - $db->sql_freeresult($result); - } - - $template_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}', '{INHERIT_FROM}'), array($mode, $style_row['template_name'], $style_row['template_copyright'], $config['version'], $use_template_name), $this->template_cfg); - - $template_cfg .= "\n\nbbcode_bitfield = {$style_row['bbcode_bitfield']}"; - - $data[] = array( - 'src' => $template_cfg, - 'prefix' => 'template/template.cfg' - ); - - // This is potentially nasty memory-wise ... - $files[] = array( - 'src' => "styles/{$style_row['template_path']}/template/", - 'prefix-' => "styles/{$style_row['template_path']}/", - 'prefix+' => false, - 'exclude' => 'template.cfg' - ); - unset($template_cfg); - } - - // Export theme core code - if ($mode == 'theme' || $inc_theme) - { - $theme_cfg = str_replace(array('{MODE}', '{NAME}', '{COPYRIGHT}', '{VERSION}'), array($mode, $style_row['theme_name'], $style_row['theme_copyright'], $config['version']), $this->theme_cfg); - - // Read old cfg file - $items = $cache->obtain_cfg_items($style_row); - $items = $items['theme']; - - $files[] = array( - 'src' => "styles/{$style_row['theme_path']}/theme/", - 'prefix-' => "styles/{$style_row['theme_path']}/", - 'prefix+' => false, - 'exclude' => 'theme.cfg', - ); - - $data[] = array( - 'src' => $theme_cfg, - 'prefix' => 'theme/theme.cfg', - ); - - unset($items, $theme_cfg); - } - - switch ($format) + if (!$id) { - case 'tar': - $ext = '.tar'; - break; - - case 'zip': - $ext = '.zip'; - break; - - case 'tar.gz': - $ext = '.tar.gz'; - break; - - case 'tar.bz2': - $ext = '.tar.bz2'; - break; - - default: - $error[] = $user->lang[$l_prefix . '_ERR_ARCHIVE']; + trigger_error($user->lang['INVALID_STYLE_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } - - if (!sizeof($error)) + if ($id == $default) { - include($phpbb_root_path . 'includes/functions_compress.' . $phpEx); - - if ($mode == 'style') - { - $path = preg_replace('#[^\w-]+#', '_', $style_row['style_name']); - } - else - { - $path = $style_row[$mode . '_path']; - } - - if ($format == 'zip') - { - $compress = new compress_zip('w', $phpbb_root_path . "store/$path$ext"); - } - else - { - $compress = new compress_tar('w', $phpbb_root_path . "store/$path$ext", $ext); - } - - if (sizeof($files)) - { - foreach ($files as $file_ary) - { - $compress->add_file($file_ary['src'], $file_ary['prefix-'], $file_ary['prefix+'], $file_ary['exclude']); - } - } - - if (sizeof($data)) - { - foreach ($data as $data_ary) - { - $compress->add_data($data_ary['src'], $data_ary['prefix']); - } - } - - $compress->close(); - - add_log('admin', 'LOG_' . $l_prefix . '_EXPORT', $style_row[$mode . '_name']); - - if (!$store) - { - $compress->download($path); - @unlink("{$phpbb_root_path}store/$path$ext"); - exit; - } - - trigger_error(sprintf($user->lang[$l_prefix . '_EXPORTED'], "store/$path$ext") . adm_back_link($this->u_action)); + trigger_error($user->lang['DELETE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); } + $deleted[$id] = false; } - $sql = "SELECT {$mode}_id, {$mode}_name - FROM " . (($mode == 'style') ? STYLES_TABLE : $sql_from) . " - WHERE {$mode}_id = $style_id"; + // Order by reversed style_id, so parent styles would be removed after child styles + // This way parent and child styles can be removed in same function call + $sql = 'SELECT * + FROM ' . STYLES_TABLE . ' + WHERE style_id IN (' . implode(', ', $ids) . ') + ORDER BY style_id DESC'; $result = $db->sql_query($sql); - $style_row = $db->sql_fetchrow($result); + + $rows = $db->sql_fetchrowset($result); $db->sql_freeresult($result); - if (!$style_row) + // Delete each style + $deleted = array(); + foreach ($rows as $style) { - trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); + $result = $this->delete_style($style, $delete_files); + + if (is_string($result)) + { + $messages[] = $result; + continue; + } + $messages[] = sprintf($user->lang['STYLE_DELETED'], $style['style_name']); + $deleted[] = $style['style_name']; + + // Attempt to delete files + if ($delete_files) + { + $messages[] = sprintf($user->lang[$this->delete_style_files($style['style_path']) ? 'DELETE_STYLE_FILES_SUCCESS' : 'DELETE_STYLE_FILES_FAILED'], $style['style_name']); + } } - $this->page_title = $l_prefix . '_EXPORT'; + if (empty($messages)) + { + // Nothing to delete? + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + } - $format_buttons = ''; - foreach ($methods as $method) + // Log action + if (count($deleted)) { - $format_buttons .= ''; + add_log('admin', 'LOG_STYLE_DELETE', implode(', ', $deleted)); } - $template->assign_vars(array( - 'S_EXPORT' => true, - 'S_ERROR_MSG' => (sizeof($error)) ? true : false, - 'S_STYLE' => ($mode == 'style') ? true : false, + // Clear cache + $cache->purge(); - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_prefix . '_NAME'], + // Show message + trigger_error(implode('
', $messages) . adm_back_link($this->u_action), E_USER_NOTICE); + } - 'U_ACTION' => $this->u_action . '&action=export&id=' . $style_id, - 'U_BACK' => $this->u_action, + /** + * Activate styles + */ + function action_activate() + { + global $user, $config, $cache, $db; + + // Get list of styles to activate + $ids = $this->request_vars('id', 0, true); + + // Activate styles + $sql = 'UPDATE ' . STYLES_TABLE . ' + SET style_active = 1 + WHERE style_id IN (' . implode(', ', $ids) . ')'; + $db->sql_query($sql); - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'NAME' => $style_row[$mode . '_name'], - 'FORMAT_BUTTONS' => $format_buttons) - ); + // Purge cache + $cache->destroy('sql', STYLES_TABLE); + + // Show styles list + $this->frontend(); } /** - * Display details + * Deactivate styles */ - function details($mode, $style_id) + function action_deactivate() { - global $template, $db, $config, $user, $safe_mode, $cache, $phpbb_root_path; + global $user, $config, $cache, $db; - $update = (isset($_POST['update'])) ? true : false; - $l_type = strtoupper($mode); + // Get list of styles to deactivate + $ids = $this->request_vars('id', 0, true); - $error = array(); - $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE); - - switch ($mode) + // Check for default style + foreach ($ids as $id) { - case 'style': - $sql_from = STYLES_TABLE; - break; + if ($id == $config['default_style']) + { + trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); + } + } - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; + // Reset default style for users who use selected styles + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = 0 + WHERE user_style IN (' . implode(', ', $ids) . ')'; + $db->sql_query($sql); - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } + // Deactivate styles + $sql = 'UPDATE ' . STYLES_TABLE . ' + SET style_active = 0 + WHERE style_id IN (' . implode(', ', $ids) . ')'; + $db->sql_query($sql); - $sql = "SELECT * - FROM $sql_from - WHERE {$mode}_id = $style_id"; - $result = $db->sql_query($sql); - $style_row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + // Purge cache + $cache->destroy('sql', STYLES_TABLE); - if (!$style_row) + // Show styles list + $this->frontend(); + } + + /** + * Show style details + */ + function action_details() + { + global $user, $config, $db, $request, $template, $cache; + + $id = $request->variable('id', 0); + if (!$id) { - trigger_error($user->lang['NO_' . $l_type] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } - - $style_row['style_default'] = ($mode == 'style' && $config['default_style'] == $style_id) ? 1 : 0; - - if ($update) + + // Get all styles + $styles = $this->get_styles(); + usort($styles, 'acp_styles::sort_styles'); + + // Find current style + $style = false; + foreach ($styles as $row) { - $name = utf8_normalize_nfc(request_var('name', '', true)); - $copyright = utf8_normalize_nfc(request_var('copyright', '', true)); - - $template_id = request_var('template_id', 0); - $theme_id = request_var('theme_id', 0); - - $style_active = request_var('style_active', 0); - $style_default = request_var('style_default', 0); - - // If the admin selected the style to be the default style, but forgot to activate it... we will do it for him - if ($style_default) - { - $style_active = 1; - } - - $sql = "SELECT {$mode}_id, {$mode}_name - FROM $sql_from - WHERE {$mode}_id <> $style_id - AND LOWER({$mode}_name) = '" . $db->sql_escape(strtolower($name)) . "'"; - $result = $db->sql_query($sql); - $conflict = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($mode == 'style' && (!$template_id || !$theme_id)) + if ($row['style_id'] == $id) { - $error[] = $user->lang['STYLE_ERR_NO_IDS']; + $style = $row; + break; } + } - if ($mode == 'style' && $style_row['style_active'] && !$style_active && $config['default_style'] == $style_id) + if ($style === false) + { + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + // Find all available parent styles + $list = $this->find_possible_parents($styles, $id); + + // Change data + if ($request->variable('update', false)) + { + $update = array( + 'style_name' => trim($request->variable('style_name', $style['style_name'])), + 'style_parent_id' => $request->variable('style_parent', (int) $style['style_parent_id']), + 'style_active' => $request->variable('style_active', (int) $style['style_active']), + ); + $update_action = $this->u_action . '&action=details&id=' . $id; + + // Check style name + if ($update['style_name'] != $style['style_name']) { - $error[] = $user->lang['DEACTIVATE_DEFAULT']; + if (!strlen($update['style_name'])) + { + trigger_error($user->lang['STYLE_ERR_STYLE_NAME'] . adm_back_link($update_action), E_USER_WARNING); + } + foreach ($styles as $row) + { + if ($row['style_name'] == $update['style_name']) + { + trigger_error($user->lang['STYLE_ERR_NAME_EXIST'] . adm_back_link($update_action), E_USER_WARNING); + } + } } - - if (!$name || $conflict) + else { - $error[] = $user->lang[$l_type . '_ERR_STYLE_NAME']; + unset($update['style_name']); } - - if (!sizeof($error)) + + // Check parent style id + if ($update['style_parent_id'] != $style['style_parent_id']) { - // Check length settings - if (utf8_strlen($name) > 30) + if ($update['style_parent_id'] != 0) { - $error[] = $user->lang[$l_type . '_ERR_NAME_LONG']; + $found = false; + foreach ($list as $row) + { + if ($row['style_id'] == $update['style_parent_id']) + { + $found = true; + $update['style_parent_tree'] = ($row['style_parent_tree'] != '' ? $row['style_parent_tree'] . '/' : '') . $row['style_path']; + break; + } + } + if (!$found) + { + trigger_error($user->lang['STYLE_ERR_INVALID_PARENT'] . adm_back_link($update_action), E_USER_WARNING); + } } - - if (utf8_strlen($copyright) > 60) + else { - $error[] = $user->lang[$l_type . '_ERR_COPY_LONG']; + $update['style_parent_tree'] = ''; } } - } - - if ($update && sizeof($error)) - { - $style_row = array_merge($style_row, array( - 'template_id' => $template_id, - 'theme_id' => $theme_id, - 'style_active' => $style_active, - $mode . '_name' => $name, - $mode . '_copyright' => $copyright) - ); - } - - // User has submitted form and no errors have occurred - if ($update && !sizeof($error)) - { - $sql_ary = array( - $mode . '_name' => $name, - $mode . '_copyright' => $copyright - ); - - switch ($mode) + else { - case 'style': - - $sql_ary += array( - 'template_id' => (int) $template_id, - 'theme_id' => (int) $theme_id, - 'style_active' => (int) $style_active, - ); - break; - - case 'theme': - break; - - case 'template': - break; + unset($update['style_parent_id']); } - - if (sizeof($sql_ary)) + + // Check style_active + if ($update['style_active'] != $style['style_active']) { - $sql = "UPDATE $sql_from - SET " . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE {$mode}_id = $style_id"; - $db->sql_query($sql); - - // Making this the default style? - if ($mode == 'style' && $style_default) + if (!$update['style_active'] && $config['default_style'] == $style['style_id']) { - set_config('default_style', $style_id); + trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($update_action), E_USER_WARNING); } } - - $cache->destroy('sql', STYLES_TABLE); - - add_log('admin', 'LOG_' . $l_type . '_EDIT_DETAILS', $name); - if (sizeof($error)) + else { - trigger_error(implode('
', $error) . adm_back_link($this->u_action), E_USER_WARNING); + unset($update['style_active']); } - else + + // Update data + if (count($update)) { - trigger_error($user->lang[$l_type . '_DETAILS_UPDATED'] . adm_back_link($this->u_action)); + $sql = 'UPDATE ' . STYLES_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $update) . " + WHERE style_id = $id"; + $db->sql_query($sql); + + $style = array_merge($style, $update); + + if (isset($update['style_parent_id'])) + { + // Update styles tree + $styles = $this->get_styles(); + if ($this->update_styles_tree(&$styles, $style)) + { + // Something was changed in styles tree, purge all cache + $cache->purge(); + } + } + add_log('admin', 'LOG_STYLE_EDIT_DETAILS', $style['style_name']); } - } - - if ($mode == 'style') - { - foreach ($element_ary as $element => $table) + + // Update default style + $default = $request->variable('style_default', 0); + if ($default) { - $sql = "SELECT {$element}_id, {$element}_name - FROM $table - ORDER BY {$element}_id ASC"; - $result = $db->sql_query($sql); - - ${$element . '_options'} = ''; - while ($row = $db->sql_fetchrow($result)) + if (!$style['style_active']) { - $selected = ($row[$element . '_id'] == $style_row[$element . '_id']) ? ' selected="selected"' : ''; - ${$element . '_options'} .= ''; + trigger_error($user->lang['STYLE_DEFAULT_CHANGE_INACTIVE'] . adm_back_link($update_action), E_USER_WARNING); } - $db->sql_freeresult($result); + set_config('default_style', $id); + $cache->purge(); } + + // Show styles list + $this->frontend(); + return; } - - if ($mode == 'template') + + // Show parent styles + foreach ($list as $row) { - $super = array(); - if (isset($style_row[$mode . '_inherits_id']) && $style_row['template_inherits_id']) - { - $super = $this->get_super($mode, $style_row['template_id']); - } + $template->assign_block_vars('parent_styles', array( + 'STYLE_ID' => $row['style_id'], + 'STYLE_NAME' => htmlspecialchars($row['style_name']), + 'LEVEL' => $row['level'], + 'SPACER' => str_repeat('  ', $row['level']), + ) + ); } - - $this->page_title = 'EDIT_DETAILS_' . $l_type; - + + // Show style details $template->assign_vars(array( - 'S_DETAILS' => true, - 'S_ERROR_MSG' => (sizeof($error)) ? true : false, - 'S_STYLE' => ($mode == 'style') ? true : false, - 'S_TEMPLATE' => ($mode == 'template') ? true : false, - 'S_THEME' => ($mode == 'theme') ? true : false, - 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, - 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, - 'S_SUPERTEMPLATE' => (isset($style_row[$mode . '_inherits_id']) && $style_row[$mode . '_inherits_id']) ? $super['template_name'] : 0, - - 'S_TEMPLATE_OPTIONS' => ($mode == 'style') ? $template_options : '', - 'S_THEME_OPTIONS' => ($mode == 'style') ? $theme_options : '', - - 'U_ACTION' => $this->u_action . '&action=details&id=' . $style_id, - 'U_BACK' => $this->u_action, - - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_type . '_NAME'], - - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'NAME' => $style_row[$mode . '_name'], - 'COPYRIGHT' => $style_row[$mode . '_copyright'], + 'S_STYLE_DETAILS' => true, + 'STYLE_ID' => $style['style_id'], + 'STYLE_NAME' => htmlspecialchars($style['style_name']), + 'STYLE_PATH' => htmlspecialchars($style['style_path']), + 'STYLE_COPYRIGHT' => strip_tags($style['style_copyright']), + 'STYLE_PARENT' => $style['style_parent_id'], + 'S_STYLE_ACTIVE' => $style['style_active'], + 'S_STYLE_DEFAULT' => ($style['style_id'] == $config['default_style']) ) ); } /** - * Load css file contents + * List installed styles */ - function load_css_file($path, $filename) + function show_installed() { - global $phpbb_root_path; + global $user, $template; - $file = "{$phpbb_root_path}styles/$path/theme/$filename"; + // Get all installed styles + $styles = $this->get_styles(); - if (file_exists($file) && ($content = file_get_contents($file))) - { - $content = trim($content); - } - else + if (!count($styles)) { - $content = ''; + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } - if (defined('DEBUG')) - { - $content = "/* BEGIN @include $filename */ \n $content \n /* END @include $filename */ \n"; - } - - return $content; - } + + usort($styles, 'acp_styles::sort_styles'); - /** - * Returns a string containing the value that should be used for the theme_data column in the theme database table. - * Includes contents of files loaded via @import - * - * @param array $theme_row is an associative array containing the theme's current database entry - * @param mixed $stylesheet can either be the new content for the stylesheet or false to load from the standard file - * @param string $root_path should only be used in case you want to use a different root path than "{$phpbb_root_path}styles/{$theme_row['theme_path']}" - * - * @return string Stylesheet data for theme_data column in the theme table - */ - function db_theme_data($theme_row, $stylesheet = false, $root_path = '') - { - global $phpbb_root_path; - - if (!$root_path) + // Get users + $users = $this->get_users(); + + // Add users counter to rows + foreach ($styles as &$style) { - $root_path = $phpbb_root_path . 'styles/' . $theme_row['theme_path']; + $style['_users'] = isset($users[$style['style_id']]) ? $users[$style['style_id']] : 0; } + + // Set up styles list variables + // Addons should increase this number and update template variable + $this->styles_list_cols = 4; + $template->assign_var('STYLES_LIST_COLS', $this->styles_list_cols); - if (!$stylesheet) + // Show styles list + $this->show_styles_list(&$styles, 0, 0); + + // Show styles with invalid inherits_id + foreach ($styles as $style) { - $stylesheet = ''; - if (file_exists($root_path . '/theme/stylesheet.css')) + if (empty($style['_shown'])) { - $stylesheet = file_get_contents($root_path . '/theme/stylesheet.css'); + $style['_note'] = sprintf($user->lang['REQUIRES_STYLE'], htmlspecialchars($style['style_parent_tree'])); + $this->list_style($style, 0); } } - // Match CSS imports - $matches = array(); - preg_match_all('/@import url\((["\'])(.*)\1\);/i', $stylesheet, $matches); + // Add buttons + $template->assign_block_vars('extra_actions', array( + 'ACTION_NAME' => 'activate', + 'L_ACTION' => $user->lang['STYLE_ACTIVATE'], + ) + ); - // remove commented stylesheets (very simple parser, allows only whitespace - // around an @import statement) - preg_match_all('#/\*\s*@import url\((["\'])(.*)\1\);\s\*/#i', $stylesheet, $commented); - $matches[2] = array_diff($matches[2], $commented[2]); + $template->assign_block_vars('extra_actions', array( + 'ACTION_NAME' => 'deactivate', + 'L_ACTION' => $user->lang['STYLE_DEACTIVATE'], + ) + ); - if (sizeof($matches)) + if (isset($this->style_counters) && $this->style_counters['total'] > 1) { - foreach ($matches[0] as $idx => $match) - { - if (isset($matches[2][$idx])) - { - $stylesheet = str_replace($match, acp_styles::load_css_file($theme_row['theme_path'], $matches[2][$idx]), $stylesheet); - } - } + $template->assign_block_vars('extra_actions', array( + 'ACTION_NAME' => 'delete', + 'L_ACTION' => $user->lang['DELETE'], + ) + ); } - - // adjust paths - return str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); } /** - * Returns an array containing all template filenames for one template that are currently cached. - * - * @param string $template_path contains the name of the template's folder in /styles/ - * - * @return array of filenames that exist in /styles/$template_path/template/ (without extension!) + * Show list of styles that can be installed */ - function template_cache_filelist($template_path) + function show_available() { - global $phpbb_root_path, $phpEx, $user; - - $cache_prefix = 'tpl_' . str_replace('_', '-', $template_path); - - if (!($dp = @opendir("{$phpbb_root_path}cache"))) + global $user, $template; + + // Get list of styles + $styles = $this->find_available(true); + + // Show styles + if (empty($styles)) { - trigger_error($user->lang['TEMPLATE_ERR_CACHE_READ'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_action), E_USER_NOTICE); } + + usort($styles, 'acp_styles::sort_styles'); - $file_ary = array(); - while ($file = readdir($dp)) + $this->styles_list_cols = 3; + $template->assign_vars(array( + 'STYLES_LIST_COLS' => $this->styles_list_cols, + 'STYLES_LIST_HIDE_COUNT' => true + ) + ); + + // Show styles + foreach ($styles as &$style) { - if ($file[0] == '.') + // Check if style has a parent style in styles list + $has_parent = false; + if ($style['_inherit_name'] != '') { - continue; - } - - if (is_file($phpbb_root_path . 'cache/' . $file) && (strpos($file, $cache_prefix) === 0)) - { - $file_ary[] = str_replace('.', '/', preg_replace('#^' . preg_quote($cache_prefix, '#') . '_(.*?)\.html\.' . $phpEx . '$#i', '\1', $file)); + foreach ($styles as $parent_style) + { + if ($parent_style['style_name'] == $style['_inherit_name'] && empty($parent_style['_shown'])) + { + // Show parent style first + $has_parent = true; + } + } } - } - closedir($dp); - - return $file_ary; - } - - /** - * Destroys cached versions of template files - * - * @param array $template_row contains the template's row in the STYLES_TEMPLATE_TABLE database table - * @param mixed $file_ary is optional and may contain an array of template file names which should be refreshed in the cache. - * The file names should be the original template file names and not the cache file names. - */ - function clear_template_cache($template_row, $file_ary = false) - { - global $phpbb_root_path, $phpEx, $user; - - $cache_prefix = 'tpl_' . str_replace('_', '-', $template_row['template_path']); - - if (!$file_ary || !is_array($file_ary)) - { - $file_ary = $this->template_cache_filelist($template_row['template_path']); - $log_file_list = $user->lang['ALL_FILES']; - } - else - { - $log_file_list = implode(', ', $file_ary); - } - - foreach ($file_ary as $file) - { - $file = str_replace('/', '.', $file); - - $file = "{$phpbb_root_path}cache/{$cache_prefix}_$file.html.$phpEx"; - if (file_exists($file) && is_file($file)) + if (!$has_parent) { - @unlink($file); + $this->list_style(&$style, 0); + $this->show_available_child_styles(&$styles, $style['style_name'], 1); } } - unset($file_ary); - - add_log('admin', 'LOG_TEMPLATE_CACHE_CLEARED', $template_row['template_name'], $log_file_list); - } - - /** - * Install Style/Template/Theme - */ - function install($mode) - { - global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template; - - $l_type = strtoupper($mode); - - $error = $installcfg = $style_row = array(); - $root_path = $cfg_file = ''; - $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE); - - $install_path = request_var('path', ''); - $update = (isset($_POST['update'])) ? true : false; - - // Installing, obtain cfg file contents - if ($install_path) + + // Show styles that do not have parent style in styles list + foreach ($styles as $style) { - $root_path = $phpbb_root_path . 'styles/' . $install_path . '/'; - $cfg_file = ($mode == 'style') ? "$root_path$mode.cfg" : "$root_path$mode/$mode.cfg"; - - if (!file_exists($cfg_file)) - { - $error[] = $user->lang[$l_type . '_ERR_NOT_' . $l_type]; - } - else + if (empty($style['_shown'])) { - $installcfg = parse_cfg_file($cfg_file); + $this->list_style(&$style, 0); } } - - // Installing - if (sizeof($installcfg)) + + // Add button + if (isset($this->style_counters) && $this->style_counters['caninstall'] > 0) { - $name = $installcfg['name']; - $copyright = $installcfg['copyright']; - $version = $installcfg['version']; - - $style_row = array( - $mode . '_id' => 0, - $mode . '_name' => '', - $mode . '_copyright' => '' + $template->assign_block_vars('extra_actions', array( + 'ACTION_NAME' => 'install', + 'L_ACTION' => $user->lang['INSTALL_STYLES'], + ) ); - - switch ($mode) - { - case 'style': - - $style_row = array( - 'style_id' => 0, - 'style_name' => $installcfg['name'], - 'style_copyright' => $installcfg['copyright'] - ); - - $reqd_template = (isset($installcfg['required_template'])) ? $installcfg['required_template'] : false; - $reqd_theme = (isset($installcfg['required_theme'])) ? $installcfg['required_theme'] : false; - - // Check to see if each element is already installed, if it is grab the id - foreach ($element_ary as $element => $table) - { - $style_row = array_merge($style_row, array( - $element . '_id' => 0, - $element . '_name' => '', - $element . '_copyright' => '') - ); - - $this->test_installed($element, $error, (${'reqd_' . $element}) ? $phpbb_root_path . 'styles/' . $reqd_template . '/' : $root_path, ${'reqd_' . $element}, $style_row[$element . '_id'], $style_row[$element . '_name'], $style_row[$element . '_copyright']); - - if (!$style_row[$element . '_name']) - { - $style_row[$element . '_name'] = $reqd_template; - } - - // Merge other information to installcfg... if present - $cfg_file = $phpbb_root_path . 'styles/' . $install_path . '/' . $element . '/' . $element . '.cfg'; - - if (file_exists($cfg_file)) - { - $cfg_contents = parse_cfg_file($cfg_file); - - // Merge only specific things. We may need them later. - foreach (array('inherit_from') as $key) - { - if (!empty($cfg_contents[$key]) && !isset($installcfg[$key])) - { - $installcfg[$key] = $cfg_contents[$key]; - } - } - } - } - - break; - - case 'template': - $this->test_installed('template', $error, $root_path, false, $style_row['template_id'], $style_row['template_name'], $style_row['template_copyright']); - break; - - case 'theme': - $this->test_installed('theme', $error, $root_path, false, $style_row['theme_id'], $style_row['theme_name'], $style_row['theme_copyright']); - break; - } - } - else - { - trigger_error($user->lang['NO_' . $l_type] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $style_row['style_active'] = request_var('style_active', 1); - $style_row['style_default'] = request_var('style_default', 0); - - // User has submitted form and no errors have occurred - if ($update && !sizeof($error)) - { - if ($mode == 'style') - { - foreach ($element_ary as $element => $table) - { - ${$element . '_root_path'} = (${'reqd_' . $element}) ? $phpbb_root_path . 'styles/' . ${'reqd_' . $element} . '/' : false; - ${$element . '_path'} = (${'reqd_' . $element}) ? ${'reqd_' . $element} : false; - } - $this->install_style($error, 'install', $root_path, $style_row['style_id'], $style_row['style_name'], $install_path, $style_row['style_copyright'], $style_row['style_active'], $style_row['style_default'], $style_row, $template_root_path, $template_path, $theme_root_path, $theme_path); - } - else - { - $this->install_element($mode, $error, 'install', $root_path, $style_row[$mode . '_id'], $style_row[$mode . '_name'], $install_path, $style_row[$mode . '_copyright']); - } - - if (!sizeof($error)) - { - $cache->destroy('sql', STYLES_TABLE); - - trigger_error($user->lang[$l_type . '_ADDED'] . adm_back_link($this->u_action)); - } } - - $this->page_title = 'INSTALL_' . $l_type; - - $template->assign_vars(array( - 'S_DETAILS' => true, - 'S_INSTALL' => true, - 'S_ERROR_MSG' => (sizeof($error)) ? true : false, - 'S_LOCATION' => (isset($installcfg['inherit_from']) && $installcfg['inherit_from']) ? false : true, - 'S_STYLE' => ($mode == 'style') ? true : false, - 'S_TEMPLATE' => ($mode == 'template') ? true : false, - 'S_SUPERTEMPLATE' => (isset($installcfg['inherit_from'])) ? $installcfg['inherit_from'] : '', - 'S_THEME' => ($mode == 'theme') ? true : false, - - 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, - 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, - - 'U_ACTION' => $this->u_action . "&action=install&path=" . urlencode($install_path), - 'U_BACK' => $this->u_action, - - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_type . '_NAME'], - - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'NAME' => $style_row[$mode . '_name'], - 'COPYRIGHT' => $style_row[$mode . '_copyright'], - 'TEMPLATE_NAME' => ($mode == 'style') ? $style_row['template_name'] : '', - 'THEME_NAME' => ($mode == 'style') ? $style_row['theme_name'] : '') - ); } - + /** - * Add new style + * Find styles available for installation + * + * @param bool $all if true, function will return all installable styles. if false, function will return only styles that can be installed + * @returns array list of styles */ - function add($mode) + function find_available($all) { - global $phpbb_root_path, $phpEx, $config, $db, $cache, $user, $template; - - $l_type = strtoupper($mode); - $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE); - $error = array(); - - $style_row = array( - $mode . '_name' => utf8_normalize_nfc(request_var('name', '', true)), - $mode . '_copyright' => utf8_normalize_nfc(request_var('copyright', '', true)), - 'template_id' => 0, - 'theme_id' => 0, - 'style_active' => request_var('style_active', 1), - 'style_default' => request_var('style_default', 0), - ); + global $user; - $basis = request_var('basis', 0); - $update = (isset($_POST['update'])) ? true : false; + // Get list of installed styles + $installed = $this->get_styles(); - if ($basis) + $installed_dirs = array(); + $installed_names = array(); + foreach ($installed as $style) { - switch ($mode) - { - case 'style': - $sql_select = 'template_id, theme_id'; - $sql_from = STYLES_TABLE; - break; - - case 'template': - $sql_select = 'template_id'; - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_select = 'theme_id'; - $sql_from = STYLES_THEME_TABLE; - break; - } - - $sql = "SELECT $sql_select - FROM $sql_from - WHERE {$mode}_id = $basis"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row) + $installed_dirs[] = $style['style_path']; + $installed_names[$style['style_name']] = array( + 'path' => $style['style_path'], + 'id' => $style['style_id'], + 'parent' => $style['style_parent_id'], + 'tree' => (strlen($style['style_parent_tree']) ? $style['style_parent_tree'] . '/' : '') . $style['style_path'], + ); + } + + // Get list of directories + $dirs = $this->find_style_dirs(); + + // Find styles that can be installed + $styles = array(); + foreach ($dirs as $dir) + { + if (in_array($dir, $installed_dirs)) { - $error[] = $user->lang['NO_' . $l_type]; + // Style is already installed + continue; } - - if (!sizeof($error)) + $cfg = $this->read_style_cfg($dir); + if ($cfg === false) { - $style_row['template_id'] = (isset($row['template_id'])) ? $row['template_id'] : $style_row['template_id']; - $style_row['theme_id'] = (isset($row['theme_id'])) ? $row['theme_id'] : $style_row['theme_id']; + // Invalid style.cfg + continue; } - } - - if ($update) - { - $style_row['template_id'] = request_var('template_id', $style_row['template_id']); - $style_row['theme_id'] = request_var('theme_id', $style_row['theme_id']); - if ($mode == 'style' && (!$style_row['template_id'] || !$style_row['theme_id'])) - { - $error[] = $user->lang['STYLE_ERR_NO_IDS']; - } - } + // Style should be available for installation + $parent = $cfg['parent']; + $style = array( + 'style_id' => 0, + 'style_name' => $cfg['name'], + 'style_copyright' => $cfg['copyright'], + 'style_active' => 0, + 'style_path' => $dir, + 'bbcode_bitfield' => $cfg['template_bitfield'], + 'style_parent_id' => 0, + 'style_parent_tree' => '', + // Extra values for styles list + // All extra variable start with _ so they won't be confused with data that can be added to styles table + '_inherit_name' => $parent, + '_available' => true, + '_note' => '', + ); - // User has submitted form and no errors have occurred - if ($update && !sizeof($error)) - { - if ($mode == 'style') + // Check style inheritance + if ($parent != '') { - $style_row['style_id'] = 0; - - $this->install_style($error, 'add', '', $style_row['style_id'], $style_row['style_name'], '', $style_row['style_copyright'], $style_row['style_active'], $style_row['style_default'], $style_row); + if (isset($installed_names[$parent])) + { + // Parent style is installed + $row = $installed_names[$parent]; + $style['style_parent_id'] = $row['id']; + $style['style_parent_tree'] = $row['tree']; + } + else + { + // Parent style is not installed yet + $style['_available'] = false; + $style['_note'] = sprintf($user->lang['REQUIRES_STYLE'], htmlspecialchars($parent)); + } } - - if (!sizeof($error)) + + if ($all || $style['_available']) { - $cache->destroy('sql', STYLES_TABLE); - - trigger_error($user->lang[$l_type . '_ADDED'] . adm_back_link($this->u_action)); + $styles[] = $style; } } - if ($mode == 'style') + return $styles; + } + + /** + * Show styles list + * + * @param array $styles styles list + * @param int $parent parent style id + * @param int $level style inheritance level + */ + function show_styles_list($styles, $parent, $level) + { + foreach ($styles as &$style) { - foreach ($element_ary as $element => $table) + if (empty($style['_shown']) && $style['style_parent_id'] == $parent) { - $sql = "SELECT {$element}_id, {$element}_name - FROM $table - ORDER BY {$element}_id ASC"; - $result = $db->sql_query($sql); - - ${$element . '_options'} = ''; - while ($row = $db->sql_fetchrow($result)) - { - $selected = ($row[$element . '_id'] == $style_row[$element . '_id']) ? ' selected="selected"' : ''; - ${$element . '_options'} .= ''; - } - $db->sql_freeresult($result); + $this->list_style(&$style, $level); + $this->show_styles_list(&$styles, $style['style_id'], $level + 1); } } - - $this->page_title = 'ADD_' . $l_type; - - $template->assign_vars(array( - 'S_DETAILS' => true, - 'S_ADD' => true, - 'S_ERROR_MSG' => (sizeof($error)) ? true : false, - 'S_STYLE' => ($mode == 'style') ? true : false, - 'S_TEMPLATE' => ($mode == 'template') ? true : false, - 'S_THEME' => ($mode == 'theme') ? true : false, - 'S_BASIS' => ($basis) ? true : false, - - 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, - 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, - 'S_TEMPLATE_OPTIONS' => ($mode == 'style') ? $template_options : '', - 'S_THEME_OPTIONS' => ($mode == 'style') ? $theme_options : '', - - 'U_ACTION' => $this->u_action . '&action=add&basis=' . $basis, - 'U_BACK' => $this->u_action, - - 'L_TITLE' => $user->lang[$this->page_title], - 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], - 'L_NAME' => $user->lang[$l_type . '_NAME'], - - 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', - 'NAME' => $style_row[$mode . '_name'], - 'COPYRIGHT' => $style_row[$mode . '_copyright']) - ); - } - + /** - - $reqd_template = (isset($installcfg['required_template'])) ? $installcfg['required_template'] : false; - $reqd_theme = (isset($installcfg['required_theme'])) ? $installcfg['required_theme'] : false; - - // Check to see if each element is already installed, if it is grab the id - foreach ($element_ary as $element => $table) - { - $style_row = array_merge($style_row, array( - $element . '_id' => 0, - $element . '_name' => '', - $element . '_copyright' => '') - ); - - $this->test_installed($element, $error, $root_path, ${'reqd_' . $element}, $style_row[$element . '_id'], $style_row[$element . '_name'], $style_row[$element . '_copyright']); - * Is this element installed? If not, grab its cfg details + * Show available styles tree + * + * @param array $styles Styles list, passed as reference + * @param string $name Name of parent style + * @param string $level Styles tree level */ - function test_installed($element, &$error, $root_path, $reqd_name, &$id, &$name, &$copyright) + function show_available_child_styles($styles, $name, $level) { - global $db, $user; - - switch ($element) - { - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } - - $l_element = strtoupper($element); - - $chk_name = ($reqd_name !== false) ? $reqd_name : $name; - - $sql = "SELECT {$element}_id, {$element}_name - FROM $sql_from - WHERE {$element}_name = '" . $db->sql_escape($chk_name) . "'"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $name = $row[$element . '_name']; - $id = $row[$element . '_id']; - } - else + foreach ($styles as &$style) { - if (!($cfg = @file("$root_path$element/$element.cfg"))) + if (empty($style['_shown']) && $style['_inherit_name'] == $name) { - $error[] = sprintf($user->lang['REQUIRES_' . $l_element], $reqd_name); - return false; + $this->list_style(&$style, $level); + $this->show_available_child_styles(&$styles, $style['style_name'], $level + 1); } - - $cfg = parse_cfg_file("$root_path$element/$element.cfg", $cfg); - - $name = $cfg['name']; - $copyright = $cfg['copyright']; - $id = 0; - - unset($cfg); } - $db->sql_freeresult($result); } - + /** - * Install/Add style + * Update styles tree + * + * @param array $styles Styles list, passed as reference + * @param array $style Current style, false if root + * @returns true if something was updated, false if not */ - function install_style(&$error, $action, $root_path, &$id, $name, $path, $copyright, $active, $default, &$style_row, $template_root_path = false, $template_path = false, $theme_root_path = false, $theme_path = false) + function update_styles_tree($styles, $style = false) { - global $config, $db, $user; - - $element_ary = array('template', 'theme'); - - if (!$name) + $parent_id = ($style === false) ? 0 : $style['style_id']; + $parent_tree = ($style === false) ? '' : ($style['style_parent_tree'] == '' ? '' : $style['style_parent_tree']) . $style['style_path']; + $update = false; + $updated = false; + foreach ($styles as &$row) { - $error[] = $user->lang['STYLE_ERR_STYLE_NAME']; + if ($row['style_parent_id'] == $parent_id) + { + if ($row['style_parent_tree'] != $parent_tree) + { + $row['style_parent_tree'] = $parent_tree; + $update = true; + } + $updated |= $this->update_styles_tree(&$styles, $row); + } } - - // Check length settings - if (utf8_strlen($name) > 30) + if ($update) { - $error[] = $user->lang['STYLE_ERR_NAME_LONG']; + global $db; + $sql = 'UPDATE ' . STYLES_TABLE . " + SET style_parent_tree = '" . $db->sql_escape($parent_tree) . "' + WHERE style_parent_id = {$parent_id}"; + $db->sql_query($sql); + $updated = true; } - - if (utf8_strlen($copyright) > 60) - { - $error[] = $user->lang['STYLE_ERR_COPY_LONG']; + return $updated; + } + + /** + * Find all possible parent styles for style + * + * @param array $styles list of styles + * @param int $id id of style + * @param int $parent current parent style id + * @param int $level current tree level + * @returns array of style ids, names and levels + */ + function find_possible_parents($styles, $id = -1, $parent = 0, $level = 0) + { + $results = array(); + foreach ($styles as $style) + { + if ($style['style_id'] != $id && $style['style_parent_id'] == $parent) + { + $results[] = array( + 'style_id' => $style['style_id'], + 'style_name' => $style['style_name'], + 'style_path' => $style['style_path'], + 'style_parent_id' => $style['style_parent_id'], + 'style_parent_tree' => $style['style_parent_tree'], + 'level' => $level + ); + $results = array_merge($results, $this->find_possible_parents($styles, $id, $style['style_id'], $level + 1)); + } } + return $results; + } + + /** + * Show item in styles list + * + * @param array $style style row + * @param array $level style inheritance level + */ + function list_style($style, $level) + { + global $template, $config, $db, $user, $phpbb_root_path, $phpEx; + + // Mark row as shown + if (!empty($style['_shown'])) return; + $style['_shown'] = true; + + // Generate template variables + $actions = array(); + $row = array( + // Style data + 'STYLE_ID' => $style['style_id'], + 'STYLE_NAME' => htmlspecialchars($style['style_name']), + 'STYLE_PATH' => htmlspecialchars($style['style_path']), + 'STYLE_COPYRIGHT' => strip_tags($style['style_copyright']), + 'STYLE_ACTIVE' => $style['style_active'], + + // Additional data + 'DEFAULT' => ($style['style_id'] && $style['style_id'] == $config['default_style']), + 'USERS' => $style['_users'], + 'LEVEL' => $level, + 'PADDING' => (4 + 16 * $level), + 'SHOW_COPYRIGHT' => ($style['style_id']) ? false : true, + 'STYLE_PATH_FULL' => htmlspecialchars($this->styles_path_absolute . '/' . $style['style_path']) . '/', + + // Comment to show below style + 'COMMENT' => (isset($style['_note'])) ? $style['_note'] : '', + + // The following variables should be used by hooks to add custom HTML code + 'EXTRA' => '', + 'EXTRA_OPTIONS' => '' + ); + + // Status specific data + if ($style['style_id']) + { + // Style is installed + + // Details + $actions[] = array( + 'U_ACTION' => $this->u_action . '&action=details&id=' . $style['style_id'], + 'L_ACTION' => $user->lang['DETAILS'] + ); - // Check if the name already exist - $sql = 'SELECT style_id - FROM ' . STYLES_TABLE . " - WHERE style_name = '" . $db->sql_escape($name) . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + // Activate + $actions[] = array( + 'U_ACTION' => $this->u_action . '&action=' . ($style['style_active'] ? 'de' : '') . 'activate&id=' . $style['style_id'], + 'L_ACTION' => $user->lang['STYLE_' . ($style['style_active'] ? 'DE' : '') . 'ACTIVATE'] + ); - if ($row) - { - $error[] = $user->lang['STYLE_ERR_NAME_EXIST']; - } +/* // Export + $actions[] = array( + 'U_ACTION' => $this->u_action . '&action=export&id=' . $style['style_id'], + 'L_ACTION' => $user->lang['EXPORT'] + ); */ - if (sizeof($error)) - { - return false; + // Delete + $actions[] = array( + 'U_ACTION' => $this->u_action . '&action=delete&id=' . $style['style_id'], + 'L_ACTION' => $user->lang['DELETE'] + ); + + // Preview + $actions[] = array( + 'U_ACTION' => append_sid("{$phpbb_root_path}index.$phpEx", 'style=' . $style['style_id']), + 'L_ACTION' => $user->lang['PREVIEW'] + ); } - - foreach ($element_ary as $element) + else { - // Zero id value ... need to install element ... run usual checks - // and do the install if necessary - if (!$style_row[$element . '_id']) + // Style is not installed + if (empty($style['_available'])) + { + $actions[] = array( + 'HTML' => $user->lang['CANNOT_BE_INSTALLED'] + ); + } + else { - $this->install_element($element, $error, $action, (${$element . '_root_path'}) ? ${$element . '_root_path'} : $root_path, $style_row[$element . '_id'], $style_row[$element . '_name'], (${$element . '_path'}) ? ${$element . '_path'} : $path, $style_row[$element . '_copyright']); + $actions[] = array( + 'U_ACTION' => $this->u_action . '&action=install&dir=' . urlencode($style['style_path']), + 'L_ACTION' => $user->lang['INSTALL_STYLE'] + ); } } - - if (!$style_row['template_id'] || !$style_row['theme_id']) + + // todo: add hook + + // Assign template variables + $template->assign_block_vars('styles_list', $row); + foreach($actions as $action) { - $error[] = $user->lang['STYLE_ERR_NO_IDS']; + $template->assign_block_vars('styles_list.actions', $action); } - - if (sizeof($error)) + + // Increase counters + $counter = ($style['style_id']) ? ($style['style_active'] ? 'active' : 'inactive') : (empty($style['_available']) ? 'cannotinstall' : 'caninstall'); + if (!isset($this->style_counters)) { - return false; + $this->style_counters = array( + 'total' => 0, + 'active' => 0, + 'inactive' => 0, + 'caninstall' => 0, + 'cannotinstall' => 0 + ); } - - $db->sql_transaction('begin'); - - $sql_ary = array( - 'style_name' => $name, - 'style_copyright' => $copyright, - 'style_active' => (int) $active, - 'template_id' => (int) $style_row['template_id'], - 'theme_id' => (int) $style_row['theme_id'], + $this->style_counters[$counter] ++; + $this->style_counters['total'] ++; + } + + /** + * Show welcome message + * + * @param string $title main title + * @param string $description page description + */ + function welcome_message($title, $description) + { + global $user, $template; + $template->assign_vars(array( + 'L_TITLE' => (isset($user->lang[$title])) ? $user->lang[$title] : $title, + 'L_EXPLAIN' => (isset($user->lang[$description])) ? $user->lang[$description] : $description + ) ); - - $sql = 'INSERT INTO ' . STYLES_TABLE . ' - ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - - $id = $db->sql_nextid(); - - if ($default) - { - $sql = 'UPDATE ' . USERS_TABLE . " - SET user_style = $id - WHERE user_style = " . $config['default_style']; - $db->sql_query($sql); - - set_config('default_style', $id); - } - - $db->sql_transaction('commit'); - - add_log('admin', 'LOG_STYLE_ADD', $name); } - + /** - * Install/add an element, doing various checks as we go + * Find all directories that have styles + * + * @returns array of directory names */ - function install_element($mode, &$error, $action, $root_path, &$id, $name, $path, $copyright) + function find_style_dirs() { - global $phpbb_root_path, $db, $user; + $styles = array(); - // we parse the cfg here (again) - $cfg_data = parse_cfg_file("$root_path$mode/$mode.cfg"); - - switch ($mode) + $dp = @opendir($this->styles_path); + if ($dp) { - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } - - $l_type = strtoupper($mode); + while (($file = readdir($dp)) !== false) + { + $dir = $this->styles_path . $file; + if ($file[0] == '.' || !is_dir($dir)) + { + continue; + } - if (!$name) - { - $error[] = $user->lang[$l_type . '_ERR_STYLE_NAME']; + if (file_exists("{$dir}/style.cfg")) + { + $styles[] = $file; + } + } + closedir($dp); } - // Check length settings - if (utf8_strlen($name) > 30) + return $styles; + } + + /** + * Sort styles + */ + function sort_styles($style1, $style2) + { + if ($style1['style_active'] != $style2['style_active']) { - $error[] = $user->lang[$l_type . '_ERR_NAME_LONG']; + return ($style1['style_active']) ? -1 : 1; } - - if (utf8_strlen($copyright) > 60) + if (isset($style1['_available']) && $style1['_available'] != $style2['_available']) { - $error[] = $user->lang[$l_type . '_ERR_COPY_LONG']; + return ($style1['_available']) ? -1 : 1; } - - // Check if the name already exist - $sql = "SELECT {$mode}_id - FROM $sql_from - WHERE {$mode}_name = '" . $db->sql_escape($name) . "'"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) + return strcasecmp(isset($style1['style_name']) ? $style1['style_name'] : $style1['name'], isset($style2['style_name']) ? $style2['style_name'] : $style2['name']); + } + + /** + * Read style configuration file + * + * @param string $dir style directory + * @returns array of style data + * @returns false on error + */ + function read_style_cfg($dir) + { + static $required = array('name', 'version', 'copyright'); + $cfg = parse_cfg_file($this->styles_path . $dir . '/style.cfg'); + + // Check if it is a valid file + foreach ($required as $key) { - // If it exist, we just use the style on installation - if ($action == 'install') + if (!isset($cfg[$key])) { - $id = $row[$mode . '_id']; return false; } - - $error[] = $user->lang[$l_type . '_ERR_NAME_EXIST']; - } - - if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from']) - { - if ($mode === 'template') - { - $select_bf = ', bbcode_bitfield'; - } - else - { - $select_bf = ''; - } - - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path $select_bf - FROM $sql_from - WHERE {$mode}_name = '" . $db->sql_escape($cfg_data['inherit_from']) . "' - AND {$mode}_inherits_id = 0"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - if (!$row) - { - $error[] = sprintf($user->lang[$l_type . '_ERR_REQUIRED_OR_INCOMPLETE'], $cfg_data['inherit_from']); - } - else - { - $inherit_id = $row["{$mode}_id"]; - $inherit_path = $row["{$mode}_path"]; - $inherit_bf = ($mode === 'template') ? $row["bbcode_bitfield"] : false; - } } - else + + // Check data + if (!isset($cfg['parent']) || !is_string($cfg['parent']) || $cfg['parent'] == $cfg['name']) { - $inherit_id = 0; - $inherit_path = ''; - $inherit_bf = false; + $cfg['parent'] = ''; } - - if (sizeof($error)) + if (!isset($cfg['template_bitfield'])) { - return false; + $cfg['template_bitfield'] = $this->default_bitfield(); } - - $sql_ary = array( - $mode . '_name' => $name, - $mode . '_copyright' => $copyright, - $mode . '_path' => $path, - ); - - switch ($mode) + + return $cfg; + } + + /** + * Install style + * + * @param $style style data + * @returns int style id + */ + function install_style($style) + { + global $db; + + // Generate row + $sql_ary = array(); + foreach ($style as $key => $value) { - case 'template': - // We check if the template author defined a different bitfield - if (!empty($cfg_data['template_bitfield'])) - { - $sql_ary['bbcode_bitfield'] = $cfg_data['template_bitfield']; - } - else if ($inherit_bf) - { - $sql_ary['bbcode_bitfield'] = $inherit_bf; - } - else - { - $sql_ary['bbcode_bitfield'] = $this->template_bitfield; - } - - if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from']) - { - $sql_ary += array( - 'template_inherits_id' => $inherit_id, - 'template_inherit_path' => $inherit_path, - ); - } - break; - - case 'theme': - break; + if ($key != 'style_id' && substr($key, 0, 1) != '_') + { + $sql_ary[$key] = $value; + } } - + + // Add to database $db->sql_transaction('begin'); - $sql = "INSERT INTO $sql_from - " . $db->sql_build_array('INSERT', $sql_ary); + $sql = 'INSERT INTO ' . STYLES_TABLE . ' + ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); $id = $db->sql_nextid(); $db->sql_transaction('commit'); - add_log('admin', 'LOG_' . $l_type . '_ADD_FS', $name); + add_log('admin', 'LOG_STYLE_ADD', $sql_ary['style_name']); + + return $id; } /** - * Checks downwards dependencies + * Lists all styles * - * @access public - * @param string $mode The element type to check - only template is supported - * @param int $id The template id - * @returns false if no component inherits, array with name, path and id for each subtemplate otherwise + * @returns array of rows with styles data */ - function check_inheritance($mode, $id) + function get_styles() { global $db; + + $sql = 'SELECT * + FROM ' . STYLES_TABLE; + $result = $db->sql_query($sql); - $l_type = strtoupper($mode); + $rows = $db->sql_fetchrowset($result); + $db->sql_freeresult($result); - switch ($mode) - { - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; + return $rows; + } - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; - } + /** + * Count users for each style + * + * @returns array of styles in following format: [style_id] = number of users + */ + function get_users() + { + global $db; - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path - FROM $sql_from - WHERE {$mode}_inherits_id = " . (int) $id; + $sql = 'SELECT user_style, COUNT(user_style) AS style_count + FROM ' . USERS_TABLE . ' + GROUP BY user_style'; $result = $db->sql_query($sql); - $names = array(); + $style_count = array(); while ($row = $db->sql_fetchrow($result)) { - - $names[$row["{$mode}_id"]] = array( - "{$mode}_id" => $row["{$mode}_id"], - "{$mode}_name" => $row["{$mode}_name"], - "{$mode}_path" => $row["{$mode}_path"], - ); + $style_count[$row['user_style']] = $row['style_count']; } $db->sql_freeresult($result); + + return $style_count; + } + + /** + * Delete style + * + * @param array $style Style data + * @returns true on success, error message on error + */ + function delete_style($style) + { + global $db, $user; + + $id = $style['style_id']; + $path = $style['style_path']; + + // Check if style has child styles + $sql = 'SELECT style_id + FROM ' . STYLES_TABLE . ' + WHERE style_parent_id = ' . $id . " OR style_parent_tree = '" . $db->sql_escape($path) . "'"; + $result = $db->sql_query($sql); + + $conflict = $db->sql_fetchrow($result); + $db->sql_freeresult($result); - if (sizeof($names)) + if ($conflict !== false) { - return $names; + return sprintf($user->lang['STYLE_DELETE_DEPENDENT'], $style['style_name']); } - else + + // Change default style for users + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = 0 + WHERE user_style = ' . $id; + $db->sql_query($sql); + + // Delete style + $sql = 'DELETE FROM ' . STYLES_TABLE . ' + WHERE style_id = ' . $id; + $db->sql_query($sql); + return true; + } + + /** + * Delete all files in style directory + * + * @param string $path Style directory + * @param string $dir Directory to remove inside style's directory + * @returns true on success, false on error + */ + function delete_style_files($path, $dir = '') + { + $dirname = $this->styles_path . $path . $dir; + $result = true; + + $dp = @opendir($dirname); + + if ($dp) + { + while (($file = readdir($dp)) !== false) + { + if ($file == '.' || $file == '..') + { + continue; + } + $filename = $dirname . '/' . $file; + if (is_dir($filename)) + { + if (!$this->delete_style_files($path, $dir . '/' . $file)) + { + $result = false; + } + } + else + { + if (!@unlink($filename)) + { + $result = false; + } + } + } + closedir($dp); + } + if (!@rmdir($dirname)) { return false; } + + return $result; } - + /** - * Checks upwards dependencies + * Get list of items from posted data * - * @access public - * @param string $mode The element type to check - only template is supported - * @param int $id The template id - * @returns false if the component does not inherit, array with name, path and id otherwise + * @param string $name Variable name + * @param $default Default value for array: string or number + * @param bool $error If true, error will be triggered if list is empty + * @returns array of items */ - function get_super($mode, $id) + function request_vars($name, $default, $error = false) { - global $db; + global $request, $user; - $l_type = strtoupper($mode); + $item = $request->variable($name, $default); + $items = $request->variable($name . 's', array($default)); - switch ($mode) + if (count($items) == 1 && $items[0] == $default) { - case 'template': - $sql_from = STYLES_TEMPLATE_TABLE; - break; - - case 'theme': - $sql_from = STYLES_THEME_TABLE; - break; + $items = array(); } - $sql = "SELECT {$mode}_inherits_id - FROM $sql_from - WHERE {$mode}_id = " . (int) $id; - $result = $db->sql_query_limit($sql, 1); - - if ($row = $db->sql_fetchrow($result)) + if ($item != $default && !count($items)) { - $db->sql_freeresult($result); + $items[] = $item; } - else + + if ($error && !count($items)) { - return false; + trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } - $super_id = $row["{$mode}_inherits_id"]; - - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path - FROM $sql_from - WHERE {$mode}_id = " . (int) $super_id; + return $items; + } - $result = $db->sql_query_limit($sql, 1); - if ($row = $db->sql_fetchrow($result)) + /** + * Generates hardcoded bitfield + * + * @returns bitfield string + */ + function default_bitfield() + { + static $value; + if(isset($value)) { - $db->sql_freeresult($result); - return $row; + return $value; } - - return false; + + // Hardcoded template bitfield to add for new templates + $bitfield = new bitfield(); + $bitfield->set(0); + $bitfield->set(1); + $bitfield->set(2); + $bitfield->set(3); + $bitfield->set(4); + $bitfield->set(8); + $bitfield->set(9); + $bitfield->set(11); + $bitfield->set(12); + $value = $bitfield->get_base64(); + return $value; } + } -- cgit v1.2.1 From bc46cfd6e5a6dd0a759c610e4654a7fad47db130 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 15:48:12 +0200 Subject: [feature/merging-style-components] Fix notices in acp_styles PHPBB3-10632 --- phpBB/includes/acp/acp_styles.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index acd010b77e..123725ef1d 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -228,7 +228,7 @@ class acp_styles */ function action_delete_confirmed($ids, $delete_files) { - global $db, $user, $cache; + global $db, $user, $cache, $config; $default = $config['default_style']; $deleted = array(); @@ -556,6 +556,7 @@ class acp_styles $users = $this->get_users(); // Add users counter to rows + $style['_users'] = array(); foreach ($styles as &$style) { $style['_users'] = isset($users[$style['style_id']]) ? $users[$style['style_id']] : 0; @@ -1288,7 +1289,7 @@ class acp_styles function default_bitfield() { static $value; - if(isset($value)) + if (isset($value)) { return $value; } -- cgit v1.2.1 From 961199755200668790b243447eac6bf3374b0bb6 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 17:04:17 +0300 Subject: [feature/merging-style-components] Fixing few errors in acp_styles Fixing notices and usability issues PHPBB3-10632 --- phpBB/includes/acp/acp_styles.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 123725ef1d..5ff79b0c19 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -181,10 +181,6 @@ class acp_styles trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } $message = implode('
', $messages); - if (count($messages) == 1 && $last_installed !== false) - { - $message .= '

' . sprintf($user->lang['STYLE_INSTALLED_EDIT_DETAILS'], $this->u_base_action . '&mode=style&action=details&id=' . $last_installed); - } $message .= '

' . sprintf($user->lang['STYLE_INSTALLED_RETURN_STYLES'], $this->u_base_action . '&mode=style'); $message .= '

' . sprintf($user->lang['STYLE_INSTALLED_RETURN_UNINSTALLED'], $this->u_base_action . '&mode=install'); trigger_error($message, E_USER_NOTICE); @@ -556,7 +552,6 @@ class acp_styles $users = $this->get_users(); // Add users counter to rows - $style['_users'] = array(); foreach ($styles as &$style) { $style['_users'] = isset($users[$style['style_id']]) ? $users[$style['style_id']] : 0; @@ -892,7 +887,7 @@ class acp_styles // Additional data 'DEFAULT' => ($style['style_id'] && $style['style_id'] == $config['default_style']), - 'USERS' => $style['_users'], + 'USERS' => (isset($style['_users'])) ? $style['_users'] : '', 'LEVEL' => $level, 'PADDING' => (4 + 16 * $level), 'SHOW_COPYRIGHT' => ($style['style_id']) ? false : true, -- cgit v1.2.1 From 0540509f145d7eb9ba1fd4468399b48edcf46d23 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 17:58:17 +0300 Subject: [feature/merging-style-components] Renaming "delete" to "uninstall" for styles Changing from "delete" to "uninstall" in acp_styles to avoid confusing users PHPBB3-10632 --- phpBB/includes/acp/acp_styles.php | 64 +++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 5ff79b0c19..9345ad470a 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -45,7 +45,7 @@ class acp_styles $this->mode = $mode; $action = $request->variable('action', ''); - $post_actions = array('install', 'activate', 'deactivate', 'delete'); + $post_actions = array('install', 'activate', 'deactivate', 'uninstall'); foreach ($post_actions as $key) { if (isset($_POST[$key])) @@ -70,8 +70,8 @@ class acp_styles case 'install': $this->action_install(); return; - case 'delete': - $this->action_delete(); + case 'uninstall': + $this->action_uninstall(); return; case 'activate': $this->action_activate(); @@ -187,47 +187,47 @@ class acp_styles } /** - * Confirm styles deletion + * Confirm styles removal */ - function action_delete() + function action_uninstall() { global $user, $config, $template, $request; - // Get list of styles to delete + // Get list of styles to uninstall $ids = $this->request_vars('id', 0, true); // Check if confirmation box was submitted if (confirm_box(true)) { - // Delete - $this->action_delete_confirmed($ids, $request->variable('confirm_delete_files', false)); + // Uninstall + $this->action_uninstall_confirmed($ids, $request->variable('confirm_delete_files', false)); return; } // Confirm box $s_hidden = build_hidden_fields(array( - 'action' => 'delete', + 'action' => 'uninstall', 'ids' => $ids )); $template->assign_var('S_CONFIRM_DELETE', true); - confirm_box(false, $user->lang['CONFIRM_DELETE_STYLES'], $s_hidden, 'acp_styles.html'); + confirm_box(false, $user->lang['CONFIRM_UNINSTALL_STYLES'], $s_hidden, 'acp_styles.html'); // Canceled - show styles list $this->frontend(); } /** - * Delete styles(s) + * Uninstall styles(s) * * @param array $ids List of style IDs * @param bool $delete_files If true, script will attempt to remove files for selected styles */ - function action_delete_confirmed($ids, $delete_files) + function action_uninstall_confirmed($ids, $delete_files) { global $db, $user, $cache, $config; $default = $config['default_style']; - $deleted = array(); + $uninstalled = array(); $messages = array(); // Check styles list @@ -239,9 +239,9 @@ class acp_styles } if ($id == $default) { - trigger_error($user->lang['DELETE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($user->lang['UNINSTALL_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); } - $deleted[$id] = false; + $uninstalled[$id] = false; } // Order by reversed style_id, so parent styles would be removed after child styles @@ -255,19 +255,19 @@ class acp_styles $rows = $db->sql_fetchrowset($result); $db->sql_freeresult($result); - // Delete each style - $deleted = array(); + // Uinstall each style + $uninstalled = array(); foreach ($rows as $style) { - $result = $this->delete_style($style, $delete_files); + $result = $this->uninstall_style($style, $delete_files); if (is_string($result)) { $messages[] = $result; continue; } - $messages[] = sprintf($user->lang['STYLE_DELETED'], $style['style_name']); - $deleted[] = $style['style_name']; + $messages[] = sprintf($user->lang['STYLE_UNINSTALLED'], $style['style_name']); + $uninstalled[] = $style['style_name']; // Attempt to delete files if ($delete_files) @@ -278,14 +278,14 @@ class acp_styles if (empty($messages)) { - // Nothing to delete? + // Nothing to uninstall? trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } // Log action - if (count($deleted)) + if (count($uninstalled)) { - add_log('admin', 'LOG_STYLE_DELETE', implode(', ', $deleted)); + add_log('admin', 'LOG_STYLE_DELETE', implode(', ', $uninstalled)); } // Clear cache @@ -591,8 +591,8 @@ class acp_styles if (isset($this->style_counters) && $this->style_counters['total'] > 1) { $template->assign_block_vars('extra_actions', array( - 'ACTION_NAME' => 'delete', - 'L_ACTION' => $user->lang['DELETE'], + 'ACTION_NAME' => 'uninstall', + 'L_ACTION' => $user->lang['STYLE_UNINSTALL'], ) ); } @@ -924,10 +924,10 @@ class acp_styles 'L_ACTION' => $user->lang['EXPORT'] ); */ - // Delete + // Uninstall $actions[] = array( - 'U_ACTION' => $this->u_action . '&action=delete&id=' . $style['style_id'], - 'L_ACTION' => $user->lang['DELETE'] + 'U_ACTION' => $this->u_action . '&action=uninstall&id=' . $style['style_id'], + 'L_ACTION' => $user->lang['STYLE_UNINSTALL'] ); // Preview @@ -1156,12 +1156,12 @@ class acp_styles } /** - * Delete style + * Uninstall style * * @param array $style Style data * @returns true on success, error message on error */ - function delete_style($style) + function uninstall_style($style) { global $db, $user; @@ -1179,7 +1179,7 @@ class acp_styles if ($conflict !== false) { - return sprintf($user->lang['STYLE_DELETE_DEPENDENT'], $style['style_name']); + return sprintf($user->lang['STYLE_UNINSTALL_DEPENDENT'], $style['style_name']); } // Change default style for users @@ -1188,7 +1188,7 @@ class acp_styles WHERE user_style = ' . $id; $db->sql_query($sql); - // Delete style + // Uninstall style $sql = 'DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $id; $db->sql_query($sql); -- cgit v1.2.1 From 5d07b16ec647f51d51504cf9d6a0861a975ceb8e Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 17:15:32 +0200 Subject: [feature/merging-style-components] Fix back link on install page When on install page and all styles are installed, fix back link to go to main styles page. PHPBB3-10632 --- phpBB/includes/acp/acp_styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 9345ad470a..2772fb2217 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -611,7 +611,7 @@ class acp_styles // Show styles if (empty($styles)) { - trigger_error($user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_action), E_USER_NOTICE); + trigger_error($user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); } usort($styles, 'acp_styles::sort_styles'); -- cgit v1.2.1 From 7c99525b98cfa015fd21ba2e873d0617596e064f Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 3 Apr 2012 00:14:30 +0300 Subject: [ticket/10752] Removing globals acp_styles Removing global variables from functions in acp_styles PHPBB3-10752 --- phpBB/includes/acp/acp_styles.php | 268 ++++++++++++++++++-------------------- 1 file changed, 127 insertions(+), 141 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 2772fb2217..c7f66b7253 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -26,25 +26,46 @@ class acp_styles var $mode; var $styles_path; var $styles_path_absolute = 'styles'; + var $default_style = 0; + + private $db = false; + private $user = false; + private $template = false; + private $request = false; + private $cache = false; + private $auth = false; + private $phpbb_root_path = false; + private $phpEx = false; function main($id, $mode) { - global $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request; + global $db, $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request, $cache, $auth, $config; + + $this->db = $db; + $this->user = $user; + $this->template = $template; + $this->request = $request; + $this->cache = $cache; + $this->auth = $auth; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; - $this->styles_path = $phpbb_root_path . $this->styles_path_absolute . '/'; + $this->default_style = $config['default_style']; + $this->styles_path = $this->phpbb_root_path . $this->styles_path_absolute . '/'; $this->u_base_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$id}"); $this->s_hidden_fields = array( 'mode' => $mode, ); - $user->add_lang('acp/styles'); + $this->user->add_lang('acp/styles'); $this->tpl_name = 'acp_styles'; $this->page_title = 'ACP_CAT_STYLES'; $this->mode = $mode; - $action = $request->variable('action', ''); + $action = $this->request->variable('action', ''); $post_actions = array('install', 'activate', 'deactivate', 'uninstall'); foreach ($post_actions as $key) { @@ -58,7 +79,7 @@ class acp_styles $this->s_hidden_fields['action'] = $action; } - $template->assign_vars(array( + $this->template->assign_vars(array( 'U_ACTION' => $this->u_base_action, 'S_HIDDEN_FIELDS' => build_hidden_fields($this->s_hidden_fields) ) @@ -107,8 +128,7 @@ class acp_styles $this->action_cache(); return; } - global $user; - trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); } /** @@ -116,17 +136,15 @@ class acp_styles */ function action_cache() { - global $cache, $auth, $user; - - $cache->purge(); + $this->cache->purge(); // Clear permissions - $auth->acl_clear_prefetch(); + $this->auth->acl_clear_prefetch(); cache_moderators(); add_log('admin', 'LOG_PURGE_CACHE'); - trigger_error($user->lang['PURGED_CACHE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); + trigger_error($this->user->lang['PURGED_CACHE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); } /** @@ -134,8 +152,6 @@ class acp_styles */ function action_install() { - global $user; - // Get list of styles to install $dirs = $this->request_vars('dir', '', true); @@ -166,23 +182,23 @@ class acp_styles $last_installed = $style['style_id']; $installed_names[] = $style['style_name']; $installed_dirs[] = $style['style_path']; - $messages[] = sprintf($user->lang['STYLE_INSTALLED'], htmlspecialchars($style['style_name'])); + $messages[] = sprintf($this->user->lang['STYLE_INSTALLED'], htmlspecialchars($style['style_name'])); } } if (!$found) { - $messages[] = sprintf($user->lang['STYLE_NOT_INSTALLED'], htmlspecialchars($dir)); + $messages[] = sprintf($this->user->lang['STYLE_NOT_INSTALLED'], htmlspecialchars($dir)); } } // Show message if (!count($messages)) { - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } $message = implode('
', $messages); - $message .= '

' . sprintf($user->lang['STYLE_INSTALLED_RETURN_STYLES'], $this->u_base_action . '&mode=style'); - $message .= '

' . sprintf($user->lang['STYLE_INSTALLED_RETURN_UNINSTALLED'], $this->u_base_action . '&mode=install'); + $message .= '

' . sprintf($this->user->lang['STYLE_INSTALLED_RETURN_STYLES'], $this->u_base_action . '&mode=style'); + $message .= '

' . sprintf($this->user->lang['STYLE_INSTALLED_RETURN_UNINSTALLED'], $this->u_base_action . '&mode=install'); trigger_error($message, E_USER_NOTICE); } @@ -191,8 +207,6 @@ class acp_styles */ function action_uninstall() { - global $user, $config, $template, $request; - // Get list of styles to uninstall $ids = $this->request_vars('id', 0, true); @@ -200,7 +214,7 @@ class acp_styles if (confirm_box(true)) { // Uninstall - $this->action_uninstall_confirmed($ids, $request->variable('confirm_delete_files', false)); + $this->action_uninstall_confirmed($ids, $this->request->variable('confirm_delete_files', false)); return; } @@ -209,8 +223,8 @@ class acp_styles 'action' => 'uninstall', 'ids' => $ids )); - $template->assign_var('S_CONFIRM_DELETE', true); - confirm_box(false, $user->lang['CONFIRM_UNINSTALL_STYLES'], $s_hidden, 'acp_styles.html'); + $this->template->assign_var('S_CONFIRM_DELETE', true); + confirm_box(false, $this->user->lang['CONFIRM_UNINSTALL_STYLES'], $s_hidden, 'acp_styles.html'); // Canceled - show styles list $this->frontend(); @@ -224,9 +238,7 @@ class acp_styles */ function action_uninstall_confirmed($ids, $delete_files) { - global $db, $user, $cache, $config; - - $default = $config['default_style']; + $default = $this->default_style; $uninstalled = array(); $messages = array(); @@ -235,11 +247,11 @@ class acp_styles { if (!$id) { - trigger_error($user->lang['INVALID_STYLE_ID'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['INVALID_STYLE_ID'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($id == $default) { - trigger_error($user->lang['UNINSTALL_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['UNINSTALL_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); } $uninstalled[$id] = false; } @@ -250,10 +262,10 @@ class acp_styles FROM ' . STYLES_TABLE . ' WHERE style_id IN (' . implode(', ', $ids) . ') ORDER BY style_id DESC'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - $rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); // Uinstall each style $uninstalled = array(); @@ -266,20 +278,20 @@ class acp_styles $messages[] = $result; continue; } - $messages[] = sprintf($user->lang['STYLE_UNINSTALLED'], $style['style_name']); + $messages[] = sprintf($this->user->lang['STYLE_UNINSTALLED'], $style['style_name']); $uninstalled[] = $style['style_name']; // Attempt to delete files if ($delete_files) { - $messages[] = sprintf($user->lang[$this->delete_style_files($style['style_path']) ? 'DELETE_STYLE_FILES_SUCCESS' : 'DELETE_STYLE_FILES_FAILED'], $style['style_name']); + $messages[] = sprintf($this->user->lang[$this->delete_style_files($style['style_path']) ? 'DELETE_STYLE_FILES_SUCCESS' : 'DELETE_STYLE_FILES_FAILED'], $style['style_name']); } } if (empty($messages)) { // Nothing to uninstall? - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } // Log action @@ -289,7 +301,7 @@ class acp_styles } // Clear cache - $cache->purge(); + $this->cache->purge(); // Show message trigger_error(implode('
', $messages) . adm_back_link($this->u_action), E_USER_NOTICE); @@ -300,8 +312,6 @@ class acp_styles */ function action_activate() { - global $user, $config, $cache, $db; - // Get list of styles to activate $ids = $this->request_vars('id', 0, true); @@ -309,10 +319,10 @@ class acp_styles $sql = 'UPDATE ' . STYLES_TABLE . ' SET style_active = 1 WHERE style_id IN (' . implode(', ', $ids) . ')'; - $db->sql_query($sql); + $this->db->sql_query($sql); // Purge cache - $cache->destroy('sql', STYLES_TABLE); + $this->cache->destroy('sql', STYLES_TABLE); // Show styles list $this->frontend(); @@ -323,17 +333,15 @@ class acp_styles */ function action_deactivate() { - global $user, $config, $cache, $db; - // Get list of styles to deactivate $ids = $this->request_vars('id', 0, true); // Check for default style foreach ($ids as $id) { - if ($id == $config['default_style']) + if ($id == $this->default_style) { - trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); } } @@ -341,16 +349,16 @@ class acp_styles $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0 WHERE user_style IN (' . implode(', ', $ids) . ')'; - $db->sql_query($sql); + $this->db->sql_query($sql); // Deactivate styles $sql = 'UPDATE ' . STYLES_TABLE . ' SET style_active = 0 WHERE style_id IN (' . implode(', ', $ids) . ')'; - $db->sql_query($sql); + $this->db->sql_query($sql); // Purge cache - $cache->destroy('sql', STYLES_TABLE); + $this->cache->destroy('sql', STYLES_TABLE); // Show styles list $this->frontend(); @@ -361,12 +369,10 @@ class acp_styles */ function action_details() { - global $user, $config, $db, $request, $template, $cache; - - $id = $request->variable('id', 0); + $id = $this->request->variable('id', 0); if (!$id) { - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } // Get all styles @@ -386,19 +392,19 @@ class acp_styles if ($style === false) { - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } // Find all available parent styles $list = $this->find_possible_parents($styles, $id); // Change data - if ($request->variable('update', false)) + if ($this->request->variable('update', false)) { $update = array( - 'style_name' => trim($request->variable('style_name', $style['style_name'])), - 'style_parent_id' => $request->variable('style_parent', (int) $style['style_parent_id']), - 'style_active' => $request->variable('style_active', (int) $style['style_active']), + 'style_name' => trim($this->request->variable('style_name', $style['style_name'])), + 'style_parent_id' => $this->request->variable('style_parent', (int) $style['style_parent_id']), + 'style_active' => $this->request->variable('style_active', (int) $style['style_active']), ); $update_action = $this->u_action . '&action=details&id=' . $id; @@ -407,13 +413,13 @@ class acp_styles { if (!strlen($update['style_name'])) { - trigger_error($user->lang['STYLE_ERR_STYLE_NAME'] . adm_back_link($update_action), E_USER_WARNING); + trigger_error($this->user->lang['STYLE_ERR_STYLE_NAME'] . adm_back_link($update_action), E_USER_WARNING); } foreach ($styles as $row) { if ($row['style_name'] == $update['style_name']) { - trigger_error($user->lang['STYLE_ERR_NAME_EXIST'] . adm_back_link($update_action), E_USER_WARNING); + trigger_error($this->user->lang['STYLE_ERR_NAME_EXIST'] . adm_back_link($update_action), E_USER_WARNING); } } } @@ -439,7 +445,7 @@ class acp_styles } if (!$found) { - trigger_error($user->lang['STYLE_ERR_INVALID_PARENT'] . adm_back_link($update_action), E_USER_WARNING); + trigger_error($this->user->lang['STYLE_ERR_INVALID_PARENT'] . adm_back_link($update_action), E_USER_WARNING); } } else @@ -455,9 +461,9 @@ class acp_styles // Check style_active if ($update['style_active'] != $style['style_active']) { - if (!$update['style_active'] && $config['default_style'] == $style['style_id']) + if (!$update['style_active'] && $this->default_style == $style['style_id']) { - trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($update_action), E_USER_WARNING); + trigger_error($this->user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($update_action), E_USER_WARNING); } } else @@ -469,9 +475,9 @@ class acp_styles if (count($update)) { $sql = 'UPDATE ' . STYLES_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $update) . " + SET ' . $this->db->sql_build_array('UPDATE', $update) . " WHERE style_id = $id"; - $db->sql_query($sql); + $this->db->sql_query($sql); $style = array_merge($style, $update); @@ -482,22 +488,22 @@ class acp_styles if ($this->update_styles_tree(&$styles, $style)) { // Something was changed in styles tree, purge all cache - $cache->purge(); + $this->cache->purge(); } } add_log('admin', 'LOG_STYLE_EDIT_DETAILS', $style['style_name']); } // Update default style - $default = $request->variable('style_default', 0); + $default = $this->request->variable('style_default', 0); if ($default) { if (!$style['style_active']) { - trigger_error($user->lang['STYLE_DEFAULT_CHANGE_INACTIVE'] . adm_back_link($update_action), E_USER_WARNING); + trigger_error($this->user->lang['STYLE_DEFAULT_CHANGE_INACTIVE'] . adm_back_link($update_action), E_USER_WARNING); } set_config('default_style', $id); - $cache->purge(); + $this->cache->purge(); } // Show styles list @@ -508,7 +514,7 @@ class acp_styles // Show parent styles foreach ($list as $row) { - $template->assign_block_vars('parent_styles', array( + $this->template->assign_block_vars('parent_styles', array( 'STYLE_ID' => $row['style_id'], 'STYLE_NAME' => htmlspecialchars($row['style_name']), 'LEVEL' => $row['level'], @@ -518,7 +524,7 @@ class acp_styles } // Show style details - $template->assign_vars(array( + $this->template->assign_vars(array( 'S_STYLE_DETAILS' => true, 'STYLE_ID' => $style['style_id'], 'STYLE_NAME' => htmlspecialchars($style['style_name']), @@ -526,7 +532,7 @@ class acp_styles 'STYLE_COPYRIGHT' => strip_tags($style['style_copyright']), 'STYLE_PARENT' => $style['style_parent_id'], 'S_STYLE_ACTIVE' => $style['style_active'], - 'S_STYLE_DEFAULT' => ($style['style_id'] == $config['default_style']) + 'S_STYLE_DEFAULT' => ($style['style_id'] == $this->default_style) ) ); } @@ -536,14 +542,12 @@ class acp_styles */ function show_installed() { - global $user, $template; - // Get all installed styles $styles = $this->get_styles(); if (!count($styles)) { - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } usort($styles, 'acp_styles::sort_styles'); @@ -560,7 +564,7 @@ class acp_styles // Set up styles list variables // Addons should increase this number and update template variable $this->styles_list_cols = 4; - $template->assign_var('STYLES_LIST_COLS', $this->styles_list_cols); + $this->template->assign_var('STYLES_LIST_COLS', $this->styles_list_cols); // Show styles list $this->show_styles_list(&$styles, 0, 0); @@ -570,29 +574,29 @@ class acp_styles { if (empty($style['_shown'])) { - $style['_note'] = sprintf($user->lang['REQUIRES_STYLE'], htmlspecialchars($style['style_parent_tree'])); + $style['_note'] = sprintf($this->user->lang['REQUIRES_STYLE'], htmlspecialchars($style['style_parent_tree'])); $this->list_style($style, 0); } } // Add buttons - $template->assign_block_vars('extra_actions', array( + $this->template->assign_block_vars('extra_actions', array( 'ACTION_NAME' => 'activate', - 'L_ACTION' => $user->lang['STYLE_ACTIVATE'], + 'L_ACTION' => $this->user->lang['STYLE_ACTIVATE'], ) ); - $template->assign_block_vars('extra_actions', array( + $this->template->assign_block_vars('extra_actions', array( 'ACTION_NAME' => 'deactivate', - 'L_ACTION' => $user->lang['STYLE_DEACTIVATE'], + 'L_ACTION' => $this->user->lang['STYLE_DEACTIVATE'], ) ); if (isset($this->style_counters) && $this->style_counters['total'] > 1) { - $template->assign_block_vars('extra_actions', array( + $this->template->assign_block_vars('extra_actions', array( 'ACTION_NAME' => 'uninstall', - 'L_ACTION' => $user->lang['STYLE_UNINSTALL'], + 'L_ACTION' => $this->user->lang['STYLE_UNINSTALL'], ) ); } @@ -603,21 +607,19 @@ class acp_styles */ function show_available() { - global $user, $template; - // Get list of styles $styles = $this->find_available(true); // Show styles if (empty($styles)) { - trigger_error($user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); + trigger_error($this->user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); } usort($styles, 'acp_styles::sort_styles'); $this->styles_list_cols = 3; - $template->assign_vars(array( + $this->template->assign_vars(array( 'STYLES_LIST_COLS' => $this->styles_list_cols, 'STYLES_LIST_HIDE_COUNT' => true ) @@ -658,9 +660,9 @@ class acp_styles // Add button if (isset($this->style_counters) && $this->style_counters['caninstall'] > 0) { - $template->assign_block_vars('extra_actions', array( + $this->template->assign_block_vars('extra_actions', array( 'ACTION_NAME' => 'install', - 'L_ACTION' => $user->lang['INSTALL_STYLES'], + 'L_ACTION' => $this->user->lang['INSTALL_STYLES'], ) ); } @@ -674,8 +676,6 @@ class acp_styles */ function find_available($all) { - global $user; - // Get list of installed styles $installed = $this->get_styles(); @@ -743,7 +743,7 @@ class acp_styles { // Parent style is not installed yet $style['_available'] = false; - $style['_note'] = sprintf($user->lang['REQUIRES_STYLE'], htmlspecialchars($parent)); + $style['_note'] = sprintf($this->user->lang['REQUIRES_STYLE'], htmlspecialchars($parent)); } } @@ -821,11 +821,10 @@ class acp_styles } if ($update) { - global $db; $sql = 'UPDATE ' . STYLES_TABLE . " - SET style_parent_tree = '" . $db->sql_escape($parent_tree) . "' + SET style_parent_tree = '" . $this->db->sql_escape($parent_tree) . "' WHERE style_parent_id = {$parent_id}"; - $db->sql_query($sql); + $this->db->sql_query($sql); $updated = true; } return $updated; @@ -869,8 +868,6 @@ class acp_styles */ function list_style($style, $level) { - global $template, $config, $db, $user, $phpbb_root_path, $phpEx; - // Mark row as shown if (!empty($style['_shown'])) return; $style['_shown'] = true; @@ -886,7 +883,7 @@ class acp_styles 'STYLE_ACTIVE' => $style['style_active'], // Additional data - 'DEFAULT' => ($style['style_id'] && $style['style_id'] == $config['default_style']), + 'DEFAULT' => ($style['style_id'] && $style['style_id'] == $this->default_style), 'USERS' => (isset($style['_users'])) ? $style['_users'] : '', 'LEVEL' => $level, 'PADDING' => (4 + 16 * $level), @@ -909,31 +906,31 @@ class acp_styles // Details $actions[] = array( 'U_ACTION' => $this->u_action . '&action=details&id=' . $style['style_id'], - 'L_ACTION' => $user->lang['DETAILS'] + 'L_ACTION' => $this->user->lang['DETAILS'] ); // Activate $actions[] = array( 'U_ACTION' => $this->u_action . '&action=' . ($style['style_active'] ? 'de' : '') . 'activate&id=' . $style['style_id'], - 'L_ACTION' => $user->lang['STYLE_' . ($style['style_active'] ? 'DE' : '') . 'ACTIVATE'] + 'L_ACTION' => $this->user->lang['STYLE_' . ($style['style_active'] ? 'DE' : '') . 'ACTIVATE'] ); /* // Export $actions[] = array( 'U_ACTION' => $this->u_action . '&action=export&id=' . $style['style_id'], - 'L_ACTION' => $user->lang['EXPORT'] + 'L_ACTION' => $this->user->lang['EXPORT'] ); */ // Uninstall $actions[] = array( 'U_ACTION' => $this->u_action . '&action=uninstall&id=' . $style['style_id'], - 'L_ACTION' => $user->lang['STYLE_UNINSTALL'] + 'L_ACTION' => $this->user->lang['STYLE_UNINSTALL'] ); // Preview $actions[] = array( - 'U_ACTION' => append_sid("{$phpbb_root_path}index.$phpEx", 'style=' . $style['style_id']), - 'L_ACTION' => $user->lang['PREVIEW'] + 'U_ACTION' => append_sid($this->phpbb_root_path . 'index.' . $this->phpEx, 'style=' . $style['style_id']), + 'L_ACTION' => $this->user->lang['PREVIEW'] ); } else @@ -942,14 +939,14 @@ class acp_styles if (empty($style['_available'])) { $actions[] = array( - 'HTML' => $user->lang['CANNOT_BE_INSTALLED'] + 'HTML' => $this->user->lang['CANNOT_BE_INSTALLED'] ); } else { $actions[] = array( 'U_ACTION' => $this->u_action . '&action=install&dir=' . urlencode($style['style_path']), - 'L_ACTION' => $user->lang['INSTALL_STYLE'] + 'L_ACTION' => $this->user->lang['INSTALL_STYLE'] ); } } @@ -957,10 +954,10 @@ class acp_styles // todo: add hook // Assign template variables - $template->assign_block_vars('styles_list', $row); + $this->template->assign_block_vars('styles_list', $row); foreach($actions as $action) { - $template->assign_block_vars('styles_list.actions', $action); + $this->template->assign_block_vars('styles_list.actions', $action); } // Increase counters @@ -987,10 +984,9 @@ class acp_styles */ function welcome_message($title, $description) { - global $user, $template; - $template->assign_vars(array( - 'L_TITLE' => (isset($user->lang[$title])) ? $user->lang[$title] : $title, - 'L_EXPLAIN' => (isset($user->lang[$description])) ? $user->lang[$description] : $description + $this->template->assign_vars(array( + 'L_TITLE' => (isset($this->user->lang[$title])) ? $this->user->lang[$title] : $title, + 'L_EXPLAIN' => (isset($this->user->lang[$description])) ? $this->user->lang[$description] : $description ) ); } @@ -1084,8 +1080,6 @@ class acp_styles */ function install_style($style) { - global $db; - // Generate row $sql_ary = array(); foreach ($style as $key => $value) @@ -1097,15 +1091,15 @@ class acp_styles } // Add to database - $db->sql_transaction('begin'); + $this->db->sql_transaction('begin'); $sql = 'INSERT INTO ' . STYLES_TABLE . ' - ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); + ' . $this->db->sql_build_array('INSERT', $sql_ary); + $this->db->sql_query($sql); - $id = $db->sql_nextid(); + $id = $this->db->sql_nextid(); - $db->sql_transaction('commit'); + $this->db->sql_transaction('commit'); add_log('admin', 'LOG_STYLE_ADD', $sql_ary['style_name']); @@ -1119,14 +1113,12 @@ class acp_styles */ function get_styles() { - global $db; - $sql = 'SELECT * FROM ' . STYLES_TABLE; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); - $rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); + $rows = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); return $rows; } @@ -1138,19 +1130,17 @@ class acp_styles */ function get_users() { - global $db; - $sql = 'SELECT user_style, COUNT(user_style) AS style_count FROM ' . USERS_TABLE . ' GROUP BY user_style'; - $result = $db->sql_query($sql); + $result = $this->db->sql_query($sql); $style_count = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = $this->db->sql_fetchrow($result)) { $style_count[$row['user_style']] = $row['style_count']; } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); return $style_count; } @@ -1163,35 +1153,33 @@ class acp_styles */ function uninstall_style($style) { - global $db, $user; - $id = $style['style_id']; $path = $style['style_path']; // Check if style has child styles $sql = 'SELECT style_id FROM ' . STYLES_TABLE . ' - WHERE style_parent_id = ' . $id . " OR style_parent_tree = '" . $db->sql_escape($path) . "'"; - $result = $db->sql_query($sql); + WHERE style_parent_id = ' . $id . " OR style_parent_tree = '" . $this->db->sql_escape($path) . "'"; + $result = $this->db->sql_query($sql); - $conflict = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $conflict = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if ($conflict !== false) { - return sprintf($user->lang['STYLE_UNINSTALL_DEPENDENT'], $style['style_name']); + return sprintf($this->user->lang['STYLE_UNINSTALL_DEPENDENT'], $style['style_name']); } // Change default style for users $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0 WHERE user_style = ' . $id; - $db->sql_query($sql); + $this->db->sql_query($sql); // Uninstall style $sql = 'DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $id; - $db->sql_query($sql); + $this->db->sql_query($sql); return true; } @@ -1253,10 +1241,8 @@ class acp_styles */ function request_vars($name, $default, $error = false) { - global $request, $user; - - $item = $request->variable($name, $default); - $items = $request->variable($name . 's', array($default)); + $item = $this->request->variable($name, $default); + $items = $this->request->variable($name . 's', array($default)); if (count($items) == 1 && $items[0] == $default) { @@ -1270,7 +1256,7 @@ class acp_styles if ($error && !count($items)) { - trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } return $items; -- cgit v1.2.1 From e558a3cb05777c838fcf09fc82f99c4d069ac62c Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 3 Apr 2012 00:18:52 +0300 Subject: [ticket/10752] Pass-by-reference fix for acp_styles Fixing pass-by-reference bug in acp_styles PHPBB3-10752 --- phpBB/includes/acp/acp_styles.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index c7f66b7253..dc14b42d5f 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -567,7 +567,7 @@ class acp_styles $this->template->assign_var('STYLES_LIST_COLS', $this->styles_list_cols); // Show styles list - $this->show_styles_list(&$styles, 0, 0); + $this->show_styles_list($styles, 0, 0); // Show styles with invalid inherits_id foreach ($styles as $style) @@ -643,8 +643,8 @@ class acp_styles } if (!$has_parent) { - $this->list_style(&$style, 0); - $this->show_available_child_styles(&$styles, $style['style_name'], 1); + $this->list_style($style, 0); + $this->show_available_child_styles($styles, $style['style_name'], 1); } } @@ -763,14 +763,14 @@ class acp_styles * @param int $parent parent style id * @param int $level style inheritance level */ - function show_styles_list($styles, $parent, $level) + function show_styles_list(&$styles, $parent, $level) { foreach ($styles as &$style) { if (empty($style['_shown']) && $style['style_parent_id'] == $parent) { - $this->list_style(&$style, $level); - $this->show_styles_list(&$styles, $style['style_id'], $level + 1); + $this->list_style($style, $level); + $this->show_styles_list($styles, $style['style_id'], $level + 1); } } } @@ -782,14 +782,14 @@ class acp_styles * @param string $name Name of parent style * @param string $level Styles tree level */ - function show_available_child_styles($styles, $name, $level) + function show_available_child_styles(&$styles, $name, $level) { foreach ($styles as &$style) { if (empty($style['_shown']) && $style['_inherit_name'] == $name) { - $this->list_style(&$style, $level); - $this->show_available_child_styles(&$styles, $style['style_name'], $level + 1); + $this->list_style($style, $level); + $this->show_available_child_styles($styles, $style['style_name'], $level + 1); } } } @@ -801,7 +801,7 @@ class acp_styles * @param array $style Current style, false if root * @returns true if something was updated, false if not */ - function update_styles_tree($styles, $style = false) + function update_styles_tree(&$styles, $style = false) { $parent_id = ($style === false) ? 0 : $style['style_id']; $parent_tree = ($style === false) ? '' : ($style['style_parent_tree'] == '' ? '' : $style['style_parent_tree']) . $style['style_path']; @@ -816,7 +816,7 @@ class acp_styles $row['style_parent_tree'] = $parent_tree; $update = true; } - $updated |= $this->update_styles_tree(&$styles, $row); + $updated |= $this->update_styles_tree($styles, $row); } } if ($update) @@ -866,7 +866,7 @@ class acp_styles * @param array $style style row * @param array $level style inheritance level */ - function list_style($style, $level) + function list_style(&$style, $level) { // Mark row as shown if (!empty($style['_shown'])) return; -- cgit v1.2.1 From a46b5480e1e3a3050be8deae870a6c74e1d76c9d Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 3 Apr 2012 00:19:16 +0300 Subject: [ticket/10752] More fixes for acp_styles Fixing return doc blocks, spacing, incorrect sorting function and other minor fixes PHPBB3-10752 --- phpBB/includes/acp/acp_styles.php | 203 +++++++++++++++++++------------------- 1 file changed, 101 insertions(+), 102 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index dc14b42d5f..2306e7d41c 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -84,7 +84,7 @@ class acp_styles 'S_HIDDEN_FIELDS' => build_hidden_fields($this->s_hidden_fields) ) ); - + // Execute actions switch ($action) { @@ -107,7 +107,7 @@ class acp_styles $this->frontend(); } } - + /** * Main page */ @@ -130,7 +130,7 @@ class acp_styles } trigger_error($this->user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING); } - + /** * Purge cache */ @@ -143,10 +143,10 @@ class acp_styles cache_moderators(); add_log('admin', 'LOG_PURGE_CACHE'); - + trigger_error($this->user->lang['PURGED_CACHE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); } - + /** * Install style(s) */ @@ -154,10 +154,10 @@ class acp_styles { // Get list of styles to install $dirs = $this->request_vars('dir', '', true); - + // Get list of styles that can be installed $styles = $this->find_available(false); - + // Install each style $messages = array(); $installed_names = array(); @@ -190,7 +190,7 @@ class acp_styles $messages[] = sprintf($this->user->lang['STYLE_NOT_INSTALLED'], htmlspecialchars($dir)); } } - + // Show message if (!count($messages)) { @@ -201,7 +201,7 @@ class acp_styles $message .= '

' . sprintf($this->user->lang['STYLE_INSTALLED_RETURN_UNINSTALLED'], $this->u_base_action . '&mode=install'); trigger_error($message, E_USER_NOTICE); } - + /** * Confirm styles removal */ @@ -209,7 +209,7 @@ class acp_styles { // Get list of styles to uninstall $ids = $this->request_vars('id', 0, true); - + // Check if confirmation box was submitted if (confirm_box(true)) { @@ -217,7 +217,7 @@ class acp_styles $this->action_uninstall_confirmed($ids, $this->request->variable('confirm_delete_files', false)); return; } - + // Confirm box $s_hidden = build_hidden_fields(array( 'action' => 'uninstall', @@ -225,7 +225,7 @@ class acp_styles )); $this->template->assign_var('S_CONFIRM_DELETE', true); confirm_box(false, $this->user->lang['CONFIRM_UNINSTALL_STYLES'], $s_hidden, 'acp_styles.html'); - + // Canceled - show styles list $this->frontend(); } @@ -314,7 +314,7 @@ class acp_styles { // Get list of styles to activate $ids = $this->request_vars('id', 0, true); - + // Activate styles $sql = 'UPDATE ' . STYLES_TABLE . ' SET style_active = 1 @@ -323,7 +323,7 @@ class acp_styles // Purge cache $this->cache->destroy('sql', STYLES_TABLE); - + // Show styles list $this->frontend(); } @@ -363,7 +363,7 @@ class acp_styles // Show styles list $this->frontend(); } - + /** * Show style details */ @@ -374,11 +374,11 @@ class acp_styles { trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } - + // Get all styles $styles = $this->get_styles(); - usort($styles, 'acp_styles::sort_styles'); - + usort($styles, array($this, 'sort_styles')); + // Find current style $style = false; foreach ($styles as $row) @@ -394,10 +394,10 @@ class acp_styles { trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } - + // Find all available parent styles $list = $this->find_possible_parents($styles, $id); - + // Change data if ($this->request->variable('update', false)) { @@ -407,7 +407,7 @@ class acp_styles 'style_active' => $this->request->variable('style_active', (int) $style['style_active']), ); $update_action = $this->u_action . '&action=details&id=' . $id; - + // Check style name if ($update['style_name'] != $style['style_name']) { @@ -427,7 +427,7 @@ class acp_styles { unset($update['style_name']); } - + // Check parent style id if ($update['style_parent_id'] != $style['style_parent_id']) { @@ -457,7 +457,7 @@ class acp_styles { unset($update['style_parent_id']); } - + // Check style_active if ($update['style_active'] != $style['style_active']) { @@ -470,7 +470,7 @@ class acp_styles { unset($update['style_active']); } - + // Update data if (count($update)) { @@ -478,14 +478,14 @@ class acp_styles SET ' . $this->db->sql_build_array('UPDATE', $update) . " WHERE style_id = $id"; $this->db->sql_query($sql); - + $style = array_merge($style, $update); - + if (isset($update['style_parent_id'])) { // Update styles tree $styles = $this->get_styles(); - if ($this->update_styles_tree(&$styles, $style)) + if ($this->update_styles_tree($styles, $style)) { // Something was changed in styles tree, purge all cache $this->cache->purge(); @@ -493,7 +493,7 @@ class acp_styles } add_log('admin', 'LOG_STYLE_EDIT_DETAILS', $style['style_name']); } - + // Update default style $default = $this->request->variable('style_default', 0); if ($default) @@ -505,12 +505,12 @@ class acp_styles set_config('default_style', $id); $this->cache->purge(); } - + // Show styles list $this->frontend(); return; } - + // Show parent styles foreach ($list as $row) { @@ -522,7 +522,7 @@ class acp_styles ) ); } - + // Show style details $this->template->assign_vars(array( 'S_STYLE_DETAILS' => true, @@ -549,18 +549,18 @@ class acp_styles { trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } - - usort($styles, 'acp_styles::sort_styles'); + + usort($styles, array($this, 'sort_styles')); // Get users $users = $this->get_users(); - + // Add users counter to rows foreach ($styles as &$style) { $style['_users'] = isset($users[$style['style_id']]) ? $users[$style['style_id']] : 0; } - + // Set up styles list variables // Addons should increase this number and update template variable $this->styles_list_cols = 4; @@ -568,7 +568,7 @@ class acp_styles // Show styles list $this->show_styles_list($styles, 0, 0); - + // Show styles with invalid inherits_id foreach ($styles as $style) { @@ -609,14 +609,14 @@ class acp_styles { // Get list of styles $styles = $this->find_available(true); - + // Show styles if (empty($styles)) { trigger_error($this->user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); } - - usort($styles, 'acp_styles::sort_styles'); + + usort($styles, array($this, 'sort_styles')); $this->styles_list_cols = 3; $this->template->assign_vars(array( @@ -624,7 +624,7 @@ class acp_styles 'STYLES_LIST_HIDE_COUNT' => true ) ); - + // Show styles foreach ($styles as &$style) { @@ -647,16 +647,16 @@ class acp_styles $this->show_available_child_styles($styles, $style['style_name'], 1); } } - + // Show styles that do not have parent style in styles list foreach ($styles as $style) { if (empty($style['_shown'])) { - $this->list_style(&$style, 0); + $this->list_style($style, 0); } } - + // Add button if (isset($this->style_counters) && $this->style_counters['caninstall'] > 0) { @@ -667,12 +667,12 @@ class acp_styles ); } } - + /** * Find styles available for installation * * @param bool $all if true, function will return all installable styles. if false, function will return only styles that can be installed - * @returns array list of styles + * @return array List of styles */ function find_available($all) { @@ -691,10 +691,10 @@ class acp_styles 'tree' => (strlen($style['style_parent_tree']) ? $style['style_parent_tree'] . '/' : '') . $style['style_path'], ); } - + // Get list of directories $dirs = $this->find_style_dirs(); - + // Find styles that can be installed $styles = array(); foreach ($dirs as $dir) @@ -746,7 +746,7 @@ class acp_styles $style['_note'] = sprintf($this->user->lang['REQUIRES_STYLE'], htmlspecialchars($parent)); } } - + if ($all || $style['_available']) { $styles[] = $style; @@ -755,7 +755,7 @@ class acp_styles return $styles; } - + /** * Show styles list * @@ -774,7 +774,7 @@ class acp_styles } } } - + /** * Show available styles tree * @@ -793,13 +793,13 @@ class acp_styles } } } - + /** * Update styles tree * * @param array $styles Styles list, passed as reference * @param array $style Current style, false if root - * @returns true if something was updated, false if not + * @return bool True if something was updated, false if not */ function update_styles_tree(&$styles, $style = false) { @@ -829,7 +829,7 @@ class acp_styles } return $updated; } - + /** * Find all possible parent styles for style * @@ -837,7 +837,7 @@ class acp_styles * @param int $id id of style * @param int $parent current parent style id * @param int $level current tree level - * @returns array of style ids, names and levels + * @return array Style ids, names and levels */ function find_possible_parents($styles, $id = -1, $parent = 0, $level = 0) { @@ -859,7 +859,7 @@ class acp_styles } return $results; } - + /** * Show item in styles list * @@ -871,7 +871,7 @@ class acp_styles // Mark row as shown if (!empty($style['_shown'])) return; $style['_shown'] = true; - + // Generate template variables $actions = array(); $row = array( @@ -881,7 +881,7 @@ class acp_styles 'STYLE_PATH' => htmlspecialchars($style['style_path']), 'STYLE_COPYRIGHT' => strip_tags($style['style_copyright']), 'STYLE_ACTIVE' => $style['style_active'], - + // Additional data 'DEFAULT' => ($style['style_id'] && $style['style_id'] == $this->default_style), 'USERS' => (isset($style['_users'])) ? $style['_users'] : '', @@ -889,20 +889,20 @@ class acp_styles 'PADDING' => (4 + 16 * $level), 'SHOW_COPYRIGHT' => ($style['style_id']) ? false : true, 'STYLE_PATH_FULL' => htmlspecialchars($this->styles_path_absolute . '/' . $style['style_path']) . '/', - + // Comment to show below style 'COMMENT' => (isset($style['_note'])) ? $style['_note'] : '', - + // The following variables should be used by hooks to add custom HTML code 'EXTRA' => '', 'EXTRA_OPTIONS' => '' ); - + // Status specific data if ($style['style_id']) { // Style is installed - + // Details $actions[] = array( 'U_ACTION' => $this->u_action . '&action=details&id=' . $style['style_id'], @@ -926,7 +926,7 @@ class acp_styles 'U_ACTION' => $this->u_action . '&action=uninstall&id=' . $style['style_id'], 'L_ACTION' => $this->user->lang['STYLE_UNINSTALL'] ); - + // Preview $actions[] = array( 'U_ACTION' => append_sid($this->phpbb_root_path . 'index.' . $this->phpEx, 'style=' . $style['style_id']), @@ -950,16 +950,16 @@ class acp_styles ); } } - + // todo: add hook - + // Assign template variables $this->template->assign_block_vars('styles_list', $row); foreach($actions as $action) { $this->template->assign_block_vars('styles_list.actions', $action); } - + // Increase counters $counter = ($style['style_id']) ? ($style['style_active'] ? 'active' : 'inactive') : (empty($style['_available']) ? 'cannotinstall' : 'caninstall'); if (!isset($this->style_counters)) @@ -972,10 +972,10 @@ class acp_styles 'cannotinstall' => 0 ); } - $this->style_counters[$counter] ++; - $this->style_counters['total'] ++; + $this->style_counters[$counter]++; + $this->style_counters['total']++; } - + /** * Show welcome message * @@ -990,11 +990,11 @@ class acp_styles ) ); } - + /** * Find all directories that have styles * - * @returns array of directory names + * @return array Directory names */ function find_style_dirs() { @@ -1021,7 +1021,7 @@ class acp_styles return $styles; } - + /** * Sort styles */ @@ -1037,19 +1037,18 @@ class acp_styles } return strcasecmp(isset($style1['style_name']) ? $style1['style_name'] : $style1['name'], isset($style2['style_name']) ? $style2['style_name'] : $style2['name']); } - + /** * Read style configuration file * * @param string $dir style directory - * @returns array of style data - * @returns false on error + * @return array|bool Style data, false on error */ function read_style_cfg($dir) { static $required = array('name', 'version', 'copyright'); $cfg = parse_cfg_file($this->styles_path . $dir . '/style.cfg'); - + // Check if it is a valid file foreach ($required as $key) { @@ -1058,7 +1057,7 @@ class acp_styles return false; } } - + // Check data if (!isset($cfg['parent']) || !is_string($cfg['parent']) || $cfg['parent'] == $cfg['name']) { @@ -1068,15 +1067,15 @@ class acp_styles { $cfg['template_bitfield'] = $this->default_bitfield(); } - + return $cfg; } - + /** * Install style * * @param $style style data - * @returns int style id + * @return int Style id */ function install_style($style) { @@ -1089,7 +1088,7 @@ class acp_styles $sql_ary[$key] = $value; } } - + // Add to database $this->db->sql_transaction('begin'); @@ -1102,18 +1101,18 @@ class acp_styles $this->db->sql_transaction('commit'); add_log('admin', 'LOG_STYLE_ADD', $sql_ary['style_name']); - + return $id; } /** * Lists all styles * - * @returns array of rows with styles data + * @return array Rows with styles data */ function get_styles() { - $sql = 'SELECT * + $sql = 'SELECT * FROM ' . STYLES_TABLE; $result = $this->db->sql_query($sql); @@ -1126,7 +1125,7 @@ class acp_styles /** * Count users for each style * - * @returns array of styles in following format: [style_id] = number of users + * @return array Styles in following format: [style_id] = number of users */ function get_users() { @@ -1135,33 +1134,33 @@ class acp_styles GROUP BY user_style'; $result = $this->db->sql_query($sql); - $style_count = array(); + $style_count = array(); while ($row = $this->db->sql_fetchrow($result)) { $style_count[$row['user_style']] = $row['style_count']; } $this->db->sql_freeresult($result); - + return $style_count; } - + /** * Uninstall style * * @param array $style Style data - * @returns true on success, error message on error + * @return bool|string True on success, error message on error */ function uninstall_style($style) { $id = $style['style_id']; $path = $style['style_path']; - + // Check if style has child styles - $sql = 'SELECT style_id + $sql = 'SELECT style_id FROM ' . STYLES_TABLE . ' - WHERE style_parent_id = ' . $id . " OR style_parent_tree = '" . $this->db->sql_escape($path) . "'"; + WHERE style_parent_id = ' . (int) $id . " OR style_parent_tree = '" . $this->db->sql_escape($path) . "'"; $result = $this->db->sql_query($sql); - + $conflict = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); @@ -1169,13 +1168,13 @@ class acp_styles { return sprintf($this->user->lang['STYLE_UNINSTALL_DEPENDENT'], $style['style_name']); } - + // Change default style for users $sql = 'UPDATE ' . USERS_TABLE . ' SET user_style = 0 WHERE user_style = ' . $id; $this->db->sql_query($sql); - + // Uninstall style $sql = 'DELETE FROM ' . STYLES_TABLE . ' WHERE style_id = ' . $id; @@ -1188,13 +1187,13 @@ class acp_styles * * @param string $path Style directory * @param string $dir Directory to remove inside style's directory - * @returns true on success, false on error + * @return bool True on success, false on error */ function delete_style_files($path, $dir = '') { $dirname = $this->styles_path . $path . $dir; $result = true; - + $dp = @opendir($dirname); if ($dp) @@ -1227,17 +1226,17 @@ class acp_styles { return false; } - + return $result; } - + /** * Get list of items from posted data * * @param string $name Variable name * @param $default Default value for array: string or number * @param bool $error If true, error will be triggered if list is empty - * @returns array of items + * @return array Items */ function request_vars($name, $default, $error = false) { @@ -1253,7 +1252,7 @@ class acp_styles { $items[] = $item; } - + if ($error && !count($items)) { trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); @@ -1265,7 +1264,7 @@ class acp_styles /** * Generates hardcoded bitfield * - * @returns bitfield string + * @return string Bitfield */ function default_bitfield() { @@ -1274,7 +1273,7 @@ class acp_styles { return $value; } - + // Hardcoded template bitfield to add for new templates $bitfield = new bitfield(); $bitfield->set(0); -- cgit v1.2.1 From f739d7accec1706abfd74352c876dd1f3fd02b09 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 3 Apr 2012 01:14:14 +0300 Subject: [ticket/10752] Changing private to protected variables in acp_styles Changing private to protected variables in acp_styles PHPBB3-10752 --- phpBB/includes/acp/acp_styles.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 2306e7d41c..2632c96660 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -28,14 +28,14 @@ class acp_styles var $styles_path_absolute = 'styles'; var $default_style = 0; - private $db = false; - private $user = false; - private $template = false; - private $request = false; - private $cache = false; - private $auth = false; - private $phpbb_root_path = false; - private $phpEx = false; + protected $db; + protected $user; + protected $template; + protected $request; + protected $cache; + protected $auth; + protected $phpbb_root_path; + protected $phpEx; function main($id, $mode) { -- cgit v1.2.1 From e27326a57bde7a73291b5e4787dbc17454d09b90 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Tue, 3 Apr 2012 14:26:38 +0300 Subject: [ticket/10752] Fixes for acp_styles Adding form token, changing functions to public/protected, fixing few more errors PHPBB3-10752 --- phpBB/includes/acp/acp_styles.php | 90 ++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 39 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 2632c96660..d33be274b4 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -20,13 +20,14 @@ if (!defined('IN_PHPBB')) */ class acp_styles { - var $u_action; - var $u_base_action; - var $s_hidden_fields; - var $mode; - var $styles_path; - var $styles_path_absolute = 'styles'; - var $default_style = 0; + public $u_action; + + protected $u_base_action; + protected $s_hidden_fields; + protected $mode; + protected $styles_path; + protected $styles_path_absolute = 'styles'; + protected $default_style = 0; protected $db; protected $user; @@ -37,7 +38,7 @@ class acp_styles protected $phpbb_root_path; protected $phpEx; - function main($id, $mode) + public function main($id, $mode) { global $db, $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request, $cache, $auth, $config; @@ -111,7 +112,7 @@ class acp_styles /** * Main page */ - function frontend() + protected function frontend() { // Check mode switch ($this->mode) @@ -134,7 +135,7 @@ class acp_styles /** * Purge cache */ - function action_cache() + protected function action_cache() { $this->cache->purge(); @@ -150,7 +151,7 @@ class acp_styles /** * Install style(s) */ - function action_install() + protected function action_install() { // Get list of styles to install $dirs = $this->request_vars('dir', '', true); @@ -205,7 +206,7 @@ class acp_styles /** * Confirm styles removal */ - function action_uninstall() + protected function action_uninstall() { // Get list of styles to uninstall $ids = $this->request_vars('id', 0, true); @@ -236,7 +237,7 @@ class acp_styles * @param array $ids List of style IDs * @param bool $delete_files If true, script will attempt to remove files for selected styles */ - function action_uninstall_confirmed($ids, $delete_files) + protected function action_uninstall_confirmed($ids, $delete_files) { $default = $this->default_style; $uninstalled = array(); @@ -310,7 +311,7 @@ class acp_styles /** * Activate styles */ - function action_activate() + protected function action_activate() { // Get list of styles to activate $ids = $this->request_vars('id', 0, true); @@ -331,7 +332,7 @@ class acp_styles /** * Deactivate styles */ - function action_deactivate() + protected function action_deactivate() { // Get list of styles to deactivate $ids = $this->request_vars('id', 0, true); @@ -367,7 +368,7 @@ class acp_styles /** * Show style details */ - function action_details() + protected function action_details() { $id = $this->request->variable('id', 0); if (!$id) @@ -398,9 +399,18 @@ class acp_styles // Find all available parent styles $list = $this->find_possible_parents($styles, $id); + // Add form key + $form_key = 'acp_styles'; + add_form_key($form_key); + // Change data if ($this->request->variable('update', false)) { + if (!check_form_key($form_key)) + { + trigger_error($this->user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); + } + $update = array( 'style_name' => trim($this->request->variable('style_name', $style['style_name'])), 'style_parent_id' => $this->request->variable('style_parent', (int) $style['style_parent_id']), @@ -540,7 +550,7 @@ class acp_styles /** * List installed styles */ - function show_installed() + protected function show_installed() { // Get all installed styles $styles = $this->get_styles(); @@ -605,7 +615,7 @@ class acp_styles /** * Show list of styles that can be installed */ - function show_available() + protected function show_available() { // Get list of styles $styles = $this->find_available(true); @@ -674,7 +684,7 @@ class acp_styles * @param bool $all if true, function will return all installable styles. if false, function will return only styles that can be installed * @return array List of styles */ - function find_available($all) + protected function find_available($all) { // Get list of installed styles $installed = $this->get_styles(); @@ -763,7 +773,7 @@ class acp_styles * @param int $parent parent style id * @param int $level style inheritance level */ - function show_styles_list(&$styles, $parent, $level) + protected function show_styles_list(&$styles, $parent, $level) { foreach ($styles as &$style) { @@ -782,7 +792,7 @@ class acp_styles * @param string $name Name of parent style * @param string $level Styles tree level */ - function show_available_child_styles(&$styles, $name, $level) + protected function show_available_child_styles(&$styles, $name, $level) { foreach ($styles as &$style) { @@ -801,7 +811,7 @@ class acp_styles * @param array $style Current style, false if root * @return bool True if something was updated, false if not */ - function update_styles_tree(&$styles, $style = false) + protected function update_styles_tree(&$styles, $style = false) { $parent_id = ($style === false) ? 0 : $style['style_id']; $parent_tree = ($style === false) ? '' : ($style['style_parent_tree'] == '' ? '' : $style['style_parent_tree']) . $style['style_path']; @@ -839,7 +849,7 @@ class acp_styles * @param int $level current tree level * @return array Style ids, names and levels */ - function find_possible_parents($styles, $id = -1, $parent = 0, $level = 0) + protected function find_possible_parents($styles, $id = -1, $parent = 0, $level = 0) { $results = array(); foreach ($styles as $style) @@ -866,7 +876,7 @@ class acp_styles * @param array $style style row * @param array $level style inheritance level */ - function list_style(&$style, $level) + protected function list_style(&$style, $level) { // Mark row as shown if (!empty($style['_shown'])) return; @@ -982,11 +992,11 @@ class acp_styles * @param string $title main title * @param string $description page description */ - function welcome_message($title, $description) + protected function welcome_message($title, $description) { $this->template->assign_vars(array( - 'L_TITLE' => (isset($this->user->lang[$title])) ? $this->user->lang[$title] : $title, - 'L_EXPLAIN' => (isset($this->user->lang[$description])) ? $this->user->lang[$description] : $description + 'L_TITLE' => $this->user->lang[$title], + 'L_EXPLAIN' => (isset($this->user->lang[$description])) ? $this->user->lang[$description] : '' ) ); } @@ -996,7 +1006,7 @@ class acp_styles * * @return array Directory names */ - function find_style_dirs() + protected function find_style_dirs() { $styles = array(); @@ -1025,7 +1035,7 @@ class acp_styles /** * Sort styles */ - function sort_styles($style1, $style2) + public function sort_styles($style1, $style2) { if ($style1['style_active'] != $style2['style_active']) { @@ -1044,7 +1054,7 @@ class acp_styles * @param string $dir style directory * @return array|bool Style data, false on error */ - function read_style_cfg($dir) + protected function read_style_cfg($dir) { static $required = array('name', 'version', 'copyright'); $cfg = parse_cfg_file($this->styles_path . $dir . '/style.cfg'); @@ -1077,7 +1087,7 @@ class acp_styles * @param $style style data * @return int Style id */ - function install_style($style) + protected function install_style($style) { // Generate row $sql_ary = array(); @@ -1110,7 +1120,7 @@ class acp_styles * * @return array Rows with styles data */ - function get_styles() + protected function get_styles() { $sql = 'SELECT * FROM ' . STYLES_TABLE; @@ -1127,7 +1137,7 @@ class acp_styles * * @return array Styles in following format: [style_id] = number of users */ - function get_users() + protected function get_users() { $sql = 'SELECT user_style, COUNT(user_style) AS style_count FROM ' . USERS_TABLE . ' @@ -1150,7 +1160,7 @@ class acp_styles * @param array $style Style data * @return bool|string True on success, error message on error */ - function uninstall_style($style) + protected function uninstall_style($style) { $id = $style['style_id']; $path = $style['style_path']; @@ -1189,7 +1199,7 @@ class acp_styles * @param string $dir Directory to remove inside style's directory * @return bool True on success, false on error */ - function delete_style_files($path, $dir = '') + protected function delete_style_files($path, $dir = '') { $dirname = $this->styles_path . $path . $dir; $result = true; @@ -1234,11 +1244,11 @@ class acp_styles * Get list of items from posted data * * @param string $name Variable name - * @param $default Default value for array: string or number + * @param string|int $default Default value for array * @param bool $error If true, error will be triggered if list is empty * @return array Items */ - function request_vars($name, $default, $error = false) + protected function request_vars($name, $default, $error = false) { $item = $this->request->variable($name, $default); $items = $this->request->variable($name . 's', array($default)); @@ -1262,11 +1272,13 @@ class acp_styles } /** - * Generates hardcoded bitfield + * Generates default bitfield + * + * This bitfield decides which bbcodes are defined in a template. * * @return string Bitfield */ - function default_bitfield() + protected function default_bitfield() { static $value; if (isset($value)) -- cgit v1.2.1 From bb628044071f40130cdfc632d7f5636a11711ae0 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Wed, 4 Apr 2012 13:13:12 +0300 Subject: [ticket/10762] Check for phpbb_version when installing style Check if phpbb_version exists when installing style. Do not warn users about installing outdated styles yet, that part of acp_styles will be changed in different branch. PHPBB3-10762 --- phpBB/includes/acp/acp_styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index d33be274b4..de1f678e38 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -1056,7 +1056,7 @@ class acp_styles */ protected function read_style_cfg($dir) { - static $required = array('name', 'version', 'copyright'); + static $required = array('name', 'phpbb_version', 'copyright'); $cfg = parse_cfg_file($this->styles_path . $dir . '/style.cfg'); // Check if it is a valid file -- cgit v1.2.1 From 701bf571dfffa171271d567759cf92c3830d159c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 29 May 2012 15:29:31 +0200 Subject: [ticket/10550] Sort not installed styles list in the styles section of the ACP. PHPBB3-10550 --- phpBB/includes/acp/acp_styles.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index d7b0484af8..47cd02bca7 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -667,7 +667,9 @@ inherit_from = {INHERIT_FROM} if ($name && !in_array($name, $installed)) { - $new_ary[] = array( + // The array key is used for sorting later on. + // $file is appended because $name doesn't have to be unique. + $new_ary[$name . $file] = array( 'path' => $file, 'name' => $name, 'copyright' => $items['copyright'], @@ -683,6 +685,8 @@ inherit_from = {INHERIT_FROM} if (sizeof($new_ary)) { + ksort($new_ary); + foreach ($new_ary as $cfg) { $template->assign_block_vars('uninstalled', array( -- cgit v1.2.1 From 85bcdbad468cd255a02d6c48b2dcd1d128978eed Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 16:19:01 +0200 Subject: [ticket/11012] Normalize $phpEx member vars to $php_ext PHPBB3-11012 --- phpBB/includes/acp/acp_styles.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 943bfe6a6f..d41ef571dd 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -36,11 +36,11 @@ class acp_styles protected $cache; protected $auth; protected $phpbb_root_path; - protected $phpEx; + protected $php_ext; public function main($id, $mode) { - global $db, $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request, $cache, $auth, $config; + global $db, $user, $phpbb_admin_path, $phpbb_root_path, $php_ext, $template, $request, $cache, $auth, $config; $this->db = $db; $this->user = $user; @@ -50,12 +50,12 @@ class acp_styles $this->auth = $auth; $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->default_style = $config['default_style']; $this->styles_path = $this->phpbb_root_path . $this->styles_path_absolute . '/'; - $this->u_base_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$id}"); + $this->u_base_action = append_sid("{$phpbb_admin_path}index.$php_ext", "i={$id}"); $this->s_hidden_fields = array( 'mode' => $mode, ); @@ -939,7 +939,7 @@ class acp_styles // Preview $actions[] = array( - 'U_ACTION' => append_sid($this->phpbb_root_path . 'index.' . $this->phpEx, 'style=' . $style['style_id']), + 'U_ACTION' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'style=' . $style['style_id']), 'L_ACTION' => $this->user->lang['PREVIEW'] ); } -- cgit v1.2.1 From a35ad4e689c204c52d23c07b701433325c27b0dc Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 2 Aug 2012 12:38:49 +0200 Subject: [ticket/11041] Correctly import PHP file extension from global space. 85bcdbad468cd255a02d6c48b2dcd1d128978eed shouldn't have changed imports of "global $phpEx". PHPBB3-11041 --- phpBB/includes/acp/acp_styles.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/acp/acp_styles.php') diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index d41ef571dd..db77825ae7 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -40,7 +40,7 @@ class acp_styles public function main($id, $mode) { - global $db, $user, $phpbb_admin_path, $phpbb_root_path, $php_ext, $template, $request, $cache, $auth, $config; + global $db, $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request, $cache, $auth, $config; $this->db = $db; $this->user = $user; @@ -50,12 +50,12 @@ class acp_styles $this->auth = $auth; $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; + $this->php_ext = $phpEx; $this->default_style = $config['default_style']; $this->styles_path = $this->phpbb_root_path . $this->styles_path_absolute . '/'; - $this->u_base_action = append_sid("{$phpbb_admin_path}index.$php_ext", "i={$id}"); + $this->u_base_action = append_sid("{$phpbb_admin_path}index.{$this->php_ext}", "i={$id}"); $this->s_hidden_fields = array( 'mode' => $mode, ); -- cgit v1.2.1