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
Pull Request — develop (#1930)
by
unknown
13:51
created

memberModel::getImageMark()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
nc 3
nop 1
dl 19
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  memberModel
5
 * @author NAVER ([email protected])
6
 * @brief Model class of the member module
7
 */
8
class memberModel extends member
9
{
10
	/**
11
	 * @brief Keep data internally which may be frequently called ...
12
	 */
13
	var $join_form_list = NULL;
14
15
	/**
16
	 * @brief Initialization
17
	 */
18
	function init()
19
	{
20
	}
21
22
	/**
23
	 * @brief Return member's configuration
24
	 */
25
	function getMemberConfig()
26
	{
27
		static $member_config;
28
29
		if($member_config)
30
		{
31
			return $member_config;
32
		}
33
34
		// Get member configuration stored in the DB
35
		$oModuleModel = getModel('module');
36
		$config = $oModuleModel->getModuleConfig('member');
37
38
		if(!$config->signupForm || !is_array($config->signupForm))
39
		{
40
			$oMemberAdminController = getAdminController('member');
41
			$identifier = ($config->identifier) ? $config->identifier : 'email_address';
42
			$config->signupForm = $oMemberAdminController->createSignupForm($identifier);
43
		}
44
		//for multi language
45
		foreach($config->signupForm AS $key=>$value)
46
		{
47
			$config->signupForm[$key]->title = ($value->isDefaultForm) ? Context::getLang($value->name) : $value->title;
48
			if($config->signupForm[$key]->isPublic != 'N') $config->signupForm[$key]->isPublic = 'Y';
49
			if($value->name == 'find_account_question') $config->signupForm[$key]->isPublic = 'N';
50
		}
51
52
		// Get terms of user
53
		$config->agreement = memberModel::_getAgreement();
54
55
		if(!$config->webmaster_name) $config->webmaster_name = 'webmaster';
56
		if(!$config->image_name_max_width) $config->image_name_max_width = 90;
57
		if(!$config->image_name_max_height) $config->image_name_max_height = 20;
58
		if(!$config->image_mark_max_width) $config->image_mark_max_width = 20;
59
		if(!$config->image_mark_max_height) $config->image_mark_max_height = 20;
60
		if(!$config->profile_image_max_width) $config->profile_image_max_width = 90;
61
		if(!$config->profile_image_max_height) $config->profile_image_max_height = 90;
62
		if(!$config->skin) $config->skin = 'default';
63
		if(!$config->colorset) $config->colorset = 'white';
64
		if(!$config->editor_skin || $config->editor_skin == 'default') $config->editor_skin = 'ckeditor';
65
		if(!$config->group_image_mark) $config->group_image_mark = "N";
66
67
		if(!$config->identifier) $config->identifier = 'user_id';
68
69
		if(!$config->max_error_count) $config->max_error_count = 10;
70
		if(!$config->max_error_count_time) $config->max_error_count_time = 300;
71
72
		if(!$config->signature_editor_skin || $config->signature_editor_skin == 'default') $config->signature_editor_skin = 'ckeditor';
73
		if(!$config->sel_editor_colorset) $config->sel_editor_colorset = 'moono';
74
75
		$member_config = $config;
76
77
		return $config;
78
	}
79
80
	function _getAgreement()
81
	{
82
		$agreement_file = _XE_PATH_.'files/member_extra_info/agreement_' . Context::get('lang_type') . '.txt';
83
		if(is_readable($agreement_file))
84
		{
85
			return FileHandler::readFile($agreement_file);
86
		}
87
88
		$db_info = Context::getDBInfo();
89
		$agreement_file = _XE_PATH_.'files/member_extra_info/agreement_' . $db_info->lang_type . '.txt';
90
		if(is_readable($agreement_file))
91
		{
92
			return FileHandler::readFile($agreement_file);
93
		}
94
95
		$lang_selected = Context::loadLangSelected();
96
		foreach($lang_selected as $key => $val)
0 ignored issues
show
Bug introduced by
The expression $lang_selected of type array|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
97
		{
98
			$agreement_file = _XE_PATH_.'files/member_extra_info/agreement_' . $key . '.txt';
99
			if(is_readable($agreement_file))
100
			{
101
				return FileHandler::readFile($agreement_file);
102
			}
103
		}
104
105
		return null;
106
	}
107
108
	/**
109
	 * @brief Display menus of the member
110
	 */
111
	function getMemberMenu()
112
	{
113
		// Get member_srl of he target member and logged info of the current user
114
		$member_srl = Context::get('target_srl');
115
		$mid = Context::get('cur_mid');
116
		$logged_info = Context::get('logged_info');
117
		$act = Context::get('cur_act');
0 ignored issues
show
Unused Code introduced by
$act 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...
118
		// When click user's own nickname
119
		if($member_srl == $logged_info->member_srl) $member_info = $logged_info;
120
		// When click other's nickname
121
		else $member_info = $this->getMemberInfoByMemberSrl($member_srl);
122
123
		$member_srl = $member_info->member_srl;
124
		if(!$member_srl) return;
125
		// List variables
126
		$user_id = $member_info->user_id;
0 ignored issues
show
Unused Code introduced by
$user_id 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...
127
		$user_name = $member_info->user_name;
0 ignored issues
show
Unused Code introduced by
$user_name 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...
128
129
		ModuleHandler::triggerCall('member.getMemberMenu', 'before', $null);
130
131
		$oMemberController = getController('member');
132
		// Display member information (Don't display to non-logged user)
133
		if($logged_info->member_srl)
134
		{
135
			$url = getUrl('','mid',$mid,'act','dispMemberInfo','member_srl',$member_srl);
136
			$oMemberController->addMemberPopupMenu($url,'cmd_view_member_info',$icon_path,'self');
0 ignored issues
show
Bug introduced by
The variable $icon_path does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
137
		}
138
		// When click other's nickname
139
		if($member_srl != $logged_info->member_srl && $logged_info->member_srl)
140
		{
141
			// Get email config
142
			foreach($this->module_config->signupForm as $field)
0 ignored issues
show
Bug introduced by
The property module_config cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
143
			{
144
				if($field->name == 'email_address')
145
				{
146
					$email_config = $field;
147
					break;
148
				}
149
			}
150
151
			// Send an email only if email address is public
152
			if(($logged_info->is_admin == 'Y' || $email_config->isPublic == 'Y') && $member_info->email_address)
0 ignored issues
show
Bug introduced by
The variable $email_config 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...
153
			{
154
				$url = 'mailto:'.htmlspecialchars($member_info->email_address, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
155
				$oMemberController->addMemberPopupMenu($url,'cmd_send_email',$icon_path);
156
			}
157
		}
158
		// View homepage info
159
		if($member_info->homepage)
160
			$oMemberController->addMemberPopupMenu(htmlspecialchars($member_info->homepage, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), 'homepage', '', 'blank');
161
		// View blog info
162
		if($member_info->blog)
163
			$oMemberController->addMemberPopupMenu(htmlspecialchars($member_info->blog, ENT_COMPAT | ENT_HTML401, 'UTF-8', false), 'blog', '', 'blank');
164
		// Call a trigger (after)
165
		ModuleHandler::triggerCall('member.getMemberMenu', 'after', $null);
166
		// Display a menu for editting member info to a top administrator
167
		if($logged_info->is_admin == 'Y')
168
		{
169
			$url = getUrl('','module','admin','act','dispMemberAdminInsert','member_srl',$member_srl);
170
			$oMemberController->addMemberPopupMenu($url,'cmd_manage_member_info',$icon_path,'MemberModifyInfo');
171
172
			$url = getUrl('','module','admin','act','dispDocumentAdminList','search_target','member_srl','search_keyword',$member_srl);
173
			$oMemberController->addMemberPopupMenu($url,'cmd_trace_document',$icon_path,'TraceMemberDocument');
174
175
			$url = getUrl('','module','admin','act','dispCommentAdminList','search_target','member_srl','search_keyword',$member_srl);
176
			$oMemberController->addMemberPopupMenu($url,'cmd_trace_comment',$icon_path,'TraceMemberComment');
177
		}
178
		// Change a language of pop-up menu
179
		$menus = Context::get('member_popup_menu_list');
180
		$menus_count = count($menus);
181 View Code Duplication
		for($i=0;$i<$menus_count;$i++)
182
		{
183
			$menus[$i]->str = Context::getLang($menus[$i]->str);
184
		}
185
		// Get a list of finalized pop-up menu
186
		$this->add('menus', $menus);
187
	}
188
189
	/**
190
	 * @brief Check if logged-in
191
	 */
192
	function isLogged() {
193
		if($_SESSION['is_logged'])
194
		{
195
			if(Mobile::isFromMobilePhone())
196
			{
197
				return true;
198
			}
199
			else
200
			{
201
				if(ip2long($_SESSION['ipaddress']) >> 8 == ip2long($_SERVER['REMOTE_ADDR']) >> 8)
202
				{
203
					return true;
204
				}
205
			}
206
		}
207
208
		$_SESSION['is_logged'] = false;
209
		return false;
210
	}
211
212
	/**
213
	 * @brief Return session information of the logged-in user
214
	 */
215
	function getLoggedInfo()
216
	{
217
		// Return session info if session info is requested and the user is logged-in
218
		if($this->isLogged())
219
		{
220
			$logged_info = Context::get('logged_info');
221
			// Admin/Group list defined depending on site_module_info
222
			$site_module_info = Context::get('site_module_info');
223
			if($site_module_info->site_srl)
224
			{
225
				$logged_info->group_list = $this->getMemberGroups($logged_info->member_srl, $site_module_info->site_srl);
226
				// Add is_site_admin bool variable into logged_info if site_administrator is
227
				$oModuleModel = getModel('module');
228
				if($oModuleModel->isSiteAdmin($logged_info)) $logged_info->is_site_admin = true;
229
				else $logged_info->is_site_admin = false;
230
			}
231
			else
232
			{
233
				// Register a default group if the site doesn't have a member group
234
				if(count($logged_info->group_list) === 0)
235
				{
236
					$default_group = $this->getDefaultGroup(0);
237
					$oMemberController = getController('member');
238
					$oMemberController->addMemberToGroup($logged_info->member_srl, $default_group->group_srl, 0);
239
					$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...
240
					$logged_info->group_list = $groups;
241
				}
242
243
				$logged_info->is_site_admin = false;
244
			}
245
			Context::set('logged_info', $logged_info);
246
247
			return $logged_info;
248
		}
249
		return NULL;
250
	}
251
252
	/**
253
	 * @brief Return member information with user_id
254
	 */
255
	function getMemberInfoByUserID($user_id, $columnList = array())
0 ignored issues
show
Unused Code introduced by
The parameter $columnList 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...
256
	{
257
		if(!$user_id) return;
258
259
		$args = new stdClass;
260
		$args->user_id = $user_id;
261
		$output = executeQuery('member.getMemberInfo', $args);
262
		if(!$output->toBool()) return $output;
263
		if(!$output->data) return;
264
265
		$member_info = $this->arrangeMemberInfo($output->data);
266
267
		return $member_info;
268
	}
269
270
	/**
271
	 * @brief Return member information with email_address
272
	 */
273
	function getMemberInfoByEmailAddress($email_address)
274
	{
275
		if(!$email_address) return;
276
277
		$args = new stdClass();
278
		
279
		$db_info = Context::getDBInfo ();
280
		if($db_info->master_db['db_type'] == "cubrid")
281
		{
282
			$args->email_address = strtolower($email_address);
283
			$output = executeQuery('member.getMemberInfoByEmailAddressForCubrid', $args);
284
		}
285
		else
286
		{
287
			$args->email_address = $email_address;
288
			$output = executeQuery('member.getMemberInfoByEmailAddress', $args);
289
		}
290
		
291
		if(!$output->toBool()) return $output;
292
		if(!$output->data) return;
293
294
		$member_info = $this->arrangeMemberInfo($output->data);
295
		return $member_info;
296
	}
297
298
	/**
299
	 * @brief Return member information with member_srl
300
	 */
301
	function getMemberInfoByMemberSrl($member_srl, $site_srl = 0, $columnList = array())
302
	{
303
		if(!$member_srl) return;
304
305
		//columnList size zero... get full member info
306
		if(!$GLOBALS['__member_info__'][$member_srl] || count($columnList) == 0)
307
		{
308
			$GLOBALS['__member_info__'][$member_srl] = false;
309
310
			$oCacheHandler = CacheHandler::getInstance('object');
311
			if($oCacheHandler->isSupport())
312
			{
313
				$columnList = array();
314
				$object_key = 'member_info:' . getNumberingPath($member_srl) . $member_srl;
315
				$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
316
				$GLOBALS['__member_info__'][$member_srl] = $oCacheHandler->get($cache_key);
317
			}
318
319
			if($GLOBALS['__member_info__'][$member_srl] === false)
320
			{
321
				$args = new stdClass();
322
				$args->member_srl = $member_srl;
323
				$output = executeQuery('member.getMemberInfoByMemberSrl', $args, $columnList);
324
				if(!$output->data) 
325
				{
326
					if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, new stdClass);
0 ignored issues
show
Bug introduced by
The variable $cache_key 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...
327
					return;
328
				}
329
				$this->arrangeMemberInfo($output->data, $site_srl);
330
331
				//insert in cache
332
				if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $GLOBALS['__member_info__'][$member_srl]);
333
			}
334
		}
335
336
		return $GLOBALS['__member_info__'][$member_srl];
337
	}
338
339
	/**
340
	 * @brief Add member info from extra_vars and other information
341
	 */
342
	function arrangeMemberInfo($info, $site_srl = 0)
343
	{
344
		if(!$GLOBALS['__member_info__'][$info->member_srl])
345
		{
346
			$oModuleModel = getModel('module');
347
			$config = $oModuleModel->getModuleConfig('member');
348
349
350
			$info->profile_image = $this->getProfileImage($info->member_srl);
351
			$info->image_name = $this->getImageName($info->member_srl);
352
			$info->image_mark = $this->getImageMark($info->member_srl);
353
			if($config->group_image_mark=='Y')
354
			{
355
				$info->group_mark = $this->getGroupImageMark($info->member_srl,$site_srl);
356
			}
357
			$info->signature = $this->getSignature($info->member_srl);
358
			$info->group_list = $this->getMemberGroups($info->member_srl, $site_srl);
359
360
			$extra_vars = unserialize($info->extra_vars);
361
			unset($info->extra_vars);
362
			if($extra_vars)
363
			{
364
				foreach($extra_vars as $key => $val)
365
				{
366 View Code Duplication
					if(!is_array($val) && strpos($val, '|@|') !== FALSE) $val = explode('|@|', $val);
367
					if(!$info->{$key}) $info->{$key} = $val;
368
				}
369
			}
370
371
			if(strlen($info->find_account_answer) == 32 && preg_match('/[a-zA-Z0-9]+/', $info->find_account_answer))
372
			{
373
				$info->find_account_answer = null;
374
			}
375
376
			// XSS defence
377
			$oSecurity = new Security($info);
378
			$oSecurity->encodeHTML('user_id', 'user_name', 'nick_name', 'find_account_answer', 'description', 'address.', 'group_list..');
379
380
			$info->homepage = strip_tags($info->homepage);
381
			$info->blog = strip_tags($info->blog);
382
383
			if($extra_vars)
384
			{
385
				foreach($extra_vars as $key => $val)
386
				{
387
					if(is_array($val))
388
					{
389
						$oSecurity->encodeHTML($key . '.');
390
					}
391
					else
392
					{
393
						$oSecurity->encodeHTML($key);
394
					}
395
				}
396
			}
397
398
			// Check format.
399
			$oValidator = new Validator();
400
			if(!$oValidator->applyRule('url', $info->homepage))
401
			{
402
				$info->homepage = '';
403
			}
404
405
			if(!$oValidator->applyRule('url', $info->blog))
406
			{
407
				$info->blog = '';
408
			}
409
410
			$GLOBALS['__member_info__'][$info->member_srl] = $info;
411
		}
412
413
		return $GLOBALS['__member_info__'][$info->member_srl];
414
	}
415
416
	/**
417
	 * @brief Get member_srl corresponding to userid
418
	 */
419
	function getMemberSrlByUserID($user_id)
420
	{
421
		$args = new stdClass();
422
		$args->user_id = $user_id;
423
		$output = executeQuery('member.getMemberSrl', $args);
424
		return $output->data->member_srl;
425
	}
426
427
	/**
428
	 * @brief Get member_srl corresponding to EmailAddress
429
	 */
430
	function getMemberSrlByEmailAddress($email_address)
431
	{
432
		$args = new stdClass();
433
		$args->email_address = $email_address;
434
		$output = executeQuery('member.getMemberSrl', $args);
435
		return $output->data->member_srl;
436
	}
437
438
	/**
439
	 * @brief Get member_srl corresponding to nickname
440
	 */
441
	function getMemberSrlByNickName($nick_name)
442
	{
443
		$args = new stdClass();
444
		$args->nick_name = $nick_name;
445
		$output = executeQuery('member.getMemberSrl', $args);
446
		return $output->data->member_srl;
447
	}
448
449
	/**
450
	 * @brief Return member_srl of the current logged-in user
451
	 */
452
	function getLoggedMemberSrl()
453
	{
454
		if(!$this->isLogged()) return;
455
		return $_SESSION['member_srl'];
456
	}
457
458
	/**
459
	 * @brief Return user_id of the current logged-in user
460
	 */
461
	function getLoggedUserID()
462
	{
463
		if(!$this->isLogged()) return;
464
		$logged_info = Context::get('logged_info');
465
		return $logged_info->user_id;
466
	}
467
468
	/**
469
	 * @brief Get a list of groups which the member_srl belongs to
470
	 */
471
	function getMemberGroups($member_srl, $site_srl = 0, $force_reload = false)
472
	{
473
		static $member_groups = array();
474
475
		// cache controll
476
		$group_list = false;
477
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
478 View Code Duplication
		if($oCacheHandler->isSupport())
479
		{
480
			$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_'.$site_srl;
481
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
482
			$group_list = $oCacheHandler->get($cache_key);
483
		}
484
485
		if(!$member_groups[$member_srl][$site_srl] || $force_reload)
486
		{
487
			if($group_list === false)
488
			{
489
				$args = new stdClass();
490
				$args->member_srl = $member_srl;
491
				$args->site_srl = $site_srl;
492
				$output = executeQueryArray('member.getMemberGroups', $args);
493
				$group_list = $output->data;
494
				//insert in cache
495
				if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $group_list);
0 ignored issues
show
Bug introduced by
The variable $cache_key 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...
496
			}
497
			if(!$group_list) return array();
498
499
			foreach($group_list as $group)
500
			{
501
				$result[$group->group_srl] = $group->title;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = 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...
502
			}
503
			$member_groups[$member_srl][$site_srl] = $result;
0 ignored issues
show
Bug introduced by
The variable $result 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...
504
		}
505
		return $member_groups[$member_srl][$site_srl];
506
	}
