9d068cd6 |
1 | <?php //$Id$ |
2f13f94c |
2 | |
2f13f94c |
3 | /** |
9d068cd6 |
4 | * Functions to support installation process |
2f13f94c |
5 | */ |
2f13f94c |
6 | |
11e7b506 |
7 | /** |
8 | *Tries to detect the right www root setting. |
9 | * |
10 | * @return string detected www root |
11 | */ |
12 | function install_guess_wwwroot() { |
13 | $wwwroot = ''; |
14 | if (empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] == 'off') { |
15 | $wwwroot .= 'http://'; |
16 | } else { |
17 | $wwwroot .= 'https://'; |
18 | } |
19 | $hostport = explode(':', $_SERVER['HTTP_HOST']); |
20 | $wwwroot .= reset($hostport); |
21 | if ($_SERVER['SERVER_PORT'] != 80 and $_SERVER['SERVER_PORT'] != '443') { |
22 | $wwwroot .= ':'.$_SERVER['SERVER_PORT']; |
23 | } |
24 | $wwwroot .= $_SERVER['SCRIPT_NAME']; |
25 | |
26 | list($wwwroot, $xtra) = explode('/install.php', $wwwroot); |
27 | |
28 | return $wwwroot; |
29 | } |
30 | |
2f13f94c |
31 | /** |
9d068cd6 |
32 | * This function returns a list of languages and their full names. The |
33 | * list of available languages is fetched from install/lang/xx/installer.php |
34 | * and it's used exclusively by the installation process |
2f13f94c |
35 | * @return array An associative array with contents in the form of LanguageCode => LanguageName |
36 | */ |
37 | function get_installer_list_of_languages() { |
38 | |
39 | global $CFG; |
40 | |
41 | $languages = array(); |
42 | |
9d068cd6 |
43 | /// Get raw list of lang directories |
2f13f94c |
44 | $langdirs = get_list_of_plugins('install/lang'); |
45 | asort($langdirs); |
9d068cd6 |
46 | /// Get some info from each lang |
2f13f94c |
47 | foreach ($langdirs as $lang) { |
48 | if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) { |
49 | include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php'); |
50 | if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show |
51 | $shortlang = substr($lang, 0, -5); |
52 | } else { |
53 | $shortlang = $lang; |
54 | } |
9d068cd6 |
55 | /* if ($lang == 'en') { //Explain this is non-utf8 en |
56 | $shortlang = 'non-utf8 en'; |
57 | }*/ |
2f13f94c |
58 | if (!empty($string['thislanguage'])) { |
9d068cd6 |
59 | $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')'; |
2f13f94c |
60 | } |
61 | unset($string); |
62 | } |
63 | } |
9d068cd6 |
64 | /// Return array |
2f13f94c |
65 | return $languages; |
66 | } |
2f13f94c |
67 | |
2f13f94c |
68 | /** |
69 | * Get memeory limit |
70 | * |
71 | * @return int |
72 | */ |
73 | function get_memory_limit() { |
74 | if ($limit = ini_get('memory_limit')) { |
75 | return $limit; |
76 | } else { |
77 | return get_cfg_var('memory_limit'); |
78 | } |
79 | } |
80 | |
2f13f94c |
81 | /** |
82 | * Check memory limit |
83 | * |
84 | * @return boolean |
85 | */ |
86 | function check_memory_limit() { |
87 | |
88 | /// if limit is already 40 or more then we don't care if we can change it or not |
89 | if ((int)str_replace('M', '', get_memory_limit()) >= 40) { |
90 | return true; |
91 | } |
92 | |
93 | /// Otherwise, see if we can change it ourselves |
94 | @ini_set('memory_limit', '40M'); |
95 | return ((int)str_replace('M', '', get_memory_limit()) >= 40); |
96 | } |
97 | |
2f13f94c |
98 | /** |
99 | * Check php version |
100 | * |
101 | * @return boolean |
102 | */ |
103 | function inst_check_php_version() { |
a4970985 |
104 | return check_php_version("5.2.4"); |
2f13f94c |
105 | } |