GitHub Access Token became invalid

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

ModuleHandler::shutdownHandler()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 17
nc 3
nop 0
dl 0
loc 29
rs 8.439
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
4
/**
5
 * @class ModuleHandler
6
 * @author NAVER ([email protected])
7
 * Handling modules
8
 *
9
 * @remarks This class is to excute actions of modules.
10
 *          Constructing an instance without any parameterconstructor, it finds the target module based on Context.
11
 *          If there is no act on the found module, excute an action referencing action_forward.
12
 * */
13
class ModuleHandler extends Handler
14
{
15
16
	var $module = NULL; ///< Module
17
	var $act = NULL; ///< action
18
	var $mid = NULL; ///< Module ID
19
	var $document_srl = NULL; ///< Document Number
20
	var $module_srl = NULL; ///< Module Number
21
	var $module_info = NULL; ///< Module Info. Object
22
	var $error = NULL; ///< an error code.
23
	var $httpStatusCode = NULL; ///< http status code.
24
25
	/**
26
	 * prepares variables to use in moduleHandler
27
	 * @param string $module name of module
28
	 * @param string $act name of action
29
	 * @param int $mid
30
	 * @param int $document_srl
31
	 * @param int $module_srl
32
	 * @return void
33
	 * */
34
35
	function ModuleHandler($module = '', $act = '', $mid = '', $document_srl = '', $module_srl = '')
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
36
	{
37
		// If XE has not installed yet, set module as install
38
		if(!Context::isInstalled())
39
		{
40
			$this->module = 'install';
41
			$this->act = Context::get('act');
42
			return;
43
		}
44
45
		$oContext = Context::getInstance();
46
		if($oContext->isSuccessInit == FALSE)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

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

Loading history...
47
		{
48
			$logged_info = Context::get('logged_info');
49
			if($logged_info->is_admin != "Y")
50
			{
51
				$this->error = 'msg_invalid_request';
52
				return;
53
			}
54
		}
55
56
		// Set variables from request arguments
57
		$this->module = $module ? $module : Context::get('module');
58
		$this->act = $act ? $act : Context::get('act');
59
		$this->mid = $mid ? $mid : Context::get('mid');
60
		$this->document_srl = $document_srl ? (int) $document_srl : (int) Context::get('document_srl');
61
		$this->module_srl = $module_srl ? (int) $module_srl : (int) Context::get('module_srl');
62
        if($entry = Context::get('entry'))
63
        {
64
            $this->entry = Context::convertEncodingStr($entry);
0 ignored issues
show
Bug introduced by
The property entry 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...
65
        }
66
67
		// Validate variables to prevent XSS
68
		$isInvalid = NULL;
69
		if($this->module && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->module))
70
		{
71
			$isInvalid = TRUE;
72
		}
73
		if($this->mid && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->mid))
74
		{
75
			$isInvalid = TRUE;
76
		}
77
		if($this->act && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->act))
78
		{
79
			$isInvalid = TRUE;
80
		}
81
		if($isInvalid)
82
		{
83
			htmlHeader();
84
			echo Context::getLang("msg_invalid_request");
85
			htmlFooter();
86
			Context::close();
87
			exit;
88
		}
89
90
		if(isset($this->act) && (strlen($this->act) >= 4 && substr_compare($this->act, 'disp', 0, 4) === 0))
91
		{
92
			if(Context::get('_use_ssl') == 'optional' && Context::isExistsSSLAction($this->act) && $_SERVER['HTTPS'] != 'on')
93
			{
94
				if(Context::get('_https_port')!=null) {
95
					header('location:https://' . $_SERVER['HTTP_HOST'] . ':' . Context::get('_https_port') . $_SERVER['REQUEST_URI']);
96
				} else {
97
					header('location:https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
98
				}
99
				return;
100
			}
101
		}
102
103
		// call a trigger before moduleHandler init
104
		ModuleHandler::triggerCall('moduleHandler.init', 'before', $this);
105
		if(__ERROR_LOG__ == 1 && __DEBUG_OUTPUT__ == 0)
106
		{
107
			if(__DEBUG_PROTECT__ === 0 || __DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ == $_SERVER['REMOTE_ADDR'])
108
			{
109
				set_error_handler(array($this, 'xeErrorLog'), E_WARNING);
110
				register_shutdown_function(array($this, 'shutdownHandler'));
111
			}
112
		}
113
114
		// execute addon (before module initialization)
115
		$called_position = 'before_module_init';
116
		$oAddonController = getController('addon');
117
		$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? 'mobile' : 'pc');
118
		if(file_exists($addon_file)) include($addon_file);
119
	}
120
121
	public static function xeErrorLog($errnumber, $errormassage, $errorfile, $errorline, $errorcontext)
0 ignored issues
show
Unused Code introduced by
The parameter $errorfile 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 $errorline 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 $errorcontext 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...
122
	{
123
		if(($errnumber & 3) == 0 || error_reporting() == 0)
124
		{
125
			return false;
126
		}
127
128
		set_error_handler(function() { }, ~0);
129
130
		$debug_file = _XE_PATH_ . 'files/_debug_message.php';
131
		if(!file_exists($debug_file))
132
		{
133
			$print[] = '<?php exit() ?>';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$print was never initialized. Although not strictly required by PHP, it is generally a good practice to add $print = 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...
134
		}
135
136
		$errorname = self::getErrorType($errnumber);
137
		$print[] = '['.date('Y-m-d H:i:s').'] ' . $errorname . ' : ' . $errormassage;
0 ignored issues
show
Bug introduced by
The variable $print 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...
138
		$backtrace_args = defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? \DEBUG_BACKTRACE_IGNORE_ARGS : 0;
139
		$backtrace = debug_backtrace($backtrace_args);
140 View Code Duplication
		if(count($backtrace) > 1 && $backtrace[1]['function'] === 'xeErrorLog' && !$backtrace[1]['class'])
141
		{
142
			array_shift($backtrace);
143
		}
144
145
		foreach($backtrace as $key => $value)
146
		{
147
			$message = '    - ' . $value['file'] . ' : ' . $value['line'];
148
			$print[] = $message;
149
		}
150
		$print[] = PHP_EOL;
151
		@file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND|LOCK_EX);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

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

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

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
152
		restore_error_handler();
153
154
		return true;
155
	}
156
157
	function shutdownHandler()
