GitHub Access Token became invalid

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

adminAdminModel::getAdminMenuLang()   C

Complexity

Conditions 7
Paths 3

Size

Total Lines 34
Code Lines 17

Duplication

Lines 11
Ratio 32.35 %

Importance

Changes 0
Metric Value
cc 7
eloc 17
nc 3
nop 0
dl 11
loc 34
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/* Copyright (C) NAVER <http://www.navercorp.com> */
3
4
/**
5
 * adminAdminModel class
6
 * admin model class of admin module
7
 * @author NAVER ([email protected])
8
 * @package /modules/admin
9
 * @version 0.1
10
 */
11
class adminAdminModel extends admin
12
{
13
14
	/**
15
	 * Ftp root path
16
	 * @var string
17
	 */
18
	var $pwd;
19
20
	/**
21
	 * Buffer for Admin GNB menu
22
	 * @var string
23
	 */
24
	var $gnbLangBuffer;
25
26
	/**
27
	 * Find XE installed path on sftp
28
	 */
29
	function getSFTPPath()
30
	{
31
		$ftp_info = Context::getRequestVars();
32
33
		if(!$ftp_info->ftp_host)
34
		{
35
			$ftp_info->ftp_host = "127.0.0.1";
0 ignored issues
show
Bug introduced by
The property ftp_host does not seem to exist in BaseObject.

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...
36
		}
37
38
		if(!$ftp_info->ftp_port || !is_numeric($ftp_info->ftp_port))
39
		{
40
			$ftp_info->ftp_port = '22';
0 ignored issues
show
Bug introduced by
The property ftp_port does not seem to exist in BaseObject.

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...
41
		}
42
43
		$connection = ssh2_connect($ftp_info->ftp_host, $ftp_info->ftp_port);
44
		if(!ssh2_auth_password($connection, $ftp_info->ftp_user, $ftp_info->ftp_password))
0 ignored issues
show
Bug introduced by
The property ftp_user does not seem to exist in BaseObject.

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...
Bug introduced by
The property ftp_password does not seem to exist in BaseObject.

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...
45
		{
46
			return new BaseObject(-1, 'msg_ftp_invalid_auth_info');
47
		}
48
		$sftp = ssh2_sftp($connection);
49
50
		// create temp file
51
		$pin = $_SERVER['REQUEST_TIME'];
52
		FileHandler::writeFile('./files/cache/ftp_check', $pin);
53
54
		// create path candidate
55
		$xe_path = _XE_PATH_;
0 ignored issues
show
Unused Code introduced by
$xe_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...
56
		$path_info = array_reverse(explode('/', _XE_PATH_));
57
		array_pop($path_info); // remove last '/'
58
		$path_candidate = array();
59
60
		$temp = '';
61
		foreach($path_info as $path)
62
		{
63
			$temp = '/' . $path . $temp;
64
			$path_candidate[] = $temp;
65
		}
66
67
		// try
68 View Code Duplication
		foreach($path_candidate as $path)
69
		{
70
			// upload check file
71
			if(!@ssh2_scp_send($connection, FileHandler::getRealPath('./files/cache/ftp_check'), $path . 'ftp_check.html'))
72
			{
73
				continue;
74
			}
75
76
			// get check file
77
			$result = FileHandler::getRemoteResource(getNotencodedFullUrl() . 'ftp_check.html');
78
79
			// delete temp check file
80
			@ssh2_sftp_unlink($sftp, $path . 'ftp_check.html');
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...
81
82
			// found
83
			if($result == $pin)
84
			{
85
				$found_path = $path;
86
				break;
87
			}
88
		}
89
90
		FileHandler::removeFile('./files/cache/ftp_check', $pin);
0 ignored issues
show
Unused Code introduced by
The call to FileHandler::removeFile() has too many arguments starting with $pin.

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...
91
92
		if($found_path)
93
		{
94
			$this->add('found_path', $found_path);
0 ignored issues
show
Bug introduced by
The variable $found_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...
95
		}
96
	}
97
98
	function getFTPPath()
99
	{
100
		$ftp_info = Context::getRequestVars();
101
102
		if(!$ftp_info->ftp_host)
103
		{
104
			$ftp_info->ftp_host = "127.0.0.1";
0 ignored issues
show
Bug introduced by
The property ftp_host does not seem to exist in BaseObject.

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...
105
		}
106
107
		if(!$ftp_info->ftp_port || !is_numeric($ftp_info->ftp_port))
108
		{
109
			$ftp_info->ftp_port = '22';
0 ignored issues
show
Bug introduced by
The property ftp_port does not seem to exist in BaseObject.

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...
110
		}
111
112
		$connection = ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port);
113
		if(!$connection)
114
		{
115
			return new BaseObject(-1, sprintf(Context::getLang('msg_ftp_not_connected'), 'host'));
116
		}
117
118
		$login_result = @ftp_login($connection, $ftp_info->ftp_user, $ftp_info->ftp_password);
0 ignored issues
show
Bug introduced by
The property ftp_user does not seem to exist in BaseObject.

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...
Bug introduced by
The property ftp_password does not seem to exist in BaseObject.

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...
119
		if(!$login_result)
120
		{
121
			ftp_close($connection);
122
			return new BaseObject(-1, 'msg_ftp_invalid_auth_info');
123
		}
124
125
		// create temp file
126
		$pin = $_SERVER['REQUEST_TIME'];
127
		FileHandler::writeFile('./files/cache/ftp_check', $pin);
128
129
		// create path candidate
130
		$xe_path = _XE_PATH_;
0 ignored issues
show
Unused Code introduced by
$xe_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...
131
		$path_info = array_reverse(explode('/', _XE_PATH_));
132
		array_pop($path_info); // remove last '/'
133
		$path_candidate = array();
134
135
		$temp = '';
136
		foreach($path_info as $path)
137
		{
138
			$temp = '/' . $path . $temp;
139
			$path_candidate[] = $temp;
140
		}
141
142
		// try
143 View Code Duplication
		foreach($path_candidate as $path)
144
		{
145
			// upload check file
146
			if(!ftp_put($connection, $path . 'ftp_check.html', FileHandler::getRealPath('./files/cache/ftp_check'), FTP_BINARY))
147
			{
148
				continue;
149
			}
150
151
			// get check file
152
			$result = FileHandler::getRemoteResource(getNotencodedFullUrl() . 'ftp_check.html');
153
154
			// delete temp check file
155
			ftp_delete($connection, $path . 'ftp_check.html');
156
157
			// found
158
			if($result == $pin)
159
			{
160
				$found_path = $path;
161
				break;
162
			}
163
		}
164
165
		FileHandler::removeFile('./files/cache/ftp_check', $pin);
0 ignored issues
show
Unused Code introduced by
The call to FileHandler::removeFile() has too many arguments starting with $pin.

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...
166
167
		if($found_path)
168
		{
169
			$this->add('found_path', $found_path);
0 ignored issues
show
Bug introduced by
The variable $found_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...
170
		}
171
	}
