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

moduleController::deleteModuleExtraVars()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 17
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  moduleController
5
 * @author NAVER ([email protected])
6
 * @brief controller class of the module module
7
 */
8
class moduleController extends module
9
{
10
	/**
11
	 * @brief Initialization
12
	 */
13
	function init()
14
	{
15
	}
16
17
	/**
18
	 * @brief Add action forward
19
	 * Action forward finds and forwards if an action is not in the requested module
20
	 * This is used when installing a module
21
	 */
22
	function insertActionForward($module, $type, $act)
23
	{
24
		$args = new stdClass();
25
		$args->module = $module;
26
		$args->type = $type;
27
		$args->act = $act;
28
29
		$output = executeQuery('module.insertActionForward', $args);
30
31
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
32
		if($oCacheHandler->isSupport())
33
		{
34
			$cache_key = 'action_forward';
35
			$oCacheHandler->delete($cache_key);
36
		}
37
38
		return $output;
39
	}
40
41
	/**
42
	 * @brief Delete action forward
43
	 */
44
	function deleteActionForward($module, $type, $act)
45
	{
46
		$args = new stdClass();
47
		$args->module = $module;
48
		$args->type = $type;
49
		$args->act = $act;
50
51
		$output = executeQuery('module.deleteActionForward', $args);
52
53
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
54
		if($oCacheHandler->isSupport())
55
		{
56
			$cache_key = 'action_forward';
57
			$oCacheHandler->delete($cache_key);
58
		}
59
60
		return $output;
61
	}
62
63
	/**
64
	 * @brief Add module trigger
65
	 * module trigger is to call a trigger to a target module
66
	 *
67
	 */
68 View Code Duplication
	function insertTrigger($trigger_name, $module, $type, $called_method, $called_position)
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...
69
	{
70
		$args = new stdClass();
71
		$args->trigger_name = $trigger_name;
72
		$args->module = $module;
73
		$args->type = $type;
74
		$args->called_method = $called_method;
75
		$args->called_position = $called_position;
76
77
		$output = executeQuery('module.insertTrigger', $args);
78
		if($output->toBool())
79
		{
80
			//remove from cache
81
			$GLOBALS['__triggers__'] = NULL;
82
			$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
83
			if($oCacheHandler->isSupport())
84
			{
85
				$cache_key = 'triggers';
86
				$oCacheHandler->delete($cache_key);
87
			}
88
		}
89
90
		return $output;
91
	}
92
93
	/**
94
	 * @brief Delete module trigger
95
	 *
96
	 */
97 View Code Duplication
	function deleteTrigger($trigger_name, $module, $type, $called_method, $called_position)
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...
98
	{
99
		$args = new stdClass();
100
		$args->trigger_name = $trigger_name;
101
		$args->module = $module;
102
		$args->type = $type;
103
		$args->called_method = $called_method;
104
		$args->called_position = $called_position;
105
106
		$output = executeQuery('module.deleteTrigger', $args);
107
		if($output->toBool())
108
		{
109
			//remove from cache
110
			$GLOBALS['__triggers__'] = NULL;
111
			$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
112
			if($oCacheHandler->isSupport())
113
			{
114
				$cache_key = 'triggers';
115
				$oCacheHandler->delete($cache_key);
116
			}
117
		}
118
119
		return $output;
120
	}
121
122
	/**
123
	 * @brief Delete module trigger
124
	 *
125
	 */
126 View Code Duplication
	function deleteModuleTriggers($module)
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...
127
	{
128
		$args = new stdClass();
129
		$args->module = $module;
130
131
		$output = executeQuery('module.deleteModuleTriggers', $args);
132
		if($output->toBool())
133
		{
134
			//remove from cache
135
			$GLOBALS['__triggers__'] = NULL;
136
			$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
137
			if($oCacheHandler->isSupport())
138
			{
139
				$cache_key = 'triggers';
140
				$oCacheHandler->delete($cache_key);
141
			}
142
		}
143
144
		return $output;
145
	}
146
147
	/**
148
	 * @brief Add module extend
149
	 *
150
	 */
151
	function insertModuleExtend($parent_module, $extend_module, $type, $kind='')
152
	{
153
		if($kind != 'admin') $kind = '';
154
		if(!in_array($type,array('model','controller','view','api','mobile'))) return false;
155
		if(in_array($parent_module, array('module','addon','widget','layout'))) return false;
156
157
		$cache_file = './files/config/module_extend.php';
158
		FileHandler::removeFile($cache_file);
159
160
		$args = new stdClass;
161
		$args->parent_module = $parent_module;
162
		$args->extend_module = $extend_module;
163
		$args->type = $type;
164
		$args->kind = $kind;
165
166
		$output = executeQuery('module.getModuleExtendCount', $args);
167
		if($output->data->count>0) return false;
168
169
		$output = executeQuery('module.insertModuleExtend', $args);
170
		return $output;
171
	}
172
173
	/**
174
	 * @brief Delete module extend
175
	 *
176
	 */
177
	function deleteModuleExtend($parent_module, $extend_module, $type, $kind='')
178
	{
179
		$cache_file = './files/config/module_extend.php';
180
		FileHandler::removeFile($cache_file);
181
182
		$args = new stdClass;
183
		$args->parent_module = $parent_module;
184
		$args->extend_module = $extend_module;
185
		$args->type = $type;
186
		$args->kind = $kind;
187
188
		$output = executeQuery('module.deleteModuleExtend', $args);
189
190
		return $output;
191
	}
192
193
	function updateModuleConfig($module, $config, $site_srl = 0)
194
	{
195
		$args = new stdClass();
196
		$args->module = $module;
197
		$args->site_srl = $site_srl;
198
199
		$oModuleModel = getModel('module');
200
		$origin_config = $oModuleModel->getModuleConfig($module, $site_srl);
201
202
		if(!$origin_config) $origin_config = new stdClass;
203
204
		foreach($config as $key => $val)
205
		{
206
			$origin_config->{$key} = $val;
207
		}
208
209
		return $this->insertModuleConfig($module, $origin_config, $site_srl);
210
	}
211
212
	/**
213
	 * @brief Enter a specific set of modules
214
	 * In order to manage global configurations of modules such as board, member and so on
215
	 */
216 View Code Duplication
	function insertModuleConfig($module, $config, $site_srl = 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...
217
	{
218
		$args =new stdClass();
219
		$args->module = $module;
220
		$args->config = serialize($config);
221
		$args->site_srl = $site_srl;
222
223
		$output = executeQuery('module.deleteModuleConfig', $args);
224
		if(!$output->toBool()) return $output;
225
226
		$output = executeQuery('module.insertModuleConfig', $args);
227
228
		//remove from cache
229
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
230
		if($oCacheHandler->isSupport())
231
		{
232
			$oCacheHandler->invalidateGroupKey('site_and_module');
233
		}
234
		return $output;
235
	}
236
237
	/**
238
	 * @brief Save module configurations of the mid
239
	 * Manage mid configurations depending on module
240
	 */
241 View Code Duplication
	function insertModulePartConfig($module, $module_srl, $config)
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...
242
	{
243
		$args = new stdClass();
244
		$args->module = $module;
245
		$args->module_srl = $module_srl;
246
		$args->config = serialize($config);
247
248
		$output = executeQuery('module.deleteModulePartConfig', $args);
249
		if(!$output->toBool()) return $output;
250
251
		$output = executeQuery('module.insertModulePartConfig', $args);
252
253
		//remove from cache
254
		$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
255
		if($oCacheHandler->isSupport())
256
		{
257
			$oCacheHandler->invalidateGroupKey('site_and_module');
258
		}
259
260
		return $output;
261
	}
262
263
	/**
264
	 * @brief create virtual site
265
	 */
266
	function insertSite($domain, $index_module_srl)
267
	{
268
		if(isSiteID($domain))
269
		{
270
			$oModuleModel = getModel('module');
271
			if($oModuleModel->isIDExists($domain, 0)) return new Object(-1,'msg_already_registed_vid');
272
		}
273
		else
274
		{
275
			$domain = strtolower($domain);
276
		}
277
278
		$args = new stdClass;
279
		$args->site_srl = getNextSequence();
280
		$args->domain = (substr_compare($domain, '/', -1) === 0) ? substr($domain, 0, -1) : $domain;
281
		$args->index_module_srl = $index_module_srl;
282
		$args->default_language = Context::getLangType();
283
284
		$columnList = array('modules.site_srl');
285
		$oModuleModel = getModel('module');
286
		$output = $oModuleModel->getSiteInfoByDomain($args->domain, $columnList);
287
		if($output) return new Object(-1,'msg_already_registed_vid');
288
289
		$output = executeQuery('module.insertSite', $args);
290
		if(!$output->toBool()) return $output;
291
292
		$output->add('site_srl', $args->site_srl);
293
		return $output;
294
	}
295
296
	/**
297
	 * @brief modify virtual site
298
	 */
299
	function updateSite($args)
300
	{
301
		$oModuleModel = getModel('module');
302
		$columnList = array('sites.site_srl', 'sites.domain');
303
		$site_info = $oModuleModel->getSiteInfo($args->site_srl, $columnList);
304
305
		if(!$args->domain && $site_info->site_srl == $args->site_srl)
306
		{
307
			$args->domain = $site_info->domain;
308
		}
309
310
		if($site_info->domain != $args->domain)
311
		{
312
			$info = $oModuleModel->getSiteInfoByDomain($args->domain, $columnList);
313
			if($info->site_srl && $info->site_srl != $args->site_srl) return new Object(-1,'msg_already_registed_domain');
314
			if(isSiteID($args->domain) && $oModuleModel->isIDExists($args->domain)) return new Object(-1,'msg_already_registed_vid');
315
316
			if($args->domain && !isSiteID($args->domain))
317
			{
318
				$args->domain = (strlen($args->domain) >= 1 && substr_compare($args->domain, '/', -1) === 0) ? substr($args->domain, 0, -1) : $args->domain;
319
			}
320
		}
321
		$output = executeQuery('module.updateSite', $args);
322
		//clear cache for default mid
323
		if($args->site_srl == 0) $vid='';
0 ignored issues
show
Unused Code introduced by
$vid 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...
324
		else $vid=$args->domain;
0 ignored issues
show
Unused Code introduced by
$vid 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...
325
326
		$module_info = $oModuleModel->getModuleInfoByModuleSrl($args->index_module_srl);
327
		$mid = $module_info->mid;
0 ignored issues
show
Unused Code introduced by
$mid 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...
328
329
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
330
		if($oCacheHandler->isSupport())
331
		{
332
			$oCacheHandler->invalidateGroupKey('site_and_module');
333
		}
334
335
		return $output;
336
	}
337
338
	/**
339
	 * @brief Arrange module information
340
	 */
341
	function arrangeModuleInfo(&$args, &$extra_vars)
342
	{
343
		// Remove unnecessary information
344
		unset($args->body);
345
		unset($args->act);
346
		unset($args->page);
347
		// Test mid value
348
		if(!preg_match("/^[a-z][a-z0-9_]+$/i", $args->mid)) return new Object(-1, 'msg_limit_mid');
349
		// Test variables (separate basic vars and other vars in modules)
350
		$extra_vars = clone($args);
351
		unset($extra_vars->module_srl);
352
		unset($extra_vars->module);
353
		unset($extra_vars->module_category_srl);
354
		unset($extra_vars->layout_srl);
355
		unset($extra_vars->mlayout_srl);
356
		unset($extra_vars->use_mobile);
357
		unset($extra_vars->menu_srl);
358
		unset($extra_vars->site_srl);
359
		unset($extra_vars->mid);
360
		unset($extra_vars->is_skin_fix);
361
		unset($extra_vars->skin);
362
		unset($extra_vars->is_mskin_fix);
363
		unset($extra_vars->mskin);
364
		unset($extra_vars->browser_title);
365
		unset($extra_vars->description);
366
		unset($extra_vars->is_default);
367
		unset($extra_vars->content);
368
		unset($extra_vars->mcontent);
369
		unset($extra_vars->open_rss);
370
		unset($extra_vars->header_text);
371
		unset($extra_vars->footer_text);
372
		$args = delObjectVars($args, $extra_vars);
373
374
		return new Object();
375
	}
376
377
	/**
378
	 * @brief Insert module
379
	 */
380
	function insertModule($args)
381
	{
382
		if(isset($args->isMenuCreate))
383
		{
384
			$isMenuCreate = $args->isMenuCreate;
385
		}
386
		else
387
		{
388
			$isMenuCreate = TRUE;
389
		}
390
391
		$output = $this->arrangeModuleInfo($args, $extra_vars);
392
		if(!$output->toBool()) return $output;
393
		// Check whether the module name already exists
394
		if(!$args->site_srl) $args->site_srl = 0;
395
		$oModuleModel = getModel('module');
396
		if($oModuleModel->isIDExists($args->mid, $args->site_srl)) return new Object(-1, 'msg_module_name_exists');
397
398
		// begin transaction
399
		$oDB = &DB::getInstance();
400
		$oDB->begin();
401
		// Get colorset from the skin information
402
		$module_path = ModuleHandler::getModulePath($args->module);
403
		$skin_info = $oModuleModel->loadSkinInfo($module_path, $args->skin);
404
		$skin_vars = new stdClass();
405
		$skin_vars->colorset = $skin_info->colorset[0]->name;
406
		// Arrange variables and then execute a query
407
		if(!$args->module_srl) $args->module_srl = getNextSequence();
408
409
		// default value
410 View Code Duplication
		if($args->skin == '/USE_DEFAULT/')
411
		{
412
			$args->is_skin_fix = 'N';
413
		}
414
		else
415
		{
416
			if(isset($args->is_skin_fix))
417
			{
418
				$args->is_skin_fix = ($args->is_skin_fix != 'Y') ? 'N' : 'Y';
419
			}
420
			else
421
			{
422
				$args->is_skin_fix = 'Y';
423
			}
424
		}
425
426 View Code Duplication
		if($args->mskin == '/USE_DEFAULT/')
427
		{
428
			$args->is_mskin_fix = 'N';
429
		}
430
		else
431
		{
432
			if(isset($args->is_mskin_fix))
433
			{
434
				$args->is_mskin_fix = ($args->is_mskin_fix != 'Y') ? 'N' : 'Y';
435
			}
436
			else
437
			{
438
				$args->is_mskin_fix = 'Y';
439
			}
440
		}
441
442
		unset($output);
443
444
		$args->browser_title = strip_tags($args->browser_title);
445
446
		if($isMenuCreate == TRUE)
447
		{
448
			$menuArgs = new stdClass;
449
			$menuArgs->menu_srl = $args->menu_srl;
450
			$menuOutput = executeQuery('menu.getMenu', $menuArgs);
451
452
			// if menu is not created, create menu also. and does not supported that in virtual site.
453
			if(!$menuOutput->data && !$args->site_srl)
454
			{
455
				$oMenuAdminModel = getAdminModel('menu');
0 ignored issues
show
Unused Code introduced by
$oMenuAdminModel 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...
456
457
				$oMenuAdminController = getAdminController('menu');
458
				$menuSrl = $oMenuAdminController->getUnlinkedMenu();
459
460
				$menuArgs->menu_srl = $menuSrl;
461
				$menuArgs->menu_item_srl = getNextSequence();
462
				$menuArgs->parent_srl = 0;
463
				$menuArgs->open_window = 'N';
464
				$menuArgs->url = $args->mid;
465
				$menuArgs->expand = 'N';
466
				$menuArgs->is_shortcut = 'N';
467
				$menuArgs->name = $args->browser_title;
468
				$menuArgs->listorder = $args->menu_item_srl * -1;
469
470
				$menuItemOutput = executeQuery('menu.insertMenuItem', $menuArgs);
471
				if(!$menuItemOutput->toBool())
472
				{
473
					$oDB->rollback();
474
					return $menuItemOutput;
475
				}
476
477
				$oMenuAdminController->makeXmlFile($menuSrl);
478
			}
479
		}
480
481
		// Insert a module
482
		$args->menu_srl = $menuArgs->menu_srl;
0 ignored issues
show
Bug introduced by
The variable $menuArgs 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...
483
		$output = executeQuery('module.insertModule', $args);
484
		if(!$output->toBool())
485
		{
486
			$oDB->rollback();
487
			return $output;
488
		}
489
		// Insert module extra vars
490
		$this->insertModuleExtraVars($args->module_srl, $extra_vars);
491
492
		// commit
493
		$oDB->commit();
494
495
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
496
		if($oCacheHandler->isSupport())
497
		{
498
			$oCacheHandler->invalidateGroupKey('site_and_module');
499
		}
500
501
		$output->add('module_srl',$args->module_srl);
502
		return $output;
503
	}
504
505
	/**
506
	 * @brief Modify module information
507
	 */
508
	function updateModule($args)
509
	{
510
		$output = $this->arrangeModuleInfo($args, $extra_vars);
511
		if(!$output->toBool()) return $output;
512
		// begin transaction
513
		$oDB = &DB::getInstance();
514
		$oDB->begin();
515
516
		$oModuleModel = getModel('module');
517
		$columnList = array('module_srl', 'site_srl', 'browser_title', 'mid');
0 ignored issues
show
Unused Code introduced by
$columnList 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...
518
		$module_info = $oModuleModel->getModuleInfoByModuleSrl($args->module_srl);
519
520
		if(!$args->site_srl || !$args->browser_title)
521
		{
522
			if(!$args->site_srl) $args->site_srl = (int)$module_info->site_srl;
523
			if(!$args->browser_title) $args->browser_title = $module_info->browser_title;
524
		}
525
526
		$args->browser_title = strip_tags($args->browser_title);
527
528
		$output = executeQuery('module.isExistsModuleName', $args);
529
		if(!$output->toBool() || $output->data->count)
530
		{
531
			$oDB->rollback();
532
			return new Object(-1, 'msg_module_name_exists');
533
		}
534
535
		// default value
536 View Code Duplication
		if($args->skin == '/USE_DEFAULT/')
537
		{
538
			$args->is_skin_fix = 'N';
539
		}
540
		else
541
		{
542
			if(isset($args->is_skin_fix))
543
			{
544
				$args->is_skin_fix = ($args->is_skin_fix != 'Y') ? 'N' : 'Y';
545
			}
546
			else
547
			{
548
				$args->is_skin_fix = 'Y';
549
			}
550
		}
551
552 View Code Duplication
		if($args->mskin == '/USE_DEFAULT/')
553
		{
554
			$args->is_mskin_fix = 'N';
555
		}
556
		else
557
		{
558
			if(isset($args->is_mskin_fix))
559
			{
560
				$args->is_mskin_fix = ($args->is_mskin_fix != 'Y') ? 'N' : 'Y';
561
			}
562
			else
563
			{
564
				$args->is_mskin_fix = 'Y';
565
			}
566
		}
567
		$output = executeQuery('module.updateModule', $args);
568
		if(!$output->toBool())
569
		{
570
			$oDB->rollback();
571
			return $output;
572
		}
573
574
		$menuArgs = new stdClass;
575
		$menuArgs->url = $module_info->mid;
576
		$menuArgs->site_srl = $module_info->site_srl;
577
		$menuOutput = executeQueryArray('menu.getMenuItemByUrl', $menuArgs);
578
		if($menuOutput->data && count($menuOutput->data))
579
		{
580
			$oMenuAdminController = getAdminController('menu');
581
			foreach($menuOutput->data as $itemInfo)
582
			{
583
				$itemInfo->url = $args->mid;
584
585
				$updateMenuItemOutput = $oMenuAdminController->updateMenuItem($itemInfo);
586
				if(!$updateMenuItemOutput->toBool())
587
				{
588
					$oDB->rollback();
589
					return $updateMenuItemOutput;
590
				}
591
			}
592
		}
593
594
		// if mid changed, change mid of success_return_url to new mid
595
		if($module_info->mid != $args->mid && Context::get('success_return_url'))
596
		{
597
			changeValueInUrl('mid', $args->mid, $module_info->mid);
598
		}
599
600
		// Insert module extra vars
601
		$this->insertModuleExtraVars($args->module_srl, $extra_vars);
602
603
		$oDB->commit();
604
605
		$output->add('module_srl',$args->module_srl);
606
607
		//remove from cache
608
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
609
		if($oCacheHandler->isSupport())
610
		{
611
			$oCacheHandler->invalidateGroupKey('site_and_module');
612
		}
613
614
		return $output;
615
	}
616
617
	/**
618
	 * @brief Change the module's virtual site
619
	 */
620
	function updateModuleSite($module_srl, $site_srl, $layout_srl = 0)
621
	{
622
		$args = new stdClass;
623
		$args->module_srl = $module_srl;
624
		$args->site_srl = $site_srl;
625
		$args->layout_srl = $layout_srl;
626
		$output = executeQuery('module.updateModuleSite', $args);
627
		if(!$output->toBool()) return $output;
628
629
		//remove from cache
630
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
631
		if($oCacheHandler->isSupport())
632
		{
633
			$oCacheHandler->invalidateGroupKey('site_and_module');
634
		}
635
636
		return $output;
637
	}
638
639
	/**
640
	 * Delete module
641
	 * Attempt to delete all related information when deleting a module.
642
	 * Origin method is changed. because menu validation check is needed
643
	 */
644
	function deleteModule($module_srl, $site_srl = 0)
645
	{
646
		if(!$module_srl) return new Object(-1,'msg_invalid_request');
647
648
		$site_module_info = Context::get('site_module_info');
649
650
		$oModuleModel = getModel('module');
651
		$output = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
652
653
		$args = new stdClass();
654
		$args->url = $output->mid;
655
		$args->is_shortcut = 'N';
656
		if(!$site_srl) $args->site_srl = $site_module_info->site_srl;
657
		else $args->site_srl = $site_srl;
658
659
		unset($output);
660
661
		$oMenuAdminModel = getAdminModel('menu');
662
		$menuOutput = $oMenuAdminModel->getMenuList($args);
663
664
		// get menu_srl by site_srl
665
		if(is_array($menuOutput->data))
666
		{
667
			foreach($menuOutput->data AS $key=>$value)
668
			{
669
				$args->menu_srl = $value->menu_srl;
670
				break;
671
			}
672
		}
673
674
		$output = executeQuery('menu.getMenuItemByUrl', $args);
675
		// menu delete
676
		if($output->data)
677
		{
678
			unset($args);
679
			$args = new stdClass;
680
			$args->menu_srl = $output->data->menu_srl;
681
			$args->menu_item_srl = $output->data->menu_item_srl;
682
			$args->is_force = 'N';
683
684
			$oMenuAdminController = getAdminController('menu');
685
			$output = $oMenuAdminController->deleteItem($args);
686
687
			if($output->isSuccess)
688
			{
689
				return new Object(0, 'success_deleted');
690
			}
691
			else
692
			{
693
				return new Object($output->error, $output->message);
694
			}
695
		}
696
		// only delete module
697
		else
698
		{
699
			return $this->onlyDeleteModule($module_srl);
700
		}
701
	}
702
703
	/**
704
	 * Delete module
705
	 * Attempt to delete all related information when deleting a module.
706
	 */
707
	public function onlyDeleteModule($module_srl)
708
	{
709
		if(!$module_srl) return new Object(-1,'msg_invalid_request');
710
711
		// check start module
712
		$oModuleModel = getModel('module');
713
		$columnList = array('sites.index_module_srl');
714
		$start_module = $oModuleModel->getSiteInfo(0, $columnList);
715
		if($module_srl == $start_module->index_module_srl) return new Object(-1, 'msg_cannot_delete_startmodule');
716
717
		// Call a trigger (before)
718
		$trigger_obj = new stdClass();
719
		$trigger_obj->module_srl = $module_srl;
720
		$output = ModuleHandler::triggerCall('module.deleteModule', 'before', $trigger_obj);
721
		if(!$output->toBool()) return $output;
722
723
		// begin transaction
724
		$oDB = &DB::getInstance();
725
		$oDB->begin();
726
727
		$args = new stdClass();
728
		$args->module_srl = $module_srl;
729
		// Delete module information from the DB
730
		$output = executeQuery('module.deleteModule', $args);
731
		if(!$output->toBool())
732
		{
733
			$oDB->rollback();
734
			return $output;
735
		}
736
		// Delete permission information
737
		$this->deleteModuleGrants($module_srl);
738
		// Remove skin information
739
		$this->deleteModuleSkinVars($module_srl);
740
		// Delete module extra vars
741
		$this->deleteModuleExtraVars($module_srl);
742
		// Remove the module manager
743
		$this->deleteAdminId($module_srl);
744
		// Call a trigger (after)
745 View Code Duplication
		if($output->toBool())
746
		{
747
			$trigger_output = ModuleHandler::triggerCall('module.deleteModule', 'after', $trigger_obj);
748
			if(!$trigger_output->toBool())
749
			{
750
				$oDB->rollback();
751
				return $trigger_output;
752
			}
753
		}
754
755
		// commit
756
		$oDB->commit();
757
758
		//remove from cache
759
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
760
		if($oCacheHandler->isSupport())
761
		{
762
			$oCacheHandler->invalidateGroupKey('site_and_module');
763
		}
764
		return $output;
765
	}
766
767
	/**
768
	 * @brief Change other information of the module
769
	 * @deprecated
770
	 */
771
	function updateModuleSkinVars($module_srl, $skin_vars)
0 ignored issues
show
Unused Code introduced by
The parameter $module_srl 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...
Unused Code introduced by
The parameter $skin_vars 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...
772
	{
773
		return new Object();
774
	}
775
776
	/**
777
	 * @brief Set is_default as N in all modules(the default module is disabled)
778
	 */
779 View Code Duplication
	function clearDefaultModule()
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...
780
	{
781
		$output = executeQuery('module.clearDefaultModule');
782
		if(!$output->toBool()) return $output;
783
784
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
785
		if($oCacheHandler->isSupport())
786
		{
787
			$oCacheHandler->invalidateGroupKey('site_and_module');
788
		}
789
790
		return $output;
791
	}
792
793
	/**
794
	 * @brief Update menu_srl of mid which belongs to menu_srl
795
	 */
796 View Code Duplication
	function updateModuleMenu($args)
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...
797
	{
798
		$output = executeQuery('module.updateModuleMenu', $args);
799
800
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
801
		if($oCacheHandler->isSupport())
802
		{
803
			$oCacheHandler->invalidateGroupKey('site_and_module');
804
		}
805
806
		return $output;
807
	}
808
809
	/**
810
	 * @brief Update layout_srl of mid which belongs to menu_srl
811
	 */
812
	function updateModuleLayout($layout_srl, $menu_srl_list)
813
	{
814
		if(!count($menu_srl_list)) return;
815
816
		$args = new stdClass;
817
		$args->layout_srl = $layout_srl;
818
		$args->menu_srls = implode(',',$menu_srl_list);
819
		$output = executeQuery('module.updateModuleLayout', $args);
820
821
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
822
		if($oCacheHandler->isSupport())
823
		{
824
			$oCacheHandler->invalidateGroupKey('site_and_module');
825
		}
826
827
		return $output;
828
	}
829
830
	/**
831
	 * @brief Change the site administrator
832
	 */
833
	function insertSiteAdmin($site_srl, $arr_admins)
834
	{
835
		// Remove the site administrator
836
		$args = new stdClass;
837
		$args->site_srl = $site_srl;
838
839
		$output = executeQuery('module.deleteSiteAdmin', $args);
840
841
		if(!$output->toBool()) return $output;
842
		// Get user id of an administrator
843
		if(!is_array($arr_admins) || !count($arr_admins)) return new Object();
844
		foreach($arr_admins as $key => $user_id)
845
		{
846
			if(!trim($user_id)) continue;
847
			$admins[] = trim($user_id);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$admins was never initialized. Although not strictly required by PHP, it is generally a good practice to add $admins = 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...
848
		}
849
		if(!count($admins)) return new Object();
0 ignored issues
show
Bug introduced by
The variable $admins 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...
850
851
		$oMemberModel = getModel('member');
852
		$member_config = $oMemberModel->getMemberConfig();
853
		if($member_config->identifier == 'email_address')
854
		{
855
			$args->email_address = '\''.implode('\',\'',$admins).'\'';
856
		}
857
		else
858
		{
859
			$args->user_ids = '\''.implode('\',\'',$admins).'\'';
860
		}
861
		$output = executeQueryArray('module.getAdminSrls', $args);
862
		if(!$output->toBool()||!$output->data) return $output;
863
864
		foreach($output->data as $key => $val)
865
		{
866
			unset($args);
867
			$args = new stdClass;
868
			$args->site_srl = $site_srl;
869
			$args->member_srl = $val->member_srl;
870
			$output = executeQueryArray('module.insertSiteAdmin', $args);
871
			if(!$output->toBool()) return $output;
872
		}
873
		return new Object();
874
	}
875
876
	/**
877
	 * @brief Specify the admin ID to a module
878
	 */
879
	function insertAdminId($module_srl, $admin_id)
880
	{
881
		$oMemberModel = getModel('member');
882
		$member_config = $oMemberModel->getMemberConfig();
883
884
		if($member_config->identifier == 'email_address')
885
			$member_info = $oMemberModel->getMemberInfoByEmailAddress($admin_id);
886
		else
887
			$member_info = $oMemberModel->getMemberInfoByUserID($admin_id);
888
889
		if(!$member_info->member_srl) return;
890
		$args = new stdClass();
891
		$args->module_srl = $module_srl;
892
		$args->member_srl = $member_info->member_srl;
893
		return executeQuery('module.insertAdminId', $args);
894
	}
895
896
	/**
897
	 * @brief Remove the admin ID from a module
898
	 */
899
	function deleteAdminId($module_srl, $admin_id = '')
900
	{
901
		$args = new stdClass();
902
		$args->module_srl = $module_srl;
903
904
		if($admin_id)
905
		{
906
			$oMemberModel = getModel('member');
907
			$member_info = $oMemberModel->getMemberInfoByUserID($admin_id);
908
			if($member_info->member_srl) $args->member_srl = $member_info->member_srl;
909
		}
910
		return executeQuery('module.deleteAdminId', $args);
911
	}
912
913
	/**
914
	 * Insert skin vars to a module
915
	 * @param $module_srl Sequence of module
916
	 * @param $obj Skin variables
917
	 */
918
	function insertModuleSkinVars($module_srl, $obj)
919
	{
920
		return $this->_insertModuleSkinVars($module_srl, $obj, 'P');
921
	}
922
923
	/**
924
	 * Insert mobile skin vars to a module
925
	 * @param $module_srl Sequence of module
926
	 * @param $obj Skin variables
927
	 */
928
	function insertModuleMobileSkinVars($module_srl, $obj)
929
	{
930
		return $this->_insertModuleSkinVars($module_srl, $obj, 'M');
931
	}
932
933
934
	/**
935
	 * @brief Insert skin vars to a module
936
	 */
937
	function _insertModuleSkinVars($module_srl, $obj, $mode)
938
	{
939
		$mode = $mode === 'P' ? 'P' : 'M';
940
941
		$oDB = DB::getInstance();
942
		$oDB->begin();
943
944
		$output = $this->_deleteModuleSkinVars($module_srl, $mode);
945
		if(!$output->toBool())
946
		{
947
			$oDB->rollback();
948
			return $output;
949
		}
950
951
		getDestroyXeVars($obj);
952
		if(!$obj || !count($obj)) return new Object();
953
954
		$args = new stdClass;
955
		$args->module_srl = $module_srl;
956
		foreach($obj as $key => $val)
957
		{
958
			// #17927989 For an old board which used the old blog module
959
			// it often saved menu item(stdClass) on the skin info column
960
			// When updating the module on XE core 1.2.0 later versions, it occurs an error
961
			// fixed the error
962
			if (is_object($val)) continue;
963
			if (is_array($val)) $val = serialize($val);
964
965
			$args->name = trim($key);
966
			$args->value = trim($val);
967
			if(!$args->name || !$args->value) continue;
968
969
			if($mode === 'P')
970
			{
971
				$output = executeQuery('module.insertModuleSkinVars', $args);
972
			}
973
			else
974
			{
975
				$output = executeQuery('module.insertModuleMobileSkinVars', $args);
976
			}
977
			if(!$output->toBool())
978
			{
979
				return $output;
980
				$oDB->rollback();
0 ignored issues
show
Unused Code introduced by
$oDB->rollback(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
981
			}
982
		}
983
984
		$oDB->commit();
985
986
		return new Object();
987
	}
988
989
	/**
990
	 * Remove skin vars ofa module
991
	 * @param $module_srl seqence of module
992
	 */
993
	function deleteModuleSkinVars($module_srl)
994
	{
995
		return $this->_deleteModuleSkinVars($module_srl, 'P');
996
	}
997
998
	/**
999
	 * Remove mobile skin vars ofa module
1000
	 * @param $module_srl seqence of module
1001
	 */
1002
	function deleteModuleMobileSkinVars($module_srl)
1003
	{
1004
		return $this->_deleteModuleSkinVars($module_srl, 'M');
1005
	}
1006
1007
	/**
1008
	 * @brief Remove skin vars of a module
1009
	 */
1010
	function _deleteModuleSkinVars($module_srl, $mode)
1011
	{
1012
		$args = new stdClass();
1013
		$args->module_srl = $module_srl;
1014
		$mode = $mode === 'P' ? 'P' : 'M';
1015
1016
		if($mode === 'P')
1017
		{
1018
			$object_key = 'module_skin_vars:'.$module_srl;
1019
			$query = 'module.deleteModuleSkinVars';
1020
		}
1021
		else
1022
		{
1023
			$object_key = 'module_mobile_skin_vars:'.$module_srl;
1024
			$query = 'module.deleteModuleMobileSkinVars';
1025
		}
1026
1027
		//remove from cache
1028
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1029
		$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1030
		if($oCacheHandler->isSupport())
1031
		{
1032
			$oCacheHandler->delete($cache_key);
1033
		}
1034
1035
		return executeQuery($query, $args);
1036
	}
1037
1038
	/**
1039
	 * @brief Register extra vars to the module
1040
	 */
1041
	function insertModuleExtraVars($module_srl, $obj)
1042
	{
1043
		$this->deleteModuleExtraVars($module_srl);
1044
		getDestroyXeVars($obj);
1045
		if(!$obj || !count($obj)) return;
1046
1047
		foreach($obj as $key => $val)
1048
		{
1049
			if(is_object($val) || is_array($val)) continue;
1050
1051
			$args = new stdClass();
1052
			$args->module_srl = $module_srl;
1053
			$args->name = trim($key);
1054
			$args->value = trim($val);
1055
			if(!$args->name || !$args->value) continue;
1056
			$output = executeQuery('module.insertModuleExtraVars', $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...
1057
		}
1058
1059
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1060
		if($oCacheHandler->isSupport())
1061
		{
1062
			$object_key = 'module_extra_vars:'.$module_srl;
1063
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1064
			$oCacheHandler->delete($cache_key);
1065
		}
1066
	}
1067
1068
	/**
1069
	 * @brief Remove extra vars from the module
1070
	 */
1071 View Code Duplication
	function deleteModuleExtraVars($module_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...
1072
	{
1073
		$args = new stdClass();
1074
		$args->module_srl = $module_srl;
1075
		$output = executeQuery('module.deleteModuleExtraVars', $args);
1076
1077
		//remove from cache
1078
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1079
		if($oCacheHandler->isSupport())
1080
		{
1081
			$object_key = 'module_extra_vars:'.$module_srl;
1082
			$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
1083
			$oCacheHandler->delete($cache_key);
1084
		}
1085
1086
		return $output;
1087
	}
1088
1089
	/**
1090
	 * @brief Grant permission to the module
1091
	 */
1092
	function insertModuleGrants($module_srl, $obj)
1093
	{
1094
		$this->deleteModuleGrants($module_srl);
1095
		if(!$obj || !count($obj)) return;
1096
1097
		foreach($obj as $name => $val)
1098
		{
1099
			if(!$val || !count($val)) continue;
1100
1101
			foreach($val as $group_srl)
1102
			{
1103
				$args = new stdClass();
1104
				$args->module_srl = $module_srl;
1105
				$args->name = $name;
1106
				$args->group_srl = trim($group_srl);
1107
				if(!$args->name || !$args->group_srl) continue;
1108
				executeQuery('module.insertModuleGrant', $args);
1109
			}
1110
		}
1111
	}
1112
1113
	/**
1114
	 * @brief Remove permission from the module
1115
	 */
1116
	function deleteModuleGrants($module_srl)
1117
	{
1118
		$args = new stdClass();
1119
		$args->module_srl = $module_srl;
1120
		return executeQuery('module.deleteModuleGrants', $args);
1121
	}
1122
1123
	/**
1124
	 * @brief Change user-defined language
1125
	 */
1126
	function replaceDefinedLangCode(&$output, $isReplaceLangCode = true)
1127
	{
1128
		if($isReplaceLangCode)
1129
		{
1130
			$output = preg_replace_callback('!\$user_lang->([a-z0-9\_]+)!is', array($this,'_replaceLangCode'), $output);
1131
		}
1132
	}
1133
1134
	function _replaceLangCode($matches)
1135
	{
1136
		static $lang = null;
1137
1138
		if(is_null($lang))
1139
		{
1140
			$site_module_info = Context::get('site_module_info');
1141
			if(!$site_module_info)
1142
			{
1143
				$oModuleModel = getModel('module');
1144
				$site_module_info = $oModuleModel->getDefaultMid();
1145
				Context::set('site_module_info', $site_module_info);
1146
			}
1147
			$cache_file = sprintf('%sfiles/cache/lang_defined/%d.%s.php', _XE_PATH_, $site_module_info->site_srl, Context::getLangType());
1148
			if(!file_exists($cache_file))
1149
			{
1150
				$oModuleAdminController = getAdminController('module');
1151
				$oModuleAdminController->makeCacheDefinedLangCode($site_module_info->site_srl);
1152
			}
1153
1154
			if(file_exists($cache_file))
1155
			{
1156
				$moduleAdminControllerMtime = filemtime(_XE_PATH_ . 'modules/module/module.admin.controller.php');
1157
				$cacheFileMtime = filemtime($cache_file);
1158
				if($cacheFileMtime < $moduleAdminControllerMtime)
1159
				{
1160
					$oModuleAdminController = getAdminController('module');
1161
					$oModuleAdminController->makeCacheDefinedLangCode($site_module_info->site_srl);
1162
				}
1163
1164
				require_once($cache_file);
1165
			}
1166
		}
1167
		if(!Context::get($matches[1]) && $lang[$matches[1]]) return $lang[$matches[1]];
1168
1169
		return str_replace('$user_lang->','',$matches[0]);
1170
	}
1171
1172
1173
	/**
1174
	 * @brief Add and update a file into the file box
1175
	 */
1176
	function procModuleFileBoxAdd()
1177
	{
1178
		$ajax = Context::get('ajax');
1179
		if ($ajax) Context::setRequestMethod('JSON');
1180
1181
		$logged_info = Context::get('logged_info');
1182
		if($logged_info->is_admin !='Y' && !$logged_info->is_site_admin) return new Object(-1, 'msg_not_permitted');
1183
1184
		$vars = Context::gets('addfile','filter');
1185
		$attributeNames = Context::get('attribute_name');
1186
		$attributeValues = Context::get('attribute_value');
1187
		if(is_array($attributeNames) && is_array($attributeValues) && count($attributeNames) == count($attributeValues))
1188
		{
1189
			$attributes = array();
1190
			foreach($attributeNames as $no => $name)
1191
			{
1192
				if(empty($name))
1193
				{
1194
					continue;
1195
				}
1196
				$attributes[] = sprintf('%s:%s', $name, $attributeValues[$no]);
1197
			}
1198
			$attributes = implode(';', $attributes);
1199
		}
1200
1201
		$vars->comment = $attributes;
0 ignored issues
show
Bug introduced by
The variable $attributes 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...
1202
		$module_filebox_srl = Context::get('module_filebox_srl');
1203
1204
		$ext = strtolower(substr(strrchr($vars->addfile['name'],'.'),1));
1205
		$vars->ext = $ext;
1206
		if($vars->filter) $filter = explode(',',$vars->filter);
1207
		else $filter = array('jpg','jpeg','gif','png');
1208
		if(!in_array($ext,$filter)) return new Object(-1, 'msg_error_occured');
1209
1210
		$vars->member_srl = $logged_info->member_srl;
1211
1212
		// update
1213
		if($module_filebox_srl > 0)
1214
		{
1215
			$vars->module_filebox_srl = $module_filebox_srl;
1216
			$output = $this->updateModuleFileBox($vars);
1217
		}
1218
		// insert
1219
		else
1220
		{
1221
			if(!Context::isUploaded()) return new Object(-1, 'msg_error_occured');
1222
			$addfile = Context::get('addfile');
1223
			if(!is_uploaded_file($addfile['tmp_name'])) return new Object(-1, 'msg_error_occured');
1224
			if($vars->addfile['error'] != 0) return new Object(-1, 'msg_error_occured');
1225
			$output = $this->insertModuleFileBox($vars);
1226
		}
1227
1228
		$this->setTemplatePath($this->module_path.'tpl');
0 ignored issues
show
Bug introduced by
The property module_path 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...
1229
1230
		if (!$ajax)
1231
		{
1232
			$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispModuleAdminFileBox');
1233
			$this->setRedirectUrl($returnUrl);
1234
			return;
1235
		}
1236
		else
1237
		{
1238
			if($output) $this->add('save_filename', $output->get('save_filename'));
1239
			else $this->add('save_filename', '');
1240
		}
1241
	}
1242
1243
	/**
1244
	 * @brief Update a file into the file box
1245
	 */
1246
	function updateModuleFileBox($vars)
1247
	{
1248
		$args = new stdClass;
1249
		// have file
1250
		if($vars->addfile['tmp_name'] && is_uploaded_file($vars->addfile['tmp_name']))
1251
		{
1252
			$oModuleModel = getModel('module');
1253
			$output = $oModuleModel->getModuleFileBox($vars->module_filebox_srl);
1254
			FileHandler::removeFile($output->data->filename);
1255
1256
			$path = $oModuleModel->getModuleFileBoxPath($vars->module_filebox_srl);
1257
			FileHandler::makeDir($path);
1258
1259
			$save_filename = sprintf('%s%s.%s',$path, $vars->module_filebox_srl, $ext);
0 ignored issues
show
Bug introduced by
The variable $ext 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...
1260
			$tmp = $vars->addfile['tmp_name'];
1261
1262
			// Check uploaded file
1263
			if(!checkUploadedFile($tmp)) return false;
1264
1265
			if(!@move_uploaded_file($tmp, $save_filename))
1266
			{
1267
				return false;
1268
			}
1269
1270
			$args->fileextension = strtolower(substr(strrchr($vars->addfile['name'],'.'),1));
1271
			$args->filename = $save_filename;
1272
			$args->filesize = $vars->addfile['size'];
1273
		}
1274
1275
		$args->module_filebox_srl = $vars->module_filebox_srl;
1276
		$args->comment = $vars->comment;
1277
1278
		// FIXME $args ??
1279
1280
		return executeQuery('module.updateModuleFileBox', $vars);
1281
	}
1282
1283
1284
	/**
1285
	 * @brief Add a file into the file box
1286
	 */
1287
	function insertModuleFileBox($vars)
1288
	{
1289
		// set module_filebox_srl
1290
		$vars->module_filebox_srl = getNextSequence();
1291
1292
		// get file path
1293
		$oModuleModel = getModel('module');
1294
		$path = $oModuleModel->getModuleFileBoxPath($vars->module_filebox_srl);
1295
		FileHandler::makeDir($path);
1296
		$save_filename = sprintf('%s%s.%s',$path, $vars->module_filebox_srl, $vars->ext);
1297
		$tmp = $vars->addfile['tmp_name'];
1298
1299
		// Check uploaded file
1300
		if(!checkUploadedFile($tmp)) return false;
1301
1302
		// upload
1303
		if(!@move_uploaded_file($tmp, $save_filename))
1304
		{
1305
			return false;
1306
		}
1307
1308
		// insert
1309
		$args = new stdClass;
1310
		$args->module_filebox_srl = $vars->module_filebox_srl;
1311
		$args->member_srl = $vars->member_srl;
1312
		$args->comment = $vars->comment;
1313
		$args->filename = $save_filename;
1314
		$args->fileextension = strtolower(substr(strrchr($vars->addfile['name'],'.'),1));
1315
		$args->filesize = $vars->addfile['size'];
1316
1317
		$output = executeQuery('module.insertModuleFileBox', $args);
1318
		$output->add('save_filename', $save_filename);
1319
		return $output;
1320
	}
1321
1322
1323
	/**
1324
	 * @brief Delete a file from the file box
1325
	 */
1326
	function procModuleFileBoxDelete()
1327
	{
1328
		$logged_info = Context::get('logged_info');
1329
		if($logged_info->is_admin !='Y' && !$logged_info->is_site_admin) return new Object(-1, 'msg_not_permitted');
1330
1331
		$module_filebox_srl = Context::get('module_filebox_srl');
1332
		if(!$module_filebox_srl) return new Object(-1, 'msg_invalid_request');
1333
		$vars = new stdClass();
1334
		$vars->module_filebox_srl = $module_filebox_srl;
1335
		$output = $this->deleteModuleFileBox($vars);
1336
		if(!$output->toBool()) return $output;
1337
	}
1338
1339
	function deleteModuleFileBox($vars)
1340
	{
1341
		// delete real file
1342
		$oModuleModel = getModel('module');
1343
		$output = $oModuleModel->getModuleFileBox($vars->module_filebox_srl);
1344
		FileHandler::removeFile($output->data->filename);
1345
1346
		$args = new stdClass();
1347
		$args->module_filebox_srl = $vars->module_filebox_srl;
1348
		return executeQuery('module.deleteModuleFileBox', $args);
1349
	}
1350
1351
	/**
1352
	 * @brief function of locking (timeout is in seconds)
1353
	 */
1354
	function lock($lock_name, $timeout, $member_srl = null)
1355
	{
1356
		$this->unlockTimeoutPassed();
1357
		$args = new stdClass;
1358
		$args->lock_name = $lock_name;
1359
		if(!$timeout) $timeout = 60;
1360
		$args->deadline = date("YmdHis", $_SERVER['REQUEST_TIME'] + $timeout);
1361
		if($member_srl) $args->member_srl = $member_srl;
1362
		$output = executeQuery('module.insertLock', $args);
1363
		if($output->toBool())
1364
		{
1365
			$output->add('lock_name', $lock_name);
1366
			$output->add('deadline', $args->deadline);
1367
		}
1368
		return $output;
1369
	}
1370
1371
	function unlockTimeoutPassed()
1372
	{
1373
		executeQuery('module.deleteLocksTimeoutPassed');
1374
	}
1375
1376
	function unlock($lock_name, $deadline)
1377
	{
1378
		$args = new stdClass;
1379
		$args->lock_name = $lock_name;
1380
		$args->deadline = $deadline;
1381
		$output = executeQuery('module.deleteLock', $args);
1382
		return $output;
1383
	}
1384
1385
	function updateModuleInSites($site_srls, $args)
0 ignored issues
show
Unused Code introduced by
The parameter $args 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...
1386
	{
1387
		$args = new stdClass;
1388
		$args->site_srls = $site_srls;
1389
		$output = executeQuery('module.updateModuleInSites', $args);
1390
1391
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
1392
		if($oCacheHandler->isSupport())
1393
		{
1394
			$oCacheHandler->invalidateGroupKey('site_and_module');
1395
		}
1396
1397
		return $output;
1398
	}
1399
}
1400
/* End of file module.controller.php */
1401
/* Location: ./modules/module/module.controller.php */
1402