158
	{
159
		$errinfo = error_get_last();
160
		if ($errinfo === null || ($errinfo['type'] != 1 && $errinfo['type'] != 4))
161
		{
162
			return false;
163
		}
164
165
		set_error_handler(function() { }, ~0);
166
167
		$debug_file = _XE_PATH_ . 'files/_debug_message.php';
168
		if(!file_exists($debug_file))
169
		{
170
			$print[] = '<?php exit() ?>';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$print was never initialized. Although not strictly required by PHP, it is generally a good practice to add $print = 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...
171
		}
172
173
		$errorname = self::getErrorType($errinfo['type']);
174
		$print[] = '['.date('Y-m-d H:i:s').']';
0 ignored issues
show
Bug introduced by
The variable $print 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...
175
		$print[] = $errorname . ' : ' . $errinfo['message'];
176
177
		$message = '    - ' . $errinfo['file'] . ' : ' . $errinfo['line'];
178
		$print[] = $message;
179
180
		$print[] = PHP_EOL;
181
		@file_put_contents($debug_file, implode(PHP_EOL, $print), FILE_APPEND|LOCK_EX);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

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

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

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
182
		set_error_handler(array($this, 'dummyHandler'), ~0);
183
184
		return true;
185
	}
186
187
	public static function getErrorType($errno)
188
	{
189
		switch ($errno)
190
		{
191
			case E_ERROR: return 'Fatal Error';
192
			case E_WARNING: return 'Warning';
193
			case E_NOTICE: return 'Notice';
194
			case E_CORE_ERROR: return 'Core Error';
195
			case E_CORE_WARNING: return 'Core Warning';
196
			case E_COMPILE_ERROR: return 'Compile Error';
197
			case E_COMPILE_WARNING: return 'Compile Warning';
198
			case E_USER_ERROR: return 'User Error';
199
			case E_USER_WARNING: return 'User Warning';
200
			case E_USER_NOTICE: return 'User Notice';
201
			case E_STRICT: return 'Strict Standards';
202
			case E_PARSE: return 'Parse Error';
203
			case E_DEPRECATED: return 'Deprecated';
204
			case E_USER_DEPRECATED: return 'User Deprecated';
205
			case E_RECOVERABLE_ERROR: return 'Catchable Fatal Error';
206
			default: return 'Error';
207
		}
208
	}
209
210
	/**
211
	 * Initialization. It finds the target module based on module, mid, document_srl, and prepares to execute an action
212
	 * @return boolean true: OK, false: redirected
213
	 * */
214
	function init()
215
	{
216
		$oModuleModel = getModel('module');
217
		$site_module_info = Context::get('site_module_info');
218
219
		// if success_return_url and error_return_url is incorrect
220
		$urls = array(Context::get('success_return_url'), Context::get('error_return_url'));
221
		foreach($urls as $url)
222
		{
223
			if(empty($url))
224
			{
225
				continue;
226
			}
227
		
228
			$urlInfo = parse_url($url);
229
			$host = $urlInfo['host'];
230
		
231
			$dbInfo = Context::getDBInfo();
232
			$defaultUrlInfo = parse_url($dbInfo->default_url);
233
			$defaultHost = $defaultUrlInfo['host'];
234
		
235
			if($host && ($host != $defaultHost && $host != $site_module_info->domain))
236
			{
237
				throw new Exception('msg_default_url_is_null');
238
			}
239
		}
240
		
241
		if(!$this->document_srl && $this->mid && $this->entry)
242
		{
243
			$oDocumentModel = getModel('document');
244
			$this->document_srl = $oDocumentModel->getDocumentSrlByAlias($this->mid, $this->entry);
245
			if($this->document_srl)
246
			{
247
				Context::set('document_srl', $this->document_srl);
248
			}
249
		}
250
251
		// Get module's information based on document_srl, if it's specified
252
		if($this->document_srl)
253
		{
254
			
255
			$module_info = $oModuleModel->getModuleInfoByDocumentSrl($this->document_srl);
256
			// If the document does not exist, remove document_srl
257
			if(!$module_info)
258
			{
259
				unset($this->document_srl);
260
			}
261
			else
262
			{
263
				// If it exists, compare mid based on the module information
264
				// if mids are not matching, set it as the document's mid
265
				if(!$this->mid || ($this->mid != $module_info->mid))
266
				{
267
					
268
					if(Context::getRequestMethod() == 'GET')
269
					{
270
						$this->mid = $module_info->mid;
271
						header('location:' . getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl));
272
						return FALSE;
273
					}
274
					else
275
					{
276
						$this->mid = $module_info->mid;
277
						Context::set('mid', $this->mid);
278
					}
279
					
280
				}
281
				// if requested module is different from one of the document, remove the module information retrieved based on the document number
282
				if($this->module && $module_info->module != $this->module)
283
				{
284
					unset($module_info);
285
				}
286
			}
287
288
		}
289
290
		// If module_info is not set yet, and there exists mid information, get module information based on the mid
291
		if(!$module_info && $this->mid)
0 ignored issues
show
Bug introduced by
The variable $module_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...
292
		{
293
			$module_info = $oModuleModel->getModuleInfoByMid($this->mid, $site_module_info->site_srl);
294
			//if($this->module && $module_info->module != $this->module) unset($module_info);
295
		}
296
297
		// redirect, if module_site_srl and site_srl are different
298
		if(!$this->module && !$module_info && $site_module_info->site_srl == 0 && $site_module_info->module_site_srl > 0)
299
		{
300
			$site_info = $oModuleModel->getSiteInfo($site_module_info->module_site_srl);
301
			header("location:" . getNotEncodedSiteUrl($site_info->domain, 'mid', $site_module_info->mid));
302
			return FALSE;
303
		}
304
305
		// If module_info is not set still, and $module does not exist, find the default module
306
		if(!$module_info && !$this->module && !$this->mid)
307
		{
308
			$module_info = $site_module_info;
309
		}
310
311
		if(!$module_info && !$this->module && $site_module_info->module_site_srl)
312
		{
313
			$module_info = $site_module_info;
314
		}
315
316
		// redirect, if site_srl of module_info is different from one of site's module_info
317
		if($module_info && $module_info->site_srl != $site_module_info->site_srl && !isCrawler())
