From da6af42d3e3fd67cfd057155bfa2bdf9ca8ed745 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Wed, 16 May 2018 22:27:18 +0300 Subject: [PATCH 01/39] added the access field to user --- .../com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql | 5 +++++ administrator/components/com_users/forms/user.xml | 7 +++++++ administrator/components/com_users/tmpl/user/edit.php | 6 ++++-- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql diff --git a/administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql new file mode 100644 index 0000000000000..7525860105320 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql @@ -0,0 +1,5 @@ +-- +-- Add access column for access levels #__content +-- + +ALTER TABLE `#__content` ADD COLUMN `access` int(10) unsigned NOT NULL DEFAULT 0; diff --git a/administrator/components/com_users/forms/user.xml b/administrator/components/com_users/forms/user.xml index e0f93a938fb9c..a6af8669a5c96 100644 --- a/administrator/components/com_users/forms/user.xml +++ b/administrator/components/com_users/forms/user.xml @@ -139,6 +139,13 @@ readonly="true" /> + + diff --git a/administrator/components/com_users/tmpl/user/edit.php b/administrator/components/com_users/tmpl/user/edit.php index 661e87e4276a1..52907c04e7d5e 100644 --- a/administrator/components/com_users/tmpl/user/edit.php +++ b/administrator/components/com_users/tmpl/user/edit.php @@ -9,6 +9,8 @@ defined('_JEXEC') or die; +use Joomla\CMS\Layout\LayoutHelper; + // Include the component HTML helpers. JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); @@ -22,7 +24,7 @@
- +
'details')); ?> @@ -48,7 +50,7 @@ ignore_fieldsets = array('user_details'); - echo JLayoutHelper::render('joomla.edit.params', $this); + echo LayoutHelper::render('joomla.edit.params', $this); ?> tfaform) && $this->item->id) : ?> From 0f853d56a69a72d61a8633387062723b1c1565f0 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Thu, 17 May 2018 20:43:48 +0300 Subject: [PATCH 02/39] added access column in users list and option in batch processing --- .../sql/updates/mysql/4.0.0-2018-05-16.sql | 4 +- .../updates/postgresql/4.0.0-2018-05-16.sql | 1 + .../components/com_users/Model/UserModel.php | 10 +++ .../components/com_users/Model/UsersModel.php | 12 ++- .../com_users/View/Users/HtmlView.php | 3 +- .../components/com_users/tmpl/user/edit.php | 39 +++++---- .../com_users/tmpl/users/default.php | 86 +++++++++++-------- .../tmpl/users/default_batch_body.php | 52 +++++++---- .../tmpl/users/default_batch_footer.php | 5 +- installation/sql/mysql/joomla.sql | 1 + installation/sql/postgresql/joomla.sql | 1 + 11 files changed, 135 insertions(+), 79 deletions(-) create mode 100644 administrator/components/com_admin/sql/updates/postgresql/4.0.0-2018-05-16.sql diff --git a/administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql index 7525860105320..b28308712dd06 100644 --- a/administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql +++ b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql @@ -1,5 +1,5 @@ -- --- Add access column for access levels #__content +-- Add access column for access levels #__users -- -ALTER TABLE `#__content` ADD COLUMN `access` int(10) unsigned NOT NULL DEFAULT 0; +ALTER TABLE `#__users` ADD COLUMN `access` int(10) unsigned NOT NULL DEFAULT 1; diff --git a/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2018-05-16.sql b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2018-05-16.sql new file mode 100644 index 0000000000000..e3ec88d91f935 --- /dev/null +++ b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2018-05-16.sql @@ -0,0 +1 @@ +ALTER TABLE "#__users" ADD COLUMN "access" bigint NOT NULL DEFAULT 1; diff --git a/administrator/components/com_users/Model/UserModel.php b/administrator/components/com_users/Model/UserModel.php index 2b269f93de7d5..31c9315ffa823 100644 --- a/administrator/components/com_users/Model/UserModel.php +++ b/administrator/components/com_users/Model/UserModel.php @@ -679,6 +679,16 @@ public function batch($commands, $pks, $contexts) $done = true; } + if (!empty($commands['assetgroup_id'])) + { + if (!$this->batchAccess($commands['assetgroup_id'], $pks, $contexts)) + { + return false; + } + + $done = true; + } + if (!$done) { $this->setError(\JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION')); diff --git a/administrator/components/com_users/Model/UsersModel.php b/administrator/components/com_users/Model/UsersModel.php index 1198fb6afec16..6ae0edf8b1e53 100644 --- a/administrator/components/com_users/Model/UsersModel.php +++ b/administrator/components/com_users/Model/UsersModel.php @@ -50,6 +50,7 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu 'range', 'lastvisitrange', 'state', + 'access', 'a.access', 'access_level', ); } @@ -96,6 +97,9 @@ protected function populateState($ordering = 'a.name', $direction = 'asc') $this->setState('filter.excluded', $excluded); + $access = json_decode(base64_decode($app->input->get('access', '', 'BASE64'))); + $this->setState('filter.access', $access); + // Load the parameters. $params = ComponentHelper::getParams('com_users'); $this->setState('params', $params); @@ -125,6 +129,7 @@ protected function getStoreId($id = '') $id .= ':' . $this->getState('filter.state'); $id .= ':' . $this->getState('filter.group_id'); $id .= ':' . $this->getState('filter.range'); + $id .= ':' . serialize($this->getState('filter.access')); return parent::getStoreId($id); } @@ -295,6 +300,10 @@ protected function getListQuery() } } + // Join over the asset groups. + $query->select('ag.title AS access_level') + ->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); + // Filter the items over the group id if set. $groupId = $this->getState('filter.group_id'); $groups = $this->getState('filter.groups'); @@ -320,7 +329,8 @@ protected function getListQuery() 'a.resetCount', 'a.otpKey', 'a.otep', - 'a.requireReset' + 'a.requireReset', + 'a.access' ) ) ); diff --git a/administrator/components/com_users/View/Users/HtmlView.php b/administrator/components/com_users/View/Users/HtmlView.php index 6a10556021c2f..13b5a1a21e617 100644 --- a/administrator/components/com_users/View/Users/HtmlView.php +++ b/administrator/components/com_users/View/Users/HtmlView.php @@ -104,7 +104,7 @@ public function display($tpl = null) $this->db = \JFactory::getDbo(); UsersHelper::addSubmenu('users'); - +//var_dump($this->items); // Check for errors. if (count($errors = $this->get('Errors'))) { @@ -194,6 +194,7 @@ protected function getSortFields() 'a.username' => \JText::_('JGLOBAL_USERNAME'), 'a.block' => \JText::_('COM_USERS_HEADING_ENABLED'), 'a.activation' => \JText::_('COM_USERS_HEADING_ACTIVATED'), + 'access_level' => \JText::_('JGRID_HEADING_ACCESS'), 'a.email' => \JText::_('JGLOBAL_EMAIL'), 'a.lastvisitDate' => \JText::_('COM_USERS_HEADING_LAST_VISIT_DATE'), 'a.registerDate' => \JText::_('COM_USERS_HEADING_REGISTRATION_DATE'), diff --git a/administrator/components/com_users/tmpl/user/edit.php b/administrator/components/com_users/tmpl/user/edit.php index 52907c04e7d5e..b7aa68d27ee48 100644 --- a/administrator/components/com_users/tmpl/user/edit.php +++ b/administrator/components/com_users/tmpl/user/edit.php @@ -10,12 +10,15 @@ defined('_JEXEC') or die; use Joomla\CMS\Layout\LayoutHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\HTML\HTMLHelper; + // Include the component HTML helpers. -JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); +HTMLHelper::addIncludePath(JPATH_COMPONENT . '/helpers/html'); -JHtml::_('behavior.formvalidator'); -JHtml::_('script', 'com_users/admin-users-user.min.js', array('version' => 'auto', 'relative' => true)); +HTMLHelper::_('behavior.formvalidator'); +HTMLHelper::_('script', 'com_users/admin-users-user.min.js', array('version' => 'auto', 'relative' => true)); // Get the form fieldsets. $fieldsets = $this->form->getFieldsets(); @@ -27,9 +30,9 @@
- 'details')); ?> + 'details')); ?> - + form->getFieldset('user_details') as $field) : ?>
@@ -40,12 +43,12 @@
- + grouplist) : ?> - + loadTemplate('groups'); ?> - + tfaform) && $this->item->id) : ?> - +
- 'Joomla.twoFactorMethodChange()', 'class' => 'custom-select'), 'value', 'text', $this->otpConfig->method, 'jform_twofactor_method', false); ?> + 'Joomla.twoFactorMethodChange()', 'class' => 'custom-select'), 'value', 'text', $this->otpConfig->method, 'jform_twofactor_method', false); ?>
@@ -77,11 +80,11 @@
- + - + otpConfig->otep)) : ?> - + otpConfig->otep as $otep) : ?> @@ -91,12 +94,12 @@
- + - +
- + diff --git a/administrator/components/com_users/tmpl/users/default.php b/administrator/components/com_users/tmpl/users/default.php index 9596ca87eeb83..082267bbab438 100644 --- a/administrator/components/com_users/tmpl/users/default.php +++ b/administrator/components/com_users/tmpl/users/default.php @@ -9,15 +9,23 @@ defined('_JEXEC') or die; -JHtml::_('behavior.multiselect'); -JHtml::_('behavior.tabstate'); +use Joomla\CMS\Layout\LayoutHelper; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Access\Access; +use Joomla\CMS\String\PunycodeHelper; +use Joomla\CMS\Router\Route; + +HTMLHelper::_('behavior.multiselect'); +HTMLHelper::_('behavior.tabstate'); +HTMLHelper::_('formbehavior.chosen', '.multipleAccessLevels', null, array('placeholder_text_multiple' => Text::_('JOPTION_SELECT_ACCESS'))); $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); $loggeduser = JFactory::getUser(); $debugUsers = $this->state->get('params')->get('debugUsers', 1); ?> -
+
sidebar; ?> @@ -26,43 +34,46 @@
$this)); + echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?> items)) : ?> - + + @@ -79,7 +90,7 @@ $canChange = $loggeduser->authorise('core.edit.state', 'com_users'); // If this group is super admin and this user is not super admin, $canEdit is false - if ((!$loggeduser->authorise('core.admin')) && JAccess::check($item->id, 'core.admin')) + if ((!$loggeduser->authorise('core.admin')) && Access::check($item->id, 'core.admin')) { $canEdit = false; $canChange = false; @@ -88,37 +99,37 @@ + - + From 920b5174b14e10218549fcc270d5f50c18494a29 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Wed, 8 Aug 2018 21:11:23 +0300 Subject: [PATCH 39/39] Changes after code review --- administrator/components/com_users/tmpl/users/default.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_users/tmpl/users/default.php b/administrator/components/com_users/tmpl/users/default.php index 183356b6d3535..dfce0cd516ef6 100644 --- a/administrator/components/com_users/tmpl/users/default.php +++ b/administrator/components/com_users/tmpl/users/default.php @@ -152,7 +152,7 @@
- + - + - + - + - + - + + + - + - + - + - +
- id); ?> + id); ?>
- + escape($item->name); ?> escape($item->name); ?>
- id); ?> + id); ?> note_count > 0) : ?>
- note_count, $item->id); ?> + note_count, $item->id); ?> requireReset == '1') : ?> - + - +
@@ -128,37 +139,40 @@ id == $item->id; - echo JHtml::_('jgrid.state', JHtmlUsers::blockStates($self), $item->block, $i, 'users.', !$self); + echo HTMLHelper::_('jgrid.state', JHtmlUsers::blockStates($self), $item->block, $i, 'users.', !$self); ?> - block ? 'JNO' : 'JYES'); ?> + block ? 'JNO' : 'JYES'); ?> activation) ? 0 : 1; - echo JHtml::_('jgrid.state', JHtmlUsers::activateStates(), $activated, $i, 'users.', (boolean) $activated); + echo HTMLHelper::_('jgrid.state', JHtmlUsers::activateStates(), $activated, $i, 'users.', (boolean) $activated); ?> group_names, "\n") > 1) : ?> - + group_names); ?> + escape($item->access_level); ?> + - escape($item->email)); ?> + escape($item->email)); ?> lastvisitDate != $this->db->getNullDate()) : ?> - lastvisitDate, 'Y-m-d H:i:s'); ?> + lastvisitDate, 'Y-m-d H:i:s'); ?> - + - registerDate, 'Y-m-d H:i:s'); ?> + registerDate, 'Y-m-d H:i:s'); ?> id; ?> @@ -171,11 +185,11 @@ authorise('core.create', 'com_users') && $loggeduser->authorise('core.edit', 'com_users') && $loggeduser->authorise('core.edit.state', 'com_users')) : ?> - JText::_('COM_USERS_BATCH_OPTIONS'), + 'title' => Text::_('COM_USERS_BATCH_OPTIONS'), 'footer' => $this->loadTemplate('batch_footer'), ), $this->loadTemplate('batch_body') @@ -185,7 +199,7 @@ - + diff --git a/administrator/components/com_users/tmpl/users/default_batch_body.php b/administrator/components/com_users/tmpl/users/default_batch_body.php index 1dba33629206b..c03a37a33301e 100644 --- a/administrator/components/com_users/tmpl/users/default_batch_body.php +++ b/administrator/components/com_users/tmpl/users/default_batch_body.php @@ -8,40 +8,54 @@ */ defined('_JEXEC') or die; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; + // Create the copy/move options. $options = array( - JHtml::_('select.option', 'add', JText::_('COM_USERS_BATCH_ADD')), - JHtml::_('select.option', 'del', JText::_('COM_USERS_BATCH_DELETE')), - JHtml::_('select.option', 'set', JText::_('COM_USERS_BATCH_SET')) + HTMLHelper::_('select.option', 'add', Text::_('COM_USERS_BATCH_ADD')), + HTMLHelper::_('select.option', 'del', Text::_('COM_USERS_BATCH_DELETE')), + HTMLHelper::_('select.option', 'set', Text::_('COM_USERS_BATCH_SET')) ); // Create the reset password options. $resetOptions = array( - JHtml::_('select.option', '', JText::_('COM_USERS_NO_ACTION')), - JHtml::_('select.option', 'yes', JText::_('JYES')), - JHtml::_('select.option', 'no', JText::_('JNO')) + HTMLHelper::_('select.option', '', Text::_('COM_USERS_NO_ACTION')), + HTMLHelper::_('select.option', 'yes', Text::_('JYES')), + HTMLHelper::_('select.option', 'no', Text::_('JNO')) ); ?>
-
- +
+
+ +
+
+
+ +
+
-
-
- +
+
+
- -
- +
+
+
+ +
+ +
diff --git a/administrator/components/com_users/tmpl/users/default_batch_footer.php b/administrator/components/com_users/tmpl/users/default_batch_footer.php index a94767014867e..4e2917b8ceb86 100644 --- a/administrator/components/com_users/tmpl/users/default_batch_footer.php +++ b/administrator/components/com_users/tmpl/users/default_batch_footer.php @@ -7,11 +7,12 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; +use Joomla\CMS\Language\Text; ?> - + \ No newline at end of file diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index 57f0940063945..a9c2745b85984 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -1994,6 +1994,7 @@ CREATE TABLE IF NOT EXISTS `#__users` ( `otpKey` varchar(1000) NOT NULL DEFAULT '' COMMENT 'Two factor authentication encrypted keys', `otep` varchar(1000) NOT NULL DEFAULT '' COMMENT 'One time emergency passwords', `requireReset` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'Require user to reset password on next login', + `access` int(10) unsigned NOT NULL DEFAULT 1, PRIMARY KEY (`id`), KEY `idx_name` (`name`(100)), KEY `idx_block` (`block`), diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index b8aa76646928f..ca893e3879b99 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -1977,6 +1977,7 @@ CREATE TABLE IF NOT EXISTS "#__users" ( "otpKey" varchar(1000) DEFAULT '' NOT NULL, "otep" varchar(1000) DEFAULT '' NOT NULL, "requireReset" smallint DEFAULT 0, + "access" bigint DEFAULT 1 NOT NULL, PRIMARY KEY ("id") ); CREATE INDEX "#__users_idx_name" ON "#__users" ("name"); From f94be7cbf7667ad814a2df584471a934b596b75d Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Tue, 22 May 2018 16:09:44 +0300 Subject: [PATCH 03/39] deleted var_dump --- administrator/components/com_users/View/Users/HtmlView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_users/View/Users/HtmlView.php b/administrator/components/com_users/View/Users/HtmlView.php index 13b5a1a21e617..1f8113f172f1e 100644 --- a/administrator/components/com_users/View/Users/HtmlView.php +++ b/administrator/components/com_users/View/Users/HtmlView.php @@ -104,7 +104,7 @@ public function display($tpl = null) $this->db = \JFactory::getDbo(); UsersHelper::addSubmenu('users'); -//var_dump($this->items); + // Check for errors. if (count($errors = $this->get('Errors'))) { From 1fdb5884b2e5b40462ec08077e1afdd0577fe8ce Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Wed, 30 May 2018 17:22:17 +0200 Subject: [PATCH 04/39] Fixed pr requirements --- .../sql/updates/mysql/4.0.0-2018-05-16.sql | 2 +- .../updates/postgresql/4.0.0-2018-05-16.sql | 2 +- .../components/com_users/Model/UsersModel.php | 2 +- .../tmpl/users/default_batch_body.php | 40 ++++++++++--------- installation/sql/mysql/joomla.sql | 2 +- installation/sql/postgresql/joomla.sql | 2 +- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql index b28308712dd06..fc6649ab0978d 100644 --- a/administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql +++ b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2018-05-16.sql @@ -2,4 +2,4 @@ -- Add access column for access levels #__users -- -ALTER TABLE `#__users` ADD COLUMN `access` int(10) unsigned NOT NULL DEFAULT 1; +ALTER TABLE `#__users` ADD COLUMN `access` int(10) unsigned NOT NULL DEFAULT 0; diff --git a/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2018-05-16.sql b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2018-05-16.sql index e3ec88d91f935..e1d20120be6ab 100644 --- a/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2018-05-16.sql +++ b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2018-05-16.sql @@ -1 +1 @@ -ALTER TABLE "#__users" ADD COLUMN "access" bigint NOT NULL DEFAULT 1; +ALTER TABLE "#__users" ADD COLUMN "access" bigint NOT NULL DEFAULT 0; diff --git a/administrator/components/com_users/Model/UsersModel.php b/administrator/components/com_users/Model/UsersModel.php index 5d26e1218b7b9..a78354f28ffba 100644 --- a/administrator/components/com_users/Model/UsersModel.php +++ b/administrator/components/com_users/Model/UsersModel.php @@ -97,7 +97,7 @@ protected function populateState($ordering = 'a.name', $direction = 'asc') $this->setState('filter.excluded', $excluded); - $access = json_decode(base64_decode($app->input->get('access', '', 'BASE64'))); + $access = $app->input->post->get('access'); $this->setState('filter.access', $access); // Load the parameters. diff --git a/administrator/components/com_users/tmpl/users/default_batch_body.php b/administrator/components/com_users/tmpl/users/default_batch_body.php index 1fb32184471c2..4a792950c4ca1 100644 --- a/administrator/components/com_users/tmpl/users/default_batch_body.php +++ b/administrator/components/com_users/tmpl/users/default_batch_body.php @@ -28,26 +28,28 @@ ?>
-
-
- -
- + +
+
+ +
+ +
+
+
+
-
- -
-
-
-
- - +
+
+ + +
-
+
diff --git a/installation/sql/mysql/joomla.sql b/installation/sql/mysql/joomla.sql index 677c1a7591edb..6a206ba649e53 100644 --- a/installation/sql/mysql/joomla.sql +++ b/installation/sql/mysql/joomla.sql @@ -1994,7 +1994,7 @@ CREATE TABLE IF NOT EXISTS `#__users` ( `otpKey` varchar(1000) NOT NULL DEFAULT '' COMMENT 'Two factor authentication encrypted keys', `otep` varchar(1000) NOT NULL DEFAULT '' COMMENT 'One time emergency passwords', `requireReset` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'Require user to reset password on next login', - `access` int(10) unsigned NOT NULL DEFAULT 1, + `access` int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (`id`), KEY `idx_name` (`name`(100)), KEY `idx_block` (`block`), diff --git a/installation/sql/postgresql/joomla.sql b/installation/sql/postgresql/joomla.sql index a1f42b3dcaf42..8c8e50aad464c 100644 --- a/installation/sql/postgresql/joomla.sql +++ b/installation/sql/postgresql/joomla.sql @@ -1977,7 +1977,7 @@ CREATE TABLE IF NOT EXISTS "#__users" ( "otpKey" varchar(1000) DEFAULT '' NOT NULL, "otep" varchar(1000) DEFAULT '' NOT NULL, "requireReset" smallint DEFAULT 0, - "access" bigint DEFAULT 1 NOT NULL, + "access" bigint DEFAULT 0 NOT NULL, PRIMARY KEY ("id") ); CREATE INDEX "#__users_idx_name" ON "#__users" ("name"); From 3d3a76f76b9f74fc39f4e79d3c74b6c96b458421 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Fri, 1 Jun 2018 15:45:54 +0200 Subject: [PATCH 05/39] Changes after code review --- administrator/components/com_users/Model/UsersModel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/administrator/components/com_users/Model/UsersModel.php b/administrator/components/com_users/Model/UsersModel.php index a78354f28ffba..ad192c1248c5f 100644 --- a/administrator/components/com_users/Model/UsersModel.php +++ b/administrator/components/com_users/Model/UsersModel.php @@ -50,7 +50,7 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu 'range', 'lastvisitrange', 'state', - 'access', 'a.access', 'access_level', + 'access', 'a.access', 'access_level', ); } @@ -97,7 +97,7 @@ protected function populateState($ordering = 'a.name', $direction = 'asc') $this->setState('filter.excluded', $excluded); - $access = $app->input->post->get('access'); + $access = $app->input->getInt('access'); $this->setState('filter.access', $access); // Load the parameters. From 7f8e09f916c5cf1e0272a2040156a6dd78d44cd9 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Sat, 2 Jun 2018 21:28:40 +0200 Subject: [PATCH 06/39] Changes after code review --- administrator/components/com_users/Model/UsersModel.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_users/Model/UsersModel.php b/administrator/components/com_users/Model/UsersModel.php index ad192c1248c5f..76447e161502e 100644 --- a/administrator/components/com_users/Model/UsersModel.php +++ b/administrator/components/com_users/Model/UsersModel.php @@ -129,7 +129,7 @@ protected function getStoreId($id = '') $id .= ':' . $this->getState('filter.state'); $id .= ':' . $this->getState('filter.group_id'); $id .= ':' . $this->getState('filter.range'); - $id .= ':' . serialize($this->getState('filter.access')); + $id .= ':' . $this->getState('filter.access'); return parent::getStoreId($id); } @@ -301,8 +301,8 @@ protected function getListQuery() } // Join over the asset groups. - $query->select('ag.title AS access_level') - ->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); + $query->select($db->quoteName('ag.title') . ' AS access_level') + ->leftJoin('#__viewlevels AS ag ON ag.id = a.access'); // Filter the items over the group id if set. $groupId = $this->getState('filter.group_id'); From 7c43e1b01e71ea5c4e18934ab1d2b1337738b34d Mon Sep 17 00:00:00 2001 From: alexandraciobica Date: Wed, 13 Jun 2018 07:59:32 +0200 Subject: [PATCH 07/39] Groups in the list view and clean links (#2) * users list view site * Tried to include translations * Added the link to the user profile in the list of users * Working at clean url * Displayed custom fields in the list of users and in the user profile * Register users view * Added groups to users list view and made clean links work * Added automatic display option in custom fields for users * user template * hotfix + todo * codestyle fixes * codestyle fixes * error fixes * added access level check on user * Removed deprecated JClasses * codestyle * Changed the type of the field to usergrouplist and did come cleaning * fixes --- .../com_users/forms/fields/user.xml | 12 --- .../language/en-GB/en-GB.com_users.sys.ini | 6 +- .../Controller/DisplayController.php | 30 ++++-- components/com_users/Model/UserModel.php | 90 +++++++++++++++++ components/com_users/Model/UsersModel.php | 92 ++++++++++++++++++ components/com_users/View/User/HtmlView.php | 96 +++++++++++++++++++ components/com_users/View/Users/HtmlView.php | 77 +++++++++++++++ components/com_users/helpers/route.php | 23 ++++- components/com_users/router.php | 66 +++++++++++++ components/com_users/tmpl/user/default.php | 49 ++++++++++ components/com_users/tmpl/users/default.php | 35 +++++++ components/com_users/tmpl/users/default.xml | 19 ++++ language/en-GB/en-GB.com_users.ini | 1 + 13 files changed, 572 insertions(+), 24 deletions(-) delete mode 100644 administrator/components/com_users/forms/fields/user.xml create mode 100644 components/com_users/Model/UserModel.php create mode 100644 components/com_users/Model/UsersModel.php create mode 100644 components/com_users/View/User/HtmlView.php create mode 100644 components/com_users/View/Users/HtmlView.php create mode 100644 components/com_users/tmpl/user/default.php create mode 100644 components/com_users/tmpl/users/default.php create mode 100644 components/com_users/tmpl/users/default.xml diff --git a/administrator/components/com_users/forms/fields/user.xml b/administrator/components/com_users/forms/fields/user.xml deleted file mode 100644 index 2c8308648e3a0..0000000000000 --- a/administrator/components/com_users/forms/fields/user.xml +++ /dev/null @@ -1,12 +0,0 @@ - -
- -
- -
-
-
diff --git a/administrator/language/en-GB/en-GB.com_users.sys.ini b/administrator/language/en-GB/en-GB.com_users.sys.ini index e99cc7c55b9d1..a1e074f262875 100644 --- a/administrator/language/en-GB/en-GB.com_users.sys.ini +++ b/administrator/language/en-GB/en-GB.com_users.sys.ini @@ -9,12 +9,16 @@ COM_USERS_CONTENT_TYPE_NOTE="User Notes" COM_USERS_CONTENT_TYPE_USER="User" COM_USERS_GROUPS_VIEW_DEFAULT_DESC="Shows a List of User Groups" COM_USERS_GROUPS_VIEW_DEFAULT_TITLE="User Groups" +COM_USERS_GROUP_LABEL="Group" COM_USERS_GROUP_VIEW_EDIT_DESC="Shows a form to create a new User Group" COM_USERS_GROUP_VIEW_EDIT_TITLE="Create User Group" COM_USERS_LEVELS_VIEW_DEFAULT_DESC="Shows a List of Access Levels" COM_USERS_LEVELS_VIEW_DEFAULT_TITLE="Access Levels" COM_USERS_LEVEL_VIEW_EDIT_DESC="Shows a form to create a new Access Level" COM_USERS_LEVEL_VIEW_EDIT_TITLE="Create Access Level" +COM_USERS_LIST_VIEW_DEFAULT_DESC="Displays a list of available users in a group." +COM_USERS_LIST_VIEW_DEFAULT_OPTION="User List" +COM_USERS_LIST_VIEW_DEFAULT_TITLE="User List" COM_USERS_MAIL_VIEW_DEFAULT_DESC="Shows a form to send mass email to multiple users." COM_USERS_MAIL_VIEW_DEFAULT_TITLE="Mass Mail Users" COM_USERS_NOTES_VIEW_DEFAULT_DESC="Shows a List of User Notes" @@ -26,6 +30,7 @@ COM_USERS_USERS_VIEW_DEFAULT_DESC="Shows a List of Users" COM_USERS_USERS_VIEW_DEFAULT_TITLE="Users" COM_USERS_USER_VIEW_EDIT_DESC="Shows a form to create a new User Account" COM_USERS_USER_VIEW_EDIT_TITLE="Create User" +COM_USERS_XML_DESCRIPTION="Component for managing users." COM_USER_LOGIN_VIEW_DEFAULT_DESC="Displays a login form." COM_USER_LOGIN_VIEW_DEFAULT_OPTION="Login Form" COM_USER_LOGIN_VIEW_DEFAULT_TITLE="Login Form" @@ -47,4 +52,3 @@ COM_USER_REMIND_VIEW_DEFAULT_TITLE="Username Reminder Request" COM_USER_RESET_VIEW_DEFAULT_DESC="Displays a request to reset password." COM_USER_RESET_VIEW_DEFAULT_OPTION="Default" COM_USER_RESET_VIEW_DEFAULT_TITLE="Password Reset" -COM_USERS_XML_DESCRIPTION="Component for managing users." diff --git a/components/com_users/Controller/DisplayController.php b/components/com_users/Controller/DisplayController.php index 28d6436d651e8..6551ca850185c 100644 --- a/components/com_users/Controller/DisplayController.php +++ b/components/com_users/Controller/DisplayController.php @@ -12,6 +12,8 @@ use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\Factory; +use Joomla\CMS\Router\Route; /** * Base controller class for Users. @@ -33,7 +35,7 @@ class DisplayController extends BaseController public function display($cachable = false, $urlparams = false) { // Get the document object. - $document = \JFactory::getDocument(); + $document = Factory::getDocument(); // Set the default view name and format from the Request. $vName = $this->input->getCmd('view', 'login'); @@ -47,12 +49,12 @@ public function display($cachable = false, $urlparams = false) { case 'registration': // If the user is already logged in, redirect to the profile page. - $user = \JFactory::getUser(); + $user = Factory::getUser(); if ($user->get('guest') != 1) { // Redirect to profile page. - $this->setRedirect(\JRoute::_('index.php?option=com_users&view=profile', false)); + $this->setRedirect(Route::_('index.php?option=com_users&view=profile', false)); return; } @@ -61,7 +63,7 @@ public function display($cachable = false, $urlparams = false) if (ComponentHelper::getParams('com_users')->get('allowUserRegistration') == 0) { // Registration is disabled - Redirect to login page. - $this->setRedirect(\JRoute::_('index.php?option=com_users&view=login', false)); + $this->setRedirect(Route::_('index.php?option=com_users&view=login', false)); return; } @@ -74,12 +76,12 @@ public function display($cachable = false, $urlparams = false) case 'profile': // If the user is a guest, redirect to the login page. - $user = \JFactory::getUser(); + $user = Factory::getUser(); if ($user->get('guest') == 1) { // Redirect to login page. - $this->setRedirect(\JRoute::_('index.php?option=com_users&view=login', false)); + $this->setRedirect(Route::_('index.php?option=com_users&view=login', false)); return; } @@ -94,12 +96,12 @@ public function display($cachable = false, $urlparams = false) case 'reset': // If the user is already logged in, redirect to the profile page. - $user = \JFactory::getUser(); + $user = Factory::getUser(); if ($user->get('guest') != 1) { // Redirect to profile page. - $this->setRedirect(\JRoute::_('index.php?option=com_users&view=profile', false)); + $this->setRedirect(Route::_('index.php?option=com_users&view=profile', false)); return; } @@ -109,12 +111,12 @@ public function display($cachable = false, $urlparams = false) case 'remind': // If the user is already logged in, redirect to the profile page. - $user = \JFactory::getUser(); + $user = Factory::getUser(); if ($user->get('guest') != 1) { // Redirect to profile page. - $this->setRedirect(\JRoute::_('index.php?option=com_users&view=profile', false)); + $this->setRedirect(Route::_('index.php?option=com_users&view=profile', false)); return; } @@ -122,6 +124,14 @@ public function display($cachable = false, $urlparams = false) $model = $this->getModel($vName); break; + case 'users': + $model = $this->getModel($vName); + break; + + case 'user': + $model = $this->getModel($vName); + break; + default: $model = $this->getModel('Login'); break; diff --git a/components/com_users/Model/UserModel.php b/components/com_users/Model/UserModel.php new file mode 100644 index 0000000000000..ec76083f3c9b4 --- /dev/null +++ b/components/com_users/Model/UserModel.php @@ -0,0 +1,90 @@ +input->getInt('id'); + $this->setState('user.id', $pk); + + $offset = $app->input->getUInt('limitstart'); + $this->setState('list.offset', $offset); + + // Load the parameters. + $params = $app->getParams(); + $this->setState('params', $params); + + } + + /** + * Method to get user data. + * + * @param integer $pk The id of the user. + * + * @return object User instance + * + * @throws \Exception + */ + public function getItem($pk = null) + { + $pk = (!empty($pk)) ? $pk : (int) $this->getState('user.id'); + + if ($this->_item === null) + { + $this->_item = array(); + } + + if (!isset($this->_item[$pk])) + { + $user = User::getInstance($pk); + + if (empty($user)) + { + throw new \Exception(Text::_('COM_USERS_ERROR_USER_NOT_FOUND'), 404); + } + + $loggedUser = Factory::getUser(); + $groups = $loggedUser->getAuthorisedViewLevels(); + $user->params = $this->getState('params'); + + // Compute view access permissions. + $user->params->set('access-view', in_array($user->access, $groups)); + + $this->_item[$pk] = $user; + } + + return $this->_item[$pk]; + } +} diff --git a/components/com_users/Model/UsersModel.php b/components/com_users/Model/UsersModel.php new file mode 100644 index 0000000000000..a9399daacddb6 --- /dev/null +++ b/components/com_users/Model/UsersModel.php @@ -0,0 +1,92 @@ +input->get('id'); + $this->setState('user.group', $groupId); + + parent::populateState($ordering = 'ordering', $direction = 'ASC'); + } + + /** + * Get the list of items. + * + * @return \JDatabaseQuery|\Joomla\Database\DatabaseQuery + * + * @throws \Exception + */ + protected function getListQuery() + { + $app = Factory::getApplication(); + $user = Factory::getUser(); + + // $u = Access::getUsersByGroup((int)$this->getState('user.group')); + + // Create a new query object. + $db = $this->getDbo(); + $query = $db->getQuery(true); + + // Select the required fields from the table. + $query->select( + ' a.id, a.name, a.username, a.email, a.access, map.group_id' + ); + + $query->from($db->quoteName('#__users') . ' AS a') + ->leftJoin($db->quoteName('#__user_usergroup_map') . ' AS map ON a.id = map.user_id') + ->where('map.group_id = (' . $this->getState('user.group') . ')'); + + // Filter by access level. + if ($this->getState('filter.access', true)) + { + $groups = implode(',', $user->getAuthorisedViewLevels()); + $query->where('a.access IN (' . $groups . ')'); + } + + $params = $app->getParams(); + $this->setState('params', $params); + + return $query; + } + +} diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php new file mode 100644 index 0000000000000..229fed45ecbfc --- /dev/null +++ b/components/com_users/View/User/HtmlView.php @@ -0,0 +1,96 @@ +item = $this->get('Item'); + $this->state = $this->get('State'); + $user = Factory::getUser(); + + /** + * Check for no 'access-view', + * - Redirect guest users to login + * - Deny access to logged users with 403 code + */ + if ($this->item->params->get('access-view') == false) + { + $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error'); + $app->setHeader('status', 403, true); + + return; + } + + // Process the content plugins. + PluginHelper::importPlugin('content'); + $offset = $this->state->get('list.offset'); + + $this->item = (object) $this->item; + + // Store the events for later + $this->item->event = new \stdClass; + + $results = $app->triggerEvent('onContentAfterTitle', array('com_users.user', &$this->item, &$this->item->params, $offset)); + $this->item->event->afterDisplayTitle = trim(implode("\n", $results)); + + $results = $app->triggerEvent('onContentBeforeDisplay', array('com_users.user', &$this->item, &$this->item->params, $offset)); + $this->item->event->beforeDisplayContent = trim(implode("\n", $results)); + + $results = $app->triggerEvent('onContentAfterDisplay', array('com_users.user', &$this->item, &$this->item->params, $offset)); + $this->item->event->afterDisplayContent = trim(implode("\n", $results)); + + return parent::display($tpl); + } +} diff --git a/components/com_users/View/Users/HtmlView.php b/components/com_users/View/Users/HtmlView.php new file mode 100644 index 0000000000000..9c9136b550500 --- /dev/null +++ b/components/com_users/View/Users/HtmlView.php @@ -0,0 +1,77 @@ +items = $this->get('Items'); + + PluginHelper::importPlugin('content'); + + foreach ($this->items as $item) + { + $item->slug = $item->id . ":" . ApplicationHelper::stringURLSafe($item->name); + + // Store the events for later + $item->event = new \stdClass; + + $item->text = ''; + + $app->triggerEvent('onContentPrepare', array('com_users.user', &$item, &$item->params, 0)); + + $results = $app->triggerEvent('onContentAfterTitle', array('com_users.user', &$item, &$item->params, 0)); + $item->event->afterDisplayTitle = trim(implode("\n", $results)); + + $results = $app->triggerEvent('onContentBeforeDisplay', array('com_users.user', &$item, &$item->params, 0)); + $item->event->beforeDisplayContent = trim(implode("\n", $results)); + + $results = $app->triggerEvent('onContentAfterDisplay', array('com_users.user', &$item, &$item->params, 0)); + $item->event->afterDisplayContent = trim(implode("\n", $results)); + } + + return parent::display($tpl); + } + +} diff --git a/components/com_users/helpers/route.php b/components/com_users/helpers/route.php index 3fe03220ce07c..98c7cded7608b 100644 --- a/components/com_users/helpers/route.php +++ b/components/com_users/helpers/route.php @@ -15,7 +15,7 @@ * @since 1.6 * @deprecated 4.0 */ -class UsersHelperRoute +abstract class UsersHelperRoute { /** * Method to get the menu items for the component. @@ -196,4 +196,25 @@ public static function getResetRoute() return null; } + + /** + * Method to get a route configuration for the user view + * + * @param integer $id The route of the user item. + * @param integer $groupId The id of the group. + * @param integer $language The language code. + * + * @return string The user's route + */ + public static function getUserRoute($id, $groupId, $language) + { + $link = 'index.php?option=com_users&view=user&id=' . $id . '&groupId=' . $groupId; + + if ($language && $language !== '*' && JLanguageMultilang::isEnabled()) + { + $link .= '&lang=' . $language; + } + + return $link; + } } diff --git a/components/com_users/router.php b/components/com_users/router.php index 5de01dca6495b..9d245db58e43d 100644 --- a/components/com_users/router.php +++ b/components/com_users/router.php @@ -15,6 +15,7 @@ use Joomla\CMS\Component\Router\Rules\MenuRules; use Joomla\CMS\Component\Router\Rules\NomenuRules; use Joomla\CMS\Component\Router\Rules\StandardRules; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Menu\AbstractMenu; /** @@ -24,6 +25,8 @@ */ class UsersRouter extends RouterView { + protected $noIDs = false; + /** * Users Component router constructor * @@ -40,10 +43,73 @@ public function __construct($app = null, $menu = null) $this->registerView(new RouterViewConfiguration('remind')); $this->registerView(new RouterViewConfiguration('reset')); + $users = new RouterViewConfiguration('users'); + $users->setKey('id'); + $this->registerView($users); + + $user = new RouterViewConfiguration('user'); + $user->setKey('id')->setParent($users, 'groupId'); + $this->registerView($user); + parent::__construct($app, $menu); $this->attachRule(new MenuRules($this)); $this->attachRule(new StandardRules($this)); $this->attachRule(new NomenuRules($this)); } + + /** + * Method to get the segment(s) for a category + * + * @param string $id ID of the category to retrieve the segments for + * @param array $query The request that is built right now + * + * @return array|string The segments of this item + */ + public function getUsersSegment($id, $query) + { + return array((int) $id => $id); + } + + /** + * Method to get the segment(s) for an user + * + * @param string $id ID of the user to retrieve the segments for + * @param array $query The request that is built right now + * + * @return array|string The segments of this item + */ + public function getUserSegment($id, $query) + { + if ($this->noIDs) + { + list($void, $segment) = explode(':', $id, 2); + + return array($void => $segment); + } + + return array((int) $id => $id); + } + + /** + * Method to get the segment(s) for an user + * + * @param string $segment Segment of the user to retrieve the ID for + * @param array $query The request that is parsed right now + * + * @return mixed The id of this item or false + */ + public function getUserId($segment, $query) + { + + if ($this->noIDs) + { + list($id, $segmentList) = explode('-', $segment, 2); + + return (int) $id; + } + + return (int) $segment; + + } } diff --git a/components/com_users/tmpl/user/default.php b/components/com_users/tmpl/user/default.php new file mode 100644 index 0000000000000..80047ec8ae0f7 --- /dev/null +++ b/components/com_users/tmpl/user/default.php @@ -0,0 +1,49 @@ + +
+
+
+ +
+
+
+
+ image +
+
+ item->event->afterDisplayTitle; ?> +
+
+ +
+
+ item->event->beforeDisplayContent; ?> +
+
+
+
+

item->username; ?>

+

item->email; ?>

+
+
+
+
+ item->event->afterDisplayContent; ?> +
+
+
+ + diff --git a/components/com_users/tmpl/users/default.php b/components/com_users/tmpl/users/default.php new file mode 100644 index 0000000000000..0bef47a6e3d40 --- /dev/null +++ b/components/com_users/tmpl/users/default.php @@ -0,0 +1,35 @@ + + +
+ items as $item) : ?> + event->afterDisplayTitle; ?> +
+ event->beforeDisplayContent; ?> + + +

id; ?>

+
+ + event->afterDisplayContent; ?> + + +
+ diff --git a/components/com_users/tmpl/users/default.xml b/components/com_users/tmpl/users/default.xml new file mode 100644 index 0000000000000..b15be8ae713ab --- /dev/null +++ b/components/com_users/tmpl/users/default.xml @@ -0,0 +1,19 @@ + + + + + + + + +
+ + +
+
+
+ diff --git a/language/en-GB/en-GB.com_users.ini b/language/en-GB/en-GB.com_users.ini index 2d185a029cc65..8720ebc427a69 100644 --- a/language/en-GB/en-GB.com_users.ini +++ b/language/en-GB/en-GB.com_users.ini @@ -26,6 +26,7 @@ COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW="Hello %s,\n\nThank y COM_USERS_EMAIL_USERNAME_REMINDER_BODY="Hello,\n\nA username reminder has been requested for your %s account.\n\nYour username is %s.\n\nTo login to your account, select the link below.\n\n%s \n\nThank you." COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT="Your %s username" COM_USERS_ERROR_SECRET_CODE_WITHOUT_TFA="You have entered a Secret Code but two factor authentication is not enabled in your user account. If you want to use a secret code to secure your login please edit your user profile and enable two factor authentication." +COM_USERS_ERROR_USER_NOT_FOUND="User not found" COM_USERS_FIELD_PASSWORD_RESET_DESC="Please enter the email address associated with your User account.
A verification code will be sent to you. Once you have received the verification code, you will be able to choose a new password for your account." COM_USERS_FIELD_PASSWORD_RESET_LABEL="Email Address" COM_USERS_FIELD_REMIND_EMAIL_DESC="Please enter the email address associated with your User account.
Your username will be emailed to the email address on file." From 8ed3675c3950aeda111a4acbe7ff9f56d0c750ae Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Thu, 14 Jun 2018 00:18:37 +0200 Subject: [PATCH 08/39] Modified templates --- components/com_users/tmpl/user/default.php | 10 ++----- components/com_users/tmpl/users/default.php | 31 ++++++++++----------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/components/com_users/tmpl/user/default.php b/components/com_users/tmpl/user/default.php index 80047ec8ae0f7..f5333ab21ff14 100644 --- a/components/com_users/tmpl/user/default.php +++ b/components/com_users/tmpl/user/default.php @@ -21,21 +21,15 @@
- image -
-
item->event->afterDisplayTitle; ?>
-
- -
-
+
item->event->beforeDisplayContent; ?>
-

item->username; ?>

+item->username; ?>

item->email; ?>

diff --git a/components/com_users/tmpl/users/default.php b/components/com_users/tmpl/users/default.php index 0bef47a6e3d40..3b95402bb5ec9 100644 --- a/components/com_users/tmpl/users/default.php +++ b/components/com_users/tmpl/users/default.php @@ -16,20 +16,19 @@ $lang = Factory::getLanguage(); ?> -
- items as $item) : ?> - event->afterDisplayTitle; ?> -
- event->beforeDisplayContent; ?> - - -

