GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — develop (#1947)
by
unknown
13:22
created

ModuleHandler::shutdownHandler()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 28
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

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