507
508
	/**
509
	 * @brief Get a list of groups which member_srls belong to
510
	 */
511
	function getMembersGroups($member_srls, $site_srl = 0)
512
	{
513
		$args->member_srls = implode(',',$member_srls);
0 ignored issues
show
Bug introduced by
The variable $args does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
514
		$args->site_srl = $site_srl;
515
		$args->sort_index = 'list_order';
516
		$output = executeQueryArray('member.getMembersGroups', $args);
517
		if(!$output->data) return array();
518
519
		$result = array();
520
		foreach($output->data as $key=>$val)
521
		{
522
			$result[$val->member_srl][] = $val->title;
523
		}
524
		return $result;
525
	}
526
527
	/**
528
	 * @brief Get a default group
529
	 */
530
	function getDefaultGroup($site_srl = 0, $columnList = array())
531
	{
532
		$default_group = false;
533
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
534
		if($oCacheHandler->isSupport())
535
		{
536
			$columnList = array();
537
			$object_key = 'default_group_' . $site_srl;
538
			$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
539
			$default_group = $oCacheHandler->get($cache_key);
540
		}
541
542
		if($default_group === false)
543
		{
544
			$args = new stdClass();
545
			$args->site_srl = $site_srl;
546
			$output = executeQuery('member.getDefaultGroup', $args, $columnList);
547
			$default_group = $output->data;
548
			if($oCacheHandler->isSupport())
549
			{
550
				$oCacheHandler->put($cache_key, $default_group);
0 ignored issues
show
Bug introduced by
The variable $cache_key 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...
551
			}
552
		}
553
554
		return $default_group;
555
	}
