diff --git a/administrator/components/com_privacy/helpers/plugin.php b/administrator/components/com_privacy/helpers/plugin.php index ddf4196571e23..0a0a329d9305a 100644 --- a/administrator/components/com_privacy/helpers/plugin.php +++ b/administrator/components/com_privacy/helpers/plugin.php @@ -12,6 +12,7 @@ JLoader::register('PrivacyExportDomain', __DIR__ . '/export/domain.php'); JLoader::register('PrivacyExportField', __DIR__ . '/export/field.php'); JLoader::register('PrivacyExportItem', __DIR__ . '/export/item.php'); +JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php'); /** * Base class for privacy plugins @@ -20,6 +21,22 @@ */ abstract class PrivacyPlugin extends JPlugin { + /** + * 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; + /** * Create a new domain object * @@ -96,4 +113,47 @@ protected function createItemForTable($table) return $this->createItemFromArray($data, $table->{$table->getKeyName(false)}); } + + /** + * Helper function to create the domain for the items custom fields. + * + * @param string $context The context + * @param stdClass $item The items + * + * @return PrivacyExportDomain + * + * @since 3.9.0 + */ + protected function createCustomFieldsDomain($context, $item) + { + $parts = FieldsHelper::extract($context); + + if (!$parts) + { + return array(); + } + + $type = str_replace('com_', '', $parts[0]); + + $domain = $this->createDomain($type . '_custom_fields', 'joomla_' . $type . '_custom_fields_data'); + + // Get item's fields, also preparing their value property for manual display + $fields = FieldsHelper::getFields($parts[0] . '.' . $parts[1], $item); + + foreach ($fields as $field) + { + $fieldValue = is_array($field->value) ? implode(', ', $field->value) : $field->value; + + $data = array( + $type . '_id' => $item->id, + 'field_name' => $field->name, + 'field_title' => $field->title, + 'field_value' => $fieldValue, + ); + + $domain->addItem($this->createItemFromArray($data)); + } + + return $domain; + } } diff --git a/plugins/privacy/actionlogs/actionlogs.php b/plugins/privacy/actionlogs/actionlogs.php index 5d6f2276f3899..f0509c9170172 100644 --- a/plugins/privacy/actionlogs/actionlogs.php +++ b/plugins/privacy/actionlogs/actionlogs.php @@ -19,22 +19,6 @@ */ class PlgPrivacyActionlogs extends PrivacyPlugin { - /** - * Database object - * - * @var JDatabaseDriver - * @since 3.9.0 - */ - protected $db; - - /** - * Affects constructor behavior. If true, language files will be loaded automatically. - * - * @var boolean - * @since 3.9.0 - */ - protected $autoloadLanguage = true; - /** * Processes an export request for Joomla core actionlog data * diff --git a/plugins/privacy/contact/contact.php b/plugins/privacy/contact/contact.php index 75999dca24314..cbfbe3bc6a99b 100644 --- a/plugins/privacy/contact/contact.php +++ b/plugins/privacy/contact/contact.php @@ -9,7 +9,6 @@ defined('_JEXEC') or die; -JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php'); JLoader::register('PrivacyPlugin', JPATH_ADMINISTRATOR . '/components/com_privacy/helpers/plugin.php'); /** @@ -19,30 +18,6 @@ */ 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 * @@ -59,95 +34,37 @@ class PlgPrivacyContact extends PrivacyPlugin */ public function onPrivacyExportRequest(PrivacyTableRequest $request, JUser $user = null) { - if ((!$user) && (!$request->email)) + 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); - } + $domain = $this->createDomain('user_contact', 'joomla_user_contact_data'); + $domains[] = $domain; - 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'); + $query = $this->db->getQuery(true) + ->select('*') + ->from($this->db->quoteName('#__contact_details')) + ->order($this->db->quoteName('ordering') . ' ASC'); 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'); + $query->where($this->db->quoteName('user_id') . ' = ' . (int) $user->id); } 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'); + $query->where($this->db->quoteName('email_to') . ' = ' . $this->db->quote($request->email)); } - $items = $this->db->setQuery($query)->loadAssocList(); + $items = $this->db->setQuery($query)->loadObjectList(); 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)); + $domain->addItem($this->createItemFromArray((array) $item)); + $domains[] = $this->createCustomFieldsDomain('com_contact.contact', $item); } - return $domain; + return $domains; } } diff --git a/plugins/privacy/content/content.php b/plugins/privacy/content/content.php index 474fc949d27bc..3dc5693c9753e 100644 --- a/plugins/privacy/content/content.php +++ b/plugins/privacy/content/content.php @@ -9,7 +9,6 @@ defined('_JEXEC') or die; -JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php'); JLoader::register('PrivacyPlugin', JPATH_ADMINISTRATOR . '/components/com_privacy/helpers/plugin.php'); /** @@ -19,30 +18,6 @@ */ class PlgPrivacyContent 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; - - /** - * Contents array - * - * @var array - * @since 3.9.0 - */ - protected $contents = array(); - /** * Processes an export request for Joomla core user content data * @@ -65,28 +40,8 @@ public function onPrivacyExportRequest(PrivacyTableRequest $request, JUser $user } $domains = array(); - $domains[] = $this->createContentDomain($user); - - foreach ($this->contents as $content) - { - $domains[] = $this->createContentCustomFieldsDomain($content); - } - - return $domains; - } - - /** - * Create the domain for the user content data - * - * @param JUser $user The user account associated with this request - * - * @return PrivacyExportDomain - * - * @since 3.9.0 - */ - private function createContentDomain(JUser $user) - { - $domain = $this->createDomain('user_content', 'joomla_user_content_data'); + $domain = $this->createDomain('user_content', 'joomla_user_content_data'); + $domains[] = $domain; $query = $this->db->getQuery(true) ->select('*') @@ -94,47 +49,14 @@ private function createContentDomain(JUser $user) ->where($this->db->quoteName('created_by') . ' = ' . (int) $user->id) ->order($this->db->quoteName('ordering') . ' ASC'); - $items = $this->db->setQuery($query)->loadAssocList(); + $items = $this->db->setQuery($query)->loadObjectList(); foreach ($items as $item) { - $domain->addItem($this->createItemFromArray($item)); - $this->contents[] = (object) $item; + $domain->addItem($this->createItemFromArray((array) $item)); + $domains[] = $this->createCustomFieldsDomain('com_content.article', $item); } - return $domain; - } - - /** - * Create the domain for the content custom fields - * - * @param Object $content The content to process - * - * @return PrivacyExportDomain - * - * @since 3.9.0 - */ - private function createContentCustomFieldsDomain($content) - { - $domain = $this->createDomain('content_custom_fields', 'joomla_content_custom_fields_data'); - - // Get item's fields, also preparing their value property for manual display - $fields = FieldsHelper::getFields('com_content.article', $content); - - foreach ($fields as $field) - { - $fieldValue = is_array($field->value) ? implode(', ', $field->value) : $field->value; - - $data = array( - 'content_id' => $content->id, - 'field_name' => $field->name, - 'field_title' => $field->title, - 'field_value' => $fieldValue, - ); - - $domain->addItem($this->createItemFromArray($data)); - } - - return $domain; + return $domains; } } diff --git a/plugins/privacy/message/message.php b/plugins/privacy/message/message.php index be1bed7a055c5..a870657b02f97 100644 --- a/plugins/privacy/message/message.php +++ b/plugins/privacy/message/message.php @@ -18,22 +18,6 @@ */ class PlgPrivacyMessage 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; - /** * Processes an export request for Joomla core user message * @@ -53,23 +37,6 @@ public function onPrivacyExportRequest(PrivacyTableRequest $request, JUser $user return array(); } - $domains = array(); - $domains[] = $this->createMessageDomain($user); - - return $domains; - } - - /** - * Create the domain for the user message data - * - * @param JUser $user The user account associated with this request - * - * @return PrivacyExportDomain - * - * @since 3.9.0 - */ - private function createMessageDomain(JUser $user) - { $domain = $this->createDomain('user_messages', 'joomla_user_messages_data'); $query = $this->db->getQuery(true) @@ -86,6 +53,6 @@ private function createMessageDomain(JUser $user) $domain->addItem($this->createItemFromArray($item)); } - return $domain; + return array($domain); } } diff --git a/plugins/privacy/user/user.php b/plugins/privacy/user/user.php index f72c896cbcb44..b02cd7e35d1f7 100644 --- a/plugins/privacy/user/user.php +++ b/plugins/privacy/user/user.php @@ -11,7 +11,6 @@ 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'); JLoader::register('PrivacyRemovalStatus', JPATH_ADMINISTRATOR . '/components/com_privacy/helpers/removal/status.php'); @@ -22,22 +21,6 @@ */ class PlgPrivacyUser extends PrivacyPlugin { - /** - * Database object - * - * @var JDatabaseDriver - * @since 3.9.0 - */ - protected $db; - - /** - * Affects constructor behavior. If true, language files will be loaded automatically. - * - * @var boolean - * @since 3.9.0 - */ - protected $autoloadLanguage = true; - /** * Performs validation to determine if the data associated with a remove information request can be processed * @@ -100,7 +83,7 @@ public function onPrivacyExportRequest(PrivacyTableRequest $request, JUser $user $domains[] = $this->createUserDomain($userTable); $domains[] = $this->createNotesDomain($userTable); $domains[] = $this->createProfileDomain($userTable); - $domains[] = $this->createUserCustomFieldsDomain($userTable); + $domains[] = $this->createCustomFieldsDomain('com_users.user', $userTable); return $domains; } @@ -272,37 +255,4 @@ private function createItemForUserTable(JTableUser $user) return $this->createItemFromArray($data, $user->id); } - - /** - * Create the domain for the user custom fields - * - * @param JTableUser $user The JTableUser object to process - * - * @return PrivacyExportDomain - * - * @since 3.9.0 - */ - private function createUserCustomFieldsDomain(JTableUser $user) - { - $domain = $this->createDomain('user_custom_fields', 'joomla_user_custom_fields_data'); - - // Get item's fields, also preparing their value property for manual display - $fields = FieldsHelper::getFields('com_users.user', $user); - - foreach ($fields as $field) - { - $fieldValue = is_array($field->value) ? implode(', ', $field->value) : $field->value; - - $data = array( - 'user_id' => $user->id, - 'field_name' => $field->name, - 'field_title' => $field->title, - 'field_value' => $fieldValue, - ); - - $domain->addItem($this->createItemFromArray($data)); - } - - return $domain; - } }