MDL-17779
[moodle.git] / lib / installlib.php
CommitLineData
9d068cd6 1<?php //$Id$
2f13f94c 2
2f13f94c 3/**
9d068cd6 4 * Functions to support installation process
2f13f94c 5 */
2f13f94c 6
7/**
9d068cd6 8 * This function returns a list of languages and their full names. The
9 * list of available languages is fetched from install/lang/xx/installer.php
10 * and it's used exclusively by the installation process
2f13f94c 11 * @return array An associative array with contents in the form of LanguageCode => LanguageName
12 */
13function get_installer_list_of_languages() {
14
15 global $CFG;
16
17 $languages = array();
18
9d068cd6 19/// Get raw list of lang directories
2f13f94c 20 $langdirs = get_list_of_plugins('install/lang');
21 asort($langdirs);
9d068cd6 22/// Get some info from each lang
2f13f94c 23 foreach ($langdirs as $lang) {
24 if (file_exists($CFG->dirroot .'/install/lang/'. $lang .'/installer.php')) {
25 include($CFG->dirroot .'/install/lang/'. $lang .'/installer.php');
26 if (substr($lang, -5) == '_utf8') { //Remove the _utf8 suffix from the lang to show
27 $shortlang = substr($lang, 0, -5);
28 } else {
29 $shortlang = $lang;
30 }
9d068cd6 31/* if ($lang == 'en') { //Explain this is non-utf8 en
32 $shortlang = 'non-utf8 en';
33 }*/
2f13f94c 34 if (!empty($string['thislanguage'])) {
9d068cd6 35 $languages[$lang] = $string['thislanguage'] .' ('. $shortlang .')';
2f13f94c 36 }
37 unset($string);
38 }
39 }
9d068cd6 40/// Return array
2f13f94c 41 return $languages;
42}
2f13f94c 43
2f13f94c 44/**
45 * Get memeory limit
46 *
47 * @return int
48 */
49function get_memory_limit() {
50 if ($limit = ini_get('memory_limit')) {
51 return $limit;
52 } else {
53 return get_cfg_var('memory_limit');
54 }
55}
56
2f13f94c 57/**
58 * Check memory limit
59 *
60 * @return boolean
61 */
62function check_memory_limit() {
63
64 /// if limit is already 40 or more then we don't care if we can change it or not
65 if ((int)str_replace('M', '', get_memory_limit()) >= 40) {
66 return true;
67 }
68
69 /// Otherwise, see if we can change it ourselves
70 @ini_set('memory_limit', '40M');
71 return ((int)str_replace('M', '', get_memory_limit()) >= 40);
72}
73
2f13f94c 74/**
75 * Check php version
76 *
77 * @return boolean
78 */
79function inst_check_php_version() {
a4970985 80 return check_php_version("5.2.4");
2f13f94c 81}