GitHub Access Token became invalid

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

ModuleHandler::__construct()   F

Complexity

Conditions 30
Paths 7682

Size

Total Lines 82

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 30
nc 7682
nop 5
dl 0
loc 82
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
	 * */
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
34
35
	function __construct($module = '', $act = '', $mid = '', $document_srl = '', $module_srl = '')
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
			// @see https://github.com/xpressengine/xe-core/issues/2304
49
			$this->error = 'msg_invalid_request';
50
			return;
51
		}
52
53
		// Set variables from request arguments
54
		$this->module = $module ? $module : Context::get('module');
55
		$this->act = $act ? $act : Context::get('act');
56
		$this->mid = $mid ? $mid : Context::get('mid');
57
		$this->document_srl = $document_srl ? (int) $document_srl : (int) Context::get('document_srl');
58
		$this->module_srl = $module_srl ? (int) $module_srl : (int) Context::get('module_srl');
59
        if($entry = Context::get('entry'))
60
        {
61
            $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...
62
        }
63
64
		// Validate variables to prevent XSS
65
		$isInvalid = NULL;
66
		if($this->module && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->module))
67
		{
68
			$isInvalid = TRUE;
69
		}
70
		if($this->mid && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->mid))
71
		{
72
			$isInvalid = TRUE;
73
		}
74
		if($this->act && !preg_match("/^([a-z0-9\_\-]+)$/i", $this->act))
75
		{
76
			$isInvalid = TRUE;
77
		}
78
		if($isInvalid)
79
		{
80
			htmlHeader();
81
			echo Context::getLang("msg_invalid_request");
82
			htmlFooter();
83
			Context::close();
84
			exit;
85
		}
86
87
		if(isset($this->act) && (strlen($this->act) >= 4 && substr_compare($this->act, 'disp', 0, 4) === 0))
88
		{
89
			if(Context::get('_use_ssl') == 'optional' && Context::isExistsSSLAction($this->act) && $_SERVER['HTTPS'] != 'on')
90
			{
91
				if(Context::get('_https_port')!=null) {
92
					header('location:https://' . $_SERVER['HTTP_HOST'] . ':' . Context::get('_https_port') . $_SERVER['REQUEST_URI']);
93
				} else {
94
					header('location:https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
95
				}
96
				return;
97
			}
98
		}
99
100
		// call a trigger before moduleHandler init
101
		ModuleHandler::triggerCall('moduleHandler.init', 'before', $this);
102
		if(__ERROR_LOG__ == 1 && __DEBUG_OUTPUT__ == 0)
103
		{
104
			if(__DEBUG_PROTECT__ === 0 || __DEBUG_PROTECT__ === 1 && __DEBUG_PROTECT_IP__ == $_SERVER['REMOTE_ADDR'])
105
			{
106
				set_error_handler(array($this, 'xeErrorLog'), E_WARNING);
107
				register_shutdown_function(array($this, 'shutdownHandler'));
108
			}
109
		}
110
111
		// execute addon (before module initialization)
112
		$called_position = 'before_module_init';
113
		$oAddonController = getController('addon');
114
		$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? 'mobile' : 'pc');
115
		if(file_exists($addon_file)) include($addon_file);
116
	}
117
118
	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...
119
	{
120
		if(($errnumber & 3) == 0 || error_reporting() == 0)
121
		{
122
			return false;
123
		}
124
125
		set_error_handler(function() { }, ~0);
126
127
		$debug_file = _XE_PATH_ . 'files/_debug_message.php';
128
		if(!file_exists($debug_file))
129
		{
130
			$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...
131
		}
132
133
		$errorname = self::getErrorType($errnumber);
134
		$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...
135
		$backtrace_args = defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? \DEBUG_BACKTRACE_IGNORE_ARGS : 0;
136
		$backtrace = debug_backtrace($backtrace_args);
137 View Code Duplication
		if(count($backtrace) > 1 && $backtrace[1]['function'] === 'xeErrorLog' && !$backtrace[1]['class'])
138
		{
139
			array_shift($backtrace);
140
		}
141
142
		foreach($backtrace as $key => $value)
143
		{
144
			$message = '    - ' . $value['file'] . ' : ' . $value['line'];
145
			$print[] = $message;
146
		}
147
		$print[] = PHP_EOL;
148
		@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...
149
		restore_error_handler();
150
151
		return true;
152
	}
153
154
	function shutdownHandler()
155
	{
156
		$errinfo = error_get_last();
157
		if ($errinfo === null || ($errinfo['type'] != 1 && $errinfo['type'] != 4))
158
		{
159
			return false;
160
		}
161
162
		set_error_handler(function() { }, ~0);
163
164
		$debug_file = _XE_PATH_ . 'files/_debug_message.php';
165
		if(!file_exists($debug_file))
166
		{
167
			$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...
168
		}
169
170
		$errorname = self::getErrorType($errinfo['type']);
171
		$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...
172
		$print[] = $errorname . ' : ' . $errinfo['message'];
173
174
		$message = '    - ' . $errinfo['file'] . ' : ' . $errinfo['line'];
175
		$print[] = $message;
176
177
		$print[] = PHP_EOL;
178
		@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...
179
		set_error_handler(array($this, 'dummyHandler'), ~0);
180
181
		return true;
182
	}
183
184
	public static function getErrorType($errno)
185
	{
186
		switch ($errno)
187
		{
188
			case E_ERROR: return 'Fatal Error';
189
			case E_WARNING: return 'Warning';
190
			case E_NOTICE: return 'Notice';
191
			case E_CORE_ERROR: return 'Core Error';
192
			case E_CORE_WARNING: return 'Core Warning';
193
			case E_COMPILE_ERROR: return 'Compile Error';
194
			case E_COMPILE_WARNING: return 'Compile Warning';
195
			case E_USER_ERROR: return 'User Error';
196
			case E_USER_WARNING: return 'User Warning';
197
			case E_USER_NOTICE: return 'User Notice';
198
			case E_STRICT: return 'Strict Standards';
199
			case E_PARSE: return 'Parse Error';
200
			case E_DEPRECATED: return 'Deprecated';
201
			case E_USER_DEPRECATED: return 'User Deprecated';
202
			case E_RECOVERABLE_ERROR: return 'Catchable Fatal Error';
203
			default: return 'Error';
204
		}
205
	}