556
557
	/**
558
	 * @brief Get an admin group
559
	 */
560
	function getAdminGroup($columnList = array())
561
	{
562
		$output = executeQuery('member.getAdminGroup', $args, $columnList);
0 ignored issues
show
Bug introduced by
The variable $args does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
563
		return $output->data;
564
	}
565
566
	/**
567
	 * @brief Get group info corresponding to group_srl
568
	 */
569
	function getGroup($group_srl, $columnList = array())
570
	{
571
		$args = new stdClass;
572
		$args->group_srl = $group_srl;
573
		$output = executeQuery('member.getGroup', $args, $columnList);
574
		return $output->data;
575
	}
576
577
	/**
578
	 * @brief Get a list of groups
579
	 */
580
	function getGroups($site_srl = 0)
581
	{
582
		if(!$GLOBALS['__group_info__'][$site_srl])
583
		{
584
			$result = array();
585
586
			if(!isset($site_srl))
587
			{
588
				$site_srl = 0;
589
			}
590
591
			$group_list = false;
592
			$oCacheHandler = CacheHandler::getInstance('object', null, true);
593
			if($oCacheHandler->isSupport())
594
			{
595
				$object_key = 'member_groups:site_'.$site_srl;
596
				$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
597
				$group_list = $oCacheHandler->get($cache_key);
598
			}
599
600
			if($group_list === false)
601
			{
602
				$args = new stdClass();
603
				$args->site_srl = $site_srl;
604
				$args->sort_index = 'list_order';
605
				$args->order_type = 'asc';
606
				$output = executeQueryArray('member.getGroups', $args);
607
				$group_list = $output->data;
608
				//insert in cache
609
				if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $group_list);
0 ignored issues
show
Bug introduced by
The variable $cache_key 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...
610
			}
611
612
			if(!$group_list)
613
			{
614
				return array();
615
			}
616
617
618
			foreach($group_list as $val)
619
			{
620
				$result[$val->group_srl] = $val;
621
			}
622
623
			$GLOBALS['__group_info__'][$site_srl] = $result;
624
		}