172
173
	/**
174
	 * Find XE installed path on ftp
175
	 */
176
	function getAdminFTPPath()
177
	{
178
		Context::loadLang(_XE_PATH_ . 'modules/autoinstall/lang');
179
		@set_time_limit(5);
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...
180
		require_once(_XE_PATH_ . 'libs/ftp.class.php');
181
182
		$ftp_info = Context::getRequestVars();
183
184
		if(!$ftp_info->ftp_user || !$ftp_info->ftp_password)
0 ignored issues
show
Bug introduced by
The property ftp_user does not seem to exist in BaseObject.

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...
Bug introduced by
The property ftp_password does not seem to exist in BaseObject.

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...
185
		{
186
			return new BaseObject(1, 'msg_ftp_invalid_auth_info');
187
		}
188
189
		if(!$ftp_info->ftp_host)
190
		{
191
			$ftp_info->ftp_host = '127.0.0.1';
0 ignored issues
show
Bug introduced by
The property ftp_host does not seem to exist in BaseObject.

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...
192
		}
193
194
		if(!$ftp_info->ftp_port || !is_numeric($ftp_info->ftp_port))
195
		{
196
			$ftp_info->ftp_port = '21';
0 ignored issues
show
Bug introduced by
The property ftp_port does not seem to exist in BaseObject.

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...
197
		}
198
199 View Code Duplication
		if($ftp_info->sftp == 'Y')
0 ignored issues
show
Bug introduced by
The property sftp does not seem to exist in BaseObject.

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...
200
		{
201
			if(!function_exists('ssh2_sftp'))
202
			{
203
				return new BaseObject(-1, 'disable_sftp_support');
204
			}
205
			return $this->getSFTPPath();
206
		}
207
208
		if($ftp_info->ftp_pasv == 'N')
209
		{
210
			if(function_exists('ftp_connect'))
211
			{
212
				return $this->getFTPPath();
213
			}
214
			$ftp_info->ftp_pasv = "Y";
0 ignored issues
show
Bug introduced by
The property ftp_pasv does not seem to exist in BaseObject.

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...
215
		}
216
217
		$oFTP = new ftp();
218
		if(!$oFTP->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port))
219
		{
220
			return new BaseObject(1, sprintf(Context::getLang('msg_ftp_not_connected'), 'host'));
221
		}
222
223
		if(!$oFTP->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password))
224
		{
225
			return new BaseObject(1, 'msg_ftp_invalid_auth_info');
226
		}
