aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/profilefields/manager.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/profilefields/manager.php')
-rw-r--r--phpBB/phpbb/profilefields/manager.php262
1 files changed, 177 insertions, 85 deletions
diff --git a/phpBB/phpbb/profilefields/manager.php b/phpBB/phpbb/profilefields/manager.php
index ac2542a6d4..ea4b24af56 100644
--- a/phpBB/phpbb/profilefields/manager.php
+++ b/phpBB/phpbb/profilefields/manager.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package phpBB3
-* @copyright (c) 2014 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
*
*/
@@ -11,7 +15,6 @@ namespace phpbb\profilefields;
/**
* Custom Profile Fields
-* @package phpBB3
*/
class manager
{
@@ -23,11 +26,17 @@ class manager
/**
* Database object
- * @var \phpbb\db\driver\driver
+ * @var \phpbb\db\driver\driver_interface
*/
protected $db;
/**
+ * Event dispatcher object
+ * @var \phpbb\event\dispatcher_interface
+ */
+ protected $dispatcher;
+
+ /**
* Request object
* @var \phpbb\request\request
*/
@@ -63,7 +72,8 @@ class manager
* Construct
*
* @param \phpbb\auth\auth $auth Auth object
- * @param \phpbb\db\driver\driver $db Database object
+ * @param \phpbb\db\driver\driver_interface $db Database object
+ * @param \phpbb\event\dispatcher_interface $dispatcher Event dispatcher object
* @param \phpbb\request\request $request Request object
* @param \phpbb\template\template $template Template object
* @param \phpbb\di\service_collection $type_collection
@@ -72,10 +82,11 @@ class manager
* @param string $fields_language_table
* @param string $fields_data_table
*/
- public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver $db, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table)
+ public function __construct(\phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\di\service_collection $type_collection, \phpbb\user $user, $fields_table, $fields_language_table, $fields_data_table)
{
$this->auth = $auth;
$this->db = $db;
+ $this->dispatcher = $dispatcher;
$this->request = $request;
$this->template = $template;
$this->type_collection = $type_collection;
@@ -231,14 +242,11 @@ class manager
if (!$this->db->sql_affectedrows())
{
+ $cp_data = $this->build_insert_sql_array($cp_data);
$cp_data['user_id'] = (int) $user_id;
- $this->db->sql_return_on_error(true);
-
$sql = 'INSERT INTO ' . $this->fields_data_table . ' ' . $this->db->sql_build_array('INSERT', $cp_data);
$this->db->sql_query($sql);
-
- $this->db->sql_return_on_error(false);
}
}
@@ -268,116 +276,200 @@ class manager
$profile_field = $this->type_collection[$field_data['field_type']];
$tpl_fields[] = array(
+ 'PROFILE_FIELD_IDENT' => $field_ident,
'PROFILE_FIELD_TYPE' => $field_data['field_type'],
'PROFILE_FIELD_NAME' => $profile_field->get_field_name($field_data['lang_name']),
'PROFILE_FIELD_EXPLAIN' => $this->user->lang($field_data['lang_explain']),
);
}
+ $profile_cache = $this->profile_cache;
+
+ /**
+ * Event to modify template headlines of the generated profile fields
+ *
+ * @event core.generate_profile_fields_template_headlines
+ * @var string restrict_option Restrict the published fields to a certain profile field option
+ * @var array tpl_fields Array with template data fields
+ * @var array profile_cache A copy of the profile cache to make additional checks
+ * @since 3.1.6-RC1
+ */
+ $vars = array(
+ 'restrict_option',
+ 'tpl_fields',
+ 'profile_cache',
+ );
+ extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_headlines', compact($vars)));
+ unset($profile_cache);
+
return $tpl_fields;
}
/**
- * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled)
- * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template
+ * Grab the user specific profile fields data
+ *
+ * @param int|array $user_ids Single user id or an array of ids
+ * @return array Users profile fields data
*/
- public function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false)
+ public function grab_profile_fields_data($user_ids = 0)
{
- if ($mode == 'grab')
+ if (!is_array($user_ids))
{
- if (!is_array($user_id))
- {
- $user_id = array($user_id);
- }
+ $user_ids = array($user_ids);
+ }
- if (!sizeof($this->profile_cache))
- {
- $this->build_cache();
- }
+ if (!sizeof($this->profile_cache))
+ {
+ $this->build_cache();
+ }
- if (!sizeof($user_id))
- {
- return array();
- }
+ if (!sizeof($user_ids))
+ {
+ return array();
+ }
- $sql = 'SELECT *
- FROM ' . $this->fields_data_table . '
- WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_id));
- $result = $this->db->sql_query($sql);
+ $sql = 'SELECT *
+ FROM ' . $this->fields_data_table . '
+ WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_ids));
+ $result = $this->db->sql_query($sql);
- $field_data = array();
- while ($row = $this->db->sql_fetchrow($result))
- {
- $field_data[$row['user_id']] = $row;
- }
- $this->db->sql_freeresult($result);
+ $field_data = array();
+ while ($row = $this->db->sql_fetchrow($result))
+ {
+ $field_data[$row['user_id']] = $row;
+ }
+ $this->db->sql_freeresult($result);
- $user_fields = array();
+ /**
+ * Event to modify profile fields data retrieved from the database
+ *
+ * @event core.grab_profile_fields_data
+ * @var array user_ids Single user id or an array of ids
+ * @var array field_data Array with profile fields data
+ * @since 3.1.0-b3
+ */
+ $vars = array('user_ids', 'field_data');
+ extract($this->dispatcher->trigger_event('core.grab_profile_fields_data', compact($vars)));
- $user_ids = $user_id;
+ $user_fields = array();
- // Go through the fields in correct order
- foreach (array_keys($this->profile_cache) as $used_ident)
+ // Go through the fields in correct order
+ foreach (array_keys($this->profile_cache) as $used_ident)
+ {
+ foreach ($field_data as $user_id => $row)
{
- foreach ($field_data as $user_id => $row)
- {
- $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
- $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
- }
+ $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
+ $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
+ }
- foreach ($user_ids as $user_id)
+ foreach ($user_ids as $user_id)
+ {
+ if (!isset($user_fields[$user_id][$used_ident]) && $this->profile_cache[$used_ident]['field_show_novalue'])
{
- if (!isset($user_fields[$user_id][$used_ident]) && $this->profile_cache[$used_ident]['field_show_novalue'])
- {
- $user_fields[$user_id][$used_ident]['value'] = '';
- $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
- }
+ $user_fields[$user_id][$used_ident]['value'] = '';
+ $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
}
}
-
- return $user_fields;
}
- else if ($mode == 'show')
+
+ return $user_fields;
+ }
+
+ /**
+ * Assign the user's profile fields data to the template
+ *
+ * @param array $profile_row Array with users profile field data
+ * @param bool $use_contact_fields Should we display contact fields as such?
+ * This requires special treatments (links should not be parsed in the values, and more)
+ * @return array
+ */
+ public function generate_profile_fields_template_data($profile_row, $use_contact_fields = true)
+ {
+ // $profile_row == $user_fields[$row['user_id']];
+ $tpl_fields = array();
+ $tpl_fields['row'] = $tpl_fields['blockrow'] = array();
+
+ /**
+ * Event to modify data of the generated profile fields, before the template assignment loop
+ *
+ * @event core.generate_profile_fields_template_data_before
+ * @var array profile_row Array with users profile field data
+ * @var array tpl_fields Array with template data fields
+ * @var bool use_contact_fields Should we display contact fields as such?
+ * @since 3.1.0-b3
+ */
+ $vars = array('profile_row', 'tpl_fields', 'use_contact_fields');
+ extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data_before', compact($vars)));
+
+ foreach ($profile_row as $ident => $ident_ary)
{
- // $profile_row == $user_fields[$row['user_id']];
- $tpl_fields = array();
- $tpl_fields['row'] = $tpl_fields['blockrow'] = array();
+ $profile_field = $this->type_collection[$ident_ary['data']['field_type']];
+ $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']);
+ $value_raw = $profile_field->get_profile_value_raw($ident_ary['value'], $ident_ary['data']);
- foreach ($profile_row as $ident => $ident_ary)
+ if ($value === null)
{
- $profile_field = $this->type_collection[$ident_ary['data']['field_type']];
- $value = $profile_field->get_profile_value($ident_ary['value'], $ident_ary['data']);
+ continue;
+ }
- if ($value === null)
+ $field_desc = $contact_url = '';
+ if ($use_contact_fields && $ident_ary['data']['field_is_contact'])
+ {
+ $value = $profile_field->get_profile_contact_value($ident_ary['value'], $ident_ary['data']);
+ $field_desc = $this->user->lang($ident_ary['data']['field_contact_desc']);
+ if (strpos($field_desc, '%s') !== false)
{
- continue;
+ $field_desc = sprintf($field_desc, $value);
}
+ $contact_url = '';
+ if (strpos($ident_ary['data']['field_contact_url'], '%s') !== false)
+ {
+ $contact_url = sprintf($ident_ary['data']['field_contact_url'], $value);
+ }
+ }
- $tpl_fields['row'] += array(
- 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value,
- 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'],
- 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']),
- 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $this->user->lang($ident_ary['data']['lang_explain']),
-
- 'S_PROFILE_' . strtoupper($ident) => true,
- );
+ $tpl_fields['row'] += array(
+ 'PROFILE_' . strtoupper($ident) . '_IDENT' => $ident,
+ 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value,
+ 'PROFILE_' . strtoupper($ident) . '_VALUE_RAW' => $value_raw,
+ 'PROFILE_' . strtoupper($ident) . '_CONTACT' => $contact_url,
+ 'PROFILE_' . strtoupper($ident) . '_DESC' => $field_desc,
+ 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'],
+ 'PROFILE_' . strtoupper($ident) . '_NAME' => $this->user->lang($ident_ary['data']['lang_name']),
+ 'PROFILE_' . strtoupper($ident) . '_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']),
+
+ 'S_PROFILE_' . strtoupper($ident) . '_CONTACT' => $ident_ary['data']['field_is_contact'],
+ 'S_PROFILE_' . strtoupper($ident) => true,
+ );
- $tpl_fields['blockrow'][] = array(
- 'PROFILE_FIELD_VALUE' => $value,
- 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'],
- 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']),
- 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']),
+ $tpl_fields['blockrow'][] = array(
+ 'PROFILE_FIELD_IDENT' => $ident,
+ 'PROFILE_FIELD_VALUE' => $value,
+ 'PROFILE_FIELD_VALUE_RAW' => $value_raw,
+ 'PROFILE_FIELD_CONTACT' => $contact_url,
+ 'PROFILE_FIELD_DESC' => $field_desc,
+ 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'],
+ 'PROFILE_FIELD_NAME' => $this->user->lang($ident_ary['data']['lang_name']),
+ 'PROFILE_FIELD_EXPLAIN' => $this->user->lang($ident_ary['data']['lang_explain']),
+
+ 'S_PROFILE_CONTACT' => $ident_ary['data']['field_is_contact'],
+ 'S_PROFILE_' . strtoupper($ident) => true,
+ );
+ }
- 'S_PROFILE_' . strtoupper($ident) => true,
- );
- }
+ /**
+ * Event to modify template data of the generated profile fields
+ *
+ * @event core.generate_profile_fields_template_data
+ * @var array profile_row Array with users profile field data
+ * @var array tpl_fields Array with template data fields
+ * @var bool use_contact_fields Should we display contact fields as such?
+ * @since 3.1.0-b3
+ */
+ $vars = array('profile_row', 'tpl_fields', 'use_contact_fields');
+ extract($this->dispatcher->trigger_event('core.generate_profile_fields_template_data', compact($vars)));
- return $tpl_fields;
- }
- else
- {
- trigger_error('Wrong mode for custom profile', E_USER_ERROR);
- }
+ return $tpl_fields;
}
/**