625
		return $GLOBALS['__group_info__'][$site_srl];
626
	}
627
628
	public function getApiGroups()
629
	{
630
		$siteSrl = Context::get('siteSrl');
631
		$groupInfo = $this->getGroups($siteSrl);
632
633
		$this->add($groupInfo);
0 ignored issues
show
Bug introduced by
The call to add() misses a required argument $val.

This check looks for function calls that miss required arguments.

Loading history...
634
	}
635
636
	/**
637
	 * @brief Get a list of member join forms
638
	 *
639
	 * This method works as an extend filter of modules/member/tpl/filter/insert.xml.
640
	 * To use as extend_filter, the argument should be boolean.
641
	 * When the argument is true, it returns object result in type of filter.
642
	 */
643
	function getJoinFormList($filter_response = false)
644
	{
645
		global $lang;
646
		// Set to ignore if a super administrator.
647
		$logged_info = Context::get('logged_info');
648
649
		if(!$this->join_form_list)
650
		{
651
			// Argument setting to sort list_order column
652
			$args = new stdClass();
653
			$args->sort_index = "list_order";
654
			$output = executeQuery('member.getJoinFormList', $args);
655
			// NULL if output data deosn't exist
656
			$join_form_list = $output->data;
657
			if(!$join_form_list) return NULL;
658
			// Need to unserialize because serialized array is inserted into DB in case of default_value
659
			if(!is_array($join_form_list)) $join_form_list = array($join_form_list);
660
			$join_form_count = count($join_form_list);
661
			for($i=0;$i<$join_form_count;$i++)
662
			{
663
				$join_form_list[$i]->column_name = strtolower($join_form_list[$i]->column_name);
664
665
				$member_join_form_srl = $join_form_list[$i]->member_join_form_srl;
666
				$column_type = $join_form_list[$i]->column_type;
667
				$column_name = $join_form_list[$i]->column_name;
668
				$column_title = $join_form_list[$i]->column_title;
669
				$default_value = $join_form_list[$i]->default_value;
670
				// Add language variable
671
				$lang->extend_vars[$column_name] = $column_title;
672
				// unserialize if the data type if checkbox, select and so on
673
				if(in_array($column_type, array('checkbox','select','radio')))
674
				{
675
					$join_form_list[$i]->default_value = unserialize($default_value);
676
					if(!$join_form_list[$i]->default_value[0]) $join_form_list[$i]->default_value = '';
677
				}
678
				else
679
				{
680
					$join_form_list[$i]->default_value = '';
681
				}
682
683
				$list[$member_join_form_srl] = $join_form_list[$i];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $list = 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...
684
			}
685
			$this->join_form_list = $list;
0 ignored issues
show
Bug introduced by
The variable $list 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...
686
		}
687
		// Get object style if the filter_response is true
688
		if($filter_response && count($this->join_form_list))
689
		{
690
			foreach($this->join_form_list as $key => $val)
691
			{
692
				if($val->is_active != 'Y') continue;
693
				unset($obj);
694
				$obj->type = $val->column_type;
0 ignored issues
show
Bug introduced by
The variable $obj does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
695
				$obj->name = $val->column_name;
696
				$obj->lang = $val->column_title;
697
				if($logged_info->is_admin != 'Y') $obj->required = $val->required=='Y'?true:false;
698
				else $obj->required = false;
699
				$filter_output[] = $obj;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$filter_output was never initialized. Although not strictly required by PHP, it is generally a good practice to add $filter_output = 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...
700
701
				unset($open_obj);
702
				$open_obj->name = 'open_'.$val->column_name;
0 ignored issues
show
Bug introduced by
The variable $open_obj does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
703
				$open_obj->required = false;
704
				$filter_output[] = $open_obj;
705
706
			}
707
			return $filter_output;
0 ignored issues
show
Bug introduced by
The variable $filter_output 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...
708
		}
709
		// Return the result
710
		return $this->join_form_list;
711
	}