318
		{
319
			// If the module is of virtual site
320
			if($module_info->site_srl)
321
			{
322
				$site_info = $oModuleModel->getSiteInfo($module_info->site_srl);
323
				$redirect_url = getNotEncodedSiteUrl($site_info->domain, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry'));
324
				// If it's called from a virtual site, though it's not a module of the virtual site
325
			}
326
			else
327
			{
328
				$db_info = Context::getDBInfo();
329
				if(!$db_info->default_url)
330
				{
331
					return Context::getLang('msg_default_url_is_not_defined');
332
				}
333
				else
334
				{
335
					$redirect_url = getNotEncodedSiteUrl($db_info->default_url, 'mid', Context::get('mid'), 'document_srl', Context::get('document_srl'), 'module_srl', Context::get('module_srl'), 'entry', Context::get('entry'));
336
				}
337
			}
338
			header("location:" . $redirect_url);
339
			return FALSE;
340
		}
341
342
		// If module info was set, retrieve variables from the module information
343
		if($module_info)
344
		{
345
			$this->module = $module_info->module;
346
			$this->mid = $module_info->mid;
347
			$this->module_info = $module_info;
348
			Context::setBrowserTitle($module_info->browser_title);
349
350
			$viewType = (Mobile::isFromMobilePhone()) ? 'M' : 'P';
351
			$targetSrl = (Mobile::isFromMobilePhone()) ? 'mlayout_srl' : 'layout_srl';
352
353
			// use the site default layout.
354
			if($module_info->{$targetSrl} == -1)
355
			{
356
				$oLayoutAdminModel = getAdminModel('layout');
357
				$layoutSrl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $module_info->site_srl);
358
			}
359
			else
360
			{
361
				$layoutSrl = $module_info->{$targetSrl};
362
			}
363
364
			// reset a layout_srl in module_info.
365
			$module_info->{$targetSrl} = $layoutSrl;
366
367
			$part_config = $oModuleModel->getModulePartConfig('layout', $layoutSrl);
368
			Context::addHtmlHeader($part_config->header_script);
369
		}
370
371
		// Set module and mid into module_info
372
		if(!isset($this->module_info))
373
		{
374
			$this->module_info = new stdClass();
375
		}
376
		$this->module_info->module = $this->module;
377
		$this->module_info->mid = $this->mid;
378
379
		// Set site_srl add 2011 08 09
380
		$this->module_info->site_srl = $site_module_info->site_srl;
381
382
		// Still no module? it's an error
383
		if(!$this->module)
384
		{
385
			$this->error = 'msg_module_is_not_exists';
386
			$this->httpStatusCode = '404';
387
		}
388
389
		// If mid exists, set mid into context
390
		if($this->mid)
391
		{
392
			Context::set('mid', $this->mid, TRUE);
0 ignored issues
show
Documentation introduced by
TRUE is of type boolean, but the function expects a integer.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
393
		}
394
		
395
		// Call a trigger after moduleHandler init
396
		$output = ModuleHandler::triggerCall('moduleHandler.init', 'after', $this->module_info);
397
		if(!$output->toBool())
398
		{
399
			$this->error = $output->getMessage();
400
			return TRUE;
401
		}
402
403
		// Set current module info into context
404
		Context::set('current_module_info', $this->module_info);
0 ignored issues
show
Documentation introduced by
$this->module_info is of type object, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
405
406
		return TRUE;
407
	}
408
409
	/**
410
	 * get a module instance and execute an action
411
	 * @return ModuleObject executed module instance
412
	 * */
413
	function procModule()
414
	{
415
		$oModuleModel = getModel('module');
416
		$display_mode = Mobile::isFromMobilePhone() ? 'mobile' : 'view';
417
418
		// If error occurred while preparation, return a message instance
419
		if($this->error)
420
		{
421
			$this->_setInputErrorToContext();
422
			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
423
			$oMessageObject->setError(-1);
424
			$oMessageObject->setMessage($this->error);
425
			$oMessageObject->dispMessage();
426
			if($this->httpStatusCode)
427
			{
428
				$oMessageObject->setHttpStatusCode($this->httpStatusCode);
429
			}
430
			return $oMessageObject;
431
		}
432
433
		// Get action information with conf/module.xml
434
		$xml_info = $oModuleModel->getModuleActionXml($this->module);
435
436
		// If not installed yet, modify act
437
		if($this->module == "install")
438
		{
439
			if(!$this->act || !$xml_info->action->{$this->act})
440
			{
441
				$this->act = $xml_info->default_index_act;
442
			}
443
		}
444
445
		// if act exists, find type of the action, if not use default index act
446
		if(!$this->act)
447
		{
448
			$this->act = $xml_info->default_index_act;
449
		}
450
451
		// still no act means error
452
		if(!$this->act)
453
		{
454
			$this->error = 'msg_module_is_not_exists';
455
			$this->httpStatusCode = '404';
456
457
			$this->_setInputErrorToContext();
458
			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
459
			$oMessageObject->setError(-1);
460
			$oMessageObject->setMessage($this->error);
461
			$oMessageObject->dispMessage();
462
			if($this->httpStatusCode)
463
			{
464
				$oMessageObject->setHttpStatusCode($this->httpStatusCode);
465
			}
466
			return $oMessageObject;
467
		}
468
469
		// get type, kind
470
		$type = $xml_info->action->{$this->act}->type;
471
		$ruleset = $xml_info->action->{$this->act}->ruleset;
472
		$kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : '';
473
		if(!$kind && $this->module == 'admin')
474
		{
475
			$kind = 'admin';
476
		}
477
478
		// check REQUEST_METHOD in controller
479 View Code Duplication
		if($type == 'controller')
480
		{
481
			$allowedMethod = $xml_info->action->{$this->act}->method;
482
483
			if(!$allowedMethod)
484
			{
485
				$allowedMethodList[0] = 'POST';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$allowedMethodList was never initialized. Although not strictly required by PHP, it is generally a good practice to add $allowedMethodList = 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...
486
			}
487
			else
488
			{
489
				$allowedMethodList = explode('|', strtoupper($allowedMethod));
490
			}
491
492
			if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList))
493
			{
494
				$this->error = "msg_invalid_request";
495
				$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
496
				$oMessageObject->setError(-1);
497
				$oMessageObject->setMessage($this->error);
498
				$oMessageObject->dispMessage();
499
				return $oMessageObject;
500
			}
501
		}
502
503
		if($this->module_info->use_mobile != "Y")
504
		{
505
			Mobile::setMobile(FALSE);
506
		}
507
508
		$logged_info = Context::get('logged_info');
509
510
		// check CSRF for POST actions
511
		if($_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && $this->act !== 'procFileUpload' && !checkCSRF()) {
512
			$this->error = 'msg_invalid_request';
513
			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
514
			$oMessageObject->setError(-1);
515
			$oMessageObject->setMessage($this->error);
516
			$oMessageObject->dispMessage();
517
			return $oMessageObject;
518
		}
519
520
		// Admin ip
521
		if($kind == 'admin' && $_SESSION['denied_admin'] == 'Y')
522
		{
523
			$this->_setInputErrorToContext();
524
			$this->error = "msg_not_permitted_act";
525
			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
526
			$oMessageObject->setError(-1);
527
			$oMessageObject->setMessage($this->error);
528
			$oMessageObject->dispMessage();
529
			return $oMessageObject;
530
		}
531
532
		// if(type == view, and case for using mobilephone)
533
		if($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled())
