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 (#1929)
by
unknown
11:46
created

layoutModel::getDownloadedLayoutList()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 46
Code Lines 21

Duplication

Lines 30
Ratio 65.22 %

Importance

Changes 0
Metric Value
cc 7
eloc 21
nc 12
nop 2
dl 30
loc 46
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
/**
4
 * @class  layoutModel
5
 * @author NAVER ([email protected])
6
 * @version 0.1
7
 * Model class of the layout module
8
 */
9
class layoutModel extends layout
10
{
11
	/**
12
	 * Check user layout temp
13
	 * @var string
14
	 */
15
	var $useUserLayoutTemp = null;
16
17
	/**
18
	 * Initialization
19
	 * @return void
20
	 */
21
	function init()
22
	{
23
	}
24
25
	/**
26
	 * Get a layout list created in the DB
27
	 * If you found a new list, it means that the layout list is inserted to the DB
28
	 * @deprecated
29
	 * @param int $site_srl
30
	 * @param string $layout_type (P : PC, M : Mobile)
31
	 * @param array $columnList
32
	 * @return array layout lists in site
33
	 */
34
	function getLayoutList($site_srl = 0, $layout_type="P", $columnList = array())
35
	{
36
		if(!$site_srl)
37
		{
38
			$site_module_info = Context::get('site_module_info');
39
			$site_srl = (int)$site_module_info->site_srl;
40
		}
41
		$args = new stdClass();
42
		$args->site_srl = $site_srl;
43
		$args->layout_type = $layout_type;
44
		$output = executeQueryArray('layout.getLayoutList', $args, $columnList);
45
46
		foreach($output->data as $no => &$val)
47
		{
48
			if(!$this->isExistsLayoutFile($val->layout, $layout_type))
49
			{
50
				unset($output->data[$no]);
51
			}
52
		}
53
54
		$oLayoutAdminModel = getAdminModel('layout');
55
		$siteDefaultLayoutSrl = $oLayoutAdminModel->getSiteDefaultLayout($layout_type, $site_srl);
56
		if($siteDefaultLayoutSrl)
57
		{
58
			$siteDefaultLayoutInfo = $this->getlayout($siteDefaultLayoutSrl);
59
			$newLayout = sprintf('%s, %s', $siteDefaultLayoutInfo->title, $siteDefaultLayoutInfo->layout);
60
			$siteDefaultLayoutInfo->layout_srl = -1;
61
			$siteDefaultLayoutInfo->title = Context::getLang('use_site_default_layout');
62
			$siteDefaultLayoutInfo->layout = $newLayout;
63
64
			array_unshift($output->data, $siteDefaultLayoutInfo);
65
		}
66
67
		return $output->data;
68
	}
69
70
	/**
71
	 * Get the list layout instance with thumbnail link. for setting design.
72
	 *
73
	 * @return void
74
	 */
75
	public function getLayoutInstanceListForJSONP()
76
	{
77
		$siteSrl = Context::get('site_srl');
78
		$layoutType = Context::get('layout_type');
79
80
		$layoutList = $this->getLayoutInstanceList($siteSrl, $layoutType);
81
		$thumbs = array();
82
83
		foreach($layoutList as $key => $val)
84
		{
85
			if($thumbs[$val->layouts])
86
			{
87
				$val->thumbnail = $thumbs[$val->layouts];
88
				continue;
89
			}
90
91
			$token = explode('|@|', $val->layout);
92
			if(count($token) == 2)
93
			{
94
				$thumbnailPath = sprintf('./themes/%s/layouts/%s/thumbnail.png' , $token[0], $token[1]);
95
			}
96
			else
97
			{
98
				$thumbnailPath = sprintf('./layouts/%s/thumbnail.png' , $val->layout);
99
			}
100
			if(is_readable($thumbnailPath))
101
			{
102
				$val->thumbnail = $thumbnailPath;
103
			}
104
			else
105
			{
106
				$val->thumbnail = sprintf('./modules/layout/tpl/img/noThumbnail.png');
107
			}
108
			$thumbs[$val->layout] = $val->thumbnail;
109
		}
110
		$this->add('layout_list', $layoutList);
111
	}
112
113
	/**
114
	 * Get layout instance list
115
	 * @param int $siteSrl
116
	 * @param string $layoutType (P : PC, M : Mobile)
117
	 * @param string $layout name of layout
118
	 * @param array $columnList
119
	 * @return array layout lists in site
120
	 */
121
	function getLayoutInstanceList($siteSrl = 0, $layoutType = 'P', $layout = null, $columnList = array())
122
	{
123
		if (!$siteSrl)
124
		{
125
			$siteModuleInfo = Context::get('site_module_info');
126
			$siteSrl = (int)$siteModuleInfo->site_srl;
127
		}
128
		$args = new stdClass();
129
		$args->site_srl = $siteSrl;
130
		$args->layout_type = $layoutType;
131
		$args->layout = $layout;
132
		$output = executeQueryArray('layout.getLayoutList', $args, $columnList);
133
134
		// Create instance name list
135
		$instanceList = array();
136 View Code Duplication
		if(is_array($output->data))
137
		{
138
			foreach($output->data as $no => $iInfo)
139
			{
140
				if($this->isExistsLayoutFile($iInfo->layout, $layoutType))
141
				{
142
					$instanceList[] = $iInfo->layout;
143
				}
144
				else
145
				{
146
					unset($output->data[$no]);
147
				}
148
			}
149
		}
150
151
		// Create downloaded name list
152
		$downloadedList = array();
153
		$titleList = array();
154
		$_downloadedList = $this->getDownloadedLayoutList($layoutType);
155
		if(is_array($_downloadedList))
156
		{
157
			foreach($_downloadedList as $dLayoutInfo)
158
			{
159
				$downloadedList[$dLayoutInfo->layout] = $dLayoutInfo->layout;
160
				$titleList[$dLayoutInfo->layout] = $dLayoutInfo->title;
161
			}
162
		}
163
164
		if($layout)
0 ignored issues
show
Bug Best Practice introduced by
The expression $layout of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null 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...
165
		{
166
			if(count($instanceList) < 1 && $downloadedList[$layout])
167
			{
168
				$insertArgs = new stdClass();
169
				$insertArgs->site_srl = $siteSrl;
170
				$insertArgs->layout_srl = getNextSequence();
171
				$insertArgs->layout = $layout;
172
				$insertArgs->title = $titleList[$layout];
173
				$insertArgs->layout_type = $layoutType;
174
175
				$oLayoutAdminController = getAdminController('layout');
176
				$oLayoutAdminController->insertLayout($insertArgs);
177
				$isCreateInstance = TRUE;
178
			}
179
		}
180
		else
181
		{
182
			// Get downloaded name list have no instance
183
			$noInstanceList = array_diff($downloadedList, $instanceList);
184
			foreach($noInstanceList as $layoutName)
185
			{
186
				$insertArgs = new stdClass();
187
				$insertArgs->site_srl = $siteSrl;
188
				$insertArgs->layout_srl = getNextSequence();
189
				$insertArgs->layout = $layoutName;
190
				$insertArgs->title = $titleList[$layoutName];
191
				$insertArgs->layout_type = $layoutType;
192
193
				$oLayoutAdminController = getAdminController('layout');
194
				$oLayoutAdminController->insertLayout($insertArgs);
195
				$isCreateInstance = TRUE;
196
			}
197
		}
198
199
		// If create layout instance, reload instance list
200
		if($isCreateInstance)
0 ignored issues
show
Bug introduced by
The variable $isCreateInstance 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...
201
		{
202
			$output = executeQueryArray('layout.getLayoutList', $args, $columnList);
203
204 View Code Duplication
			if(is_array($output->data))
205
			{
206
				foreach($output->data as $no => $iInfo)
207
				{
208
					if(!$this->isExistsLayoutFile($iInfo->layout, $layoutType))
209
					{
210
						unset($output->data[$no]);
211
					}
212
				}
213
			}
214
		}
215
216
		return $output->data;
217
	}
218
219
	/**
220
	 * If exists layout file returns true
221
	 *
222
	 * @param string $layout layout name
223
	 * @param string $layoutType P or M
224
	 * @return bool
225
	 */
226
	function isExistsLayoutFile($layout, $layoutType)
227
	{
228
		//TODO If remove a support themes, remove this codes also.
229
		if($layoutType == 'P')
230
		{
231
			$pathPrefix = _XE_PATH_ . 'layouts/';
232
			$themePathFormat = _XE_PATH_ . 'themes/%s/layouts/%s';
233
		}
234
		else
235
		{
236
			$pathPrefix = _XE_PATH_ . 'm.layouts/';
237
			$themePathFormat = _XE_PATH_ . 'themes/%s/m.layouts/%s';
238
		}
239
240
		if(strpos($layout, '|@|') !== FALSE)
241
		{
242
			list($themeName, $layoutName) = explode('|@|', $layout);
243
			$path = sprintf($themePathFormat, $themeName, $layoutName);
244
		}
245
		else
246
		{
247
			$path = $pathPrefix . $layout;
248
		}
249
250
		return is_readable($path . '/layout.html');
251
	}
252
253
	/**
254
	 * Get one of layout information created in the DB
255
	 * Return DB info + XML info of the generated layout
256
	 * @param int $layout_srl
257
	 * @return object info of layout
258
	 */
259
	function getLayout($layout_srl)
260
	{
261
		// Get information from the DB
262
		$args = new stdClass();
263
		$args->layout_srl = $layout_srl;
264
		$output = executeQuery('layout.getLayout', $args);
265
		if(!$output->data) return;
266
267
		// Return xml file informaton after listing up the layout and extra_vars
268
		$layout_info = $this->getLayoutInfo($layout, $output->data, $output->data->layout_type);
0 ignored issues
show
Bug introduced by
The variable $layout does not exist. Did you mean $layout_srl?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
269
270
		return $layout_info;
271
	}
272
273
	function getLayoutRawData($layout_srl, $columnList = array())
274
	{
275
		$args = new stdClass();
276
		$args->layout_srl = $layout_srl;
277
		$output = executeQuery('layout.getLayout', $args, $columnList);
278
		if(!$output->toBool())
279
		{
280
			return;
281
		}
282
283
		return $output->data;
284
	}
285
286
	/**
287
	 * Get a layout path
288
	 * @param string $layout_name
289
	 * @param string $layout_type (P : PC, M : Mobile)
290
	 * @return string path of layout
291
	 */
292
	function getLayoutPath($layout_name = "", $layout_type = "P")
293
	{
294
		$layout_parse = explode('|@|', $layout_name);
295
		if(count($layout_parse) > 1)
296
		{
297
			$class_path = './themes/'.$layout_parse[0].'/layouts/'.$layout_parse[1].'/';
298
		}
299
		else if($layout_name == 'faceoff')
300
		{
301
			$class_path = './modules/layout/faceoff/';
302
		}
303
		else if($layout_type == "M")
304
		{
305
			$class_path = sprintf("./m.layouts/%s/", $layout_name);
306
		}
307
		else
308
		{
309
			$class_path = sprintf('./layouts/%s/', $layout_name);
310
		}
311
		if(is_dir($class_path)) return $class_path;
312
		return "";
313
	}
314
315
	/**
316
	 * Get a type and information of the layout
317
	 * A type of downloaded layout
318
	 * @param string $layout_type (P : PC, M : Mobile)
319
	 * @param boolean $withAutoinstallInfo
320
	 * @return array info of layout
321
	 */
322
	function getDownloadedLayoutList($layout_type = "P", $withAutoinstallInfo = false)
323
	{
324
		if ($withAutoinstallInfo) $oAutoinstallModel = getModel('autoinstall');
325
326
		// Get a list of downloaded layout and installed layout
327
		$searched_list = $this->_getInstalledLayoutDirectories($layout_type);
328
		$searched_count = count($searched_list);
329
		if(!$searched_count) return;
330
331
		// natcasesort($searched_list);
332
		// Return information for looping searched list of layouts
333
		$list = array();
334 View Code Duplication
		for($i=0;$i<$searched_count;$i++)
335
		{
336
			// Name of the layout
337
			$layout = $searched_list[$i];
338
			// Get information of the layout
339
			$layout_info = $this->getLayoutInfo($layout, null, $layout_type);
340
341
			if(!$layout_info)
342
			{
343
				continue;
344
			}
345
346
			if($withAutoinstallInfo)
347
			{
348
				// get easyinstall remove url
349
				$packageSrl = $oAutoinstallModel->getPackageSrlByPath($layout_info->path);
0 ignored issues
show
Bug introduced by
The variable $oAutoinstallModel 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...
350
				$layout_info->remove_url = $oAutoinstallModel->getRemoveUrlByPackageSrl($packageSrl);
351
352
				// get easyinstall need update
353
				$package = $oAutoinstallModel->getInstalledPackages($packageSrl);
354
				$layout_info->need_update = $package[$packageSrl]->need_update;
355
356
				// get easyinstall update url
357
				if($layout_info->need_update)
358
				{
359
					$layout_info->update_url = $oAutoinstallModel->getUpdateUrlByPackageSrl($packageSrl);
360
				}
361
			}
362
			$list[] = $layout_info;
363
		}
364
365
		usort($list, array($this, 'sortLayoutByTitle'));
366
		return $list;
367
	}
368
369
	/**
370
	 * Sort layout by title
371
	 */
372
	function sortLayoutByTitle($a, $b)
373
	{
374
		if(!$a->title)
375
		{
376
			$a->title = $a->layout;
377
		}
378
379
		if(!$b->title)
380
		{
381
			$b->title = $b->layout;
382
		}
383
384
		$aTitle = strtolower($a->title);
385
		$bTitle = strtolower($b->title);
386
387
		if($aTitle == $bTitle)
388
		{
389
			return 0;
390
		}
391
392
		return ($aTitle < $bTitle) ? -1 : 1;
393
	}
394
395
	/**
396
	 * Get a count of layout
397
	 * @param string $layoutType (P : PC, M : Mobile)
398
	 * @return int
399
	 */
400
	function getInstalledLayoutCount($layoutType = 'P')
401
	{
402
		$searchedList = $this->_getInstalledLayoutDirectories($layoutType);
403
		return  count($searchedList);
404
	}
405
406
	/**
407
	 * Get list of layouts directory
408
	 * @param string $layoutType (P : PC, M : Mobile)
409
	 * @return array
410
	 */
411
	function _getInstalledLayoutDirectories($layoutType = 'P')
412
	{
413
		if($layoutType == 'M')
414
		{
415
			$directory = './m.layouts';
416
			$globalValueKey = 'MOBILE_LAYOUT_DIRECTOIES';
417
		}
418
		else
419
		{
420
			$directory = './layouts';
421
			$globalValueKey = 'PC_LAYOUT_DIRECTORIES';
422
		}
423
424
		if($GLOBALS[$globalValueKey]) return $GLOBALS[$globalValueKey];
425
426
		$searchedList = FileHandler::readDir($directory);
427
		if (!$searchedList) $searchedList = array();
0 ignored issues
show
Bug Best Practice introduced by
The expression $searchedList of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
428
		$GLOBALS[$globalValueKey] = $searchedList;
429
430
		return $searchedList;
431
	}
432
433
	/**
434
	 * Get information by reading conf/info.xml in the module
435
	 * It uses caching to reduce time for xml parsing ..
436
	 * @param string $layout
437
	 * @param object $info
438
	 * @param string $layoutType (P : PC, M : Mobile)
0 ignored issues
show
Documentation introduced by
There is no parameter named $layoutType. Did you maybe mean $layout?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
439
	 * @return object info of layout
440
	 */
441
	function getLayoutInfo($layout, $info = null, $layout_type = "P")
442
	{
443
		if($info)
444
		{
445
			$layout_title = $info->title;
446
			$layout = $info->layout;
447
			$layout_srl = $info->layout_srl;
448
			$site_srl = $info->site_srl;
449
			$vars = unserialize($info->extra_vars);
450
451
			if($info->module_srl)
452
			{
453
				$layout_path = preg_replace('/([a-zA-Z0-9\_\.]+)(\.html)$/','',$info->layout_path);
454
				$xml_file = sprintf('%sskin.xml', $layout_path);
455
			}
456
		}
457
458
		// Get a path of the requested module. Return if not exists.
459
		if(!$layout_path) $layout_path = $this->getLayoutPath($layout, $layout_type);
0 ignored issues
show
Bug introduced by
The variable $layout_path 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...
460
		if(!is_dir($layout_path)) return;
461
462
		// Read the xml file for module skin information
463
		if(!$xml_file) $xml_file = sprintf("%sconf/info.xml", $layout_path);
0 ignored issues
show
Bug introduced by
The variable $xml_file 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...
464
		if(!file_exists($xml_file))
465
		{
466
			$layout_info = new stdClass;
467
			$layout_info->title = $layout;
468
			$layout_info->layout = $layout;
469
			$layout_info->path = $layout_path;
470
			$layout_info->layout_title = $layout_title;
0 ignored issues
show
Bug introduced by
The variable $layout_title 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...
471
			if(!$layout_info->layout_type)
472
			{
473
				$layout_info->layout_type =  $layout_type;
474
			}
475
			return $layout_info;
476
		}
477
478
		// Include the cache file if it is valid and then return $layout_info variable
479
		if(!$layout_srl)
480
		{
481
			$cache_file = $this->getLayoutCache($layout, Context::getLangType(), $layout_type);
482
		}
483
		else
484
		{
485
			$cache_file = $this->getUserLayoutCache($layout_srl, Context::getLangType());
0 ignored issues
show
Bug introduced by
The variable $layout_srl 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...
486
		}
487
488
		if(file_exists($cache_file)&&filemtime($cache_file)>filemtime($xml_file))
489
		{
490
			include($cache_file);
491
492
			if($layout_info->extra_var && $vars)
0 ignored issues
show
Bug introduced by
The variable $layout_info seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
493
			{
494
				foreach($vars as $key => $value)
0 ignored issues
show
Bug introduced by
The variable $vars 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...
495
				{
496
					if(!$layout_info->extra_var->{$key} && !$layout_info->{$key})
0 ignored issues
show
Bug introduced by
The variable $layout_info seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
497
					{
498
						$layout_info->{$key} = $value;
0 ignored issues
show
Bug introduced by
The variable $layout_info seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
499
					}
500
				}
501
			}
502
503
			if(!$layout_info->title)
0 ignored issues
show
Bug introduced by
The variable $layout_info seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
504
			{
505
				$layout_info->title = $layout;
0 ignored issues
show
Bug introduced by
The variable $layout_info seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
506
			}
507
508
			return $layout_info;
0 ignored issues
show
Bug introduced by
The variable $layout_info seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
509
		}
510
		// If no cache file exists, parse the xml and then return the variable.
511
		$oXmlParser = new XmlParser();
512
		$tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file);
513
514
		if($tmp_xml_obj->layout) $xml_obj = $tmp_xml_obj->layout;
515
		elseif($tmp_xml_obj->skin) $xml_obj = $tmp_xml_obj->skin;
516
517
		if(!$xml_obj) return;
0 ignored issues
show
Bug introduced by
The variable $xml_obj 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...
518
519
		$buff = array();
520
		$buff[] = '$layout_info = new stdClass;';
521
		$buff[] = sprintf('$layout_info->site_srl = "%s";', $site_srl);
0 ignored issues
show
Bug introduced by
The variable $site_srl 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...
522
523
		if($xml_obj->version && $xml_obj->attrs->version == '0.2')
524
		{
525
			// Layout title, version and other information
526
			sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
0 ignored issues
show
Bug introduced by
The variable $date_obj 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...
527
			$date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
528
			$buff[] = sprintf('$layout_info->layout = "%s";', $layout);
529
			$buff[] = sprintf('$layout_info->type = "%s";', $xml_obj->attrs->type);
530
			$buff[] = sprintf('$layout_info->path = "%s";', $layout_path);
531
			$buff[] = sprintf('$layout_info->title = "%s";', $xml_obj->title->body);
532
			$buff[] = sprintf('$layout_info->description = "%s";', $xml_obj->description->body);
533
			$buff[] = sprintf('$layout_info->version = "%s";', $xml_obj->version->body);
534
			$buff[] = sprintf('$layout_info->date = "%s";', $date);
535
			$buff[] = sprintf('$layout_info->homepage = "%s";', $xml_obj->link->body);
536
			$buff[] = sprintf('$layout_info->layout_srl = $layout_srl;');
537
			$buff[] = sprintf('$layout_info->layout_title = $layout_title;');
538
			$buff[] = sprintf('$layout_info->license = "%s";', $xml_obj->license->body);
539
			$buff[] = sprintf('$layout_info->license_link = "%s";', $xml_obj->license->attrs->link);
540
			$buff[] = sprintf('$layout_info->layout_type = "%s";', $layout_type);
541
542
			// Author information
543 View Code Duplication
			if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$author_list was never initialized. Although not strictly required by PHP, it is generally a good practice to add $author_list = 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...
544
			else $author_list = $xml_obj->author;
545
546
			$buff[] = '$layout_info->author = array();';
547
			for($i=0, $c=count($author_list); $i<$c; $i++)
548
			{
549
				$buff[] = sprintf('$layout_info->author[%d] = new stdClass;', $i);
550
				$buff[] = sprintf('$layout_info->author[%d]->name = "%s";', $i, $author_list[$i]->name->body);
551
				$buff[] = sprintf('$layout_info->author[%d]->email_address = "%s";', $i, $author_list[$i]->attrs->email_address);
552
				$buff[] = sprintf('$layout_info->author[%d]->homepage = "%s";', $i, $author_list[$i]->attrs->link);
553
			}
554
555
			// Extra vars (user defined variables to use in a template)
556
			$extra_var_groups = $xml_obj->extra_vars->group;
557
			if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
558
			if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
559
560
			$buff[] = '$layout_info->extra_var = new stdClass;';
561
			$extra_var_count = 0;
562
			foreach($extra_var_groups as $group)
563
			{
564
				$extra_vars = $group->var;
565
				if($extra_vars)
566
				{
567
					if(!is_array($extra_vars)) $extra_vars = array($extra_vars);
568
569
					$count = count($extra_vars);
570
					$extra_var_count += $count;
571
					
572
					for($i=0;$i<$count;$i++)
573
					{
574
						unset($var, $options);
575
						$var = $extra_vars[$i];
576
						$name = $var->attrs->name;
577
578
						$buff[] = sprintf('$layout_info->extra_var->%s = new stdClass;', $name);
579
						$buff[] = sprintf('$layout_info->extra_var->%s->group = "%s";', $name, $group->title->body);
580
						$buff[] = sprintf('$layout_info->extra_var->%s->title = "%s";', $name, $var->title->body);
581
						$buff[] = sprintf('$layout_info->extra_var->%s->type = "%s";', $name, $var->attrs->type);
582
						$buff[] = sprintf('$layout_info->extra_var->%s->value = $vars->%s;', $name, $name);
583
						$buff[] = sprintf('$layout_info->extra_var->%s->description = "%s";', $name, str_replace('"','\"',$var->description->body));
584
585
						$options = $var->options;
586
						if(!$options) continue;
587
						if(!is_array($options)) $options = array($options);
588
589
						$buff[] = sprintf('$layout_info->extra_var->%s->options = array();', $var->attrs->name);
590
						$options_count = count($options);
591
						$thumbnail_exist = false;
592
						for($j=0; $j < $options_count; $j++)
593
						{
594
							$buff[] = sprintf('$layout_info->extra_var->%s->options["%s"] = new stdClass;', $var->attrs->name, $options[$j]->attrs->value);
595
							$thumbnail = $options[$j]->attrs->src;
596
							if($thumbnail)
597
							{
598
								$thumbnail = $layout_path.$thumbnail;
599
								if(file_exists($thumbnail))
600
								{
601
									$buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->thumbnail = "%s";', $var->attrs->name, $options[$j]->attrs->value, $thumbnail);
602
									if(!$thumbnail_exist)
603
									{
604
										$buff[] = sprintf('$layout_info->extra_var->%s->thumbnail_exist = true;', $var->attrs->name);
605
										$thumbnail_exist = true;
606
									}
607
								}
608
							}
609
							$buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->val = "%s";', $var->attrs->name, $options[$j]->attrs->value, $options[$j]->title->body);
610
						}
611
					}
612
				}
613
			}
614
			$buff[] = sprintf('$layout_info->extra_var_count = "%s";', $extra_var_count);
615
			// Menu
616
			if($xml_obj->menus->menu)
617
			{
618
				$menus = $xml_obj->menus->menu;
619
				if(!is_array($menus)) $menus = array($menus);
620
621
				$menu_count = count($menus);
622
				$buff[] = sprintf('$layout_info->menu_count = "%s";', $menu_count);
623
				$buff[] = '$layout_info->menu = new stdClass;';
624
				for($i=0;$i<$menu_count;$i++)
625
				{
626
					$name = $menus[$i]->attrs->name;
627
					if($menus[$i]->attrs->default == "true") $buff[] = sprintf('$layout_info->default_menu = "%s";', $name);
628
					$buff[] = sprintf('$layout_info->menu->%s = new stdClass;', $name);
629
					$buff[] = sprintf('$layout_info->menu->%s->name = "%s";',$name, $menus[$i]->attrs->name);
630
					$buff[] = sprintf('$layout_info->menu->%s->title = "%s";',$name, $menus[$i]->title->body);
631
					$buff[] = sprintf('$layout_info->menu->%s->maxdepth = "%s";',$name, $menus[$i]->attrs->maxdepth);
632
633
					$buff[] = sprintf('$layout_info->menu->%s->menu_srl = $vars->%s;', $name, $name);
634
					$buff[] = sprintf('$layout_info->menu->%s->xml_file = "./files/cache/menu/".$vars->%s.".xml.php";',$name, $name);
635
					$buff[] = sprintf('$layout_info->menu->%s->php_file = "./files/cache/menu/".$vars->%s.".php";',$name, $name);
636
				}
637
			}
638
		}
639
		else
640
		{
641
			// Layout title, version and other information
642
			sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d);
643
			$date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
644
			$buff[] = sprintf('$layout_info->layout = "%s";', $layout);
645
			$buff[] = sprintf('$layout_info->path = "%s";', $layout_path);
646
			$buff[] = sprintf('$layout_info->title = "%s";', $xml_obj->title->body);
647
			$buff[] = sprintf('$layout_info->description = "%s";', $xml_obj->author->description->body);
648
			$buff[] = sprintf('$layout_info->version = "%s";', $xml_obj->attrs->version);
649
			$buff[] = sprintf('$layout_info->date = "%s";', $date);
650
			$buff[] = sprintf('$layout_info->layout_srl = $layout_srl;');
651
			$buff[] = sprintf('$layout_info->layout_title = $layout_title;');
652
			// Author information
653
			$buff[] = sprintf('$layout_info->author[0]->name = "%s";', $xml_obj->author->name->body);
654
			$buff[] = sprintf('$layout_info->author[0]->email_address = "%s";', $xml_obj->author->attrs->email_address);
655
			$buff[] = sprintf('$layout_info->author[0]->homepage = "%s";', $xml_obj->author->attrs->link);
656
			// Extra vars (user defined variables to use in a template)
657
			$extra_var_groups = $xml_obj->extra_vars->group;
658
			if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
659
			if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
660
			foreach($extra_var_groups as $group)
661
			{
662
				$extra_vars = $group->var;
663
				if($extra_vars)
664
				{
665
					if(!is_array($extra_vars)) $extra_vars = array($extra_vars);
666
667
					$extra_var_count = count($extra_vars);
668
669
					$buff[] = sprintf('$layout_info->extra_var_count = "%s";', $extra_var_count);
670
					for($i=0;$i<$extra_var_count;$i++)
671
					{
672
						unset($var, $options);
673
						$var = $extra_vars[$i];
674
						$name = $var->attrs->name;
675
676
						$buff[] = sprintf('$layout_info->extra_var->%s->group = "%s";', $name, $group->title->body);
677
						$buff[] = sprintf('$layout_info->extra_var->%s->title = "%s";', $name, $var->title->body);
678
						$buff[] = sprintf('$layout_info->extra_var->%s->type = "%s";', $name, $var->attrs->type);
679
						$buff[] = sprintf('$layout_info->extra_var->%s->value = $vars->%s;', $name, $name);
680
						$buff[] = sprintf('$layout_info->extra_var->%s->description = "%s";', $name, str_replace('"','\"',$var->description->body));
681
682
						$options = $var->options;
683
						if(!$options) continue;
684
685
						if(!is_array($options)) $options = array($options);
686
						$options_count = count($options);
687
						for($j=0;$j<$options_count;$j++)
688
						{
689
							$buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->val = "%s";', $var->attrs->name, $options[$j]->value->body, $options[$j]->title->body);
690
						}
691
					}
692
				}
693
			}
694
			// Menu
695
			if($xml_obj->menus->menu)
696
			{
697
				$menus = $xml_obj->menus->menu;
698
				if(!is_array($menus)) $menus = array($menus);
699
700
				$menu_count = count($menus);
701
				$buff[] = sprintf('$layout_info->menu_count = "%s";', $menu_count);
702
				for($i=0;$i<$menu_count;$i++)
703
				{
704
					$name = $menus[$i]->attrs->name;
705
					if($menus[$i]->attrs->default == "true") $buff[] = sprintf('$layout_info->default_menu = "%s";', $name);
706
					$buff[] = sprintf('$layout_info->menu->%s->name = "%s";',$name, $name);
707
					$buff[] = sprintf('$layout_info->menu->%s->title = "%s";',$name, $menus[$i]->title->body);
708
					$buff[] = sprintf('$layout_info->menu->%s->maxdepth = "%s";',$name, $menus[$i]->maxdepth->body);
709
					$buff[] = sprintf('$layout_info->menu->%s->menu_srl = $vars->%s;', $name, $name);
710
					$buff[] = sprintf('$layout_info->menu->%s->xml_file = "./files/cache/menu/".$vars->%s.".xml.php";',$name, $name);
711
					$buff[] = sprintf('$layout_info->menu->%s->php_file = "./files/cache/menu/".$vars->%s.".php";',$name, $name);
712
				}
713
			}
714
		}
715
716
		// header_script
717
		$oModuleModel = getModel('module');
718
		$layout_config = $oModuleModel->getModulePartConfig('layout', $layout_srl);
719
		$header_script = trim($layout_config->header_script);
720
721
		if($header_script)
722
		{
723
			$buff[] = sprintf(' $layout_info->header_script = "%s"; ', str_replace(array('$','"'),array('\$','\\"'),$header_script));
724
		}
725
726
		FileHandler::writeFile($cache_file, '<?php if(!defined("__XE__")) exit(); ' . join(PHP_EOL, $buff));
727
		if(FileHandler::exists($cache_file)) include($cache_file);
0 ignored issues
show
Bug Best Practice introduced by
The expression \FileHandler::exists($cache_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...
728
729
		if(!$layout_info->title)
0 ignored issues
show
Bug introduced by
The variable $layout_info seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
730
		{
731
			$layout_info->title = $layout;
0 ignored issues
show
Bug introduced by
The variable $layout_info seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
732
		}
733
734
		return $layout_info;
0 ignored issues
show
Bug introduced by
The variable $layout_info seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
735
	}
736
737
	/**
738
	 * Return a list of images which are uploaded on the layout setting page
739
	 * @param int $layout_srl
740
	 * @return array image list in layout
741
	 */
742
	function getUserLayoutImageList($layout_srl)
743
	{
744
		return FileHandler::readDir($this->getUserLayoutImagePath($layout_srl));
745
	}
746
747
	/**
748
	 * Get ini configurations and make them an array.
749
	 * @param int $layout_srl
750
	 * @param string $layout_name
751
	 * @return array
752
	 */
753
	function getUserLayoutIniConfig($layout_srl, $layout_name=null)
754
	{
755
		$file = $this->getUserLayoutIni($layout_srl);
756
		if($layout_name && FileHandler::exists($file) === FALSE)
0 ignored issues
show
Bug Best Practice introduced by
The expression $layout_name of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null 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...
757
		{
758
			FileHandler::copyFile($this->getDefaultLayoutIni($layout_name),$this->getUserLayoutIni($layout_srl));
759
		}
760
761
		return FileHandler::readIniFile($file);
762
	}
763
764
	/**
765
	 * get user layout path
766
	 * @param int $layout_srl
767
	 * @return string
768
	 */
769
	function getUserLayoutPath($layout_srl)
770
	{
771
		return sprintf("./files/faceOff/%s", getNumberingPath($layout_srl,3));
772
	}
773
774
	/**
775
	 * get user layout image path
776
	 * @param int $layout_srl
777
	 * @return string
778
	 */
779
	function getUserLayoutImagePath($layout_srl)
780
	{
781
		return $this->getUserLayoutPath($layout_srl). 'images/';
782
	}
783
784
	/**
785
	 * css which is set by an administrator on the layout setting page
786
	 * @param int $layout_srl
787
	 * @return string
788
	 */
789
	function getUserLayoutCss($layout_srl)
790
	{
791
		return $this->getUserLayoutPath($layout_srl). 'layout.css';
792
	}
793
794
	/**
795
	 * Import faceoff css from css module handler
796
	 * @param int $layout_srl
797
	 * @return string
798
	 */
799
	function getUserLayoutFaceOffCss($layout_srl)
800
	{
801
		if($this->useUserLayoutTemp == 'temp') return;
802
		return $this->_getUserLayoutFaceOffCss($layout_srl);
803
	}
804
805
	/**
806
	 * Import faceoff css from css module handler
807
	 * @param int $layout_srl
808
	 * @return string
809
	 */
810
	function _getUserLayoutFaceOffCss($layout_srl)
811
	{
812
		return $this->getUserLayoutPath($layout_srl). 'faceoff.css';
813
	}
814
815
	/**
816
	 * get user layout tmp html
817
	 * @param int $layout_srl
818
	 * @return string
819
	 */
820
	function getUserLayoutTempFaceOffCss($layout_srl)
821
	{
822
		return $this->getUserLayoutPath($layout_srl). 'tmp.faceoff.css';
823
	}
824
825
	/**
826
	 * user layout html
827
	 * @param int $layout_srl
828
	 * @return string
829
	 */
830 View Code Duplication
	function getUserLayoutHtml($layout_srl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
831
	{
832
		$src = $this->getUserLayoutPath($layout_srl). 'layout.html';
833
		if($this->useUserLayoutTemp == 'temp')
834
		{
835
			$temp = $this->getUserLayoutTempHtml($layout_srl);
836
			if(FileHandler::exists($temp) === FALSE) FileHandler::copyFile($src,$temp);
837
			return $temp;
838
		}
839
840
		return $src;
841
	}
842
843
	/**
844
	 * user layout tmp html
845
	 * @param int $layout_srl
846
	 * @return string
847
	 */
848
	function getUserLayoutTempHtml($layout_srl)
849
	{
850
		return $this->getUserLayoutPath($layout_srl). 'tmp.layout.html';
851
	}
852
853
	/**
854
	 * user layout ini
855
	 * @param int $layout_srl
856
	 * @return string
857
	 */
858 View Code Duplication
	function getUserLayoutIni($layout_srl)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
859
	{
860
		$src = $this->getUserLayoutPath($layout_srl). 'layout.ini';
861
		if($this->useUserLayoutTemp == 'temp')
862
		{
863
			$temp = $this->getUserLayoutTempIni($layout_srl);
864
			if(!file_exists(FileHandler::getRealPath($temp))) FileHandler::copyFile($src,$temp);
865
			return $temp;
866
		}
867
868
		return $src;
869
	}
870
871
	/**
872
	 * user layout tmp ini
873
	 * @param int $layout_srl
874
	 * @return string
875
	 */
876
	function getUserLayoutTempIni($layout_srl)
877
	{
878
		return $this->getUserLayoutPath($layout_srl). 'tmp.layout.ini';
879
	}
880
881
	/**
882
	 * user layout cache
883
	 * TODO It may need to remove the file itself
884
	 * @param int $layout_srl
885
	 * @param string $lang_type
886
	 * @return string
887
	 */
888
	function getUserLayoutCache($layout_srl,$lang_type)
889
	{
890
		return $this->getUserLayoutPath($layout_srl). "{$lang_type}.cache.php";
891
	}
892
893
	/**
894
	 * layout cache
895
	 * @param int $layout_srl
0 ignored issues
show
Bug introduced by
There is no parameter named $layout_srl. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
896
	 * @param string $lang_type
897
	 * @return string
898
	 */
899
	function getLayoutCache($layout_name,$lang_type,$layout_type='P')
900
	{
901
		if($layout_type=='P')
902
		{
903
			return sprintf("%sfiles/cache/layout/%s.%s.cache.php", _XE_PATH_, $layout_name,$lang_type);
904
		}
905
		else
906
		{
907
			return sprintf("%sfiles/cache/layout/m.%s.%s.cache.php", _XE_PATH_, $layout_name,$lang_type);
908
		}
909
	}
910
911
	/**
912
	 * default layout ini to prevent arbitrary changes by a user
913
	 * @param string $layout_name
914
	 * @return string
915
	 */
916
	function getDefaultLayoutIni($layout_name)
917
	{
918
		return $this->getDefaultLayoutPath($layout_name). 'layout.ini';
0 ignored issues
show
Unused Code introduced by
The call to layoutModel::getDefaultLayoutPath() has too many arguments starting with $layout_name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Deprecated Code introduced by
The method layoutModel::getDefaultLayoutPath() has been deprecated.

This method has been deprecated.

Loading history...
919
	}
920
921
	/**
922
	 * default layout html to prevent arbitrary changes by a user
923
	 * @param string $layout_name
924
	 * @return string
925
	 */
926
	function getDefaultLayoutHtml($layout_name)
927
	{
928
		return $this->getDefaultLayoutPath($layout_name). 'layout.html';
0 ignored issues
show
Unused Code introduced by
The call to layoutModel::getDefaultLayoutPath() has too many arguments starting with $layout_name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Deprecated Code introduced by
The method layoutModel::getDefaultLayoutPath() has been deprecated.

This method has been deprecated.

Loading history...
929
	}
930
931
	/**
932
	 * default layout css to prevent arbitrary changes by a user
933
	 * @param string $layout_name
934
	 * @return string
935
	 */
936
	function getDefaultLayoutCss($layout_name)
937
	{
938
		return $this->getDefaultLayoutPath($layout_name). 'css/layout.css';
0 ignored issues
show
Unused Code introduced by
The call to layoutModel::getDefaultLayoutPath() has too many arguments starting with $layout_name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Deprecated Code introduced by
The method layoutModel::getDefaultLayoutPath() has been deprecated.

This method has been deprecated.

Loading history...
939
	}
940
941
	/**
942
	 * default layout path to prevent arbitrary changes by a user
943
	 * @deprecated
944
	 * @return string
945
	 */
946
	function getDefaultLayoutPath()
947
	{
948
		return "./modules/layout/faceoff/";
949
	}
950
951
	/**
952
	 * faceoff is
953
	 * @param string $layout_name
954
	 * @return boolean (true : faceoff, false : layout)
955
	 */
956
	function useDefaultLayout($layout_name)
957
	{
958
		$info = $this->getLayoutInfo($layout_name);
959
		return ($info->type == 'faceoff');
960
	}
961
962
	/**
963
	 * Set user layout as temporary save mode
964
	 * @param string $flag (default 'temp')
965
	 * @return void
966
	 */
967
	function setUseUserLayoutTemp($flag='temp')
968
	{
969
		$this->useUserLayoutTemp = $flag;
970
	}
971
972
	/**
973
	 * Temp file list for User Layout
974
	 * @param int $layout_srl
975
	 * @return array temp files info
976
	 */
977
	function getUserLayoutTempFileList($layout_srl)
978
	{
979
		return array(
980
				$this->getUserLayoutTempHtml($layout_srl),
981
				$this->getUserLayoutTempFaceOffCss($layout_srl),
982
				$this->getUserLayoutTempIni($layout_srl)
983
				);
984
	}
985
986
	/**
987
	 * Saved file list for User Layout
988
	 * @param int $layout_srl
989
	 * @return array files info
990
	 */
991
	function getUserLayoutFileList($layout_srl)
992
	{
993
		$file_list = array(
994
			basename($this->getUserLayoutHtml($layout_srl)),
995
			basename($this->getUserLayoutFaceOffCss($layout_srl)),
996
			basename($this->getUserLayoutIni($layout_srl)),
997
			basename($this->getUserLayoutCss($layout_srl))
998
		);
999
1000
		$image_path = $this->getUserLayoutImagePath($layout_srl);
1001
		$image_list = FileHandler::readDir($image_path,'/(.*(?:swf|jpg|jpeg|gif|bmp|png)$)/i');
1002
1003
		foreach($image_list as $image)
1004
		{
1005
			$file_list[] = 'images/' . $image;
1006
		}
1007
		return $file_list;
1008
	}
1009
1010
	/**
1011
	 * faceOff related services for the operation run out
1012
	 * @deprecated
1013
	 * @param object $layout_info
1014
	 * @return void
1015
	 */
1016
	function doActivateFaceOff(&$layout_info)
1017
	{
1018
		$layout_info->faceoff_ini_config = $this->getUserLayoutIniConfig($layout_info->layout_srl, $layout_info->layout);
1019
		// faceoff layout CSS
1020
		Context::addCSSFile($this->getDefaultLayoutCss($layout_info->layout));
0 ignored issues
show
Deprecated Code introduced by
The method Context::addCSSFile() has been deprecated.

This method has been deprecated.

Loading history...
1021
		// CSS generated in the layout manager
1022
		$faceoff_layout_css = $this->getUserLayoutFaceOffCss($layout_info->layout_srl);
1023
		if($faceoff_layout_css) Context::addCSSFile($faceoff_layout_css);
0 ignored issues
show
Bug Best Practice introduced by
The expression $faceoff_layout_css of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null 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...
Deprecated Code introduced by
The method Context::addCSSFile() has been deprecated.

This method has been deprecated.

Loading history...
1024
		// CSS output for the widget
1025
		Context::loadFile($this->module_path.'/tpl/css/widget.css', true);
0 ignored issues
show
Bug introduced by
The property module_path cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Documentation introduced by
$this->module_path . '/tpl/css/widget.css' is of type string, but the function expects a array.

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...
Unused Code introduced by
The call to Context::loadFile() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1026
		if($layout_info->extra_var->colorset->value == 'black') Context::loadFile($this->module_path.'/tpl/css/[email protected]', true);
0 ignored issues
show
Bug introduced by
The property module_path cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Documentation introduced by
$this->module_path . '/tpl/css/[email protected]' is of type string, but the function expects a array.

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...
Unused Code introduced by
The call to Context::loadFile() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1027
		else Context::loadFile($this->module_path.'/tpl/css/[email protected]', true);
0 ignored issues
show
Bug introduced by
The property module_path cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Documentation introduced by
$this->module_path . '/tpl/css/[email protected]' is of type string, but the function expects a array.

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...
Unused Code introduced by
The call to Context::loadFile() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1028
		// Different page displayed upon user's permission
1029
		$logged_info = Context::get('logged_info');
1030
		// Display edit button for faceoff layout
1031
		if(Context::get('module')!='admin' && strpos(Context::get('act'),'Admin')===false && ($logged_info->is_admin == 'Y' || $logged_info->is_site_admin))
1032
		{
1033
			Context::addHtmlFooter('<div class="faceOffManager" style="height: 23px; position: fixed; right: 3px; top: 3px;"><a href="'.getUrl('','mid',Context::get('mid'),'act','dispLayoutAdminLayoutModify','delete_tmp','Y').'">'.Context::getLang('cmd_layout_edit').'</a></div>');
1034
		}
1035
		// Display menu when editing the faceOff page
1036
		if(Context::get('act')=='dispLayoutAdminLayoutModify' && ($logged_info->is_admin == 'Y' || $logged_info->is_site_admin))
1037
		{
1038
			$oTemplate = &TemplateHandler::getInstance();
1039
			Context::addBodyHeader($oTemplate->compile($this->module_path.'/tpl', 'faceoff_layout_menu'));
0 ignored issues
show
Bug introduced by
The property module_path cannot be accessed from this context as it is declared private in class ModuleObject.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
1040
		}
1041
	}
1042
}
1043
/* End of file layout.model.php */
1044
/* Location: ./modules/layout/layout.model.php */
1045