206
207
	/**
208
	 * Initialization. It finds the target module based on module, mid, document_srl, and prepares to execute an action
209
	 * @return boolean true: OK, false: redirected
210
	 * */
211
	function init()
212
	{
213
		$oModuleModel = getModel('module');
214
		$site_module_info = Context::get('site_module_info');
215
216
		// if success_return_url and error_return_url is incorrect
217
		$urls = array(Context::get('success_return_url'), Context::get('error_return_url'));
218
		$dbInfo = Context::getDBInfo();
219
		$defaultUrlInfo = parse_url($dbInfo->default_url);
220
		$defaultHost = $defaultUrlInfo['host'];
221
222
		foreach($urls as $url)
223
		{
224
			if(empty($url))
225
			{
226
				continue;
227
			}
228
229
			$urlInfo = parse_url($url);
230
			$host = $urlInfo['host'];
231
232
			if($host && ($host != $defaultHost && $host != $site_module_info->domain))
233
			{
234
				throw new Exception('msg_default_url_is_null');
235
			}
236
		}
237
238
		if(!$this->document_srl && $this->mid && $this->entry)
239
		{
240
			$oDocumentModel = getModel('document');
241
			$this->document_srl = $oDocumentModel->getDocumentSrlByAlias($this->mid, $this->entry);
242
			if($this->document_srl)
243
			{
244
				Context::set('document_srl', $this->document_srl);
245
			}
246
		}
247
248
		// Get module's information based on document_srl, if it's specified
249
		if($this->document_srl)
250
		{
251
252
			$module_info = $oModuleModel->getModuleInfoByDocumentSrl($this->document_srl);
253
			// If the document does not exist, remove document_srl
254
			if(!$module_info)
255
			{
256
				unset($this->document_srl);
257
			}
258
			else
259
			{
260
				// If it exists, compare mid based on the module information
261
				// if mids are not matching, set it as the document's mid
262
				if(!$this->mid || ($this->mid != $module_info->mid))
263
				{
264
265
					if(Context::getRequestMethod() == 'GET')
266
					{
267
						$this->mid = $module_info->mid;
268
						header('location:' . getNotEncodedSiteUrl($site_module_info->domain, 'mid', $this->mid, 'document_srl', $this->document_srl));
269
						return FALSE;
270
					}
271
					else
272
					{
273
						$this->mid = $module_info->mid;
274
						Context::set('mid', $this->mid);
275
					}
276
277
				}
278
				// if requested module is different from one of the document, remove the module information retrieved based on the document number
279
				if($this->module && $module_info->module != $this->module)
280
				{
281
					unset($module_info);
282
				}
283
			}
284
285
		}
286
287
		// If module_info is not set yet, and there exists mid information, get module information based on the mid
288
		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...
289
		{
290
			$module_info = $oModuleModel->getModuleInfoByMid($this->mid, $site_module_info->site_srl);
291
			//if($this->module && $module_info->module != $this->module) unset($module_info);
292
		}
293
294
		// redirect, if module_site_srl and site_srl are different
295
		if(!$this->module && !$module_info && $site_module_info->site_srl == 0 && $site_module_info->module_site_srl > 0)
296
		{
297
			$site_info = $oModuleModel->getSiteInfo($site_module_info->module_site_srl);
298
			header("location:" . getNotEncodedSiteUrl($site_info->domain, 'mid', $site_module_info->mid));
299
			return FALSE;
300
		}
301
302
		// If module_info is not set still, and $module does not exist, find the default module
303
		if(!$module_info && !$this->module && !$this->mid)
304
		{
305
			$module_info = $site_module_info;
306
		}
307
308
		if(!$module_info && !$this->module && $site_module_info->module_site_srl)
309
		{
310
			$module_info = $site_module_info;
311
		}
312
313
		// redirect, if site_srl of module_info is different from one of site's module_info
314
		if($module_info && $module_info->site_srl != $site_module_info->site_srl && !isCrawler())
315
		{
316
			// If the module is of virtual site
317
			if($module_info->site_srl)
318
			{
319
				$site_info = $oModuleModel->getSiteInfo($module_info->site_srl);
320
				$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'));
321
				// If it's called from a virtual site, though it's not a module of the virtual site
322
			}
323
			else
324
			{
325
				$db_info = Context::getDBInfo();
326
				if(!$db_info->default_url)
327
				{
328
					return Context::getLang('msg_default_url_is_not_defined');
329
				}
330
				else
331
				{
332
					$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'));
333
				}
334
			}
335
			header("location:" . $redirect_url);
336
			return FALSE;
337
		}
338
339
		// If module info was set, retrieve variables from the module information
340
		if($module_info)
341
		{
342
			$this->module = $module_info->module;
343
			$this->mid = $module_info->mid;
344
			$this->module_info = $module_info;
345
			Context::setBrowserTitle($module_info->browser_title);
346
347
			$viewType = (Mobile::isFromMobilePhone()) ? 'M' : 'P';
348
			$targetSrl = (Mobile::isFromMobilePhone()) ? 'mlayout_srl' : 'layout_srl';
349
350
			// use the site default layout.
351
			if($module_info->{$targetSrl} == -1)
352
			{
353
				$oLayoutAdminModel = getAdminModel('layout');
354
				$layoutSrl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $module_info->site_srl);
355
			}
356
			else
357
			{
358
				$layoutSrl = $module_info->{$targetSrl};
359
			}
360
361
			// reset a layout_srl in module_info.
362
			$module_info->{$targetSrl} = $layoutSrl;
363
364
			$part_config = $oModuleModel->getModulePartConfig('layout', $layoutSrl);
365
			Context::addHtmlHeader($part_config->header_script);
366
		}
367
368
		// Set module and mid into module_info
369
		if(!isset($this->module_info))
370
		{
371
			$this->module_info = new stdClass();
372
		}
373
		$this->module_info->module = $this->module;
374
		$this->module_info->mid = $this->mid;
375
376
		// Set site_srl add 2011 08 09
377
		$this->module_info->site_srl = $site_module_info->site_srl;
378
379
		// Still no module? it's an error
380
		if(!$this->module)
381
		{
382
			$this->error = 'msg_module_is_not_exists';
383
			$this->httpStatusCode = '404';
384
		}
385
386
		// If mid exists, set mid into context
387
		if($this->mid)
388
		{
389
			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...
390
		}
391
392
		// Call a trigger after moduleHandler init
393
		$output = ModuleHandler::triggerCall('moduleHandler.init', 'after', $this->module_info);