534
		{
535
			$orig_type = "view";
536
			$type = "mobile";
537
			// create a module instance
538
			$oModule = $this->getModuleInstance($this->module, $type, $kind);
539 View Code Duplication
			if(!is_object($oModule) || !method_exists($oModule, $this->act))
540
			{
541
				$type = $orig_type;
542
				Mobile::setMobile(FALSE);
543
				$oModule = $this->getModuleInstance($this->module, $type, $kind);
544
			}
545
		}
546
		else
547
		{
548
			// create a module instance
549
			$oModule = $this->getModuleInstance($this->module, $type, $kind);
550
		}
551
552 View Code Duplication
		if(!is_object($oModule))
553
		{
554
			$this->_setInputErrorToContext();
555
			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
556
			$oMessageObject->setError(-1);
557
			$oMessageObject->setMessage($this->error);
558
			$oMessageObject->dispMessage();
559
			if($this->httpStatusCode)
560
			{
561
				$oMessageObject->setHttpStatusCode($this->httpStatusCode);
562
			}
563
			return $oMessageObject;
564
		}
565
566
		// If there is no such action in the module object
567
		if(!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act))
568
		{
569
570 View Code Duplication
			if(!Context::isInstalled())
571
			{
572
				$this->_setInputErrorToContext();
573
				$this->error = 'msg_invalid_request';
574
				$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
575
				$oMessageObject->setError(-1);
576
				$oMessageObject->setMessage($this->error);
577
				$oMessageObject->dispMessage();
578
				if($this->httpStatusCode)
579
				{
580
					$oMessageObject->setHttpStatusCode($this->httpStatusCode);
581
				}
582
				return $oMessageObject;
583
			}
584
585
			$forward = NULL;
586
			// 1. Look for the module with action name
587
			if(preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches))
588
			{
589
				$module = strtolower($matches[2] . $matches[3]);
590
				$xml_info = $oModuleModel->getModuleActionXml($module);
591
592
				if($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false'))
593
				{
594
					$forward = new stdClass();
595
					$forward->module = $module;
596
					$forward->type = $xml_info->action->{$this->act}->type;
597
					$forward->ruleset = $xml_info->action->{$this->act}->ruleset;
598
					$forward->act = $this->act;
599
				}
600 View Code Duplication
				else
601
				{
602
					$this->error = 'msg_invalid_request';
603
					$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
604
					$oMessageObject->setError(-1);
605
					$oMessageObject->setMessage($this->error);
606
					$oMessageObject->dispMessage();
607
608
					return $oMessageObject;
609
				}
610
			}
611
612
			if(!$forward)
613
			{
614
				$forward = $oModuleModel->getActionForward($this->act);
615
			}
616
617
			if($forward->module && $forward->type && $forward->act && $forward->act == $this->act)
618
			{
619
				$kind = stripos($forward->act, 'admin') !== FALSE ? 'admin' : '';
620
				$type = $forward->type;
621
				$ruleset = $forward->ruleset;
622
				$tpl_path = $oModule->getTemplatePath();
0 ignored issues
show
Unused Code introduced by
$tpl_path 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...
623
				$orig_module = $oModule;
0 ignored issues
show
Unused Code introduced by
$orig_module 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...
624
625
				$xml_info = $oModuleModel->getModuleActionXml($forward->module);
626
627
				// SECISSUE also check foward act method
628
				// check REQUEST_METHOD in controller
629 View Code Duplication
				if($type == 'controller')
630
				{
631
					$allowedMethod = $xml_info->action->{$forward->act}->method;
632
633
					if(!$allowedMethod)
634
					{
635
						$allowedMethodList[0] = 'POST';
0 ignored issues
show
Bug introduced by
The variable $allowedMethodList 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...
636
					}
637
					else
638
					{
639
						$allowedMethodList = explode('|', strtoupper($allowedMethod));
640
					}
641
642
					if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList))
643
					{
644
						$this->error = "msg_invalid_request";
645
						$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
646
						$oMessageObject->setError(-1);
647
						$oMessageObject->setMessage($this->error);
648
						$oMessageObject->dispMessage();
649
						return $oMessageObject;
650
					}
651
				}
652
653
				if($type == "view" && Mobile::isFromMobilePhone())
654
				{
655
					$orig_type = "view";
656
					$type = "mobile";
657
					// create a module instance
658
					$oModule = $this->getModuleInstance($forward->module, $type, $kind);
659 View Code Duplication
					if(!is_object($oModule) || !method_exists($oModule, $this->act))
660
					{
661
						$type = $orig_type;
662
						Mobile::setMobile(FALSE);
663
						$oModule = $this->getModuleInstance($forward->module, $type, $kind);
664
					}
665
				}
666
				else
667
				{
668
					$oModule = $this->getModuleInstance($forward->module, $type, $kind);
669
				}
670
671 View Code Duplication
				if(!is_object($oModule))
672
				{
673
					$this->_setInputErrorToContext();
674
					$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
675
					$oMessageObject->setError(-1);
676
					$oMessageObject->setMessage('msg_module_is_not_exists');
677
					$oMessageObject->dispMessage();
678
					if($this->httpStatusCode)
679
					{
680
						$oMessageObject->setHttpStatusCode($this->httpStatusCode);
681
					}
682
					return $oMessageObject;
683
				}
684
685
				if($this->module == "admin" && $type == "view")
686
				{
687
					if($logged_info->is_admin == 'Y')
688
					{
689
						if($this->act != 'dispLayoutAdminLayoutModify')
690
						{
691
							$oAdminView = getAdminView('admin');
692
							$oAdminView->makeGnbUrl($forward->module);
693
							$oModule->setLayoutPath("./modules/admin/tpl");
694
							$oModule->setLayoutFile("layout.html");
695
						}
696
					}
697 View Code Duplication
					else
698
					{
699
						$this->_setInputErrorToContext();
700
701
						$this->error = 'msg_is_not_administrator';
702
						$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
703
						$oMessageObject->setError(-1);
704
						$oMessageObject->setMessage($this->error);
705
						$oMessageObject->dispMessage();
706
						return $oMessageObject;
707
					}
708
				}
709
				if($kind == 'admin')
710
				{
711
					$grant = $oModuleModel->getGrant($this->module_info, $logged_info);
712
					if(!$grant->manager)
713
					{
714
						$this->_setInputErrorToContext();
715
						$this->error = 'msg_is_not_manager';
716
						$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
717
						$oMessageObject->setError(-1);
718
						$oMessageObject->setMessage($this->error);
719
						$oMessageObject->dispMessage();
720
						return $oMessageObject;
721
					}
722
					else
723
					{
724
						if(!$grant->is_admin && $this->module != $this->orig_module->module && $xml_info->permission->{$this->act} != 'manager')
0 ignored issues
show
Bug introduced by
The property orig_module does not seem to exist. Did you mean module?

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

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

Loading history...
725
						{
726
							$this->_setInputErrorToContext();
727
							$this->error = 'msg_is_not_administrator';
728
							$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
729
							$oMessageObject->setError(-1);
730
							$oMessageObject->setMessage($this->error);
731
							$oMessageObject->dispMessage();
732
							return $oMessageObject;
733
						}
734
					}
735
				}
