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 — develop ( ec9052...ffa67b )
by gyeong-won
10:11 queued 02:21
created

memberController::procMemberDeleteSavedDocument()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 14
nc 5
nop 0
dl 0
loc 25
rs 8.439
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
		// Get document
135
		$oDocumentModel = getModel('document');
136
		$oDocument = $oDocumentModel->getDocument($document_srl);
137
		// Variables
138
		$args = new stdClass();
139
		$args->document_srl = $document_srl;
140
		$args->member_srl = $logged_info->member_srl;
141
		$args->user_id = $oDocument->get('user_id');
142
		$args->user_name = $oDocument->get('user_name');
143
		$args->nick_name = $oDocument->get('nick_name');
144
		$args->target_member_srl = $oDocument->get('member_srl');
145
		$args->title = $oDocument->get('title');
146
		// Check if already scrapped
147
		$output = executeQuery('member.getScrapDocument', $args);
148
		if($output->data->count) return new Object(-1, 'msg_alreay_scrapped');
149
		// Insert
150
		$output = executeQuery('member.addScrapDocument', $args);
151
		if(!$output->toBool()) return $output;
152
153
		$this->setError(-1);
154
		$this->setMessage('success_registed');
155
	}
156
157
	/**
158
	 * Delete a scrap
159
	 *
160
	 * @return void|Object (void : success, Object : fail)
161
	 */
162
	function procMemberDeleteScrap()
163
	{
164
		// Check login information
165
		if(!Context::get('is_logged')) return new Object(-1, 'msg_not_logged');
166
		$logged_info = Context::get('logged_info');
167
168
		$document_srl = (int)Context::get('document_srl');
169
		if(!$document_srl) return new Object(-1,'msg_invalid_request');
170
		// Variables
171
		$args = new stdClass;
172
		$args->member_srl = $logged_info->member_srl;
173
		$args->document_srl = $document_srl;
174
		return executeQuery('member.deleteScrapDocument', $args);
175
	}
176
177
	/**
178
	 * Save posts
179
	 * @deprecated - instead Document Controller - procDocumentTempSave method use
180
	 * @return Object
181
	 */
182
	function procMemberSaveDocument()
183
	{
184
		return new Object(0, 'Deprecated method');
185
	}
186
187
	/**
188
	 * Delete the post
189
	 *
190
	 * @return void|Object (void : success, Object : fail)
191
	 */
192
	function procMemberDeleteSavedDocument()
193
	{
194
		// Check login information
195
		if(!Context::get('is_logged')) return new Object(-1, 'msg_not_logged');
196
		$logged_info = Context::get('logged_info');
197
198
		$document_srl = (int)Context::get('document_srl');
199
		if(!$document_srl) return new Object(-1,'msg_invalid_request');
200
201
		$oDocumentModel = getModel('document');
202
		$oDocument = $oDocumentModel->getDocument($document_srl);
203
		if ($oDocument->get('member_srl') != $logged_info->member_srl)
204
		{
205
			return new Object(-1,'msg_invalid_request');
206
		}
207
208
		$configStatusList = $oDocumentModel->getStatusList();
209
		if ($oDocument->get('status') != $configStatusList['temp'])
210
		{
211
			return new Object(-1,'msg_invalid_request');
212
		}
213
214
		$oDocumentController = getController('document');
215
		$oDocumentController->deleteDocument($document_srl);
216
	}
217
218
	/**
219
	 * Check values when member joining
220
	 *
221
	 * @return void|Object (void : success, Object : fail)
222
	 */
223
	function procMemberCheckValue()
224
	{
225
		$name = Context::get('name');
226
		$value = Context::get('value');
227
		if(!$value) return;
228
229
		$oMemberModel = getModel('member');
230
		// Check if logged-in
231
		$logged_info = Context::get('logged_info');
232
233
234
		switch($name)
235
		{
236
			case 'user_id' :
237
				// Check denied ID
238
				if($oMemberModel->isDeniedID($value)) return new Object(0,'denied_user_id');
239
				// Check if duplicated
240
				$member_srl = $oMemberModel->getMemberSrlByUserID($value);
241
				if($member_srl && $logged_info->member_srl != $member_srl ) return new Object(0,'msg_exists_user_id');
242
				break;
243
			case 'nick_name' :
244
				// Check denied ID
245
				if($oMemberModel->isDeniedNickName($value))
246
				{
247
					return new Object(0,'denied_nick_name');
248
				}
249
				// Check if duplicated
250
				$member_srl = $oMemberModel->getMemberSrlByNickName($value);
251
				if($member_srl && $logged_info->member_srl != $member_srl ) return new Object(0,'msg_exists_nick_name');
252
253
				break;
254
			case 'email_address' :
255
				// Check if duplicated
256
				$member_srl = $oMemberModel->getMemberSrlByEmailAddress($value);
257
				if($member_srl && $logged_info->member_srl != $member_srl ) return new Object(0,'msg_exists_email_address');
258
				break;
259
		}
260
	}
261
262
	/**
263
	 * Join Membership
264
	 *
265
	 * @return void|Object (void : success, Object : fail)
266
	 */
267
	function procMemberInsert()
