$extension
extension",
$result ? 0 : 2,
$result ?
"Extension installed and loaded" :
'Please install or enable ' . $extension . '
extension'
);
}
}
displayCategory("File / directory permission checks");
// file / directory writable checks
{
// path => true if file, false if directory
$paths = array(
__CONFIG_FILE => true,
__INSTALLER_LOCK_FILE => true,
__CACHE_DIR => false,
__CACHE_DIR . "/templates" => false,
__CACHE_DIR . "/servericons" => false,
);
foreach ($paths as $path => $isFile) {
$exists = file_exists($path);
// If file / directory doesnt exists try to create it and update the variable
if(!$exists)
$exists = $isFile ? @touch($path) : @mkdir($path);
$writable = is_writable($path);
$basename = basename($path);
// we are using a custom method instead of realpath,
// because it does not work with non-existing files
$realpath = resolveFilename($path);
$msg = "Yes";
if(!$writable)
$msg = "Please make $realpath
writable";
if(!$exists)
$msg = ($isFile ? "File" : "Directory") . " $realpath
does not exists, please create it";
$success = $exists && $writable;
if (!$success && !defined("FILE_PERM_ERROR")) {
define("FILE_PERM_ERROR", true);
}
showCheckResult("Is $basename
writable?", $success ? 0 : 2, $msg);
}
}
displayCategory("Miscellaneous");
// cache test
{
$result = false;
try {
require_once __PRIVATE_DIR . "/vendor/autoload.php";
$cache = new Wruczek\PhpFileCache\PhpFileCache();
$teststring = "cachetest123";
$cache->store("installertest", $teststring, 3);
$result = $cache->retrieve("installertest") === $teststring;
$cache->clearCache();
} catch (Exception $e) {}
showCheckResult(
"Cache save and read test",
$result ? 0 : 2,
$result ?
"Save and read success" :
"Something went wrong! Please make sure that private/cache
directory is writable"
);
}
// template test
{
if($result) {
if(extension_loaded("mbstring")) {
$result = false;
try {
$latte = new Latte\Engine();
$latte->setTempDirectory(__CACHE_DIR);
$latte->setLoader(new Latte\Loaders\StringLoader());
$render = @$latte->renderToString('Hello, {$test|upper}!', array("test" => "Wruczek"));
$result = $render === "Hello, WRUCZEK!";
} catch (Exception $e) {}
showCheckResult(
"Template render and cache test",
$result ? 0 : 2,
$result ?
"Render and cache success" :
"Something went wrong! Please make sure that private/cache
directory is writable"
);
} else {
showCheckResult("Template render and cache test", 2, "mbstring
extension not found, cannot start the test");
}
} else {
showCheckResult("Template render and cache test", 2, "private/cache
directory is not writable, cannot start the test");
}
}
}
// Utils
function showCheckResult($name, $state, $resulttext) {
if($state === 0) {
$attr = "fa-check-circle color-success";
} else if($state === 1) {
$attr = "fa-minus-circle color-warning";
} else {
$attr = "fa-times-circle color-danger";
if(!defined("CANNOT_INSTALL")) {
define("CANNOT_INSTALL", true);
}
}
?>