227
228
		// create temp file
229
		$pin = $_SERVER['REQUEST_TIME'];
230
		FileHandler::writeFile('./files/cache/ftp_check', $pin);
231
232
		// create path candidate
233
		$xe_path = _XE_PATH_;
0 ignored issues
show
Unused Code introduced by
$xe_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...
234
		$path_info = array_reverse(explode('/', _XE_PATH_));
235
		array_pop($path_info); // remove last '/'
236
		$path_candidate = array();
237
238
		$temp = '';
239
		foreach($path_info as $path)
240
		{
241
			$temp = '/' . $path . $temp;
242
			$path_candidate[] = $temp;
243
		}
244
245
		// try
246
		foreach($path_candidate as $path)
247
		{
248
			// upload check file
249
			if(!$oFTP->ftp_put($path . 'ftp_check.html', FileHandler::getRealPath('./files/cache/ftp_check')))
250
			{
251
				continue;
252
			}
253
254
			// get check file
255
			$result = FileHandler::getRemoteResource(getNotencodedFullUrl() . 'ftp_check.html');
256
257
			// delete temp check file
258
			$oFTP->ftp_delete($path . 'ftp_check.html');
259
260
			// found
261
			if($result == $pin)
262
			{
263
				$found_path = $path;
264
				break;
265
			}
266
		}
267
268
		FileHandler::removeFile('./files/cache/ftp_check', $pin);
0 ignored issues
show
Unused Code introduced by
The call to FileHandler::removeFile() has too many arguments starting with $pin.

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...
269
270
		if($found_path)
271
		{
272
			$this->add('found_path', $found_path);
0 ignored issues
show
Bug introduced by
The variable $found_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...
273
		}
274
	}
275
276
	/**
277
	 * Add file list to BaseObject after sftp connect
278
	 * @return void|BaseObject
279
	 */
280 View Code Duplication
	function getSFTPList()
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...
281
	{
282
		$ftp_info = Context::getRequestVars();
283
		if(!$ftp_info->ftp_host)
284
		{
285
			$ftp_info->ftp_host = "127.0.0.1";
0 ignored issues
show
Bug introduced by
The property ftp_host does not seem to exist in BaseObject.

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...
286
		}
287
		$connection = ssh2_connect($ftp_info->ftp_host, $ftp_info->ftp_port);
0 ignored issues
show
Bug introduced by
The property ftp_port does not seem to exist in BaseObject.

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...
288
		if(!ssh2_auth_password($connection, $ftp_info->ftp_user, $ftp_info->ftp_password))
0 ignored issues
show
Bug introduced by
The property ftp_user does not seem to exist in BaseObject.

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...
Bug introduced by
The property ftp_password does not seem to exist in BaseObject.

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...
289
		{
290
			return new BaseObject(-1, 'msg_ftp_invalid_auth_info');
291
		}
292
293
		$sftp = ssh2_sftp($connection);
294
		$curpwd = "ssh2.sftp://$sftp" . $this->pwd;
295
		$dh = @opendir($curpwd);
296
		if(!$dh)
297
		{
298
			return new BaseObject(-1, 'msg_ftp_invalid_path');
299
		}
300
		$list = array();
301
		while(($file = readdir($dh)) !== FALSE)
302
		{
303
			if(is_dir($curpwd . $file))
304
			{
305
				$file .= "/";
306
			}
307
			else
308
			{
309
				continue;
310
			}
311
			$list[] = $file;
312
		}
313
		closedir($dh);
314
		$this->add('list', $list);
315
	}
316
317
	/**
318
	 * Add file list to BaseObject after ftp connect
319
	 * @return void|BaseObject
320
	 */
321
	function getAdminFTPList()
