- md5
- 8e9ec6e5edbcac9d6c226f2b5faac182
- sha1
- b61962c8db0d50d8fb8049c92cd34d6f29214ae9
- sha256
- 86a6211240a21960867571ad89ac2382970835f05289fdc21109a39c2f203ff1
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
<?php
/**
* @package Joomla.Plugin
* @subpackage Privacy.contact
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\Utilities\ArrayHelper;
JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php');
JLoader::register('PrivacyPlugin', JPATH_ADMINISTRATOR . '/components/com_privacy/helpers/plugin.php');
/**
* Privacy plugin managing Joomla user contact data
*
* @since 3.9.0
*/
class PlgPrivacyContact extends PrivacyPlugin
{
/**
* Database object
*
* @var JDatabaseDriver
* @since 3.9.0
*/
protected $db;
/**
* Affects constructor behaviour. If true, language files will be loaded automatically.
*
* @var boolean
* @since 3.9.0
*/
protected $autoloadLanguage = true;
/**
* Contacts array
*
* @var Array
* @since 3.9.0
*/
protected $contacts = array();
/**
* Processes an export request for Joomla core user contact data
*
* This event will collect data for the contact core tables:
*
* - Contact custom fields
*
* @param PrivacyTableRequest $request The request record being processed
* @param JUser $user The user account associated with this request if available
*
* @return PrivacyExportDomain[]
*
* @since 3.9.0
*/
public function onPrivacyExportRequest(PrivacyTableRequest $request, JUser $user = null)
{
if ((!$user) && (!$request->email))
{
return array();
}
$domains = array();
$domains[] = $this->createContactDomain($request, $user);
// An user may have more than 1 contact linked to them
foreach ($this->contacts as $contact)
{
$domains[] = $this->createContactCustomFieldsDomain($contact);
}
return $domains;
}
/**
* Create the domain for the user contact data
*
* @param PrivacyTableRequest $request The request record being processed
* @param JUser $user The user account associated with this request if available
*
* @return PrivacyExportDomain
*
* @since 3.9.0
*/
private function createContactDomain(PrivacyTableRequest $request, JUser $user = null)
{
$domain = $this->createDomain('user contact', 'Joomla! user contact data');
if ($user)
{
$query = $this->db->getQuery(true)
->select('*')
->from($this->db->quoteName('#__contact_details'))
->where($this->db->quoteName('user_id') . ' = ' . (int) $user->id)
->order($this->db->quoteName('ordering') . ' ASC');
}
else
{
$query = $this->db->getQuery(true)
->select('*')
->from($this->db->quoteName('#__contact_details'))
->where($this->db->quoteName('email_to') . ' = ' . $this->db->quote($request->email))
->order($this->db->quoteName('ordering') . ' ASC');
}
$items = $this->db->setQuery($query)->loadAssocList();
foreach ($items as $item)
{
$domain->addItem($this->createItemFromArray($item));
$this->contacts[] = (object) $item;
}
return $domain;
}
/**
* Create the domain for the contact custom fields
*
* @param Object $contact The contact to process
*
* @return PrivacyExportDomain
*
* @since 3.9.0
*/
private function createContactCustomFieldsDomain($contact)
{
$domain = $this->createDomain('contact custom fields', 'Joomla! contact custom fields data');
// Get item's fields, also preparing their value property for manual display
$fields = FieldsHelper::getFields('com_contact.contact', $contact);
foreach ($fields as $field)
{
$fieldValue = is_array($field->value) ? implode(', ', $field->value) : $field->value;
$data = array(
'contact_id' => $contact->id,
'field_name' => $field->name,
'field_title' => $field->title,
'field_value' => $fieldValue,
);
$domain->addItem($this->createItemFromArray($data));
}
return $domain;
}
}
The same content is in 3 releases, Joomla 3.9.0-alpha to 3.9.0-beta2. See them all, or every version of this file.