aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/profilefields
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/profilefields')
-rw-r--r--phpBB/phpbb/profilefields/profilefields.php79
-rw-r--r--phpBB/phpbb/profilefields/type/type_bool.php21
-rw-r--r--phpBB/phpbb/profilefields/type/type_date.php29
-rw-r--r--phpBB/phpbb/profilefields/type/type_dropdown.php12
-rw-r--r--phpBB/phpbb/profilefields/type/type_int.php19
-rw-r--r--phpBB/phpbb/profilefields/type/type_interface.php8
-rw-r--r--phpBB/phpbb/profilefields/type/type_string.php12
-rw-r--r--phpBB/phpbb/profilefields/type/type_text.php12
8 files changed, 112 insertions, 80 deletions
diff --git a/phpBB/phpbb/profilefields/profilefields.php b/phpBB/phpbb/profilefields/profilefields.php
index 3d9339d1d7..b34a85f9fa 100644
--- a/phpBB/phpbb/profilefields/profilefields.php
+++ b/phpBB/phpbb/profilefields/profilefields.php
@@ -22,10 +22,11 @@ class profilefields
/**
*
*/
- public function __construct($auth, $db, $request, $template, $user)
+ public function __construct($auth, $db, /** @todo: */ $phpbb_container, $request, $template, $user)
{
$this->auth = $auth;
$this->db = $db;
+ $this->container = $phpbb_container;
$this->request = $request;
$this->template = $template;
$this->user = $user;
@@ -300,7 +301,8 @@ class profilefields
while ($row = $this->db->sql_fetchrow($result))
{
- $cp_data['pf_' . $row['field_ident']] = $this->get_profile_field($row);
+ $profile_field = $this->container->get('profilefields.type.' . $this->profile_types[$row['field_type']]);
+ $cp_data['pf_' . $row['field_ident']] = $profile_field->get_profile_field($row);
$check_value = $cp_data['pf_' . $row['field_ident']];
if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false)
@@ -362,7 +364,7 @@ class profilefields
return;
}
- switch ($db->sql_layer)
+ switch ($this->db->sql_layer)
{
case 'oracle':
case 'firebird':
@@ -900,75 +902,4 @@ class profilefields
return $cp_data;
}
-
- /**
- * Get profile field value on submit
- * @access private
- */
- function get_profile_field($profile_row)
- {
- $var_name = 'pf_' . $profile_row['field_ident'];
-
- switch ($profile_row['field_type'])
- {
- case FIELD_DATE:
-
- if (!isset($_REQUEST[$var_name . '_day']))
- {
- if ($profile_row['field_default_value'] == 'now')
- {
- $now = getdate();
- $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
- }
- list($day, $month, $year) = explode('-', $profile_row['field_default_value']);
- }
- else
- {
- $day = request_var($var_name . '_day', 0);
- $month = request_var($var_name . '_month', 0);
- $year = request_var($var_name . '_year', 0);
- }
-
- $var = sprintf('%2d-%2d-%4d', $day, $month, $year);
- break;
-
- case FIELD_BOOL:
- // Checkbox
- if ($profile_row['field_length'] == 2)
- {
- $var = (isset($_REQUEST[$var_name])) ? 1 : 0;
- }
- else
- {
- $var = request_var($var_name, (int) $profile_row['field_default_value']);
- }
- break;
-
- case FIELD_STRING:
- case FIELD_TEXT:
- $var = utf8_normalize_nfc(request_var($var_name, (string) $profile_row['field_default_value'], true));
- break;
-
- case FIELD_INT:
- if (isset($_REQUEST[$var_name]) && $this->request->variable($var_name, '') === '')
- {
- $var = NULL;
- }
- else
- {
- $var = request_var($var_name, (int) $profile_row['field_default_value']);
- }
- break;
-
- case FIELD_DROPDOWN:
- $var = request_var($var_name, (int) $profile_row['field_default_value']);
- break;
-
- default:
- $var = request_var($var_name, $profile_row['field_default_value']);
- break;
- }
-
- return $var;
- }
}
diff --git a/phpBB/phpbb/profilefields/type/type_bool.php b/phpBB/phpbb/profilefields/type/type_bool.php
index b3dafa30d4..31d1c7d780 100644
--- a/phpBB/phpbb/profilefields/type/type_bool.php
+++ b/phpBB/phpbb/profilefields/type/type_bool.php
@@ -14,9 +14,10 @@ class type_bool implements type_interface
/**
*
*/
- public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user)
+ public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user)
{
$this->profilefields = $profilefields;
+ $this->request = $request;
$this->user = $user;
}
@@ -60,4 +61,22 @@ class type_bool implements type_interface
'field_default_value' => 0,
);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_profile_field($profile_row)
+ {
+ $var_name = 'pf_' . $profile_row['field_ident'];
+
+ // Checkbox
+ if ($profile_row['field_length'] == 2)
+ {
+ return ($this->request->is_set($var_name)) ? 1 : 0;
+ }
+ else
+ {
+ return $this->request->variable($var_name, (int) $profile_row['field_default_value']);
+ }
+ }
}
diff --git a/phpBB/phpbb/profilefields/type/type_date.php b/phpBB/phpbb/profilefields/type/type_date.php
index 9639b45770..f5b5182222 100644
--- a/phpBB/phpbb/profilefields/type/type_date.php
+++ b/phpBB/phpbb/profilefields/type/type_date.php
@@ -14,9 +14,10 @@ class type_date implements type_interface
/**
*
*/
- public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user)
+ public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user)
{
$this->profilefields = $profilefields;
+ $this->request = $request;
$this->user = $user;
}
@@ -68,4 +69,30 @@ class type_date implements type_interface
'field_default_value' => ' 0- 0- 0',
);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_profile_field($profile_row)
+ {
+ $var_name = 'pf_' . $profile_row['field_ident'];
+
+ if (!$this->request->is_set($var_name . '_day'))
+ {
+ if ($profile_row['field_default_value'] == 'now')
+ {
+ $now = getdate();
+ $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
+ }
+ list($day, $month, $year) = explode('-', $profile_row['field_default_value']);
+ }
+ else
+ {
+ $day = $this->request->variable($var_name . '_day', 0);
+ $month = $this->request->variable($var_name . '_month', 0);
+ $year = $this->request->variable($var_name . '_year', 0);
+ }
+
+ return sprintf('%2d-%2d-%4d', $day, $month, $year);
+ }
}
diff --git a/phpBB/phpbb/profilefields/type/type_dropdown.php b/phpBB/phpbb/profilefields/type/type_dropdown.php
index 8a101f1fc1..7324ef3ee7 100644
--- a/phpBB/phpbb/profilefields/type/type_dropdown.php
+++ b/phpBB/phpbb/profilefields/type/type_dropdown.php
@@ -14,9 +14,10 @@ class type_dropdown implements type_interface
/**
*
*/
- public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\user $user)
+ public function __construct(\phpbb\profilefields\profilefields $profilefields, \phpbb\request\request $request, \phpbb\user $user)
{
$this->profilefields = $profilefields;
+ $this->request = $request;
$this->user = $user;
}
@@ -64,4 +65,13 @@ class type_dropdown implements type_interface
'field_default_value' => 0,
);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_profile_field($profile_row)
+ {
+ $var_name = 'pf_' . $profile_row['field_ident'];
+ return $this->request->variable($var_name, (int) $profile_row['field_default_value']);
+ }
}
diff --git a/phpBB/phpbb/profilefields/type/type_int.php b/phpBB/phpbb/profilefields/type/type_int.php
index 7cc74b6e44..c40d137a2b 100644
--- a/phpBB/phpbb/profilefields/type/type_int.php
+++ b/phpBB/phpbb/profilefields/type/type_int.php
@@ -14,8 +14,9 @@ class type_int implements type_interface
/**
*
*/
- public function __construct($user)
+ public function __construct(\phpbb\request\request $request, \phpbb\user $user)
{
+ $this->request = $request;
$this->user = $user;
}
@@ -48,4 +49,20 @@ class type_int implements type_interface
'field_default_value' => 0,
);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_profile_field($profile_row)
+ {
+ $var_name = 'pf_' . $profile_row['field_ident'];
+ if ($this->request->is_set($var_name) && $this->request->variable($var_name, '') === '')
+ {
+ return null;
+ }
+ else
+ {
+ return $this->request->variable($var_name, (int) $profile_row['field_default_value']);
+ }
+ }
}
diff --git a/phpBB/phpbb/profilefields/type/type_interface.php b/phpBB/phpbb/profilefields/type/type_interface.php
index 8b011aa48e..f3ca903e30 100644
--- a/phpBB/phpbb/profilefields/type/type_interface.php
+++ b/phpBB/phpbb/profilefields/type/type_interface.php
@@ -36,4 +36,12 @@ interface type_interface
* @return array with values like default field size and more
*/
public function get_default_values();
+
+ /**
+ * Get profile field value on submit
+ *
+ * @param array $profile_row Array with data for this field
+ * @return mixed Submitted value of the profile field
+ */
+ public function get_profile_field($profile_row);
}
diff --git a/phpBB/phpbb/profilefields/type/type_string.php b/phpBB/phpbb/profilefields/type/type_string.php
index c7f9d188ae..64b0660e6e 100644
--- a/phpBB/phpbb/profilefields/type/type_string.php
+++ b/phpBB/phpbb/profilefields/type/type_string.php
@@ -14,8 +14,9 @@ class type_string extends type_string_common implements type_interface
/**
*
*/
- public function __construct($user)
+ public function __construct(\phpbb\request\request $request, \phpbb\user $user)
{
+ $this->request = $request;
$this->user = $user;
}
@@ -48,4 +49,13 @@ class type_string extends type_string_common implements type_interface
'field_default_value' => '',
);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_profile_field($profile_row)
+ {
+ $var_name = 'pf_' . $profile_row['field_ident'];
+ return $this->request->variable($var_name, (string) $profile_row['field_default_value'], true);
+ }
}
diff --git a/phpBB/phpbb/profilefields/type/type_text.php b/phpBB/phpbb/profilefields/type/type_text.php
index 4b58ef0486..8fff2c917a 100644
--- a/phpBB/phpbb/profilefields/type/type_text.php
+++ b/phpBB/phpbb/profilefields/type/type_text.php
@@ -14,8 +14,9 @@ class type_text extends type_string_common implements type_interface
/**
*
*/
- public function __construct($user)
+ public function __construct(\phpbb\request\request $request, \phpbb\user $user)
{
+ $this->request = $request;
$this->user = $user;
}
@@ -48,4 +49,13 @@ class type_text extends type_string_common implements type_interface
'field_default_value' => '',
);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public function get_profile_field($profile_row)
+ {
+ $var_name = 'pf_' . $profile_row['field_ident'];
+ return $this->request->variable($var_name, (string) $profile_row['field_default_value'], true);
+ }
}