322
	{
323
		Context::loadLang(_XE_PATH_ . 'modules/autoinstall/lang');
324
		@set_time_limit(5);
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...
325
326
		require_once(_XE_PATH_ . 'libs/ftp.class.php');
327
328
		$ftp_info = Context::getRequestVars();
329
		if(!$ftp_info->ftp_user || !$ftp_info->ftp_password)
0 ignored issues
show
Bug introduced by
The property ftp_user does not seem to exist in BaseObject.

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...
Bug introduced by
The property ftp_password does not seem to exist in BaseObject.

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...
330
		{
331
			return new BaseObject(-1, 'msg_ftp_invalid_auth_info');
332
		}
333
334
		$this->pwd = $ftp_info->ftp_root_path;
0 ignored issues
show
Bug introduced by
The property ftp_root_path does not seem to exist in BaseObject.

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...
335
336
		if(!$ftp_info->ftp_host)
337
		{
338
			$ftp_info->ftp_host = "127.0.0.1";
0 ignored issues
show
Bug introduced by
The property ftp_host does not seem to exist in BaseObject.

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...
339
		}
340
341
		if(!$ftp_info->ftp_port || !is_numeric($ftp_info->ftp_port))
342
		{
343
			$ftp_info->ftp_port = "21";
0 ignored issues
show
Bug introduced by
The property ftp_port does not seem to exist in BaseObject.

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...
344
		}
345
346 View Code Duplication
		if($ftp_info->sftp == 'Y')
0 ignored issues
show
Bug introduced by
The property sftp does not seem to exist in BaseObject.

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...
347
		{
348
			if(!function_exists('ssh2_sftp'))
349
			{
350
				return new BaseObject(-1, 'disable_sftp_support');
351
			}
352
			return $this->getSFTPList();
353
		}
354
355
		$oFtp = new ftp();
356 View Code Duplication
		if($oFtp->ftp_connect($ftp_info->ftp_host, $ftp_info->ftp_port))
357
		{
358
			if($oFtp->ftp_login($ftp_info->ftp_user, $ftp_info->ftp_password))
359
			{
360
				$_list = $oFtp->ftp_rawlist($this->pwd);
361
				$oFtp->ftp_quit();
362
			}
363
			else
364
			{
365
				return new BaseObject(-1, 'msg_ftp_invalid_auth_info');
366
			}
367
		}
368
		$list = array();
369
370 View Code Duplication
		if($_list)
371
		{
372
			foreach($_list as $k => $v)
0 ignored issues
show
Bug introduced by
The variable $_list 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...
373
			{
374
				$src = new stdClass();
375
				$src->data = $v;
376
				$res = Context::convertEncoding($src);
377
				$v = $res->data;
378
				if(strpos($v, 'd') === 0 || strpos($v, '<DIR>'))
379
				{
380
					$list[] = substr(strrchr($v, ' '), 1) . '/';
381
				}
382
			}
383
		}
384
		else
385
		{
386
			return new BaseObject(-1, 'msg_ftp_no_directory');
387
		}
388
		$this->add('list', $list);
389
	}
390
391
	/**
392
	 * Parameter arrange for send to XE collect server
393
	 * @param string $type 'WORKING', 'INSTALL'
394
	 * @return string
395
	 */
396
	function getEnv($type = 'WORKING')