712
713
	/**
714
	 * get used join form list.
715
	 *
716
	 * @return array $joinFormList
717
	 */
718
	function getUsedJoinFormList()
719
	{
720
		$args = new stdClass();
721
		$args->sort_index = "list_order";
722
		$output = executeQueryArray('member.getJoinFormList', $args);
723
724
		if(!$output->toBool())
725
		{
726
			return array();
727
		}
728
729
		$joinFormList = array();
730
		foreach($output->data as $val)
731
		{
732
			if($val->is_active != 'Y')
733
			{
734
				continue;
735
			}
736
737
			$joinFormList[] = $val;
738
		}
739
740
		return $joinFormList;
741
	}
742
743
	/**
744
	 * @brief Combine extend join form and member information (used to modify member information)
745
	 */
746
	function getCombineJoinForm($member_info)
747
	{
748
		$extend_form_list = $this->getJoinFormlist();
749
		if(!$extend_form_list) return;
750
		// Member info is open only to an administrator and him/herself when is_private is true.
751
		$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...
752
753
		foreach($extend_form_list as $srl => $item)
754
		{
755
			$column_name = $item->column_name;
756
			$value = $member_info->{$column_name};
757
758
			// Change values depening on the type of extend form
759
			switch($item->column_type)
760
			{
761
				case 'checkbox' :
762
					if($value && !is_array($value)) $value = array($value);
763
					break;
764
				case 'text' :
765
				case 'homepage' :
766
				case 'email_address' :
767
				case 'tel' :
768
				case 'textarea' :
769
				case 'select' :
770
				case 'kr_zip' :
771
					break;
772
			}
773
774
			$extend_form_list[$srl]->value = $value;
775
776
			if($member_info->{'open_'.$column_name}=='Y') $extend_form_list[$srl]->is_opened = true;
777
			else $extend_form_list[$srl]->is_opened = false;
778
		}
779
		return $extend_form_list;
780
	}