394
		if(!$output->toBool())
395
		{
396
			$this->error = $output->getMessage();
397
			return TRUE;
398
		}
399
400
		// Set current module info into context
401
		Context::set('current_module_info', $this->module_info);
402
403
		return TRUE;
404
	}
405
406
	/**
407
	 * get a module instance and execute an action
408
	 * @return ModuleObject executed module instance
409
	 * */
410
	function procModule()
411
	{
412
		$oModuleModel = getModel('module');
413
		$display_mode = Mobile::isFromMobilePhone() ? 'mobile' : 'view';
414
415
		// If error occurred while preparation, return a message instance
416
		if($this->error)
417
		{
418
			$this->_setInputErrorToContext();
419
			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
420
			$oMessageObject->setError(-1);
421
			$oMessageObject->setMessage($this->error);
422
			$oMessageObject->dispMessage();
423
			if($this->httpStatusCode)
424
			{
425
				$oMessageObject->setHttpStatusCode($this->httpStatusCode);
426
			}
427
			return $oMessageObject;
428
		}
429
430
		// Get action information with conf/module.xml
431
		$xml_info = $oModuleModel->getModuleActionXml($this->module);
432
433
		// If not installed yet, modify act
434
		if($this->module == "install")
435
		{
436
			if(!$this->act || !$xml_info->action->{$this->act})
437
			{
438
				$this->act = $xml_info->default_index_act;
439
			}
440
		}
441
442
		// if act exists, find type of the action, if not use default index act
443
		if(!$this->act)
444
		{
445
			$this->act = $xml_info->default_index_act;
446
		}
447
448
		// still no act means error
449
		if(!$this->act)
450
		{
451
			$this->error = 'msg_module_is_not_exists';
452
			$this->httpStatusCode = '404';
453
454
			$this->_setInputErrorToContext();
455
			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
456
			$oMessageObject->setError(-1);
457
			$oMessageObject->setMessage($this->error);
458
			$oMessageObject->dispMessage();
459
			if($this->httpStatusCode)
460
			{
461
				$oMessageObject->setHttpStatusCode($this->httpStatusCode);
462
			}
463
			return $oMessageObject;
464
		}
465
466
		// get type, kind
467
		$type = $xml_info->action->{$this->act}->type;
468
		$ruleset = $xml_info->action->{$this->act}->ruleset;
469
		$meta_noindex = $xml_info->action->{$this->act}->meta_noindex;
470
		$kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : '';
471
472
		if ($meta_noindex === 'true')
473
		{
474
			Context::addMetaTag('robots', 'noindex');
475
		}
476
477
		if(!$kind && $this->module == 'admin')
478
		{
479
			$kind = 'admin';
480
		}
481
482
		// check REQUEST_METHOD in controller
483 View Code Duplication
		if($type == 'controller')
484
		{
485
			$allowedMethod = $xml_info->action->{$this->act}->method;
486
487
			if(!$allowedMethod)
488
			{
489
				$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...
490
			}
491
			else
492
			{
493
				$allowedMethodList = explode('|', strtoupper($allowedMethod));
494
			}
495
496
			if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList))
497
			{
498
				$this->error = "msg_invalid_request";
499
				$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
500
				$oMessageObject->setError(-1);
501
				$oMessageObject->setMessage($this->error);
502
				$oMessageObject->dispMessage();
503
				return $oMessageObject;
504
			}
505
		}
506
507
		if($this->module_info->use_mobile != "Y")
508
		{
509
			Mobile::setMobile(FALSE);
510
		}
511
512
		$logged_info = Context::get('logged_info');
513
514
		// check CSRF for non-GET actions
515
		$use_check_csrf = isset($xml_info->action->{$this->act}) && $xml_info->action->{$this->act}->check_csrf !== 'false';
516 View Code Duplication
		if($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF())
517
		{
518
			$this->error = 'msg_invalid_request';
519
			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
520
			$oMessageObject->setError(-1);
521
			$oMessageObject->setMessage($this->error);
522
			$oMessageObject->dispMessage();
523
			return $oMessageObject;
524
		}
525
526
		// Admin ip
527
		if($kind == 'admin' && $_SESSION['denied_admin'] == 'Y')
528
		{
529
			$this->_setInputErrorToContext();
530
			$this->error = "msg_not_permitted_act";
531
			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
532
			$oMessageObject->setError(-1);
533
			$oMessageObject->setMessage($this->error);
534
			$oMessageObject->dispMessage();
535
			return $oMessageObject;
536
		}
537
538
		// if(type == view, and case for using mobilephone)
539
		if($type == "view" && Mobile::isFromMobilePhone() && Context::isInstalled())
540
		{
541
			$orig_type = "view";
542
			$type = "mobile";
543
			// create a module instance
544
			$oModule = $this->getModuleInstance($this->module, $type, $kind);
545 View Code Duplication
			if(!is_object($oModule) || !method_exists($oModule, $this->act))
546
			{
547
				$type = $orig_type;
548
				Mobile::setMobile(FALSE);
549
				$oModule = $this->getModuleInstance($this->module, $type, $kind);
550
			}
551
		}
552
		else
553
		{
554
			// create a module instance
555
			$oModule = $this->getModuleInstance($this->module, $type, $kind);
556
		}
557
558 View Code Duplication
		if(!is_object($oModule))
559
		{
560
			$this->_setInputErrorToContext();
561
			$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
562
			$oMessageObject->setError(-1);
563
			$oMessageObject->setMessage($this->error);
564
			$oMessageObject->dispMessage();
565
			if($this->httpStatusCode)
566
			{
567
				$oMessageObject->setHttpStatusCode($this->httpStatusCode);
568
			}
569
			return $oMessageObject;
570
		}
571
572
		// If there is no such action in the module object
573
		if(!isset($xml_info->action->{$this->act}) || !method_exists($oModule, $this->act))