397
	{
398
		$skip = array(
399
			'ext' => array('pcre', 'json', 'hash', 'dom', 'session', 'spl', 'standard', 'date', 'ctype', 'tokenizer', 'apache2handler', 'filter', 'posix', 'reflection', 'pdo')
400
			, 'module' => array('addon', 'admin', 'autoinstall', 'comment', 'communication', 'counter', 'document', 'editor', 'file', 'importer', 'install', 'integration_search', 'layout', 'member', 'menu', 'message', 'module', 'opage', 'page', 'point', 'poll', 'rss', 'session', 'spamfilter', 'tag', 'trackback', 'trash', 'widget')
401
			, 'addon' => array('autolink', 'blogapi', 'captcha', 'counter', 'member_communication', 'member_extra_info', 'mobile', 'openid_delegation_id', 'point_level_icon', 'resize_image')
402
			, 'layout' => array('default')
403
			, 'widget' => array('content', 'language_select', 'login_info','mcontent')
404
			, 'widgetstyle' => array(),
405
		);
406
		$info = array();
407
		$db_info = Context::getDBInfo();
408
409
		$info['type'] = ($type != 'INSTALL' ? 'WORKING' : 'INSTALL');
410
		$info['location'] = _XE_LOCATION_;
411
		$info['package'] = _XE_PACKAGE_;
412
		$info['host'] = $db_type->default_url ? $db_type->default_url : getFullUrl();
0 ignored issues
show
Bug introduced by
The variable $db_type 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...
413
		$info['app'] = $_SERVER['SERVER_SOFTWARE'];
414
		$info['xe_version'] = __XE_VERSION__;
415
		$info['php'] = phpversion();
416
417
		$info['db_type'] = Context::getDBType();
418
		$info['use_rewrite'] = $db_info->use_rewrite;
419
		$info['use_db_session'] = $db_info->use_db_session == 'Y' ? 'Y' : 'N';
420
		$info['use_ssl'] = $db_info->use_ssl;
421
		
422
		$info['phpext'] = '';
423
		foreach(get_loaded_extensions() as $ext)
424
		{
425
			$ext = strtolower($ext);
426
			if(in_array($ext, $skip['ext']))
427
			{
428
				continue;
429
			}
430
			$info['phpext'] .= '|' . $ext;
431
		}
432
		$info['phpext'] = substr($info['phpext'], 1);
433
434
		$info['module'] = '';
435
		$oModuleModel = getModel('module');
436
		$module_list = $oModuleModel->getModuleList();
437
		if($module_list) foreach($module_list as $module)
438
		{
439
			if(in_array($module->module, $skip['module']))
440
			{
441
				continue;
442
			}
443
			$info['module'] .= '|' . $module->module;
444
		}
445
		$info['module'] = substr($info['module'], 1);
446
447
		$info['addon'] = '';
448
		$oAddonAdminModel = getAdminModel('addon');
449
		$addon_list = $oAddonAdminModel->getAddonList();
450
		if($addon_list) foreach($addon_list as $addon)
451
		{
452
			if(in_array($addon->addon, $skip['addon']))
453
			{
454
				continue;
455
			}
456
			$info['addon'] .= '|' . $addon->addon;
457
		}
458
		$info['addon'] = substr($info['addon'], 1);
459
460
		$info['layout'] = "";
461
		$oLayoutModel = getModel('layout');
462
		$layout_list = $oLayoutModel->getDownloadedLayoutList();
463
		if($layout_list) foreach($layout_list as $layout)
464
		{
465
			if(in_array($layout->layout, $skip['layout']))
466
			{
467
				continue;
468
			}
469
			$info['layout'] .= '|' . $layout->layout;
470
		}
471
		$info['layout'] = substr($info['layout'], 1);
472
473
		$info['widget'] = "";
474
		$oWidgetModel = getModel('widget');
475
		$widget_list = $oWidgetModel->getDownloadedWidgetList();
476
		if($widget_list) foreach($widget_list as $widget)
477
		{
478
			if(in_array($widget->widget, $skip['widget']))
479
			{
480
				continue;
481
			}
482
			$info['widget'] .= '|' . $widget->widget;
483
		}
484
		$info['widget'] = substr($info['widget'], 1);
485
486
		$info['widgetstyle'] = "";
487
		$oWidgetModel = getModel('widget');
488
		$widgetstyle_list = $oWidgetModel->getDownloadedWidgetStyleList();
489
		if($widgetstyle_list) foreach($widgetstyle_list as $widgetstyle)
490
		{
491
			if(in_array($widgetstyle->widgetStyle, $skip['widgetstyle']))
492
			{
493
				continue;
494
			}
495
			$info['widgetstyle'] .= '|' . $widgetstyle->widgetStyle;
496
		}
497
		$info['widgetstyle'] = substr($info['widgetstyle'], 1);
498
499
		$param = '';
500
		foreach($info as $k => $v)
501
		{
502
			if($v)
503
			{
504
				$param .= sprintf('&%s=%s', $k, urlencode($v));
505
			}
506
		}
507
		$param = substr($param, 1);
508
509
		return $param;
510
	}
511
512
	/**
513
	 * Return theme info list by theme directory list
514
	 * @return array
515
	 */
516
	function getThemeList()
517
	{
518
		$path = _XE_PATH_ . 'themes';
519
		$list = FileHandler::readDir($path);
520
521
		$theme_info = array();
522
		if(count($list) > 0)
523
		{
524
			foreach($list as $val)
525
			{
526
				$theme_info[$val] = $this->getThemeInfo($val);
527
			}
528
		}
529
530
		return $theme_info;
531
	}
532
533
	/**
534
	 * Return theme info
535
	 * @param string $theme_name
536
	 * @param array $layout_list
537
	 * @return object
538
	 */
539
	function getThemeInfo($theme_name, $layout_list = NULL)
0 ignored issues
show
Unused Code introduced by
The parameter $layout_list 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...
540
	{
541
		if($GLOBALS['__ThemeInfo__'][$theme_name])
542
		{
543
			return $GLOBALS['__ThemeInfo__'][$theme_name];
544
		}
545
546
		$info_file = _XE_PATH_ . 'themes/' . $theme_name . '/conf/info.xml';
547
		if(!file_exists($info_file))
548
		{
549
			return;
550
		}
551
552
		$oXmlParser = new XmlParser();
553
		$_xml_obj = $oXmlParser->loadXmlFile($info_file);
554
		if(!$_xml_obj->theme)
555
		{
556
			return;
557
		}
558
559
		$xml_obj = $_xml_obj->theme;
560
561
		// 스킨이름
562
		$theme_info = new stdClass();
563
		$theme_info->name = $theme_name;
564
		$theme_info->title = $xml_obj->title->body;
565
		$thumbnail = './themes/' . $theme_name . '/thumbnail.png';
566
		$theme_info->thumbnail = (FileHandler::exists($thumbnail)) ? $thumbnail : NULL;
567
		$theme_info->version = $xml_obj->version->body;
568
		$date_obj = new stdClass();
569
		sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
570
		$theme_info->date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
571
		$theme_info->description = $xml_obj->description->body;
572
		$theme_info->path = './themes/' . $theme_name . '/';
573
574
		if(!is_array($xml_obj->publisher))
575
		{
576
			$publisher_list = array();
577
			$publisher_list[] = $xml_obj->publisher;
578
		}
579
		else
580
		{
581
			$publisher_list = $xml_obj->publisher;
582
		}
583
584
		$theme_info->publisher = array();
585 View Code Duplication
		foreach($publisher_list as $publisher)
586
		{
587
			$publisher_obj = new stdClass();
588
			$publisher_obj->name = $publisher->name->body;
589
			$publisher_obj->email_address = $publisher->attrs->email_address;
590
			$publisher_obj->homepage = $publisher->attrs->link;
591
			$theme_info->publisher[] = $publisher_obj;
592
		}
593
594
		$layout = $xml_obj->layout;
595
		$layout_path = $layout->directory->attrs->path;
596
		$layout_parse = explode('/', $layout_path);
597
		$layout_info = new stdClass();
598
		switch($layout_parse[1])
599
		{
600
			case 'themes' :
601
					$layout_info->name = $theme_name . '|@|' . $layout_parse[count($layout_parse) - 1];
602
					break;
603
604
			case 'layouts' :
605
					$layout_info->name = $layout_parse[count($layout_parse) - 1];
606
					break;
607
608
		}
609
		$layout_info->title = $layout_parse[count($layout_parse) - 1];
610
		$layout_info->path = $layout_path;
611
612
		$site_info = Context::get('site_module_info');
613
		// check layout instance
614
		$is_new_layout = TRUE;
615
		$oLayoutModel = getModel('layout');
616
		$layout_info_list = array();
0 ignored issues
show
Unused Code introduced by
$layout_info_list 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...
617
		$layout_list = $oLayoutModel->getLayoutList($site_info->site_srl);
618
		if($layout_list)
619
		{
620
			foreach($layout_list as $val)
621
			{
622
				if($val->layout == $layout_info->name)
623
				{
624
					$is_new_layout = FALSE;
625
					$layout_info->layout_srl = $val->layout_srl;
626
					break;
627
				}
628
			}
629
		}
630
631
		if($is_new_layout)
632
		{
633
			$site_module_info = Context::get('site_module_info');
634
			$args = new stdClass();
635
			$args->site_srl = (int) $site_module_info->site_srl;
636
			$args->layout_srl = getNextSequence();
637
			$args->layout = $layout_info->name;
638
			$args->title = $layout_info->title;
639
			$args->layout_type = "P";
640
			// Insert into the DB
641
			$oLayoutAdminController = getAdminController('layout');
642
			$output = $oLayoutAdminController->insertLayout($args);
0 ignored issues
show
Unused Code introduced by
$output 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
			$layout_info->layout_srl = $args->layout_srl;
644
		}
645
646
		$theme_info->layout_info = $layout_info;
647
648
		$skin_infos = $xml_obj->skininfos;
649
		if(is_array($skin_infos->skininfo))
650
		{
651
			$skin_list = $skin_infos->skininfo;
652
		}
653
		else
654
		{
655
			$skin_list = array($skin_infos->skininfo);
656
		}
657
658
		$oModuleModel = getModel('module');
659
		$skins = array();
660
		foreach($skin_list as $val)
661
		{
662
			$skin_info = new stdClass();
663
			unset($skin_parse);
664
			$skin_parse = explode('/', $val->directory->attrs->path);
665
			switch($skin_parse[1])
666
			{
667 View Code Duplication
				case 'themes' :
668
						$is_theme = TRUE;
669
						$module_name = $skin_parse[count($skin_parse) - 1];
670
						$skin_info->name = $theme_name . '|@|' . $module_name;
671
						break;
672
673 View Code Duplication
				case 'modules' :
674
						$is_theme = FALSE;
675
						$module_name = $skin_parse[2];
676
						$skin_info->name = $skin_parse[count($skin_parse) - 1];
677
						break;
678
679
			}
680
			$skin_info->path = $val->directory->attrs->path;
681
			$skin_info->is_theme = $is_theme;
0 ignored issues
show
Bug introduced by
The variable $is_theme 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...
682
			$skins[$module_name] = $skin_info;
0 ignored issues
show
Bug introduced by
The variable $module_name 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...
683
684
			if($is_theme)
685
			{
686 View Code Duplication
				if(!$GLOBALS['__ThemeModuleSkin__'][$module_name])
687
				{
688
					$GLOBALS['__ThemeModuleSkin__'][$module_name] = array();
689
					$GLOBALS['__ThemeModuleSkin__'][$module_name]['skins'] = array();
690
					$moduleInfo = $oModuleModel->getModuleInfoXml($module_name);
691
					$GLOBALS['__ThemeModuleSkin__'][$module_name]['title'] = $moduleInfo->title;
692
				}
693
				$GLOBALS['__ThemeModuleSkin__'][$module_name]['skins'][$skin_info->name] = $oModuleModel->loadSkinInfo($skin_info->path, '', '');
694
			}
695
		}
696
		$theme_info->skin_infos = $skins;
697
698
		$GLOBALS['__ThemeInfo__'][$theme_name] = $theme_info;
699
		return $theme_info;
700
	}