781
782
	/**
783
	 * @brief Get a join form
784
	 */
785
	function getJoinForm($member_join_form_srl)
786
	{
787
		$args->member_join_form_srl = $member_join_form_srl;
0 ignored issues
show
Bug introduced by
The variable $args does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
788
		$output = executeQuery('member.getJoinForm', $args);
789
		$join_form = $output->data;
790
		if(!$join_form) return NULL;
791
792
		$column_type = $join_form->column_type;
793
		$default_value = $join_form->default_value;
794
795
		if(in_array($column_type, array('checkbox','select','radio')))
796
		{
797
			$join_form->default_value = unserialize($default_value);
798
		}
799
		else
800
		{
801
			$join_form->default_value = '';
802
		}
803
804
		return $join_form;
805
	}
806
807
	/**
808
	 * @brief Get a list of denied IDs
809
	 */
810
	function getDeniedIDList()
811
	{
812
		if(!$this->denied_id_list)
813
		{
814
			$args->sort_index = "list_order";
0 ignored issues
show
Bug introduced by
The variable $args does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
815
			$args->page = Context::get('page');
816
			$args->list_count = 40;
817
			$args->page_count = 10;
818
819
			$output = executeQuery('member.getDeniedIDList', $args);
820
			$this->denied_id_list = $output;
0 ignored issues
show
Bug introduced by
The property denied_id_list does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
821
		}
822
		return $this->denied_id_list;
823
	}
824
825
	function getDeniedIDs()
826
	{
827
		$output = executeQueryArray('member.getDeniedIDs');
828
		if(!$output->toBool()) return array();
829
		return $output->data;
830
	}
831
832
	function getDeniedNickNames()
833
	{
834
		$output = executeQueryArray('member.getDeniedNickNames');
835
		if(!$output->toBool())
836
		{
837
			return array();
838
		}
839
840
		return $output->data;
841
	}
842
843
	/**
844
	 * @brief Verify if ID is denied
845
	 */
846
	function isDeniedID($user_id)
847
	{
848
		$args = new stdClass();
849
		$args->user_id = $user_id;
850
		$output = executeQuery('member.chkDeniedID', $args);
851
		if($output->data->count) return true;
852
		return false;
853
	}
854
855
	/**
856
	 * @brief Verify if nick name is denied
857
	 */
858 View Code Duplication
	function isDeniedNickName($nickName)
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...
859
	{
860
		$args = new stdClass();
861
		$args->nick_name = $nickName;
862
		$output = executeQuery('member.chkDeniedNickName', $args);
863
		if($output->data->count) return true;
864
		if(!$output->toBool())
865
		{
866
			return true;
867
		}
868
		return false;
869
	}