574
		{
575
576 View Code Duplication
			if(!Context::isInstalled())
577
			{
578
				$this->_setInputErrorToContext();
579
				$this->error = 'msg_invalid_request';
580
				$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
581
				$oMessageObject->setError(-1);
582
				$oMessageObject->setMessage($this->error);
583
				$oMessageObject->dispMessage();
584
				if($this->httpStatusCode)
585
				{
586
					$oMessageObject->setHttpStatusCode($this->httpStatusCode);
587
				}
588
				return $oMessageObject;
589
			}
590
591
			$forward = NULL;
592
			// 1. Look for the module with action name
593
			if(preg_match('/^([a-z]+)([A-Z])([a-z0-9\_]+)(.*)$/', $this->act, $matches))
594
			{
595
				$module = strtolower($matches[2] . $matches[3]);
596
				$xml_info = $oModuleModel->getModuleActionXml($module);
597
598
				if($xml_info->action->{$this->act} && ((stripos($this->act, 'admin') !== FALSE) || $xml_info->action->{$this->act}->standalone != 'false'))
599
				{
600
					$forward = new stdClass();
601
					$forward->module = $module;
602
					$forward->type = $xml_info->action->{$this->act}->type;
603
					$forward->ruleset = $xml_info->action->{$this->act}->ruleset;
604
					$forward->meta_noindex = $xml_info->action->{$this->act}->meta_noindex;
605
					$forward->act = $this->act;
606
				}
607 View Code Duplication
				else
608
				{
609
					$this->error = 'msg_invalid_request';
610
					$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
611
					$oMessageObject->setError(-1);
612
					$oMessageObject->setMessage($this->error);
613
					$oMessageObject->dispMessage();
614
615
					return $oMessageObject;
616
				}
617
			}
618
619
			if(!$forward)
620
			{
621
				$forward = $oModuleModel->getActionForward($this->act);
622
			}
623
624
			if($forward->module && $forward->type && $forward->act && $forward->act == $this->act)
625
			{
626
				$kind = stripos($forward->act, 'admin') !== FALSE ? 'admin' : '';
627
				$type = $forward->type;
628
				$ruleset = $forward->ruleset;
629
				$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...
630
				$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...
631
632
				if($forward->meta_noindex === 'true') {
633
					Context::addMetaTag('robots', 'noindex');
634
				}
635
636
				$xml_info = $oModuleModel->getModuleActionXml($forward->module);
637
638
				// check CSRF for non-GET actions
639
				$use_check_csrf = isset($xml_info->action->{$this->act}) && $xml_info->action->{$this->act}->check_csrf !== 'false';
640 View Code Duplication
				if($use_check_csrf && $_SERVER['REQUEST_METHOD'] !== 'GET' && Context::isInstalled() && !checkCSRF())
641
				{
642
					$this->error = 'msg_invalid_request';
643
					$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
644
					$oMessageObject->setError(-1);
645
					$oMessageObject->setMessage($this->error);
646
					$oMessageObject->dispMessage();
647
					return $oMessageObject;
648
				}
649
650
				// SECISSUE also check foward act method
651
				// check REQUEST_METHOD in controller
652 View Code Duplication
				if($type == 'controller')
653
				{
654
					$allowedMethod = $xml_info->action->{$forward->act}->method;
655
656
					if(!$allowedMethod)
657
					{
658
						$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...
659
					}
660
					else
661
					{
662
						$allowedMethodList = explode('|', strtoupper($allowedMethod));
663
					}
664
665
					if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowedMethodList))
666
					{
667
						$this->error = "msg_invalid_request";
668
						$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
669
						$oMessageObject->setError(-1);
670
						$oMessageObject->setMessage($this->error);
671
						$oMessageObject->dispMessage();
672
						return $oMessageObject;
673
					}
674
				}
675
676
				if($type == "view" && Mobile::isFromMobilePhone())
677
				{
678
					$orig_type = "view";
679
					$type = "mobile";
680
					// create a module instance
681
					$oModule = $this->getModuleInstance($forward->module, $type, $kind);
682 View Code Duplication
					if(!is_object($oModule) || !method_exists($oModule, $this->act))
683
					{
684
						$type = $orig_type;
685
						Mobile::setMobile(FALSE);
686
						$oModule = $this->getModuleInstance($forward->module, $type, $kind);
687
					}
688
				}
689
				else
690
				{
691
					$oModule = $this->getModuleInstance($forward->module, $type, $kind);
692
				}
693
694 View Code Duplication
				if(!is_object($oModule))
695
				{
696
					$this->_setInputErrorToContext();
697
					$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
698
					$oMessageObject->setError(-1);
699
					$oMessageObject->setMessage('msg_module_is_not_exists');
700
					$oMessageObject->dispMessage();
701
					if($this->httpStatusCode)
702
					{
703
						$oMessageObject->setHttpStatusCode($this->httpStatusCode);
704
					}
705
					return $oMessageObject;
706
				}
707
708
				if($this->module == "admin" && $type == "view")
709
				{
710
					if($logged_info->is_admin == 'Y')
711
					{
712
						if($this->act != 'dispLayoutAdminLayoutModify')
713
						{
714
							$oAdminView = getAdminView('admin');
715
							$oAdminView->makeGnbUrl($forward->module);
716
							$oModule->setLayoutPath("./modules/admin/tpl");
717
							$oModule->setLayoutFile("layout.html");
718
						}
719
					}
720 View Code Duplication
					else
721
					{
722
						$this->_setInputErrorToContext();
723
724
						$this->error = 'msg_is_not_administrator';
725
						$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
726
						$oMessageObject->setError(-1);
727
						$oMessageObject->setMessage($this->error);
728
						$oMessageObject->dispMessage();
729
						return $oMessageObject;
730
					}
731
				}
732
				if($kind == 'admin')
733
				{
734
					$grant = $oModuleModel->getGrant($this->module_info, $logged_info);
735
					if(!$grant->manager)
736
					{
737
						$this->_setInputErrorToContext();
738
						$this->error = 'msg_is_not_manager';
739
						$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
740
						$oMessageObject->setError(-1);
741
						$oMessageObject->setMessage($this->error);
742
						$oMessageObject->dispMessage();
743
						return $oMessageObject;
744
					}
745
					else
746
					{
747
						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...
748
						{
749
							$this->_setInputErrorToContext();
750
							$this->error = 'msg_is_not_administrator';
751
							$oMessageObject = ModuleHandler::getModuleInstance('message', $display_mode);
752
							$oMessageObject->setError(-1);
753
							$oMessageObject->setMessage($this->error);
754
							$oMessageObject->dispMessage();
755
							return $oMessageObject;
756
						}
757
					}
758
				}
759
			}
760
			else if($xml_info->default_index_act && method_exists($oModule, $xml_info->default_index_act))
761
			{
762
				$this->act = $xml_info->default_index_act;
763
			}
764
			else