268
	{
269
		if (Context::getRequestMethod () == "GET") return new Object (-1, "msg_invalid_request");
270
		$oMemberModel = &getModel ('member');
271
		$config = $oMemberModel->getMemberConfig();
272
273
		// call a trigger (before)
274
		$trigger_output = ModuleHandler::triggerCall ('member.procMemberInsert', 'before', $config);
275
		if(!$trigger_output->toBool ()) return $trigger_output;
276
		// Check if an administrator allows a membership
277
		if($config->enable_join != 'Y') return $this->stop ('msg_signup_disabled');
278
		// Check if the user accept the license terms (only if terms exist)
279
		if($config->agreement && Context::get('accept_agreement')!='Y') return $this->stop('msg_accept_agreement');
280
281
		// Extract the necessary information in advance
282
		$getVars = array();
283 View Code Duplication
		if($config->signupForm)
284
		{
285
			foreach($config->signupForm as $formInfo)
286
			{
287
				if($formInfo->isDefaultForm && ($formInfo->isUse || $formInfo->required || $formInfo->mustRequired))
288
				{
289
					$getVars[] = $formInfo->name;
290
				}
291
			}
292
		}
293
294
		$args = new stdClass;
295 View Code Duplication
		foreach($getVars as $val)
296
		{
297
			$args->{$val} = Context::get($val);
298
			if($val == 'birthday') $args->birthday_ui = Context::get('birthday_ui');
299
		}
300
		$args->birthday = intval(strtr($args->birthday, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
301 View Code Duplication
		if(!$args->birthday && $args->birthday_ui) $args->birthday = intval(strtr($args->birthday_ui, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
302
303
		$args->find_account_answer = Context::get('find_account_answer');
304
		$args->allow_mailing = Context::get('allow_mailing');
305
		$args->allow_message = Context::get('allow_message');
306
307
		if($args->password1) $args->password = $args->password1;
308
309
		// check password strength
310 View Code Duplication
		if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
311
		{
312
			$message = Context::getLang('about_password_strength');
313
			return new Object(-1, $message[$config->password_strength]);
314
		}
315
316
		// Remove some unnecessary variables from all the vars
317
		$all_args = Context::getRequestVars();
318
		unset($all_args->module);
319
		unset($all_args->act);
320
		unset($all_args->is_admin);
321
		unset($all_args->member_srl);
322
		unset($all_args->description);
323
		unset($all_args->group_srl_list);
324
		unset($all_args->body);
325
		unset($all_args->accept_agreement);
326
		unset($all_args->signature);
327
		unset($all_args->password);
328
		unset($all_args->password2);
329
		unset($all_args->mid);
330
		unset($all_args->error_return_url);
331
		unset($all_args->ruleset);
332
		unset($all_args->captchaType);
333
		unset($all_args->secret_text);
334
335
		// Set the user state as "denied" when using mail authentication
336
		if($config->enable_confirm == 'Y') $args->denied = 'Y';
337
		// Add extra vars after excluding necessary information from all the requested arguments
338
		$extra_vars = delObjectVars($all_args, $args);
339
		$args->extra_vars = serialize($extra_vars);
340
341
		// remove whitespace
342
		$checkInfos = array('user_id', 'user_name', 'nick_name', 'email_address');
343 View Code Duplication
		foreach($checkInfos as $val)
344
		{
345
			if(isset($args->{$val}))
346
			{
347
				$args->{$val} = preg_replace('/[\pZ\pC]+/u', '', $args->{$val});
348
			}
349
		}
350
		$output = $this->insertMember($args);
351
		if(!$output->toBool()) return $output;
352
353
		// insert ProfileImage, ImageName, ImageMark
354
		$profile_image = $_FILES['profile_image'];
355
		if(is_uploaded_file($profile_image['tmp_name']))
356
		{
357
			$this->insertProfileImage($args->member_srl, $profile_image['tmp_name']);
358
		}
359
360
		$image_mark = $_FILES['image_mark'];
361
		if(is_uploaded_file($image_mark['tmp_name']))
362
		{
363
			$this->insertImageMark($args->member_srl, $image_mark['tmp_name']);
364
		}
365
366
		$image_name = $_FILES['image_name'];
367
		if(is_uploaded_file($image_name['tmp_name']))
368
		{
369
			$this->insertImageName($args->member_srl, $image_name['tmp_name']);
370
		}
371
372
		// If a virtual site, join the site
373
		$site_module_info = Context::get('site_module_info');
374
		if($site_module_info->site_srl > 0)
375
		{
376
			$columnList = array('site_srl', 'group_srl');
377
			$default_group = $oMemberModel->getDefaultGroup($site_module_info->site_srl, $columnList);
378
			if($default_group->group_srl)
379
			{
380
				$this->addMemberToGroup($args->member_srl, $default_group->group_srl, $site_module_info->site_srl);
381
			}
382
383
		}
384
		// Log-in
385
		if($config->enable_confirm != 'Y')
386
		{
387
			if($config->identifier == 'email_address')
388
			{
389
				$output = $this->doLogin($args->email_address);
390
			}
391
			else
392
			{
393
				$output = $this->doLogin($args->user_id);
394
			}
395
			if(!$output->toBool()) {
396
				if($output->error == -9)
397
					$output->error = -11;
398
				return $this->setRedirectUrl(getUrl('', 'act', 'dispMemberLoginForm'), $output);
399
			}
400
		}
401
402
		// Results
403
		$this->add('member_srl', $args->member_srl);
404
		if($config->redirect_url) $this->add('redirect_url', $config->redirect_url);
405
		if($config->enable_confirm == 'Y')
406
		{
407
			$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $args->email_address);
408
			$this->setMessage($msg);
409
			return $this->setRedirectUrl(getUrl('', 'act', 'dispMemberLoginForm'), new Object(-12, $msg));
410
		}
411
		else $this->setMessage('success_registed');
412
		// Call a trigger (after)
413
		$trigger_output = ModuleHandler::triggerCall('member.procMemberInsert', 'after', $config);
414
		if(!$trigger_output->toBool()) return $trigger_output;
415
416
		if($config->redirect_url)
417
		{
418
			$returnUrl = $config->redirect_url;
419
		}
420
		else
421
		{
422
			if(Context::get('success_return_url'))
423
			{
424
				$returnUrl = Context::get('success_return_url');
425
			}
426
			else if($_COOKIE['XE_REDIRECT_URL'])
427
			{
428
				$returnUrl = $_COOKIE['XE_REDIRECT_URL'];
429
				setcookie("XE_REDIRECT_URL", '', 1);
430
			}
431
		}
432
433
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
434
435
		$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...
436
	}
437
438
	function procMemberModifyInfoBefore()
439
	{
440
		if($_SESSION['rechecked_password_step'] != 'INPUT_PASSWORD')
441
		{
442
			return $this->stop('msg_invalid_request');
443
		}
444
445
		if(!Context::get('is_logged'))
446
		{
447
			return $this->stop('msg_not_logged');
448
		}
449
450
		$password = Context::get('password');
451
452
		if(!$password)
453
		{
454
			return $this->stop('msg_invalid_request');
455
		}
456
457
		$oMemberModel = getModel('member');
458
459
		if(!$this->memberInfo->password)
460
		{
461
			// Get information of logged-in user
462
			$logged_info = Context::get('logged_info');
463
			$member_srl = $logged_info->member_srl;
464
465
			$columnList = array('member_srl', 'password');
466
			$memberInfo = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
467
			$this->memberInfo->password = $memberInfo->password;
468
		}
469
		// Verify the current password
470
		if(!$oMemberModel->isValidPassword($this->memberInfo->password, $password))
471
		{
472
			return new Object(-1, 'invalid_password');
473
		}
474
475
		$_SESSION['rechecked_password_step'] = 'VALIDATE_PASSWORD';
476
477
		if(Context::get('success_return_url'))
478
		{
479
			$redirectUrl = Context::get('success_return_url');
480
		}
481
		else
482
		{
483
			$redirectUrl = getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
484
		}
485
		$this->setRedirectUrl($redirectUrl);
486
	}
487
488
	/**
489
	 * Edit member profile
490
	 *
491
	 * @return void|Object (void : success, Object : fail)
492
	 */
493
	function procMemberModifyInfo()
494
	{
495
		if(!Context::get('is_logged'))
496
		{
497
			return $this->stop('msg_not_logged');
498
		}
499
500
		if($_SESSION['rechecked_password_step'] != 'INPUT_DATA')
501
		{
502
			return $this->stop('msg_invalid_request');
503
		}
504
		unset($_SESSION['rechecked_password_step']);
505
506
		// Extract the necessary information in advance
507
		$oMemberModel = getModel('member');
508
		$config = $oMemberModel->getMemberConfig ();
509
		$getVars = array('find_account_answer','allow_mailing','allow_message');
510 View Code Duplication
		if($config->signupForm)
511
		{
512
			foreach($config->signupForm as $formInfo)
513
			{
514
				if($formInfo->isDefaultForm && ($formInfo->isUse || $formInfo->required || $formInfo->mustRequired))
515
				{
516
					$getVars[] = $formInfo->name;
517
				}
518
			}
519
		}
520
521
		$args = new stdClass;
522 View Code Duplication
		foreach($getVars as $val)
523
		{
524
			$args->{$val} = Context::get($val);
525
			if($val == 'birthday') $args->birthday_ui = Context::get('birthday_ui');
526
		}
527
		// Login Information
528
		$logged_info = Context::get('logged_info');
529
		$args->member_srl = $logged_info->member_srl;
530
		$args->birthday = intval(strtr($args->birthday, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
531 View Code Duplication
		if(!$args->birthday && $args->birthday_ui) $args->birthday = intval(strtr($args->birthday_ui, array('-'=>'', '/'=>'', '.'=>'', ' '=>'')));
532
		// Remove some unnecessary variables from all the vars
533
		$all_args = Context::getRequestVars();
534
		unset($all_args->module);
535
		unset($all_args->act);
536
		unset($all_args->member_srl);
537
		unset($all_args->is_admin);
538
		unset($all_args->description);
539
		unset($all_args->group_srl_list);
540
		unset($all_args->body);
541
		unset($all_args->accept_agreement);
542
		unset($all_args->signature);
543
		unset($all_args->_filter);
544
		unset($all_args->mid);
545
		unset($all_args->error_return_url);
546
		unset($all_args->ruleset);
547
		unset($all_args->password);
548
549
		// Add extra vars after excluding necessary information from all the requested arguments
550
		$extra_vars = delObjectVars($all_args, $args);
551
		$args->extra_vars = serialize($extra_vars);
552
553
		// remove whitespace
554
		$checkInfos = array('user_id', 'user_name', 'nick_name', 'email_address');
555 View Code Duplication
		foreach($checkInfos as $val)
556
		{
557
			if(isset($args->{$val}))
558
			{
559
				$args->{$val} = preg_replace('/[\pZ\pC]+/u', '', $args->{$val});
560
			}
561
		}
562
563
		// Execute insert or update depending on the value of member_srl
564
		$output = $this->updateMember($args);
565
		if(!$output->toBool()) return $output;
566
567
		$profile_image = $_FILES['profile_image'];
568
		if(is_uploaded_file($profile_image['tmp_name']))
569
		{
570
			$this->insertProfileImage($args->member_srl, $profile_image['tmp_name']);
571
		}
572
573
		$image_mark = $_FILES['image_mark'];
574
		if(is_uploaded_file($image_mark['tmp_name']))
575
		{
576
			$this->insertImageMark($args->member_srl, $image_mark['tmp_name']);
577
		}
578
579
		$image_name = $_FILES['image_name'];
580
		if(is_uploaded_file($image_name['tmp_name']))
581
		{
582
			$this->insertImageName($args->member_srl, $image_name['tmp_name']);
583
		}
584
585
		// Save Signature
586
		$signature = Context::get('signature');
587
		$this->putSignature($args->member_srl, $signature);
588
589
		// Get user_id information
590
		$this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($args->member_srl);
591
592
593
		// Call a trigger after successfully log-in (after)
594
		$trigger_output = ModuleHandler::triggerCall('member.procMemberModifyInfo', 'after', $this->memberInfo);
595
		if(!$trigger_output->toBool()) return $trigger_output;
596
597
		$this->setSessionInfo();
598
		// Return result
599
		$this->add('member_srl', $args->member_srl);
600
		$this->setMessage('success_updated');
601
602
		$site_module_info = Context::get('site_module_info');
603
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
604
605
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberInfo');
606
		$this->setRedirectUrl($returnUrl);
607
	}
608
609
	/**
610
	 * Change the user password
611
	 *
612
	 * @return void|Object (void : success, Object : fail)
613
	 */
614
	function procMemberModifyPassword()
615
	{
616
		if(!Context::get('is_logged')) return $this->stop('msg_not_logged');
617
		// Extract the necessary information in advance
618
		$current_password = trim(Context::get('current_password'));
619
		$password = trim(Context::get('password1'));
620
		// Get information of logged-in user
621
		$logged_info = Context::get('logged_info');
622
		$member_srl = $logged_info->member_srl;
623
		// Create a member model object
624
		$oMemberModel = getModel('member');
625
		// Get information of member_srl
626
		$columnList = array('member_srl', 'password');
627
628
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
629
		// Verify the cuttent password
630
		if(!$oMemberModel->isValidPassword($member_info->password, $current_password, $member_srl)) return new Object(-1, 'invalid_password');
631
632
		// Check if a new password is as same as the previous password
633
		if($current_password == $password) return new Object(-1, 'invalid_new_password');
634
635
		// Execute insert or update depending on the value of member_srl
636
		$args = new stdClass;
637
		$args->member_srl = $member_srl;
638
		$args->password = $password;
639
		$output = $this->updateMemberPassword($args);
640
		if(!$output->toBool()) return $output;
641
642
		$this->add('member_srl', $args->member_srl);
643
		$this->setMessage('success_updated');
644
645
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberInfo');
646
		$this->setRedirectUrl($returnUrl);
647
	}
648
649
	/**
650
	 * Membership withdrawal
651
	 *
652
	 * @return void|Object (void : success, Object : fail)
653
	 */
654
	function procMemberLeave()
655
	{
656
		if(!Context::get('is_logged')) return $this->stop('msg_not_logged');
657
		// Extract the necessary information in advance
658
		$password = trim(Context::get('password'));
659
		// Get information of logged-in user
660
		$logged_info = Context::get('logged_info');
661
		$member_srl = $logged_info->member_srl;
662
		// Create a member model object
663
		$oMemberModel = getModel('member');
664
		// Get information of member_srl
665
		if(!$this->memberInfo->password)
666
		{
667
			$columnList = array('member_srl', 'password');
668
			$memberInfo = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
669
			$this->memberInfo->password = $memberInfo->password;
670
		}
671
		// Verify the cuttent password
672
		if(!$oMemberModel->isValidPassword($this->memberInfo->password, $password)) return new Object(-1, 'invalid_password');
673
674
		$output = $this->deleteMember($member_srl);
675
		if(!$output->toBool()) return $output;
676
		// Destroy all session information
677
		$this->destroySessionInfo();
678
		// Return success message
679
		$this->setMessage('success_leaved');
680
681
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
682
		$this->setRedirectUrl($returnUrl);
683
	}
684
685
	/**
686
	 * Add a profile image
687
	 *
688
	 * @return void|Object (void : success, Object : fail)
689
	 */
690 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...
691
	{
692
		// Check if the file is successfully uploaded
693
		$file = $_FILES['profile_image'];
694
		if(!is_uploaded_file($file['tmp_name'])) return $this->stop('msg_not_uploaded_profile_image');
695
		// Ignore if member_srl is invalid or doesn't exist.
696
		$member_srl = Context::get('member_srl');
697
		if(!$member_srl) return $this->stop('msg_not_uploaded_profile_image');
698
699
		$logged_info = Context::get('logged_info');
700
		if($logged_info->is_admin != 'Y' && $logged_info->member_srl != $member_srl) return $this->stop('msg_not_uploaded_profile_image');
701
		// Return if member module is set not to use an image name or the user is not an administrator ;
702
		$oModuleModel = getModel('module');
703
		$config = $oModuleModel->getModuleConfig('member');
704
		if($logged_info->is_admin != 'Y' && $config->profile_image != 'Y') return $this->stop('msg_not_uploaded_profile_image');
705
706
		$this->insertProfileImage($member_srl, $file['tmp_name']);
707
		// Page refresh
708
		//$this->setRefreshPage();
709
710
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
711
		$this->setRedirectUrl($returnUrl);
712
	}
713
714
	/**
715
	 * Insert a profile image
716
	 *
717
	 * @param int $member_srl
718
	 * @param object $target_file
719
	 *
720
	 * @return void
721
	 */
722
	function insertProfileImage($member_srl, $target_file)
723
	{
724
725
		// Check uploaded file
726
		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...
727
728
		$oMemberModel = getModel('member');
729
		$config = $oMemberModel->getMemberConfig();
730
731
		// Get an image size
732
		$max_width = $config->profile_image_max_width;
733
		if(!$max_width) $max_width = "90";
734
		$max_height = $config->profile_image_max_height;
735
		if(!$max_height) $max_height = "90";
736
		// Get a target path to save
737
		$target_path = sprintf('files/member_extra_info/profile_image/%s', getNumberingPath($member_srl));
738
		FileHandler::makeDir($target_path);
739
740
		// Get file information
741
		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...
742
		if(IMAGETYPE_PNG == $type) $ext = 'png';
743
		elseif(IMAGETYPE_JPEG == $type) $ext = 'jpg';
744
		elseif(IMAGETYPE_GIF == $type) $ext = 'gif';
745
		else
746
		{
747
			return;
748
		}
749
750
		FileHandler::removeFilesInDir($target_path);
751
752
		$target_filename = sprintf('%s%d.%s', $target_path, $member_srl, $ext);
753
		// Convert if the image size is larger than a given size or if the format is not a gif
754
		if(($width > $max_width || $height > $max_height ) && $type != 1)
755
		{
756
			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...
757
		}
758
		else
759
		{
760
			@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...
761
		}
762
	}
763
764
	/**
765
	 * Add an image name
766
	 *
767
	 * @return void|Object (void : success, Object : fail)
768
	 */
769 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...
770
	{
771
		// Check if the file is successfully uploaded
772
		$file = $_FILES['image_name'];
773
		if(!is_uploaded_file($file['tmp_name'])) return $this->stop('msg_not_uploaded_image_name');
774
		// Ignore if member_srl is invalid or doesn't exist.
775
		$member_srl = Context::get('member_srl');
776
		if(!$member_srl) return $this->stop('msg_not_uploaded_image_name');
777
778
		$logged_info = Context::get('logged_info');
779
		if($logged_info->is_admin != 'Y' && $logged_info->member_srl != $member_srl) return $this->stop('msg_not_uploaded_image_name');
780
		// Return if member module is set not to use an image name or the user is not an administrator ;
781
		$oModuleModel = getModel('module');
782
		$config = $oModuleModel->getModuleConfig('member');
783
		if($logged_info->is_admin != 'Y' && $config->image_name != 'Y') return $this->stop('msg_not_uploaded_image_name');
784
785
		$this->insertImageName($member_srl, $file['tmp_name']);
786
		// Page refresh
787
		//$this->setRefreshPage();
788
789
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
790
		$this->setRedirectUrl($returnUrl);
791
	}
792
793
	/**
794
	 * Insert a image name
795
	 *
796
	 * @param int $member_srl
797
	 * @param object $target_file
798
	 *
799
	 * @return void
800
	 */
801 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...
802
	{
803
		// Check uploaded file
804
		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...
805
806
		$oModuleModel = getModel('module');
807
		$config = $oModuleModel->getModuleConfig('member');
808
		// Get an image size
809
		$max_width = $config->image_name_max_width;
810
		if(!$max_width) $max_width = "90";
811
		$max_height = $config->image_name_max_height;
812
		if(!$max_height) $max_height = "20";
813
		// Get a target path to save
814
		$target_path = sprintf('files/member_extra_info/image_name/%s/', getNumberingPath($member_srl));
815
		FileHandler::makeDir($target_path);
816
817
		$target_filename = sprintf('%s%d.gif', $target_path, $member_srl);
818
		// Get file information
819
		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...
820
		// Convert if the image size is larger than a given size or if the format is not a gif
821
		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...
822
		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...
823
	}
824
825
	/**
826
	 * Delete profile image
827
	 *
828
	 * @return Object
829
	 */
830 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...
831
	{
832
		$member_srl = ($_memberSrl) ? $_memberSrl : Context::get('member_srl');
833
		if(!$member_srl)
834
		{
835
			return new Object(0,'success');
836
		}
837
838
		$logged_info = Context::get('logged_info');
839
840
		if($logged_info && ($logged_info->is_admin == 'Y' || $logged_info->member_srl == $member_srl))
841
		{
842
			$oMemberModel = getModel('member');
843
			$profile_image = $oMemberModel->getProfileImage($member_srl);
844
			FileHandler::removeFile($profile_image->file);
845
		}
846
		return new Object(0,'success');
847
	}
848
849
	/**
850
	 * Delete Image name
851
	 *
852
	 * @return void
853
	 */
854 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...
855
	{
856
		$member_srl = ($_memberSrl) ? $_memberSrl : Context::get('member_srl');
857
		if(!$member_srl)
858
		{
859
			return new Object(0,'success');
860
		}
861
862
		$logged_info = Context::get('logged_info');
863
864
		if($logged_info && ($logged_info->is_admin == 'Y' || $logged_info->member_srl == $member_srl))
865
		{
866
			$oMemberModel = getModel('member');
867
			$image_name = $oMemberModel->getImageName($member_srl);
868
			FileHandler::removeFile($image_name->file);
869
		}
870
		return new Object(0,'success');
871
	}
872
873
	/**
874
	 * Add an image to mark
875
	 *
876
	 * @return void|Object (void : success, Object : fail)
877
	 */
878 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...
879
	{
880
		// Check if the file is successfully uploaded
881
		$file = $_FILES['image_mark'];
882
		if(!is_uploaded_file($file['tmp_name'])) return $this->stop('msg_not_uploaded_image_mark');
883
		// Ignore if member_srl is invalid or doesn't exist.
884
		$member_srl = Context::get('member_srl');
885
		if(!$member_srl) return $this->stop('msg_not_uploaded_image_mark');
886
887
		$logged_info = Context::get('logged_info');
888
		if($logged_info->is_admin != 'Y' && $logged_info->member_srl != $member_srl) return $this->stop('msg_not_uploaded_image_mark');
889
		// Membership in the images mark the module using the ban was set by an administrator or return;
890
		$oModuleModel = getModel('module');
891
		$config = $oModuleModel->getModuleConfig('member');
892
		if($logged_info->is_admin != 'Y' && $config->image_mark != 'Y') return $this->stop('msg_not_uploaded_image_mark');
893
894
		$this->insertImageMark($member_srl, $file['tmp_name']);
895
		// Page refresh
896
		//$this->setRefreshPage();
897
898
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberModifyInfo');
899
		$this->setRedirectUrl($returnUrl);
900
	}
901
902
	/**
903
	 * Insert a image mark
904
	 *
905
	 * @param int $member_srl
906
	 * @param object $target_file
907
	 *
908
	 * @return void
909
	 */
910 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...
911
	{
912
		// Check uploaded file
913
		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...
914
915
		$oModuleModel = getModel('module');
916
		$config = $oModuleModel->getModuleConfig('member');
917
		// Get an image size
918
		$max_width = $config->image_mark_max_width;
919
		if(!$max_width) $max_width = "20";
920
		$max_height = $config->image_mark_max_height;
921
		if(!$max_height) $max_height = "20";
922
923
		$target_path = sprintf('files/member_extra_info/image_mark/%s/', getNumberingPath($member_srl));
924
		FileHandler::makeDir($target_path);
925
926
		$target_filename = sprintf('%s%d.gif', $target_path, $member_srl);
927
		// Get file information
928
		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...
929
930
		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...
931
		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...
932
	}
933
934
	/**
935
	 * Delete Image Mark
936
	 *
937
	 * @return Object
938
	 */
939 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...
940
	{
941
		$member_srl = ($_memberSrl) ? $_memberSrl : Context::get('member_srl');
942
		if(!$member_srl)
943
		{
944
			return new Object(0,'success');
945
		}
946
947
		$logged_info = Context::get('logged_info');
948
949
		if($logged_info && ($logged_info->is_admin == 'Y' || $logged_info->member_srl == $member_srl))
950
		{
951
			$oMemberModel = getModel('member');
952
			$image_mark = $oMemberModel->getImageMark($member_srl);
953
			FileHandler::removeFile($image_mark->file);
954
		}
955
		return new Object(0,'success');
956
	}
957
958
	/**
959
	 * Find ID/Password
960
	 *
961
	 * @return Object
962
	 */
963
	function procMemberFindAccount()
964
	{
965
		$email_address = Context::get('email_address');
966
		if(!$email_address) return new Object(-1, 'msg_invalid_request');
967
968
		$oMemberModel = getModel('member');
969
		$oModuleModel = getModel('module');
970
971
		// Check if a member having the same email address exists
972
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($email_address);
973
		if(!$member_srl) return new Object(-1, 'msg_email_not_exists');
974
975
		// Get information of the member
976
		$columnList = array('denied', 'member_srl', 'user_id', 'user_name', 'email_address', 'nick_name');
977
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
978
979
		// Check if possible to find member's ID and password
980
		if($member_info->denied == 'Y')
981
		{
982
			$chk_args = new stdClass;
983
			$chk_args->member_srl = $member_info->member_srl;
984
			$output = executeQuery('member.chkAuthMail', $chk_args);
985
			if($output->toBool() && $output->data->count != '0') return new Object(-1, 'msg_user_not_confirmed');
986
		}
987
988
		// Insert data into the authentication DB
989
		$oPassword = new Password();
990
		$args = new stdClass();
991
		$args->user_id = $member_info->user_id;
992
		$args->member_srl = $member_info->member_srl;
993
		$args->new_password = $oPassword->createTemporaryPassword(8);
994
		$args->auth_key = $oPassword->createSecureSalt(40);
995
		$args->is_register = 'N';
996
997
		$output = executeQuery('member.insertAuthMail', $args);
998
		if(!$output->toBool()) return $output;
999
		// Get content of the email to send a member
1000
		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...
1001
1002
		$member_config = $oModuleModel->getModuleConfig('member');
1003
		$memberInfo = array();
1004
		global $lang;
1005 View Code Duplication
		if(is_array($member_config->signupForm))
1006
		{
1007
			$exceptForm=array('password', 'find_account_question');
1008
			foreach($member_config->signupForm as $form)
1009
			{
1010
				if(!in_array($form->name, $exceptForm) && $form->isDefaultForm && ($form->required || $form->mustRequired))
1011
				{
1012
					$memberInfo[$lang->{$form->name}] = $member_info->{$form->name};
1013
				}
1014
			}
1015
		}
1016
		else
1017
		{
1018
			$memberInfo[$lang->user_id] = $args->user_id;
1019
			$memberInfo[$lang->user_name] = $args->user_name;
1020
			$memberInfo[$lang->nick_name] = $args->nick_name;
1021
			$memberInfo[$lang->email_address] = $args->email_address;
1022
		}
1023
		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...
1024
1025
		if(!$member_config->skin) $member_config->skin = "default";
1026
		if(!$member_config->colorset) $member_config->colorset = "white";
1027
1028
		Context::set('member_config', $member_config);
1029
1030
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
1031
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
1032
1033
		$find_url = getFullUrl ('', 'module', 'member', 'act', 'procMemberAuthAccount', 'member_srl', $member_info->member_srl, 'auth_key', $args->auth_key);
1034
		Context::set('find_url', $find_url);
1035
1036
		$oTemplate = &TemplateHandler::getInstance();
1037
		$content = $oTemplate->compile($tpl_path, 'find_member_account_mail');
1038
		// Get information of the Webmaster
1039
		$oModuleModel = getModel('module');
1040
		$member_config = $oModuleModel->getModuleConfig('member');
1041
		// Send a mail
1042
		$oMail = new Mail();
1043
		$oMail->setTitle( Context::getLang('msg_find_account_title') );
1044
		$oMail->setContent($content);
1045
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
1046
		$oMail->setReceiptor( $member_info->user_name, $member_info->email_address );
1047
		$oMail->send();
1048
		// Return message
1049
		$msg = sprintf(Context::getLang('msg_auth_mail_sent'), $member_info->email_address);
1050 View Code Duplication
		if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON')))
1051
		{
1052
			$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', 'dispMemberFindAccount');
1053
			$this->setRedirectUrl($returnUrl);
1054
		}
1055
		return new Object(0,$msg);
1056
	}
1057
1058
	/**
1059
	 * Generate a temp password by answering to the pre-determined question
1060
	 *
1061
	 * @return void|Object (void : success, Object : fail)
1062
	 */
1063
	function procMemberFindAccountByQuestion()
1064
	{
1065
		$oMemberModel = getModel('member');
1066
		$config = $oMemberModel->getMemberConfig();
1067
1068
		$email_address = Context::get('email_address');
1069
		$user_id = Context::get('user_id');
1070
		$find_account_question = trim(Context::get('find_account_question'));
1071
		$find_account_answer = trim(Context::get('find_account_answer'));
1072
1073
		if(($config->identifier == 'user_id' && !$user_id) || !$email_address || !$find_account_question || !$find_account_answer) return new Object(-1, 'msg_invalid_request');
1074
1075
		$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...
1076
		// Check if a member having the same email address exists
1077
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($email_address);
1078
		if(!$member_srl) return new Object(-1, 'msg_email_not_exists');
1079
		// Get information of the member
1080
		$columnList = array('member_srl', 'find_account_question', 'find_account_answer');
1081
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
1082
1083
		// Display a message if no answer is entered
1084
		if(!$member_info->find_account_question || !$member_info->find_account_answer) return new Object(-1, 'msg_question_not_exists');
1085
1086
		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');
1087
1088
		if($config->identifier == 'email_address')
1089
		{
1090
			$user_id = $email_address;
1091
		}
1092
1093
		// Update to a temporary password and set change_password_date to 1
1094
		$oPassword =  new Password();
1095
		$temp_password = $oPassword->createTemporaryPassword(8);
1096
1097
		$args = new stdClass();
1098
		$args->member_srl = $member_srl;
1099
		$args->password = $temp_password;
1100
		$args->change_password_date = '1';
1101
		$output = $this->updateMemberPassword($args);
1102
		if(!$output->toBool()) return $output;
1103
1104
		$_SESSION['xe_temp_password_' . $user_id] = $temp_password;
1105
1106
		$this->add('user_id',$user_id);
1107
1108
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
1109
		$this->setRedirectUrl($returnUrl.'&user_id='.$user_id);
1110
	}
1111
1112
	/**
1113
	 * Execute finding ID/Passoword
1114
	 * When clicking the link in the verification email, a method is called to change the old password and to authenticate it
1115
	 *
1116
	 * @return void|Object (void : success, Object : fail)
1117
	 */
1118
	function procMemberAuthAccount()
1119
	{
1120
		$oMemberModel = getModel('member');
1121
1122
		// Test user_id and authkey
1123
		$member_srl = Context::get('member_srl');
1124
		$auth_key = Context::get('auth_key');
1125
1126
		if(!$member_srl || !$auth_key)
1127
		{
1128
			return $this->stop('msg_invalid_request');
1129
		}
1130
1131
		// Test logs for finding password by user_id and authkey
1132
		$args = new stdClass;
1133
		$args->member_srl = $member_srl;
1134
		$args->auth_key = $auth_key;
1135
		$output = executeQuery('member.getAuthMail', $args);
1136
1137 View Code Duplication
		if(!$output->toBool() || $output->data->auth_key != $auth_key)
1138
		{
1139
			if(strlen($output->data->auth_key) !== strlen($auth_key))
1140
			{
1141
				executeQuery('member.deleteAuthMail', $args);
1142
			}
1143
1144
			return $this->stop('msg_invalid_auth_key');
1145
		}
1146
1147
		if(ztime($output->data->regdate) < $_SERVER['REQUEST_TIME'] + zgap() - 86400)
1148
		{
1149
			executeQuery('member.deleteAuthMail', $args);
1150
			return $this->stop('msg_invalid_auth_key');
1151
		}
1152
1153
		$args->password = $output->data->new_password;
1154
1155
		// If credentials are correct, change the password to a new one
1156
		if($output->data->is_register == 'Y')
1157
		{
1158
			$args->denied = 'N';
1159
		}
1160
		else
1161
		{
1162
			$args->password = $oMemberModel->hashPassword($args->password);
1163
		}
1164
1165
		// Back up the value of $Output->data->is_register
1166
		$is_register = $output->data->is_register;
1167
1168
		$output = executeQuery('member.updateMemberPassword', $args);
1169
		if(!$output->toBool())
1170
		{
1171
			return $this->stop($output->getMessage());
1172
		}
1173
1174
		// Remove all values having the member_srl from authentication table
1175
		executeQuery('member.deleteAuthMail',$args);
1176
1177
		$this->_clearMemberCache($args->member_srl);
1178
1179
		// Notify the result
1180
		Context::set('is_register', $is_register);
1181
		$this->setTemplatePath($this->module_path.'tpl');
1182
		$this->setTemplateFile('msg_success_authed');
1183
	}
1184
1185
	/**
1186
	 * Request to re-send the authentication mail
1187
	 *
1188
	 * @return void|Object (void : success, Object : fail)
1189
	 */
1190
	function procMemberResendAuthMail()
1191
	{
1192
		// Get an email_address
1193
		$email_address = Context::get('email_address');
1194
		if(!$email_address) return new Object(-1, 'msg_invalid_request');
1195
		// Log test by using email_address
1196
		$oMemberModel = getModel('member');
1197
1198
		$args = new stdClass;
1199
		$args->email_address = $email_address;
1200
		$memberSrl = $oMemberModel->getMemberSrlByEmailAddress($email_address);
1201
		if(!$memberSrl) return new Object(-1, 'msg_not_exists_member');
1202
1203
		$columnList = array('member_srl', 'user_id', 'user_name', 'nick_name', 'email_address');
1204
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($memberSrl, 0, $columnList);
1205
1206
		$oModuleModel = getModel('module');
1207
		$member_config = $oModuleModel->getModuleConfig('member');
1208
		if(!$member_config->skin) $member_config->skin = "default";
1209
		if(!$member_config->colorset) $member_config->colorset = "white";
1210
1211
		// Check if a authentication mail has been sent previously
1212
		$chk_args = new stdClass;
1213
		$chk_args->member_srl = $member_info->member_srl;
1214
		$output = executeQuery('member.chkAuthMail', $chk_args);
1215
		if($output->toBool() && $output->data->count == '0') return new Object(-1, 'msg_invalid_request');
1216
1217
		$auth_args = new stdClass;
1218
		$auth_args->member_srl = $member_info->member_srl;
1219
		$output = executeQueryArray('member.getAuthMailInfo', $auth_args);
1220
		if(!$output->data || !$output->data[0]->auth_key)  return new Object(-1, 'msg_invalid_request');
1221
		$auth_info = $output->data[0];
1222
1223
		// Update the regdate of authmail entry
1224
		$renewal_args = new stdClass;
1225
		$renewal_args->member_srl = $member_info->member_srl;
1226
		$renewal_args->auth_key = $auth_info->auth_key;
1227
		$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...
1228
1229
		$memberInfo = array();
1230
		global $lang;
1231 View Code Duplication
		if(is_array($member_config->signupForm))
1232
		{
1233
			$exceptForm=array('password', 'find_account_question');
1234
			foreach($member_config->signupForm as $form)
1235
			{
1236
				if(!in_array($form->name, $exceptForm) && $form->isDefaultForm && ($form->required || $form->mustRequired))
1237
				{
1238
					$memberInfo[$lang->{$form->name}] = $member_info->{$form->name};
1239
				}
1240
			}
1241
		}
1242
		else
1243
		{
1244
			$memberInfo[$lang->user_id] = $member_info->user_id;
1245
			$memberInfo[$lang->user_name] = $member_info->user_name;
1246
			$memberInfo[$lang->nick_name] = $member_info->nick_name;
1247
			$memberInfo[$lang->email_address] = $member_info->email_address;
1248
		}
1249
1250
		// Get content of the email to send a member
1251
		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...
1252
		Context::set('member_config', $member_config);
1253
1254
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
1255
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
1256
1257
		$auth_url = getFullUrl('','module','member','act','procMemberAuthAccount','member_srl',$member_info->member_srl, 'auth_key',$auth_info->auth_key);
1258
		Context::set('auth_url', $auth_url);
1259
1260
		$oTemplate = &TemplateHandler::getInstance();
1261
		$content = $oTemplate->compile($tpl_path, 'confirm_member_account_mail');
1262
		// Send a mail
1263
		$oMail = new Mail();
1264
		$oMail->setTitle( Context::getLang('msg_confirm_account_title') );
1265
		$oMail->setContent($content);
1266
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
1267
		$oMail->setReceiptor( $args->user_name, $args->email_address );
1268
		$oMail->send();
1269
1270
		$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $args->email_address);
1271
		$this->setMessage($msg);
1272
1273
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
1274
		$this->setRedirectUrl($returnUrl);
1275
	}
1276
1277
	function procMemberResetAuthMail()
1278
	{
1279
		$memberInfo = $_SESSION['auth_member_info'];
1280
		unset($_SESSION['auth_member_info']);
1281
1282
		if(!$memberInfo)
1283
		{
1284
			return $this->stop('msg_invalid_request');
1285
		}
1286
1287
		$newEmail = Context::get('email_address');
1288
1289
		if(!$newEmail)
1290
		{
1291
			return $this->stop('msg_invalid_request');
1292
		}
1293
1294
		$oMemberModel = getModel('member');
1295
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($newEmail);
1296
		if($member_srl)
1297
		{
1298
			return new Object(-1,'msg_exists_email_address');
1299
		}
1300
1301
		// remove all key by member_srl
1302
		$args = new stdClass;
1303
		$args->member_srl = $memberInfo->member_srl;
1304
		$output = executeQuery('member.deleteAuthMail', $args);
1305
1306
		if(!$output->toBool())
1307
		{
1308
			return $output;
1309
		}
1310
1311
		// update member info
1312
		$args->email_address = $newEmail;
1313
		list($args->email_id, $args->email_host) = explode('@', $newEmail);
1314
1315
		$output = executeQuery('member.updateMemberEmailAddress', $args);
1316
		if(!$output->toBool())
1317
		{
1318
			return $this->stop($output->getMessage());
1319
		}
1320
1321
		$this->_clearMemberCache($args->member_srl);
1322
1323
		// generate new auth key
1324
		$oPassword = new Password();
1325
		$auth_args = new stdClass();
1326
		$auth_args->user_id = $memberInfo->user_id;
1327
		$auth_args->member_srl = $memberInfo->member_srl;
1328
		$auth_args->new_password = $memberInfo->password;
1329
		$auth_args->auth_key = $oPassword->createSecureSalt(40);
1330
		$auth_args->is_register = 'Y';
1331
1332
		$output = executeQuery('member.insertAuthMail', $auth_args);
1333
		if(!$output->toBool()) return $output;
1334
1335
		$memberInfo->email_address = $newEmail;
1336
1337
		// resend auth mail.
1338
		$this->_sendAuthMail($auth_args, $memberInfo);
1339
1340
		$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $memberInfo->email_address);
1341
		$this->setMessage($msg);
1342
1343
		$returnUrl = getUrl('');
1344
		$this->setRedirectUrl($returnUrl);
1345
	}
1346
1347
	function _sendAuthMail($auth_args, $member_info)
1348
	{
1349
		$oMemberModel = getModel('member');
1350
		$member_config = $oMemberModel->getMemberConfig();
1351
		// Get content of the email to send a member
1352
		Context::set('auth_args', $auth_args);
1353
1354
		$memberInfo = array();
1355
1356
		global $lang;
1357 View Code Duplication
		if(is_array($member_config->signupForm))
1358
		{
1359
			$exceptForm=array('password', 'find_account_question');
1360
			foreach($member_config->signupForm as $form)
1361
			{
1362
				if(!in_array($form->name, $exceptForm) && $form->isDefaultForm && ($form->required || $form->mustRequired))
1363
				{
1364
					$memberInfo[$lang->{$form->name}] = $member_info->{$form->name};
1365
				}
1366
			}
1367
		}
1368
		else
1369
		{
1370
			$memberInfo[$lang->user_id] = $member_info->user_id;
1371
			$memberInfo[$lang->user_name] = $member_info->user_name;
1372
			$memberInfo[$lang->nick_name] = $member_info->nick_name;
1373
			$memberInfo[$lang->email_address] = $member_info->email_address;
1374
		}
1375
		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...
1376
1377
		if(!$member_config->skin) $member_config->skin = "default";
1378
		if(!$member_config->colorset) $member_config->colorset = "white";
1379
1380
		Context::set('member_config', $member_config);
1381
1382
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
1383
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
1384
1385
		$auth_url = getFullUrl('','module','member','act','procMemberAuthAccount','member_srl',$member_info->member_srl, 'auth_key',$auth_args->auth_key);
1386
		Context::set('auth_url', $auth_url);
1387
1388
		$oTemplate = &TemplateHandler::getInstance();
1389
		$content = $oTemplate->compile($tpl_path, 'confirm_member_account_mail');
1390
		// Send a mail
1391
		$oMail = new Mail();
1392
		$oMail->setTitle( Context::getLang('msg_confirm_account_title') );
1393
		$oMail->setContent($content);
1394
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
1395
		$oMail->setReceiptor( $member_info->user_name, $member_info->email_address );
1396
		$oMail->send();
1397
	}
1398
1399
	/**
1400
	 * Join a virtual site
1401
	 *
1402
	 * @return void|Object (void : success, Object : fail)
1403
	 */
1404
	function procMemberSiteSignUp()
1405
	{
1406
		$site_module_info = Context::get('site_module_info');
1407
		$logged_info = Context::get('logged_info');
1408 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');
1409
1410
		$oMemberModel = getModel('member');
1411
		$columnList = array('site_srl', 'group_srl', 'title');
1412
		$default_group = $oMemberModel->getDefaultGroup($site_module_info->site_srl, $columnList);
1413
		$this->addMemberToGroup($logged_info->member_srl, $default_group->group_srl, $site_module_info->site_srl);
1414
		$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...
1415
		$logged_info->group_list = $groups;
1416
	}
1417
1418
	/**
1419
	 * Leave the virtual site
1420
	 *
1421
	 * @return void|Object (void : success, Object : fail)
1422
	 */
1423
	function procMemberSiteLeave()
1424
	{
1425
		$site_module_info = Context::get('site_module_info');
1426
		$logged_info = Context::get('logged_info');
1427 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');
1428
1429
		$args = new stdClass;
1430
		$args->site_srl= $site_module_info->site_srl;
1431
		$args->member_srl = $logged_info->member_srl;
1432
		$output = executeQuery('member.deleteMembersGroup', $args);
1433
		if(!$output->toBool()) return $output;
1434
		$this->setMessage('success_deleted');
1435
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
1436
	}
1437
1438
	/**
1439
	 * Save the member configurations
1440
	 *
1441
	 * @param object $args
1442
	 *
1443
	 * @return void
1444
	 */
1445
	function setMemberConfig($args)
1446
	{
1447
		if(!$args->skin) $args->skin = "default";
1448
		if(!$args->colorset) $args->colorset = "white";
1449
		if(!$args->editor_skin) $args->editor_skin= "ckeditor";
1450
		if(!$args->editor_colorset) $args->editor_colorset = "moono";
1451
		if($args->enable_join!='Y') $args->enable_join = 'N';
1452
		$args->enable_openid= 'N';
1453
		if($args->profile_image !='Y') $args->profile_image = 'N';
1454
		if($args->image_name!='Y') $args->image_name = 'N';
1455
		if($args->image_mark!='Y') $args->image_mark = 'N';
1456
		if($args->group_image_mark!='Y') $args->group_image_mark = 'N';
1457
		if(!trim(strip_tags($args->agreement))) $args->agreement = null;
1458
		$args->limit_day = (int)$args->limit_day;
1459
1460
		$agreement = trim($args->agreement);
1461
		unset($args->agreement);
1462
1463
		$oModuleController = getController('module');
1464
		$output = $oModuleController->insertModuleConfig('member',$args);
1465
		if(!$output->toBool()) return $output;
1466
1467
		$agreement_file = _XE_PATH_.'files/member_extra_info/agreement.txt';
1468
		FileHandler::writeFile($agreement_file, $agreement);
1469
1470
		return new Object();
1471
	}
1472
1473
	/**
1474
	 * Save the signature as a file
1475
	 *
1476
	 * @param int $member_srl
1477
	 * @param string $signature
1478
	 *
1479
	 * @return void
1480
	 */
1481
	function putSignature($member_srl, $signature)
1482
	{
1483
		$signature = trim(removeHackTag($signature));
1484
		$signature = preg_replace('/<(\/?)(embed|object|param)/is', '&lt;$1$2', $signature);
1485
1486
		$check_signature = trim(str_replace(array('&nbsp;',"\n","\r"), '', strip_tags($signature, '<img><object>')));
1487
		$path = sprintf('files/member_extra_info/signature/%s/', getNumberingPath($member_srl));
1488
		$filename = sprintf('%s%d.signature.php', $path, $member_srl);
1489
1490
		if(!$check_signature) return FileHandler::removeFile($filename);
1491
1492
		$buff = sprintf('<?php if(!defined("__XE__")) exit();?>%s', $signature);
1493
		FileHandler::makeDir($path);
1494
		FileHandler::writeFile($filename, $buff);
1495
	}
1496
1497
	/**
1498
	 * Delete the signature file
1499
	 *
1500
	 * @param string $member_srl
1501
	 *
1502
	 * @return void
1503
	 */
1504
	function delSignature($member_srl)
1505
	{
1506
		$filename = sprintf('files/member_extra_info/signature/%s%d.gif', getNumberingPath($member_srl), $member_srl);
1507
		FileHandler::removeFile($filename);
1508
	}
1509
1510
	/**
1511
	 * Add group_srl to member_srl
1512
	 *
1513
	 * @param int $member_srl
1514
	 * @param int $group_srl
1515
	 * @param int $site_srl
1516
	 *
1517
	 * @return Object
1518
	 */
1519
	function addMemberToGroup($member_srl, $group_srl, $site_srl=0)
1520
	{
1521
		$args = new stdClass();
1522
		$args->member_srl = $member_srl;
1523
		$args->group_srl = $group_srl;
1524
		if($site_srl) $args->site_srl = $site_srl;
1525
1526
		// Add
1527
		$output = executeQuery('member.addMemberToGroup',$args);
1528
		$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...
1529
1530
		$this->_clearMemberCache($member_srl, $site_srl);
1531
1532
		return $output;
1533
	}
1534
1535
	/**
1536
	 * Change a group of certain members
1537
	 * Available only when a member has a single group
1538
	 *
1539
	 * @param object $args
1540
	 *
1541
	 * @return Object
1542
	 */
1543
	function replaceMemberGroup($args)
1544
	{
1545
		$obj = new stdClass;
1546
		$obj->site_srl = $args->site_srl;
1547
		$obj->member_srl = implode(',',$args->member_srl);
1548
1549
		$output = executeQueryArray('member.getMembersGroup', $obj);
1550
		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...
1551
1552
		$output = executeQuery('member.deleteMembersGroup', $obj);
1553
		if(!$output->toBool()) return $output;
1554
1555
		$inserted_members = array();
1556
		foreach($args->member_srl as $key => $val)
1557
		{
1558
			if($inserted_members[$val]) continue;
1559
			$inserted_members[$val] = true;
1560
1561
			unset($obj);
1562
			$obj = new stdClass;
1563
			$obj->member_srl = $val;
1564
			$obj->group_srl = $args->group_srl;
1565
			$obj->site_srl = $args->site_srl;
1566
			$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...
1567
			$output = executeQuery('member.addMemberToGroup', $obj);
1568
			if(!$output->toBool()) return $output;
1569
1570
			$this->_clearMemberCache($obj->member_srl, $args->site_srl);
1571
		}
1572
1573
		return new Object();
1574
	}
1575
1576
1577
	/**
1578
	 * Auto-login
1579
	 *
1580
	 * @return void
1581
	 */
1582
	function doAutologin()
1583
	{
1584
		// Get a key value of auto log-in
1585
		$args = new stdClass;
1586
		$args->autologin_key = $_COOKIE['xeak'];
1587
		// Get information of the key
1588
		$output = executeQuery('member.getAutologin', $args);
1589
		// If no information exists, delete a cookie
1590 View Code Duplication
		if(!$output->toBool() || !$output->data)
1591
		{
1592
			setCookie('xeak',null,$_SERVER['REQUEST_TIME']+60*60*24*365, '/');
1593
			return;
1594
		}
1595
1596
		$oMemberModel = getModel('member');
1597
		$config = $oMemberModel->getMemberConfig();
1598
1599
		$user_id = ($config->identifier == 'user_id') ? $output->data->user_id : $output->data->email_address;
1600
		$password = $output->data->password;
1601
1602 View Code Duplication
		if(!$user_id || !$password)
1603
		{
1604
			setCookie('xeak',null,$_SERVER['REQUEST_TIME']+60*60*24*365, '/');
1605
			return;
1606
		}
1607
1608
		$do_auto_login = false;
1609
1610
		// Compare key values based on the information
1611
		$check_key = strtolower($user_id).$password.$_SERVER['HTTP_USER_AGENT'];
1612
		$check_key = substr(hash_hmac('sha256', $check_key, substr($args->autologin_key, 0, 32)), 0, 32);
1613
1614
		if($check_key === substr($args->autologin_key, 32))
1615
		{
1616
			// Check change_password_date
1617
			$oModuleModel = getModel('module');
1618
			$member_config = $oModuleModel->getModuleConfig('member');
1619
			$limit_date = $member_config->change_password_date;
1620
1621
			// Check if change_password_date is set
1622
			if($limit_date > 0)
1623
			{
1624
				$oMemberModel = getModel('member');
1625
				$columnList = array('member_srl', 'change_password_date');
1626
1627
				if($config->identifier == 'user_id')
1628
				{
1629
					$member_info = $oMemberModel->getMemberInfoByUserID($user_id, $columnList);
1630
				}
1631
				else
1632
				{
1633
					$member_info = $oMemberModel->getMemberInfoByEmailAddress($user_id, $columnList);
1634
				}
1635
1636
				if($member_info->change_password_date >= date('YmdHis', strtotime('-'.$limit_date.' day')) ){
1637
					$do_auto_login = true;
1638
				}
1639
1640
			}
1641
			else
1642
			{
1643
				$do_auto_login = true;
1644
			}
1645
		}
1646
1647
		if($do_auto_login)
1648
		{
1649
			$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...
1650
		}
1651
		else
1652
		{
1653
			executeQuery('member.deleteAutologin', $args);
1654
			setCookie('xeak',null,$_SERVER['REQUEST_TIME']+60*60*24*365, '/');
1655
		}
1656
	}
1657
1658
	/**
1659
	 * Log-in
1660
	 *
1661
	 * @param string $user_id
1662
	 * @param string $password
1663
	 * @param boolean $keep_signed
1664
	 *
1665
	 * @return Object
1666
	 */
1667
	function doLogin($user_id, $password = '', $keep_signed = false)
1668
	{
1669
		$user_id = strtolower($user_id);
1670
		if(!$user_id) return new Object(-1, 'null_user_id');
1671
		// Call a trigger before log-in (before)
1672
		$trigger_obj = new stdClass();
1673
		$trigger_obj->user_id = $user_id;
1674
		$trigger_obj->password = $password;
1675
		$trigger_output = ModuleHandler::triggerCall('member.doLogin', 'before', $trigger_obj);
1676
		if(!$trigger_output->toBool()) return $trigger_output;
1677
		// Create a member model object
1678
		$oMemberModel = getModel('member');
1679
1680
		// check IP access count.
1681
		$config = $oMemberModel->getMemberConfig();
1682
		$args = new stdClass();
1683
		$args->ipaddress = $_SERVER['REMOTE_ADDR'];
1684
1685
		// check identifier
1686
		if($config->identifier == 'email_address')
1687
		{
1688
			// Get user_id information
1689
			$this->memberInfo = $oMemberModel->getMemberInfoByEmailAddress($user_id);
1690
			// Set an invalid user if no value returned
1691
			if(!$user_id || strtolower($this->memberInfo->email_address) != strtolower($user_id)) return $this->recordLoginError(-1, 'invalid_email_address');
1692
1693
		}
1694
		else
1695
		{
1696
			// Get user_id information
1697
			$this->memberInfo = $oMemberModel->getMemberInfoByUserID($user_id);
1698
			// Set an invalid user if no value returned
1699
			if(!$user_id || strtolower($this->memberInfo->user_id) != strtolower($user_id)) return $this->recordLoginError(-1, 'invalid_user_id');
1700
		}
1701
1702
		$output = executeQuery('member.getLoginCountByIp', $args);
1703
		$errorCount = $output->data->count;
1704
		if($errorCount >= $config->max_error_count)
1705
		{
1706
			$last_update = strtotime($output->data->last_update);
1707
			$term = intval($_SERVER['REQUEST_TIME']-$last_update);
1708
			if($term < $config->max_error_count_time)
1709
			{
1710
				$term = $config->max_error_count_time - $term;
1711
				if($term < 60) $term = intval($term).Context::getLang('unit_sec');
1712
				elseif(60 <= $term && $term < 3600) $term = intval($term/60).Context::getLang('unit_min');
1713
				elseif(3600 <= $term && $term < 86400) $term = intval($term/3600).Context::getLang('unit_hour');
1714
				else $term = intval($term/86400).Context::getLang('unit_day');
1715
1716
				return new Object(-1, sprintf(Context::getLang('excess_ip_access_count'),$term));
1717
			}
1718
			else
1719
			{
1720
				$args->ipaddress = $_SERVER['REMOTE_ADDR'];
1721
				$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...
1722
			}
1723
		}
1724
1725
		// Password Check
1726
		if($password && !$oMemberModel->isValidPassword($this->memberInfo->password, $password, $this->memberInfo->member_srl))
1727
		{
1728
			return $this->recordMemberLoginError(-1, 'invalid_password',$this->memberInfo);
1729
		}
1730
1731
		// If denied == 'Y', notify
1732
		if($this->memberInfo->denied == 'Y')
1733
		{
1734
			$args->member_srl = $this->memberInfo->member_srl;
1735
			$output = executeQuery('member.chkAuthMail', $args);
1736
			if ($output->toBool() && $output->data->count != '0')
1737
			{
1738
				$_SESSION['auth_member_srl'] = $this->memberInfo->member_srl;
1739
				$redirectUrl = getUrl('', 'act', 'dispMemberResendAuthMail');
1740
				return $this->setRedirectUrl($redirectUrl, new Object(-1,'msg_user_not_confirmed'));
1741
			}
1742
			return new Object(-1,'msg_user_denied');
1743
		}
1744
		// Notify if denied_date is less than the current time
1745
		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")));
1746
		// Update the latest login time
1747
		$args->member_srl = $this->memberInfo->member_srl;
1748
		$output = executeQuery('member.updateLastLogin', $args);
1749
1750
		$site_module_info = Context::get('site_module_info');
1751
		$this->_clearMemberCache($args->member_srl, $site_module_info->site_srl);
1752
1753
		// Check if there is recoding table.
1754
		$oDB = &DB::getInstance();
1755
		if($oDB->isTableExists('member_count_history') && $config->enable_login_fail_report != 'N')
1756
		{
1757
			// check if there is login fail records.
1758
			$output = executeQuery('member.getLoginCountHistoryByMemberSrl', $args);
1759
			if($output->data && $output->data->content)
1760
			{
1761
				$title = Context::getLang('login_fail_report');
1762
				$message = '<ul>';
1763
				$content = unserialize($output->data->content);
1764
				if(count($content) > $config->max_error_count)
1765
				{
1766
					foreach($content as $val)
1767
					{
1768
						$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>';
1769
					}
1770
					$message .= '</ul>';
1771
					$content = sprintf(Context::getLang('login_fail_report_contents'),$message,date('Y-m-d h:i:sa'));
1772
1773
					//send message
1774
					$oCommunicationController = getController('communication');
1775
					$oCommunicationController->sendMessage($args->member_srl, $args->member_srl, $title, $content, true);
1776
1777
					if($this->memberInfo->email_address && $this->memberInfo->allow_mailing == 'Y')
1778
					{
1779
						$view_url = Context::getRequestUri();
1780
						$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);
1781
						$oMail = new Mail();
1782
						$oMail->setTitle($title);
1783
						$oMail->setContent($content);
1784
						$oMail->setSender($config->webmaster_name?$config->webmaster_name:'webmaster', $config->webmaster_email);
1785
						$oMail->setReceiptor($this->memberInfo->email_id.'('.$this->memberInfo->nick_name.')', $this->memberInfo->email_address);
1786
						$oMail->send();
1787
					}
1788
					$output = executeQuery('member.deleteLoginCountHistoryByMemberSrl', $args);
1789
				}
1790
			}
1791
		}
1792
		// Call a trigger after successfully log-in (after)
1793
		$trigger_output = ModuleHandler::triggerCall('member.doLogin', 'after', $this->memberInfo);
1794
		if(!$trigger_output->toBool()) return $trigger_output;
1795
		// When user checked to use auto-login
1796
		if($keep_signed)
1797
		{
1798
			// Key generate for auto login
1799
			$oPassword = new Password();
1800
			$random_key = $oPassword->createSecureSalt(32, 'hex');
1801
			$extra_key = strtolower($user_id).$this->memberInfo->password.$_SERVER['HTTP_USER_AGENT'];
1802
			$extra_key = substr(hash_hmac('sha256', $extra_key, $random_key), 0, 32);
1803
			$autologin_args = new stdClass;
1804
			$autologin_args->autologin_key = $random_key.$extra_key;
1805
			$autologin_args->member_srl = $this->memberInfo->member_srl;
1806
			executeQuery('member.deleteAutologin', $autologin_args);
1807
			$autologin_output = executeQuery('member.insertAutologin', $autologin_args);
1808
			if($autologin_output->toBool()) setCookie('xeak',$autologin_args->autologin_key, $_SERVER['REQUEST_TIME']+31536000, '/');
1809
		}
1810
		if($this->memberInfo->is_admin == 'Y')
1811
		{
1812
			$oMemberAdminModel = getAdminModel('member');
1813
			if(!$oMemberAdminModel->getMemberAdminIPCheck())
1814
			{
1815
				$_SESSION['denied_admin'] = 'Y';
1816
			}
1817
		}
1818
1819
		$this->setSessionInfo();
1820
1821
		return $output;
1822
	}
1823
1824
	/**
1825
	 * Update or create session information
1826
	 */
1827
	function setSessionInfo()
1828
	{
1829
		$oMemberModel = getModel('member');
1830
		// If your information came through the current session information to extract information from the users
1831
		if(!$this->memberInfo && $_SESSION['member_srl'] && $oMemberModel->isLogged() )
1832
		{
1833
			$this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($_SESSION['member_srl']);
1834
			// If you do not destroy the session Profile
1835
			if($this->memberInfo->member_srl != $_SESSION['member_srl'])
1836
			{
1837
				$this->destroySessionInfo();
1838
				return;
1839
			}
1840
		}
1841
		// Stop using the session id is destroyed
1842
		if($this->memberInfo->denied=='Y')
1843
		{
1844
			$this->destroySessionInfo();
1845
			return;
1846
		}
1847
		// Log in for treatment sessions set
1848
		$_SESSION['is_logged'] = true;
1849
		$_SESSION['ipaddress'] = $_SERVER['REMOTE_ADDR'];
1850
		$_SESSION['member_srl'] = $this->memberInfo->member_srl;
1851
		$_SESSION['is_admin'] = '';
1852
		setcookie('xe_logged', 'true', 0, '/');
1853
		// Do not save your password in the session jiwojum;;
1854
		//unset($this->memberInfo->password);
1855
		// User Group Settings
1856
		/*
1857
		   if($this->memberInfo->group_list) {
1858
		   $group_srl_list = array_keys($this->memberInfo->group_list);
1859
		   $_SESSION['group_srls'] = $group_srl_list;
1860
		// If the group is designated as an administrator administrator
1861
		$oMemberModel = getModel('member');
1862
		$admin_group = $oMemberModel->getAdminGroup();
1863
		if($admin_group->group_srl && in_array($admin_group->group_srl, $group_srl_list)) $_SESSION['is_admin'] = 'Y';
1864
		}
1865
		 */
1866
1867
		// Information stored in the session login user
1868
		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...
1869
		Context::set('logged_info', $this->memberInfo);
1870
1871
		// Only the menu configuration of the user (such as an add-on to the menu can be changed)
1872
		$this->addMemberMenu( 'dispMemberInfo', 'cmd_view_member_info');
1873
		$this->addMemberMenu( 'dispMemberScrappedDocument', 'cmd_view_scrapped_document');
1874
		$this->addMemberMenu( 'dispMemberSavedDocument', 'cmd_view_saved_document');
1875
		$this->addMemberMenu( 'dispMemberOwnDocument', 'cmd_view_own_document');
1876
	}
1877
1878
	/**
1879
	 * Logged method for providing a personalized menu
1880
	 * Login information is used in the output widget, or personalized page
1881
	 */
1882
	function addMemberMenu($act, $str)
1883
	{
1884
		$logged_info = Context::get('logged_info');
1885
1886
		$logged_info->menu_list[$act] = Context::getLang($str);
1887
1888
		Context::set('logged_info', $logged_info);
1889
	}
1890
1891
	/**
1892
	 * Nickname and click Log In to add a pop-up menu that appears when the method
1893
	 */
1894 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...
1895
	{
1896
		$member_popup_menu_list = Context::get('member_popup_menu_list');
1897
		if(!is_array($member_popup_menu_list)) $member_popup_menu_list = array();
1898
1899
		$obj = new stdClass;
1900
		$obj->url = $url;
1901
		$obj->str = $str;
1902
		$obj->icon = $icon;
1903
		$obj->target = $target;
1904
		$member_popup_menu_list[] = $obj;
1905
1906
		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...
1907
	}
1908
1909
	/**
1910
	 * Add users to the member table
1911
	 */
1912
	function insertMember(&$args, $password_is_hashed = false)
1913
	{
1914
		// Call a trigger (before)
1915
		$output = ModuleHandler::triggerCall('member.insertMember', 'before', $args);
1916
		if(!$output->toBool()) return $output;
1917
		// Terms and Conditions portion of the information set up by members reaffirmed
1918
		$oModuleModel = getModel('module');
1919
		$config = $oModuleModel->getModuleConfig('member');
1920
1921
		$logged_info = Context::get('logged_info');
1922
		// If the date of the temporary restrictions limit further information on the date of
1923
		if($config->limit_day) $args->limit_date = date("YmdHis", $_SERVER['REQUEST_TIME']+$config->limit_day*60*60*24);
1924
1925
		$args->member_srl = getNextSequence();
1926
		$args->list_order = -1 * $args->member_srl;
1927
1928
		// Execute insert or update depending on the value of member_srl
1929
		if(!$args->user_id) $args->user_id = 't'.$args->member_srl;
1930
		// Enter the user's identity changed to lowercase
1931
		else $args->user_id = strtolower($args->user_id);
1932
		if(!$args->user_name) $args->user_name = $args->member_srl;
1933
		if(!$args->nick_name) $args->nick_name = $args->member_srl;
1934
1935
		// Control of essential parameters
1936
		if($args->allow_mailing!='Y') $args->allow_mailing = 'N';
1937
		if($args->denied!='Y') $args->denied = 'N';
1938 View Code Duplication
		if(!$args->allow_message || ($args->allow_message && !in_array($args->allow_message, array('Y','N','F')))) $args->allow_message = 'Y';
1939
1940
		if($logged_info->is_admin == 'Y')
1941
		{
1942
			if($args->is_admin!='Y') $args->is_admin = 'N';
1943
		}
1944
		else
1945
		{
1946
			unset($args->is_admin);
1947
		}
1948
1949
		list($args->email_id, $args->email_host) = explode('@', $args->email_address);
1950
1951
		// Sanitize user ID, username, nickname, homepage, blog
1952
		$args->user_id = htmlspecialchars($args->user_id, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
1953
		$args->user_name = htmlspecialchars($args->user_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
1954
		$args->nick_name = htmlspecialchars($args->nick_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
1955
		$args->homepage = htmlspecialchars($args->homepage, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
1956
		$args->blog = htmlspecialchars($args->blog, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
1957 View Code Duplication
		if($args->homepage && !preg_match("/^[a-z]+:\/\//i",$args->homepage)) $args->homepage = 'http://'.$args->homepage;
1958 View Code Duplication
		if($args->blog && !preg_match("/^[a-z]+:\/\//i",$args->blog)) $args->blog = 'http://'.$args->blog;
1959
1960
		// Create a model object
1961
		$oMemberModel = getModel('member');
1962
1963
		// Check password strength
1964
		if($args->password && !$password_is_hashed)
1965
		{
1966 View Code Duplication
			if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
1967
			{
1968
				$message = Context::getLang('about_password_strength');
1969
				return new Object(-1, $message[$config->password_strength]);
1970
			}
1971
			$args->password = $oMemberModel->hashPassword($args->password);
1972
		}
1973
		elseif(!$args->password)
1974
		{
1975
			unset($args->password);
1976
		}
1977
1978
		// Check if ID is prohibited
1979
		if($oMemberModel->isDeniedID($args->user_id))
1980
		{
1981
			return new Object(-1,'denied_user_id');
1982
		}
1983
1984
		// Check if ID is duplicate
1985
		$member_srl = $oMemberModel->getMemberSrlByUserID($args->user_id);
1986
		if($member_srl)
1987
		{
1988
			return new Object(-1,'msg_exists_user_id');
1989
		}
1990
1991
		// Check if nickname is prohibited
1992
		if($oMemberModel->isDeniedNickName($args->nick_name))
1993
		{
1994
			return new Object(-1,'denied_nick_name');
1995
		}
1996
1997
		// Check if nickname is duplicate
1998
		$member_srl = $oMemberModel->getMemberSrlByNickName($args->nick_name);
1999
		if($member_srl)
2000
		{
2001
			return new Object(-1,'msg_exists_nick_name');
2002
		}
2003
2004
		// Check if email address is duplicate
2005
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($args->email_address);
2006
		if($member_srl)
2007
		{
2008
			return new Object(-1,'msg_exists_email_address');
2009
		}
2010
2011
		// Insert data into the DB
2012
		$args->list_order = -1 * $args->member_srl;
2013
2014
		if(!$args->user_id) $args->user_id = 't'.$args->member_srl;
2015
		if(!$args->user_name) $args->user_name = $args->member_srl;
2016
2017
		$oDB = &DB::getInstance();
2018
		$oDB->begin();
2019
2020
		$output = executeQuery('member.insertMember', $args);
2021
		if(!$output->toBool())
2022
		{
2023
			$oDB->rollback();
2024
			return $output;
2025
		}
2026
2027 View Code Duplication
		if(is_array($args->group_srl_list)) $group_srl_list = $args->group_srl_list;
2028
		else $group_srl_list = explode('|@|', $args->group_srl_list);
2029
		// If no value is entered the default group, the value of group registration
2030
		if(!$args->group_srl_list)
2031
		{
2032
			$columnList = array('site_srl', 'group_srl');
2033
			$default_group = $oMemberModel->getDefaultGroup(0, $columnList);
2034
			if($default_group)
2035
			{
2036
				// Add to the default group
2037
				$output = $this->addMemberToGroup($args->member_srl,$default_group->group_srl);
2038
				if(!$output->toBool())
2039
				{
2040
					$oDB->rollback();
2041
					return $output;
2042
				}
2043
			}
2044
			// If the value is the value of the group entered the group registration
2045
		}
2046
		else
2047
		{
2048 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...
2049
			{
2050
				$output = $this->addMemberToGroup($args->member_srl,$group_srl_list[$i]);
2051
2052
				if(!$output->toBool())
2053
				{
2054
					$oDB->rollback();
2055
					return $output;
2056
				}
2057
			}
2058
		}
2059
2060
		$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...
2061
		// When using email authentication mode (when you subscribed members denied a) certified mail sent
2062
		if($args->denied == 'Y')
2063
		{
2064
			// Insert data into the authentication DB
2065
			$oPassword = new Password();
2066
			$auth_args = new stdClass();
2067
			$auth_args->user_id = $args->user_id;
2068
			$auth_args->member_srl = $args->member_srl;
2069
			$auth_args->new_password = $args->password;
2070
			$auth_args->auth_key = $oPassword->createSecureSalt(40);
2071
			$auth_args->is_register = 'Y';
2072
2073
			$output = executeQuery('member.insertAuthMail', $auth_args);
2074
			if(!$output->toBool())
2075
			{
2076
				$oDB->rollback();
2077
				return $output;
2078
			}
2079
			$this->_sendAuthMail($auth_args, $args);
2080
		}
2081
		// Call a trigger (after)
2082 View Code Duplication
		if($output->toBool())
2083
		{
2084
			$trigger_output = ModuleHandler::triggerCall('member.insertMember', 'after', $args);
2085
			if(!$trigger_output->toBool())
2086
			{
2087
				$oDB->rollback();
2088
				return $trigger_output;
2089
			}
2090
		}
2091
2092
		$oDB->commit(true);
2093
2094
		$output->add('member_srl', $args->member_srl);
2095
		return $output;
2096
	}
2097
2098
	/**
2099
	 * Modify member information
2100
	 *
2101
	 * @param bool $is_admin , modified 2013-11-22
2102
	 */
2103
	function updateMember($args, $is_admin = FALSE)
2104
	{
2105
		// Call a trigger (before)
2106
		$output = ModuleHandler::triggerCall('member.updateMember', 'before', $args);
2107
		if(!$output->toBool()) return $output;
2108
		// Create a model object
2109
		$oMemberModel = getModel('member');
2110
2111
		$logged_info = Context::get('logged_info');
2112
		// Get what you want to modify the original information
2113
		if(!$this->memberInfo) $this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($args->member_srl);
2114
		// Control of essential parameters
2115
		if($args->allow_mailing!='Y') $args->allow_mailing = 'N';
2116 View Code Duplication
		if($args->allow_message && !in_array($args->allow_message, array('Y','N','F'))) $args->allow_message = 'Y';
2117
2118
		if($logged_info->is_admin == 'Y')
2119
		{
2120
			if($args->denied!='Y') $args->denied = 'N';
2121
			if($args->is_admin!='Y' && $logged_info->member_srl != $args->member_srl) $args->is_admin = 'N';
2122
		}
2123
		else
2124
		{
2125
			unset($args->is_admin);
2126
			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...
2127
				unset($args->denied);
2128
			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...
2129
			{
2130
				return $this->stop('msg_invalid_request');
2131
			}
2132
		}
2133
2134
		// Sanitize user ID, username, nickname, homepage, blog
2135
		if($args->user_id) $args->user_id = htmlspecialchars($args->user_id, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2136
		$args->user_name = htmlspecialchars($args->user_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2137
		$args->nick_name = htmlspecialchars($args->nick_name, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2138
		$args->homepage = htmlspecialchars($args->homepage, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2139
		$args->blog = htmlspecialchars($args->blog, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
2140 View Code Duplication
		if($args->homepage && !preg_match("/^[a-z]+:\/\//is",$args->homepage)) $args->homepage = 'http://'.$args->homepage;
2141 View Code Duplication
		if($args->blog && !preg_match("/^[a-z]+:\/\//is",$args->blog)) $args->blog = 'http://'.$args->blog;
2142
2143
		// check member identifier form
2144
		$config = $oMemberModel->getMemberConfig();
2145
2146
		$output = executeQuery('member.getMemberInfoByMemberSrl', $args);
2147
		$orgMemberInfo = $output->data;
2148
2149
		// Check if email address or user ID is duplicate
2150
		if($config->identifier == 'email_address')
2151
		{
2152
			$member_srl = $oMemberModel->getMemberSrlByEmailAddress($args->email_address);
2153
			if($member_srl && $args->member_srl != $member_srl)
2154
			{
2155
				return new Object(-1,'msg_exists_email_address');
2156
			}
2157
			$args->email_address = $orgMemberInfo->email_address;
2158
		}
2159 View Code Duplication
		else
2160
		{
2161
			$member_srl = $oMemberModel->getMemberSrlByUserID($args->user_id);
2162
			if($member_srl && $args->member_srl != $member_srl)
2163
			{
2164
				return new Object(-1,'msg_exists_user_id');
2165
			}
2166
2167
			$args->user_id = $orgMemberInfo->user_id;
2168
		}
2169
2170
		if($logged_info->is_admin !== 'Y')
2171
		{
2172
			// Check if ID is prohibited
2173
			if($args->user_id && $oMemberModel->isDeniedID($args->user_id))
2174
			{
2175
				return new Object(-1,'denied_user_id');
2176
			}
2177
2178
			// Check if nickname is prohibited
2179
			if($args->nick_name && $oMemberModel->isDeniedNickName($args->nick_name))
2180
			{
2181
				return new Object(-1, 'denied_nick_name');
2182
			}
2183
		}
2184
2185
		// Check if ID is duplicate
2186 View Code Duplication
		if($args->user_id)
2187
		{
2188
			$member_srl = $oMemberModel->getMemberSrlByUserID($args->user_id);
2189
			if($member_srl && $args->member_srl != $member_srl)
2190
			{
2191
				return new Object(-1,'msg_exists_user_id');
2192
			}
2193
		}
2194
2195
		// Check if nickname is duplicate
2196
		$member_srl = $oMemberModel->getMemberSrlByNickName($args->nick_name);
2197
 		if($member_srl && $args->member_srl != $member_srl)
2198
 		{
2199
 			return new Object(-1,'msg_exists_nick_name');
2200
 		}
2201
2202
		list($args->email_id, $args->email_host) = explode('@', $args->email_address);
2203
2204
		$oDB = &DB::getInstance();
2205
		$oDB->begin();
2206
2207
		// Check password strength
2208
		if($args->password)
2209
		{
2210 View Code Duplication
			if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
2211
			{
2212
				$message = Context::getLang('about_password_strength');
2213
				return new Object(-1, $message[$config->password_strength]);
2214
			}
2215
			$args->password = $oMemberModel->hashPassword($args->password);
2216
		}
2217
		else
2218
		{
2219
			$args->password = $orgMemberInfo->password;
2220
		}
2221
2222
		if(!$args->user_name) $args->user_name = $orgMemberInfo->user_name;
2223
		if(!$args->user_id) $args->user_id = $orgMemberInfo->user_id;
2224
		if(!$args->nick_name) $args->nick_name = $orgMemberInfo->nick_name;
2225
		if(!$args->description) $args->description = $orgMemberInfo->description;
2226
		if(!$args->birthday) $args->birthday = '';
2227
2228
		$output = executeQuery('member.updateMember', $args);
2229
2230
		if(!$output->toBool())
2231
		{
2232
			$oDB->rollback();
2233
			return $output;
2234
		}
2235
2236
		if($args->group_srl_list)
2237
		{
2238 View Code Duplication
			if(is_array($args->group_srl_list)) $group_srl_list = $args->group_srl_list;
2239
			else $group_srl_list = explode('|@|', $args->group_srl_list);
2240
			// If the group information, group information changes
2241
			if(count($group_srl_list) > 0)
2242
			{
2243
				$args->site_srl = 0;
2244
				// One of its members to delete all the group
2245
				$output = executeQuery('member.deleteMemberGroupMember', $args);
2246
				if(!$output->toBool())
2247
				{
2248
					$oDB->rollback();
2249
					return $output;
2250
				}
2251
				// Enter one of the loop a
2252 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...
2253
				{
2254
					$output = $this->addMemberToGroup($args->member_srl,$group_srl_list[$i]);
2255
					if(!$output->toBool())
2256
					{
2257
						$oDB->rollback();
2258
						return $output;
2259
					}
2260
				}
2261
2262
				// if group is changed, point changed too.
2263
				$this->_updatePointByGroup($orgMemberInfo->member_srl, $group_srl_list);
2264
			}
2265
		}
2266
		// Call a trigger (after)
2267 View Code Duplication
		if($output->toBool()) {
2268
			$trigger_output = ModuleHandler::triggerCall('member.updateMember', 'after', $args);
2269
			if(!$trigger_output->toBool())
2270
			{
2271
				$oDB->rollback();
2272
				return $trigger_output;
2273
			}
2274
		}
2275
2276
		$oDB->commit();
2277
2278
		//remove from cache
2279
		$this->_clearMemberCache($args->member_srl, $args->site_srl);
2280
2281
		// Save Session
2282
		if(!$this->memberInfo) $this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($args->member_srl);
2283
		$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...
2284
2285
		$output->add('member_srl', $args->member_srl);
2286
		return $output;
2287
	}
2288
2289
	/**
2290
	 * Modify member password
2291
	 */
2292
	function updateMemberPassword($args)
2293
	{
2294
		if($args->password)
2295
		{
2296
2297
			// check password strength
2298
			$oMemberModel = getModel('member');
2299
			$config = $oMemberModel->getMemberConfig();
2300
2301 View Code Duplication
			if(!$oMemberModel->checkPasswordStrength($args->password, $config->password_strength))
2302
			{
2303
				$message = Context::getLang('about_password_strength');
2304
				return new Object(-1, $message[$config->password_strength]);
2305
			}
2306
2307
			$args->password = $oMemberModel->hashPassword($args->password);
2308
		}
2309
		else if($args->hashed_password)
2310
		{
2311
			$args->password = $args->hashed_password;
2312
		}
2313
2314
		$output = executeQuery('member.updateMemberPassword', $args);
2315
		if($output->toBool())
2316
		{
2317
			$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...
2318
		}
2319
2320
		$this->_clearMemberCache($args->member_srl);
2321
2322
		return $output;
2323
	}
2324
2325
	/**
2326
	 * Delete User
2327
	 */
2328
	function deleteMember($member_srl)
2329
	{
2330
		// Call a trigger (before)
2331
		$trigger_obj = new stdClass();
2332
		$trigger_obj->member_srl = $member_srl;
2333
		$output = ModuleHandler::triggerCall('member.deleteMember', 'before', $trigger_obj);
2334
		if(!$output->toBool()) return $output;
2335
		// Create a model object
2336
		$oMemberModel = getModel('member');
2337
		// Bringing the user's information
2338
		if(!$this->memberInfo || $this->memberInfo->member_srl != $member_srl || !isset($this->memberInfo->is_admin))
2339
		{
2340
			$columnList = array('member_srl', 'is_admin');
2341
			$this->memberInfo = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
2342
		}
2343
		if(!$this->memberInfo) return new Object(-1, 'msg_not_exists_member');
2344
		// If managers can not be deleted
2345
		if($this->memberInfo->is_admin == 'Y') return new Object(-1, 'msg_cannot_delete_admin');
2346
2347
		$oDB = &DB::getInstance();
2348
		$oDB->begin();
2349
2350
		$args = new stdClass();
2351
		$args->member_srl = $member_srl;
2352
		// Delete the entries in member_auth_mail
2353
		$output = executeQuery('member.deleteAuthMail', $args);
2354
		if(!$output->toBool())
2355
		{
2356
			$oDB->rollback();
2357
			return $output;
2358
		}
2359
2360
		// TODO: If the table is not an upgrade may fail.
2361
		/*
2362
		   if(!$output->toBool()) {
2363
		   $oDB->rollback();
2364
		   return $output;
2365
		   }
2366
		 */
2367
		// Delete the entries in member_group_member
2368
		$output = executeQuery('member.deleteMemberGroupMember', $args);
2369
		if(!$output->toBool())
2370
		{
2371
			$oDB->rollback();
2372
			return $output;
2373
		}
2374
		// member removed from the table
2375
		$output = executeQuery('member.deleteMember', $args);
2376
		if(!$output->toBool())
2377
		{
2378
			$oDB->rollback();
2379
			return $output;
2380
		}
2381
		// Call a trigger (after)
2382 View Code Duplication
		if($output->toBool())
2383
		{
2384
			$trigger_output = ModuleHandler::triggerCall('member.deleteMember', 'after', $trigger_obj);
2385
			if(!$trigger_output->toBool())
2386
			{
2387
				$oDB->rollback();
2388
				return $trigger_output;
2389
			}
2390
		}
2391
2392
		$oDB->commit();
2393
		// Name, image, image, mark, sign, delete
2394
		$this->procMemberDeleteImageName($member_srl);
2395
		$this->procMemberDeleteImageMark($member_srl);
2396
		$this->procMemberDeleteProfileImage($member_srl);
2397
		$this->delSignature($member_srl);
2398
2399
		$this->_clearMemberCache($member_srl);
2400
2401
		return $output;
2402
	}
2403
2404
	/**
2405
	 * Destroy all session information
2406
	 */
2407
	function destroySessionInfo()
2408
	{
2409
		if(!$_SESSION || !is_array($_SESSION)) return;
2410
2411
		$memberInfo = Context::get('logged_info');
2412
		$memberSrl = $memberInfo->member_srl;
2413
2414
		foreach($_SESSION as $key => $val)
2415
		{
2416
			$_SESSION[$key] = '';
2417
		}
2418
2419
		session_destroy();
2420
		setcookie(session_name(), '', $_SERVER['REQUEST_TIME']-42000, '/');
2421
		setcookie('sso','',$_SERVER['REQUEST_TIME']-42000, '/');
2422
		setcookie('xeak','',$_SERVER['REQUEST_TIME']-42000, '/');
2423
		setcookie('xe_logged', 'false', $_SERVER['REQUEST_TIME'] - 42000, '/');
2424
2425
		if($memberSrl || $_COOKIE['xeak'])
2426
		{
2427
			$args = new stdClass();
2428
			$args->member_srl = $memberSrl;
2429
			$args->autologin_key = $_COOKIE['xeak'];
2430
			$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...
2431
		}
2432
	}
2433
2434
	function _updatePointByGroup($memberSrl, $groupSrlList)
2435
	{
2436
		$oModuleModel = getModel('module');
2437
		$pointModuleConfig = $oModuleModel->getModuleConfig('point');
2438
		$pointGroup = $pointModuleConfig->point_group;
2439
2440
		$levelGroup = array();
2441
		if(is_array($pointGroup) && count($pointGroup)>0)
2442
		{
2443
			$levelGroup = array_flip($pointGroup);
2444
			ksort($levelGroup);
2445
		}
2446
		$maxLevel = 0;
2447
		$resultGroup = array_intersect($levelGroup, $groupSrlList);
2448
		if(count($resultGroup) > 0)
2449
			$maxLevel = max(array_flip($resultGroup));
2450
2451
		if($maxLevel > 0)
2452
		{
2453
			$oPointModel = getModel('point');
2454
			$originPoint = $oPointModel->getPoint($memberSrl);
2455
2456
			if($pointModuleConfig->level_step[$maxLevel] > $originPoint)
2457
			{
2458
				$oPointController = getController('point');
2459
				$oPointController->setPoint($memberSrl, $pointModuleConfig->level_step[$maxLevel], 'update');
2460
			}
2461
		}
2462
	}
2463
2464
	function procMemberModifyEmailAddress()
2465
	{
2466
		if(!Context::get('is_logged')) return $this->stop('msg_not_logged');
2467
2468
		$member_info = Context::get('logged_info');
2469
		$newEmail = Context::get('email_address');
2470
2471
		if(!$newEmail) return $this->stop('msg_invalid_request');
2472
2473
		$oMemberModel = getModel('member');
2474
		$member_srl = $oMemberModel->getMemberSrlByEmailAddress($newEmail);
2475
		if($member_srl) return new Object(-1,'msg_exists_email_address');
2476
2477
		if($_SESSION['rechecked_password_step'] != 'INPUT_DATA')
2478
		{
2479
			return $this->stop('msg_invalid_request');
2480
		}
2481
		unset($_SESSION['rechecked_password_step']);
2482
2483
		$oPassword = new Password();
2484
		$auth_args = new stdClass();
2485
		$auth_args->user_id = $newEmail;
2486
		$auth_args->member_srl = $member_info->member_srl;
2487
		$auth_args->auth_key = $oPassword->createSecureSalt(40);
2488
		$auth_args->new_password = 'XE_change_emaill_address';
2489
2490
		$oDB = &DB::getInstance();
2491
		$oDB->begin();
2492
		$output = executeQuery('member.insertAuthMail', $auth_args);
2493
		if(!$output->toBool())
2494
		{
2495
			$oDB->rollback();
2496
			return $output;
2497
		}
2498
2499
		$oModuleModel = getModel('module');
2500
		$member_config = $oModuleModel->getModuleConfig('member');
2501
2502
		$tpl_path = sprintf('%sskins/%s', $this->module_path, $member_config->skin);
2503
		if(!is_dir($tpl_path)) $tpl_path = sprintf('%sskins/%s', $this->module_path, 'default');
2504
2505
		global $lang;
2506
2507
		$memberInfo = array();
2508
		$memberInfo[$lang->email_address] = $member_info->email_address;
2509
		$memberInfo[$lang->nick_name] = $member_info->nick_name;
2510
2511
		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...
2512
2513
		Context::set('newEmail', $newEmail);
2514
2515
		$auth_url = getFullUrl('','module','member','act','procMemberAuthEmailAddress','member_srl',$member_info->member_srl, 'auth_key',$auth_args->auth_key);
2516
		Context::set('auth_url', $auth_url);
2517
2518
		$oTemplate = &TemplateHandler::getInstance();
2519
		$content = $oTemplate->compile($tpl_path, 'confirm_member_new_email');
2520
2521
		$oMail = new Mail();
2522
		$oMail->setTitle( Context::getLang('title_modify_email_address') );
2523
		$oMail->setContent($content);
2524
		$oMail->setSender( $member_config->webmaster_name?$member_config->webmaster_name:'webmaster', $member_config->webmaster_email);
2525
		$oMail->setReceiptor( $member_info->nick_name, $newEmail );
2526
		$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...
2527
2528
		$msg = sprintf(Context::getLang('msg_confirm_mail_sent'), $newEmail);
2529
		$this->setMessage($msg);
2530
2531
		$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'mid', Context::get('mid'), 'act', '');
2532
		$this->setRedirectUrl($returnUrl);
2533
	}
2534
2535
	function procMemberAuthEmailAddress()
2536
	{
2537
		$member_srl = Context::get('member_srl');
2538
		$auth_key = Context::get('auth_key');
2539
		if(!$member_srl || !$auth_key) return $this->stop('msg_invalid_request');
2540
2541
		// Test logs for finding password by user_id and authkey
2542
		$args = new stdClass;
2543
		$args->member_srl = $member_srl;
2544
		$args->auth_key = $auth_key;
2545
		$output = executeQuery('member.getAuthMail', $args);
2546 View Code Duplication
		if(!$output->toBool() || $output->data->auth_key != $auth_key)
2547
		{
2548
			if(strlen($output->data->auth_key) !== strlen($auth_key)) executeQuery('member.deleteAuthChangeEmailAddress', $args);
2549
			return $this->stop('msg_invalid_modify_email_auth_key');
2550
		}
2551
2552
		$newEmail = $output->data->user_id;
2553
		$args->email_address = $newEmail;
2554
		list($args->email_id, $args->email_host) = explode('@', $newEmail);
2555
2556
		$output = executeQuery('member.updateMemberEmailAddress', $args);
2557
		if(!$output->toBool()) return $this->stop($output->getMessage());
2558
2559
		// Remove all values having the member_srl and new_password equal to 'XE_change_emaill_address' from authentication table
2560
		executeQuery('member.deleteAuthChangeEmailAddress',$args);
2561
2562
		$this->_clearMemberCache($args->member_srl);
2563
2564
		// Notify the result
2565
		$this->setTemplatePath($this->module_path.'tpl');
2566
		$this->setTemplateFile('msg_success_modify_email_address');
2567
	}
2568
2569
	/**
2570
	 * trigger for document.getDocumentMenu. Append to popup menu a button for procMemberSpammerManage()
2571
	 *
2572
	 * @param array &$menu_list
2573
	 *
2574
	 * @return object
2575
	**/
2576 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...
2577
	{
2578
		if(!Context::get('is_logged')) return new Object();
2579
2580
		$logged_info = Context::get('logged_info');
2581
		$document_srl = Context::get('target_srl');
2582
2583
		$oDocumentModel = getModel('document');
2584
		$columnList = array('document_srl', 'module_srl', 'member_srl', 'ipaddress');
2585
		$oDocument = $oDocumentModel->getDocument($document_srl, false, false, $columnList);
2586
		$member_srl = $oDocument->get('member_srl');
2587
		$module_srl = $oDocument->get('module_srl');
2588
2589
		if(!$member_srl) return new Object();
2590
		if($oDocumentModel->grant->manager != 1 || $member_srl==$logged_info->member_srl) return new Object();
2591
2592
		$oDocumentController = getController('document');
2593
		$url = getUrl('','module','member','act','dispMemberSpammer','member_srl',$member_srl,'module_srl',$module_srl);
2594
		$oDocumentController->addDocumentPopupMenu($url,'cmd_spammer','','popup');
2595
2596
		return new Object();
2597
	}
2598
2599
	/**
2600
	 * trigger for comment.getCommentMenu. Append to popup menu a button for procMemberSpammerManage()
2601
	 *
2602
	 * @param array &$menu_list
2603
	 *
2604
	 * @return object
2605
	**/
2606 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...
2607
	{
2608
		if(!Context::get('is_logged')) return new Object();
2609
2610
		$logged_info = Context::get('logged_info');
2611
		$comment_srl = Context::get('target_srl');
2612
2613
		$oCommentModel = getModel('comment');
2614
		$columnList = array('comment_srl', 'module_srl', 'member_srl', 'ipaddress');
2615
		$oComment = $oCommentModel->getComment($comment_srl, FALSE, $columnList);
2616
		$module_srl = $oComment->get('module_srl');
2617
		$member_srl = $oComment->get('member_srl');
2618
2619
		if(!$member_srl) return new Object();
2620
		if($oCommentModel->grant->manager != 1 || $member_srl==$logged_info->member_srl) return new Object();
2621
2622
		$oCommentController = getController('comment');
2623
		$url = getUrl('','module','member','act','dispMemberSpammer','member_srl',$member_srl,'module_srl',$module_srl);
2624
		$oCommentController->addCommentPopupMenu($url,'cmd_spammer','','popup');
2625
2626
		return new Object();
2627
	}
2628
2629
	/**
2630
	 * Spammer manage. Denied user login. And delete or trash all documents. Response Ajax string
2631
	 *
2632
	 * @return object
2633
	**/
2634
	function procMemberSpammerManage()
2635
	{
2636
		if(!Context::get('is_logged')) return new Object(-1,'msg_not_permitted');
2637
2638
		$logged_info = Context::get('logged_info');
2639
		$member_srl = Context::get('member_srl');
2640
		$module_srl = Context::get('module_srl');
2641
		$cnt_loop = Context::get('cnt_loop');
2642
		$proc_type = Context::get('proc_type');
2643
		$isMoveToTrash = true;
2644
		if($proc_type == "delete")
2645
			$isMoveToTrash = false;
2646
2647
		// check grant
2648
		$oModuleModel = getModel('module');
2649
		$columnList = array('module_srl', 'module');
2650
		$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl, $columnList);
2651
		$grant = $oModuleModel->getGrant($module_info, $logged_info);
2652
2653
		if(!$grant->manager) return new Object(-1,'msg_not_permitted');
2654
2655
		$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...
2656
2657
		$oDocumentModel = getModel('document');
2658
		$oCommentModel = getModel('comment');
2659
2660
		// delete or trash destination
2661
		// proc member
2662
		if($cnt_loop == 1)
2663
			$this->_spammerMember($member_srl);
2664
		// proc document and comment
2665
		elseif($cnt_loop>1)
2666
			$this->_spammerDocuments($member_srl, $isMoveToTrash);
2667
2668
		// get destination count
2669
		$cnt_document = $oDocumentModel->getDocumentCountByMemberSrl($member_srl);
2670
		$cnt_comment = $oCommentModel->getCommentCountByMemberSrl($member_srl);
2671
2672
		$total_count = Context::get('total_count');
2673
		$remain_count = $cnt_document + $cnt_comment;
2674
		if($cnt_loop == 1) $total_count = $remain_count;
2675
2676
		// get progress percent
2677
		if($total_count > 0)
2678
			$progress = intval( ( ( $total_count - $remain_count ) / $total_count ) * 100 );
2679
		else
2680
			$progress = 100;
2681
2682
		$this->add('total_count', $total_count);
2683
		$this->add('remain_count', $remain_count);
2684
		$this->add('progress', $progress);
2685
		$this->add('member_srl', $member_srl);
2686
		$this->add('module_srl', $module_srl);
2687
		$this->add('cnt_loop', ++$cnt_loop);
2688
		$this->add('proc_type', $proc_type);
2689
2690
		return new Object(0);
2691
	}
2692
2693
	/**
2694
	 * Denied user login and write description
2695
	 *
2696
	 * @param int $member_srl
2697
	 *
2698
	 * @return object
2699
	**/
2700
	private function _spammerMember($member_srl) {
2701
		$logged_info = Context::get('logged_info');
2702
		$spam_description = trim( Context::get('spam_description') );
2703
2704
		$oMemberModel = getModel('member');
2705
		$columnList = array('member_srl', 'email_address', 'user_id', 'nick_name', 'description');
2706
		// get member current infomation
2707
		$member_info = $oMemberModel->getMemberInfoByMemberSrl($member_srl, 0, $columnList);
2708
2709
		$oDocumentModel = getModel('document');
2710
		$oCommentModel = getModel('comment');
2711
		$cnt_comment = $oCommentModel->getCommentCountByMemberSrl($member_srl);
2712
		$cnt_document = $oDocumentModel->getDocumentCountByMemberSrl($member_srl);
2713
		$total_count = $cnt_comment + $cnt_document;
2714
2715
		$args = new stdClass();
2716
		$args->member_srl = $member_info->member_srl;
2717
		$args->email_address = $member_info->email_address;
2718
		$args->user_id = $member_info->user_id;
2719
		$args->nick_name = $member_info->nick_name;
2720
		$args->denied = "Y";
2721
		$args->description = trim( $member_info->description );
2722
		if( $args->description != "" ) $args->description .= "\n";	// add new line
2723
2724
		$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 . "]";
2725
2726
		$output = $this->updateMember($args, true);
2727
2728
		$this->_clearMemberCache($args->member_srl);
2729
2730
		return $output;
2731
	}
2732
2733
	/**
2734
	 * Delete or trash all documents
2735
	 *
2736
	 * @param int $member_srl
2737
	 * @param bool $isMoveToTrash
2738
	 *
2739
	 * @return object
2740
	**/
2741
	private function _spammerDocuments($member_srl, $isMoveToTrash) {
2742
		$oDocumentController = getController('document');
2743
		$oDocumentModel = getModel('document');
2744
		$oCommentController = getController('comment');
2745
		$oCommentModel = getModel('comment');
2746
2747
		// delete count by one request
2748
		$getContentsCount = 10;
2749
2750
		// 1. proc comment, 2. proc document
2751
		$cnt_comment = $oCommentModel->getCommentCountByMemberSrl($member_srl);
2752
		$cnt_document = $oDocumentModel->getDocumentCountByMemberSrl($member_srl);
2753
		if($cnt_comment > 0)
2754
		{
2755
			$columnList = array();
2756
			$commentList = $oCommentModel->getCommentListByMemberSrl($member_srl, $columnList, 0, false, $getContentsCount);
2757
			if($commentList) {
2758
				foreach($commentList as $v) {
2759
					$oCommentController->deleteComment($v->comment_srl, true, $isMoveToTrash);
2760
				}
2761
			}
2762
		} elseif($cnt_document > 0) {
2763
			$columnList = array();
2764
			$documentList = $oDocumentModel->getDocumentListByMemberSrl($member_srl, $columnList, 0, false, $getContentsCount);
2765
			if($documentList) {
2766
				foreach($documentList as $v) {
2767
					if($isMoveToTrash) $oDocumentController->moveDocumentToTrash($v);
2768
					else $oDocumentController->deleteDocument($v->document_srl);
2769
				}
2770
			}
2771
		}
2772
2773
		return array();
2774
	}
2775
2776
	function _clearMemberCache($member_srl, $site_srl = 0)
2777
	{
2778
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
2779
		if($oCacheHandler->isSupport())
2780
		{
2781
			$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_' . $site_srl;
2782
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
2783
			$oCacheHandler->delete($cache_key);
2784
2785
			if($site_srl !== 0)
2786
			{
2787
				$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_0';
2788
				$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
2789
				$oCacheHandler->delete($cache_key);
2790
			}
2791
		}
2792
2793
		$oCacheHandler = CacheHandler::getInstance('object');
2794
		if($oCacheHandler->isSupport())
2795
		{
2796
			$object_key = 'member_info:' . getNumberingPath($member_srl) . $member_srl;
2797
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
2798
			$oCacheHandler->delete($cache_key);
2799
		}
2800
	}
2801
}
2802
/* End of file member.controller.php */
2803
/* Location: ./modules/member/member.controller.php */
2804