id; ?>

+items as $item) : ?> +
+
+
+

+ +

+ event->afterDisplayTitle; ?> + event->beforeDisplayContent; ?> + event->afterDisplayContent; ?> +
- - event->afterDisplayContent; ?> - - -
- +
+ From 9a429e3b76f6029972cde8ee8d32059d3dcf86d9 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Fri, 15 Jun 2018 14:08:37 +0300 Subject: [PATCH 09/39] user view --- components/com_users/tmpl/user/default.php | 40 +++++++--------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/components/com_users/tmpl/user/default.php b/components/com_users/tmpl/user/default.php index f5333ab21ff14..92e673e8bb6b4 100644 --- a/components/com_users/tmpl/user/default.php +++ b/components/com_users/tmpl/user/default.php @@ -10,34 +10,20 @@ defined('_JEXEC') or die; ?>
-
-
- -
-
-
-
- item->event->afterDisplayTitle; ?> -
-
- item->event->beforeDisplayContent; ?> -
-
-
-
-item->username; ?> -

item->email; ?>

-
-
-
-
- item->event->afterDisplayContent; ?> -
+ + + item->event->afterDisplayTitle; ?> + + item->event->beforeDisplayContent; ?> + +

item->username; ?>

+

item->email; ?>

+ + item->event->afterDisplayContent; ?>
From 27db2a67665c82019ef902c0bf8db68a07ae9676 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Fri, 15 Jun 2018 22:33:30 +0300 Subject: [PATCH 10/39] added user name to breadcrumbs --- components/com_users/Model/UsersModel.php | 2 +- components/com_users/View/User/HtmlView.php | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/components/com_users/Model/UsersModel.php b/components/com_users/Model/UsersModel.php index a9399daacddb6..424b7aad08440 100644 --- a/components/com_users/Model/UsersModel.php +++ b/components/com_users/Model/UsersModel.php @@ -40,7 +40,7 @@ class UsersModel extends ListModel */ protected function populateState($ordering = 'ordering', $direction = 'ASC') { - $app = \JFactory::getApplication(); + $app = Factory::getApplication(); // List state information $groupId = $app->input->get('id'); diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php index 229fed45ecbfc..32facd9b9fd9d 100644 --- a/components/com_users/View/User/HtmlView.php +++ b/components/com_users/View/User/HtmlView.php @@ -57,7 +57,9 @@ public function display($tpl = null) { $app = Factory::getApplication(); $this->item = $this->get('Item'); - $this->state = $this->get('State'); + $state = $this->get('State'); + $params = $state->get('params'); + $user = Factory::getUser(); /** @@ -75,7 +77,7 @@ public function display($tpl = null) // Process the content plugins. PluginHelper::importPlugin('content'); - $offset = $this->state->get('list.offset'); + $offset = $state->get('list.offset'); $this->item = (object) $this->item; @@ -91,6 +93,21 @@ public function display($tpl = null) $results = $app->triggerEvent('onContentAfterDisplay', array('com_users.user', &$this->item, &$this->item->params, $offset)); $this->item->event->afterDisplayContent = trim(implode("\n", $results)); + $this->_prepareDocument(); + return parent::display($tpl); } + /** + * Prepares the document. + * + * @return void + */ + protected function _prepareDocument() + { + $app = \JFactory::getApplication(); + $pathway = $app->getPathway(); + + $pathway->addItem($this->item->name, ""); + + } } From ee2ef0fb160593c7b4a64fe98c363741c2a0cd41 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 18 Jun 2018 10:00:09 +0300 Subject: [PATCH 11/39] Added checks in user view for bredcrumbs --- components/com_users/View/User/HtmlView.php | 37 ++++++++++++++++---- components/com_users/View/Users/HtmlView.php | 11 +++++- language/en-GB/en-GB.com_users.ini | 1 + 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php index 32facd9b9fd9d..8a5d33ef04df6 100644 --- a/components/com_users/View/User/HtmlView.php +++ b/components/com_users/View/User/HtmlView.php @@ -55,10 +55,10 @@ class HtmlView extends BaseHtmlView */ public function display($tpl = null) { - $app = Factory::getApplication(); - $this->item = $this->get('Item'); - $state = $this->get('State'); - $params = $state->get('params'); + $app = Factory::getApplication(); + $this->item = $this->get('Item'); + $this->state = $this->get('State'); + $this->params = $this->state->get('params'); $user = Factory::getUser(); @@ -77,7 +77,7 @@ public function display($tpl = null) // Process the content plugins. PluginHelper::importPlugin('content'); - $offset = $state->get('list.offset'); + $offset = $this->state->get('list.offset'); $this->item = (object) $this->item; @@ -104,10 +104,33 @@ public function display($tpl = null) */ protected function _prepareDocument() { - $app = \JFactory::getApplication(); + $app = Factory::getApplication(); $pathway = $app->getPathway(); + $menus = $app->getMenu(); + $menu = $menus->getActive(); - $pathway->addItem($this->item->name, ""); + if ($menu) + { + $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); + } + else + { + $this->params->def('page_heading', Text::_('COM_USERS_DEFAULT_PAGE_TITLE')); + } + $title = $this->params->get('page_title', ''); + + $id = (int) @$menu->query['id']; + + // If the menu item does not concern this user + if ($menu && ($menu->query['option'] !== 'com_users' || $menu->query['view'] !== 'user' || $id != $this->item->id)) + { + // If this is not a single user menu item, set the page title to the user title + if ($this->item->name) + { + $title = $this->item->name; + } + $pathway->addItem($title, ''); + } } } diff --git a/components/com_users/View/Users/HtmlView.php b/components/com_users/View/Users/HtmlView.php index 9c9136b550500..51a8e38211317 100644 --- a/components/com_users/View/Users/HtmlView.php +++ b/components/com_users/View/Users/HtmlView.php @@ -34,6 +34,14 @@ class HtmlView extends BaseHtmlView */ protected $items; + /** + * The page parameters + * + * @var \Joomla\Registry\Registry|null + * @since 4.0.0 + */ + protected $params = null; + /** * Execute and display a template script. * @@ -47,6 +55,8 @@ public function display($tpl = null) { $app = Factory::getApplication(); $this->items = $this->get('Items'); + $this->state = $this->get('State'); + $this->params = $this->state->get('params'); PluginHelper::importPlugin('content'); @@ -73,5 +83,4 @@ public function display($tpl = null) return parent::display($tpl); } - } diff --git a/language/en-GB/en-GB.com_users.ini b/language/en-GB/en-GB.com_users.ini index 8720ebc427a69..e452873335601 100644 --- a/language/en-GB/en-GB.com_users.ini +++ b/language/en-GB/en-GB.com_users.ini @@ -7,6 +7,7 @@ COM_USERS_ACTIVATION_TOKEN_NOT_FOUND="Verification code not found." COM_USERS_CAPTCHA_LABEL="Captcha" COM_USERS_CAPTCHA_DESC="Please complete the security check." COM_USERS_DATABASE_ERROR="Error getting the user from the database: %s" +COM_USERS_DEFAULT_PAGE_TITLE="Users" COM_USERS_DESIRED_USERNAME="Enter your desired username." COM_USERS_EDIT_PROFILE="Edit Profile" COM_USERS_EMAIL_ACCOUNT_DETAILS="Account Details for %s at %s" From 407e23efbe742ee25f0f9e8087a8a733b2454c7b Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 18 Jun 2018 10:03:47 +0300 Subject: [PATCH 12/39] user default.xml --- components/com_users/tmpl/user/default.xml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 components/com_users/tmpl/user/default.xml diff --git a/components/com_users/tmpl/user/default.xml b/components/com_users/tmpl/user/default.xml new file mode 100644 index 0000000000000..d3029c2c2dc69 --- /dev/null +++ b/components/com_users/tmpl/user/default.xml @@ -0,0 +1,18 @@ + + + + + + + + +
+ + +
+
+
+ From 6bf4abc5475f5b5a438b0bd173eec0d06ab4e87d Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 18 Jun 2018 13:00:39 +0300 Subject: [PATCH 13/39] user details menu item --- .../language/en-GB/en-GB.com_users.sys.ini | 3 +++ components/com_users/tmpl/user/default.xml | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 components/com_users/tmpl/user/default.xml diff --git a/administrator/language/en-GB/en-GB.com_users.sys.ini b/administrator/language/en-GB/en-GB.com_users.sys.ini index a1e074f262875..e020abbc712e0 100644 --- a/administrator/language/en-GB/en-GB.com_users.sys.ini +++ b/administrator/language/en-GB/en-GB.com_users.sys.ini @@ -28,6 +28,9 @@ COM_USERS_NOTE_VIEW_EDIT_TITLE="Create User Note" COM_USERS_TAGS_CATEGORY="User Note Category" COM_USERS_USERS_VIEW_DEFAULT_DESC="Shows a List of Users" COM_USERS_USERS_VIEW_DEFAULT_TITLE="Users" +COM_USERS_USER_DETAILS_VIEW_DEFAULT_DESC="Displays the details of the chosen user" +COM_USERS_USER_DETAILS_VIEW_DEFAULT_OPTION="User details" +COM_USERS_USER_DETAILS_VIEW_DEFAULT_TITLE="User details" COM_USERS_USER_VIEW_EDIT_DESC="Shows a form to create a new User Account" COM_USERS_USER_VIEW_EDIT_TITLE="Create User" COM_USERS_XML_DESCRIPTION="Component for managing users." diff --git a/components/com_users/tmpl/user/default.xml b/components/com_users/tmpl/user/default.xml new file mode 100644 index 0000000000000..ee1d06467b945 --- /dev/null +++ b/components/com_users/tmpl/user/default.xml @@ -0,0 +1,16 @@ + + + + + + + + +
+ +
+
+
From cb9f8bff992d9bd540332034a57c22ccdb5b7c11 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 18 Jun 2018 16:40:20 +0300 Subject: [PATCH 14/39] cleanning --- components/com_users/View/User/HtmlView.php | 25 +-------------------- components/com_users/tmpl/user/default.xml | 18 --------------- 2 files changed, 1 insertion(+), 42 deletions(-) delete mode 100644 components/com_users/tmpl/user/default.xml diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php index 8a5d33ef04df6..79ba4b11a17f9 100644 --- a/components/com_users/View/User/HtmlView.php +++ b/components/com_users/View/User/HtmlView.php @@ -106,31 +106,8 @@ protected function _prepareDocument() { $app = Factory::getApplication(); $pathway = $app->getPathway(); - $menus = $app->getMenu(); - $menu = $menus->getActive(); - if ($menu) - { - $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); - } - else - { - $this->params->def('page_heading', Text::_('COM_USERS_DEFAULT_PAGE_TITLE')); - } + $pathway->addItem($this->item->name, ''); - $title = $this->params->get('page_title', ''); - - $id = (int) @$menu->query['id']; - - // If the menu item does not concern this user - if ($menu && ($menu->query['option'] !== 'com_users' || $menu->query['view'] !== 'user' || $id != $this->item->id)) - { - // If this is not a single user menu item, set the page title to the user title - if ($this->item->name) - { - $title = $this->item->name; - } - $pathway->addItem($title, ''); - } } } diff --git a/components/com_users/tmpl/user/default.xml b/components/com_users/tmpl/user/default.xml deleted file mode 100644 index d3029c2c2dc69..0000000000000 --- a/components/com_users/tmpl/user/default.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - -
- - -
-
-
- From b677cd0a59d0b83f61da42feb4570d69301fc54c Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 18 Jun 2018 16:53:52 +0300 Subject: [PATCH 15/39] added breadcrumb for user name --- components/com_users/View/User/HtmlView.php | 24 +++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php index 229fed45ecbfc..d21adb92af4a4 100644 --- a/components/com_users/View/User/HtmlView.php +++ b/components/com_users/View/User/HtmlView.php @@ -55,9 +55,10 @@ class HtmlView extends BaseHtmlView */ public function display($tpl = null) { - $app = Factory::getApplication(); - $this->item = $this->get('Item'); - $this->state = $this->get('State'); + $app = Factory::getApplication(); + $this->item = $this->get('Item'); + $this->state = $this->get('State'); + $this->params = $this->state->get('params'); $user = Factory::getUser(); /** @@ -91,6 +92,21 @@ public function display($tpl = null) $results = $app->triggerEvent('onContentAfterDisplay', array('com_users.user', &$this->item, &$this->item->params, $offset)); $this->item->event->afterDisplayContent = trim(implode("\n", $results)); + $this->_prepareDocument(); + return parent::display($tpl); } -} + /** + * Prepares the document. + * + * @return void + */ + protected function _prepareDocument() + { + $app = Factory::getApplication(); + $pathway = $app->getPathway(); + + $pathway->addItem($this->item->name, ''); + + } +} \ No newline at end of file From 13b9d6652bfb57e308224eb0f19d99d593ade019 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 18 Jun 2018 16:57:21 +0300 Subject: [PATCH 16/39] newline --- components/com_users/View/User/HtmlView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php index d21adb92af4a4..810d7afe8d5da 100644 --- a/components/com_users/View/User/HtmlView.php +++ b/components/com_users/View/User/HtmlView.php @@ -109,4 +109,4 @@ protected function _prepareDocument() $pathway->addItem($this->item->name, ''); } -} \ No newline at end of file +} From 2d35a864594e9e0379d9cd90423982436b5009f2 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 18 Jun 2018 19:11:11 +0300 Subject: [PATCH 17/39] revert breadcrumbs from this branch --- components/com_users/View/User/HtmlView.php | 25 ++++----------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php index 79ba4b11a17f9..02fa6f3ae3cce 100644 --- a/components/com_users/View/User/HtmlView.php +++ b/components/com_users/View/User/HtmlView.php @@ -55,11 +55,9 @@ class HtmlView extends BaseHtmlView */ public function display($tpl = null) { - $app = Factory::getApplication(); - $this->item = $this->get('Item'); - $this->state = $this->get('State'); - $this->params = $this->state->get('params'); - + $app = Factory::getApplication(); + $this->item = $this->get('Item'); + $this->state = $this->get('State'); $user = Factory::getUser(); /** @@ -93,21 +91,6 @@ public function display($tpl = null) $results = $app->triggerEvent('onContentAfterDisplay', array('com_users.user', &$this->item, &$this->item->params, $offset)); $this->item->event->afterDisplayContent = trim(implode("\n", $results)); - $this->_prepareDocument(); - return parent::display($tpl); } - /** - * Prepares the document. - * - * @return void - */ - protected function _prepareDocument() - { - $app = Factory::getApplication(); - $pathway = $app->getPathway(); - - $pathway->addItem($this->item->name, ''); - - } -} +} \ No newline at end of file From 52616cdf3c15468faf956da41a295619d0cc4a0b Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 18 Jun 2018 19:14:57 +0300 Subject: [PATCH 18/39] add schema to views --- components/com_users/tmpl/user/default.php | 10 +++++----- components/com_users/tmpl/users/default.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/com_users/tmpl/user/default.php b/components/com_users/tmpl/user/default.php index 92e673e8bb6b4..e1d69dacb6099 100644 --- a/components/com_users/tmpl/user/default.php +++ b/components/com_users/tmpl/user/default.php @@ -9,10 +9,10 @@ defined('_JEXEC') or die; ?> -
+
@@ -20,8 +20,8 @@ item->event->beforeDisplayContent; ?> -