765
			{
766
				$this->error = 'msg_invalid_request';
767
				$oModule->setError(-1);
768
				$oModule->setMessage($this->error);
769
				return $oModule;
770
			}
771
		}
772
773
		// ruleset check...
774
		if(!empty($ruleset))
775
		{
776
			$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...
777
			$rulesetFile = $oModuleModel->getValidatorFilePath($rulesetModule, $ruleset, $this->mid);
778
			if(!empty($rulesetFile))
779
			{
780
				if($_SESSION['XE_VALIDATOR_ERROR_LANG'])
781
				{
782
					$errorLang = $_SESSION['XE_VALIDATOR_ERROR_LANG'];
783
					foreach($errorLang as $key => $val)
784
					{
785
						Context::setLang($key, $val);
786
					}
787
					unset($_SESSION['XE_VALIDATOR_ERROR_LANG']);
788
				}
789
790
				$Validator = new Validator($rulesetFile);
791
				$result = $Validator->validate();
792
				if(!$result)
793
				{
794
					$lastError = $Validator->getLastError();
795
					$returnUrl = Context::get('error_return_url');
796
					$errorMsg = $lastError['msg'] ? $lastError['msg'] : 'validation error';
797
798
					//for xml response
799
					$oModule->setError(-1);
800
					$oModule->setMessage($errorMsg);
801
					//for html redirect
802
					$this->error = $errorMsg;
803
					$_SESSION['XE_VALIDATOR_ERROR'] = -1;
804
					$_SESSION['XE_VALIDATOR_MESSAGE'] = $this->error;
805
					$_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = 'error';
806
					$_SESSION['XE_VALIDATOR_RETURN_URL'] = $returnUrl;
807
					$_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id');
808
					$this->_setInputValueToSession();
809
					return $oModule;
810
				}
811
			}
812
		}
813
814
		$oModule->setAct($this->act);
815
816
		$this->module_info->module_type = $type;
817
		$oModule->setModuleInfo($this->module_info, $xml_info);
818
819
		$skipAct = array(
820
				'dispEditorConfigPreview' => 1,
821
				'dispLayoutPreviewWithModule' => 1
822
		);
823
		$db_use_mobile = Mobile::isMobileEnabled();
824
		if($type == "view" && $this->module_info->use_mobile == "Y" && Mobile::isMobileCheckByAgent() && !isset($skipAct[Context::get('act')]) && $db_use_mobile === true)
825
		{
826
			global $lang;
827
			$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>';
828
			$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>';
829
			Context::addHtmlHeader($header);
830
			Context::addHtmlFooter($footer);
831
		}
832
833
		if(($type == 'view' || $type == 'mobile') && $kind != 'admin')
834
		{
835
			$module_config = $oModuleModel->getModuleConfig('module');
836
			if($module_config->htmlFooter)
837
			{
838
				Context::addHtmlFooter($module_config->htmlFooter);
839
			}
840
			if($module_config->siteTitle)
841
			{
842
				$siteTitle = Context::getBrowserTitle();
843
				if(!$siteTitle)
844
				{
845
					Context::setBrowserTitle($module_config->siteTitle);
846
				}
847
			}
848
		}
849
850
		if ($kind === 'admin') {
851
			Context::addMetaTag('robots', 'noindex');
852
		}
853
854
		// if failed message exists in session, set context
855
		$this->_setInputErrorToContext();
856
857
		$procResult = $oModule->proc();
858
859
		$methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1);
860
		if(!$oModule->stop_proc && !isset($methodList[Context::getRequestMethod()]))
861
		{
862
			$error = $oModule->getError();
863
			$message = $oModule->getMessage();
864
			$messageType = $oModule->getMessageType();
865
			$redirectUrl = $oModule->getRedirectUrl();
866
			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...
867
868
			if(!$procResult)
869
			{
870
				$this->error = $message;
871
				if(!$redirectUrl && Context::get('error_return_url'))
872
				{
873
					$redirectUrl = Context::get('error_return_url');
874
				}
875
				$this->_setInputValueToSession();
876
			}
877
			else
878
			{
879
880
			}
881
882
			$_SESSION['XE_VALIDATOR_ERROR'] = $error;
883
			$_SESSION['XE_VALIDATOR_ID'] = Context::get('xe_validator_id');
884
			if($message != 'success')
885
			{
886
				$_SESSION['XE_VALIDATOR_MESSAGE'] = $message;
887
			}
888
			$_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = $messageType;
889
890
			if(Context::get('xeVirtualRequestMethod') != 'xml')
891
			{
892
				$_SESSION['XE_VALIDATOR_RETURN_URL'] = $redirectUrl;
893
			}
894
		}
895
896
		unset($logged_info);
897
		return $oModule;
898
	}
899
900
	/**
901
	 * set error message to Session.
902
	 * @return void
903
	 * */
904
	function _setInputErrorToContext()
905
	{
906
		if($_SESSION['XE_VALIDATOR_ERROR'] && !Context::get('XE_VALIDATOR_ERROR'))
907
		{
908
			Context::set('XE_VALIDATOR_ERROR', $_SESSION['XE_VALIDATOR_ERROR']);
909
		}
910
		if($_SESSION['XE_VALIDATOR_MESSAGE'] && !Context::get('XE_VALIDATOR_MESSAGE'))
911
		{
912
			Context::set('XE_VALIDATOR_MESSAGE', $_SESSION['XE_VALIDATOR_MESSAGE']);
913
		}
914
		if($_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] && !Context::get('XE_VALIDATOR_MESSAGE_TYPE'))
915
		{
916
			Context::set('XE_VALIDATOR_MESSAGE_TYPE', $_SESSION['XE_VALIDATOR_MESSAGE_TYPE']);
917
		}
918
		if($_SESSION['XE_VALIDATOR_RETURN_URL'] && !Context::get('XE_VALIDATOR_RETURN_URL'))
919
		{
920
			Context::set('XE_VALIDATOR_RETURN_URL', $_SESSION['XE_VALIDATOR_RETURN_URL']);
921
		}
922
		if($_SESSION['XE_VALIDATOR_ID'] && !Context::get('XE_VALIDATOR_ID'))
923
		{
924
			Context::set('XE_VALIDATOR_ID', $_SESSION['XE_VALIDATOR_ID']);
925
		}
926
		if(count($_SESSION['INPUT_ERROR']))
927
		{
928
			Context::set('INPUT_ERROR', $_SESSION['INPUT_ERROR']);
929
		}