701
702
	/**
703
	 * Return theme module skin list
704
	 * @return array
705
	 */
706
	function getModulesSkinList()
707
	{
708
		if($GLOBALS['__ThemeModuleSkin__']['__IS_PARSE__'])
709
		{
710
			return $GLOBALS['__ThemeModuleSkin__'];
711
		}
712
		$searched_list = FileHandler::readDir('./modules');
713
		sort($searched_list);
714
715
		$searched_count = count($searched_list);
716
		if(!$searched_count)
717
		{
718
			return;
719
		}
720
721
		$exceptionModule = array('editor', 'poll', 'homepage', 'textyle');
722
723
		$oModuleModel = getModel('module');
724
		foreach($searched_list as $val)
725
		{
726
			$skin_list = $oModuleModel->getSkins(_XE_PATH_ . 'modules/' . $val);
727
728
			if(is_array($skin_list) && count($skin_list) > 0 && !in_array($val, $exceptionModule))
729
			{
730 View Code Duplication
				if(!$GLOBALS['__ThemeModuleSkin__'][$val])
731
				{
732
					$GLOBALS['__ThemeModuleSkin__'][$val] = array();
733
					$moduleInfo = $oModuleModel->getModuleInfoXml($val);
734
					$GLOBALS['__ThemeModuleSkin__'][$val]['title'] = $moduleInfo->title;
735
					$GLOBALS['__ThemeModuleSkin__'][$val]['skins'] = array();
736
				}
737
				$GLOBALS['__ThemeModuleSkin__'][$val]['skins'] = array_merge($GLOBALS['__ThemeModuleSkin__'][$val]['skins'], $skin_list);
738
			}
739
		}
740
		$GLOBALS['__ThemeModuleSkin__']['__IS_PARSE__'] = TRUE;
741
742
		return $GLOBALS['__ThemeModuleSkin__'];
743
	}
744
745
	/**
746
	 * Return admin menu language
747
	 * @return array
748
	 */
749
	function getAdminMenuLang()
750
	{
751
		static $lang = false;
752
753
		$oCacheHandler = CacheHandler::getInstance('object', null, true);
754
		if($lang === false && $oCacheHandler->isSupport())
755
		{
756
			$cache_key = 'admin_menu_langs:' . Context::getLangType();
757
			$lang = $oCacheHandler->get($cache_key);
758
759
			if($lang === false)
760
			{
761
				$lang = array();
762
				$oModuleModel = getModel('module');
763
				$installed_module_list = $oModuleModel->getModulesXmlInfo();
764
765 View Code Duplication
				foreach($installed_module_list as $key => $value)
766
				{
767
					$moduleActionInfo = $oModuleModel->getModuleActionXml($value->module);
768
					if(is_object($moduleActionInfo->menu))
769
					{
770
						foreach($moduleActionInfo->menu as $key2 => $value2)
771
						{
772
							$lang[$key2] = $value2->title;
773
						}
774
					}
775
				}
776
777
				$oCacheHandler->put($cache_key, $lang);
778
			}
779
		}
780
781
		return $lang;
782
	}
783
784
	/**
785
	 * Get admin favorite list
786
	 * @param int $siteSrl if default site, siteSrl is zero
787
	 * @param bool $isGetModuleInfo
788
	 * @return object
789
	 */
790
	function getFavoriteList($siteSrl = 0, $isGetModuleInfo = FALSE)
791
	{
792
		$args = new stdClass();
793
		$args->site_srl = $siteSrl;
794
		$output = executeQueryArray('admin.getFavoriteList', $args);
795
		if(!$output->toBool())
796
		{
797
			return $output;
798
		}
799
		if(!$output->data)
800
		{
801
			return new BaseObject();
802
		}
803
804
		if($isGetModuleInfo && is_array($output->data))
805
		{
806
			$oModuleModel = getModel('module');
807
			foreach($output->data AS $key => $value)
808
			{
809
				$moduleInfo = $oModuleModel->getModuleInfoXml($value->module);
810
				$output->data[$key]->admin_index_act = $moduleInfo->admin_index_act;
811
				$output->data[$key]->title = $moduleInfo->title;
812
			}
813
		}
814
815
		$returnObject = new BaseObject();
816
		$returnObject->add('favoriteList', $output->data);
817
		return $returnObject;
818
	}