item->username; ?>

-

item->email; ?>

+
escape($this->item->username); ?>
+
escape($this->item->email); ?>
item->event->afterDisplayContent; ?>
diff --git a/components/com_users/tmpl/users/default.php b/components/com_users/tmpl/users/default.php index 3b95402bb5ec9..09ddb89e3a1f6 100644 --- a/components/com_users/tmpl/users/default.php +++ b/components/com_users/tmpl/users/default.php @@ -17,12 +17,12 @@ ?> items as $item) : ?> -
+
-

+

event->afterDisplayTitle; ?> From 10c02cd2d3219daab6e46617669de072633d8a6a Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 18 Jun 2018 19:16:05 +0300 Subject: [PATCH 19/39] newline --- components/com_users/View/User/HtmlView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php index 02fa6f3ae3cce..229fed45ecbfc 100644 --- a/components/com_users/View/User/HtmlView.php +++ b/components/com_users/View/User/HtmlView.php @@ -93,4 +93,4 @@ public function display($tpl = null) return parent::display($tpl); } -} \ No newline at end of file +} From 9aaff7028fa2cc9495fde429ace00aa2e9091068 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 18 Jun 2018 19:53:31 +0300 Subject: [PATCH 20/39] revert changes not needed --- components/com_users/View/Users/HtmlView.php | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/components/com_users/View/Users/HtmlView.php b/components/com_users/View/Users/HtmlView.php index 51a8e38211317..d37cad8b5ad45 100644 --- a/components/com_users/View/Users/HtmlView.php +++ b/components/com_users/View/Users/HtmlView.php @@ -34,14 +34,6 @@ class HtmlView extends BaseHtmlView */ protected $items; - /** - * The page parameters - * - * @var \Joomla\Registry\Registry|null - * @since 4.0.0 - */ - protected $params = null; - /** * Execute and display a template script. * @@ -55,8 +47,6 @@ public function display($tpl = null) { $app = Factory::getApplication(); $this->items = $this->get('Items'); - $this->state = $this->get('State'); - $this->params = $this->state->get('params'); PluginHelper::importPlugin('content'); @@ -83,4 +73,5 @@ public function display($tpl = null) return parent::display($tpl); } -} + +} \ No newline at end of file From 0a91048933125404bef9ebde55d54b685ad79537 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 18 Jun 2018 19:55:33 +0300 Subject: [PATCH 21/39] newline --- components/com_users/View/Users/HtmlView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/com_users/View/Users/HtmlView.php b/components/com_users/View/Users/HtmlView.php index d37cad8b5ad45..9c9136b550500 100644 --- a/components/com_users/View/Users/HtmlView.php +++ b/components/com_users/View/Users/HtmlView.php @@ -74,4 +74,4 @@ public function display($tpl = null) return parent::display($tpl); } -} \ No newline at end of file +} From bbcf061789cf854581de5eb72acb956ab6dc8694 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Tue, 19 Jun 2018 14:42:27 +0300 Subject: [PATCH 22/39] added show/hide group title in users list --- components/com_users/View/Users/HtmlView.php | 30 ++++++++++++++++++-- components/com_users/tmpl/users/default.php | 5 ++++ components/com_users/tmpl/users/default.xml | 15 ++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/components/com_users/View/Users/HtmlView.php b/components/com_users/View/Users/HtmlView.php index 9c9136b550500..35539bacbac8c 100644 --- a/components/com_users/View/Users/HtmlView.php +++ b/components/com_users/View/Users/HtmlView.php @@ -14,6 +14,7 @@ use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Factory; use Joomla\CMS\Application\ApplicationHelper; +use Joomla\CMS\Object\CMSObject; /** * Users List view class for Users. @@ -25,15 +26,32 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \JObject + * @var \Joomla\Registry\Registry */ protected $state; /** + * User items data + * * @var array */ protected $items; + /** + * The group + * + * @var CMSObject + */ + protected $group; + + /** + * The page parameters + * + * @var \Joomla\Registry\Registry|null + * @since 4.0.0 + */ + protected $params = null; + /** * Execute and display a template script. * @@ -45,8 +63,16 @@ class HtmlView extends BaseHtmlView */ public function display($tpl = null) { - $app = Factory::getApplication(); + $app = Factory::getApplication(); $this->items = $this->get('Items'); + $this->state = $this->get('State'); + $this->params = $this->state->get('params'); + + $menus = $app->getMenu(); + $menu = $menus->getActive(); + + $this->group = new CMSObject; + $this->group->title = $menu->title; PluginHelper::importPlugin('content'); diff --git a/components/com_users/tmpl/users/default.php b/components/com_users/tmpl/users/default.php index 09ddb89e3a1f6..0a92037e29fd5 100644 --- a/components/com_users/tmpl/users/default.php +++ b/components/com_users/tmpl/users/default.php @@ -16,6 +16,11 @@ $lang = Factory::getLanguage(); ?> +params->get('show_group_title', 1)) : ?> +