930
931
		$this->_clearErrorSession();
932
	}
933
934
	/**
935
	 * clear error message to Session.
936
	 * @return void
937
	 * */
938
	function _clearErrorSession()
939
	{
940
		$_SESSION['XE_VALIDATOR_ERROR'] = '';
941
		$_SESSION['XE_VALIDATOR_MESSAGE'] = '';
942
		$_SESSION['XE_VALIDATOR_MESSAGE_TYPE'] = '';
943
		$_SESSION['XE_VALIDATOR_RETURN_URL'] = '';
944
		$_SESSION['XE_VALIDATOR_ID'] = '';
945
		$_SESSION['INPUT_ERROR'] = '';
946
	}
947
948
	/**
949
	 * occured error when, set input values to session.
950
	 * @return void
951
	 * */
952
	function _setInputValueToSession()
953
	{
954
		$requestVars = Context::getRequestVars();
955
		unset($requestVars->act, $requestVars->mid, $requestVars->vid, $requestVars->success_return_url, $requestVars->error_return_url);
956
		foreach($requestVars AS $key => $value)
0 ignored issues
show
Bug introduced by
The expression $requestVars of type object<BaseObject> is not traversable.
Loading history...
957
		{
958
			$_SESSION['INPUT_ERROR'][$key] = $value;
959
		}
960
	}
961
962
	/**
963
	 * display contents from executed module
964
	 * @param ModuleObject $oModule module instance
965
	 * @return void
966
	 * */
967
	function displayContent($oModule = NULL)
968
	{
969
		// If the module is not set or not an object, set error
970
		if(!$oModule || !is_object($oModule))
971
		{
972
			$this->error = 'msg_module_is_not_exists';
973
			$this->httpStatusCode = '404';
974
		}
975
976
		// If connection to DB has a problem even though it's not install module, set error
977
		if($this->module != 'install' && isset($GLOBALS['__DB__']) && $GLOBALS['__DB__'][Context::getDBType()]->isConnected() == FALSE)
978
		{
979
			$this->error = 'msg_dbconnect_failed';
980
		}
981
982
		// Call trigger after moduleHandler proc
983
		$output = ModuleHandler::triggerCall('moduleHandler.proc', 'after', $oModule);
0 ignored issues
show
Bug introduced by
It seems like $oModule defined by parameter $oModule on line 967 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...
984
		if(!$output->toBool())
985
		{
986
			$this->error = $output->getMessage();
987
		}
988
989
		// Use message view object, if HTML call
990
		$methodList = array('XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1);
991
		if(!isset($methodList[Context::getRequestMethod()]))
992
		{
993
994
			if($_SESSION['XE_VALIDATOR_RETURN_URL'])
995
			{
996
				$display_handler = new DisplayHandler();
997
				$display_handler->_debugOutput();
998
999
				header('location:' . $_SESSION['XE_VALIDATOR_RETURN_URL']);
1000
				return;
1001
			}
1002
1003
			// If error occurred, handle it
1004
			if($this->error)
1005
			{
1006
				// display content with message module instance
1007
				$type = Mobile::isFromMobilePhone() ? 'mobile' : 'view';
1008
				$oMessageObject = ModuleHandler::getModuleInstance('message', $type);
1009
				$oMessageObject->setError(-1);
1010
				$oMessageObject->setMessage($this->error);
1011
				$oMessageObject->dispMessage();
1012
1013
				if($oMessageObject->getHttpStatusCode() && $oMessageObject->getHttpStatusCode() != '200')
1014
				{
1015
					$this->_setHttpStatusMessage($oMessageObject->getHttpStatusCode());
1016
					$oMessageObject->setTemplateFile('http_status_code');
1017
				}
1018
1019
				// If module was called normally, change the templates of the module into ones of the message view module
1020
				if($oModule)
1021
				{
1022
					$oModule->setTemplatePath($oMessageObject->getTemplatePath());
1023
					$oModule->setTemplateFile($oMessageObject->getTemplateFile());
1024
					// Otherwise, set message instance as the target module
1025
				}
1026
				else
1027
				{
1028
					$oModule = $oMessageObject;
1029
				}
1030
1031
				$this->_clearErrorSession();
1032
			}
1033
1034
			// Check if layout_srl exists for the module
1035
			if(Mobile::isFromMobilePhone())
1036
			{
1037
				$layout_srl = $oModule->module_info->mlayout_srl;
1038
			}
1039
			else
1040
			{
1041
				$layout_srl = $oModule->module_info->layout_srl;
1042
			}
1043
1044
			// if layout_srl is rollback by module, set default layout
1045
			if($layout_srl == -1)
1046
			{
1047
				$viewType = (Mobile::isFromMobilePhone()) ? 'M' : 'P';
1048
				$oLayoutAdminModel = getAdminModel('layout');
1049
				$layout_srl = $oLayoutAdminModel->getSiteDefaultLayout($viewType, $oModule->module_info->site_srl);
1050
			}
1051
1052
			if($layout_srl && !$oModule->getLayoutFile())
1053
			{
1054
1055
				// If layout_srl exists, get information of the layout, and set the location of layout_path/ layout_file
1056
				$oLayoutModel = getModel('layout');
1057
				$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...
1058
				if($layout_info)
1059
				{
1060
1061
					// Input extra_vars into $layout_info
1062 View Code Duplication
					if($layout_info->extra_var_count)
1063
					{
1064
1065
						foreach($layout_info->extra_var as $var_id => $val)
1066
						{
1067
							if($val->type == 'image')
1068
							{
1069
								if(strncmp('./files/attach/images/', $val->value, 22) === 0)
1070
								{
1071
									$val->value = Context::getRequestUri() . substr($val->value, 2);
1072
								}
1073
							}
1074
							$layout_info->{$var_id} = $val->value;
1075
						}
1076
					}
1077
					// Set menus into context
1078
					if($layout_info->menu_count)
1079
					{
1080
						foreach($layout_info->menu as $menu_id => $menu)
1081
						{
1082
							// set default menu set(included home menu)
1083 View Code Duplication
							if(!$menu->menu_srl || $menu->menu_srl == -1)
1084
							{
1085
								$oMenuAdminController = getAdminController('menu');
1086
								$homeMenuCacheFile = $oMenuAdminController->getHomeMenuCacheFile();
1087
1088
								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...
1089
								{
1090
									include($homeMenuCacheFile);
1091
								}
1092
1093
								if(!$menu->menu_srl)
1094
								{
1095
									$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...
1096
									$menu->php_file = str_replace('.php', $homeMenuSrl . '.php', $menu->php_file);
1097
									$layout_info->menu->{$menu_id}->menu_srl = $homeMenuSrl;
1098
								}
1099
								else
1100
								{
1101
									$menu->xml_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->xml_file);
1102
									$menu->php_file = str_replace($menu->menu_srl, $homeMenuSrl, $menu->php_file);
1103
								}
1104
							}
1105
1106
							$php_file = FileHandler::exists($menu->php_file);
1107
							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...
1108
							{
1109
								include($php_file);
1110
							}
1111
							Context::set($menu_id, $menu);
1112
						}
1113
					}
1114
1115
					// Set layout information into context
1116
					Context::set('layout_info', $layout_info);
1117
1118
					$oModule->setLayoutPath($layout_info->path);
1119
					$oModule->setLayoutFile('layout');
1120
1121
					// If layout was modified, use the modified version
1122
					$edited_layout = $oLayoutModel->getUserLayoutHtml($layout_info->layout_srl);
1123
					if(file_exists($edited_layout))
1124
					{
1125
						$oModule->setEditedLayoutFile($edited_layout);
1126
					}
1127
				}
1128
			}
1129
			$isLayoutDrop = Context::get('isLayoutDrop');
1130
			if($isLayoutDrop)
1131
			{
1132
				$kind = stripos($this->act, 'admin') !== FALSE ? 'admin' : '';
1133
				if($kind == 'admin')
1134
				{
1135
					$oModule->setLayoutFile('popup_layout');
1136
				}
1137
				else
1138
				{
1139
					$oModule->setLayoutPath('common/tpl');
1140
					$oModule->setLayoutFile('default_layout');
1141
				}
1142
			}
1143
		}
1144
1145
		// Display contents
1146
		$oDisplayHandler = new DisplayHandler();
1147
		$oDisplayHandler->printContent($oModule);
1148
	}