870
	/**
871
	 * @brief Get information of the profile image
872
	 */
873
	function getProfileImage($member_srl)
874
	{
875
		if(!isset($GLOBALS['__member_info__']['profile_image'][$member_srl]))
876
		{
877
			$GLOBALS['__member_info__']['profile_image'][$member_srl] = null;
878
			$exts = array('gif','jpg','png');
879
			for($i=0;$i<3;$i++)
880
			{
881
				$image_name_file = sprintf('files/member_extra_info/profile_image/%s%d.%s', getNumberingPath($member_srl), $member_srl, $exts[$i]);
882
				if(file_exists($image_name_file))
883
				{
884
					list($width, $height, $type, $attrs) = getimagesize($image_name_file);
0 ignored issues
show
Unused Code introduced by
The assignment to $type 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...
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...
885
					$info = new stdClass();
886
					$info->width = $width;
887
					$info->height = $height;
888
					$info->src = Context::getRequestUri().$image_name_file;
889
					$info->file = './'.$image_name_file;
890
					$GLOBALS['__member_info__']['profile_image'][$member_srl] = $info;
891
					break;
892
				}
893
			}
894
		}
895
896
		return $GLOBALS['__member_info__']['profile_image'][$member_srl];
897
	}
898
899
	/**
900
	 * @brief Get the image name
901
	 */
902 View Code Duplication
	function getImageName($member_srl)
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...
903
	{
904
		if(!isset($GLOBALS['__member_info__']['image_name'][$member_srl]))
905
		{
906
			$image_name_file = sprintf('files/member_extra_info/image_name/%s%d.gif', getNumberingPath($member_srl), $member_srl);
907
			if(file_exists($image_name_file))
908
			{
909
				list($width, $height, $type, $attrs) = getimagesize($image_name_file);
0 ignored issues
show
Unused Code introduced by
The assignment to $type 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...
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...
910
				$info = new stdClass;
911
				$info->width = $width;
912
				$info->height = $height;
913
				$info->src = Context::getRequestUri().$image_name_file;
914
				$info->file = './'.$image_name_file;
915
				$GLOBALS['__member_info__']['image_name'][$member_srl] = $info;
916
			}
917
			else $GLOBALS['__member_info__']['image_name'][$member_srl] = null;
918
		}
919
		return $GLOBALS['__member_info__']['image_name'][$member_srl];
920
	}
921
922
	/**
923
	 * @brief Get the image mark
924
	 */
925 View Code Duplication
	function getImageMark($member_srl)
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...
926
	{
927
		if(!isset($GLOBALS['__member_info__']['image_mark'][$member_srl]))
928
		{
929
			$image_mark_file = sprintf('files/member_extra_info/image_mark/%s%d.gif', getNumberingPath($member_srl), $member_srl);
930
			if(file_exists($image_mark_file))
931
			{
932
				list($width, $height, $type, $attrs) = getimagesize($image_mark_file);
0 ignored issues
show
Unused Code introduced by
The assignment to $type 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...
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...
933
				$info->width = $width;
0 ignored issues
show
Bug introduced by
The variable $info does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
934
				$info->height = $height;
935
				$info->src = Context::getRequestUri().$image_mark_file;
936
				$info->file = './'.$image_mark_file;
937
				$GLOBALS['__member_info__']['image_mark'][$member_srl] = $info;
938
			}
939
			else $GLOBALS['__member_info__']['image_mark'][$member_srl] = null;
940
		}
941
942
		return $GLOBALS['__member_info__']['image_mark'][$member_srl];
943
	}
944
945
946
	/**
947
	 * @brief Get the image mark of the group
948
	 */
949
	function getGroupImageMark($member_srl,$site_srl=0)
950
	{
951
		if(!isset($GLOBALS['__member_info__']['group_image_mark'][$member_srl]))
952
		{
953
			$oModuleModel = getModel('module');
954
			$config = $oModuleModel->getModuleConfig('member');
955
			if($config->group_image_mark!='Y')
956
			{
957
				return null;
958
			}
959
			$member_group = $this->getMemberGroups($member_srl,$site_srl);
960
			$groups_info = $this->getGroups($site_srl);
961
			if(count($member_group) > 0 && is_array($member_group))
962
			{
963
				$memberGroups = array_keys($member_group);
964
965
				foreach($groups_info as $group_srl=>$group_info)
966
				{
967
					if(in_array($group_srl, $memberGroups))
968
					{
969
						if($group_info->image_mark)
970
						{
971
							$info = new stdClass();
972
							$info->title = $group_info->title;
973
							$info->description = $group_info->description;
974
							$info->src = $group_info->image_mark;
975
							$GLOBALS['__member_info__']['group_image_mark'][$member_srl] = $info;
976
							break;
977
						}
978
					}
979
				}
980
			}
981
			if (!$info) $GLOBALS['__member_info__']['group_image_mark'][$member_srl] == 'N';
0 ignored issues
show
Bug introduced by
The variable $info 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...
982
		}
983
		if ($GLOBALS['__member_info__']['group_image_mark'][$member_srl] == 'N') return null;
984
985
		return $GLOBALS['__member_info__']['group_image_mark'][$member_srl];
986
	}
987
988
	/**
989
	 * @brief Get user's signature
990
	 */
991
	function getSignature($member_srl)
