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
16:09 queued 04:21
created

ModuleHandler::displayContent()   F

Complexity

Conditions 35
Paths > 20000

Size

Total Lines 182
Code Lines 83

Duplication

Lines 37
Ratio 20.33 %

Importance

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