1149
1150
	/**
1151
	 * returns module's path
1152
	 * @param string $module module name
1153
	 * @return string path of the module
1154
	 * */
1155
	function getModulePath($module)
1156
	{
1157
		return sprintf('./modules/%s/', $module);
1158
	}
1159
1160
	/**
1161
	 * It creates a module instance
1162
	 * @param string $module module name
1163
	 * @param string $type instance type, (e.g., view, controller, model)
1164
	 * @param string $kind admin or svc
1165
	 * @return ModuleObject module instance (if failed it returns null)
1166
	 * @remarks if there exists a module instance created before, returns it.
1167
	 * */
1168
	function &getModuleInstance($module, $type = 'view', $kind = '')
1169
	{
1170
1171
		if(__DEBUG__ == 3)
1172
		{
1173
			$start_time = getMicroTime();
1174
		}
1175
1176
		$parent_module = $module;
1177
		$kind = strtolower($kind);
1178
		$type = strtolower($type);
1179
1180
		$kinds = array('svc' => 1, 'admin' => 1);
1181
		if(!isset($kinds[$kind]))
1182
		{
1183
			$kind = 'svc';
1184
		}
1185
1186
		$key = $module . '.' . ($kind != 'admin' ? '' : 'admin') . '.' . $type;
1187
1188
		if(is_array($GLOBALS['__MODULE_EXTEND__']) && array_key_exists($key, $GLOBALS['__MODULE_EXTEND__']))
1189
		{
1190
			$module = $extend_module = $GLOBALS['__MODULE_EXTEND__'][$key];
1191
		}
1192
1193
		// if there is no instance of the module in global variable, create a new one
1194
		if(!isset($GLOBALS['_loaded_module'][$module][$type][$kind]))
1195
		{
1196
			ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name);
1197
1198
			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...
1199
			{
1200
				$module = $parent_module;
1201
				ModuleHandler::_getModuleFilePath($module, $type, $kind, $class_path, $high_class_file, $class_file, $instance_name);
1202
			}
1203
1204
			// Check if the base class and instance class exist
1205
			if(!class_exists($module, true))
1206
			{
1207
				return NULL;
1208
			}
1209
			if(!class_exists($instance_name, true))
1210
			{
1211
				return NULL;
1212
			}
1213
1214
			// Create an instance
1215
			$oModule = new $instance_name();
1216
			if(!is_object($oModule))
1217
			{
1218
				return NULL;
1219
			}
1220
1221
			// Load language files for the class
1222
			Context::loadLang($class_path . 'lang');
1223
			if($extend_module)
1224
			{
1225
				Context::loadLang(ModuleHandler::getModulePath($parent_module) . 'lang');
1226
			}
1227
1228
			// Set variables to the instance
1229
			$oModule->setModule($module);
1230
			$oModule->setModulePath($class_path);
1231
1232
			// If the module has a constructor, run it.
1233
			if(!isset($GLOBALS['_called_constructor'][$instance_name]))
1234
			{
1235
				$GLOBALS['_called_constructor'][$instance_name] = TRUE;
1236
				if(@method_exists($oModule, $instance_name))
1237
				{
1238
					$oModule->{$instance_name}();
1239
				}
1240
			}
1241
1242
			// Store the created instance into GLOBALS variable
1243
			$GLOBALS['_loaded_module'][$module][$type][$kind] = $oModule;
1244
		}
1245
1246
		if(__DEBUG__ == 3)
1247
		{
1248
			$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...
1249
		}
1250
1251
		// return the instance
1252
		return $GLOBALS['_loaded_module'][$module][$type][$kind];
1253
	}
1254
1255
	function _getModuleFilePath($module, $type, $kind, &$classPath, &$highClassFile, &$classFile, &$instanceName)
1256
	{
1257
		$classPath = ModuleHandler::getModulePath($module);
1258
1259
		$highClassFile = sprintf('%s%s%s.class.php', _XE_PATH_, $classPath, $module);
1260
		$highClassFile = FileHandler::getRealPath($highClassFile);
1261
1262
		$types = array('view','controller','model','api','wap','mobile','class');
1263
		if(!in_array($type, $types))
1264
		{
1265
			$type = $types[0];
1266
		}
1267
		if($type == 'class')
1268
		{
1269
			$instanceName = '%s';
1270
			$classFile = '%s%s.%s.php';
1271
		}
1272
		elseif($kind == 'admin' && array_search($type, $types) < 3)
1273
		{
1274
			$instanceName = '%sAdmin%s';
1275
			$classFile = '%s%s.admin.%s.php';
1276
		}
1277
		else
1278
		{
1279
			$instanceName = '%s%s';
1280
			$classFile = '%s%s.%s.php';
1281
		}
1282
1283
		$instanceName = sprintf($instanceName, $module, ucfirst($type));
1284
		$classFile = FileHandler::getRealPath(sprintf($classFile, $classPath, $module, $type));
1285
	}