+ group->title; ?> +

+ items as $item) : ?>
diff --git a/components/com_users/tmpl/users/default.xml b/components/com_users/tmpl/users/default.xml index b15be8ae713ab..d0a7276e867aa 100644 --- a/components/com_users/tmpl/users/default.xml +++ b/components/com_users/tmpl/users/default.xml @@ -15,5 +15,20 @@ + + + +
+ + + + +
+
From 35648b8a6cb2c77fc33075e7681112958a758b98 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Tue, 19 Jun 2018 15:07:44 +0300 Subject: [PATCH 23/39] added page heading --- components/com_users/View/Users/HtmlView.php | 49 ++++++++++++++++++-- components/com_users/tmpl/users/default.php | 7 +++ 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/components/com_users/View/Users/HtmlView.php b/components/com_users/View/Users/HtmlView.php index 35539bacbac8c..8c9f05d63d410 100644 --- a/components/com_users/View/Users/HtmlView.php +++ b/components/com_users/View/Users/HtmlView.php @@ -15,6 +15,7 @@ use Joomla\CMS\Factory; use Joomla\CMS\Application\ApplicationHelper; use Joomla\CMS\Object\CMSObject; +use Joomla\CMS\Language\Text; /** * Users List view class for Users. @@ -68,11 +69,7 @@ public function display($tpl = null) $this->state = $this->get('State'); $this->params = $this->state->get('params'); - $menus = $app->getMenu(); - $menu = $menus->getActive(); - $this->group = new CMSObject; - $this->group->title = $menu->title; PluginHelper::importPlugin('content'); @@ -97,6 +94,50 @@ public function display($tpl = null) $item->event->afterDisplayContent = trim(implode("\n", $results)); } + $menus = $app->getMenu(); + $menu = $menus->getActive(); + + $this->group = new CMSObject; + $this->group->title = $menu->title; + $this->group->id = $this->state->get('user.group'); + + if ($menu + && $menu->component == 'com_users' + && isset($menu->query['view'], $menu->query['id']) + && $menu->query['view'] == 'users' + && $menu->query['id'] == $this->group->id) + { + $this->params->def('page_heading', $this->params->get('page_title', $menu->title)); + $title = $this->params->get('page_title', $menu->title); + } + else + { + $this->params->def('page_heading', $this->group->title); + $title = $this->group->title; + $this->params->set('page_title', $title); + } + + // Check for empty title and add site name if param is set + if (empty($title)) + { + $title = $app->get('sitename'); + } + elseif ($app->get('sitename_pagetitles', 0) == 1) + { + $title = Text::sprintf('JPAGETITLE', $app->get('sitename'), $title); + } + elseif ($app->get('sitename_pagetitles', 0) == 2) + { + $title = Text::sprintf('JPAGETITLE', $title, $app->get('sitename')); + } + + if (empty($title)) + { + $title = $this->group->title; + } + + $this->document->setTitle($title); + return parent::display($tpl); } diff --git a/components/com_users/tmpl/users/default.php b/components/com_users/tmpl/users/default.php index 0a92037e29fd5..9883c300fe7c4 100644 --- a/components/com_users/tmpl/users/default.php +++ b/components/com_users/tmpl/users/default.php @@ -16,11 +16,18 @@ $lang = Factory::getLanguage(); ?> +params->get('show_page_heading')) : ?> + + + params->get('show_group_title', 1)) : ?>

group->title; ?>

+ items as $item) : ?>
From 0aedfc619d30ad865d2914674188e209ac6879b0 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Wed, 20 Jun 2018 00:08:11 +0300 Subject: [PATCH 24/39] added the real group name --- components/com_users/Model/UsersModel.php | 23 ++++++++++++++++++-- components/com_users/View/Users/HtmlView.php | 7 +----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/components/com_users/Model/UsersModel.php b/components/com_users/Model/UsersModel.php index 424b7aad08440..c67fe60674ef5 100644 --- a/components/com_users/Model/UsersModel.php +++ b/components/com_users/Model/UsersModel.php @@ -61,8 +61,6 @@ protected function getListQuery() $app = Factory::getApplication(); $user = Factory::getUser(); - // $u = Access::getUsersByGroup((int)$this->getState('user.group')); - // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); @@ -89,4 +87,25 @@ protected function getListQuery() return $query; } + /** + * Method to get group name for the current group + * + * @return string + */ + public function getGroup() + { + $db = $this->getDbo(); + $query = $db->getQuery(true); + + $query->select( + 'a.id, a.title' + ); + + $query->from($db->quoteName('#__usergroups') . ' AS a') + ->where('a.id = (' . $this->getState('user.group') . ')'); + + $db->setQuery($query); + + return $db->loadObject(); + } } diff --git a/components/com_users/View/Users/HtmlView.php b/components/com_users/View/Users/HtmlView.php index 8c9f05d63d410..7764311df5c8d 100644 --- a/components/com_users/View/Users/HtmlView.php +++ b/components/com_users/View/Users/HtmlView.php @@ -68,8 +68,7 @@ public function display($tpl = null) $this->items = $this->get('Items'); $this->state = $this->get('State'); $this->params = $this->state->get('params'); - - + $this->group = $this->get('Group'); PluginHelper::importPlugin('content'); @@ -97,10 +96,6 @@ public function display($tpl = null) $menus = $app->getMenu(); $menu = $menus->getActive(); - $this->group = new CMSObject; - $this->group->title = $menu->title; - $this->group->id = $this->state->get('user.group'); - if ($menu && $menu->component == 'com_users' && isset($menu->query['view'], $menu->query['id']) From 7e9c604cec5d527e72097c4f0d0e198785d117c7 Mon Sep 17 00:00:00 2001 From: Allon Moritz Date: Wed, 20 Jun 2018 07:37:08 +0200 Subject: [PATCH 25/39] Update HtmlView.php --- components/com_users/View/Users/HtmlView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/com_users/View/Users/HtmlView.php b/components/com_users/View/Users/HtmlView.php index 7764311df5c8d..a2a998e450e1f 100644 --- a/components/com_users/View/Users/HtmlView.php +++ b/components/com_users/View/Users/HtmlView.php @@ -68,7 +68,7 @@ public function display($tpl = null) $this->items = $this->get('Items'); $this->state = $this->get('State'); $this->params = $this->state->get('params'); - $this->group = $this->get('Group'); + $this->group = $this->get('Group'); PluginHelper::importPlugin('content'); From cc990f3709cd1298a5da624fb96556483d79fa4b Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Thu, 12 Jul 2018 16:05:45 +0300 Subject: [PATCH 26/39] Added contact form to user --- .../components/com_users/forms/user.xml | 67 ++++++ .../language/en-GB/en-GB.com_users.ini | 10 + .../com_users/Controller/UserController.php | 194 +++++++++++++++++- components/com_users/Model/UserModel.php | 72 ++++++- .../Rule/ContactEmailMessageRule.php | 57 +++++ .../com_users/Rule/ContactEmailRule.php | 62 ++++++ .../Rule/ContactEmailSubjectRule.php | 57 +++++ components/com_users/View/User/HtmlView.php | 9 + components/com_users/forms/contact.xml | 64 ++++++ components/com_users/tmpl/user/default.php | 5 + .../com_users/tmpl/user/default_form.php | 40 ++++ language/en-GB/en-GB.com_users.ini | 12 ++ 12 files changed, 645 insertions(+), 4 deletions(-) create mode 100644 components/com_users/Rule/ContactEmailMessageRule.php create mode 100644 components/com_users/Rule/ContactEmailRule.php create mode 100644 components/com_users/Rule/ContactEmailSubjectRule.php create mode 100644 components/com_users/forms/contact.xml create mode 100644 components/com_users/tmpl/user/default_form.php diff --git a/administrator/components/com_users/forms/user.xml b/administrator/components/com_users/forms/user.xml index a6af8669a5c96..75713afd6f9d5 100644 --- a/administrator/components/com_users/forms/user.xml +++ b/administrator/components/com_users/forms/user.xml @@ -209,5 +209,72 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ diff --git a/administrator/language/en-GB/en-GB.com_users.ini b/administrator/language/en-GB/en-GB.com_users.ini index 97469836c0b0b..b561707f92d3f 100644 --- a/administrator/language/en-GB/en-GB.com_users.ini +++ b/administrator/language/en-GB/en-GB.com_users.ini @@ -68,6 +68,15 @@ COM_USERS_ERROR_NO_ADDITIONS="The selected user(s) are already assigned to the s COM_USERS_ERROR_VIEW_LEVEL_IN_USE="You can't delete the view access level '%d:%s' because it is being used by content." COM_USERS_ERROR_SECRET_CODE_WITHOUT_TFA="You have entered a Secret Code but two factor authentication is not enabled in your user account. If you want to use a secret code to secure your login please edit your user profile and enable two factor authentication." COM_USERS_FIELD_CATEGORY_ID_LABEL="Category" +COM_USERS_FIELD_CONFIG_SESSION_CHECK_LABEL="Session Check" +COM_USERS_FIELD_EMAIL_BANNED_EMAIL_DESC="Email addresses not allowed to submit contact form. Separate multiple email addresses with a semicolon." +COM_USERS_FIELD_EMAIL_BANNED_EMAIL_LABEL="Banned Email" +COM_USERS_FIELD_EMAIL_BANNED_SUBJECT_DESC="Subjects not allowed in contact form. Separate multiple subjects with a semicolon." +COM_USERS_FIELD_EMAIL_BANNED_SUBJECT_LABEL="Banned Subject" +COM_USERS_FIELD_EMAIL_BANNED_TEXT_DESC="Text not allowed in contact form body. Separate multiple words with a semicolon." +COM_USERS_FIELD_EMAIL_BANNED_TEXT_LABEL="Banned Text" +COM_USERS_FIELD_EMAIL_EMAIL_COPY_LABEL="Send Copy to Submitter" +COM_USERS_FIELD_EMAIL_SHOW_FORM_LABEL="Contact Form" COM_USERS_FIELD_ID_LABEL="ID" COM_USERS_FIELD_LOGIN_MENUITEM="Menu Item" COM_USERS_FIELD_LOGIN_REDIRECT_PLACEHOLDER="index.php?Itemid=999&lang=en-GB" @@ -86,6 +95,7 @@ COM_USERS_FIELD_USER_ID_LABEL="User" COM_USERS_FIELDS_USER_FIELDS_TITLE="Users: Fields" COM_USERS_FIELDS_USER_FIELD_ADD_TITLE="Users: New Field" COM_USERS_FIELDS_USER_FIELD_EDIT_TITLE="Users: Edit Field" +COM_USERS_FIELDSET_CONTACT_LABEL="Form" COM_USERS_FILTER_ACTIVE="- Select Active State -" COM_USERS_FILTER_NOTES="Show notes list" COM_USERS_FILTER_STATE="- Select State -" diff --git a/components/com_users/Controller/UserController.php b/components/com_users/Controller/UserController.php index f973b953abe52..b6022d7b4c305 100644 --- a/components/com_users/Controller/UserController.php +++ b/components/com_users/Controller/UserController.php @@ -10,7 +10,14 @@ use Joomla\CMS\Application\ApplicationHelper; use Joomla\CMS\Language\Multilanguage; -use Joomla\CMS\MVC\Controller\BaseController; +use Joomla\CMS\MVC\Controller\FormController; +use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Language\Text; +use Joomla\CMS\String\PunycodeHelper; +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\User\User; defined('_JEXEC') or die; @@ -19,8 +26,24 @@ * * @since 1.6 */ -class UserController extends BaseController +class UserController extends FormController { + /** + * Method to get a model object, loading it if required. + * + * @param string $name The model name. Optional. + * @param string $prefix The class prefix. Optional. + * @param array $config Configuration array for model. Optional. + * + * @return \Joomla\CMS\MVC\Model\BaseDatabaseModel The model. + * + * @since 1.6.4 + */ + public function getModel($name = '', $prefix = '', $config = array('ignore_request' => true)) + { + return parent::getModel($name, $prefix, array('ignore_request' => false)); + } + /** * Method to log in a user. * @@ -357,4 +380,171 @@ public function resend() // Check for request forgeries // $this->checkToken('post'); } + + /** + * Method to submit the contact form and send an email. + * + * @return boolean True on success sending the email. False on failure. + * + * @since 1.5.19 + * @throws \Exception + */ + public function submit() + { + // Check for request forgeries. + $this->checkToken(); + + $app = Factory::getApplication(); + $model = $this->getModel('user'); + + $params = ComponentHelper::getParams('com_users'); + + $stub = $this->input->getString('id'); + $id = (int) $stub; + + // Get the data from POST + $data = $this->input->post->get('jform', array(), 'array'); + $contact = $model->getItem($id); + + $params->merge($contact->params); + + // Check for a valid session cookie + if ($params->get('validate_session', 0)) + { + if (Factory::getSession()->getState() !== 'active') + { + $this->app->enqueueMessage(Text::_('JLIB_ENVIRONMENT_SESSION_INVALID'), 'warning'); + + // Save the data in the session. + $this->app->setUserState('com_users.contact.data', $data); + + // Redirect back to the contact form. + $this->setRedirect(Route::_('index.php?option=com_users&view=user&id=' . $stub, false)); + + return false; + } + } + + // Validate the posted data. + $form = $model->getForm(); + + if (!$form) + { + throw new \Exception($model->getError(), 500); + + return false; + } + + if (!$model->validate($form, $data)) + { + $errors = $model->getErrors(); + + foreach ($errors as $error) + { + $errorMessage = $error; + + if ($error instanceof \Exception) + { + $errorMessage = $error->getMessage(); + } + + $app->enqueueMessage($errorMessage, 'error'); + } + + $app->setUserState('com_users.contact.data', $data); + + $this->setRedirect(Route::_('index.php?option=com_users&view=user&id=' . $stub, false)); + + return false; + } + + // Send the email + $sent = $this->_sendEmail($data, $contact, $params->get('show_email_copy', 0)); + + // Set the success message if it was a success + if (!($sent instanceof \Exception)) + { + $msg = Text::_('COM_USERS_CONTACT_EMAIL_THANKS'); + } + else + { + $msg = ''; + } + + // Flush the data from the session + $this->app->setUserState('com_users.contact.data', null); + + // Redirect if it is set in the parameters, otherwise redirect back to where we came from + if ($contact->params->get('redirect')) + { + $this->setRedirect($contact->params->get('redirect'), $msg); + } + else + { + $this->setRedirect(Route::_('index.php?option=com_users&view=user&id=' . $stub, false), $msg); + } + + return true; + } + + /** + * Method to send an email. + * + * @param array $data The data to send in the email. + * @param \stdClass $contact The user information to send the email to + * @param boolean $copy_email_activated True to send a copy of the email to the user. + * + * @return boolean True on success sending the email, false on failure. + * + * @since 1.6.4 + */ + private function _sendEmail($data, $contact, $copy_email_activated) + { + $app = $this->app; + + if ($contact->email == '' && $contact->id != 0) + { + $contact_user = User::getInstance($contact->id); + $contact->email = $contact_user->get('email'); + } + + $mailfrom = $app->get('mailfrom'); + $fromname = $app->get('fromname'); + $sitename = $app->get('sitename'); + + $name = $data['contact_name']; + $email = PunycodeHelper::emailToPunycode($data['contact_email']); + $subject = $data['contact_subject']; + $body = $data['contact_message']; + + // Prepare email body + $prefix = Text::sprintf('COM_USERS_CONTACT_ENQUIRY_TEXT', Uri::base()); + $body = $prefix . "\n" . $name . ' <' . $email . '>' . "\r\n\r\n" . stripslashes($body); + + $mail = Factory::getMailer(); + $mail->addRecipient($contact->email); + $mail->addReplyTo($email, $name); + $mail->setSender(array($mailfrom, $fromname)); + $mail->setSubject($sitename . ': ' . $subject); + $mail->setBody($body); + $sent = $mail->Send(); + + // Check whether email copy function activated + if ($copy_email_activated == true && !empty($data['contact_email_copy'])) + { + $copytext = Text::sprintf('COM_USERS_CONTACT_COPYTEXT_OF', $contact->name, $sitename); + $copytext .= "\r\n\r\n" . $body; + $copysubject = Text::sprintf('COM_USERS_CONTACT_COPYSUBJECT_OF', $subject); + + $mail = Factory::getMailer(); + $mail->addRecipient($email); + $mail->addReplyTo($email, $name); + $mail->setSender(array($mailfrom, $fromname)); + $mail->setSubject($copysubject); + $mail->setBody($copytext); + $sent = $mail->Send(); + } + + return $sent; + } } diff --git a/components/com_users/Model/UserModel.php b/components/com_users/Model/UserModel.php index ec76083f3c9b4..25cd1735edb78 100644 --- a/components/com_users/Model/UserModel.php +++ b/components/com_users/Model/UserModel.php @@ -10,18 +10,29 @@ defined('_JEXEC') or die; -use Joomla\CMS\MVC\Model\ItemModel; +use Joomla\CMS\MVC\Model\FormModel; use Joomla\CMS\User\User; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; +use Joomla\CMS\Language\Multilanguage; +use Joomla\Registry\Registry; /** * Public Profile model class for Users. * * @since 4.0 */ -class UserModel extends ItemModel +class UserModel extends FormModel { + /** + * A loaded item + * + * @since 1.6 + */ + protected $_item = null; + + protected $user; + /** * Method to auto-populate the model state. * @@ -77,7 +88,12 @@ public function getItem($pk = null) $loggedUser = Factory::getUser(); $groups = $loggedUser->getAuthorisedViewLevels(); + + $registry = new Registry($user->params); $user->params = $this->getState('params'); + $user->params = clone $this->getState('params'); + $user->params->merge($registry); + // Compute view access permissions. $user->params->set('access-view', in_array($user->access, $groups)); @@ -87,4 +103,56 @@ public function getItem($pk = null) return $this->_item[$pk]; } + + /** + * Method to get the contact form. + * The base form is loaded from XML and then an event is fired + * + * @param array $data An optional array of data for the form to interrogate. + * @param boolean $loadData True if the form is to load its own data (default case), false if not. + * + * @return \JForm A \JForm object on success, false on failure + * + * @since 1.6 + */ + public function getForm($data = array(), $loadData = true) + { + $form = $this->loadForm('com_users.contact', 'contact', array('control' => 'jform', 'load_data' => true)); + + if (empty($form)) + { + return false; + } + + $user = $this->_item[$this->getState('user.id')]; + + if (!$user->params->get('show_email_copy', 0)) + { + $form->removeField('contact_email_copy'); + } + + return $form; + } + + /** + * Method to get the data that should be injected in the form. + * + * @return array The default data is an empty array. + * + * @since 1.6.2 + * @throws \Exception + */ + protected function loadFormData() + { + $data = (array) Factory::getApplication()->getUserState('com_users.contact.data', array()); + + if (empty($data['language']) && Multilanguage::isEnabled()) + { + $data['language'] = Factory::getLanguage()->getTag(); + } + + $this->preprocessData('com_users.contact', $data); + + return $data; + } } diff --git a/components/com_users/Rule/ContactEmailMessageRule.php b/components/com_users/Rule/ContactEmailMessageRule.php new file mode 100644 index 0000000000000..eb7b134310929 --- /dev/null +++ b/components/com_users/Rule/ContactEmailMessageRule.php @@ -0,0 +1,57 @@ + tag for the form field object. + * @param mixed $value The form field value to validate. + * @param string $group The field name group control value. This acts as an array container for the field. + * For example if the field has name="foo" and the group value is set to "bar" then the + * full field name would end up being "bar[foo]". + * @param Registry $input An optional Registry object with the entire data set to validate against the entire form. + * @param Form $form The form object for which the field is being tested. + * + * @return boolean True if the value is valid, false otherwise. + */ + public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null) + { + $params = ComponentHelper::getParams('com_users'); + $banned = $params->get('banned_text'); + + if ($banned) + { + foreach (explode(';', $banned) as $item) + { + if ($item != '' && StringHelper::stristr($value, $item) !== false) + { + return false; + } + } + } + + return true; + } +} diff --git a/components/com_users/Rule/ContactEmailRule.php b/components/com_users/Rule/ContactEmailRule.php new file mode 100644 index 0000000000000..0974b22458ab1 --- /dev/null +++ b/components/com_users/Rule/ContactEmailRule.php @@ -0,0 +1,62 @@ + tag for the form field object. + * @param mixed $value The form field value to validate. + * @param string $group The field name group control value. This acts as an array container for the field. + * For example if the field has name="foo" and the group value is set to "bar" then the + * full field name would end up being "bar[foo]". + * @param Registry $input An optional Registry object with the entire data set to validate against the entire form. + * @param Form $form The form object for which the field is being tested. + * + * @return boolean True if the value is valid, false otherwise. + */ + public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null) + { + if (!parent::test($element, $value, $group, $input, $form)) + { + return false; + } + + $params = ComponentHelper::getParams('com_users'); + $banned = $params->get('banned_email'); + + if ($banned) + { + foreach (explode(';', $banned) as $item) + { + if ($item != '' && StringHelper::stristr($value, $item) !== false) + { + return false; + } + } + } + + return true; + } +} diff --git a/components/com_users/Rule/ContactEmailSubjectRule.php b/components/com_users/Rule/ContactEmailSubjectRule.php new file mode 100644 index 0000000000000..2db8297ac75c5 --- /dev/null +++ b/components/com_users/Rule/ContactEmailSubjectRule.php @@ -0,0 +1,57 @@ + tag for the form field object. + * @param mixed $value The form field value to validate. + * @param string $group The field name group control value. This acts as an array container for the field. + * For example if the field has name="foo" and the group value is set to "bar" then the + * full field name would end up being "bar[foo]". + * @param Registry $input An optional Registry object with the entire data set to validate against the entire form. + * @param Form $form The form object for which the field is being tested. + * + * @return boolean True if the value is valid, false otherwise + */ + public function test(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null) + { + $params = ComponentHelper::getParams('com_users'); + $banned = $params->get('banned_subject'); + + if ($banned) + { + foreach (explode(';', $banned) as $item) + { + if ($item != '' && StringHelper::stristr($value, $item) !== false) + { + return false; + } + } + } + + return true; + } +} diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php index 810d7afe8d5da..dbab24de7d021 100644 --- a/components/com_users/View/User/HtmlView.php +++ b/components/com_users/View/User/HtmlView.php @@ -44,6 +44,14 @@ class HtmlView extends BaseHtmlView */ protected $state; + /** + * The form object for the user contact item + * + * @var \JForm + * @since 1.6 + */ + protected $form; + /** * Execute and display a template script. * @@ -58,6 +66,7 @@ public function display($tpl = null) $app = Factory::getApplication(); $this->item = $this->get('Item'); $this->state = $this->get('State'); + $this->form = $this->get('Form'); $this->params = $this->state->get('params'); $user = Factory::getUser(); diff --git a/components/com_users/forms/contact.xml b/components/com_users/forms/contact.xml new file mode 100644 index 0000000000000..9c6cbc67ff8d5 --- /dev/null +++ b/components/com_users/forms/contact.xml @@ -0,0 +1,64 @@ + +
+
+ + + + + + + + + + + +
+
diff --git a/components/com_users/tmpl/user/default.php b/components/com_users/tmpl/user/default.php index e1d69dacb6099..a344a2b7ee6ee 100644 --- a/components/com_users/tmpl/user/default.php +++ b/components/com_users/tmpl/user/default.php @@ -8,6 +8,7 @@ */ defined('_JEXEC') or die; +$params = $this->item->params; ?>
diff --git a/components/com_users/tmpl/user/default_form.php b/components/com_users/tmpl/user/default_form.php new file mode 100644 index 0000000000000..3a7355f61acdf --- /dev/null +++ b/components/com_users/tmpl/user/default_form.php @@ -0,0 +1,40 @@ + +
+
+ form->getFieldsets() as $fieldset) : ?> + form->getFieldset($fieldset->name); ?> + +
+ label) && ($legend = trim(JText::_($fieldset->label))) !== '') : ?> + + + + renderField(); ?> + +
+ + +
+
+ + + + +
+
+
+
diff --git a/language/en-GB/en-GB.com_users.ini b/language/en-GB/en-GB.com_users.ini index e452873335601..eb0b0ce5dad72 100644 --- a/language/en-GB/en-GB.com_users.ini +++ b/language/en-GB/en-GB.com_users.ini @@ -6,6 +6,18 @@ COM_USERS_ACTIVATION_TOKEN_NOT_FOUND="Verification code not found." COM_USERS_CAPTCHA_LABEL="Captcha" COM_USERS_CAPTCHA_DESC="Please complete the security check." +COM_USERS_CONTACT_COPYSUBJECT_OF="Copy of: %s" +COM_USERS_CONTACT_COPYTEXT_OF="This is a copy of the following message you sent to %s via %s" +COM_USERS_CONTACT_DEFAULT_LABEL="Send an Email" +COM_USERS_CONTACT_EMAIL_A_COPY_LABEL="Send a copy to yourself" +COM_USERS_CONTACT_EMAIL_NAME_LABEL="Name" +COM_USERS_CONTACT_EMAIL_THANKS="Thank you for your email." +COM_USERS_CONTACT_ENQUIRY_TEXT="This is an enquiry email via %s from:" +COM_USERS_CONTACT_ENTER_MESSAGE_LABEL="Message" +COM_USERS_CONTACT_MESSAGE_SUBJECT_LABEL="Subject" +COM_USERS_CONTACT_REPLY_EMAIL_LABEL="Reply to email" +COM_USERS_CONTACT_REQUIRED="* Required field" +COM_USERS_CONTACT_SEND="Send Email" COM_USERS_DATABASE_ERROR="Error getting the user from the database: %s" COM_USERS_DEFAULT_PAGE_TITLE="Users" COM_USERS_DESIRED_USERNAME="Enter your desired username." From 853ac6536b5d5cd9621062a50fe1226f8c381d19 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 16 Jul 2018 14:50:47 +0300 Subject: [PATCH 27/39] Fixes after the merge --- .../tmpl/users/default_batch_footer.php | 2 -- .../com_users/tmpl/user/default_form.php | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/administrator/components/com_users/tmpl/users/default_batch_footer.php b/administrator/components/com_users/tmpl/users/default_batch_footer.php index bbc30b019b034..4bb0e1543c30b 100644 --- a/administrator/components/com_users/tmpl/users/default_batch_footer.php +++ b/administrator/components/com_users/tmpl/users/default_batch_footer.php @@ -9,8 +9,6 @@ defined('_JEXEC') or die; use Joomla\CMS\Language\Text; -use Joomla\CMS\Language\Text; - ?> diff --git a/components/com_users/tmpl/user/default_form.php b/components/com_users/tmpl/user/default_form.php index 3a7355f61acdf..1907c54faff03 100644 --- a/components/com_users/tmpl/user/default_form.php +++ b/components/com_users/tmpl/user/default_form.php @@ -9,17 +9,24 @@ defined('_JEXEC') or die; -JHtml::_('behavior.keepalive'); -JHtml::_('behavior.formvalidator'); +use Joomla\CMS\Router\Route; +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; + +HTMLHelper::_('behavior.keepalive'); +HTMLHelper::_('behavior.formvalidator'); ?>
-
+ form->getFieldsets() as $fieldset) : ?> + name === 'captcha' && !$this->captchaEnabled) : ?> + + form->getFieldset($fieldset->name); ?>
- label) && ($legend = trim(JText::_($fieldset->label))) !== '') : ?> + label) && ($legend = trim(Text::_($fieldset->label))) !== '') : ?> @@ -30,10 +37,10 @@
- + - +
From 20d91ca3a3e1d9ada079615848eaf8433521b691 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 16 Jul 2018 14:51:32 +0300 Subject: [PATCH 28/39] Added captcha, custom reply param and global configuration to the user form --- administrator/components/com_users/config.xml | 107 ++++++++++++++++++ .../components/com_users/forms/user.xml | 11 ++ .../language/en-GB/en-GB.com_users.ini | 10 ++ .../com_users/Controller/UserController.php | 7 +- components/com_users/View/User/HtmlView.php | 21 ++++ components/com_users/forms/contact.xml | 10 ++ 6 files changed, 165 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_users/config.xml b/administrator/components/com_users/config.xml index a78b791174aed..aaca7305e90d1 100644 --- a/administrator/components/com_users/config.xml +++ b/administrator/components/com_users/config.xml @@ -184,6 +184,113 @@ />
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/administrator/components/com_users/forms/user.xml b/administrator/components/com_users/forms/user.xml index 688dae17a3f9c..9392c9242a84d 100644 --- a/administrator/components/com_users/forms/user.xml +++ b/administrator/components/com_users/forms/user.xml @@ -216,6 +216,7 @@ name="show_email_form" type="list" label="COM_USERS_FIELD_EMAIL_SHOW_FORM_LABEL" + useglobal="true" > @@ -269,6 +270,16 @@ + + + + + _sendEmail($data, $contact, $params->get('show_email_copy', 0)); + $sent = false; + + if (!$params->get('custom_reply')) + { + $sent = $this->_sendEmail($data, $contact, $params->get('show_email_copy', 0)); + } // Set the success message if it was a success if (!($sent instanceof \Exception)) diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php index dbab24de7d021..11ca4de2db42e 100644 --- a/components/com_users/View/User/HtmlView.php +++ b/components/com_users/View/User/HtmlView.php @@ -52,6 +52,14 @@ class HtmlView extends BaseHtmlView */ protected $form; + /** + * Should we show a captcha form for the submission of the contact request? + * + * @var bool + * @since 3.6.3 + */ + protected $captchaEnabled = false; + /** * Execute and display a template script. * @@ -60,6 +68,7 @@ class HtmlView extends BaseHtmlView * @return mixed A string if successful, otherwise an Error object. * * @since 1.6 + * @throws \Exception */ public function display($tpl = null) { @@ -101,6 +110,17 @@ public function display($tpl = null) $results = $app->triggerEvent('onContentAfterDisplay', array('com_users.user', &$this->item, &$this->item->params, $offset)); $this->item->event->afterDisplayContent = trim(implode("\n", $results)); + $captchaSet = $this->item->params->get('captcha', Factory::getApplication()->get('captcha', '0')); + + foreach (PluginHelper::getPlugin('captcha') as $plugin) + { + if ($captchaSet === $plugin->name) + { + $this->captchaEnabled = true; + break; + } + } + $this->_prepareDocument(); return parent::display($tpl); @@ -109,6 +129,7 @@ public function display($tpl = null) * Prepares the document. * * @return void + * @throws \Exception */ protected function _prepareDocument() { diff --git a/components/com_users/forms/contact.xml b/components/com_users/forms/contact.xml index 9c6cbc67ff8d5..f4158fcc39748 100644 --- a/components/com_users/forms/contact.xml +++ b/components/com_users/forms/contact.xml @@ -61,4 +61,14 @@ default="0" />
+ +
+ +
From 59c81b70199324b4d0f204f379cbe8f8fc6ba149 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Mon, 16 Jul 2018 14:54:01 +0300 Subject: [PATCH 29/39] codestyle fix --- components/com_users/View/User/HtmlView.php | 1 + 1 file changed, 1 insertion(+) diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php index 11ca4de2db42e..a0675db4e6c8e 100644 --- a/components/com_users/View/User/HtmlView.php +++ b/components/com_users/View/User/HtmlView.php @@ -129,6 +129,7 @@ public function display($tpl = null) * Prepares the document. * * @return void + * * @throws \Exception */ protected function _prepareDocument() From aac4ed9b9727668ac443ceea1c50940ddc56b75c Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Tue, 17 Jul 2018 00:12:14 +0300 Subject: [PATCH 30/39] Made form extendable with custom fields --- .../com_users/Helper/UsersHelper.php | 1 + .../language/en-GB/en-GB.com_users.ini | 1 + .../com_users/Controller/UserController.php | 19 +++++ components/com_users/layouts/field/render.php | 46 +++++++++++ .../com_users/layouts/fields/render.php | 77 +++++++++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 components/com_users/layouts/field/render.php create mode 100644 components/com_users/layouts/fields/render.php diff --git a/administrator/components/com_users/Helper/UsersHelper.php b/administrator/components/com_users/Helper/UsersHelper.php index 864d1507f2486..1f910b8afed9e 100644 --- a/administrator/components/com_users/Helper/UsersHelper.php +++ b/administrator/components/com_users/Helper/UsersHelper.php @@ -339,6 +339,7 @@ public static function getContexts() $contexts = array( 'com_users.user' => Text::_('COM_USERS'), + 'com_users.contact' => Text::_('COM_USERS_FIELDS_CONTEXT_CONTACT'), ); return $contexts; diff --git a/administrator/language/en-GB/en-GB.com_users.ini b/administrator/language/en-GB/en-GB.com_users.ini index 68b7726c3cbef..5945d38db4d9e 100644 --- a/administrator/language/en-GB/en-GB.com_users.ini +++ b/administrator/language/en-GB/en-GB.com_users.ini @@ -102,6 +102,7 @@ COM_USERS_FIELD_NOTEBODY_LABEL="Note" COM_USERS_FIELD_REVIEW_TIME_LABEL="Review Date" COM_USERS_FIELD_SUBJECT_LABEL="Subject" COM_USERS_FIELD_USER_ID_LABEL="User" +COM_USERS_FIELDS_CONTEXT_CONTACT="Contact" COM_USERS_FIELDS_USER_FIELDS_TITLE="Users: Fields" COM_USERS_FIELDS_USER_FIELD_ADD_TITLE="Users: New Field" COM_USERS_FIELDS_USER_FIELD_EDIT_TITLE="Users: Edit Field" diff --git a/components/com_users/Controller/UserController.php b/components/com_users/Controller/UserController.php index 137fd0d65a5d8..c23bcc5523d1b 100644 --- a/components/com_users/Controller/UserController.php +++ b/components/com_users/Controller/UserController.php @@ -526,6 +526,25 @@ private function _sendEmail($data, $contact, $copy_email_activated) $prefix = Text::sprintf('COM_USERS_CONTACT_ENQUIRY_TEXT', Uri::base()); $body = $prefix . "\n" . $name . ' <' . $email . '>' . "\r\n\r\n" . stripslashes($body); + // Load the custom fields + if (!empty($data['com_fields']) && $fields = \FieldsHelper::getFields('com_users.contact', $contact, true, $data['com_fields'])) + { + $output = \FieldsHelper::render( + 'com_users.contact', + 'fields.render', + array( + 'context' => 'com_users.contact', + 'item' => $contact, + 'fields' => $fields, + ) + ); + + if ($output) + { + $body .= "\r\n\r\n" . $output; + } + } + $mail = Factory::getMailer(); $mail->addRecipient($contact->email); $mail->addReplyTo($email, $name); diff --git a/components/com_users/layouts/field/render.php b/components/com_users/layouts/field/render.php new file mode 100644 index 0000000000000..21d5da8d45280 --- /dev/null +++ b/components/com_users/layouts/field/render.php @@ -0,0 +1,46 @@ +label); +$value = $field->value; +$class = $field->params->get('render_class'); +$showLabel = $field->params->get('showlabel'); + +if ($field->context == 'com_users.contact') +{ + // Prepare the value for the contact form mail + $value = html_entity_decode($value); + + echo ($showLabel ? $label . ': ' : '') . $value . "\r\n"; + return; +} + +if (!$value) +{ + return; +} + +?> +
+ + : + +
+
+ +
diff --git a/components/com_users/layouts/fields/render.php b/components/com_users/layouts/fields/render.php new file mode 100644 index 0000000000000..67fea30fecfdb --- /dev/null +++ b/components/com_users/layouts/fields/render.php @@ -0,0 +1,77 @@ +jcfields ?: FieldsHelper::getFields($context, $item, true); +} + +if (!$fields) +{ + return; +} + +// Check if we have contact context in first element +$isMail = (reset($fields)->context == 'com_users.contact'); + +if (!$isMail) +{ + // Print the container tag + echo '
'; +} + +// Loop through the fields and print them +foreach ($fields as $field) +{ + // If the value is empty do nothing + if (empty($field->value) && !$isMail) + { + continue; + } + + echo FieldsHelper::render($context, 'field.render', array('field' => $field)); +} + +if (!$isMail) +{ + // Close the container + echo '
'; +} From d0cfbf9831195fb43ab994a4961adb448d9941fa Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Tue, 17 Jul 2018 12:22:43 +0300 Subject: [PATCH 31/39] Add newline --- .../components/com_users/tmpl/users/default_batch_footer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/administrator/components/com_users/tmpl/users/default_batch_footer.php b/administrator/components/com_users/tmpl/users/default_batch_footer.php index 4bb0e1543c30b..102e53bc44ded 100644 --- a/administrator/components/com_users/tmpl/users/default_batch_footer.php +++ b/administrator/components/com_users/tmpl/users/default_batch_footer.php @@ -7,6 +7,7 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; + use Joomla\CMS\Language\Text; ?> From fcc816c8b2474f58aeaa96dea1c2f7d8b5867778 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Tue, 17 Jul 2018 12:24:01 +0300 Subject: [PATCH 32/39] Moved jexec --- components/com_users/Controller/UserController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/com_users/Controller/UserController.php b/components/com_users/Controller/UserController.php index c23bcc5523d1b..4b5d7f4e5f965 100644 --- a/components/com_users/Controller/UserController.php +++ b/components/com_users/Controller/UserController.php @@ -8,6 +8,8 @@ */ namespace Joomla\Component\Users\Site\Controller; +defined('_JEXEC') or die; + use Joomla\CMS\Application\ApplicationHelper; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\MVC\Controller\FormController; @@ -20,7 +22,6 @@ use Joomla\CMS\String\PunycodeHelper; use Joomla\CMS\User\User; -defined('_JEXEC') or die; /** * Registration controller class for Users. * From c42d1f14b565dbaf99dccbb614ddc48cf7431a34 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Tue, 17 Jul 2018 12:36:52 +0300 Subject: [PATCH 33/39] Added newlines and removed spaces --- components/com_users/Model/UserModel.php | 2 -- components/com_users/tmpl/user/default.php | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/components/com_users/Model/UserModel.php b/components/com_users/Model/UserModel.php index 25cd1735edb78..e8c728f344e7e 100644 --- a/components/com_users/Model/UserModel.php +++ b/components/com_users/Model/UserModel.php @@ -31,8 +31,6 @@ class UserModel extends FormModel */ protected $_item = null; - protected $user; - /** * Method to auto-populate the model state. * diff --git a/components/com_users/tmpl/user/default.php b/components/com_users/tmpl/user/default.php index a344a2b7ee6ee..3922e935736ef 100644 --- a/components/com_users/tmpl/user/default.php +++ b/components/com_users/tmpl/user/default.php @@ -8,6 +8,7 @@ */ defined('_JEXEC') or die; + $params = $this->item->params; ?>
@@ -24,7 +25,7 @@
escape($this->item->username); ?>
escape($this->item->email); ?>
- get('show_email_form')) : ?> + get('show_email_form')) : ?> loadTemplate('form'); ?> From fa384e135874fca3ceef3404b15b8acf3636f7b8 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Tue, 17 Jul 2018 12:38:07 +0300 Subject: [PATCH 34/39] Removed extra tabs --- administrator/components/com_users/config.xml | 124 +++++++++--------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/administrator/components/com_users/config.xml b/administrator/components/com_users/config.xml index aaca7305e90d1..9ef574447df4a 100644 --- a/administrator/components/com_users/config.xml +++ b/administrator/components/com_users/config.xml @@ -185,109 +185,109 @@
From 21255493fb87879696c07ba3a87f8415dae6f98c Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Wed, 8 Aug 2018 20:04:28 +0300 Subject: [PATCH 35/39] Changes after code review --- administrator/components/com_users/config.xml | 23 +++-- .../components/com_users/forms/user.xml | 84 +++++++++---------- .../language/en-GB/en-GB.com_users.ini | 2 +- .../language/en-GB/en-GB.com_users.sys.ini | 2 +- components/com_users/View/User/HtmlView.php | 1 - 5 files changed, 55 insertions(+), 57 deletions(-) diff --git a/administrator/components/com_users/config.xml b/administrator/components/com_users/config.xml index 136fac69cfda1..a8c76809c0045 100644 --- a/administrator/components/com_users/config.xml +++ b/administrator/components/com_users/config.xml @@ -188,8 +188,7 @@ name="Contact_Form" label="COM_USERS_CONFIG_FIELD_CONTACT_FORM" description="COM_USERS_CONFIG_FIELD_INDIVIDUAL_CONTACT_DESC" - > - + > + > + > @@ -219,7 +218,7 @@ default="0" class="switcher" showon="show_email_form:1" - > + > @@ -260,11 +259,11 @@ + > @@ -272,11 +271,11 @@ + > @@ -320,7 +319,7 @@
+ description="COM_USERS_MASS_MAIL_DESC" > + > + > + name="show_email_copy" + type="list" + label="COM_USERS_FIELD_EMAIL_EMAIL_COPY_LABEL" + useglobal="true" + > + name="validate_session" + type="list" + label="COM_USERS_FIELD_CONFIG_SESSION_CHECK_LABEL" + useglobal="true" + > + name="custom_reply" + type="list" + label="COM_USERS_CONFIG_FIELD_CUSTOM_REPLY_LABEL" + useglobal="true" + >
diff --git a/administrator/language/en-GB/en-GB.com_users.ini b/administrator/language/en-GB/en-GB.com_users.ini index 88799fcf04c31..8d00d68f84e8f 100644 --- a/administrator/language/en-GB/en-GB.com_users.ini +++ b/administrator/language/en-GB/en-GB.com_users.ini @@ -30,7 +30,7 @@ COM_USERS_CONFIG_FIELD_FRONTEND_RESET_COUNT_LABEL="Maximum Reset Count" COM_USERS_CONFIG_FIELD_FRONTEND_RESET_TIME_LABEL="Reset Time" COM_USERS_CONFIG_FIELD_FRONTEND_USERPARAMS_LABEL="Frontend User Parameters" COM_USERS_CONFIG_FIELD_GUEST_USER_GROUP_LABEL="Guest User Group" -COM_USERS_CONFIG_FIELD_INDIVIDUAL_CONTACT_DESC="These settings apply for single User unless they are changed for a specific User." +COM_USERS_CONFIG_FIELD_INDIVIDUAL_CONTACT_DESC="These settings apply for all Users unless they are changed for a specific User." COM_USERS_CONFIG_FIELD_MAILBODY_SUFFIX_LABEL="Mailbody Suffix" COM_USERS_CONFIG_FIELD_MAILTOADMIN_LABEL="Send Mail to Administrators" COM_USERS_CONFIG_FIELD_MINIMUM_INTEGERS="Minimum Integers" diff --git a/administrator/language/en-GB/en-GB.com_users.sys.ini b/administrator/language/en-GB/en-GB.com_users.sys.ini index e020abbc712e0..294b428c45033 100644 --- a/administrator/language/en-GB/en-GB.com_users.sys.ini +++ b/administrator/language/en-GB/en-GB.com_users.sys.ini @@ -28,7 +28,7 @@ COM_USERS_NOTE_VIEW_EDIT_TITLE="Create User Note" COM_USERS_TAGS_CATEGORY="User Note Category" COM_USERS_USERS_VIEW_DEFAULT_DESC="Shows a List of Users" COM_USERS_USERS_VIEW_DEFAULT_TITLE="Users" -COM_USERS_USER_DETAILS_VIEW_DEFAULT_DESC="Displays the details of the chosen user" +COM_USERS_USER_DETAILS_VIEW_DEFAULT_DESC="Displays the details of the chosen user." COM_USERS_USER_DETAILS_VIEW_DEFAULT_OPTION="User details" COM_USERS_USER_DETAILS_VIEW_DEFAULT_TITLE="User details" COM_USERS_USER_VIEW_EDIT_DESC="Shows a form to create a new User Account" diff --git a/components/com_users/View/User/HtmlView.php b/components/com_users/View/User/HtmlView.php index a0675db4e6c8e..2576bd52b17fe 100644 --- a/components/com_users/View/User/HtmlView.php +++ b/components/com_users/View/User/HtmlView.php @@ -138,6 +138,5 @@ protected function _prepareDocument() $pathway = $app->getPathway(); $pathway->addItem($this->item->name, ''); - } } From 918ede34e98e2449313e0188233625cfe8c4aa29 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Wed, 8 Aug 2018 20:19:16 +0300 Subject: [PATCH 36/39] Remove blank line --- administrator/components/com_users/forms/user.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/administrator/components/com_users/forms/user.xml b/administrator/components/com_users/forms/user.xml index f29349d2001a8..9bd52d833d4c0 100644 --- a/administrator/components/com_users/forms/user.xml +++ b/administrator/components/com_users/forms/user.xml @@ -217,7 +217,6 @@ type="list" label="COM_USERS_FIELD_EMAIL_SHOW_FORM_LABEL" useglobal="true" - > From 9a1d66c2aac2da9276be0377495ee2cdd7c38479 Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Wed, 8 Aug 2018 20:45:13 +0300 Subject: [PATCH 37/39] Changes after code review --- components/com_users/Controller/UserController.php | 2 +- components/com_users/Model/UserModel.php | 2 -- components/com_users/layouts/field/render.php | 1 + components/com_users/router.php | 1 - components/com_users/tmpl/users/default.xml | 4 ++-- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/components/com_users/Controller/UserController.php b/components/com_users/Controller/UserController.php index 4b5d7f4e5f965..5f8d8a56148c4 100644 --- a/components/com_users/Controller/UserController.php +++ b/components/com_users/Controller/UserController.php @@ -510,7 +510,7 @@ private function _sendEmail($data, $contact, $copy_email_activated) if ($contact->email == '' && $contact->id != 0) { - $contact_user = User::getInstance($contact->id); + $contact_user = User::getInstance($contact->id); $contact->email = $contact_user->get('email'); } diff --git a/components/com_users/Model/UserModel.php b/components/com_users/Model/UserModel.php index e8c728f344e7e..82c9825468fbf 100644 --- a/components/com_users/Model/UserModel.php +++ b/components/com_users/Model/UserModel.php @@ -54,7 +54,6 @@ protected function populateState() // Load the parameters. $params = $app->getParams(); $this->setState('params', $params); - } /** @@ -92,7 +91,6 @@ public function getItem($pk = null) $user->params = clone $this->getState('params'); $user->params->merge($registry); - // Compute view access permissions. $user->params->set('access-view', in_array($user->access, $groups)); diff --git a/components/com_users/layouts/field/render.php b/components/com_users/layouts/field/render.php index 21d5da8d45280..9b70c36fa19af 100644 --- a/components/com_users/layouts/field/render.php +++ b/components/com_users/layouts/field/render.php @@ -27,6 +27,7 @@ $value = html_entity_decode($value); echo ($showLabel ? $label . ': ' : '') . $value . "\r\n"; + return; } diff --git a/components/com_users/router.php b/components/com_users/router.php index 9d245db58e43d..c5916d24611bf 100644 --- a/components/com_users/router.php +++ b/components/com_users/router.php @@ -110,6 +110,5 @@ public function getUserId($segment, $query) } return (int) $segment; - } } diff --git a/components/com_users/tmpl/users/default.xml b/components/com_users/tmpl/users/default.xml index d0a7276e867aa..2357771ff8f3f 100644 --- a/components/com_users/tmpl/users/default.xml +++ b/components/com_users/tmpl/users/default.xml @@ -11,7 +11,7 @@ name="id" type="usergrouplist" label="COM_USERS_GROUP_LABEL" - > + > @@ -24,7 +24,7 @@ type="list" label="COM_USERS_GROUP_FIELD_TITLE_LABEL" useglobal="true" - > + > From ca24e1a0b6f62b1516e06f84315a63d690d013fc Mon Sep 17 00:00:00 2001 From: Alexandra Ciobica Date: Wed, 8 Aug 2018 21:06:48 +0300 Subject: [PATCH 38/39] Changes after code review --- administrator/components/com_users/tmpl/users/default.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_users/tmpl/users/default.php b/administrator/components/com_users/tmpl/users/default.php index 19107307853b9..183356b6d3535 100644 --- a/administrator/components/com_users/tmpl/users/default.php +++ b/administrator/components/com_users/tmpl/users/default.php @@ -151,9 +151,9 @@ group_names); ?>
- escape($item->access_level); ?> - + escape($item->access_level); ?> + escape($item->email)); ?> - escape($item->access_level); ?> + escape($item->access_level); ?> escape($item->email)); ?>