diff --git a/phpBB/includes/acm/acm_file.php b/phpBB/includes/acm/acm_file.php index b6af055399..ecc4db8a89 100644 --- a/phpBB/includes/acm/acm_file.php +++ b/phpBB/includes/acm/acm_file.php @@ -71,12 +71,11 @@ class acm } global $phpEx; - $file = "vars = " . $this->format_array($this->vars) . ";\n\n\$this->var_expires = " . $this->format_array($this->var_expires) . "\n?>"; if ($fp = @fopen($this->cache_dir . 'data_global.' . $phpEx, 'wb')) { @flock($fp, LOCK_EX); - fwrite($fp, $file); + fwrite($fp, "vars = " . var_export($this->vars, true) . ";\n\n\$this->var_expires = " . var_export($this->var_expires, true) . "\n?>"); @flock($fp, LOCK_UN); fclose($fp); } @@ -151,7 +150,7 @@ class acm return false; } - include($this->cache_dir . 'data' . $var_name . ".$phpEx"); + include($this->cache_dir . "data{$var_name}.$phpEx"); return (isset($data)) ? $data : false; } else @@ -169,10 +168,10 @@ class acm { global $phpEx; - if ($fp = @fopen($this->cache_dir . 'data' . $var_name . ".$phpEx", 'wb')) + if ($fp = @fopen($this->cache_dir . "data{$var_name}.$phpEx", 'wb')) { @flock($fp, LOCK_EX); - fwrite($fp, " " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n\n\$data = unserialize('" . str_replace("'", "\\'", str_replace('\\', '\\\\', serialize($var))) . "');\n?>"); + fwrite($fp, " " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n\n\$data = " . var_export($var, true) . ";\n?>"); @flock($fp, LOCK_UN); fclose($fp); } @@ -290,37 +289,6 @@ class acm } } - /** - * Format an array to be stored on filesystem - */ - function format_array($array, $tab = '') - { - $tab .= "\t"; - - $lines = array(); - foreach ($array as $k => $v) - { - if (is_array($v)) - { - $lines[] = "\n{$tab}'$k' => " . $this->format_array($v, $tab); - } - else if (is_int($v)) - { - $lines[] = "\n{$tab}'$k' => $v"; - } - else if (is_bool($v)) - { - $lines[] = "\n{$tab}'$k' => " . (($v) ? 'true' : 'false'); - } - else - { - $lines[] = "\n{$tab}'$k' => '" . str_replace("'", "\\'", str_replace('\\', '\\\\', $v)) . "'"; - } - } - - return 'array(' . implode(',', $lines) . ')'; - } - /** * Load cached sql query */ @@ -368,7 +336,6 @@ class acm { @flock($fp, LOCK_EX); - $lines = array(); $query_id = sizeof($this->sql_rowset); $this->sql_rowset[$query_id] = array(); $this->sql_row_pointer[$query_id] = 0; @@ -376,12 +343,13 @@ class acm while ($row = $db->sql_fetchrow($query_result)) { $this->sql_rowset[$query_id][] = $row; - - $lines[] = "unserialize('" . str_replace("'", "\\'", str_replace('\\', '\\\\', serialize($row))) . "')"; } $db->sql_freeresult($query_result); - fwrite($fp, " " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n\n\$this->sql_rowset[\$query_id] = array(" . implode(',', $lines) . ') ?>'); + $file = " " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n"; + + fwrite($fp, $file . "\n\$this->sql_rowset[\$query_id] = " . var_export($this->sql_rowset[$query_id], true) . ";\n?>"); @flock($fp, LOCK_UN); fclose($fp); diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index f7b4d8fc66..669e98f32f 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -363,7 +363,7 @@ class acp_groups // Since the user only has the option to copy permissions from non leader managed groups this seems to be a good compromise. if ($group_perm_from && $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) { - $sql = 'SELECT group_manage_founder + $sql = 'SELECT group_founder_manage FROM ' . GROUPS_TABLE . ' WHERE group_id = ' . $group_perm_from; $result = $db->sql_query($sql); @@ -371,7 +371,7 @@ class acp_groups $db->sql_freeresult($result); // Check the group if non-founder - if ($check_row && ($user->data['user_type'] == USER_FOUNDER || $check_row['group_manage_founder'] == 0)) + if ($check_row && ($user->data['user_type'] == USER_FOUNDER || $check_row['group_founder_manage'] == 0)) { // From the mysql documentation: // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14. diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php index 94a79fa2d3..16f75d9c92 100644 --- a/phpBB/includes/acp/acp_language.php +++ b/phpBB/includes/acp/acp_language.php @@ -674,6 +674,13 @@ class acp_language WHERE user_lang = '" . $db->sql_escape($row['lang_iso']) . "'"; $db->sql_query($sql); + // We also need to remove the translated entries for custom profile fields - we want clean tables, don't we? + $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . ' WHERE lang_id = ' . $lang_id; + $db->sql_query($sql); + + $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . ' WHERE lang_id = ' . $lang_id; + $db->sql_query($sql); + add_log('admin', 'LOG_LANGUAGE_PACK_DELETED', $row['lang_english_name']); trigger_error(sprintf($user->lang['LANGUAGE_PACK_DELETED'], $row['lang_english_name']) . adm_back_link($this->u_action)); @@ -725,6 +732,43 @@ class acp_language ); $db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); + $lang_id = $db->sql_nextid(); + + // Now let's copy the default language entries for custom profile fields for this new language - makes admin's life easier. + $sql = 'SELECT lang_id + FROM ' . LANG_TABLE . " + WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'"; + $result = $db->sql_query($sql); + $default_lang_id = (int) $db->sql_fetchfield('lang_id'); + $db->sql_freeresult($result); + + // From the mysql documentation: + // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14. + // Due to this we stay on the safe side if we do the insertion "the manual way" + + $sql = 'SELECT field_id, lang_name, lang_explain, lang_default_value + FROM ' . PROFILE_LANG_TABLE . ' + WHERE lang_id = ' . $default_lang_id; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $row['lang_id'] = $lang_id; + $db->sql_query('INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row)); + } + $db->sql_freeresult($result); + + $sql = 'SELECT field_id, option_id, field_type, lang_value + FROM ' . PROFILE_FIELDS_LANG_TABLE . ' + WHERE lang_id = ' . $default_lang_id; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $row['lang_id'] = $lang_id; + $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $row)); + } + $db->sql_freeresult($result); add_log('admin', 'LOG_LANGUAGE_PACK_INSTALLED', $lang_pack['name']); diff --git a/phpBB/includes/acp/acp_profile.php b/phpBB/includes/acp/acp_profile.php index e093308f4d..da11868cc2 100644 --- a/phpBB/includes/acp/acp_profile.php +++ b/phpBB/includes/acp/acp_profile.php @@ -15,6 +15,9 @@ class acp_profile { var $u_action; + var $edit_lang_id; + var $lang_defs; + function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache; @@ -47,7 +50,7 @@ class acp_profile // Build Language array // Based on this, we decide which elements need to be edited later and which language items are missing - $lang_defs = array(); + $this->lang_defs = array(); $sql = 'SELECT lang_id, lang_iso FROM ' . LANG_TABLE . ' @@ -57,8 +60,8 @@ class acp_profile while ($row = $db->sql_fetchrow($result)) { // Make some arrays with all available languages - $lang_defs['id'][] = $row['lang_id']; - $lang_defs['iso'][$row['lang_iso']] = $row['lang_id']; + $this->lang_defs['id'][$row['lang_id']] = $row['lang_iso']; + $this->lang_defs['iso'][$row['lang_iso']] = $row['lang_id']; } $db->sql_freeresult($result); @@ -70,17 +73,17 @@ class acp_profile while ($row = $db->sql_fetchrow($result)) { // Which languages are available for each item - $lang_defs['entry'][$row['field_id']][] = $row['lang_id']; + $this->lang_defs['entry'][$row['field_id']][] = $row['lang_id']; } $db->sql_freeresult($result); // Have some fields been defined? - if (isset($lang_defs['entry'])) + if (isset($this->lang_defs['entry'])) { - foreach ($lang_defs['entry'] as $field_id => $field_ary) + foreach ($this->lang_defs['entry'] as $field_id => $field_ary) { // Fill an array with the languages that are missing for each field - $lang_defs['diff'][$field_id] = array_diff($lang_defs['id'], $field_ary); + $this->lang_defs['diff'][$field_id] = array_diff(array_values($this->lang_defs['iso']), $field_ary); } } @@ -207,7 +210,7 @@ class acp_profile $default_lang_id = (int) $db->sql_fetchfield('lang_id'); $db->sql_freeresult($result); - if (!in_array($default_lang_id, $lang_defs['entry'][$field_id])) + if (!in_array($default_lang_id, $this->lang_defs['entry'][$field_id])) { trigger_error($user->lang['DEFAULT_LANGUAGE_NOT_FILLED'] . adm_back_link($this->u_action), E_USER_WARNING); } @@ -275,6 +278,9 @@ class acp_profile $submit = (isset($_REQUEST['next']) || isset($_REQUEST['prev'])) ? true : false; $save = (isset($_REQUEST['save'])) ? true : false; + // The language id of default language + $this->edit_lang_id = $this->lang_defs['iso'][$config['default_lang']]; + // We are editing... we need to grab basic things if ($action == 'edit') { @@ -285,7 +291,7 @@ class acp_profile $sql = 'SELECT l.*, f.* FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f - WHERE l.lang_id = ' . $lang_defs['iso'][$config['default_lang']] . " + WHERE l.lang_id = ' . $this->edit_lang_id . " AND f.field_id = $field_id AND l.field_id = f.field_id"; $result = $db->sql_query($sql); @@ -294,14 +300,29 @@ class acp_profile if (!$field_row) { - trigger_error($user->lang['FIELD_NOT_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + // Some admin changed the default language? + $sql = 'SELECT l.*, f.* + FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f + WHERE l.lang_id <> ' . $this->edit_lang_id . " + AND f.field_id = $field_id + AND l.field_id = f.field_id"; + $result = $db->sql_query($sql); + $field_row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + + if (!$field_row) + { + trigger_error($user->lang['FIELD_NOT_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); + } + + $this->edit_lang_id = $field_row['lang_id']; } $field_type = $field_row['field_type']; // Get language entries $sql = 'SELECT * FROM ' . PROFILE_FIELDS_LANG_TABLE . ' - WHERE lang_id = ' . $lang_defs['iso'][$config['default_lang']] . " + WHERE lang_id = ' . $this->edit_lang_id . " AND field_id = $field_id ORDER BY option_id ASC"; $result = $db->sql_query($sql); @@ -404,17 +425,17 @@ class acp_profile { // The number of options in the field is equal to the number of options already in the database // Or we are creating a new dropdown list. - $cp->vars['lang_options'] = $exploded_options; + $cp->vars['lang_options'] = $exploded_options; } else if ($action == 'edit') { // Changing the number of options? (We remove and re-create the option fields) - $cp->vars['lang_options'] = $exploded_options; + $cp->vars['lang_options'] = $exploded_options; } } else { - $cp->vars['lang_options'] = $lang_options; + $cp->vars['lang_options'] = $lang_options; } // step 2 @@ -483,7 +504,7 @@ class acp_profile // Get language entries $sql = 'SELECT * FROM ' . PROFILE_FIELDS_LANG_TABLE . ' - WHERE lang_id <> ' . $lang_defs['iso'][$config['default_lang']] . " + WHERE lang_id <> ' . $this->edit_lang_id . " AND field_id = $field_id ORDER BY option_id ASC"; $result = $db->sql_query($sql); @@ -498,7 +519,7 @@ class acp_profile $sql = 'SELECT lang_id, lang_name, lang_explain, lang_default_value FROM ' . PROFILE_LANG_TABLE . ' - WHERE lang_id <> ' . $lang_defs['iso'][$config['default_lang']] . " + WHERE lang_id <> ' . $this->edit_lang_id . " AND field_id = $field_id ORDER BY lang_id ASC"; $result = $db->sql_query($sql); @@ -616,13 +637,13 @@ class acp_profile if (!sizeof($error)) { - if ($step == 3 && (sizeof($lang_defs['iso']) == 1 || $save)) + if ($step == 3 && (sizeof($this->lang_defs['iso']) == 1 || $save)) { - $this->save_profile_field($cp, $field_type, $lang_defs, $action); + $this->save_profile_field($cp, $field_type, $action); } else if ($action == 'edit' && $save) { - $this->save_profile_field($cp, $field_type, $lang_defs, $action); + $this->save_profile_field($cp, $field_type, $action); } } @@ -706,7 +727,7 @@ class acp_profile $template->assign_vars(array( 'S_STEP_TWO' => true, - 'L_NEXT' => (sizeof($lang_defs['iso']) == 1) ? $user->lang['SAVE'] : $user->lang['PROFILE_LANG_OPTIONS']) + 'L_NEXT' => (sizeof($this->lang_defs['iso']) == 1) ? $user->lang['SAVE'] : $user->lang['PROFILE_LANG_OPTIONS']) ); // Build options based on profile type @@ -729,7 +750,7 @@ class acp_profile foreach ($options as $lang_id => $lang_ary) { $template->assign_block_vars('options', array( - 'LANGUAGE' => ($lang_ary['lang_iso'] == $config['default_lang']) ? sprintf($user->lang['DEFAULT_ISO_LANGUAGE'], $config['default_lang']) : sprintf($user->lang['ISO_LANGUAGE'], $lang_ary['lang_iso'])) + 'LANGUAGE' => sprintf($user->lang[(($lang_id == $this->edit_lang_id) ? 'DEFAULT_' : '') . 'ISO_LANGUAGE'], $lang_ary['lang_iso'])) ); foreach ($lang_ary['fields'] as $field_ident => $field_ary) @@ -766,7 +787,7 @@ class acp_profile $active_value = (!$row['field_active']) ? 'activate' : 'deactivate'; $id = $row['field_id']; - $s_need_edit = (sizeof($lang_defs['diff'][$row['field_id']])) ? true : false; + $s_need_edit = (sizeof($this->lang_defs['diff'][$row['field_id']])) ? true : false; if ($s_need_edit) { @@ -815,10 +836,12 @@ class acp_profile { global $user, $config, $db; + $default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']]; + $sql = 'SELECT lang_id, lang_iso - FROM ' . LANG_TABLE . " - WHERE lang_iso <> '" . $config['default_lang'] . "' - ORDER BY lang_english_name"; + FROM ' . LANG_TABLE . ' + WHERE lang_id <> ' . (int) $default_lang_id . ' + ORDER BY lang_english_name'; $result = $db->sql_query($sql); $languages = array(); @@ -858,7 +881,7 @@ class acp_profile foreach ($options as $field => $field_type) { - $lang_options[1]['lang_iso'] = $config['default_lang']; + $lang_options[1]['lang_iso'] = $this->lang_defs['id'][$default_lang_id]; $lang_options[1]['fields'][$field] = array( 'TITLE' => $user->lang['CP_' . strtoupper($field)], 'FIELD' => '