users.php
6.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
/**
* @package Joomla.Administrator
* @subpackage com_users
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Users component helper.
*
* @since 1.6
*/
class UsersHelper
{
/**
* @var JObject A cache for the available actions.
* @since 1.6
*/
protected static $actions;
/**
* Configure the Linkbar.
*
* @param string $vName The name of the active view.
*
* @return void
*
* @since 1.6
*/
public static function addSubmenu($vName)
{
JHtmlSidebar::addEntry(
JText::_('COM_USERS_SUBMENU_USERS'),
'index.php?option=com_users&view=users',
$vName == 'users'
);
// Groups and Levels are restricted to core.admin
$canDo = JHelperContent::getActions('com_users');
if ($canDo->get('core.admin'))
{
JHtmlSidebar::addEntry(
JText::_('COM_USERS_SUBMENU_GROUPS'),
'index.php?option=com_users&view=groups',
$vName == 'groups'
);
JHtmlSidebar::addEntry(
JText::_('COM_USERS_SUBMENU_LEVELS'),
'index.php?option=com_users&view=levels',
$vName == 'levels'
);
}
if (JComponentHelper::isEnabled('com_fields') && JComponentHelper::getParams('com_users')->get('custom_fields_enable', '1'))
{
JHtmlSidebar::addEntry(
JText::_('JGLOBAL_FIELDS'),
'index.php?option=com_fields&context=com_users.user',
$vName == 'fields.fields'
);
JHtmlSidebar::addEntry(
JText::_('JGLOBAL_FIELD_GROUPS'),
'index.php?option=com_fields&view=groups&context=com_users.user',
$vName == 'fields.groups'
);
}
JHtmlSidebar::addEntry(
JText::_('COM_USERS_SUBMENU_NOTES'),
'index.php?option=com_users&view=notes',
$vName == 'notes'
);
JHtmlSidebar::addEntry(
JText::_('COM_USERS_SUBMENU_NOTE_CATEGORIES'),
'index.php?option=com_categories&extension=com_users',
$vName == 'categories'
);
}
/**
* Gets a list of the actions that can be performed.
*
* @return JObject
*
* @deprecated 3.2 Use JHelperContent::getActions() instead
*/
public static function getActions()
{
// Log usage of deprecated function
try
{
JLog::add(
sprintf('%s() is deprecated. Use JHelperContent::getActions() with new arguments order instead.', __METHOD__),
JLog::WARNING,
'deprecated'
);
}
catch (RuntimeException $exception)
{
// Informational log only
}
// Get list of actions
return JHelperContent::getActions('com_users');
}
/**
* Get a list of filter options for the blocked state of a user.
*
* @return array An array of JHtmlOption elements.
*
* @since 1.6
*/
public static function getStateOptions()
{
// Build the filter options.
$options = array();
$options[] = JHtml::_('select.option', '0', JText::_('JENABLED'));
$options[] = JHtml::_('select.option', '1', JText::_('JDISABLED'));
return $options;
}
/**
* Get a list of filter options for the activated state of a user.
*
* @return array An array of JHtmlOption elements.
*
* @since 1.6
*/
public static function getActiveOptions()
{
// Build the filter options.
$options = array();
$options[] = JHtml::_('select.option', '0', JText::_('COM_USERS_ACTIVATED'));
$options[] = JHtml::_('select.option', '1', JText::_('COM_USERS_UNACTIVATED'));
return $options;
}
/**
* Get a list of the user groups for filtering.
*
* @return array An array of JHtmlOption elements.
*
* @since 1.6
*/
public static function getGroups()
{
$options = JHelperUsergroups::getInstance()->getAll();
foreach ($options as &$option)
{
$option->value = $option->id;
$option->text = str_repeat('- ', $option->level) . $option->title;
}
return $options;
}
/**
* Creates a list of range options used in filter select list
* used in com_users on users view
*
* @return array
*
* @since 2.5
*/
public static function getRangeOptions()
{
$options = array(
JHtml::_('select.option', 'today', JText::_('COM_USERS_OPTION_RANGE_TODAY')),
JHtml::_('select.option', 'past_week', JText::_('COM_USERS_OPTION_RANGE_PAST_WEEK')),
JHtml::_('select.option', 'past_1month', JText::_('COM_USERS_OPTION_RANGE_PAST_1MONTH')),
JHtml::_('select.option', 'past_3month', JText::_('COM_USERS_OPTION_RANGE_PAST_3MONTH')),
JHtml::_('select.option', 'past_6month', JText::_('COM_USERS_OPTION_RANGE_PAST_6MONTH')),
JHtml::_('select.option', 'past_year', JText::_('COM_USERS_OPTION_RANGE_PAST_YEAR')),
JHtml::_('select.option', 'post_year', JText::_('COM_USERS_OPTION_RANGE_POST_YEAR')),
);
return $options;
}
/**
* Creates a list of two factor authentication methods used in com_users
* on user view
*
* @return array
*
* @since 3.2.0
*/
public static function getTwoFactorMethods()
{
FOFPlatform::getInstance()->importPlugin('twofactorauth');
$identities = FOFPlatform::getInstance()->runPlugins('onUserTwofactorIdentify', array());
$options = array(
JHtml::_('select.option', 'none', JText::_('JGLOBAL_OTPMETHOD_NONE'), 'value', 'text'),
);
if (!empty($identities))
{
foreach ($identities as $identity)
{
if (!is_object($identity))
{
continue;
}
$options[] = JHtml::_('select.option', $identity->method, $identity->title, 'value', 'text');
}
}
return $options;
}
/**
* Get a list of the User Groups for Viewing Access Levels
*
* @param string $rules User Groups in JSON format
*
* @return string $groups Comma separated list of User Groups
*
* @since 3.6
*/
public static function getVisibleByGroups($rules)
{
$rules = json_decode($rules);
if (!$rules)
{
return false;
}
$rules = implode(',', $rules);
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('a.title AS text')
->from('#__usergroups as a')
->where('a.id IN (' . $rules . ')');
$db->setQuery($query);
$groups = $db->loadColumn();
$groups = implode(', ', $groups);
return $groups;
}
/**
* Returns a valid section for users. If it is not valid then null
* is returned.
*
* @param string $section The section to get the mapping for
*
* @return string|null The new section
*
* @since 3.7.0
*/
public static function validateSection($section)
{
if (JFactory::getApplication()->isClient('site'))
{
switch ($section)
{
case 'registration':
case 'profile':
$section = 'user';
}
}
if ($section != 'user')
{
// We don't know other sections
return null;
}
return $section;
}
/**
* Returns valid contexts
*
* @return array
*
* @since 3.7.0
*/
public static function getContexts()
{
JFactory::getLanguage()->load('com_users', JPATH_ADMINISTRATOR);
$contexts = array(
'com_users.user' => JText::_('COM_USERS'),
);
return $contexts;
}
}