Completed
Pull Request — develop (#716)
by Agel_Nash
06:26
created

welcome.static.php ➔ getRecentInfoList()   F

Complexity

Conditions 19
Paths 2306

Size

Total Lines 84
Code Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 19
eloc 59
nc 2306
nop 0
dl 0
loc 84
rs 2.0436
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
if( ! defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) {
3
	die('<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly.');
4
}
5
6
unset($_SESSION['itemname']); // clear this, because it's only set for logging purposes
7
8
if($modx->hasPermission('settings') && (!isset($settings_version) || $settings_version != $modx->getVersionData('version'))) {
9
	// seems to be a new install - send the user to the configuration page
10
	exit('<script type="text/javascript">document.location.href="index.php?a=17";</script>');
11
}
12
13
// set placeholders
14
$ph = $_lang;
15
$_SESSION['nrtotalmessages'] = 0;
16
$_SESSION['nrnewmessages'] = 0;
17
18
// setup message info
19
if($modx->hasPermission('messages')) {
20
	include_once(MODX_MANAGER_PATH . 'includes/messageCount.inc.php');
21
	$_SESSION['nrtotalmessages'] = $nrtotalmessages;
22
	$_SESSION['nrnewmessages'] = $nrnewmessages;
23
24
	$msg = array();
25
	$msg[] = sprintf('<a href="index.php?a=10" target="main"><img src="%s" /></a>', $_style['icons_mail_large']);
26
	$nrnewmessages = $_SESSION['nrnewmessages'] > 0 ? ' (<span style="color:red">' . $_SESSION['nrnewmessages'] . '</span>)' : '';
27
	$msg[] = sprintf('<span style="color:#909090;font-size:15px;font-weight:bold">&nbsp;<a class="wm_messages_inbox_link" href="index.php?a=10" target="main">[%%inbox%%]</a>%s</span><br />', $nrnewmessages);
28
	$nrnewmessages = $_SESSION['nrnewmessages'] > 0 ? '<span style="color:red;">' . $_SESSION['nrnewmessages'] . '</span>' : '0';
29
	$welcome_messages = sprintf($_lang['welcome_messages'], $_SESSION['nrtotalmessages'], $nrnewmessages);
30
	$msg[] = sprintf('<span class="comment">%s</span>', $welcome_messages);
31
	$ph['MessageInfo'] = implode("\n", $msg);
32
}
33
34
$iconTpl = $managerTheme->getPartial('welcome/WrapIcon');
35
// setup icons
36
if($modx->hasPermission('new_user') || $modx->hasPermission('edit_user')) {
37
	$icon = '<i class="[&icons_security_large&]" alt="[%user_management_title%]"> </i>[%user_management_title%]';
38
	$ph['SecurityIcon'] = sprintf($iconTpl,$icon, 75);
39
}
40
if($modx->hasPermission('new_web_user') || $modx->hasPermission('edit_web_user')) {
41
	$icon = '<i class="[&icons_webusers_large&]" alt="[%web_user_management_title%]"> </i>[%web_user_management_title%]';
42
	$ph['WebUserIcon'] = sprintf($iconTpl,$icon, 99);
43
}
44
if($modx->hasPermission('new_module') || $modx->hasPermission('edit_module')) {
45
	$icon = '<i class="[&icons_modules_large&]" alt="[%manage_modules%]"> </i>[%modules%]';
46
	$ph['ModulesIcon'] = sprintf($iconTpl,$icon, 106);
47
}
48 View Code Duplication
if($modx->hasPermission('new_template') || $modx->hasPermission('edit_template') || $modx->hasPermission('new_snippet') || $modx->hasPermission('edit_snippet') || $modx->hasPermission('new_plugin') || $modx->hasPermission('edit_plugin') || $modx->hasPermission('manage_metatags')) {
49
	$icon = '<i class="[&icons_resources_large&]" alt="[%element_management%]"> </i>[%elements%]';
50
	$ph['ResourcesIcon'] = sprintf($iconTpl,$icon, 76);
51
}
52
if($modx->hasPermission('bk_manager')) {
53
	$icon = '<i class="[&icons_backup_large&]" alt="[%bk_manager%]"> </i>[%backup%]';
54
	$ph['BackupIcon'] = sprintf($iconTpl,$icon, 93);
55
}
56
if($modx->hasPermission('help')) {
57
	$icon = '<i class="[&icons_help_large&]" alt="[%help%]" /> </i>[%help%]';
58
	$ph['HelpIcon'] = sprintf($iconTpl,$icon, 9);
59
}
60
61
if($modx->hasPermission('new_document')) {
62
	$icon = '<i class="[&icons_resource_large&]"></i>[%add_resource%]';
63
	$ph['ResourceIcon'] = sprintf($iconTpl,$icon, 4);
64
	$icon = '<i class="[&icons_weblink_large&]"></i>[%add_weblink%]';
65
	$ph['WeblinkIcon'] = sprintf($iconTpl,$icon, 72);
66
}
67
if($modx->hasPermission('assets_images')) {
68
	$icon = '<i class="[&icons_images_large&]"></i>[%images_management%]';
69
	$ph['ImagesIcon'] = sprintf($iconTpl,$icon, 72);
70
}
71
if($modx->hasPermission('assets_files')) {
72
	$icon = '<i class="[&icons_files_large&]"></i>[%files_management%]';
73
	$ph['FilesIcon'] = sprintf($iconTpl,$icon, 72);
74
}
75
if($modx->hasPermission('change_password')) {
76
	$icon = '<i class="[&icons_password_large&]"></i>[%change_password%]';
77
	$ph['PasswordIcon'] = sprintf($iconTpl,$icon, 28);
78
}
79
$icon = '<i class="[&icons_logout_large&]"></i>[%logout%]';
80
$ph['LogoutIcon'] = sprintf($iconTpl,$icon, 8);
81
82
// do some config checks
83
if(($modx->config['warning_visibility'] == 0 && $_SESSION['mgrRole'] == 1) || $modx->config['warning_visibility'] == 1) {
84
	include_once(MODX_MANAGER_PATH . 'includes/config_check.inc.php');
85
	if($config_check_results != $_lang['configcheck_ok']) {
86
		$ph['config_check_results'] = $config_check_results;
87
		$ph['config_display'] = 'block';
88
	} else {
89
		$ph['config_display'] = 'none';
90
	}
91
} else {
92
	$ph['config_display'] = 'none';
93
}
94
95
// Check logout-reminder
96
if(isset($_SESSION['show_logout_reminder'])) {
97
	switch($_SESSION['show_logout_reminder']['type']) {
98
		case 'logout_reminder':
99
			$date = $modx->toDateFormat($_SESSION['show_logout_reminder']['lastHit'], 'dateOnly');
100
			$ph['logout_reminder_msg'] = str_replace('[+date+]', $date, $_lang['logout_reminder_msg']);
101
			break;
102
	}
103
	$ph['show_logout_reminder'] = 'block';
104
	unset($_SESSION['show_logout_reminder']);
105
} else {
106
	$ph['show_logout_reminder'] = 'none';
107
}
108
109
// Check multiple sessions
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
110
//$where = sprintf("internalKey='%s'", $modx->db->escape($_SESSION['mgrInternalKey']));
111
//$rs = $modx->db->select('count(*) AS count', '[+prefix+]active_user_sessions', $where);
112
//$count = $modx->db->getValue($rs);
113
/*
114
if($count > 1) {
115
	$ph['multiple_sessions_msg'] = $modx->parseText($_lang['multiple_sessions_msg'], array(
116
		'username' => $_SESSION['mgrShortname'],
117
		'total' => $count
118
	));
119
	$ph['show_multiple_sessions'] = 'block';
120
} else {
121
	$ph['show_multiple_sessions'] = 'none';
122
}*/
123
$ph['show_multiple_sessions'] = 'none';
124
125
$modx->addSnippet('recentInfoList', $managerTheme->getPartial('welcome/RecentInfo/Snippet'));
126
$ph['RecentInfo'] = $managerTheme->getPartial('welcome/RecentInfo/Template');
127
128
$tpl = '
129
<table class="table data">
130
	<tr>
131
		<td width="150">[%yourinfo_username%]</td>
132
		<td><b>[+username+]</b></td>
133
	</tr>
134
	<tr>
135
		<td>[%yourinfo_role%]</td>
136
		<td><b>[+role+]</b></td>
137
	</tr>
138
	<tr>
139
		<td>[%yourinfo_previous_login%]</td>
140
		<td><b>[+lastlogin+]</b></td>
141
	</tr>
142
	<tr>
143
		<td>[%yourinfo_total_logins%]</td>
144
		<td><b>[+logincount+]</b></td>
145
	</tr>
146
	<tr>
147
		<td>[%inbox%]</td>
148
		<td><a href="index.php?a=10" target="main"><b>[+msginfo+]</b></a></td>
149
	</tr>
150
</table>';
151
152
$nrnewmessages = '<span class="text-danger">' . $_SESSION['nrnewmessages'] . '</span>';
153
154
$ph['UserInfo'] = $modx->parseText($tpl, array(
155
	'username' => $modx->getLoginUserName(),
156
	'role' => $_SESSION['mgrPermissions']['name'],
157
	'lastlogin' => $modx->toDateFormat($_SESSION['mgrLastlogin'] + $server_offset_time),
158
	'logincount' => $_SESSION['mgrLogincount'] + 1,
159
	'msginfo' => sprintf($_lang['welcome_messages'], $_SESSION['nrtotalmessages'], $nrnewmessages)
160
));
161
162
$from = array();
163
$from[] = '[+prefix+]active_user_sessions';
164
$from[] = " us LEFT JOIN [+prefix+]active_users au ON au.sid=us.sid WHERE au.action <> '8'";
165
$rs = $modx->db->select('*', $from, '', 'username ASC, au.sid ASC');
166
167
if($modx->db->getRecordCount($rs) < 1) {
168
	$html = '<p>[%no_active_users_found%]</p>';
169
} else {
170
	include_once(MODX_MANAGER_PATH . 'includes/actionlist.inc.php');
171
	$now = $_SERVER['REQUEST_TIME'] + $server_offset_time;
172
	$ph['now'] = strftime('%H:%M:%S', $now);
173
	$timetocheck = ($now - (60 * 20)); //+$server_offset_time;
174
	$html = '
175
	<div class="card-body">
176
		[%onlineusers_message%] 
177
		<b>[+now+]</b>):
178
	</div>
179
	<div class="table-responsive">
180
	<table class="table data">
181
	<thead>
182
		<tr>
183
			<th>[%onlineusers_user%]</th>
184
			<th>ID</th>
185
			<th>[%onlineusers_ipaddress%]</th>
186
			<th>[%onlineusers_lasthit%]</th>
187
			<th>[%onlineusers_action%]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
188
		</tr>
189
	</thead>
190
	<tbody>';
191
192
	$userList = array();
193
	$userCount = array();
194
	// Create userlist with session-count first before output
195
	while($activeusers = $modx->db->getRow($rs)) {
196
		$userCount[$activeusers['internalKey']] = isset($userCount[$activeusers['internalKey']]) ? $userCount[$activeusers['internalKey']] + 1 : 1;
197
198
		$idle = $activeusers['lasthit'] < $timetocheck ? ' class="userIdle"' : '';
199
		$webicon = $activeusers['internalKey'] < 0 ? '<img src="[&tree_globe&]" alt="Web user" />&nbsp;' : '';
200
		$ip = $activeusers['ip'] === '::1' ? '127.0.0.1' : $activeusers['ip'];
201
		$currentaction = getAction($activeusers['action'], $activeusers['id']);
202
		$userList[] = array(
203
			$idle,
204
			'',
205
			$activeusers['username'],
206
			$webicon,
207
			abs($activeusers['internalKey']),
208
			$ip,
209
			strftime('%H:%M:%S', $activeusers['lasthit'] + $server_offset_time),
210
			$currentaction
211
		);
212
	}
213
	foreach($userList as $params) {
214
		$params[1] = $userCount[$params[4]] > 1 ? ' class="userMultipleSessions"' : '';
215
		$html .= "\n\t\t" . vsprintf('<tr%s><td><strong%s>%s</strong></td><td>%s%s</td><td>%s</td><td>%s</td><td>%s</td></tr>', $params);
216
	}
217
218
	$html .= '
219
	</tbody>
220
	</table>
221
</div>
222
';
223
}
224
$ph['OnlineInfo'] = $html;
225
226
// include rss feeds for important forum topics
227
include_once(MODX_MANAGER_PATH . 'includes/rss.inc.php');
228
$ph['modx_security_notices_content'] = $feedData['modx_security_notices_content'];
229
$ph['modx_news_content'] = $feedData['modx_news_content'];
230
231
$ph['theme'] = $modx->config['manager_theme'];
232
$ph['site_name'] = $modx->config['site_name'];
233
$ph['home'] = $_lang['home'];
234
$ph['logo_slogan'] = $_lang['logo_slogan'];
235
$ph['welcome_title'] = $_lang['welcome_title'];
236
$ph['search'] = $_lang['search'];
237
$ph['settings_config'] = $_lang['settings_config'];
238
$ph['configcheck_title'] = $_lang['configcheck_title'];
239
$ph['online'] = $_lang['online'];
240
$ph['onlineusers_title'] = $_lang['onlineusers_title'];
241
$ph['recent_docs'] = $_lang['recent_docs'];
242
$ph['activity_title'] = $_lang['activity_title'];
243
$ph['info'] = $_lang['info'];
244
$ph['yourinfo_title'] = $_lang['yourinfo_title'];
245
246
$ph['modx_security_notices'] = $_lang['security_notices_tab'];
247
$ph['modx_security_notices_title'] = $_lang['security_notices_title'];
248
$ph['modx_news'] = $_lang['modx_news_tab'];
249
$ph['modx_news_title'] = $_lang['modx_news_title'];
250
251
$modx->toPlaceholders($ph);
252
253
$script = $managerTheme->getPartial('welcome/StartUpScript');
254
$modx->regClientScript($script);
255
256
// invoke event OnManagerWelcomePrerender
257
$evtOut = $modx->invokeEvent('OnManagerWelcomePrerender');
258
if(is_array($evtOut)) {
259
	$output = implode('', $evtOut);
260
	$ph['OnManagerWelcomePrerender'] = $output;
261
}
262
263
$widgets['welcome'] = array(
264
	'menuindex' => '10',
265
	'id' => 'welcome',
266
	'cols' => 'col-lg-6',
267
	'icon' => 'fa-home',
268
	'title' => '[%welcome_title%]',
269
	'body' => '
270
				<div class="wm_buttons card-body"> 
271
					<!--@IF:[[#hasPermission?key=new_document]]--> 
272
					<span class="wm_button">
273
						<a target="main" href="index.php?a=4">
274
							<i class="[&icons_resource_large&]"></i>
275
							<span>[%add_resource%]</span>
276
						</a>
277
					</span> 
278
					<span class="wm_button">
279
						<a target="main" href="index.php?a=72">
280
							<i class="[&icons_weblink_large&]"></i>
281
							<span>[%add_weblink%]</span>
282
						</a>
283
					</span> 
284
					<!--@ENDIF--> 
285
					<!--@IF:[[#hasPermission?key=assets_images]]--> 
286
					<span class="wm_button">
287
						<a target="main" href="media/browser/mcpuk/browse.php?filemanager=media/browser/mcpuk/browse.php&type=images">
288
							<i class="[&icons_images_large&]"></i>
289
							<span>[%images_management%]</span>
290
						</a>
291
					</span> 
292
					<!--@ENDIF-->
293
					<!--@IF:[[#hasPermission?key=assets_files]]--> 
294
					<span class="wm_button">
295
						<a target="main" href="media/browser/mcpuk/browse.php?filemanager=media/browser/mcpuk/browse.php&type=files">
296
							<i class="[&icons_files_large&]"></i>
297
							<span>[%files_management%]</span>
298
						</a>
299
					</span> 
300
					<!--@ENDIF-->
301
					<!--@IF:[[#hasPermission?key=change_password]]--> 
302
					<span class="wm_button">
303
						<a target="main" href="index.php?a=28">
304
							<i class="[&icons_password_large&]"></i>
305
							<span>[%change_password%]</span>
306
						</a>
307
					</span> 
308
					<!--@ENDIF--> 
309
					<span class="wm_button">
310
						<a target="_top" href="index.php?a=8">
311
							<i class="[&icons_logout_large&]"></i>
312
							<span>[%logout%]</span>
313
						</a>
314
					</span> 
315
				</div>
316
				<div class="userprofiletable card-body">
317
					<table>
318
						<tr>
319
							<td width="150">[%yourinfo_username%]</td>
320
							<td><b>[[#getLoginUserName]]</b></td>
321
						</tr>
322
						<tr>
323
							<td>[%yourinfo_role%]</td>
324
							<td><b>[[$_SESSION[\'mgrPermissions\'][\'name\'] ]]</b></td>
325
						</tr>
326
						<tr>
327
							<td>[%yourinfo_previous_login%]</td>
328
							<td><b>[[$_SESSION[\'mgrLastlogin\']:math(\'%s+[(server_offset_time)]\'):dateFormat]]</b></td>
329
						</tr>
330
						<tr>
331
							<td>[%yourinfo_total_logins%]</td>
332
							<td><b>[[$_SESSION[\'mgrLogincount\']:math(\'%s+1\')]]</b></td>
333
						</tr>
334
						<!--@IF:[[#hasPermission?key=messages]]-->
335
						<tr>
336
							<td>[%inbox%]</td>
337
							<td><a href="index.php?a=10" target="main"><b>[[#getMessageCount]]</b></a></td>
338
						</tr>
339
						<!--@ENDIF-->
340
					</table>
341
				</div>
342
		',
343
	'hide'=>'0'
344
);
345
$widgets['onlineinfo'] = array(
346
	'menuindex' => '20',
347
	'id' => 'onlineinfo',
348
	'cols' => 'col-lg-6',
349
	'icon' => 'fa-user',
350
	'title' => '[%onlineusers_title%]',
351
	'body' => '<div class="userstable">[+OnlineInfo+]</div>',
352
	'hide'=>'0'
353
);
354
$widgets['recentinfo'] = array(
355
	'menuindex' => '30',
356
	'id' => 'modxrecent_widget',
357
	'cols' => 'col-sm-12',
358
	'icon' => 'fa-pencil-square-o',
359
	'title' => '[%activity_title%]',
360
	'body' => '<div class="widget-stage">[+RecentInfo+]</div>',
361
	'hide'=>'0'
362
);
363 View Code Duplication
if ($modx->config['rss_url_news']) {
364
    $widgets['news'] = array(
365
        'menuindex' => '40',
366
        'id' => 'news',
367
        'cols' => 'col-sm-6',
368
        'icon' => 'fa-rss',
369
        'title' => '[%modx_news_title%]',
370
        'body' => '<div style="max-height:200px;overflow-y: scroll;padding: 1rem .5rem">[+modx_news_content+]</div>',
371
        'hide'=>'0'
372
    );
373
}
374 View Code Duplication
if ($modx->config['rss_url_security']) {
375
    $widgets['security'] = array(
376
        'menuindex' => '50',
377
        'id' => 'security',
378
        'cols' => 'col-sm-6',
379
        'icon' => 'fa-exclamation-triangle',
380
        'title' => '[%security_notices_title%]',
381
        'body' => '<div style="max-height:200px;overflow-y: scroll;padding: 1rem .5rem">[+modx_security_notices_content+]</div>',
382
        'hide'=>'0'
383
    );
384
}
385
386
// invoke OnManagerWelcomeHome event
387
$sitewidgets = $modx->invokeEvent("OnManagerWelcomeHome", array('widgets' => $widgets));
388
if(is_array($sitewidgets)) {
389
	$newwidgets = array();
390
    foreach($sitewidgets as $widget){
391
        $newwidgets = array_merge($newwidgets, unserialize($widget));
392
    }
393
    $widgets = (count($newwidgets) > 0) ? $newwidgets : $widgets;
394
}
395
396
usort($widgets, function ($a, $b) {
397
	return $a['menuindex'] - $b['menuindex'];
398
});
399
400
$tpl = $managerTheme->getPartial('welcome/Widget');
401
$output = '';
402
foreach($widgets as $widget) {
403
	if ($widget['hide'] != '1'){
404
		$output .= $modx->parseText($tpl, $widget);
405
	}
406
}
407
$ph['widgets'] = $output;
408
409
// load template
410 View Code Duplication
if(!isset($modx->config['manager_welcome_tpl']) || empty($modx->config['manager_welcome_tpl'])) {
411
	$modx->config['manager_welcome_tpl'] = MODX_MANAGER_PATH . 'media/style/common/welcome.tpl';
412
}
413
414
$target = $modx->config['manager_welcome_tpl'];
415
$target = str_replace('[+base_path+]', MODX_BASE_PATH, $target);
416
$target = $modx->mergeSettingsContent($target);
417
418
if(substr($target, 0, 1) === '@') {
419
	if(substr($target, 0, 6) === '@CHUNK') {
420
		$content = $modx->getChunk(trim(substr($target, 7)));
421
	} elseif(substr($target, 0, 5) === '@FILE') {
422
		$content = file_get_contents(trim(substr($target, 6)));
423
	} else {
424
		$content = '';
425
	}
426
} else {
427
	$chunk = $modx->getChunk($target);
428
	if($chunk !== false && !empty($chunk)) {
429
		$content = $chunk;
430
	} elseif(is_file(MODX_BASE_PATH . $target)) {
431
		$content = file_get_contents(MODX_BASE_PATH . $target);
432
	} elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/welcome.tpl')) {
433
		$content = file_get_contents(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/welcome.tpl');
434
	} elseif(is_file(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/html/welcome.html')) // ClipperCMS compatible
435
	{
436
		$content = file_get_contents(MODX_MANAGER_PATH . 'media/style/' . $modx->config['manager_theme'] . '/html/welcome.html');
437
	} else {
438
		$content = file_get_contents(MODX_MANAGER_PATH . 'media/style/common/welcome.tpl');
439
	}
440
}
441
442
// merge placeholders
443
$content = $modx->mergeConditionalTagsContent($content);
444
$content = $modx->mergeSettingsContent($content);
445
$content = $modx->parseText($content, $ph);
446
if(strpos($content, '[+') !== false) {
447
	$modx->toPlaceholders($ph);
448
	$content = $modx->mergePlaceholderContent($content);
449
}
450
$content = $modx->parseDocumentSource($content);
451
$content = $modx->parseText($content, $_lang, '[%', '%]');
452
$content = $modx->parseText($content, $_style, '[&', '&]');
453
$content = $modx->cleanUpMODXTags($content); //cleanup
454
455
if($js = $modx->getRegisteredClientScripts()) {
456
	$content .= $js;
457
}
458
459
echo $content;
460
461
//<span class="conf">
462
//	<a href="javascript:;" class="setting"><i class="fa fa-cog"></i></a>
463
//  <a href="javascript:;" class="closed"><i class="fa fa-close"></i></a>
464
//</span>
465