736
			}
737
			else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act))
738
			{
739
				$this->act = $xml_info->default_index_act;
740
			}
741
			else
742
			{
743
				$this->error = 'msg_invalid_request';
744
				$oModule->setError(-1);
745
				$oModule->setMessage($this->error);
746
				return $oModule;
747
			}
748
		}
749
750
		// ruleset check...
751
		if(!empty($ruleset))
752
		{
753
			$rulesetModule = $forward->module ? $forward->module : $this->module;
0 ignored issues
show
Bug introduced by
The variable $forward 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...
754
			$rulesetFile = $oModuleModel->getValidatorFilePath($rulesetModule, $ruleset, $this->mid);
755
			if(!empty($rulesetFile))
756
			{
757
				if($_SESSION['XE_VALIDATOR_ERROR_LANG'])
758
				{
759
					$errorLang = $_SESSION['XE_VALIDATOR_ERROR_LANG'];
760
					foreach($errorLang as $key => $val)
761
					{
762
						Context::setLang($key, $val);
763
					}
764
					unset($_SESSION['XE_VALIDATOR_ERROR_LANG']);
765
				}
766
767
				$Validator = new Validator($rulesetFile);
768
				$result = $Validator->validate();
769
				if(!$result)
770
				{
771
					$lastError = $Validator->getLastError();
772
					$returnUrl = Context::get('error_return_url');
773
					$errorMsg = $lastError['msg'] ? $lastError['msg'] : 'validation error';
774
775
					//for xml response
776
					$oModule->setError(-1);
777
					$oModule->setMessage($errorMsg);
778
					//for html redirect
779
					$this->error = $errorMsg;
780
					$_SESSION['XE_VALIDATOR_ERROR'] = -1;
781
					$_SESSION['XE_VALIDATOR_MESSAGE'] = $this->error;
782
					$_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = 'error';
783
					$_SESSION['XE_VALIDATOR_RETURN_URL'] = $returnUrl;
784
					$_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id');
785
					$this->_setInputValueToSession();
786
					return $oModule;
787
				}
788
			}
789
		}
790
791
		$oModule->setAct($this->act);
792
793
		$this->module_info->module_type = $type;
794
		$oModule->setModuleInfo($this->module_info, $xml_info);
795
796
		$skipAct = array(
797
				'dispEditorConfigPreview' => 1,
798
				'dispLayoutPreviewWithModule' => 1
799
		);
800
		$db_use_mobile = Mobile::isMobileEnabled();
801
		if($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true)
802
		{
803
			global $lang;
804
			$header = '<style>div.xe_mobile{opacity:0.7;margin:1em 0;padding:.5em;background:#333;border:1px solid #666;border-left:0;border-right:0}p.xe_mobile{text-align:center;margin:1em 0}a.xe_mobile{color:#ff0;font-weight:bold;font-size:24px}@media only screen and (min-width:500px){a.xe_mobile{font-size:15px}}</style>';
805
			$footer = '<div class="xe_mobile"><p class="xe_mobile"><a class="xe_mobile" href="' . getUrl('m', '1') . '">' . $lang->msg_pc_to_mobile . '</a></p></div>';
806
			Context::addHtmlHeader($header);
807
			Context::addHtmlFooter($footer);
808
		}
809
810
		if($type == "view" && $kind != 'admin')
811
		{
812
			$module_config = $oModuleModel->getModuleConfig('module');
813
			if($module_config->htmlFooter)
814
			{
815
				Context::addHtmlFooter($module_config->htmlFooter);
816
			}
817
			if($module_config->siteTitle)
818
			{
819
				$siteTitle = Context::getBrowserTitle();
820
				if(!$siteTitle)
821
				{
822
					Context::setBrowserTitle($module_config->siteTitle);
823
				}
824
			}
825
		}
826
827
		// if failed message exists in session, set context
828
		$this->_setInputErrorToContext();
829
830
		$procResult = $oModule->proc();
831
832
		$methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1);
833
		if(!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()]))
834
		{
835
			$error = $oModule->getError();
836
			$message = $oModule->getMessage();
837
			$messageType = $oModule->getMessageType();
838
			$redirectUrl = $oModule->getRedirectUrl();
839
			if($messageType == 'error') debugPrint($message, 'ERROR');
0 ignored issues
show
Documentation introduced by
'ERROR' is of type string, but the function expects a boolean.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
840
841
			if(!$procResult)
842
			{
843
				$this->error = $message;
844
				if(!$redirectUrl && Context::get('error_return_url'))
845
				{
846
					$redirectUrl = Context::get('error_return_url');
847
				}
848
				$this->_setInputValueToSession();
849
			}
850
			else
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
851
			{
852
853
			}
854
855
			$_SESSION['XE_VALIDATOR_ERROR'] = $error;
856
			$_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id');
857
			if($message != 'success')
858
			{
859
				$_SESSION['XE_VALIDATOR_MESSAGE'] = $message;
860
			}
861
			$_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = $messageType;
862
863
			if(Context::get('xeVirtualRequestMethod') != 'xml')
864
			{
865
				$_SESSION['XE_VALIDATOR_RETURN_URL'] = $redirectUrl;
866
			}
867
		}
868
869
		unset($logged_info);
870
		return $oModule;
871
	}
872
873
	/**
874
	 * set error message to Session.
875
	 * @return void
876
	 * */
877
	function _setInputErrorToContext()
878
	{
879
		if($_SESSION['XE_VALIDATOR_ERROR'] && !Context::get('XE_VALIDATOR_ERROR'))
880
		{
881
			Context::set('XE_VALIDATOR_ERROR', $_SESSION['XE_VALIDATOR_ERROR']);
882
		}
883
		if($_SESSION['XE_VALIDATOR_MESSAGE'] && !Context::get('XE_VALIDATOR_MESSAGE'))
884
		{
885
			Context::set('XE_VALIDATOR_MESSAGE', $_SESSION['XE_VALIDATOR_MESSAGE']);
886
		}
887
		if($_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] && !Context::get('XE_VALIDATOR_MESSAGE_TYPE'))
888
		{
889
			Context::set('XE_VALIDATOR_MESSAGE_TYPE', $_SESSION['XE_VALIDATOR_MESSAGE_TYPE']);
890
		}
891
		if($_SESSION['XE_VALIDATOR_RETURN_URL'] && !Context::get('XE_VALIDATOR_RETURN_URL'))
