diff --git a/administrator/components/com_admin/sql/updates/mysql/3.9.0-2018-04-01.sql b/administrator/components/com_admin/sql/updates/mysql/3.9.0-2018-04-01.sql new file mode 100644 index 0000000000000..b3f2e8f22664d --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/3.9.0-2018-04-01.sql @@ -0,0 +1,5 @@ +INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES +(481, 0, 'plg_user_privacyconsent', 'plugin', 'privacyconsent', 'user', 0, 0, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0); +INSERT INTO `#__postinstall_messages` (`extension_id`, `title_key`, `description_key`, `action_key`, `language_extension`, `language_client_id`, `type`, `action_file`, `action`, `condition_file`, `condition_method`, `version_introduced`, `enabled`) +VALUES +(700, 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_TITLE', 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_BODY', '', 'plg_user_privacyconsent', 1, 'message', '', '', '', '', '3.9.0', 1); diff --git a/administrator/components/com_admin/sql/updates/postgresql/3.9.0-2018-04-01.sql b/administrator/components/com_admin/sql/updates/postgresql/3.9.0-2018-04-01.sql new file mode 100644 index 0000000000000..9b9efce4fdd2a --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/3.9.0-2018-04-01.sql @@ -0,0 +1,5 @@ +INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES +(481, 0, 'plg_user_privacyconsent', 'plugin', 'privacyconsent', 'user', 0, 0, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0); +INSERT INTO "#__postinstall_messages" ("extension_id", "title_key", "description_key", "action_key", "language_extension", "language_client_id", "type", "action_file", "action", "condition_file", "condition_method", "version_introduced", "enabled") +VALUES +(700, 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_TITLE', 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_BODY', '', 'plg_user_privacyconsent', 1, 'message', '', '', '', '', '3.9.0', 1); \ No newline at end of file diff --git a/administrator/components/com_admin/sql/updates/sqlazure/3.9.0-2018-04-01.sql b/administrator/components/com_admin/sql/updates/sqlazure/3.9.0-2018-04-01.sql new file mode 100644 index 0000000000000..be3ae1c227a2d --- /dev/null +++ b/administrator/components/com_admin/sql/updates/sqlazure/3.9.0-2018-04-01.sql @@ -0,0 +1,5 @@ +INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES +(481, 0, 'plg_user_privacyconsent', 'plugin', 'privacyconsent', 'user', 0, 0, 1, 0, '', '', '', '', 0, '1990-01-01 00:00:00', 0, 0); +INSERT INTO "#__postinstall_messages" ("extension_id", "title_key", "description_key", "action_key", "language_extension", "language_client_id", "type", "action_file", "action", "condition_file", "condition_method", "version_introduced", "enabled") +VALUES +(700, 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_TITLE', 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_BODY', '', 'plg_user_privacyconsent', 1, 'message', '', '', '', '', '3.9.0', 1); diff --git a/administrator/language/en-GB/en-GB.plg_user_privacyconsent.ini b/administrator/language/en-GB/en-GB.plg_user_privacyconsent.ini new file mode 100644 index 0000000000000..7e22d31ed2f75 --- /dev/null +++ b/administrator/language/en-GB/en-GB.plg_user_privacyconsent.ini @@ -0,0 +1,23 @@ +; Joomla! Project +; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +PLG_USER_PRIVACYCONSENT_BODY="

The user consented to storing their user information using the IP address %s

The user agent string of the user's browser was:
%s

This information was automatically recorded when the user submitted their details on the web site and checked the confirm box

