Last active
October 7, 2015 12:57
-
-
Save ehough/3168023 to your computer and use it in GitHub Desktop.
Requirements check for TubePress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Copyright (c) 2012 - 2015 Eric Hough (eric@tubepress.com) | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining | |
* a copy of this software and associated documentation files (the "Software"), | |
* to deal in the Software without restriction, including without limitation | |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
* and/or sell copies of the Software, and to permit persons to whom the | |
* Software is furnished to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in | |
* all copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
* THE SOFTWARE. | |
*/ | |
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | |
"http://www.w3.org/TR/html4/strict.dtd"> | |
<html> | |
<head> | |
<title>TubePress Requirements Check</title> | |
</head> | |
<body> | |
<p>Check TubePress requirements...</p> | |
<?php | |
@ini_set('display_errors', 1); | |
function msg($color, $text) | |
{ | |
global $detail; | |
echo "<span style=\"color: $color\">$text</span>"; | |
if ($detail !== null) { | |
echo " <span style=\"font-size:smaller; color:gray\">($detail)</span>"; | |
} | |
echo "<br /><br />"; | |
} | |
function pass() | |
{ | |
global $passCount; | |
$passCount++; | |
msg('green', 'OK'); | |
} | |
function fail() | |
{ | |
global $failureCount; | |
$failureCount++; | |
msg('red', 'FAIL'); | |
} | |
function warn() | |
{ | |
global $warningCount; | |
$warningCount++; | |
msg('orange', 'WARN'); | |
} | |
function findExtension($name) | |
{ | |
$extensions = get_loaded_extensions(); | |
foreach ($extensions as $extension) { | |
if (strcasecmp($extension, $name) === 0) { | |
return $extension; | |
} | |
} | |
return null; | |
} | |
function gatherExtensionDetails($name) | |
{ | |
$extension = findExtension($name); | |
if ($extension === null) { | |
return false; | |
} | |
return array($extension, phpversion($extension)); | |
} | |
function passExtensionDontCareVersion($results) | |
{ | |
global $detail; | |
if (isset($results[1]) && $results[1] !== false) { | |
$detail = 'detected ' . $results[0] . ' extension version ' . $results[1]; | |
} else { | |
$detail = 'detected ' . $results[0] . ' extension'; | |
} | |
pass(); | |
} | |
function passExtensionDoCareVersion($results) | |
{ | |
global $detail; | |
if (isset($results[1]) && $results[1] !== false) { | |
$detail = 'detected ' . $results[0] . ' extension version ' . $results[1]; | |
pass(); | |
} else { | |
$detail = $results[0] . ' detected, but unable to determine version - please manually verify the version below.'; | |
warn(); | |
} | |
} | |
function phpVersionCheck() | |
{ | |
global $detail; | |
$detail = 'detected PHP version ' . PHP_VERSION; | |
if (version_compare(PHP_VERSION, '5.2.9') >= 0) { | |
pass(); | |
return true; | |
} else { | |
fail(); | |
return false; | |
} | |
} | |
function mbstringExtensionCheck() | |
{ | |
$results = gatherExtensionDetails('mbstring'); | |
if ($results === false) { | |
global $detail; | |
$detail = 'mbstring extension is missing, but this extension is only required if you intend to run TubePress Pro in a standalone PHP environment'; | |
warn(); | |
return true; | |
} | |
passExtensionDontCareVersion($results); | |
return true; | |
} | |
function apcExtensionCheck() | |
{ | |
$apcResults = gatherExtensionDetails('apc'); | |
$apcuResults = gatherExtensionDetails('apcu'); | |
if ($apcResults !== false) { | |
global $detail; | |
$detail = 'APC extension is loaded. This extension is obsolete and not compatible with TubePress.'; | |
if ($apcuResults !== false) { | |
warn(); | |
return true; | |
} | |
fail(); | |
return false; | |
} | |
return true; | |
} | |
$checks = array( | |
array('phpVersion', 'PHP version'), | |
array('mbstringExtension', 'mbstring extension'), | |
array('apcExtension', 'APC extension'), | |
); | |
global $detail, $failureCount, $warningCount, $passCount; | |
$checksIndex = 1; | |
$checksCount = count($checks); | |
$detail = null; | |
$failureCount = 0; | |
$warningCount = 0; | |
$passCount = 0; | |
foreach ($checks as $check) { | |
$detail = null; | |
echo "\n<i>Check ($checksIndex / $checksCount):</i> " . $check[1] . '... '; | |
$checksIndex++; | |
if (call_user_func($check[0] . 'Check') === false) { | |
break; | |
} | |
} | |
if ($failureCount > 0) { | |
echo "<span style=\"font-size: larger; color: red\">This server does not meet the requirements for TubePress</span>"; | |
} else { | |
if ($warningCount > 0) { | |
echo "<span style=\"font-size: larger; color: orange\">Checks passed, but there were warnings. This server <i>might</i> meet the requirements for TubePress</span>"; | |
} else { | |
echo "<span style=\"font-size: larger; color: green\">All checks passed! This server meets the requirements for TubePress</span>"; | |
} | |
} | |
echo "<br /><br />"; | |
phpinfo(); | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment