1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 17:59:21 +02:00

Clean up PHP tests and reuse them in init.php

Also move the config-related functions out of debug.lib.php (why they
were there in the first place is anyone's guess.)
This commit is contained in:
Paul Arthur 2013-02-03 11:15:03 -05:00
parent c8cd1da88f
commit dd70337451
4 changed files with 89 additions and 122 deletions

View file

@ -20,43 +20,49 @@
*
*/
/**
* check_php_ver
* checks the php version and makes
* sure that it's good enough
*/
function check_php_ver($level=0) {
function check_php() {
if (
check_php_version() &&
check_php_hash() &&
check_php_hash_algo() &&
check_php_pdo() &&
check_php_session() &&
check_php_json() &&
check_php_safemode()
) {
return true;
}
return false;
}
function check_php_version() {
if (floatval(phpversion()) < 5.3) {
return false;
}
return true;
}
/**
* check_php_session
* checks to make sure the needed functions
* for sessions exist
*/
function check_php_hash() {
return function_exists('hash_algos');
}
function check_php_hash_algo() {
return function_exists('hash_algos') ? in_array('sha256', hash_algos()) : false;
}
function check_php_json() {
return function_exists('json_encode');
}
function check_php_session() {
return function_exists('session_set_save_handler');
}
if (!function_exists('session_set_save_handler')) {
return false;
}
return true;
} // check_php_session
/**
* check_pdo
*
* Checks to make sure that PDO is available.
*/
function check_pdo() {
function check_php_pdo() {
if (class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
return true;
}
return false;
}
@ -135,7 +141,7 @@ function check_php_timelimit() {
* check_safe_mode
* Checks to make sure we aren't in safe mode
*/
function check_safemode() {
function check_php_safemode() {
if (ini_get('safe_mode')) {
return false;
}
@ -182,34 +188,6 @@ function check_override_exec_time() {
return true;
}
/**
* check_gettext
* This checks to see if you've got gettext installed
*/
function check_gettext() {
if (!function_exists('gettext')) {
return false;
}
return true;
} // check_gettext
/**
* check_mbstring
* This checks for mbstring support
*/
function check_mbstring() {
if (!function_exists('mb_check_encoding')) {
return false;
}
return true;
} // check_mbstring
/**
* check_config_writable
* This checks whether we can write the config file
@ -221,63 +199,6 @@ function check_config_writable() {
|| (!file_exists(Config::get('prefix') . '/config/ampache.cfg.php') && is_writeable(Config::get('prefix') . '/config/')));
}
/**
* generate_config
* This takes an array of results and re-generates the config file
* this is used by the installer and by the admin/system page
*/
function generate_config($current) {
/* Start building the new config file */
$distfile = Config::get('prefix') . '/config/ampache.cfg.php.dist';
$handle = fopen($distfile,'r');
$dist = fread($handle,filesize($distfile));
fclose($handle);
$data = explode("\n",$dist);
/* Run throught the lines and set our settings */
foreach ($data as $line) {
/* Attempt to pull out Key */
if (preg_match("/^;?([\w\d]+)\s+=\s+[\"]{1}(.*?)[\"]{1}$/",$line,$matches)
|| preg_match("/^;?([\w\d]+)\s+=\s+[\']{1}(.*?)[\']{1}$/", $line, $matches)
|| preg_match("/^;?([\w\d]+)\s+=\s+[\'\"]{0}(.*)[\'\"]{0}$/",$line,$matches)) {
$key = $matches[1];
$value = $matches[2];
/* Put in the current value */
if ($key == 'config_version') {
$line = $key . ' = ' . escape_ini($value);
}
elseif (isset($current[$key])) {
$line = $key . ' = "' . escape_ini($current[$key]) . '"';
unset($current[$key]);
} // if set
} // if key
$final .= $line . "\n";
} // end foreach line
return $final;
} // generate_config
/**
* escape_ini
* Escape a value used for inserting into an ini file.
* Won't quote ', like addslashes does.
*/
function escape_ini($str) {
return str_replace('"', '\"', $str);
}
/**
* debug_result
*