" +PLG_USER_PRIVACYCONSENT_FIELD_ARTICLE_DESC="Select the desired Privacy article from the list." +PLG_USER_PRIVACYCONSENT_FIELD_ARTICLE_LABEL="Privacy Article" +PLG_USER_PRIVACYCONSENT_FIELD_DESC="Read the full privacy policy" +PLG_USER_PRIVACYCONSENT_FIELD_ERROR="Agreement to the site's Privacy Policy is required." +PLG_USER_PRIVACYCONSENT_FIELD_LABEL="Privacy Policy" +PLG_USER_PRIVACYCONSENT_LABEL="Web Site Privacy" +PLG_USER_PRIVACYCONSENT_NOTE_FIELD_DEFAULT="By signing up to this web site and agreeing to the Privacy Policy you agree to this web site storing your information." +PLG_USER_PRIVACYCONSENT_NOTE_FIELD_DESC="Write a summary of the site's privacy policy." +PLG_USER_PRIVACYCONSENT_NOTE_FIELD_LABEL="Short Privacy Policy" +PLG_USER_PRIVACYCONSENT_OPTION_AGREE="I agree" +PLG_USER_PRIVACYCONSENT_POSTINSTALL_TITLE="Privacy Policy (GDPR) Plugin" +PLG_USER_PRIVACYCONSENT_POSTINSTALL_BODY="This is a basic plugin to request user's consent to the site's privacy policy. Existing users who have not consented yet will be redirected on login to update their profile." +PLG_USER_PRIVACYCONSENT_REDIRECT_MESSAGE_DEFAULT="Please confirm that you consent to this web site storing your information by agreeing to the privacy policy." +PLG_USER_PRIVACYCONSENT_REDIRECT_MESSAGE_DESC="Custom message to be displayed on redirect. If left blank then the default message will be used." +PLG_USER_PRIVACYCONSENT_REDIRECT_MESSAGE_LABEL="Redirect Message" +PLG_USER_PRIVACYCONSENT_SUBJECT="Privacy Policy" +PLG_USER_PRIVACYCONSENT_XML_DESCRIPTION="Basic plugin to request user's consent to the site's privacy policy. Existing users who have not consented yet will be redirected on login to update their profile." diff --git a/administrator/language/en-GB/en-GB.plg_user_privacyconsent.sys.ini b/administrator/language/en-GB/en-GB.plg_user_privacyconsent.sys.ini new file mode 100644 index 0000000000000..ac4a81f877bec --- /dev/null +++ b/administrator/language/en-GB/en-GB.plg_user_privacyconsent.sys.ini @@ -0,0 +1,7 @@ +; Joomla! Project +; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved. +; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php +; Note : All ini files need to be saved as UTF-8 + +PLG_USER_PRIVACYCONSENT="User - Privacy Consent" +PLG_USER_PRIVACYCONSENT_XML_DESCRIPTION="Basic plugin to request user's consent to the site's privacy policy. Existing users who have not consented yet will be redirected on login to update their profile." \ No newline at end of file diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index 72dddaa5bb888..361d4df8a6dcb 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -643,6 +643,7 @@ INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `elem (478, 0, 'plg_editors-xtd_fields', 'plugin', 'fields', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0), (479, 0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0), (480, 0, 'plg_system_sessiongc', 'plugin', 'sessiongc', 'system', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0), +(481, 0, 'plg_user_privacyconsent', 'plugin', 'privacyconsent', 'user', 0, 0, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0), (503, 0, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '0000-00-00 00:00:00', 0, 0), (504, 0, 'hathor', 'template', 'hathor', '', 1, 1, 1, 0, '', '{"showSiteName":"0","colourChoice":"0","boldText":"0"}', '', '', 0, '0000-00-00 00:00:00', 0, 0), (506, 0, 'protostar', 'template', 'protostar', '', 0, 1, 1, 0, '', '{"templateColor":"","logoFile":"","googleFont":"1","googleFontName":"Open+Sans","fluidContainer":"0"}', '', '', 0, '0000-00-00 00:00:00', 0, 0), @@ -1644,7 +1645,8 @@ INSERT INTO `#__postinstall_messages` (`extension_id`, `title_key`, `description (700, 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME', 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_BODY', 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_ACTION', 'plg_system_updatenotification', 1, 'action', 'site://plugins/system/updatenotification/postinstall/updatecachetime.php', 'updatecachetime_postinstall_action', 'site://plugins/system/updatenotification/postinstall/updatecachetime.php', 'updatecachetime_postinstall_condition', '3.6.3', 1), (700, 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_TITLE', 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_BODY', '', 'com_cpanel', 1, 'message', '', '', 'admin://components/com_admin/postinstall/joomla40checks.php', 'admin_postinstall_joomla40checks_condition', '3.7.0', 1), (700, 'TPL_HATHOR_MESSAGE_POSTINSTALL_TITLE', 'TPL_HATHOR_MESSAGE_POSTINSTALL_BODY', 'TPL_HATHOR_MESSAGE_POSTINSTALL_ACTION', 'tpl_hathor', 1, 'action', 'admin://templates/hathor/postinstall/hathormessage.php', 'hathormessage_postinstall_action', 'admin://templates/hathor/postinstall/hathormessage.php', 'hathormessage_postinstall_condition', '3.7.0', 1), -(700, 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_TITLE', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_BODY', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_ACTION', 'plg_captcha_recaptcha', 1, 'action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_condition', '3.8.6', 1); +(700, 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_TITLE', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_BODY', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_ACTION', 'plg_captcha_recaptcha', 1, 'action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_condition', '3.8.6', 1), +(700, 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_TITLE', 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_BODY', '', 'plg_user_privacyconsent', 1, 'message', '', '', '', '', '3.9.0', 1); -- -------------------------------------------------------- diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index d5686a2e6f61c..ea523ad5b294e 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -657,6 +657,7 @@ INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "elem (478, 0, 'plg_editors-xtd_fields', 'plugin', 'fields', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0), (479, 0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0), (480, 0, 'plg_system_sessiongc', 'plugin', 'sessiongc', 'system', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0), +(481, 0, 'plg_user_privacyconsent', 'plugin', 'privacyconsent', 'user', 0, 0, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0); (503, 0, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '1970-01-01 00:00:00', 0, 0), (504, 0, 'hathor', 'template', 'hathor', '', 1, 1, 1, 0, '', '{"showSiteName":"0","colourChoice":"0","boldText":"0"}', '', '', 0, '1970-01-01 00:00:00', 0, 0), (506, 0, 'protostar', 'template', 'protostar', '', 0, 1, 1, 0, '', '{"templateColor":"","logoFile":"","googleFont":"1","googleFontName":"Open+Sans","fluidContainer":"0"}', '', '', 0, '1970-01-01 00:00:00', 0, 0), @@ -1627,7 +1628,8 @@ INSERT INTO "#__postinstall_messages" ("extension_id", "title_key", "description (700, 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME', 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_BODY', 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_ACTION', 'plg_system_updatenotification', 1, 'action', 'site://plugins/system/updatenotification/postinstall/updatecachetime.php', 'updatecachetime_postinstall_action', 'site://plugins/system/updatenotification/postinstall/updatecachetime.php', 'updatecachetime_postinstall_condition', '3.6.3', 1), (700, 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_TITLE', 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_BODY', '', 'com_cpanel', 1, 'message', '', '', 'admin://components/com_admin/postinstall/joomla40checks.php', 'admin_postinstall_joomla40checks_condition', '3.7.0', 1), (700, 'TPL_HATHOR_MESSAGE_POSTINSTALL_TITLE', 'TPL_HATHOR_MESSAGE_POSTINSTALL_BODY', 'TPL_HATHOR_MESSAGE_POSTINSTALL_ACTION', 'tpl_hathor', 1, 'action', 'admin://templates/hathor/postinstall/hathormessage.php', 'hathormessage_postinstall_action', 'admin://templates/hathor/postinstall/hathormessage.php', 'hathormessage_postinstall_condition', '3.7.0', 1), -(700, 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_TITLE', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_BODY', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_ACTION', 'plg_captcha_recaptcha', 1, 'action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_condition', '3.8.6', 1); +(700, 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_TITLE', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_BODY', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_ACTION', 'plg_captcha_recaptcha', 1, 'action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_condition', '3.8.6', 1), +(700, 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_TITLE', 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_BODY', '', 'plg_user_privacyconsent', 1, 'message', '', '', '', '', '3.9.0', 1); -- -- Table structure for table `#__redirect_links` diff --git a/installation/sql/sqlazure/joomla.sql b/installation/sql/sqlazure/joomla.sql index 49e643241b005..7b25a96744804 100644 --- a/installation/sql/sqlazure/joomla.sql +++ b/installation/sql/sqlazure/joomla.sql @@ -872,6 +872,7 @@ INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "elem (478, 0, 'plg_editors-xtd_fields', 'plugin', 'fields', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0), (479, 0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0), (480, 0, 'plg_system_sessiongc', 'plugin', 'sessiongc', 'system', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0), +(481, 0, 'plg_user_privacyconsent', 'plugin', 'privacyconsent', 'user', 0, 0, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0); (503, 0, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '1900-01-01 00:00:00', 0, 0), (504, 0, 'hathor', 'template', 'hathor', '', 1, 1, 1, 0, '', '{"showSiteName":"0","colourChoice":"0","boldText":"0"}', '', '', 0, '1900-01-01 00:00:00', 0, 0), (506, 0, 'protostar', 'template', 'protostar', '', 0, 1, 1, 0, '', '{"templateColor":"","logoFile":"","googleFont":"1","googleFontName":"Open+Sans","fluidContainer":"0"}', '', '', 0, '1900-01-01 00:00:00', 0, 0), @@ -2342,7 +2343,8 @@ INSERT INTO "#__postinstall_messages" ("extension_id", "title_key", "description (700, 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME', 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_BODY', 'PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_ACTION', 'plg_system_updatenotification', 1, 'action', 'site://plugins/system/updatenotification/postinstall/updatecachetime.php', 'updatecachetime_postinstall_action', 'site://plugins/system/updatenotification/postinstall/updatecachetime.php', 'updatecachetime_postinstall_condition', '3.6.3', 1), (700, 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_TITLE', 'COM_CPANEL_MSG_JOOMLA40_PRE_CHECKS_BODY', '', 'com_cpanel', 1, 'message', '', '', 'admin://components/com_admin/postinstall/joomla40checks.php', 'admin_postinstall_joomla40checks_condition', '3.7.0', 1), (700, 'TPL_HATHOR_MESSAGE_POSTINSTALL_TITLE', 'TPL_HATHOR_MESSAGE_POSTINSTALL_BODY', 'TPL_HATHOR_MESSAGE_POSTINSTALL_ACTION', 'tpl_hathor', 1, 'action', 'admin://templates/hathor/postinstall/hathormessage.php', 'hathormessage_postinstall_action', 'admin://templates/hathor/postinstall/hathormessage.php', 'hathormessage_postinstall_condition', '3.7.0', 1), -(700, 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_TITLE', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_BODY', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_ACTION', 'plg_captcha_recaptcha', 1, 'action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_condition', '3.8.6', 1); +(700, 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_TITLE', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_BODY', 'PLG_PLG_RECAPTCHA_VERSION_1_POSTINSTALL_ACTION', 'plg_captcha_recaptcha', 1, 'action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_action', 'site://plugins/captcha/recaptcha/postinstall/actions.php', 'recaptcha_postinstall_condition', '3.8.6', 1), +(700, 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_TITLE', 'PLG_USER_PRIVACYCONSENT_POSTINSTALL_BODY', '', 'plg_user_privacyconsent', 1, 'message', '', '', '', '', '3.9.0', 1); -- -- Table structure for table `#__redirect_links` diff --git a/libraries/src/Extension/ExtensionHelper.php b/libraries/src/Extension/ExtensionHelper.php index 373fd1b6f6bee..86dd57e5f1d94 100644 --- a/libraries/src/Extension/ExtensionHelper.php +++ b/libraries/src/Extension/ExtensionHelper.php @@ -234,6 +234,7 @@ class ExtensionHelper // Core plugin extensions - user array('plugin', 'contactcreator', 'user', 0), array('plugin', 'joomla', 'user', 0), + array('plugin', 'privacyconsent', 'user', 0), array('plugin', 'profile', 'user', 0), // Core template extensions - administrator diff --git a/plugins/user/privacyconsent/field/privacy.php b/plugins/user/privacyconsent/field/privacy.php new file mode 100644 index 0000000000000..834986ea14acc --- /dev/null +++ b/plugins/user/privacyconsent/field/privacy.php @@ -0,0 +1,136 @@ +element['note']) ? $this->element['note'] : Text::_('PLG_USER_PRIVACYCONSENT_NOTE_FIELD_DEFAULT'); + + echo '
' . $privacynote . '
'; + + return parent::getInput(); + } + + /** + * Method to get the field label markup. + * + * @return string The field label markup. + * + * @since __DEPLOY_VERSION__ + */ + protected function getLabel() + { + if ($this->hidden) + { + return ''; + } + + // Get the label text from the XML element, defaulting to the element name. + $text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name']; + $text = $this->translateLabel ? Text::_($text) : $text; + + // Set required to true as this field is not displayed at all if not required. + $this->required = true; + + JHtml::_('behavior.modal'); + + // Build the class for the label. + $class = !empty($this->description) ? 'hasTooltip' : ''; + $class = $class . ' required'; + $class = !empty($this->labelClass) ? $class . ' ' . $this->labelClass : $class; + + // Add the opening label tag and main attributes. + $label = ''; + + return $label; + } +} diff --git a/plugins/user/privacyconsent/privacyconsent.php b/plugins/user/privacyconsent/privacyconsent.php new file mode 100644 index 0000000000000..899bf7eb12a3f --- /dev/null +++ b/plugins/user/privacyconsent/privacyconsent.php @@ -0,0 +1,374 @@ +_subject->setError('JERROR_NOT_A_FORM'); + + return false; + } + + // Check we are manipulating a valid form - we do not display this in the admin users form or profile view. + $name = $form->getName(); + $layout = $this->app->input->get('layout', 'default', 'string'); + $view = $this->app->input->get('view', 'default', 'string'); + + // Check for the correct form. + if (!in_array($name, array('com_admin.profile', 'com_users.profile', 'com_users.registration'))) + { + return true; + } + + // Check for the correct layout and view. + if ($layout != 'edit' && $view != 'registration') + { + return true; + } + + // Add the registration fields to the form. + JForm::addFormPath(__DIR__ . '/privacyconsent'); + $form->loadFile('privacyconsent'); + + $fields = array( + 'privacy', + ); + + if (is_object($data)) + { + $userId = isset($data->id) ? $data->id : 0; + + if ($userId > 0) + { + // Load the profile data from the database. + $db = JFactory::getDbo(); + + $query = $db->getQuery(true) + ->select($db->quoteName('profile_value')) + ->from($db->quoteName('#__user_profiles')) + ->where($db->quoteName('user_id') . ' = ' . (int) $userId) + ->where($db->quoteName('profile_key') . ' = ' . $db->quote('consent')) + ->where($db->quoteName('profile_value') . ' = ' . $db->quote('1')); + $db->setQuery($query); + + try + { + $results = $db->loadRowList(); + } + + catch (RuntimeException $e) + { + $this->_subject->setError($e->getMessage()); + + return false; + } + + if (!empty($results[0])) + { + $form->removeField('privacy', 'privacyconsent'); + $form->removeGroup('privacyconsent'); + + return true; + } + } + } + + $privacyarticle = $this->params->get('privacy_article'); + $privacynote = $this->params->get('privacy_note'); + + // Push the privacy article ID into the privacy field. + $form->setFieldAttribute('privacy', 'article', $privacyarticle, 'privacyconsent'); + $form->setFieldAttribute('privacy', 'note', $privacynote, 'privacyconsent'); + } + + /** + * Method is called before user data is stored in the database + * + * @param array $user Holds the old user data. + * @param boolean $isNew True if a new user is stored. + * @param array $data Holds the new user data. + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + * @throws InvalidArgumentException on missing required data. + */ + public function onUserBeforeSave($user, $isNew, $data) + { + // Check that the privacy is checked if required ie only in registration from frontend. + $form = $this->app->input->post->get('jform', array(), 'array'); + + if ($this->app->isClient('administrator')) + { + return true; + } + + if (isset($form['privacyconsent']['privacy']) && (!$form['privacyconsent']['privacy'])) + { + throw new InvalidArgumentException(Text::_('PLG_USER_PRIVACYCONSENT_FIELD_ERROR')); + } + + return true; + } + + /** + * Saves user privacy confirmation and note + * + * @param array $data entered user data + * @param boolean $isNew true if this is a new user + * @param boolean $result true if saving the user worked + * @param string $error error message + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public function onUserAfterSave($data, $isNew, $result, $error) + { + $option = $this->app->input->getCmd('option'); + + // Only create an entry on front-end user creation/update and admin profile + if ($this->app->isClient('administrator') && $option != 'com_admin') + { + return; + } + + $form = $this->app->input->post->get('jform', array(), 'array'); + + if (isset($form['privacyconsent']['privacy']) && ($form['privacyconsent']['privacy'])) + { + // Get the user's ID + $userId = ArrayHelper::getValue($data, 'id', 0, 'int'); + + // Get the user's IP address + $ip = $this->app->input->server->get('REMOTE_ADDR', '', 'string'); + + // Get the user agent string + $userAgent = $this->app->input->server->get('HTTP_USER_AGENT', '', 'string'); + + // Create the user note + $userNote = (object) array( + 'user_id' => $userId, + 'catid' => 0, + 'subject' => Text::_('PLG_USER_PRIVACYCONSENT_SUBJECT'), + 'body' => Text::sprintf('PLG_USER_PRIVACYCONSENT_BODY', $ip, $userAgent), + 'state' => 1, + 'created_time' => Factory::getDate()->toSql(), + ); + + try + { + $this->db->insertObject('#__user_notes', $userNote); + } + catch (Exception $e) + { + // Do nothing if the save fails + } + + // Create the consent confirmation + $confirm = (object) array( + 'user_id' => $userId, + 'profile_key' => 'consent', + 'profile_value' => 1 + ); + + try + { + $this->db->insertObject('#__user_profiles', $confirm); + } + catch (Exception $e) + { + // Do nothing if the save fails + } + } + + return true; + } + + /** + * Remove all user privacy consent information for the given user ID + * + * Method is called after user data is deleted from the database + * + * @param array $user Holds the user data + * @param boolean $success True if user was succesfully stored in the database + * @param string $msg Message + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + public function onUserAfterDelete($user, $success, $msg) + { + if (!$success) + { + return false; + } + + $userId = ArrayHelper::getValue($user, 'id', 0, 'int'); + + if ($userId) + { + // Remove any user notes + try + { + $query = $this->db->getQuery(true) + ->delete($this->db->quoteName('#__user_notes')) + ->where($this->db->quoteName('user_id') . ' = ' . (int) $userId); + $this->db->setQuery($query); + $this->db->execute(); + } + catch (Exception $e) + { + $this->_subject->setError($e->getMessage()); + + return false; + } + + // Remove any user profile fields + try + { + $query = $this->db->getQuery(true) + ->delete($this->db->quoteName('#__user_profiles')) + ->where($this->db->quoteName('user_id') . ' = ' . (int) $userId); + $this->db->setQuery($query); + $this->db->execute(); + } + catch (Exception $e) + { + $this->_subject->setError($e->getMessage()); + + return false; + } + } + + return true; + } + + /** + * Check if a user has already consented when they login. + * If not will load the edit profile + * + * @param array $options Array holding options + * + * @return boolean True on success + * + * @since __DEPLOY_VERSION__ + */ + public function onUserAfterLogin($options) + { + // Run this in frontend only + if ($this->app->isClient('administrator')) + { + return; + } + + $userId = Factory::getUser()->id; + + $query = $this->db->getQuery(true) + ->select('1') + ->from($this->db->quoteName('#__user_profiles')) + ->where($this->db->quoteName('user_id') . ' = ' . (int) $userId) + ->where($this->db->quoteName('profile_key') . ' = ' . $this->db->quote('consent')); + $this->db->setQuery($query); + + $consent = $this->db->loadObjectList(); + + if (count($consent) != 0) + { + return; + } + + // If the count of $consent is 0 then redirect to com_users profile edit + $this->app->enqueueMessage($this->getRedirectMessage(), 'notice'); + $this->app->redirect(\JRoute::_('index.php?option=com_users&view=profile&layout=edit', false)); + } + + /** + * Returns the configured redirect message and falls back to the default version. + * + * @return string redirect message + * + * @since __DEPLOY_VERSION__ + */ + private function getRedirectMessage() + { + $messageOnRedirect = trim($this->params->get('messageOnRedirect', '')); + + if (empty($messageOnRedirect)) + { + return Text::_('PLG_USER_PRIVACYCONSENT_REDIRECT_MESSAGE_DEFAULT'); + } + + return $messageOnRedirect; + } +} diff --git a/plugins/user/privacyconsent/privacyconsent.xml b/plugins/user/privacyconsent/privacyconsent.xml new file mode 100644 index 0000000000000..d3abaeb16bbe5 --- /dev/null +++ b/plugins/user/privacyconsent/privacyconsent.xml @@ -0,0 +1,59 @@ + + + plg_user_privacyconsent + Joomla! Project + April 2018 + (C) 2005 - 2018 Open Source Matters. All rights reserved. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + 3.9.0 + PLG_USER_PRIVACYCONSENT_XML_DESCRIPTION + + privacyconsent.php + privacyconsent + field + + + en-GB.plg_user_privacyconsent.ini + en-GB.plg_user_privacyconsent.sys.ini + + + +
+ + + +
+
+
+
diff --git a/plugins/user/privacyconsent/privacyconsent/privacyconsent.xml b/plugins/user/privacyconsent/privacyconsent/privacyconsent.xml new file mode 100644 index 0000000000000..95ffefbcd6249 --- /dev/null +++ b/plugins/user/privacyconsent/privacyconsent/privacyconsent.xml @@ -0,0 +1,20 @@ + +
+ +
+ + + + +
+
+