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
12:04 queued 12s
created

ModuleHandler   D

Complexity

Total Complexity 282

Size/Duplication

Total Lines 1391
Duplicated Lines 11.21 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 156
loc 1391
rs 4.4102
wmc 282
lcom 1
cbo 8

16 Methods

Rating   Name   Duplication   Size   Complexity  
F ModuleHandler() 0 96 33
D xeErrorLog() 0 37 9
B shutdownHandler() 0 28 5
A dummyHandler() 0 3 1
C getErrorType() 0 22 16
F init() 0 194 42
F procModule() 119 459 89
C _setInputErrorToContext() 0 29 12
A _clearErrorSession() 0 9 1
A _setInputValueToSession() 0 9 2
F displayContent() 37 182 35
A getModulePath() 0 4 1
F getModuleInstance() 0 86 17
B _getModuleFilePath() 0 31 5
C triggerCall() 0 57 12
A _setHttpStatusMessage() 0 53 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ModuleHandler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ModuleHandler, and based on these observations, apply Extract Interface, too.

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