892
		{
893
			Context::set('XE_VALIDATOR_RETURN_URL', $_SESSION['XE_VALIDATOR_RETURN_URL']);
894
		}
895
		if($_SESSION['XE_VALIDATOR_ID'] && !Context::get('XE_VALIDATOR_ID'))
896
		{
897
			Context::set('XE_VALIDATOR_ID', $_SESSION['XE_VALIDATOR_ID']);
898
		}
899
		if(count($_SESSION['INPUT_ERROR']))
900
		{
901
			Context::set('INPUT_ERROR', $_SESSION['INPUT_ERROR']);
902
		}
903
904
		$this->_clearErrorSession();
905
	}
906
907
	/**
908
	 * clear error message to Session.
909
	 * @return void
910
	 * */
911
	function _clearErrorSession()
912
	{
913
		$_SESSION['XE_VALIDATOR_ERROR'] = '';
914
		$_SESSION['XE_VALIDATOR_MESSAGE'] = '';
915
		$_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = '';
916
		$_SESSION['XE_VALIDATOR_RETURN_URL'] = '';
917
		$_SESSION['XE_VALIDATOR_ID'] = '';
918
		$_SESSION['INPUT_ERROR'] = '';
919
	}
920
921
	/**
922
	 * occured error when, set input values to session.
923
	 * @return void
924
	 * */
925
	function _setInputValueToSession()
926
	{
927
		$requestVars = Context::getRequestVars();
928
		unset($requestVars->act, $requestVars->mid, $requestVars->vid, $requestVars->success_return_url, $requestVars->error_return_url);
929
		foreach($requestVars AS $key => $value)
930
		{
931
			$_SESSION['INPUT_ERROR'][$key] = $value;
932
		}
933
	}
934
935
	/**
936
	 * display contents from executed module
937
	 * @param ModuleObject $oModule module instance
938
	 * @return void
939
	 * */
940
	function displayContent($oModule = NULL)
941
	{
942
		// If the module is not set or not an object, set error
943
		if(!$oModule || !is_object($oModule))
944
		{
945
			$this->error = 'msg_module_is_not_exists';
946
			$this->httpStatusCode = '404';
947
		}
948
949
		// If connection to DB has a problem even though it's not install module, set error
950
		if($this->module != 'install' && isset($GLOBALS['__DB__']) && $GLOBALS['__DB__'][Context::getDBType()]->isConnected() == FALSE)
951
		{
952
			$this->error = 'msg_dbconnect_failed';
953
		}
954
955
		// Call trigger after moduleHandler proc
956
		$output = ModuleHandler::triggerCall('moduleHandler.proc', 'after', $oModule);
0 ignored issues
show
Bug introduced by
It seems like $oModule defined by parameter $oModule on line 940 can be null; however, ModuleHandler::triggerCall() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
957
		if(!$output->toBool())
958
		{
959
			$this->error = $output->getMessage();
960
		}
961
962
		// Use message view object, if HTML call
963
		$methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1);
964
		if(!isset($methodList[Context::getRequestMethod()]))
965
		{
966
967
			if($_SESSION['XE_VALIDATOR_RETURN_URL'])
968
			{
969
				$display_handler = new DisplayHandler();
970
				$display_handler->_debugOutput();
971
972
				header('location:' . $_SESSION['XE_VALIDATOR_RETURN_URL']);
973
				return;
974
			}
975
976
			// If error occurred, handle it
977
			if($this->error)
978
			{
979
				// display content with message module instance
980
				$type = Mobile::isFromMobilePhone() ? 'mobile' : 'view';
981
				$oMessageObject = ModuleHandler::getModuleInstance('message', $type);
982
				$oMessageObject->setError(-1);
983
				$oMessageObject->setMessage($this->error);
984
				$oMessageObject->dispMessage();
985
986
				if($oMessageObject->getHttpStatusCode() && $oMessageObject->getHttpStatusCode() != '200')
987
				{
988
					$this->_setHttpStatusMessage($oMessageObject->getHttpStatusCode());
989
					$oMessageObject->setTemplateFile('http_status_code');
990
				}
991
992
				// If module was called normally, change the templates of the module into ones of the message view module
993
				if($oModule)
994
				{
995
					$oModule->setTemplatePath($oMessageObject->getTemplatePath());
996
					$oModule->setTemplateFile($oMessageObject->getTemplateFile());
997
					// Otherwise, set message instance as the target module
998
				}
999
				else
1000
				{
1001
					$oModule = $oMessageObject;
1002
				}
1003
1004
				$this->_clearErrorSession();
1005
			}
1006
1007
			// Check if layout_srl exists for the module
1008
			if(Mobile::isFromMobilePhone())
1009
			{
1010
				$layout_srl = $oModule->module_info->mlayout_srl;
1011
			}
1012
			else
1013
			{
1014
				$layout_srl = $oModule->module_info->layout_srl;
1015
			}
1016
1017
			// if layout_srl is rollback by module, set default layout
1018
			if($layout_srl == -1)
1019
			{
1020
				$viewType = (Mobile::isFromMobilePhone()) ? 'M' : 'P';
1021
				$oLayoutAdminModel = getAdminModel('layout');
1022
				$layout_srl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $oModule->module_info->site_srl);
1023
			}
1024
1025
			if($layout_srl && !$oModule->getLayoutFile())
1026
			{
1027
1028
				// If layout_srl exists, get information of the layout, and set the location of layout_path/ layout_file
1029
				$oLayoutModel = getModel('layout');
1030
				$layout_info = $oLayoutModel->getLayout($layout_srl);
0 ignored issues
show
Bug introduced by
The method getLayout() does not exist on ModuleObject. Did you maybe mean getLayoutFile()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1031
				if($layout_info)
1032
				{
1033
1034
					// Input extra_vars into $layout_info
1035 View Code Duplication
					if($layout_info->extra_var_count)
1036
					{
1037
1038
						foreach($layout_info->extra_var as $var_id => $val)
1039
						{
1040
							if($val->type == 'image')
1041
							{
1042
								if(strncmp('./files/attach/images/', $val->value, 22) === 0)
1043
								{
1044
									$val->value = Context::getRequestUri() . substr($val->value, 2);
1045
								}
1046
							}
1047
							$layout_info->{$var_id} = $val->value;
1048
						}
1049
					}
1050
					// Set menus into context
1051
					if($layout_info->menu_count)
1052
					{
1053
						foreach($layout_info->menu as $menu_id => $menu)
1054
						{
1055
							// set default menu set(included home menu)
1056 View Code Duplication
							if(!$menu->menu_srl || $menu->menu_srl == -1)
1057
							{
1058
								$oMenuAdminController = getAdminController('menu');
1059
								$homeMenuCacheFile = $oMenuAdminController->getHomeMenuCacheFile();
1060
1061
								if(FileHandler::exists($homeMenuCacheFile))
0 ignored issues
show
Bug Best Practice introduced by
The expression \FileHandler::exists($homeMenuCacheFile) of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

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

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

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

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1062
								{
1063
									include($homeMenuCacheFile);
1064
								}
1065
1066
								if(!$menu->menu_srl)
1067
								{
1068
									$menu->xml_file = str_replace('.xml.php', $homeMenuSrl . '.xml.php', $menu->xml_file);
0 ignored issues
show
Bug introduced by
The variable $homeMenuSrl 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...
1069
									$menu->php_file = str_replace('.php', $homeMenuSrl . '.php', $menu->php_file);
1070
									$layout_info->menu->{$menu_id}->menu_srl = $homeMenuSrl;
1071
								}
1072
								else
1073
								{
1074
									$menu->xml_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->xml_file);
1075
									$menu->php_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->php_file);
1076
								}
1077
							}
1078
1079
							$php_file = FileHandler::exists($menu->php_file);
1080
							if($php_file)
0 ignored issues
show
Bug Best Practice introduced by
The expression $php_file of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

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

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

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

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
1081
							{
1082
								include($php_file);
1083
							}
1084
							Context::set($menu_id, $menu);
1085
						}
1086
					}
