summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2013-02-03 11:15:03 -0500
committerPaul Arthur <paul.arthur@flowerysong.com>2013-02-03 11:16:46 -0500
commitdd70337451390b260e95f998c8b79b9fefbf3b3a (patch)
tree4bfd3c3728841843badfadaca0920d4622c9f891
parentc8cd1da88fbf0df1a99463032d97ac42d221a774 (diff)
downloadampache-dd70337451390b260e95f998c8b79b9fefbf3b3a.tar.gz
ampache-dd70337451390b260e95f998c8b79b9fefbf3b3a.tar.bz2
ampache-dd70337451390b260e95f998c8b79b9fefbf3b3a.zip
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.)
-rw-r--r--lib/debug.lib.php141
-rw-r--r--lib/general.lib.php49
-rw-r--r--lib/init.php5
-rw-r--r--templates/show_test_table.inc.php12
4 files changed, 87 insertions, 120 deletions
diff --git a/lib/debug.lib.php b/lib/debug.lib.php
index 0c8f9ab9..7ce061f6 100644
--- a/lib/debug.lib.php
+++ b/lib/debug.lib.php
@@ -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_session() {
+function check_php_hash() {
+ return function_exists('hash_algos');
+}
- if (!function_exists('session_set_save_handler')) {
- return false;
- }
+function check_php_hash_algo() {
+ return function_exists('hash_algos') ? in_array('sha256', hash_algos()) : false;
+}
- return true;
+function check_php_json() {
+ return function_exists('json_encode');
+}
-} // check_php_session
+function check_php_session() {
+ return function_exists('session_set_save_handler');
+}
-/**
- * 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;
}
@@ -183,34 +189,6 @@ function check_override_exec_time() {
}
/**
- * 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
*/
@@ -222,63 +200,6 @@ function check_config_writable() {
}
/**
- * 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
*
* Convenience function to format the output.
diff --git a/lib/general.lib.php b/lib/general.lib.php
index 0e0f10c8..f42c3f87 100644
--- a/lib/general.lib.php
+++ b/lib/general.lib.php
@@ -261,4 +261,53 @@ function translate_pattern_code($code) {
} // translate_pattern_code
+/**
+ * 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);
+
+ foreach ($data as $line) {
+ 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]);
+ }
+ }
+
+ $final .= $line . "\n";
+ }
+
+ return $final;
+}
+
+/**
+ * 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);
+}
+
?>
diff --git a/lib/init.php b/lib/init.php
index 672f945e..8a1aaf78 100644
--- a/lib/init.php
+++ b/lib/init.php
@@ -53,10 +53,7 @@ else {
// Verify that a few important but commonly disabled PHP functions exist and
// that we're on a usable version
-if (!function_exists('json_encode') ||
- !function_exists('hash') ||
- (floatval(phpversion()) < 5.3) ||
- !class_exists('PDO')) {
+if (!check_php()) {
$link = $path . '/test.php';
}
diff --git a/templates/show_test_table.inc.php b/templates/show_test_table.inc.php
index eaef19d1..f48bc429 100644
--- a/templates/show_test_table.inc.php
+++ b/templates/show_test_table.inc.php
@@ -23,7 +23,7 @@
<tr>
<td valign="top"><?php echo T_('PHP version'); ?></td>
<td valign="top">
- <?php echo debug_result(check_php_ver()); ?>
+ <?php echo debug_result(check_php_version()); ?>
</td>
<td>
<?php echo T_('This tests whether you are running at least the minimum version of PHP required by Ampache.'); ?>
@@ -32,7 +32,7 @@
<tr>
<td valign="top"><?php echo T_('Hash extension'); ?></td>
<td valign="top">
- <?php echo debug_result(function_exists('hash_algos')); ?>
+ <?php echo debug_result(check_php_hash()); ?>
</td>
<td>
<?php echo T_('This tests whether you have the hash extension enabled. This extension is required by Ampache.'); ?>
@@ -41,7 +41,7 @@
<tr>
<td valign="top"><?php echo T_('SHA256 Hash'); ?></td>
<td valign="top">
- <?php echo debug_result(function_exists('hash_algos') ? in_array('sha256', hash_algos()) : false); ?>
+ <?php echo debug_result(check_php_hash_algo()); ?>
</td>
<td>
<?php echo T_('This tests whether the hash extension supports SHA256. This algorithm is required by Ampache.'); ?>
@@ -50,7 +50,7 @@
<tr>
<td valign="top"><?php echo T_('PHP PDO'); ?></td>
<td valign="top">
- <?php echo debug_result(check_pdo()); ?>
+ <?php echo debug_result(check_php_pdo()); ?>
</td>
<td>
<?php echo T_('This tests whether the PDO extension and the MySQL driver for PDO are installed. These are required by Ampache.'); ?>
@@ -77,7 +77,7 @@
<tr>
<td valign="top"><?php echo T_('JSON extension'); ?></td>
<td valign="top">
- <?php echo debug_result(function_exists('json_encode')); ?>
+ <?php echo debug_result(check_php_json()); ?>
</td>
<td>
<?php echo T_('This tests whether you have the JSON extension enabled. This extension is required by Ampache.'); ?>
@@ -86,7 +86,7 @@
<tr>
<td valign="top"><?php echo T_('PHP safe mode disabled'); ?></td>
<td valign="top">
- <?php echo debug_result(check_safemode()); ?>
+ <?php echo debug_result(check_php_safemode()); ?>
</td>
<td>
<?php echo T_('This test makes sure that PHP is not running in safe mode. Some features of Ampache will not work correctly in safe mode.'); ?>