diff options
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/db/migration/data/v310/profilefield_types.php | 106 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/lang_helper.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/profilefields.php | 15 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_base.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_bool.php | 12 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_date.php | 10 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_dropdown.php | 16 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_int.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_interface.php | 14 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_string.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/profilefields/type/type_text.php | 8 |
11 files changed, 191 insertions, 16 deletions
diff --git a/phpBB/phpbb/db/migration/data/v310/profilefield_types.php b/phpBB/phpbb/db/migration/data/v310/profilefield_types.php new file mode 100644 index 0000000000..553ff592a4 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v310/profilefield_types.php @@ -0,0 +1,106 @@ +<?php +/** +* +* @package migration +* @copyright (c) 2014 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License v2 +* +*/ + +namespace phpbb\db\migration\data\v310; + +class profilefield_types extends \phpbb\db\migration\migration +{ + + static public function depends_on() + { + return array( + '\phpbb\db\migration\data\v310\alpha2', + ); + } + + public function update_schema() + { + return array( + 'change_columns' => array( + $this->table_prefix . 'profile_fields' => array( + 'field_type' => array('VCHAR:100', ''), + ), + $this->table_prefix . 'profile_fields_lang' => array( + 'field_type' => array('VCHAR:100', ''), + ), + ), + ); + } + + public function update_data() + { + return array( + array('custom', array(array($this, 'update_profile_fields_type'))), + array('custom', array(array($this, 'update_profile_fields_lang_type'))), + ); + } + + public function update_profile_fields_type() + { + // Update profile field types + $sql = 'SELECT field_type + FROM ' . $this->table_prefix . 'profile_fields + GROUP BY field_type'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . $this->table_prefix . "profile_fields + SET field_type = '" . $this->db->sql_escape($this->convert_phpbb30_field_type($row['field_type'])) . "' + WHERE field_type = '" . $this->db->sql_escape($row['field_type']) . "'"; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + public function update_profile_fields_lang_type() + { + // Update profile field language types + $sql = 'SELECT field_type + FROM ' . $this->table_prefix . 'profile_fields_lang + GROUP BY field_type'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $sql = 'UPDATE ' . $this->table_prefix . "profile_fields_lang + SET field_type = '" . $this->db->sql_escape($this->convert_phpbb30_field_type($row['field_type'])) . "' + WHERE field_type = '" . $this->db->sql_escape($row['field_type']) . "'"; + $this->sql_query($sql); + } + $this->db->sql_freeresult($result); + } + + /** + * Determine the new field type for a given phpBB 3.0 field type + * + * @param $field_type int Field type in 3.0 + * @return string Field new type which is used since 3.1 + */ + public function convert_phpbb30_field_type($field_type) + { + switch ($field_type) + { + case FIELD_INT: + return 'profilefields.type.int'; + case FIELD_STRING: + return 'profilefields.type.string'; + case FIELD_TEXT: + return 'profilefields.type.text'; + case FIELD_BOOL: + return 'profilefields.type.bool'; + case FIELD_DROPDOWN: + return 'profilefields.type.dropdown'; + case FIELD_DATE: + return 'profilefields.type.date'; + default: + return $field_type; + } + } +} diff --git a/phpBB/phpbb/profilefields/lang_helper.php b/phpBB/phpbb/profilefields/lang_helper.php index 569eaaca40..432c0aa40b 100644 --- a/phpBB/phpbb/profilefields/lang_helper.php +++ b/phpBB/phpbb/profilefields/lang_helper.php @@ -65,7 +65,7 @@ class lang_helper FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id AND lang_id = $lang_id - AND field_type = $field_type + AND field_type = '" . $this->db->sql_escape($field_type) . "' ORDER BY option_id"; $result = $this->db->sql_query($sql); diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php index a580ca2937..bd9765d04c 100644 --- a/phpBB/phpbb/profilefields/profilefields.php +++ b/phpBB/phpbb/profilefields/profilefields.php @@ -82,10 +82,9 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - // Return templated field $tpl_snippet = $this->process_field_row('change', $row); - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$row['field_type']]; $this->template->assign_block_vars('profile_fields', array( 'LANG_NAME' => $row['lang_name'], @@ -160,7 +159,7 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$row['field_type']]; $cp_data['pf_' . $row['field_ident']] = $profile_field->get_profile_field($row); $check_value = $cp_data['pf_' . $row['field_ident']]; @@ -300,7 +299,7 @@ class profilefields foreach ($profile_row as $ident => $ident_ary) { - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$ident_ary['data']['field_type']]; $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']); if ($value === NULL) @@ -349,13 +348,13 @@ class profilefields )); // empty previously filled blockvars - foreach ($this->profile_types as $field_case => $field_type) + foreach ($this->type_collection as $field_key => $field_type) { - $this->template->destroy_block_vars($field_type); + $this->template->destroy_block_vars($field_type->get_name()); } // Assign template variables - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$profile_row['field_type']]]; + $profile_field = $this->type_collection[$profile_row['field_type']]; $profile_field->generate_field($profile_row, $preview_options); // Return templated data @@ -382,7 +381,7 @@ class profilefields while ($row = $this->db->sql_fetchrow($result)) { - $profile_field = $this->type_collection['profilefields.type.' . $this->profile_types[$row['field_type']]]; + $profile_field = $this->type_collection[$row['field_type']]; $cp_data['pf_' . $row['field_ident']] = $profile_field->get_default_field_value($row); } $this->db->sql_freeresult($result); diff --git a/phpBB/phpbb/profilefields/type/type_base.php b/phpBB/phpbb/profilefields/type/type_base.php index 2fd4c50f6b..7aee74d9ff 100644 --- a/phpBB/phpbb/profilefields/type/type_base.php +++ b/phpBB/phpbb/profilefields/type/type_base.php @@ -24,6 +24,14 @@ abstract class type_base implements type_interface /** * {@inheritDoc} */ + public function get_service_name() + { + return 'profilefields.type.' . $this->get_name(); + } + + /** + * {@inheritDoc} + */ public function get_field_ident($field_data) { return 'pf_' . $field_data['field_ident']; diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php index 016ceb6000..f466b60099 100644 --- a/phpBB/phpbb/profilefields/type/type_bool.php +++ b/phpBB/phpbb/profilefields/type/type_bool.php @@ -26,6 +26,14 @@ class type_bool extends type_base /** * {@inheritDoc} */ + public function get_name() + { + return 'bool'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $profile_row = array( @@ -36,7 +44,7 @@ class type_bool extends type_base 'lang_id' => $default_lang_id, 'field_default_value' => $field_data['field_default_value'], 'field_ident' => 'field_default_value', - 'field_type' => FIELD_BOOL, + 'field_type' => $this->get_service_name(), 'field_length' => $field_data['field_length'], 'lang_options' => $field_data['lang_options'] ); @@ -163,7 +171,7 @@ class type_bool extends type_base { if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview_options); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $this->get_service_name(), $preview_options); } $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php index 301e05c9ae..e59c959f5d 100644 --- a/phpBB/phpbb/profilefields/type/type_date.php +++ b/phpBB/phpbb/profilefields/type/type_date.php @@ -25,6 +25,14 @@ class type_date extends type_base /** * {@inheritDoc} */ + public function get_name() + { + return 'date'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $profile_row = array( @@ -34,7 +42,7 @@ class type_date extends type_base 'lang_id' => $default_lang_id, 'field_default_value' => $field_data['field_default_value'], 'field_ident' => 'field_default_value', - 'field_type' => FIELD_DATE, + 'field_type' => $this->get_service_name(), 'field_length' => $field_data['field_length'], ); diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php index 95f250f444..c9d0936816 100644 --- a/phpBB/phpbb/profilefields/type/type_dropdown.php +++ b/phpBB/phpbb/profilefields/type/type_dropdown.php @@ -26,6 +26,14 @@ class type_dropdown extends type_base /** * {@inheritDoc} */ + public function get_name() + { + return 'dropdown'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $profile_row[0] = array( @@ -36,7 +44,7 @@ class type_dropdown extends type_base 'lang_id' => $default_lang_id, 'field_default_value' => $field_data['field_default_value'], 'field_ident' => 'field_default_value', - 'field_type' => FIELD_DROPDOWN, + 'field_type' => $this->get_service_name(), 'lang_options' => $field_data['lang_options'], ); @@ -95,7 +103,7 @@ class type_dropdown extends type_base // retrieve option lang data if necessary if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1)) { - $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], FIELD_DROPDOWN, false); + $this->lang_helper->get_option_lang($field_data['field_id'], $field_data['lang_id'], $this->get_service_name(), false); } if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value)) @@ -120,7 +128,7 @@ class type_dropdown extends type_base $lang_id = $field_data['lang_id']; if (!$this->lang_helper->is_set($field_id, $lang_id)) { - $this->lang_helper->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false); + $this->lang_helper->get_option_lang($field_id, $lang_id, $this->get_service_name(), false); } if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue']) @@ -159,7 +167,7 @@ class type_dropdown extends type_base if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { - $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview_options); + $this->lang_helper->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], $this->get_service_name(), $preview_options); } $profile_row['field_value'] = (int) $value; diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php index e22b45e7a4..5b5f84d41b 100644 --- a/phpBB/phpbb/profilefields/type/type_int.php +++ b/phpBB/phpbb/profilefields/type/type_int.php @@ -24,6 +24,14 @@ class type_int extends type_base /** * {@inheritDoc} */ + public function get_name() + { + return 'int'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $options = array( diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php index e0c2ba824d..5a88200bad 100644 --- a/phpBB/phpbb/profilefields/type/type_interface.php +++ b/phpBB/phpbb/profilefields/type/type_interface.php @@ -12,6 +12,20 @@ namespace phpbb\profilefields\type; interface type_interface { /** + * Get the name of the type, used for error messages and template loops + * + * @return string lowercase version of the fields type + */ + public function get_name(); + + /** + * Get the name of service representing the type + * + * @return string lowercase version of the fields type + */ + public function get_service_name(); + + /** * Get dropdown options for second step in ACP * * @param string $default_lang_id ID of the default language diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php index 9542a6256a..73563bc579 100644 --- a/phpBB/phpbb/profilefields/type/type_string.php +++ b/phpBB/phpbb/profilefields/type/type_string.php @@ -24,6 +24,14 @@ class type_string extends type_string_common /** * {@inheritDoc} */ + public function get_name() + { + return 'string'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $options = array( diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php index 0ead505262..1638bffcff 100644 --- a/phpBB/phpbb/profilefields/type/type_text.php +++ b/phpBB/phpbb/profilefields/type/type_text.php @@ -24,6 +24,14 @@ class type_text extends type_string_common /** * {@inheritDoc} */ + public function get_name() + { + return 'text'; + } + + /** + * {@inheritDoc} + */ public function get_options($default_lang_id, $field_data) { $options = array( |