1286
1287
	/**
1288
	 * call a trigger
1289
	 * @param string $trigger_name trigger's name to call
1290
	 * @param string $called_position called position
1291
	 * @param object $obj an object as a parameter to trigger
1292
	 * @return BaseObject
1293
	 * */
1294
	function triggerCall($trigger_name, $called_position, &$obj)
1295
	{
1296
		// skip if not installed
1297
		if(!Context::isInstalled())
1298
		{
1299
			return new BaseObject();
1300
		}
1301
1302
		$oModuleModel = getModel('module');
1303
		$triggers = $oModuleModel->getTriggers($trigger_name, $called_position);
1304
		if(!$triggers || count($triggers) < 1)
1305
		{
1306
			return new BaseObject();
1307
		}
1308
1309
		//store before trigger call time
1310
		$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...
1311
		if(__LOG_SLOW_TRIGGER__> 0)
1312
		{
1313
			$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...
1314
		}
1315
1316
		foreach($triggers as $item)
1317
		{
1318
			$module = $item->module;
1319
			$type = $item->type;
1320
			$called_method = $item->called_method;
1321
1322
			// todo why don't we call a normal class object ?
1323
			$oModule = getModule($module, $type);
1324
			if(!$oModule || !method_exists($oModule, $called_method))
1325
			{
1326
				continue;
1327
			}
1328
1329
			$before_each_trigger_time = microtime(true);
1330
1331
			$output = $oModule->{$called_method}($obj);
1332
1333
			$after_each_trigger_time = microtime(true);
1334
			$elapsed_time_trigger = $after_each_trigger_time - $before_each_trigger_time;
1335
1336
			$slowlog = new stdClass;
1337
			$slowlog->caller = $trigger_name . '.' . $called_position;
1338
			$slowlog->called = $module . '.' . $called_method;
1339
			$slowlog->called_extension = $module;
1340
			if($trigger_name != 'XE.writeSlowlog') writeSlowlog('trigger', $elapsed_time_trigger, $slowlog);
1341
1342
			if(is_object($output) && method_exists($output, 'toBool') && !$output->toBool())
1343
			{
1344
				return $output;
1345
			}
1346
			unset($oModule);
1347
		}
1348
1349
		return new BaseObject();
1350
	}
1351
1352
	/**
1353
	 * get http status message by http status code
1354
	 * @param string $code
1355
	 * @return string
1356
	 * */
1357
	function _setHttpStatusMessage($code)
1358
	{
1359
		$statusMessageList = array(
1360
			// 1×× Informational
1361
			'100' => 'Continue',
1362
			'101' => 'Switching Protocols',
1363
			'102' => 'Processing',
1364
			// 2×× Success
1365
			'200' => 'OK',
1366
			'201' => 'Created',
1367
			'202' => 'Accepted',
1368
			'203' => 'Non-authoritative Information',
1369
			'204' => 'No Content',
1370
			'205' => 'Reset Content',
1371
			'206' => 'Partial Content',
1372
			'207' => 'Multi-Status',
1373
			'208' => 'Already Reported',
1374
			'226' => 'IM Used',
1375
			// 3×× Redirection
1376
			'300' => 'Multiple Choices',
1377
			'301' => 'Moved Permanently',
1378
			'302' => 'Found',
1379
			'303' => 'See Other',
1380
			'304' => 'Not Modified',
1381
			'305' => 'Use Proxy',
1382
			'307' => 'Temporary Redirect',
1383
			'308' => 'Permanent Redirect',
1384
			// 4×× Client Error
1385
			'400' => 'Bad Request',
1386
			'401' => 'Unauthorized',
1387
			'402' => 'Payment Required',
1388
			'403' => 'Forbidden',
1389
			'404' => 'Not Found',
1390
			'405' => 'Method Not Allowed',
1391
			'406' => 'Not Acceptable',
1392
			'407' => 'Proxy Authentication Required',
1393
			'408' => 'Request Timeout',
1394
			'409' => 'Conflict',
1395
			'410' => 'Gone',
1396
			'411' => 'Length Required',
1397
			'412' => 'Precondition Failed',
1398
			'413' => 'Payload Too Large',
1399
			'414' => 'Request-URI Too Long',
1400
			'415' => 'Unsupported Media Type',
1401
			'416' => 'Requested Range Not Satisfiable',
1402
			'417' => 'Expectation Failed',
1403
			'418' => 'I\'m a teapot',
1404
			'421' => 'Misdirected Request',
1405
			'422' => 'Unprocessable Entity',
1406
			'423' => 'Locked',
1407
			'424' => 'Failed Dependency',
1408
			'426' => 'Upgrade Required',
1409
			'428' => 'Precondition Required',
1410
			'429' => 'Too Many Requests',
1411
			'431' => 'Request Header Fields Too Large',
1412
			'451' => 'Unavailable For Legal Reasons',
1413
			// 5×× Server Error
1414
			'500' => 'Internal Server Error',
1415
			'501' => 'Not Implemented',
1416
			'502' => 'Bad Gateway',
1417
			'503' => 'Service Unavailable',
1418
			'504' => 'Gateway Timeout',
1419
			'505' => 'HTTP Version Not Supported',
1420
			'506' => 'Variant Also Negotiates',
1421
			'507' => 'Insufficient Storage',
1422
			'508' => 'Loop Detected',
1423
			'510' => 'Not Extended',
1424
			'511' => 'Network Authentication Required',
1425
		);
1426
		$statusMessage = $statusMessageList[$code];
1427
		if(!$statusMessage)
1428
		{
1429
			$statusMessage = 'HTTP ' . $code;
1430
		}
1431
1432
		Context::set('http_status_code', $code);
1433
		Context::set('http_status_message', $statusMessage);
1434
	}
1435
1436
}
1437
/* End of file ModuleHandler.class.php */
1438
/* Location: ./classes/module/ModuleHandler.class.php */
1439