Completed
Pull Request — develop (#526)
by
unknown
08:39
created

functions.php ➔ getLangs()   C

Complexity

Conditions 8
Paths 12

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 19
nc 12
nop 1
dl 0
loc 29
rs 5.3846
c 0
b 0
f 0
1
<?php
2
function install_sessionCheck()
3
{
4
	global $_lang;
5
	
6
	// session loop-back tester
7
	if(!isset($_GET['action']) || $_GET['action']!=='mode')
8
	{
9
		if(!isset($_SESSION['test']) || $_SESSION['test']!=1)
10
		{
11
			echo '
12
<html>
13
<head>
14
	<title>Install Problem</title>
15
	<style type="text/css">
16
		*{margin:0;padding:0}
17
		body{margin:150px;background:#eee;}
18
		.install{padding:10px;border:3px solid #ffc565;background:#ffddb4;margin:0 auto;text-align:center;}
19
		p{ margin:20px 0; }
20
		a{margin-top:30px;padding:5px;}
21
	</style>
22
</head>
23
<body>
24
	<div class="install">
25
		<p>' . $_lang["session_problem"] . '</p>
26
		<p><a href="./">' .$_lang["session_problem_try_again"] . '</a></p>
27
	</div>
28
</body>
29
</html>';
30
		exit;
31
		}
32
	}
33
}
34
35
function parse($src,$ph,$left='[+',$right='+]')
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
36
{
37
	foreach($ph as $k=>$v)
38
	{
39
		$k = $left . $k . $right;
40
		$src = str_replace($k,$v,$src);
41
	}
42
	return $src;
43
}
44
45
function ph()
46
{
47
	global $_lang,$moduleName,$moduleVersion,$modx_textdir,$modx_release_date;
48
49
	if(isset($_SESSION['installmode'])) $installmode = $_SESSION['installmode'];
50
	else                                $installmode = get_installmode();
51
52
	$ph['pagetitle']     = $_lang['modx_install'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$ph was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ph = 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...
53
	$ph['textdir']       = $modx_textdir ? ' id="rtl"':'';
54
	$ph['help_link']     = $installmode == 0 ? $_lang['help_link_new'] : $_lang['help_link_upd'];
55
	$ph['version']       = $moduleVersion;
56
	$ph['release_date']  = ($modx_textdir ? '&rlm;':'') . $modx_release_date;
57
	$ph['footer1']       = $_lang['modx_footer1'];
58
	$ph['footer2']       = $_lang['modx_footer2'];
59
	$ph['current_year']  = date('Y');
60
	return $ph;
61
}
62
63
function get_installmode()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
64
{
65
	global $base_path,$database_server, $database_user, $database_password, $dbase, $table_prefix;
66
	
67
	$conf_path = "{$base_path}manager/includes/config.inc.php";
68
	if (!is_file($conf_path)) $installmode = 0;
69
	elseif(isset($_POST['installmode'])) $installmode = $_POST['installmode'];
70
	else
71
	{
72
		include_once("{$base_path}manager/includes/config.inc.php");
73
		
74
		if(!isset($dbase) || empty($dbase)) $installmode = 0;
75
		else
76
		{
77
			$conn = mysqli_connect($database_server, $database_user, $database_password);
78
			if($conn)
79
			{
80
				$_SESSION['database_server']   = $database_server;
81
				$_SESSION['database_user']     = $database_user;
82
				$_SESSION['database_password'] = $database_password;
83
				
84
				$dbase = trim($dbase, '`');
85
				$rs = mysqli_select_db($conn, $dbase);
86
			}
87
			else $rs = false;
88
			
89
			if($rs)
90
			{
91
				$_SESSION['dbase']                      = $dbase;
92
				$_SESSION['table_prefix']               = $table_prefix;
93
				$_SESSION['database_collation']         = 'utf8_general_ci';
94
				$_SESSION['database_connection_method'] = 'SET CHARACTER SET';
95
				
96
				$tbl_system_settings = "`{$dbase}`.`{$table_prefix}system_settings`";
97
				$rs = mysqli_query($conn, "SELECT setting_value FROM {$tbl_system_settings} WHERE setting_name='settings_version'");
98
				if($rs)
99
				{
100
					$row = mysqli_fetch_assoc($rs);
101
					$settings_version = $row['setting_value'];
102
				}
103
				else $settings_version = '';
104
				
105
				if (empty($settings_version)) $installmode = 0;
106
				else                          $installmode = 1;
107
			}
108
			else $installmode = 1;
109
		}
110
	}
111
	return $installmode;
112
}
113
114
function getLangs($install_language)
115
{
116
    if ($install_language !== "english" && is_file(sprintf("../%s/includes/lang/%s.inc.php", MGR_DIR, $install_language))) {
117
        $manager_language = $install_language;
118
    } else {
119
        $manager_language = "english";
120
    }
121
122
    $langs = array();
123
    if ($handle = opendir("../" . MGR_DIR . "/includes/lang")) {
124
        while (false !== ($file = readdir($handle))) {
125
            if (strpos($file, '.inc.') !== false) {
126
                $langs[] = $file;
127
            }
128
        }
129
        closedir($handle);
130
    }
131
    sort($langs);
132
133
    $_ = array();
134
   foreach ($langs as $language) {
135
        $abrv_language = explode('.', $language);
136
        $selected = (strtolower($abrv_language[0]) == strtolower($manager_language)) ? ' selected' : '';
137
        $_[] = sprintf('<option value="%s" %s>%s</option>', $abrv_language[0], $selected,
138
            ucwords($abrv_language[0]));
139
    }
140
141
    return implode("\n", $_);
142
}