GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 954c90...c0df7f )
by gyeong-won
31:08 queued 03:00
created

memberController::procMemberScrapDocument()   C

Complexity

Conditions 8
Paths 11

Size

Total Lines 40
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 24
nc 11
nop 0
dl 0
loc 40
rs 5.3846
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  memberController
5
 * @author NAVER ([email protected])
6
 * Controller class of member module
7
 */
8
class memberController extends member
9
{
10
	/**
11
	 * Info of selected member
12
	 *
13
	 * @var object
14
	 */
15
	var $memberInfo;
16
17
	/**
18
	 * Initialization
19
	 *
20
	 * @return void
21
	 */
22
	function init()
23
	{
24
	}
25
26
	/**
27
	 * Log-in by checking user_id and password
28
	 *
29
	 * @param string $user_id
30
	 * @param string $password
31
	 * @param string $keep_signed
32
	 *
33
	 * @return void|Object (void : success, Object : fail)
34
	 */
35
	function procMemberLogin($user_id = null, $password = null, $keep_signed = null)
36
	{
37
		if(!$user_id && !$password && Context::getRequestMethod() == 'GET')
0 ignored issues
show
Bug Best Practice introduced by
The expression $user_id of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Bug Best Practice introduced by
The expression $password of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
38
		{
39
			$this->setRedirectUrl(getNotEncodedUrl(''));
40
			return new Object(-1, 'null_user_id');
41
		}
42
43
		// Variables
44
		if(!$user_id) $user_id = Context::get('user_id');
0 ignored issues
show
Bug Best Practice introduced by
The expression $user_id of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
45
		$user_id = trim($user_id);
46
47
		if(!$password) $password = Context::get('password');
0 ignored issues
show
Bug Best Practice introduced by
The expression $password of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
48
		$password = trim($password);
49
50
		if(!$keep_signed) $keep_signed = Context::get('keep_signed');
0 ignored issues
show
Bug Best Practice introduced by
The expression $keep_signed of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
51
		// Return an error when id and password doesn't exist
52
		if(!$user_id) return new Object(-1,'null_user_id');
53
		if(!$password) return new Object(-1,'null_password');
54
55
		$output = $this->doLogin($user_id, $password, $keep_signed=='Y'?true:false);
56
		if (!$output->toBool()) return $output;
57
58
		$oModuleModel = getModel('module');
59
		$config = $oModuleModel->getModuleConfig('member');
60
61
		// Check change_password_date
62
		$limit_date = $config->change_password_date;
63
64
		// Check if change_password_date is set
65
		if($limit_date > 0)
66
		{
67
			$oMemberModel = getModel('member');
0 ignored issues
show
Unused Code introduced by
$oMemberModel is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
68
			if($this->memberInfo->change_password_date < date ('YmdHis', strtotime ('-' . $limit_date . ' day')))
69
			{
70
				$msg = sprintf(Context::getLang('msg_change_password_date'), $limit_date);
71
				return $this->setRedirectUrl(getNotEncodedUrl('','vid',Context::get('vid'),'mid',Context::get('mid'),'act','dispMemberModifyPassword'), new Object(-1, $msg));
72
			}
73
		}
74
75
		// Delete all previous authmail if login is successful
76
		$args = new stdClass();
77
		$args->member_srl = $this->memberInfo->member_srl;
78
		executeQuery('member.deleteAuthMail', $args);
79
80
		if(!$config->after_login_url)
81
		{
82
			$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
83
		}
84
		else
85
		{
86
			$returnUrl = $config->after_login_url;
87
		}
88
		return $this->setRedirectUrl($returnUrl, $output);
89
	}
90
91
	/**
92
	 * Log-out
93
	 *
94
	 * @return Object
95
	 */
96
	function procMemberLogout()
97
	{
98
		// Call a trigger before log-out (before)
99
		$logged_info = Context::get('logged_info');
100
		$trigger_output = ModuleHandler::triggerCall('member.doLogout', 'before', $logged_info);
0 ignored issues
show
Documentation introduced by
$logged_info is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
101
		if(!$trigger_output->toBool()) return $trigger_output;
102
		// Destroy session information
103
		$this->destroySessionInfo();
104
		// Call a trigger after log-out (after)
105
		$trigger_output = ModuleHandler::triggerCall('member.doLogout', 'after', $logged_info);
106
		if(!$trigger_output->toBool()) return $trigger_output;
107
108
		$output = new Object();
109
110
		$oModuleModel = getModel('module');
111
		$config = $oModuleModel->getModuleConfig('member');
112
		if($config->after_logout_url)
113
			$output->redirect_url = $config->after_logout_url;
0 ignored issues
show
Bug introduced by
The property redirect_url does not seem to exist in Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
114
115
		$this->_clearMemberCache($logged_info->member_srl);
116
117
		return $output;
118
	}
119
120
	/**
121
	 * Scrap document
122
	 *
123
	 * @return void|Object (void : success, Object : fail)
124
	 */
125
	function procMemberScrapDocument()
126
	{
127
		// Check login information
128
		if(!Context::get('is_logged')) return new Object(-1, 'msg_not_logged');
129
		$logged_info = Context::get('logged_info');
130
131
		$document_srl = (int)Context::get('document_srl');
132
		if(!$document_srl) $document_srl = (int)Context::get('target_srl');
133
		if(!$document_srl) return new Object(-1,'msg_invalid_request');
134
135
		// Get document
136
		$oDocumentModel = getModel('document');
137
		$oDocument = $oDocumentModel->getDocument($document_srl);
138
139
		if($oDocument->isSecret() && !$oDocument->isGranted())
140
		{
141
			return new Object(-1, 'msg_is_secret');
142
		}
143
144
		// Variables
145
		$args = new stdClass();
146
		$args->document_srl = $document_srl;
147
		$args->member_srl = $logged_info->member_srl;
148
		$args->user_id = $oDocument->get('user_id');
149
		$args->user_name = $oDocument->get('user_name');
150
		$args->nick_name = $oDocument->get('nick_name');
151
		$args->target_member_srl = $oDocument->get('member_srl');
152
		$args->title = $oDocument->get('title');
153
154
		// Check if already scrapped
155
		$output = executeQuery('member.getScrapDocument', $args);
156
		if($output->data->count) return new Object(-1, 'msg_alreay_scrapped');
157
158
		// Insert
159
		$output = executeQuery('member.addScrapDocument', $args);
160
		if(!$output->toBool()) return $output;
161
162
		$this->setError(-1);
163
		$this->setMessage('success_registed');
164
	}
165
166
	/**
167
	 * Delete a scrap
168
	 *
169
	 * @return void|Object (void : success, Object : fail)
170
	 */
171
	function procMemberDeleteScrap()
172
	{
173
		// Check login information
174
		if(!Context::get('is_logged')) return new Object(-1, 'msg_not_logged');
175
		$logged_info = Context::get('logged_info');
176
177
		$document_srl = (int)Context::get('document_srl');
178
		if(!$document_srl) return new Object(-1,'msg_invalid_request');
179
		// Variables
180
		$args = new stdClass;
181
		$args->member_srl = $logged_info->member_srl;
182
		$args->document_srl = $document_srl;
183
		return executeQuery('member.deleteScrapDocument', $args);
184
	}
185
186
	/**
187
	 * Save posts
188
	 * @deprecated - instead Document Controller - procDocumentTempSave method use
189
	 * @return Object
190
	 */
191
	function procMemberSaveDocument()
192
	{
193
		return new Object(0, 'Deprecated method');
194
	}
195
196
	/**
197
	 * Delete the post
198
	 *
199
	 * @return void|Object (void : success, Object : fail)
200
	 */
201
	function procMemberDeleteSavedDocument()
202
	{
203
		// Check login information
204
		if(!Context::get('is_logged')) return new Object(-1, 'msg_not_logged');
205
		$logged_info = Context::get('logged_info');
206
207
		$document_srl = (int)Context::get('document_srl');
208
		if(!$document_srl) return new Object(-1,'msg_invalid_request');
209
210
		$oDocumentModel = getModel('document');
211
		$oDocument = $oDocumentModel->getDocument($document_srl);
212
		if ($oDocument->get('member_srl') != $logged_info->member_srl)
213
		{
214
			return new Object(-1,'msg_invalid_request');
215
		}
216
217
		$configStatusList = $oDocumentModel->getStatusList();
218
		if ($oDocument->get('status') != $configStatusList['temp'])
219
		{
220
			return new Object(-1,'msg_invalid_request');
221
		}
222
223
		$oDocumentController = getController('document');
224
		$oDocumentController->deleteDocument($document_srl);
225
	}
226
227
	/**
228
	 * Check values when member joining
229
	 *
230
	 * @return void|Object (void : success, Object : fail)
231
	 */
232
	function procMemberCheckValue()
233
	{
234
		$name = Context::get('name');
235
		$value = Context::get('value');
236
		if(!$value) return;
237
238
		$oMemberModel = getModel('member');
239
		// Check if logged-in
240
		$logged_info = Context::get('logged_info');
241
242
243
		switch($name)
244
		{
245
			case 'user_id' :
246
				// Check denied ID
247
				if($oMemberModel->isDeniedID($value)) return new Object(0,'denied_user_id');
248
				// Check if duplicated
249
				$member_srl = $oMemberModel->getMemberSrlByUserID($value);
250
				if($member_srl && $logged_info->member_srl != $member_srl ) return new Object(0,'msg_exists_user_id');
251
				break;
252
			case 'nick_name' :
253
				// Check denied ID
254
				if($oMemberModel->isDeniedNickName($value))
255
				{
256
					return new Object(0,'denied_nick_name');
257
				}
258
				// Check if duplicated
259
				$member_srl = $oMemberModel->getMemberSrlByNickName($value);
260
				if($member_srl && $logged_info->member_srl != $member_srl ) return new Object(0,'msg_exists_nick_name');
261
262
				break;
263
			case 'email_address' :
264
				// Check if duplicated
265
				$member_srl = $oMemberModel->getMemberSrlByEmailAddress($value);
266
				if($member_srl && $logged_info->member_srl != $member_srl ) return new Object(0,'msg_exists_email_address');
267
				break;
268
		}
269
	}
270
271
	/**
272
	 * Join Membership
273
	 *
274
	 * @return void|Object (void : success, Object : fail)
275
	 */
276
	function procMemberInsert()
277
	{
278
		if (Context::getRequestMethod () == "GET") return new Object (-1, "msg_invalid_request");
279
		$oMemberModel = &getModel ('member');
280
		$config = $oMemberModel->getMemberConfig();
281
282
		// call a trigger (before)
283
		$trigger_output = ModuleHandler::triggerCall ('member.procMemberInsert', 'before', $config);
284
		if(!$trigger_output->toBool ()) return $trigger_output;
285
		// Check if an administrator allows a membership
286
		if($config->enable_join != 'Y') return $this->stop ('msg_signup_disabled');
287
		// Check if the user accept the license terms (only if terms exist)
288
		if($config->agreement && Context::get('accept_agreement')!='Y') return $this->stop('msg_accept_agreement');
289
290
		// Extract the necessary information in advance
291
		$getVars = array();
292 View Code Duplication
		if($config->signupForm)
293
		{
294
			foreach($config->signupForm as $formInfo)
295
			{
296
				if($formInfo->isDefaultForm && ($formInfo->isUse || $formInfo->required || $formInfo->mustRequired))
297
				{
298
					$getVars[] = $formInfo->name;
299
				}
300
			}
301
		}
302
303
		$args = new stdClass;
304 View Code Duplication
		foreach($getVars as $val)
305
		{
306
			$args->{$val} = Context::get($val);
307
			if($val == 'birthday') $args->birthday_ui = Context::get('birthday_ui');
308
		}
309
		$args->birthday = intval(strtr($args->birthday, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
310 View Code Duplication
		if(!$args->birthday && $args->birthday_ui) $args->birthday = intval(strtr($args->birthday_ui, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
311
312
		$args->find_account_answer = Context::get('find_account_answer');
313
		$args->allow_mailing = Context::get('allow_mailing');
314
		$args->allow_message = Context::get('allow_message');
315
316
		if($args->password1) $args->password = $args->password1;
317
318
		// check password strength
319 View Code Duplication
		if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
320
		{
321
			$message = Context::getLang('about_password_strength');
322
			return new Object(-1, $message[$config->password_strength]);
323
		}
324
325
		// Remove some unnecessary variables from all the vars
326
		$all_args = Context::getRequestVars();
327
		unset($all_args->module);
328
		unset($all_args->act);
329
		unset($all_args->is_admin);
330
		unset($all_args->member_srl);
331
		unset($all_args->description);
332
		unset($all_args->group_srl_list);
333
		unset($all_args->body);
334
		unset($all_args->accept_agreement);
335
		unset($all_args->signature);
336
		unset($all_args->password);
337
		unset($all_args->password2);
338
		unset($all_args->mid);
339
		unset($all_args->error_return_url);
340
		unset($all_args->ruleset);
341
		unset($all_args->captchaType);
342
		unset($all_args->secret_text);
343
344
		// Set the user state as "denied" when using mail authentication
345
		if($config->enable_confirm == 'Y') $args->denied = 'Y';
346
		// Add extra vars after excluding necessary information from all the requested arguments
347
		$extra_vars = delObjectVars($all_args, $args);
348
		$args->extra_vars = serialize($extra_vars);
349
350
		// remove whitespace
351
		$checkInfos = array('user_id', 'user_name', 'nick_name', 'email_address');
352 View Code Duplication
		foreach($checkInfos as $val)
353
		{
354
			if(isset($args->{$val}))
355
			{
356
				$args->{$val} = preg_replace('/[\pZ\pC]+/u', '', $args->{$val});
357
			}
358
		}
359
		$output = $this->insertMember($args);
360
		if(!$output->toBool()) return $output;
361
362
		// insert ProfileImage, ImageName, ImageMark
363
		$profile_image = $_FILES['profile_image'];
364
		if(is_uploaded_file($profile_image['tmp_name']))
365
		{
366
			$this->insertProfileImage($args->member_srl, $profile_image['tmp_name']);
367
		}
368
369
		$image_mark = $_FILES['image_mark'];
370
		if(is_uploaded_file($image_mark['tmp_name']))
371
		{
372
			$this->insertImageMark($args->member_srl, $image_mark['tmp_name']);
373
		}
374
375
		$image_name = $_FILES['image_name'];
376
		if(is_uploaded_file($image_name['tmp_name']))
377
		{
378
			$this->insertImageName($args->member_srl, $image_name['tmp_name']);
379
		}
380
381
		// If a virtual site, join the site
382
		$site_module_info = Context::get('site_module_info');
383
		if($site_module_info->site_srl > 0)
384
		{
385
			$columnList = array('site_srl', 'group_srl');
386
			$default_group = $oMemberModel->getDefaultGroup($site_module_info->site_srl, $columnList);
387
			if($default_group->group_srl)
388
			{
389
				$this->addMemberToGroup($args->member_srl, $default_group->group_srl, $site_module_info->site_srl);
390
			}
391
392
		}
393
		// Log-in
394
		if($config->enable_confirm != 'Y')
395
		{
396
			if($config->identifier == 'email_address')
397
			{
398
				$output = $this->doLogin($args->email_address);
399
			}
400
			else
401
			{
402
				$output = $this->doLogin($args->user_id);
403
			}
404
			if(!$output->toBool()) {
405
				if($output->error == -9)
406
					$output->error = -11;
407
				return $this->setRedirectUrl(getUrl('', 'act', 'dispMemberLoginForm'), $output);
408
			}
409
		}
410
411
		// Results
412
		$this->add('member_srl', $args->member_srl);
413
		if($config->redirect_url) $this->add('redirect_url', $config->redirect_url);
414
		if($config->enable_confirm == 'Y')
415
		{
416
			$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $args->email_address);
417
			$this->setMessage($msg);
418
			return $this->setRedirectUrl(getUrl('', 'act', 'dispMemberLoginForm'), new Object(-12, $msg));
419
		}
420
		else $this->setMessage('success_registed');
421
		// Call a trigger (after)
422
		$trigger_output = ModuleHandler::triggerCall('member.procMemberInsert', 'after', $config);
423
		if(!$trigger_output->toBool()) return $trigger_output;
424
425
		if($config->redirect_url)
426
		{
427
			$returnUrl = $config->redirect_url;
428
		}
429
		else
430
		{
431
			if(Context::get('success_return_url'))
432
			{
433
				$returnUrl = Context::get('success_return_url');
434
			}
435
			else if($_COOKIE['XE_REDIRECT_URL'])
436
			{
437
				$returnUrl = $_COOKIE['XE_REDIRECT_URL'];
438
				setcookie("XE_REDIRECT_URL", '', 1);
439
			}
440
		}
441
442
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
443
444
		$this->setRedirectUrl($returnUrl);
0 ignored issues
show
Bug introduced by
The variable $returnUrl does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
445
	}
446
447
	function procMemberModifyInfoBefore()
448
	{
449
		if($_SESSION['rechecked_password_step'] != 'INPUT_PASSWORD')
450
		{
451
			return $this->stop('msg_invalid_request');
452
		}
453
454
		if(!Context::get('is_logged'))
455
		{
456
			return $this->stop('msg_not_logged');
457
		}
458
459
		$password = Context::get('password');
460
461
		if(!$password)
462
		{
463
			return $this->stop('msg_invalid_request');
464
		}
465
466
		$oMemberModel = getModel('member');
467
468
		if(!$this->memberInfo->password)
469
		{
470
			// Get information of logged-in user
471
			$logged_info = Context::get('logged_info');
472
			$member_srl = $logged_info->member_srl;
473
474
			$columnList = array('member_srl', 'password');
475
			$memberInfo = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
476
			$this->memberInfo->password = $memberInfo->password;
477
		}
478
		// Verify the current password
479
		if(!$oMemberModel->isValidPassword($this->memberInfo->password, $password))
480
		{
481
			return new Object(-1, 'invalid_password');
482
		}
483
484
		$_SESSION['rechecked_password_step'] = 'VALIDATE_PASSWORD';
485
486
		if(Context::get('success_return_url'))
487
		{
488
			$redirectUrl = Context::get('success_return_url');
489
		}
490
		else
491
		{
492
			$redirectUrl = getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
493
		}
494
		$this->setRedirectUrl($redirectUrl);
495
	}
496
497
	/**
498
	 * Edit member profile
499
	 *
500
	 * @return void|Object (void : success, Object : fail)
501
	 */
502
	function procMemberModifyInfo()
503
	{
504
		if(!Context::get('is_logged'))
505
		{
506
			return $this->stop('msg_not_logged');
507
		}
508
509
		if($_SESSION['rechecked_password_step'] != 'INPUT_DATA')
510
		{
511
			return $this->stop('msg_invalid_request');
512
		}
513
		unset($_SESSION['rechecked_password_step']);
514
515
		// Extract the necessary information in advance
516
		$oMemberModel = getModel('member');
517
		$config = $oMemberModel->getMemberConfig ();
518
		$getVars = array('find_account_answer','allow_mailing','allow_message');
519 View Code Duplication
		if($config->signupForm)
520
		{
521
			foreach($config->signupForm as $formInfo)
522
			{
523
				if($formInfo->isDefaultForm && ($formInfo->isUse || $formInfo->required || $formInfo->mustRequired))
524
				{
525
					$getVars[] = $formInfo->name;
526
				}
527
			}
528
		}
529
530
		$args = new stdClass;
531 View Code Duplication
		foreach($getVars as $val)
532
		{
533
			$args->{$val} = Context::get($val);
534
			if($val == 'birthday') $args->birthday_ui = Context::get('birthday_ui');
535
		}
536
		// Login Information
537
		$logged_info = Context::get('logged_info');
538
		$args->member_srl = $logged_info->member_srl;
539
		$args->birthday = intval(strtr($args->birthday, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
540 View Code Duplication
		if(!$args->birthday && $args->birthday_ui) $args->birthday = intval(strtr($args->birthday_ui, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
541
		// Remove some unnecessary variables from all the vars
542
		$all_args = Context::getRequestVars();
543
		unset($all_args->module);
544
		unset($all_args->act);
545
		unset($all_args->member_srl);
546
		unset($all_args->is_admin);
547
		unset($all_args->description);
548
		unset($all_args->group_srl_list);
549
		unset($all_args->body);
550
		unset($all_args->accept_agreement);
551
		unset($all_args->signature);
552
		unset($all_args->_filter);
553
		unset($all_args->mid);
554
		unset($all_args->error_return_url);
555
		unset($all_args->ruleset);
556
		unset($all_args->password);
557
558
		// Add extra vars after excluding necessary information from all the requested arguments
559
		$extra_vars = delObjectVars($all_args, $args);
560
		$args->extra_vars = serialize($extra_vars);
561
562
		// remove whitespace
563
		$checkInfos = array('user_id', 'user_name', 'nick_name', 'email_address');
564 View Code Duplication
		foreach($checkInfos as $val)
565
		{
566
			if(isset($args->{$val}))
567
			{
568
				$args->{$val} = preg_replace('/[\pZ\pC]+/u', '', $args->{$val});
569
			}
570
		}
571
572
		// Execute insert or update depending on the value of member_srl
573
		$output = $this->updateMember($args);
574
		if(!$output->toBool()) return $output;
575
576
		$profile_image = $_FILES['profile_image'];
577
		if(is_uploaded_file($profile_image['tmp_name']))
578
		{
579
			$this->insertProfileImage($args->member_srl, $profile_image['tmp_name']);
580
		}
581
582
		$image_mark = $_FILES['image_mark'];
583
		if(is_uploaded_file($image_mark['tmp_name']))
584
		{
585
			$this->insertImageMark($args->member_srl, $image_mark['tmp_name']);
586
		}
587
588
		$image_name = $_FILES['image_name'];
589
		if(is_uploaded_file($image_name['tmp_name']))
590
		{
591
			$this->insertImageName($args->member_srl, $image_name['tmp_name']);
592
		}
593
594
		// Save Signature
595
		$signature = Context::get('signature');
596
		$this->putSignature($args->member_srl, $signature);
597
598
		// Get user_id information
599
		$this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($args->member_srl);
600
601
602
		// Call a trigger after successfully log-in (after)
603
		$trigger_output = ModuleHandler::triggerCall('member.procMemberModifyInfo', 'after', $this->memberInfo);
604
		if(!$trigger_output->toBool()) return $trigger_output;
605
606
		$this->setSessionInfo();
607
		// Return result
608
		$this->add('member_srl', $args->member_srl);
609
		$this->setMessage('success_updated');
610
611
		$site_module_info = Context::get('site_module_info');
612
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
613
614
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberInfo');
615
		$this->setRedirectUrl($returnUrl);
616
	}
617
618
	/**
619
	 * Change the user password
620
	 *
621
	 * @return void|Object (void : success, Object : fail)
622
	 */
623
	function procMemberModifyPassword()
624
	{
625
		if(!Context::get('is_logged')) return $this->stop('msg_not_logged');
626
		// Extract the necessary information in advance
627
		$current_password = trim(Context::get('current_password'));
628
		$password = trim(Context::get('password1'));
629
		// Get information of logged-in user
630
		$logged_info = Context::get('logged_info');
631
		$member_srl = $logged_info->member_srl;
632
		// Create a member model object
633
		$oMemberModel = getModel('member');
634
		// Get information of member_srl
635
		$columnList = array('member_srl', 'password');
636
637
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
638
		// Verify the cuttent password
639
		if(!$oMemberModel->isValidPassword($member_info->password, $current_password, $member_srl)) return new Object(-1, 'invalid_password');
640
641
		// Check if a new password is as same as the previous password
642
		if($current_password == $password) return new Object(-1, 'invalid_new_password');
643
644
		// Execute insert or update depending on the value of member_srl
645
		$args = new stdClass;
646
		$args->member_srl = $member_srl;
647
		$args->password = $password;
648
		$output = $this->updateMemberPassword($args);
649
		if(!$output->toBool()) return $output;
650
651
		$this->add('member_srl', $args->member_srl);
652
		$this->setMessage('success_updated');
653
654
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberInfo');
655
		$this->setRedirectUrl($returnUrl);
656
	}
657
658
	/**
659
	 * Membership withdrawal
660
	 *
661
	 * @return void|Object (void : success, Object : fail)
662
	 */
663
	function procMemberLeave()
664
	{
665
		if(!Context::get('is_logged')) return $this->stop('msg_not_logged');
666
		// Extract the necessary information in advance
667
		$password = trim(Context::get('password'));
668
		// Get information of logged-in user
669
		$logged_info = Context::get('logged_info');
670
		$member_srl = $logged_info->member_srl;
671
		// Create a member model object
672
		$oMemberModel = getModel('member');
673
		// Get information of member_srl
674
		if(!$this->memberInfo->password)
675
		{
676
			$columnList = array('member_srl', 'password');
677
			$memberInfo = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
678
			$this->memberInfo->password = $memberInfo->password;
679
		}
680
		// Verify the cuttent password
681
		if(!$oMemberModel->isValidPassword($this->memberInfo->password, $password)) return new Object(-1, 'invalid_password');
682
683
		$output = $this->deleteMember($member_srl);
684
		if(!$output->toBool()) return $output;
685
		// Destroy all session information
686
		$this->destroySessionInfo();
687
		// Return success message
688
		$this->setMessage('success_leaved');
689
690
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
691
		$this->setRedirectUrl($returnUrl);
692
	}
693
694
	/**
695
	 * Add a profile image
696
	 *
697
	 * @return void|Object (void : success, Object : fail)
698
	 */
699 View Code Duplication
	function procMemberInsertProfileImage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
700
	{
701
		// Check if the file is successfully uploaded
702
		$file = $_FILES['profile_image'];
703
		if(!is_uploaded_file($file['tmp_name'])) return $this->stop('msg_not_uploaded_profile_image');
704
		// Ignore if member_srl is invalid or doesn't exist.
705
		$member_srl = Context::get('member_srl');
706
		if(!$member_srl) return $this->stop('msg_not_uploaded_profile_image');
707
708
		$logged_info = Context::get('logged_info');
709
		if($logged_info->is_admin != 'Y' && $logged_info->member_srl != $member_srl) return $this->stop('msg_not_uploaded_profile_image');
710
		// Return if member module is set not to use an image name or the user is not an administrator ;
711
		$oModuleModel = getModel('module');
712
		$config = $oModuleModel->getModuleConfig('member');
713
		if($logged_info->is_admin != 'Y' && $config->profile_image != 'Y') return $this->stop('msg_not_uploaded_profile_image');
714
715
		$this->insertProfileImage($member_srl, $file['tmp_name']);
716
		// Page refresh
717
		//$this->setRefreshPage();
718
719
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
720
		$this->setRedirectUrl($returnUrl);
721
	}
722
723
	/**
724
	 * Insert a profile image
725
	 *
726
	 * @param int $member_srl
727
	 * @param object $target_file
728
	 *
729
	 * @return void
730
	 */
731
	function insertProfileImage($member_srl, $target_file)
732
	{
733
734
		// Check uploaded file
735
		if(!checkUploadedFile($target_file)) return;
0 ignored issues
show
Documentation introduced by
$target_file is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
736
737
		$oMemberModel = getModel('member');
738
		$config = $oMemberModel->getMemberConfig();
739
740
		// Get an image size
741
		$max_width = $config->profile_image_max_width;
742
		if(!$max_width) $max_width = "90";
743
		$max_height = $config->profile_image_max_height;
744
		if(!$max_height) $max_height = "90";
745
		// Get a target path to save
746
		$target_path = sprintf('files/member_extra_info/profile_image/%s', getNumberingPath($member_srl));
747
		FileHandler::makeDir($target_path);
748
749
		// Get file information
750
		list($width, $height, $type, $attrs) = @getimagesize($target_file);
0 ignored issues
show
Unused Code introduced by
The assignment to $attrs is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
751
		if(IMAGETYPE_PNG == $type) $ext = 'png';
752
		elseif(IMAGETYPE_JPEG == $type) $ext = 'jpg';
753
		elseif(IMAGETYPE_GIF == $type) $ext = 'gif';
754
		else
755
		{
756
			return;
757
		}
758
759
		FileHandler::removeFilesInDir($target_path);
760
761
		$target_filename = sprintf('%s%d.%s', $target_path, $member_srl, $ext);
762
		// Convert if the image size is larger than a given size or if the format is not a gif
763
		if(($width > $max_width || $height > $max_height ) && $type != 1)
764
		{
765
			FileHandler::createImageFile($target_file, $target_filename, $max_width, $max_height, $ext);
0 ignored issues
show
Documentation introduced by
$target_file is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
766
		}
767
		else
768
		{
769
			@copy($target_file, $target_filename);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
770
		}
771
	}
772
773
	/**
774
	 * Add an image name
775
	 *
776
	 * @return void|Object (void : success, Object : fail)
777
	 */
778 View Code Duplication
	function procMemberInsertImageName()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
779
	{
780
		// Check if the file is successfully uploaded
781
		$file = $_FILES['image_name'];
782
		if(!is_uploaded_file($file['tmp_name'])) return $this->stop('msg_not_uploaded_image_name');
783
		// Ignore if member_srl is invalid or doesn't exist.
784
		$member_srl = Context::get('member_srl');
785
		if(!$member_srl) return $this->stop('msg_not_uploaded_image_name');
786
787
		$logged_info = Context::get('logged_info');
788
		if($logged_info->is_admin != 'Y' && $logged_info->member_srl != $member_srl) return $this->stop('msg_not_uploaded_image_name');
789
		// Return if member module is set not to use an image name or the user is not an administrator ;
790
		$oModuleModel = getModel('module');
791
		$config = $oModuleModel->getModuleConfig('member');
792
		if($logged_info->is_admin != 'Y' && $config->image_name != 'Y') return $this->stop('msg_not_uploaded_image_name');
793
794
		$this->insertImageName($member_srl, $file['tmp_name']);
795
		// Page refresh
796
		//$this->setRefreshPage();
797
798
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
799
		$this->setRedirectUrl($returnUrl);
800
	}
801
802
	/**
803
	 * Insert a image name
804
	 *
805
	 * @param int $member_srl
806
	 * @param object $target_file
807
	 *
808
	 * @return void
809
	 */
810 View Code Duplication
	function insertImageName($member_srl, $target_file)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
811
	{
812
		// Check uploaded file
813
		if(!checkUploadedFile($target_file)) return;
0 ignored issues
show
Documentation introduced by
$target_file is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
814
815
		$oModuleModel = getModel('module');
816
		$config = $oModuleModel->getModuleConfig('member');
817
		// Get an image size
818
		$max_width = $config->image_name_max_width;
819
		if(!$max_width) $max_width = "90";
820
		$max_height = $config->image_name_max_height;
821
		if(!$max_height) $max_height = "20";
822
		// Get a target path to save
823
		$target_path = sprintf('files/member_extra_info/image_name/%s/', getNumberingPath($member_srl));
824
		FileHandler::makeDir($target_path);
825
826
		$target_filename = sprintf('%s%d.gif', $target_path, $member_srl);
827
		// Get file information
828
		list($width, $height, $type, $attrs) = @getimagesize($target_file);
0 ignored issues
show
Unused Code introduced by
The assignment to $attrs is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
829
		// Convert if the image size is larger than a given size or if the format is not a gif
830
		if($width > $max_width || $height > $max_height || $type!=1) FileHandler::createImageFile($target_file, $target_filename, $max_width, $max_height, 'gif');
0 ignored issues
show
Documentation introduced by
$target_file is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
831
		else @copy($target_file, $target_filename);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
832
	}
833
834
	/**
835
	 * Delete profile image
836
	 *
837
	 * @return Object
838
	 */
839 View Code Duplication
	function procMemberDeleteProfileImage($_memberSrl = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
840
	{
841
		$member_srl = ($_memberSrl) ? $_memberSrl : Context::get('member_srl');
842
		if(!$member_srl)
843
		{
844
			return new Object(0,'success');
845
		}
846
847
		$logged_info = Context::get('logged_info');
848
849
		if($logged_info && ($logged_info->is_admin == 'Y' || $logged_info->member_srl == $member_srl))
850
		{
851
			$oMemberModel = getModel('member');
852
			$profile_image = $oMemberModel->getProfileImage($member_srl);
853
			FileHandler::removeFile($profile_image->file);
854
		}
855
		return new Object(0,'success');
856
	}
857
858
	/**
859
	 * Delete Image name
860
	 *
861
	 * @return void
862
	 */
863 View Code Duplication
	function procMemberDeleteImageName($_memberSrl = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
864
	{
865
		$member_srl = ($_memberSrl) ? $_memberSrl : Context::get('member_srl');
866
		if(!$member_srl)
867
		{
868
			return new Object(0,'success');
869
		}
870
871
		$logged_info = Context::get('logged_info');
872
873
		if($logged_info && ($logged_info->is_admin == 'Y' || $logged_info->member_srl == $member_srl))
874
		{
875
			$oMemberModel = getModel('member');
876
			$image_name = $oMemberModel->getImageName($member_srl);
877
			FileHandler::removeFile($image_name->file);
878
		}
879
		return new Object(0,'success');
880
	}
881
882
	/**
883
	 * Add an image to mark
884
	 *
885
	 * @return void|Object (void : success, Object : fail)
886
	 */
887 View Code Duplication
	function procMemberInsertImageMark()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
888
	{
889
		// Check if the file is successfully uploaded
890
		$file = $_FILES['image_mark'];
891
		if(!is_uploaded_file($file['tmp_name'])) return $this->stop('msg_not_uploaded_image_mark');
892
		// Ignore if member_srl is invalid or doesn't exist.
893
		$member_srl = Context::get('member_srl');
894
		if(!$member_srl) return $this->stop('msg_not_uploaded_image_mark');
895
896
		$logged_info = Context::get('logged_info');
897
		if($logged_info->is_admin != 'Y' && $logged_info->member_srl != $member_srl) return $this->stop('msg_not_uploaded_image_mark');
898
		// Membership in the images mark the module using the ban was set by an administrator or return;
899
		$oModuleModel = getModel('module');
900
		$config = $oModuleModel->getModuleConfig('member');
901
		if($logged_info->is_admin != 'Y' && $config->image_mark != 'Y') return $this->stop('msg_not_uploaded_image_mark');
902
903
		$this->insertImageMark($member_srl, $file['tmp_name']);
904
		// Page refresh
905
		//$this->setRefreshPage();
906
907
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
908
		$this->setRedirectUrl($returnUrl);
909
	}
910
911
	/**
912
	 * Insert a image mark
913
	 *
914
	 * @param int $member_srl
915
	 * @param object $target_file
916
	 *
917
	 * @return void
918
	 */
919 View Code Duplication
	function insertImageMark($member_srl, $target_file)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
920
	{
921
		// Check uploaded file
922
		if(!checkUploadedFile($target_file)) return;
0 ignored issues
show
Documentation introduced by
$target_file is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
923
924
		$oModuleModel = getModel('module');
925
		$config = $oModuleModel->getModuleConfig('member');
926
		// Get an image size
927
		$max_width = $config->image_mark_max_width;
928
		if(!$max_width) $max_width = "20";
929
		$max_height = $config->image_mark_max_height;
930
		if(!$max_height) $max_height = "20";
931
932
		$target_path = sprintf('files/member_extra_info/image_mark/%s/', getNumberingPath($member_srl));
933
		FileHandler::makeDir($target_path);
934
935
		$target_filename = sprintf('%s%d.gif', $target_path, $member_srl);
936
		// Get file information
937
		list($width, $height, $type, $attrs) = @getimagesize($target_file);
0 ignored issues
show
Unused Code introduced by
The assignment to $attrs is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
938
939
		if($width > $max_width || $height > $max_height || $type!=1) FileHandler::createImageFile($target_file, $target_filename, $max_width, $max_height, 'gif');
0 ignored issues
show
Documentation introduced by
$target_file is of type object, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
940
		else @copy($target_file, $target_filename);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
941
	}
942
943
	/**
944
	 * Delete Image Mark
945
	 *
946
	 * @return Object
947
	 */
948 View Code Duplication
	function procMemberDeleteImageMark($_memberSrl = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
949
	{
950
		$member_srl = ($_memberSrl) ? $_memberSrl : Context::get('member_srl');
951
		if(!$member_srl)
952
		{
953
			return new Object(0,'success');
954
		}
955
956
		$logged_info = Context::get('logged_info');
957
958
		if($logged_info && ($logged_info->is_admin == 'Y' || $logged_info->member_srl == $member_srl))
959
		{
960
			$oMemberModel = getModel('member');
961
			$image_mark = $oMemberModel->getImageMark($member_srl);
962
			FileHandler::removeFile($image_mark->file);
963
		}
964
		return new Object(0,'success');
965
	}
966
967
	/**
968
	 * Find ID/Password
969
	 *
970
	 * @return Object
971
	 */
972
	function procMemberFindAccount()
973
	{
974
		$email_address = Context::get('email_address');
975
		if(!$email_address) return new Object(-1, 'msg_invalid_request');
976
977
		$oMemberModel = getModel('member');
978
		$oModuleModel = getModel('module');
979
980
		// Check if a member having the same email address exists
981
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($email_address);
982
		if(!$member_srl) return new Object(-1, 'msg_email_not_exists');
983
984
		// Get information of the member
985
		$columnList = array('denied', 'member_srl', 'user_id', 'user_name', 'email_address', 'nick_name');
986
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
987
988
		// Check if possible to find member's ID and password
989
		if($member_info->denied == 'Y')
990
		{
991
			$chk_args = new stdClass;
992
			$chk_args->member_srl = $member_info->member_srl;
993
			$output = executeQuery('member.chkAuthMail', $chk_args);
994
			if($output->toBool() && $output->data->count != '0') return new Object(-1, 'msg_user_not_confirmed');
995
		}
996
997
		// Insert data into the authentication DB
998
		$oPassword = new Password();
999
		$args = new stdClass();
1000
		$args->user_id = $member_info->user_id;
1001
		$args->member_srl = $member_info->member_srl;
1002
		$args->new_password = $oPassword->createTemporaryPassword(8);
1003
		$args->auth_key = $oPassword->createSecureSalt(40);
1004
		$args->is_register = 'N';
1005
1006
		$output = executeQuery('member.insertAuthMail', $args);
1007
		if(!$output->toBool()) return $output;
1008
		// Get content of the email to send a member
1009
		Context::set('auth_args', $args);
0 ignored issues
show
Documentation introduced by
$args is of type object<stdClass>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1010
1011
		$member_config = $oModuleModel->getModuleConfig('member');
1012
		$memberInfo = array();
1013
		global $lang;
1014 View Code Duplication
		if(is_array($member_config->signupForm))
1015
		{
1016
			$exceptForm=array('password', 'find_account_question');
1017
			foreach($member_config->signupForm as $form)
1018
			{
1019
				if(!in_array($form->name, $exceptForm) && $form->isDefaultForm && ($form->required || $form->mustRequired))
1020
				{
1021
					$memberInfo[$lang->{$form->name}] = $member_info->{$form->name};
1022
				}
1023
			}
1024
		}
1025
		else
1026
		{
1027
			$memberInfo[$lang->user_id] = $args->user_id;
1028
			$memberInfo[$lang->user_name] = $args->user_name;
1029
			$memberInfo[$lang->nick_name] = $args->nick_name;
1030
			$memberInfo[$lang->email_address] = $args->email_address;
1031
		}
1032
		Context::set('memberInfo', $memberInfo);
0 ignored issues
show
Documentation introduced by
$memberInfo is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1033
1034
		if(!$member_config->skin) $member_config->skin = "default";
1035
		if(!$member_config->colorset) $member_config->colorset = "white";
1036
1037
		Context::set('member_config', $member_config);
1038
1039
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
1040
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
1041
1042
		$find_url = getFullUrl ('', 'module', 'member', 'act', 'procMemberAuthAccount', 'member_srl', $member_info->member_srl, 'auth_key', $args->auth_key);
1043
		Context::set('find_url', $find_url);
1044
1045
		$oTemplate = &TemplateHandler::getInstance();
1046
		$content = $oTemplate->compile($tpl_path, 'find_member_account_mail');
1047
		// Get information of the Webmaster
1048
		$oModuleModel = getModel('module');
1049
		$member_config = $oModuleModel->getModuleConfig('member');
1050
		// Send a mail
1051
		$oMail = new Mail();
1052
		$oMail->setTitle( Context::getLang('msg_find_account_title') );
1053
		$oMail->setContent($content);
1054
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
1055
		$oMail->setReceiptor( $member_info->user_name, $member_info->email_address );
1056
		$oMail->send();
1057
		// Return message
1058
		$msg = sprintf(Context::getLang('msg_auth_mail_sent'), $member_info->email_address);
1059 View Code Duplication
		if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON')))
1060
		{
1061
			$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberFindAccount');
1062
			$this->setRedirectUrl($returnUrl);
1063
		}
1064
		return new Object(0,$msg);
1065
	}
1066
1067
	/**
1068
	 * Generate a temp password by answering to the pre-determined question
1069
	 *
1070
	 * @return void|Object (void : success, Object : fail)
1071
	 */
1072
	function procMemberFindAccountByQuestion()
1073
	{
1074
		$oMemberModel = getModel('member');
1075
		$config = $oMemberModel->getMemberConfig();
1076
1077
		$email_address = Context::get('email_address');
1078
		$user_id = Context::get('user_id');
1079
		$find_account_question = trim(Context::get('find_account_question'));
1080
		$find_account_answer = trim(Context::get('find_account_answer'));
1081
1082
		if(($config->identifier == 'user_id' && !$user_id) || !$email_address || !$find_account_question || !$find_account_answer) return new Object(-1, 'msg_invalid_request');
1083
1084
		$oModuleModel = getModel('module');
0 ignored issues
show
Unused Code introduced by
$oModuleModel is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1085
		// Check if a member having the same email address exists
1086
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($email_address);
1087
		if(!$member_srl) return new Object(-1, 'msg_email_not_exists');
1088
		// Get information of the member
1089
		$columnList = array('member_srl', 'find_account_question', 'find_account_answer');
1090
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
1091
1092
		// Display a message if no answer is entered
1093
		if(!$member_info->find_account_question || !$member_info->find_account_answer) return new Object(-1, 'msg_question_not_exists');
1094
1095
		if(trim($member_info->find_account_question) != $find_account_question || trim($member_info->find_account_answer) != $find_account_answer) return new Object(-1, 'msg_answer_not_matches');
1096
1097
		if($config->identifier == 'email_address')
1098
		{
1099
			$user_id = $email_address;
1100
		}
1101
1102
		// Update to a temporary password and set change_password_date to 1
1103
		$oPassword =  new Password();
1104
		$temp_password = $oPassword->createTemporaryPassword(8);
1105
1106
		$args = new stdClass();
1107
		$args->member_srl = $member_srl;
1108
		$args->password = $temp_password;
1109
		$args->change_password_date = '1';
1110
		$output = $this->updateMemberPassword($args);
1111
		if(!$output->toBool()) return $output;
1112
1113
		$_SESSION['xe_temp_password_' . $user_id] = $temp_password;
1114
1115
		$this->add('user_id',$user_id);
1116
1117
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
1118
		$this->setRedirectUrl($returnUrl.'&user_id='.$user_id);
1119
	}
1120
1121
	/**
1122
	 * Execute finding ID/Passoword
1123
	 * When clicking the link in the verification email, a method is called to change the old password and to authenticate it
1124
	 *
1125
	 * @return void|Object (void : success, Object : fail)
1126
	 */
1127
	function procMemberAuthAccount()
1128
	{
1129
		$oMemberModel = getModel('member');
1130
1131
		// Test user_id and authkey
1132
		$member_srl = Context::get('member_srl');
1133
		$auth_key = Context::get('auth_key');
1134
1135
		if(!$member_srl || !$auth_key)
1136
		{
1137
			return $this->stop('msg_invalid_request');
1138
		}
1139
1140
		// Test logs for finding password by user_id and authkey
1141
		$args = new stdClass;
1142
		$args->member_srl = $member_srl;
1143
		$args->auth_key = $auth_key;
1144
		$output = executeQuery('member.getAuthMail', $args);
1145
1146 View Code Duplication
		if(!$output->toBool() || $output->data->auth_key != $auth_key)
1147
		{
1148
			if(strlen($output->data->auth_key) !== strlen($auth_key))
1149
			{
1150
				executeQuery('member.deleteAuthMail', $args);
1151
			}
1152
1153
			return $this->stop('msg_invalid_auth_key');
1154
		}
1155
1156
		if(ztime($output->data->regdate) < $_SERVER['REQUEST_TIME'] + zgap() - 86400)
1157
		{
1158
			executeQuery('member.deleteAuthMail', $args);
1159
			return $this->stop('msg_invalid_auth_key');
1160
		}
1161
1162
		$args->password = $output->data->new_password;
1163
1164
		// If credentials are correct, change the password to a new one
1165
		if($output->data->is_register == 'Y')
1166
		{
1167
			$args->denied = 'N';
1168
		}
1169
		else
1170
		{
1171
			$args->password = $oMemberModel->hashPassword($args->password);
1172
		}
1173
1174
		// Back up the value of $Output->data->is_register
1175
		$is_register = $output->data->is_register;
1176
1177
		$output = executeQuery('member.updateMemberPassword', $args);
1178
		if(!$output->toBool())
1179
		{
1180
			return $this->stop($output->getMessage());
1181
		}
1182
1183
		// Remove all values having the member_srl from authentication table
1184
		executeQuery('member.deleteAuthMail',$args);
1185
1186
		$this->_clearMemberCache($args->member_srl);
1187
1188
		// Notify the result
1189
		Context::set('is_register', $is_register);
1190
		$this->setTemplatePath($this->module_path.'tpl');
1191
		$this->setTemplateFile('msg_success_authed');
1192
	}
1193
1194
	/**
1195
	 * Request to re-send the authentication mail
1196
	 *
1197
	 * @return void|Object (void : success, Object : fail)
1198
	 */
1199
	function procMemberResendAuthMail()
1200
	{
1201
		// Get an email_address
1202
		$email_address = Context::get('email_address');
1203
		if(!$email_address) return new Object(-1, 'msg_invalid_request');
1204
		// Log test by using email_address
1205
		$oMemberModel = getModel('member');
1206
1207
		$args = new stdClass;
1208
		$args->email_address = $email_address;
1209
		$memberSrl = $oMemberModel->getMemberSrlByEmailAddress($email_address);
1210
		if(!$memberSrl) return new Object(-1, 'msg_not_exists_member');
1211
1212
		$columnList = array('member_srl', 'user_id', 'user_name', 'nick_name', 'email_address');
1213
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($memberSrl, 0, $columnList);
1214
1215
		$oModuleModel = getModel('module');
1216
		$member_config = $oModuleModel->getModuleConfig('member');
1217
		if(!$member_config->skin) $member_config->skin = "default";
1218
		if(!$member_config->colorset) $member_config->colorset = "white";
1219
1220
		// Check if a authentication mail has been sent previously
1221
		$chk_args = new stdClass;
1222
		$chk_args->member_srl = $member_info->member_srl;
1223
		$output = executeQuery('member.chkAuthMail', $chk_args);
1224
		if($output->toBool() && $output->data->count == '0') return new Object(-1, 'msg_invalid_request');
1225
1226
		$auth_args = new stdClass;
1227
		$auth_args->member_srl = $member_info->member_srl;
1228
		$output = executeQueryArray('member.getAuthMailInfo', $auth_args);
1229
		if(!$output->data || !$output->data[0]->auth_key)  return new Object(-1, 'msg_invalid_request');
1230
		$auth_info = $output->data[0];
1231
1232
		// Update the regdate of authmail entry
1233
		$renewal_args = new stdClass;
1234
		$renewal_args->member_srl = $member_info->member_srl;
1235
		$renewal_args->auth_key = $auth_info->auth_key;
1236
		$output = executeQuery('member.updateAuthMail', $renewal_args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1237
1238
		$memberInfo = array();
1239
		global $lang;
1240 View Code Duplication
		if(is_array($member_config->signupForm))
1241
		{
1242
			$exceptForm=array('password', 'find_account_question');
1243
			foreach($member_config->signupForm as $form)
1244
			{
1245
				if(!in_array($form->name, $exceptForm) && $form->isDefaultForm && ($form->required || $form->mustRequired))
1246
				{
1247
					$memberInfo[$lang->{$form->name}] = $member_info->{$form->name};
1248
				}
1249
			}
1250
		}
1251
		else
1252
		{
1253
			$memberInfo[$lang->user_id] = $member_info->user_id;
1254
			$memberInfo[$lang->user_name] = $member_info->user_name;
1255
			$memberInfo[$lang->nick_name] = $member_info->nick_name;
1256
			$memberInfo[$lang->email_address] = $member_info->email_address;
1257
		}
1258
1259
		// Get content of the email to send a member
1260
		Context::set('memberInfo', $memberInfo);
0 ignored issues
show
Documentation introduced by
$memberInfo is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1261
		Context::set('member_config', $member_config);
1262
1263
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
1264
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
1265
1266
		$auth_url = getFullUrl('','module','member','act','procMemberAuthAccount','member_srl',$member_info->member_srl, 'auth_key',$auth_info->auth_key);
1267
		Context::set('auth_url', $auth_url);
1268
1269
		$oTemplate = &TemplateHandler::getInstance();
1270
		$content = $oTemplate->compile($tpl_path, 'confirm_member_account_mail');
1271
		// Send a mail
1272
		$oMail = new Mail();
1273
		$oMail->setTitle( Context::getLang('msg_confirm_account_title') );
1274
		$oMail->setContent($content);
1275
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
1276
		$oMail->setReceiptor( $args->user_name, $args->email_address );
1277
		$oMail->send();
1278
1279
		$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $args->email_address);
1280
		$this->setMessage($msg);
1281
1282
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
1283
		$this->setRedirectUrl($returnUrl);
1284
	}
1285
1286
	function procMemberResetAuthMail()
1287
	{
1288
		$memberInfo = $_SESSION['auth_member_info'];
1289
		unset($_SESSION['auth_member_info']);
1290
1291
		if(!$memberInfo)
1292
		{
1293
			return $this->stop('msg_invalid_request');
1294
		}
1295
1296
		$newEmail = Context::get('email_address');
1297
1298
		if(!$newEmail)
1299
		{
1300
			return $this->stop('msg_invalid_request');
1301
		}
1302
1303
		$oMemberModel = getModel('member');
1304
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($newEmail);
1305
		if($member_srl)
1306
		{
1307
			return new Object(-1,'msg_exists_email_address');
1308
		}
1309
1310
		// remove all key by member_srl
1311
		$args = new stdClass;
1312
		$args->member_srl = $memberInfo->member_srl;
1313
		$output = executeQuery('member.deleteAuthMail', $args);
1314
1315
		if(!$output->toBool())
1316
		{
1317
			return $output;
1318
		}
1319
1320
		// update member info
1321
		$args->email_address = $newEmail;
1322
		list($args->email_id, $args->email_host) = explode('@', $newEmail);
1323
1324
		$output = executeQuery('member.updateMemberEmailAddress', $args);
1325
		if(!$output->toBool())
1326
		{
1327
			return $this->stop($output->getMessage());
1328
		}
1329
1330
		$this->_clearMemberCache($args->member_srl);
1331
1332
		// generate new auth key
1333
		$oPassword = new Password();
1334
		$auth_args = new stdClass();
1335
		$auth_args->user_id = $memberInfo->user_id;
1336
		$auth_args->member_srl = $memberInfo->member_srl;
1337
		$auth_args->new_password = $memberInfo->password;
1338
		$auth_args->auth_key = $oPassword->createSecureSalt(40);
1339
		$auth_args->is_register = 'Y';
1340
1341
		$output = executeQuery('member.insertAuthMail', $auth_args);
1342
		if(!$output->toBool()) return $output;
1343
1344
		$memberInfo->email_address = $newEmail;
1345
1346
		// resend auth mail.
1347
		$this->_sendAuthMail($auth_args, $memberInfo);
1348
1349
		$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $memberInfo->email_address);
1350
		$this->setMessage($msg);
1351
1352
		$returnUrl = getUrl('');
1353
		$this->setRedirectUrl($returnUrl);
1354
	}
1355
1356
	function _sendAuthMail($auth_args, $member_info)
1357
	{
1358
		$oMemberModel = getModel('member');
1359
		$member_config = $oMemberModel->getMemberConfig();
1360
		// Get content of the email to send a member
1361
		Context::set('auth_args', $auth_args);
1362
1363
		$memberInfo = array();
1364
1365
		global $lang;
1366 View Code Duplication
		if(is_array($member_config->signupForm))
1367
		{
1368
			$exceptForm=array('password', 'find_account_question');
1369
			foreach($member_config->signupForm as $form)
1370
			{
1371
				if(!in_array($form->name, $exceptForm) && $form->isDefaultForm && ($form->required || $form->mustRequired))
1372
				{
1373
					$memberInfo[$lang->{$form->name}] = $member_info->{$form->name};
1374
				}
1375
			}
1376
		}
1377
		else
1378
		{
1379
			$memberInfo[$lang->user_id] = $member_info->user_id;
1380
			$memberInfo[$lang->user_name] = $member_info->user_name;
1381
			$memberInfo[$lang->nick_name] = $member_info->nick_name;
1382
			$memberInfo[$lang->email_address] = $member_info->email_address;
1383
		}
1384
		Context::set('memberInfo', $memberInfo);
0 ignored issues
show
Documentation introduced by
$memberInfo is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1385
1386
		if(!$member_config->skin) $member_config->skin = "default";
1387
		if(!$member_config->colorset) $member_config->colorset = "white";
1388
1389
		Context::set('member_config', $member_config);
1390
1391
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
1392
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
1393
1394
		$auth_url = getFullUrl('','module','member','act','procMemberAuthAccount','member_srl',$member_info->member_srl, 'auth_key',$auth_args->auth_key);
1395
		Context::set('auth_url', $auth_url);
1396
1397
		$oTemplate = &TemplateHandler::getInstance();
1398
		$content = $oTemplate->compile($tpl_path, 'confirm_member_account_mail');
1399
		// Send a mail
1400
		$oMail = new Mail();
1401
		$oMail->setTitle( Context::getLang('msg_confirm_account_title') );
1402
		$oMail->setContent($content);
1403
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
1404
		$oMail->setReceiptor( $member_info->user_name, $member_info->email_address );
1405
		$oMail->send();
1406
	}
1407
1408
	/**
1409
	 * Join a virtual site
1410
	 *
1411
	 * @return void|Object (void : success, Object : fail)
1412
	 */
1413
	function procMemberSiteSignUp()
1414
	{
1415
		$site_module_info = Context::get('site_module_info');
1416
		$logged_info = Context::get('logged_info');
1417 View Code Duplication
		if(!$site_module_info->site_srl || !Context::get('is_logged') || count($logged_info->group_srl_list) ) return new Object(-1,'msg_invalid_request');
1418
1419
		$oMemberModel = getModel('member');
1420
		$columnList = array('site_srl', 'group_srl', 'title');
1421
		$default_group = $oMemberModel->getDefaultGroup($site_module_info->site_srl, $columnList);
1422
		$this->addMemberToGroup($logged_info->member_srl, $default_group->group_srl, $site_module_info->site_srl);
1423
		$groups[$default_group->group_srl] = $default_group->title;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$groups was never initialized. Although not strictly required by PHP, it is generally a good practice to add $groups = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1424
		$logged_info->group_list = $groups;
1425
	}
1426
1427
	/**
1428
	 * Leave the virtual site
1429
	 *
1430
	 * @return void|Object (void : success, Object : fail)
1431
	 */
1432
	function procMemberSiteLeave()
1433
	{
1434
		$site_module_info = Context::get('site_module_info');
1435
		$logged_info = Context::get('logged_info');
1436 View Code Duplication
		if(!$site_module_info->site_srl || !Context::get('is_logged') || count($logged_info->group_srl_list) ) return new Object(-1,'msg_invalid_request');
1437
1438
		$args = new stdClass;
1439
		$args->site_srl= $site_module_info->site_srl;
1440
		$args->member_srl = $logged_info->member_srl;
1441
		$output = executeQuery('member.deleteMembersGroup', $args);
1442
		if(!$output->toBool()) return $output;
1443
		$this->setMessage('success_deleted');
1444
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
1445
	}
1446
1447
	/**
1448
	 * Save the member configurations
1449
	 *
1450
	 * @param object $args
1451
	 *
1452
	 * @return void
1453
	 */
1454
	function setMemberConfig($args)
1455
	{
1456
		if(!$args->skin) $args->skin = "default";
1457
		if(!$args->colorset) $args->colorset = "white";
1458
		if(!$args->editor_skin) $args->editor_skin= "ckeditor";
1459
		if(!$args->editor_colorset) $args->editor_colorset = "moono";
1460
		if($args->enable_join!='Y') $args->enable_join = 'N';
1461
		$args->enable_openid= 'N';
1462
		if($args->profile_image !='Y') $args->profile_image = 'N';
1463
		if($args->image_name!='Y') $args->image_name = 'N';
1464
		if($args->image_mark!='Y') $args->image_mark = 'N';
1465
		if($args->group_image_mark!='Y') $args->group_image_mark = 'N';
1466
		if(!trim(strip_tags($args->agreement))) $args->agreement = null;
1467
		$args->limit_day = (int)$args->limit_day;
1468
1469
		$agreement = trim($args->agreement);
1470
		unset($args->agreement);
1471
1472
		$oModuleController = getController('module');
1473
		$output = $oModuleController->insertModuleConfig('member',$args);
1474
		if(!$output->toBool()) return $output;
1475
1476
		$agreement_file = _XE_PATH_.'files/member_extra_info/agreement.txt';
1477
		FileHandler::writeFile($agreement_file, $agreement);
1478
1479
		return new Object();
1480
	}
1481
1482
	/**
1483
	 * Save the signature as a file
1484
	 *
1485
	 * @param int $member_srl
1486
	 * @param string $signature
1487
	 *
1488
	 * @return void
1489
	 */
1490
	function putSignature($member_srl, $signature)
1491
	{
1492
		$signature = trim(removeHackTag($signature));
1493
		$signature = preg_replace('/<(\/?)(embed|object|param)/is', '&lt;$1$2', $signature);
1494
1495
		$check_signature = trim(str_replace(array('&nbsp;',"\n","\r"), '', strip_tags($signature, '<img><object>')));
1496
		$path = sprintf('files/member_extra_info/signature/%s/', getNumberingPath($member_srl));
1497
		$filename = sprintf('%s%d.signature.php', $path, $member_srl);
1498
1499
		if(!$check_signature) return FileHandler::removeFile($filename);
1500
1501
		$buff = sprintf('<?php if(!defined("__XE__")) exit();?>%s', $signature);
1502
		FileHandler::makeDir($path);
1503
		FileHandler::writeFile($filename, $buff);
1504
	}
1505
1506
	/**
1507
	 * Delete the signature file
1508
	 *
1509
	 * @param string $member_srl
1510
	 *
1511
	 * @return void
1512
	 */
1513
	function delSignature($member_srl)
1514
	{
1515
		$filename = sprintf('files/member_extra_info/signature/%s%d.gif', getNumberingPath($member_srl), $member_srl);
1516
		FileHandler::removeFile($filename);
1517
	}
1518
1519
	/**
1520
	 * Add group_srl to member_srl
1521
	 *
1522
	 * @param int $member_srl
1523
	 * @param int $group_srl
1524
	 * @param int $site_srl
1525
	 *
1526
	 * @return Object
1527
	 */
1528
	function addMemberToGroup($member_srl, $group_srl, $site_srl=0)
1529
	{
1530
		$args = new stdClass();
1531
		$args->member_srl = $member_srl;
1532
		$args->group_srl = $group_srl;
1533
		if($site_srl) $args->site_srl = $site_srl;
1534
1535
		// Add
1536
		$output = executeQuery('member.addMemberToGroup',$args);
1537
		$output2 = ModuleHandler::triggerCall('member.addMemberToGroup', 'after', $args);
0 ignored issues
show
Unused Code introduced by
$output2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1538
1539
		$this->_clearMemberCache($member_srl, $site_srl);
1540
1541
		return $output;
1542
	}
1543
1544
	/**
1545
	 * Change a group of certain members
1546
	 * Available only when a member has a single group
1547
	 *
1548
	 * @param object $args
1549
	 *
1550
	 * @return Object
1551
	 */
1552
	function replaceMemberGroup($args)
1553
	{
1554
		$obj = new stdClass;
1555
		$obj->site_srl = $args->site_srl;
1556
		$obj->member_srl = implode(',',$args->member_srl);
1557
1558
		$output = executeQueryArray('member.getMembersGroup', $obj);
1559
		if($output->data) foreach($output->data as $key => $val) $date[$val->member_srl] = $val->regdate;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$date was never initialized. Although not strictly required by PHP, it is generally a good practice to add $date = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1560
1561
		$output = executeQuery('member.deleteMembersGroup', $obj);
1562
		if(!$output->toBool()) return $output;
1563
1564
		$inserted_members = array();
1565
		foreach($args->member_srl as $key => $val)
1566
		{
1567
			if($inserted_members[$val]) continue;
1568
			$inserted_members[$val] = true;
1569
1570
			unset($obj);
1571
			$obj = new stdClass;
1572
			$obj->member_srl = $val;
1573
			$obj->group_srl = $args->group_srl;
1574
			$obj->site_srl = $args->site_srl;
1575
			$obj->regdate = $date[$obj->member_srl];
0 ignored issues
show
Bug introduced by
The variable $date does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1576
			$output = executeQuery('member.addMemberToGroup', $obj);
1577
			if(!$output->toBool()) return $output;
1578
1579
			$this->_clearMemberCache($obj->member_srl, $args->site_srl);
1580
		}
1581
1582
		return new Object();
1583
	}
1584
1585
1586
	/**
1587
	 * Auto-login
1588
	 *
1589
	 * @return void
1590
	 */
1591
	function doAutologin()
1592
	{
1593
		// Get a key value of auto log-in
1594
		$args = new stdClass;
1595
		$args->autologin_key = $_COOKIE['xeak'];
1596
		// Get information of the key
1597
		$output = executeQuery('member.getAutologin', $args);
1598
		// If no information exists, delete a cookie
1599 View Code Duplication
		if(!$output->toBool() || !$output->data)
1600
		{
1601
			setCookie('xeak',null,$_SERVER['REQUEST_TIME']+60*60*24*365);
1602
			return;
1603
		}
1604
1605
		$oMemberModel = getModel('member');
1606
		$config = $oMemberModel->getMemberConfig();
1607
1608
		$user_id = ($config->identifier == 'user_id') ? $output->data->user_id : $output->data->email_address;
1609
		$password = $output->data->password;
1610
1611 View Code Duplication
		if(!$user_id || !$password)
1612
		{
1613
			setCookie('xeak',null,$_SERVER['REQUEST_TIME']+60*60*24*365);
1614
			return;
1615
		}
1616
1617
		$do_auto_login = false;
1618
1619
		// Compare key values based on the information
1620
		$check_key = strtolower($user_id).$password.$_SERVER['HTTP_USER_AGENT'];
1621
		$check_key = substr(hash_hmac('sha256', $check_key, substr($args->autologin_key, 0, 32)), 0, 32);
1622
1623
		if($check_key === substr($args->autologin_key, 32))
1624
		{
1625
			// Check change_password_date
1626
			$oModuleModel = getModel('module');
1627
			$member_config = $oModuleModel->getModuleConfig('member');
1628
			$limit_date = $member_config->change_password_date;
1629
1630
			// Check if change_password_date is set
1631
			if($limit_date > 0)
1632
			{
1633
				$oMemberModel = getModel('member');
1634
				$columnList = array('member_srl', 'change_password_date');
1635
1636
				if($config->identifier == 'user_id')
1637
				{
1638
					$member_info = $oMemberModel->getMemberInfoByUserID($user_id, $columnList);
1639
				}
1640
				else
1641
				{
1642
					$member_info = $oMemberModel->getMemberInfoByEmailAddress($user_id, $columnList);
1643
				}
1644
1645
				if($member_info->change_password_date >= date('YmdHis', strtotime('-'.$limit_date.' day')) ){
1646
					$do_auto_login = true;
1647
				}
1648
1649
			}
1650
			else
1651
			{
1652
				$do_auto_login = true;
1653
			}
1654
		}
1655
1656
		if($do_auto_login)
1657
		{
1658
			$output = $this->doLogin($user_id);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1659
		}
1660
		else
1661
		{
1662
			executeQuery('member.deleteAutologin', $args);
1663
			setCookie('xeak',null,$_SERVER['REQUEST_TIME']+60*60*24*365);
1664
		}
1665
	}
1666
1667
	/**
1668
	 * Log-in
1669
	 *
1670
	 * @param string $user_id
1671
	 * @param string $password
1672
	 * @param boolean $keep_signed
1673
	 *
1674
	 * @return Object
1675
	 */
1676
	function doLogin($user_id, $password = '', $keep_signed = false)
1677
	{
1678
		$user_id = strtolower($user_id);
1679
		if(!$user_id) return new Object(-1, 'null_user_id');
1680
		// Call a trigger before log-in (before)
1681
		$trigger_obj = new stdClass();
1682
		$trigger_obj->user_id = $user_id;
1683
		$trigger_obj->password = $password;
1684
		$trigger_output = ModuleHandler::triggerCall('member.doLogin', 'before', $trigger_obj);
1685
		if(!$trigger_output->toBool()) return $trigger_output;
1686
		// Create a member model object
1687
		$oMemberModel = getModel('member');
1688
1689
		// check IP access count.
1690
		$config = $oMemberModel->getMemberConfig();
1691
		$args = new stdClass();
1692
		$args->ipaddress = $_SERVER['REMOTE_ADDR'];
1693
1694
		// check identifier
1695
		if($config->identifier == 'email_address')
1696
		{
1697
			// Get user_id information
1698
			$this->memberInfo = $oMemberModel->getMemberInfoByEmailAddress($user_id);
1699
			// Set an invalid user if no value returned
1700
			if(!$user_id || strtolower($this->memberInfo->email_address) != strtolower($user_id)) return $this->recordLoginError(-1, 'invalid_email_address');
1701
1702
		}
1703
		else
1704
		{
1705
			// Get user_id information
1706
			$this->memberInfo = $oMemberModel->getMemberInfoByUserID($user_id);
1707
			// Set an invalid user if no value returned
1708
			if(!$user_id || strtolower($this->memberInfo->user_id) != strtolower($user_id)) return $this->recordLoginError(-1, 'invalid_user_id');
1709
		}
1710
1711
		$output = executeQuery('member.getLoginCountByIp', $args);
1712
		$errorCount = $output->data->count;
1713
		if($errorCount >= $config->max_error_count)
1714
		{
1715
			$last_update = strtotime($output->data->last_update);
1716
			$term = intval($_SERVER['REQUEST_TIME']-$last_update);
1717
			if($term < $config->max_error_count_time)
1718
			{
1719
				$term = $config->max_error_count_time - $term;
1720
				if($term < 60) $term = intval($term).Context::getLang('unit_sec');
1721
				elseif(60 <= $term && $term < 3600) $term = intval($term/60).Context::getLang('unit_min');
1722
				elseif(3600 <= $term && $term < 86400) $term = intval($term/3600).Context::getLang('unit_hour');
1723
				else $term = intval($term/86400).Context::getLang('unit_day');
1724
1725
				return new Object(-1, sprintf(Context::getLang('excess_ip_access_count'),$term));
1726
			}
1727
			else
1728
			{
1729
				$args->ipaddress = $_SERVER['REMOTE_ADDR'];
1730
				$output = executeQuery('member.deleteLoginCountByIp', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1731
			}
1732
		}
1733
1734
		// Password Check
1735
		if($password && !$oMemberModel->isValidPassword($this->memberInfo->password, $password, $this->memberInfo->member_srl))
1736
		{
1737
			return $this->recordMemberLoginError(-1, 'invalid_password',$this->memberInfo);
1738
		}
1739
1740
		// If denied == 'Y', notify
1741
		if($this->memberInfo->denied == 'Y')
1742
		{
1743
			$args->member_srl = $this->memberInfo->member_srl;
1744
			$output = executeQuery('member.chkAuthMail', $args);
1745
			if ($output->toBool() && $output->data->count != '0')
1746
			{
1747
				$_SESSION['auth_member_srl'] = $this->memberInfo->member_srl;
1748
				$redirectUrl = getUrl('', 'act', 'dispMemberResendAuthMail');
1749
				return $this->setRedirectUrl($redirectUrl, new Object(-1,'msg_user_not_confirmed'));
1750
			}
1751
			return new Object(-1,'msg_user_denied');
1752
		}
1753
		// Notify if denied_date is less than the current time
1754
		if($this->memberInfo->limit_date && substr($this->memberInfo->limit_date,0,8) >= date("Ymd")) return new Object(-9,sprintf(Context::getLang('msg_user_limited'),zdate($this->memberInfo->limit_date,"Y-m-d")));
1755
		// Update the latest login time
1756
		$args->member_srl = $this->memberInfo->member_srl;
1757
		$output = executeQuery('member.updateLastLogin', $args);
1758
1759
		$site_module_info = Context::get('site_module_info');
1760
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
1761
1762
		// Check if there is recoding table.
1763
		$oDB = &DB::getInstance();
1764
		if($oDB->isTableExists('member_count_history') && $config->enable_login_fail_report != 'N')
1765
		{
1766
			// check if there is login fail records.
1767
			$output = executeQuery('member.getLoginCountHistoryByMemberSrl', $args);
1768
			if($output->data && $output->data->content)
1769
			{
1770
				$title = Context::getLang('login_fail_report');
1771
				$message = '<ul>';
1772
				$content = unserialize($output->data->content);
1773
				if(count($content) > $config->max_error_count)
1774
				{
1775
					foreach($content as $val)
1776
					{
1777
						$message .= '<li>'.Context::getLang('regdate').': '.date('Y-m-d h:i:sa',$val[2]).'<ul><li>'.Context::getLang('ipaddress').': '.$val[0].'</li><li>'.Context::getLang('message').': '.$val[1].'</li></ul></li>';
1778
					}
1779
					$message .= '</ul>';
1780
					$content = sprintf(Context::getLang('login_fail_report_contents'),$message,date('Y-m-d h:i:sa'));
1781
1782
					//send message
1783
					$oCommunicationController = getController('communication');
1784
					$oCommunicationController->sendMessage($args->member_srl, $args->member_srl, $title, $content, true);
1785
1786
					if($this->memberInfo->email_address && $this->memberInfo->allow_mailing == 'Y')
1787
					{
1788
						$view_url = Context::getRequestUri();
1789
						$content = sprintf("%s<hr /><p>From: <a href=\"%s\" target=\"_blank\">%s</a><br />To: %s(%s)</p>",$content, $view_url, $view_url, $this->memberInfo->nick_name, $this->memberInfo->email_id);
1790
						$oMail = new Mail();
1791
						$oMail->setTitle($title);
1792
						$oMail->setContent($content);
1793
						$oMail->setSender($config->webmaster_name?$config->webmaster_name:'webmaster', $config->webmaster_email);
1794
						$oMail->setReceiptor($this->memberInfo->email_id.'('.$this->memberInfo->nick_name.')', $this->memberInfo->email_address);
1795
						$oMail->send();
1796
					}
1797
					$output = executeQuery('member.deleteLoginCountHistoryByMemberSrl', $args);
1798
				}
1799
			}
1800
		}
1801
		// Call a trigger after successfully log-in (after)
1802
		$trigger_output = ModuleHandler::triggerCall('member.doLogin', 'after', $this->memberInfo);
1803
		if(!$trigger_output->toBool()) return $trigger_output;
1804
		// When user checked to use auto-login
1805
		if($keep_signed)
1806
		{
1807
			// Key generate for auto login
1808
			$oPassword = new Password();
1809
			$random_key = $oPassword->createSecureSalt(32, 'hex');
1810
			$extra_key = strtolower($user_id).$this->memberInfo->password.$_SERVER['HTTP_USER_AGENT'];
1811
			$extra_key = substr(hash_hmac('sha256', $extra_key, $random_key), 0, 32);
1812
			$autologin_args = new stdClass;
1813
			$autologin_args->autologin_key = $random_key.$extra_key;
1814
			$autologin_args->member_srl = $this->memberInfo->member_srl;
1815
			executeQuery('member.deleteAutologin', $autologin_args);
1816
			$autologin_output = executeQuery('member.insertAutologin', $autologin_args);
1817
			if($autologin_output->toBool()) setCookie('xeak',$autologin_args->autologin_key, $_SERVER['REQUEST_TIME']+31536000);
1818
		}
1819
		if($this->memberInfo->is_admin == 'Y')
1820
		{
1821
			$oMemberAdminModel = getAdminModel('member');
1822
			if(!$oMemberAdminModel->getMemberAdminIPCheck())
1823
			{
1824
				$_SESSION['denied_admin'] = 'Y';
1825
			}
1826
		}
1827
1828
		$this->setSessionInfo();
1829
1830
		return $output;
1831
	}
1832
1833
	/**
1834
	 * Update or create session information
1835
	 */
1836
	function setSessionInfo()
1837
	{
1838
		$oMemberModel = getModel('member');
1839
		// If your information came through the current session information to extract information from the users
1840
		if(!$this->memberInfo && $_SESSION['member_srl'] && $oMemberModel->isLogged() )
1841
		{
1842
			$this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($_SESSION['member_srl']);
1843
			// If you do not destroy the session Profile
1844
			if($this->memberInfo->member_srl != $_SESSION['member_srl'])
1845
			{
1846
				$this->destroySessionInfo();
1847
				return;
1848
			}
1849
		}
1850
		// Stop using the session id is destroyed
1851
		if($this->memberInfo->denied=='Y')
1852
		{
1853
			$this->destroySessionInfo();
1854
			return;
1855
		}
1856
		// Log in for treatment sessions set
1857
		$_SESSION['is_logged'] = true;
1858
		$_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR'];
1859
		$_SESSION['member_srl'] = $this->memberInfo->member_srl;
1860
		$_SESSION['is_admin'] = '';
1861
		setcookie('xe_logged', 'true');
1862
		// Do not save your password in the session jiwojum;;
1863
		//unset($this->memberInfo->password);
1864
		// User Group Settings
1865
		/*
1866
		   if($this->memberInfo->group_list) {
1867
		   $group_srl_list = array_keys($this->memberInfo->group_list);
1868
		   $_SESSION['group_srls'] = $group_srl_list;
1869
		// If the group is designated as an administrator administrator
1870
		$oMemberModel = getModel('member');
1871
		$admin_group = $oMemberModel->getAdminGroup();
1872
		if($admin_group->group_srl && in_array($admin_group->group_srl, $group_srl_list)) $_SESSION['is_admin'] = 'Y';
1873
		}
1874
		 */
1875
1876
		// Information stored in the session login user
1877
		Context::set('is_logged', true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1878
		Context::set('logged_info', $this->memberInfo);
1879
1880
		// Only the menu configuration of the user (such as an add-on to the menu can be changed)
1881
		$this->addMemberMenu( 'dispMemberInfo', 'cmd_view_member_info');
1882
		$this->addMemberMenu( 'dispMemberScrappedDocument', 'cmd_view_scrapped_document');
1883
		$this->addMemberMenu( 'dispMemberSavedDocument', 'cmd_view_saved_document');
1884
		$this->addMemberMenu( 'dispMemberOwnDocument', 'cmd_view_own_document');
1885
	}
1886
1887
	/**
1888
	 * Logged method for providing a personalized menu
1889
	 * Login information is used in the output widget, or personalized page
1890
	 */
1891
	function addMemberMenu($act, $str)
1892
	{
1893
		$logged_info = Context::get('logged_info');
1894
1895
		$logged_info->menu_list[$act] = Context::getLang($str);
1896
1897
		Context::set('logged_info', $logged_info);
1898
	}
1899
1900
	/**
1901
	 * Nickname and click Log In to add a pop-up menu that appears when the method
1902
	 */
1903 View Code Duplication
	function addMemberPopupMenu($url, $str, $icon = '', $target = 'self')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1904
	{
1905
		$member_popup_menu_list = Context::get('member_popup_menu_list');
1906
		if(!is_array($member_popup_menu_list)) $member_popup_menu_list = array();
1907
1908
		$obj = new stdClass;
1909
		$obj->url = $url;
1910
		$obj->str = $str;
1911
		$obj->icon = $icon;
1912
		$obj->target = $target;
1913
		$member_popup_menu_list[] = $obj;
1914
1915
		Context::set('member_popup_menu_list', $member_popup_menu_list);
0 ignored issues
show
Documentation introduced by
$member_popup_menu_list is of type array<integer,object<stdClass>>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1916
	}
1917
1918
	/**
1919
	 * Add users to the member table
1920
	 */
1921
	function insertMember(&$args, $password_is_hashed = false)
1922
	{
1923
		// Call a trigger (before)
1924
		$output = ModuleHandler::triggerCall('member.insertMember', 'before', $args);
1925
		if(!$output->toBool()) return $output;
1926
		// Terms and Conditions portion of the information set up by members reaffirmed
1927
		$oModuleModel = getModel('module');
1928
		$config = $oModuleModel->getModuleConfig('member');
1929
1930
		$logged_info = Context::get('logged_info');
1931
		// If the date of the temporary restrictions limit further information on the date of
1932
		if($config->limit_day) $args->limit_date = date("YmdHis", $_SERVER['REQUEST_TIME']+$config->limit_day*60*60*24);
1933
1934
		$args->member_srl = getNextSequence();
1935
		$args->list_order = -1 * $args->member_srl;
1936
1937
		// Execute insert or update depending on the value of member_srl
1938
		if(!$args->user_id) $args->user_id = 't'.$args->member_srl;
1939
		// Enter the user's identity changed to lowercase
1940
		else $args->user_id = strtolower($args->user_id);
1941
		if(!$args->user_name) $args->user_name = $args->member_srl;
1942
		if(!$args->nick_name) $args->nick_name = $args->member_srl;
1943
1944
		// Control of essential parameters
1945
		if($args->allow_mailing!='Y') $args->allow_mailing = 'N';
1946
		if($args->denied!='Y') $args->denied = 'N';
1947 View Code Duplication
		if(!$args->allow_message || ($args->allow_message && !in_array($args->allow_message, array('Y','N','F')))) $args->allow_message = 'Y';
1948
1949
		if($logged_info->is_admin == 'Y')
1950
		{
1951
			if($args->is_admin!='Y') $args->is_admin = 'N';
1952
		}
1953
		else
1954
		{
1955
			unset($args->is_admin);
1956
		}
1957
1958
		list($args->email_id, $args->email_host) = explode('@', $args->email_address);
1959
1960
		// Sanitize user ID, username, nickname, homepage, blog
1961
		$args->user_id = htmlspecialchars($args->user_id, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
1962
		$args->user_name = htmlspecialchars($args->user_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
1963
		$args->nick_name = htmlspecialchars($args->nick_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
1964
		$args->homepage = htmlspecialchars($args->homepage, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
1965
		$args->blog = htmlspecialchars($args->blog, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
1966 View Code Duplication
		if($args->homepage && !preg_match("/^[a-z]+:\/\//i",$args->homepage)) $args->homepage = 'http://'.$args->homepage;
1967 View Code Duplication
		if($args->blog && !preg_match("/^[a-z]+:\/\//i",$args->blog)) $args->blog = 'http://'.$args->blog;
1968
1969
		// Create a model object
1970
		$oMemberModel = getModel('member');
1971
1972
		// Check password strength
1973
		if($args->password && !$password_is_hashed)
1974
		{
1975 View Code Duplication
			if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
1976
			{
1977
				$message = Context::getLang('about_password_strength');
1978
				return new Object(-1, $message[$config->password_strength]);
1979
			}
1980
			$args->password = $oMemberModel->hashPassword($args->password);
1981
		}
1982
		elseif(!$args->password)
1983
		{
1984
			unset($args->password);
1985
		}
1986
1987
		// Check if ID is prohibited
1988
		if($oMemberModel->isDeniedID($args->user_id))
1989
		{
1990
			return new Object(-1,'denied_user_id');
1991
		}
1992
1993
		// Check if ID is duplicate
1994
		$member_srl = $oMemberModel->getMemberSrlByUserID($args->user_id);
1995
		if($member_srl)
1996
		{
1997
			return new Object(-1,'msg_exists_user_id');
1998
		}
1999
2000
		// Check if nickname is prohibited
2001
		if($oMemberModel->isDeniedNickName($args->nick_name))
2002
		{
2003
			return new Object(-1,'denied_nick_name');
2004
		}
2005
2006
		// Check if nickname is duplicate
2007
		$member_srl = $oMemberModel->getMemberSrlByNickName($args->nick_name);
2008
		if($member_srl)
2009
		{
2010
			return new Object(-1,'msg_exists_nick_name');
2011
		}
2012
2013
		// Check if email address is duplicate
2014
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($args->email_address);
2015
		if($member_srl)
2016
		{
2017
			return new Object(-1,'msg_exists_email_address');
2018
		}
2019
2020
		// Insert data into the DB
2021
		$args->list_order = -1 * $args->member_srl;
2022
2023
		if(!$args->user_id) $args->user_id = 't'.$args->member_srl;
2024
		if(!$args->user_name) $args->user_name = $args->member_srl;
2025
2026
		$oDB = &DB::getInstance();
2027
		$oDB->begin();
2028
2029
		$output = executeQuery('member.insertMember', $args);
2030
		if(!$output->toBool())
2031
		{
2032
			$oDB->rollback();
2033
			return $output;
2034
		}
2035
2036 View Code Duplication
		if(is_array($args->group_srl_list)) $group_srl_list = $args->group_srl_list;
2037
		else $group_srl_list = explode('|@|', $args->group_srl_list);
2038
		// If no value is entered the default group, the value of group registration
2039
		if(!$args->group_srl_list)
2040
		{
2041
			$columnList = array('site_srl', 'group_srl');
2042
			$default_group = $oMemberModel->getDefaultGroup(0, $columnList);
2043
			if($default_group)
2044
			{
2045
				// Add to the default group
2046
				$output = $this->addMemberToGroup($args->member_srl,$default_group->group_srl);
2047
				if(!$output->toBool())
2048
				{
2049
					$oDB->rollback();
2050
					return $output;
2051
				}
2052
			}
2053
			// If the value is the value of the group entered the group registration
2054
		}
2055
		else
2056
		{
2057 View Code Duplication
			for($i=0;$i<count($group_srl_list);$i++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2058
			{
2059
				$output = $this->addMemberToGroup($args->member_srl,$group_srl_list[$i]);
2060
2061
				if(!$output->toBool())
2062
				{
2063
					$oDB->rollback();
2064
					return $output;
2065
				}
2066
			}
2067
		}
2068
2069
		$member_config = $oModuleModel->getModuleConfig('member');
0 ignored issues
show
Unused Code introduced by
$member_config is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2070
		// When using email authentication mode (when you subscribed members denied a) certified mail sent
2071
		if($args->denied == 'Y')
2072
		{
2073
			// Insert data into the authentication DB
2074
			$oPassword = new Password();
2075
			$auth_args = new stdClass();
2076
			$auth_args->user_id = $args->user_id;
2077
			$auth_args->member_srl = $args->member_srl;
2078
			$auth_args->new_password = $args->password;
2079
			$auth_args->auth_key = $oPassword->createSecureSalt(40);
2080
			$auth_args->is_register = 'Y';
2081
2082
			$output = executeQuery('member.insertAuthMail', $auth_args);
2083
			if(!$output->toBool())
2084
			{
2085
				$oDB->rollback();
2086
				return $output;
2087
			}
2088
			$this->_sendAuthMail($auth_args, $args);
2089
		}
2090
		// Call a trigger (after)
2091 View Code Duplication
		if($output->toBool())
2092
		{
2093
			$trigger_output = ModuleHandler::triggerCall('member.insertMember', 'after', $args);
2094
			if(!$trigger_output->toBool())
2095
			{
2096
				$oDB->rollback();
2097
				return $trigger_output;
2098
			}
2099
		}
2100
2101
		$oDB->commit(true);
2102
2103
		$output->add('member_srl', $args->member_srl);
2104
		return $output;
2105
	}
2106
2107
	/**
2108
	 * Modify member information
2109
	 *
2110
	 * @param bool $is_admin , modified 2013-11-22
2111
	 */
2112
	function updateMember($args, $is_admin = FALSE)
2113
	{
2114
		// Call a trigger (before)
2115
		$output = ModuleHandler::triggerCall('member.updateMember', 'before', $args);
2116
		if(!$output->toBool()) return $output;
2117
		// Create a model object
2118
		$oMemberModel = getModel('member');
2119
2120
		$logged_info = Context::get('logged_info');
2121
		// Get what you want to modify the original information
2122
		if(!$this->memberInfo) $this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($args->member_srl);
2123
		// Control of essential parameters
2124
		if($args->allow_mailing!='Y') $args->allow_mailing = 'N';
2125 View Code Duplication
		if($args->allow_message && !in_array($args->allow_message, array('Y','N','F'))) $args->allow_message = 'Y';
2126
2127
		if($logged_info->is_admin == 'Y')
2128
		{
2129
			if($args->denied!='Y') $args->denied = 'N';
2130
			if($args->is_admin!='Y' && $logged_info->member_srl != $args->member_srl) $args->is_admin = 'N';
2131
		}
2132
		else
2133
		{
2134
			unset($args->is_admin);
2135
			if($is_admin == false)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
2136
				unset($args->denied);
2137
			if($logged_info->member_srl != $args->member_srl && $is_admin == false)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
2138
			{
2139
				return $this->stop('msg_invalid_request');
2140
			}
2141
		}
2142
2143
		// Sanitize user ID, username, nickname, homepage, blog
2144
		if($args->user_id) $args->user_id = htmlspecialchars($args->user_id, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2145
		$args->user_name = htmlspecialchars($args->user_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2146
		$args->nick_name = htmlspecialchars($args->nick_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2147
		$args->homepage = htmlspecialchars($args->homepage, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2148
		$args->blog = htmlspecialchars($args->blog, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2149 View Code Duplication
		if($args->homepage && !preg_match("/^[a-z]+:\/\//is",$args->homepage)) $args->homepage = 'http://'.$args->homepage;
2150 View Code Duplication
		if($args->blog && !preg_match("/^[a-z]+:\/\//is",$args->blog)) $args->blog = 'http://'.$args->blog;
2151
2152
		// check member identifier form
2153
		$config = $oMemberModel->getMemberConfig();
2154
2155
		$output = executeQuery('member.getMemberInfoByMemberSrl', $args);
2156
		$orgMemberInfo = $output->data;
2157
2158
		// Check if email address or user ID is duplicate
2159
		if($config->identifier == 'email_address')
2160
		{
2161
			$member_srl = $oMemberModel->getMemberSrlByEmailAddress($args->email_address);
2162
			if($member_srl && $args->member_srl != $member_srl)
2163
			{
2164
				return new Object(-1,'msg_exists_email_address');
2165
			}
2166
			$args->email_address = $orgMemberInfo->email_address;
2167
		}
2168 View Code Duplication
		else
2169
		{
2170
			$member_srl = $oMemberModel->getMemberSrlByUserID($args->user_id);
2171
			if($member_srl && $args->member_srl != $member_srl)
2172
			{
2173
				return new Object(-1,'msg_exists_user_id');
2174
			}
2175
2176
			$args->user_id = $orgMemberInfo->user_id;
2177
		}
2178
2179
		if($logged_info->is_admin !== 'Y')
2180
		{
2181
			// Check if ID is prohibited
2182
			if($args->user_id && $oMemberModel->isDeniedID($args->user_id))
2183
			{
2184
				return new Object(-1,'denied_user_id');
2185
			}
2186
2187
			// Check if nickname is prohibited
2188
			if($args->nick_name && $oMemberModel->isDeniedNickName($args->nick_name))
2189
			{
2190
				return new Object(-1, 'denied_nick_name');
2191
			}
2192
		}
2193
2194
		// Check if ID is duplicate
2195 View Code Duplication
		if($args->user_id)
2196
		{
2197
			$member_srl = $oMemberModel->getMemberSrlByUserID($args->user_id);
2198
			if($member_srl && $args->member_srl != $member_srl)
2199
			{
2200
				return new Object(-1,'msg_exists_user_id');
2201
			}
2202
		}
2203
2204
		// Check if nickname is duplicate
2205
		$member_srl = $oMemberModel->getMemberSrlByNickName($args->nick_name);
2206
 		if($member_srl && $args->member_srl != $member_srl)
2207
 		{
2208
 			return new Object(-1,'msg_exists_nick_name');
2209
 		}
2210
2211
		list($args->email_id, $args->email_host) = explode('@', $args->email_address);
2212
2213
		$oDB = &DB::getInstance();
2214
		$oDB->begin();
2215
2216
		// Check password strength
2217
		if($args->password)
2218
		{
2219 View Code Duplication
			if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
2220
			{
2221
				$message = Context::getLang('about_password_strength');
2222
				return new Object(-1, $message[$config->password_strength]);
2223
			}
2224
			$args->password = $oMemberModel->hashPassword($args->password);
2225
		}
2226
		else
2227
		{
2228
			$args->password = $orgMemberInfo->password;
2229
		}
2230
2231
		if(!$args->user_name) $args->user_name = $orgMemberInfo->user_name;
2232
		if(!$args->user_id) $args->user_id = $orgMemberInfo->user_id;
2233
		if(!$args->nick_name) $args->nick_name = $orgMemberInfo->nick_name;
2234
		if(!$args->description) $args->description = $orgMemberInfo->description;
2235
		if(!$args->birthday) $args->birthday = '';
2236
2237
		$output = executeQuery('member.updateMember', $args);
2238
2239
		if(!$output->toBool())
2240
		{
2241
			$oDB->rollback();
2242
			return $output;
2243
		}
2244
2245
		if($args->group_srl_list)
2246
		{
2247 View Code Duplication
			if(is_array($args->group_srl_list)) $group_srl_list = $args->group_srl_list;
2248
			else $group_srl_list = explode('|@|', $args->group_srl_list);
2249
			// If the group information, group information changes
2250
			if(count($group_srl_list) > 0)
2251
			{
2252
				$args->site_srl = 0;
2253
				// One of its members to delete all the group
2254
				$output = executeQuery('member.deleteMemberGroupMember', $args);
2255
				if(!$output->toBool())
2256
				{
2257
					$oDB->rollback();
2258
					return $output;
2259
				}
2260
				// Enter one of the loop a
2261 View Code Duplication
				for($i=0;$i<count($group_srl_list);$i++)
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2262
				{
2263
					$output = $this->addMemberToGroup($args->member_srl,$group_srl_list[$i]);
2264
					if(!$output->toBool())
2265
					{
2266
						$oDB->rollback();
2267
						return $output;
2268
					}
2269
				}
2270
2271
				// if group is changed, point changed too.
2272
				$this->_updatePointByGroup($orgMemberInfo->member_srl, $group_srl_list);
2273
			}
2274
		}
2275
		// Call a trigger (after)
2276 View Code Duplication
		if($output->toBool()) {
2277
			$trigger_output = ModuleHandler::triggerCall('member.updateMember', 'after', $args);
2278
			if(!$trigger_output->toBool())
2279
			{
2280
				$oDB->rollback();
2281
				return $trigger_output;
2282
			}
2283
		}
2284
2285
		$oDB->commit();
2286
2287
		//remove from cache
2288
		$this->_clearMemberCache($args->member_srl, $args->site_srl);
2289
2290
		// Save Session
2291
		if(!$this->memberInfo) $this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($args->member_srl);
2292
		$logged_info = Context::get('logged_info');
0 ignored issues
show
Unused Code introduced by
$logged_info is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2293
2294
		$output->add('member_srl', $args->member_srl);
2295
		return $output;
2296
	}
2297
2298
	/**
2299
	 * Modify member password
2300
	 */
2301
	function updateMemberPassword($args)
2302
	{
2303
		if($args->password)
2304
		{
2305
2306
			// check password strength
2307
			$oMemberModel = getModel('member');
2308
			$config = $oMemberModel->getMemberConfig();
2309
2310 View Code Duplication
			if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
2311
			{
2312
				$message = Context::getLang('about_password_strength');
2313
				return new Object(-1, $message[$config->password_strength]);
2314
			}
2315
2316
			$args->password = $oMemberModel->hashPassword($args->password);
2317
		}
2318
		else if($args->hashed_password)
2319
		{
2320
			$args->password = $args->hashed_password;
2321
		}
2322
2323
		$output = executeQuery('member.updateMemberPassword', $args);
2324
		if($output->toBool())
2325
		{
2326
			$result = executeQuery('member.updateChangePasswordDate', $args);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2327
		}
2328
2329
		$this->_clearMemberCache($args->member_srl);
2330
2331
		return $output;
2332
	}
2333
2334
	/**
2335
	 * Delete User
2336
	 */
2337
	function deleteMember($member_srl)
2338
	{
2339
		// Call a trigger (before)
2340
		$trigger_obj = new stdClass();
2341
		$trigger_obj->member_srl = $member_srl;
2342
		$output = ModuleHandler::triggerCall('member.deleteMember', 'before', $trigger_obj);
2343
		if(!$output->toBool()) return $output;
2344
		// Create a model object
2345
		$oMemberModel = getModel('member');
2346
		// Bringing the user's information
2347
		if(!$this->memberInfo || $this->memberInfo->member_srl != $member_srl || !isset($this->memberInfo->is_admin))
2348
		{
2349
			$columnList = array('member_srl', 'is_admin');
2350
			$this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
2351
		}
2352
		if(!$this->memberInfo) return new Object(-1, 'msg_not_exists_member');
2353
		// If managers can not be deleted
2354
		if($this->memberInfo->is_admin == 'Y') return new Object(-1, 'msg_cannot_delete_admin');
2355
2356
		$oDB = &DB::getInstance();
2357
		$oDB->begin();
2358
2359
		$args = new stdClass();
2360
		$args->member_srl = $member_srl;
2361
		// Delete the entries in member_auth_mail
2362
		$output = executeQuery('member.deleteAuthMail', $args);
2363
		if(!$output->toBool())
2364
		{
2365
			$oDB->rollback();
2366
			return $output;
2367
		}
2368
2369
		// TODO: If the table is not an upgrade may fail.
2370
		/*
2371
		   if(!$output->toBool()) {
2372
		   $oDB->rollback();
2373
		   return $output;
2374
		   }
2375
		 */
2376
		// Delete the entries in member_group_member
2377
		$output = executeQuery('member.deleteMemberGroupMember', $args);
2378
		if(!$output->toBool())
2379
		{
2380
			$oDB->rollback();
2381
			return $output;
2382
		}
2383
		// member removed from the table
2384
		$output = executeQuery('member.deleteMember', $args);
2385
		if(!$output->toBool())
2386
		{
2387
			$oDB->rollback();
2388
			return $output;
2389
		}
2390
		// Call a trigger (after)
2391 View Code Duplication
		if($output->toBool())
2392
		{
2393
			$trigger_output = ModuleHandler::triggerCall('member.deleteMember', 'after', $trigger_obj);
2394
			if(!$trigger_output->toBool())
2395
			{
2396
				$oDB->rollback();
2397
				return $trigger_output;
2398
			}
2399
		}
2400
2401
		$oDB->commit();
2402
		// Name, image, image, mark, sign, delete
2403
		$this->procMemberDeleteImageName($member_srl);
2404
		$this->procMemberDeleteImageMark($member_srl);
2405
		$this->procMemberDeleteProfileImage($member_srl);
2406
		$this->delSignature($member_srl);
2407
2408
		$this->_clearMemberCache($member_srl);
2409
2410
		return $output;
2411
	}
2412
2413
	/**
2414
	 * Destroy all session information
2415
	 */
2416
	function destroySessionInfo()
2417
	{
2418
		if(!$_SESSION || !is_array($_SESSION)) return;
2419
2420
		$memberInfo = Context::get('logged_info');
2421
		$memberSrl = $memberInfo->member_srl;
2422
2423
		foreach($_SESSION as $key => $val)
2424
		{
2425
			$_SESSION[$key] = '';
2426
		}
2427
2428
		session_destroy();
2429
		setcookie(session_name(), '', $_SERVER['REQUEST_TIME']-42000);
2430
		setcookie('sso','',$_SERVER['REQUEST_TIME']-42000);
2431
		setcookie('xeak','',$_SERVER['REQUEST_TIME']-42000);
2432
		setcookie('xe_logged', 'false', $_SERVER['REQUEST_TIME'] - 42000);
2433
2434
		if($memberSrl || $_COOKIE['xeak'])
2435
		{
2436
			$args = new stdClass();
2437
			$args->member_srl = $memberSrl;
2438
			$args->autologin_key = $_COOKIE['xeak'];
2439
			$output = executeQuery('member.deleteAutologin', $args);
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2440
		}
2441
	}
2442
2443
	function _updatePointByGroup($memberSrl, $groupSrlList)
2444
	{
2445
		$oModuleModel = getModel('module');
2446
		$pointModuleConfig = $oModuleModel->getModuleConfig('point');
2447
		$pointGroup = $pointModuleConfig->point_group;
2448
2449
		$levelGroup = array();
2450
		if(is_array($pointGroup) && count($pointGroup)>0)
2451
		{
2452
			$levelGroup = array_flip($pointGroup);
2453
			ksort($levelGroup);
2454
		}
2455
		$maxLevel = 0;
2456
		$resultGroup = array_intersect($levelGroup, $groupSrlList);
2457
		if(count($resultGroup) > 0)
2458
			$maxLevel = max(array_flip($resultGroup));
2459
2460
		if($maxLevel > 0)
2461
		{
2462
			$oPointModel = getModel('point');
2463
			$originPoint = $oPointModel->getPoint($memberSrl);
2464
2465
			if($pointModuleConfig->level_step[$maxLevel] > $originPoint)
2466
			{
2467
				$oPointController = getController('point');
2468
				$oPointController->setPoint($memberSrl, $pointModuleConfig->level_step[$maxLevel], 'update');
2469
			}
2470
		}
2471
	}
2472
2473
	function procMemberModifyEmailAddress()
2474
	{
2475
		if(!Context::get('is_logged')) return $this->stop('msg_not_logged');
2476
2477
		$member_info = Context::get('logged_info');
2478
		$newEmail = Context::get('email_address');
2479
2480
		if(!$newEmail) return $this->stop('msg_invalid_request');
2481
2482
		$oMemberModel = getModel('member');
2483
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($newEmail);
2484
		if($member_srl) return new Object(-1,'msg_exists_email_address');
2485
2486
		if($_SESSION['rechecked_password_step'] != 'INPUT_DATA')
2487
		{
2488
			return $this->stop('msg_invalid_request');
2489
		}
2490
		unset($_SESSION['rechecked_password_step']);
2491
2492
		$oPassword = new Password();
2493
		$auth_args = new stdClass();
2494
		$auth_args->user_id = $newEmail;
2495
		$auth_args->member_srl = $member_info->member_srl;
2496
		$auth_args->auth_key = $oPassword->createSecureSalt(40);
2497
		$auth_args->new_password = 'XE_change_emaill_address';
2498
2499
		$oDB = &DB::getInstance();
2500
		$oDB->begin();
2501
		$output = executeQuery('member.insertAuthMail', $auth_args);
2502
		if(!$output->toBool())
2503
		{
2504
			$oDB->rollback();
2505
			return $output;
2506
		}
2507
2508
		$oModuleModel = getModel('module');
2509
		$member_config = $oModuleModel->getModuleConfig('member');
2510
2511
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
2512
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
2513
2514
		global $lang;
2515
2516
		$memberInfo = array();
2517
		$memberInfo[$lang->email_address] = $member_info->email_address;
2518
		$memberInfo[$lang->nick_name] = $member_info->nick_name;
2519
2520
		Context::set('memberInfo', $memberInfo);
0 ignored issues
show
Documentation introduced by
$memberInfo is of type array<?,?>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2521
2522
		Context::set('newEmail', $newEmail);
2523
2524
		$auth_url = getFullUrl('','module','member','act','procMemberAuthEmailAddress','member_srl',$member_info->member_srl, 'auth_key',$auth_args->auth_key);
2525
		Context::set('auth_url', $auth_url);
2526
2527
		$oTemplate = &TemplateHandler::getInstance();
2528
		$content = $oTemplate->compile($tpl_path, 'confirm_member_new_email');
2529
2530
		$oMail = new Mail();
2531
		$oMail->setTitle( Context::getLang('title_modify_email_address') );
2532
		$oMail->setContent($content);
2533
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
2534
		$oMail->setReceiptor( $member_info->nick_name, $newEmail );
2535
		$result = $oMail->send();
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2536
2537
		$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $newEmail);
2538
		$this->setMessage($msg);
2539
2540
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
2541
		$this->setRedirectUrl($returnUrl);
2542
	}
2543
2544
	function procMemberAuthEmailAddress()
2545
	{
2546
		$member_srl = Context::get('member_srl');
2547
		$auth_key = Context::get('auth_key');
2548
		if(!$member_srl || !$auth_key) return $this->stop('msg_invalid_request');
2549
2550
		// Test logs for finding password by user_id and authkey
2551
		$args = new stdClass;
2552
		$args->member_srl = $member_srl;
2553
		$args->auth_key = $auth_key;
2554
		$output = executeQuery('member.getAuthMail', $args);
2555 View Code Duplication
		if(!$output->toBool() || $output->data->auth_key != $auth_key)
2556
		{
2557
			if(strlen($output->data->auth_key) !== strlen($auth_key)) executeQuery('member.deleteAuthChangeEmailAddress', $args);
2558
			return $this->stop('msg_invalid_modify_email_auth_key');
2559
		}
2560
2561
		$newEmail = $output->data->user_id;
2562
		$args->email_address = $newEmail;
2563
		list($args->email_id, $args->email_host) = explode('@', $newEmail);
2564
2565
		$output = executeQuery('member.updateMemberEmailAddress', $args);
2566
		if(!$output->toBool()) return $this->stop($output->getMessage());
2567
2568
		// Remove all values having the member_srl and new_password equal to 'XE_change_emaill_address' from authentication table
2569
		executeQuery('member.deleteAuthChangeEmailAddress',$args);
2570
2571
		$this->_clearMemberCache($args->member_srl);
2572
2573
		// Notify the result
2574
		$this->setTemplatePath($this->module_path.'tpl');
2575
		$this->setTemplateFile('msg_success_modify_email_address');
2576
	}
2577
2578
	/**
2579
	 * trigger for document.getDocumentMenu. Append to popup menu a button for procMemberSpammerManage()
2580
	 *
2581
	 * @param array &$menu_list
2582
	 *
2583
	 * @return object
2584
	**/
2585 View Code Duplication
	function triggerGetDocumentMenu(&$menu_list)
0 ignored issues
show
Unused Code introduced by
The parameter $menu_list is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2586
	{
2587
		if(!Context::get('is_logged')) return new Object();
2588
2589
		$logged_info = Context::get('logged_info');
2590
		$document_srl = Context::get('target_srl');
2591
2592
		$oDocumentModel = getModel('document');
2593
		$columnList = array('document_srl', 'module_srl', 'member_srl', 'ipaddress');
2594
		$oDocument = $oDocumentModel->getDocument($document_srl, false, false, $columnList);
2595
		$member_srl = $oDocument->get('member_srl');
2596
		$module_srl = $oDocument->get('module_srl');
2597
2598
		if(!$member_srl) return new Object();
2599
		if($oDocumentModel->grant->manager != 1 || $member_srl==$logged_info->member_srl) return new Object();
2600
2601
		$oDocumentController = getController('document');
2602
		$url = getUrl('','module','member','act','dispMemberSpammer','member_srl',$member_srl,'module_srl',$module_srl);
2603
		$oDocumentController->addDocumentPopupMenu($url,'cmd_spammer','','popup');
2604
2605
		return new Object();
2606
	}
2607
2608
	/**
2609
	 * trigger for comment.getCommentMenu. Append to popup menu a button for procMemberSpammerManage()
2610
	 *
2611
	 * @param array &$menu_list
2612
	 *
2613
	 * @return object
2614
	**/
2615 View Code Duplication
	function triggerGetCommentMenu(&$menu_list)
0 ignored issues
show
Unused Code introduced by
The parameter $menu_list is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
2616
	{
2617
		if(!Context::get('is_logged')) return new Object();
2618
2619
		$logged_info = Context::get('logged_info');
2620
		$comment_srl = Context::get('target_srl');
2621
2622
		$oCommentModel = getModel('comment');
2623
		$columnList = array('comment_srl', 'module_srl', 'member_srl', 'ipaddress');
2624
		$oComment = $oCommentModel->getComment($comment_srl, FALSE, $columnList);
2625
		$module_srl = $oComment->get('module_srl');
2626
		$member_srl = $oComment->get('member_srl');
2627
2628
		if(!$member_srl) return new Object();
2629
		if($oCommentModel->grant->manager != 1 || $member_srl==$logged_info->member_srl) return new Object();
2630
2631
		$oCommentController = getController('comment');
2632
		$url = getUrl('','module','member','act','dispMemberSpammer','member_srl',$member_srl,'module_srl',$module_srl);
2633
		$oCommentController->addCommentPopupMenu($url,'cmd_spammer','','popup');
2634
2635
		return new Object();
2636
	}
2637
2638
	/**
2639
	 * Spammer manage. Denied user login. And delete or trash all documents. Response Ajax string
2640
	 *
2641
	 * @return object
2642
	**/
2643
	function procMemberSpammerManage()
2644
	{
2645
		if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted');
2646
2647
		$logged_info = Context::get('logged_info');
2648
		$member_srl = Context::get('member_srl');
2649
		$module_srl = Context::get('module_srl');
2650
		$cnt_loop = Context::get('cnt_loop');
2651
		$proc_type = Context::get('proc_type');
2652
		$isMoveToTrash = true;
2653
		if($proc_type == "delete")
2654
			$isMoveToTrash = false;
2655
2656
		// check grant
2657
		$oModuleModel = getModel('module');
2658
		$columnList = array('module_srl', 'module');
2659
		$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl, $columnList);
2660
		$grant = $oModuleModel->getGrant($module_info, $logged_info);
2661
2662
		if(!$grant->manager) return new Object(-1,'msg_not_permitted');
2663
2664
		$proc_msg = "";
0 ignored issues
show
Unused Code introduced by
$proc_msg is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2665
2666
		$oDocumentModel = getModel('document');
2667
		$oCommentModel = getModel('comment');
2668
2669
		// delete or trash destination
2670
		// proc member
2671
		if($cnt_loop == 1)
2672
			$this->_spammerMember($member_srl);
2673
		// proc document and comment
2674
		elseif($cnt_loop>1)
2675
			$this->_spammerDocuments($member_srl, $isMoveToTrash);
2676
2677
		// get destination count
2678
		$cnt_document = $oDocumentModel->getDocumentCountByMemberSrl($member_srl);
2679
		$cnt_comment = $oCommentModel->getCommentCountByMemberSrl($member_srl);
2680
2681
		$total_count = Context::get('total_count');
2682
		$remain_count = $cnt_document + $cnt_comment;
2683
		if($cnt_loop == 1) $total_count = $remain_count;
2684
2685
		// get progress percent
2686
		if($total_count > 0)
2687
			$progress = intval( ( ( $total_count - $remain_count ) / $total_count ) * 100 );
2688
		else
2689
			$progress = 100;
2690
2691
		$this->add('total_count', $total_count);
2692
		$this->add('remain_count', $remain_count);
2693
		$this->add('progress', $progress);
2694
		$this->add('member_srl', $member_srl);
2695
		$this->add('module_srl', $module_srl);
2696
		$this->add('cnt_loop', ++$cnt_loop);
2697
		$this->add('proc_type', $proc_type);
2698
2699
		return new Object(0);
2700
	}
2701
2702
	/**
2703
	 * Denied user login and write description
2704
	 *
2705
	 * @param int $member_srl
2706
	 *
2707
	 * @return object
2708
	**/
2709
	private function _spammerMember($member_srl) {
2710
		$logged_info = Context::get('logged_info');
2711
		$spam_description = trim( Context::get('spam_description') );
2712
2713
		$oMemberModel = getModel('member');
2714
		$columnList = array('member_srl', 'email_address', 'user_id', 'nick_name', 'description');
2715
		// get member current infomation
2716
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
2717
2718
		$oDocumentModel = getModel('document');
2719
		$oCommentModel = getModel('comment');
2720
		$cnt_comment = $oCommentModel->getCommentCountByMemberSrl($member_srl);
2721
		$cnt_document = $oDocumentModel->getDocumentCountByMemberSrl($member_srl);
2722
		$total_count = $cnt_comment + $cnt_document;
2723
2724
		$args = new stdClass();
2725
		$args->member_srl = $member_info->member_srl;
2726
		$args->email_address = $member_info->email_address;
2727
		$args->user_id = $member_info->user_id;
2728
		$args->nick_name = $member_info->nick_name;
2729
		$args->denied = "Y";
2730
		$args->description = trim( $member_info->description );
2731
		if( $args->description != "" ) $args->description .= "\n";	// add new line
2732
2733
		$args->description .= Context::getLang('cmd_spammer') . "[" . date("Y-m-d H:i:s") . " from:" . $logged_info->user_id . " info:" . $spam_description . " docuemnts count:" . $total_count . "]";
2734
2735
		$output = $this->updateMember($args, true);
2736
2737
		$this->_clearMemberCache($args->member_srl);
2738
2739
		return $output;
2740
	}
2741
2742
	/**
2743
	 * Delete or trash all documents
2744
	 *
2745
	 * @param int $member_srl
2746
	 * @param bool $isMoveToTrash
2747
	 *
2748
	 * @return object
2749
	**/
2750
	private function _spammerDocuments($member_srl, $isMoveToTrash) {
2751
		$oDocumentController = getController('document');
2752
		$oDocumentModel = getModel('document');
2753
		$oCommentController = getController('comment');
2754
		$oCommentModel = getModel('comment');
2755
2756
		// delete count by one request
2757
		$getContentsCount = 10;
2758
2759
		// 1. proc comment, 2. proc document
2760
		$cnt_comment = $oCommentModel->getCommentCountByMemberSrl($member_srl);
2761
		$cnt_document = $oDocumentModel->getDocumentCountByMemberSrl($member_srl);
2762
		if($cnt_comment > 0)
2763
		{
2764
			$columnList = array();
2765
			$commentList = $oCommentModel->getCommentListByMemberSrl($member_srl, $columnList, 0, false, $getContentsCount);
2766
			if($commentList) {
2767
				foreach($commentList as $v) {
2768
					$oCommentController->deleteComment($v->comment_srl, true, $isMoveToTrash);
2769
				}
2770
			}
2771
		} elseif($cnt_document > 0) {
2772
			$columnList = array();
2773
			$documentList = $oDocumentModel->getDocumentListByMemberSrl($member_srl, $columnList, 0, false, $getContentsCount);
2774
			if($documentList) {
2775
				foreach($documentList as $v) {
2776
					if($isMoveToTrash) $oDocumentController->moveDocumentToTrash($v);
2777
					else $oDocumentController->deleteDocument($v->document_srl);
2778
				}
2779
			}
2780
		}
2781
2782
		return array();
2783
	}
2784
2785
	function _clearMemberCache($member_srl, $site_srl = 0)
2786
	{
2787
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
2788
		if($oCacheHandler->isSupport())
2789
		{
2790
			$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_' . $site_srl;
2791
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
2792
			$oCacheHandler->delete($cache_key);
2793
2794
			if($site_srl !== 0)
2795
			{
2796
				$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_0';
2797
				$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
2798
				$oCacheHandler->delete($cache_key);
2799
			}
2800
		}
2801
2802
		$oCacheHandler = CacheHandler::getInstance('object');
2803
		if($oCacheHandler->isSupport())
2804
		{
2805
			$object_key = 'member_info:' . getNumberingPath($member_srl) . $member_srl;
2806
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
2807
			$oCacheHandler->delete($cache_key);
2808
		}
2809
	}
2810
}
2811
/* End of file member.controller.php */
2812
/* Location: ./modules/member/member.controller.php */
2813