819
820
	/**
821
	 * Check available insert favorite
822
	 * @param int $siteSrl if default site, siteSrl is zero
823
	 * @param string $module
824
	 * @return object
825
	 */
826
	function isExistsFavorite($siteSrl, $module)
827
	{
828
		$args = new stdClass();
829
		$args->site_srl = $siteSrl;
830
		$args->module = $module;
831
		$output = executeQuery('admin.getFavorite', $args);
832
		if(!$output->toBool())
833
		{
834
			return $output;
835
		}
836
837
		$returnObject = new BaseObject();
838
		if($output->data)
839
		{
840
			$returnObject->add('result', TRUE);
841
			$returnObject->add('favoriteSrl', $output->data->admin_favorite_srl);
842
		}
843
		else
844
		{
845
			$returnObject->add('result', FALSE);
846
		}
847
848
		return $returnObject;
849
	}
850
851
	/**
852
	 * Return site list
853
	 * @return void
854
	 */
855
	function getSiteAllList()
856
	{
857
		if(Context::get('domain'))
858
		{
859
			$domain = Context::get('domain');
860
		}
861
		$siteList = $this->getAllSitesThatHaveModules($domain);
0 ignored issues
show
Bug introduced by
The variable $domain 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...
862
		$this->add('site_list', $siteList);
863
	}
864
865
	/**
866
	 * Returns a list of all sites that contain modules
867
	 * For each site domain and site_srl are retrieved
868
	 *
869
	 * @return array
870
	 */
871
	function getAllSitesThatHaveModules($domain = NULL)
872
	{
873
		$args = new stdClass();
874
		if($domain)
875
		{
876
			$args->domain = $domain;
877
		}
878
		$columnList = array('domain', 'site_srl');
879
880
		$siteList = array();
881
		$output = executeQueryArray('admin.getSiteAllList', $args, $columnList);
882
		if($output->toBool())
883
		{
884
			$siteList = $output->data;
885
		}
886
887
		$oModuleModel = getModel('module');
888
		foreach($siteList as $key => $value)
889
		{
890
			$args->site_srl = $value->site_srl;
891
			$list = $oModuleModel->getModuleSrlList($args);
892
893
			if(!is_array($list))
894
			{
895
				$list = array($list);
896
			}
897
898
			foreach($list as $k => $v)
899
			{
900
				if(!is_dir(_XE_PATH_ . 'modules/' . $v->module))
901
				{
902
					unset($list[$k]);
903
				}
904
			}
905
906
			if(!count($list))
907
			{
908
				unset($siteList[$key]);
909
			}
910
		}
911
		return $siteList;
912
	}
913
914
	/**
915
	 * Return site count
916
	 * @param string $date
917
	 * @return int
918
	 */
919 View Code Duplication
	function getSiteCountByDate($date = '')
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...
920
	{
921
		$args = new stdClass();
922
923
		if($date)
924
		{
925
			$args->regDate = date('Ymd', strtotime($date));
926
		}
927
928
		$output = executeQuery('admin.getSiteCountByDate', $args);
929
		if(!$output->toBool())
930
		{
931
			return 0;
932
		}
933
934
		return $output->data->count;
935
	}
936
937
	function getFaviconUrl($default = true)
938
	{
939
		return $this->iconUrlCheck('favicon.ico', 'faviconSample.png', $default);
940
	}
941
942
	function getMobileIconUrl($default = true)
943
	{
944
		return $this->iconUrlCheck('mobicon.png', 'mobiconSample.png', $default);
945
	}
946
947
	function iconUrlCheck($iconname, $default_icon_name, $default)
948
	{
949
		$site_info = Context::get('site_module_info');
950
		$virtual_site = '';
951
		if($site_info->site_srl) 
952
		{
953
			$virtual_site = $site_info->site_srl . '/';
954
		}
955
956
		$file_exsit = FileHandler::readFile(_XE_PATH_ . 'files/attach/xeicon/' . $virtual_site . $iconname);
957
		if(!$file_exsit && $default === true)
958
        {
959
            $icon_url = './modules/admin/tpl/img/' . $default_icon_name;
960
        }
961
        elseif($file_exsit)
962
		{
963
			$default_url = Context::getDefaultUrl();
964 View Code Duplication
			if($default_url && substr_compare($default_url, '/', -1) === 0) $default_url = substr($default_url, 0, -1);
965
			$icon_url = $default_url . '/files/attach/xeicon/' . $virtual_site . $iconname;
966
		}
967
		return $icon_url;
0 ignored issues
show
Bug introduced by
The variable $icon_url 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...
968
	}
969
970
}
971
/* End of file admin.admin.model.php */
972
/* Location: ./modules/admin/admin.admin.model.php */
973