1087
1088
					// Set layout information into context
1089
					Context::set('layout_info', $layout_info);
1090
1091
					$oModule->setLayoutPath($layout_info->path);
1092
					$oModule->setLayoutFile('layout');
1093
1094
					// If layout was modified, use the modified version
1095
					$edited_layout = $oLayoutModel->getUserLayoutHtml($layout_info->layout_srl);
1096
					if(file_exists($edited_layout))
1097
					{
1098
						$oModule->setEditedLayoutFile($edited_layout);
1099
					}
1100
				}
1101
			}
1102
			$isLayoutDrop = Context::get('isLayoutDrop');
1103
			if($isLayoutDrop)
1104
			{
1105
				$kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : '';
1106
				if($kind == 'admin')
1107
				{
1108
					$oModule->setLayoutFile('popup_layout');
1109
				}
1110
				else
1111
				{
1112
					$oModule->setLayoutPath('common/tpl');
1113
					$oModule->setLayoutFile('default_layout');
1114
				}
1115
			}
1116
		}
1117
1118
		// Display contents
1119
		$oDisplayHandler = new DisplayHandler();
1120
		$oDisplayHandler->printContent($oModule);
1121
	}
1122
1123
	/**
1124
	 * returns module's path
1125
	 * @param string $module module name
1126
	 * @return string path of the module
1127
	 * */
1128
	function getModulePath($module)
1129
	{
1130
		return sprintf('./modules/%s/', $module);
1131
	}
1132
1133
	/**
1134
	 * It creates a module instance
1135
	 * @param string $module module name
1136
	 * @param string $type instance type, (e.g., view, controller, model)
1137
	 * @param string $kind admin or svc
1138
	 * @return ModuleObject module instance (if failed it returns null)
1139
	 * @remarks if there exists a module instance created before, returns it.
1140
	 * */
1141
	function &getModuleInstance($module, $type = 'view', $kind = '')
1142
	{
1143
1144
		if(__DEBUG__ == 3)
1145
		{
1146
			$start_time = getMicroTime();
1147
		}
1148
1149
		$parent_module = $module;
1150
		$kind = strtolower($kind);
1151
		$type = strtolower($type);
1152
1153
		$kinds = array('svc' => 1, 'admin' => 1);
1154
		if(!isset($kinds[$kind]))
1155
		{
1156
			$kind = 'svc';
1157
		}
1158
1159
		$key = $module . '.' . ($kind != 'admin' ? '' : 'admin') . '.' . $type;
1160
1161
		if(is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__']))
1162
		{
1163
			$module = $extend_module = $GLOBALS['__MODULE_EXTEND__'][$key];
1164
		}
1165
1166
		// if there is no instance of the module in global variable, create a new one
1167
		if(!isset($GLOBALS['_loaded_module'][$module][$type][$kind]))
1168
		{
1169
			ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name);
1170
1171
			if($extend_module && (!is_readable($high_class_file) || !is_readable($class_file)))
0 ignored issues
show
Bug introduced by
The variable $extend_module 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...
1172
			{
1173
				$module = $parent_module;
1174
				ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name);
1175
			}
1176
1177
			// Check if the base class and instance class exist
1178
			if(!class_exists($module, true))
1179
			{
1180
				return NULL;
1181
			}
1182
			if(!class_exists($instance_name, true))
1183
			{
1184
				return NULL;
1185
			}
1186
1187
			// Create an instance
1188
			$oModule = new $instance_name();
1189
			if(!is_object($oModule))
1190
			{
1191
				return NULL;
1192
			}
1193
1194
			// Load language files for the class
1195
			Context::loadLang($class_path . 'lang');
1196
			if($extend_module)
1197
			{
1198
				Context::loadLang(ModuleHandler::getModulePath($parent_module) . 'lang');
1199
			}
1200
1201
			// Set variables to the instance
1202
			$oModule->setModule($module);
1203
			$oModule->setModulePath($class_path);
1204
1205
			// If the module has a constructor, run it.
1206
			if(!isset($GLOBALS['_called_constructor'][$instance_name]))
1207
			{
1208
				$GLOBALS['_called_constructor'][$instance_name] = TRUE;
1209
				if(@method_exists($oModule, $instance_name))
1210
				{
1211
					$oModule->{$instance_name}();
1212
				}
1213
			}
1214
1215
			// Store the created instance into GLOBALS variable
1216
			$GLOBALS['_loaded_module'][$module][$type][$kind] = $oModule;
1217
		}
1218
1219
		if(__DEBUG__ == 3)
1220
		{
1221
			$GLOBALS['__elapsed_class_load__'] += getMicroTime() - $start_time;
0 ignored issues
show
Bug introduced by
The variable $start_time 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...
1222
		}
1223
1224
		// return the instance
1225
		return $GLOBALS['_loaded_module'][$module][$type][$kind];
1226
	}
1227
1228
	function _getModuleFilePath($module, $type, $kind, &$classPath, &$highClassFile, &$classFile, &$instanceName)