992
	{
993
		if(!isset($GLOBALS['__member_info__']['signature'][$member_srl]))
994
		{
995
			$filename = sprintf('files/member_extra_info/signature/%s%d.signature.php', getNumberingPath($member_srl), $member_srl);
996
			if(file_exists($filename))
997
			{
998
				$buff = FileHandler::readFile($filename);
999
				$signature = preg_replace('/<\?.*\?>/', '', $buff);
1000
				$GLOBALS['__member_info__']['signature'][$member_srl] = $signature;
1001
			}
1002
			else $GLOBALS['__member_info__']['signature'][$member_srl] = null;
1003
		}
1004
		return $GLOBALS['__member_info__']['signature'][$member_srl];
1005
	}
1006
1007
	/**
1008
	 * @brief Compare plain text password to the password saved in DB
1009
	 * @param string $hashed_password The hash that was saved in DB
1010
	 * @param string $password_text The password to check
1011
	 * @param int $member_srl Set this to member_srl when comparing a member's password (optional)
1012
	 * @return bool
1013
	 */
1014
	function isValidPassword($hashed_password, $password_text, $member_srl=null)
1015
	{
1016
		// False if no password in entered
1017
		if(!$password_text)
1018
		{
1019
			return false;
1020
		}
1021
		
1022
		// Check the password
1023
		$oPassword = new Password();
1024
		$current_algorithm = $oPassword->checkAlgorithm($hashed_password);
1025
		$match = $oPassword->checkPassword($password_text, $hashed_password, $current_algorithm);
0 ignored issues
show
Security Bug introduced by
It seems like $current_algorithm defined by $oPassword->checkAlgorithm($hashed_password) on line 1024 can also be of type false; however, Password::checkPassword() does only seem to accept string|null, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
1026
		if(!$match)
1027
		{
1028
			return false;
1029
		}
1030
		
1031
		// Update the encryption method if necessary
1032
		$config = $this->getMemberConfig();
1033
		if($member_srl > 0 && $config->password_hashing_auto_upgrade != 'N')
1034
		{
1035
			$need_upgrade = false;
1036
			
1037
			if(!$need_upgrade)
1038
			{
1039
				$required_algorithm = $oPassword->getCurrentlySelectedAlgorithm();
1040
				if($required_algorithm !== $current_algorithm) $need_upgrade = true;
1041
			}
1042
			
1043
			if(!$need_upgrade)
1044
			{
1045
				$required_work_factor = $oPassword->getWorkFactor();
1046
				$current_work_factor = $oPassword->checkWorkFactor($hashed_password);
1047
				if($current_work_factor !== false && $required_work_factor > $current_work_factor) $need_upgrade = true;
1048
			}
1049
			
1050
			if($need_upgrade === true)
1051
			{
1052
				$args = new stdClass();
1053
				$args->member_srl = $member_srl;
1054
				$args->hashed_password = $this->hashPassword($password_text, $required_algorithm);
0 ignored issues
show
Bug introduced by
The variable $required_algorithm 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...
1055
				$oMemberController = getController('member');
1056
				$oMemberController->updateMemberPassword($args);
1057
			}
1058
		}
1059
		
1060
		return true;
1061
	}
1062
	
1063
	/**
1064
	 * @brief Create a hash of plain text password
1065
	 * @param string $password_text The password to hash
1066
	 * @param string $algorithm The algorithm to use (optional, only set this when you want to use a non-default algorithm)
1067
	 * @return string
1068
	 */
1069
	function hashPassword($password_text, $algorithm = null)
1070
	{
1071
		$oPassword = new Password();
1072
		return $oPassword->createHash($password_text, $algorithm);
1073
	}
1074
	
1075
	function checkPasswordStrength($password, $strength)
1076
	{
1077
		$logged_info = Context::get('logged_info');
1078
		if($logged_info->is_admin == 'Y') return true;
1079
		
1080
		if($strength == NULL)
1081
		{
1082
			$config = $this->getMemberConfig();
1083
			$strength = $config->password_strength?$config->password_strength:'normal';
1084
		}
1085
		
1086
		$length = strlen($password);
1087
		
1088
		switch ($strength) {
1089
			case 'high':
1090
				if($length < 8 || !preg_match('/[^a-zA-Z0-9]/', $password)) return false;
1091
				/* no break */
1092
				
1093
			case 'normal':
1094
				if($length < 6 || !preg_match('/[a-zA-Z]/', $password) || !preg_match('/[0-9]/', $password)) return false;
1095
				break;
1096
				
1097
			case 'low':
1098
				if($length < 4) return false;
1099
				break; 
1100
		}
1101
		
1102
		return true;
1103
	}
1104
	
1105
	function getAdminGroupSrl($site_srl = 0)
1106
	{
1107
		$groupSrl = 0;
1108
		$output = $this->getGroups($site_srl);
1109
		if(is_array($output))
1110
		{
1111
			foreach($output AS $key=>$value)
1112
			{
1113
				if($value->is_admin == 'Y')
1114
				{
1115
					$groupSrl = $value->group_srl;
1116
					break;
1117
				}
1118
			}
1119
		}
1120
		return $groupSrl;
1121
	}
1122
}
1123
/* End of file member.model.php */
1124
/* Location: ./modules/member/member.model.php */
1125