1229
	{
1230
		$classPath = ModuleHandler::getModulePath($module);
1231
1232
		$highClassFile = sprintf('%s%s%s.class.php', _XE_PATH_, $classPath, $module);
1233
		$highClassFile = FileHandler::getRealPath($highClassFile);
1234
1235
		$types = array('view','controller','model','api','wap','mobile','class');
1236
		if(!in_array($type, $types))
1237
		{
1238
			$type = $types[0];
1239
		}
1240
		if($type == 'class')
1241
		{
1242
			$instanceName = '%s';
1243
			$classFile = '%s%s.%s.php';
1244
		}
1245
		elseif($kind == 'admin' && array_search($type, $types) < 3)
1246
		{
1247
			$instanceName = '%sAdmin%s';
1248
			$classFile = '%s%s.admin.%s.php';
1249
		}
1250
		else
1251
		{
1252
			$instanceName = '%s%s';
1253
			$classFile = '%s%s.%s.php';
1254
		}
1255
1256
		$instanceName = sprintf($instanceName, $module, ucfirst($type));
1257
		$classFile = FileHandler::getRealPath(sprintf($classFile, $classPath, $module, $type));
1258
	}
1259
1260
	/**
1261
	 * call a trigger
1262
	 * @param string $trigger_name trigger's name to call
1263
	 * @param string $called_position called position
1264
	 * @param object $obj an object as a parameter to trigger
1265
	 * @return Object
1266
	 * */
1267
	function triggerCall($trigger_name, $called_position, &$obj)
1268
	{
1269
		// skip if not installed
1270
		if(!Context::isInstalled())
1271
		{
1272
			return new Object();
1273
		}
1274
1275
		$oModuleModel = getModel('module');
1276
		$triggers = $oModuleModel->getTriggers($trigger_name, $called_position);
1277
		if(!$triggers || count($triggers) < 1)
1278
		{
1279
			return new Object();
1280
		}
1281
		
1282
		//store before trigger call time
1283
		$before_trigger_time = NULL;
0 ignored issues
show
Unused Code introduced by
$before_trigger_time 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...
1284
		if(__LOG_SLOW_TRIGGER__> 0)
1285
		{
1286
			$before_trigger_time = microtime(true);
0 ignored issues
show
Unused Code introduced by
$before_trigger_time 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...
1287
		}
1288
1289
		foreach($triggers as $item)
1290
		{
1291
			$module = $item->module;
1292
			$type = $item->type;
1293
			$called_method = $item->called_method;
1294
1295
			// todo why don't we call a normal class object ?
1296
			$oModule = getModule($module, $type);
1297
			if(!$oModule || !method_exists($oModule, $called_method))
1298
			{
1299
				continue;
1300
			}
1301
1302
			$before_each_trigger_time = microtime(true);
1303
1304
			$output = $oModule->{$called_method}($obj);
1305
1306
			$after_each_trigger_time = microtime(true);
1307
			$elapsed_time_trigger = $after_each_trigger_time - $before_each_trigger_time;
1308
1309
			$slowlog = new stdClass;
1310
			$slowlog->caller = $trigger_name . '.' . $called_position;
1311
			$slowlog->called = $module . '.' . $called_method;
1312
			$slowlog->called_extension = $module;
1313
			if($trigger_name != 'XE.writeSlowlog') writeSlowlog('trigger', $elapsed_time_trigger, $slowlog);
1314
1315
			if(is_object($output) && method_exists($output, 'toBool') && !$output->toBool())
1316
			{
1317
				return $output;
1318
			}
1319
			unset($oModule);
1320
		}
1321
1322
		return new Object();
1323
	}
1324
1325
	/**
1326
	 * get http status message by http status code
1327
	 * @param string $code
1328
	 * @return string
1329
	 * */
1330
	function _setHttpStatusMessage($code)
1331
	{
1332
		$statusMessageList = array(
1333
			// 1×× Informational
1334
			'100' => 'Continue',
1335
			'101' => 'Switching Protocols',
1336
			'102' => 'Processing',
1337
			// 2×× Success
1338
			'200' => 'OK',
1339
			'201' => 'Created',
1340
			'202' => 'Accepted',
1341
			'203' => 'Non-authoritative Information',
1342
			'204' => 'No Content',
1343
			'205' => 'Reset Content',
1344
			'206' => 'Partial Content',
1345
			'207' => 'Multi-Status',
1346
			'208' => 'Already Reported',
1347
			'226' => 'IM Used',
1348
			// 3×× Redirection
1349
			'300' => 'Multiple Choices',
1350
			'301' => 'Moved Permanently',
1351
			'302' => 'Found',
1352
			'303' => 'See Other',
1353
			'304' => 'Not Modified',
1354
			'305' => 'Use Proxy',
1355
			'307' => 'Temporary Redirect',
1356
			'308' => 'Permanent Redirect',
1357
			// 4×× Client Error
1358
			'400' => 'Bad Request',
1359
			'401' => 'Unauthorized',
1360
			'402' => 'Payment Required',
1361
			'403' => 'Forbidden',
1362
			'404' => 'Not Found',
1363
			'405' => 'Method Not Allowed',
1364
			'406' => 'Not Acceptable',
1365
			'407' => 'Proxy Authentication Required',
1366
			'408' => 'Request Timeout',
1367
			'409' => 'Conflict',
1368
			'410' => 'Gone',
1369
			'411' => 'Length Required',
1370
			'412' => 'Precondition Failed',
1371
			'413' => 'Payload Too Large',
1372
			'414' => 'Request-URI Too Long',
1373
			'415' => 'Unsupported Media Type',
1374
			'416' => 'Requested Range Not Satisfiable',
1375
			'417' => 'Expectation Failed',
1376
			'418' => 'I\'m a teapot',
1377
			'421' => 'Misdirected Request',
1378
			'422' => 'Unprocessable Entity',
1379
			'423' => 'Locked',
1380
			'424' => 'Failed Dependency',
1381
			'426' => 'Upgrade Required',
1382
			'428' => 'Precondition Required',
1383
			'429' => 'Too Many Requests',
1384
			'431' => 'Request Header Fields Too Large',
1385
			'451' => 'Unavailable For Legal Reasons',
1386
			// 5×× Server Error
1387
			'500' => 'Internal Server Error',
1388
			'501' => 'Not Implemented',
1389
			'502' => 'Bad Gateway',
1390
			'503' => 'Service Unavailable',
1391
			'504' => 'Gateway Timeout',
1392
			'505' => 'HTTP Version Not Supported',
1393
			'506' => 'Variant Also Negotiates',
1394
			'507' => 'Insufficient Storage',
1395
			'508' => 'Loop Detected',
1396
			'510' => 'Not Extended',
1397
			'511' => 'Network Authentication Required',
1398
		);
1399
		$statusMessage = $statusMessageList[$code];
1400
		if(!$statusMessage)
1401
		{
1402
			$statusMessage = 'HTTP ' . $code;
1403
		}
1404
1405
		Context::set('http_status_code', $code);
1406
		Context::set('http_status_message', $statusMessage);
1407
	}
1408
1409
}
1410
/* End of file ModuleHandler.class.php */
1411
/* Location: ./classes/module/ModuleHandler.class.php */
1412