class/utility.php
<?php
/**
* Class MyalbumUtil
*/
class ApcalUtility extends XoopsObject
{
/**
* Function responsible for checking if a directory exists, we can also write in and create an index.html file
*
* @param string $folder The full path of the directory to check
*
* @return void
*/
public static function createFolder($folder)
{
// try {
// if (!mkdir($folder) && !is_dir($folder)) {
// throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
// } else {
// file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
// }
// }
// catch (Exception $e) {
// echo 'Caught exception: ', $e->getMessage(), "\n", '<br/>';
// }
try {
if (!file_exists($folder)) {
if (!mkdir($folder) && !is_dir($folder)) {
throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder));
} else {
file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
}
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n", '<br/>';
}
}
/**
* @param $file
* @param $folder
* @return bool
*/
public static function copyFile($file, $folder)
{
return copy($file, $folder);
// try {
// if (!is_dir($folder)) {
// throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder));
// } else {
// return copy($file, $folder);
// }
// } catch (Exception $e) {
// echo 'Caught exception: ', $e->getMessage(), "\n", "<br/>";
// }
// return false;
}
/**
* @param $src
* @param $dst
*/
public static function recurseCopy($src, $dst)
{
$dir = opendir($src);
// @mkdir($dst);
while (false !== ($file = readdir($dir))) {
if (($file !== '.') && ($file !== '..')) {
if (is_dir($src . '/' . $file)) {
self::recurseCopy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
}
/**
*
* Verifies XOOPS version meets minimum requirements for this module
* @static
* @param XoopsModule $module
*
* @return bool true if meets requirements, false if not
*/
public static function checkVerXoops(XoopsModule $module)
{
xoops_loadLanguage('admin', $module->dirname());
// check for minimum PHP version
$success = true;
$verNum = PHP_VERSION;
$reqVer = $module->getInfo('min_php');
if ((false !== $reqVer) && ('' !== $reqVer)) {
if (version_compare($verNum, (string)$reqVer, '<')) {
$module->setErrors(sprintf(_AM_XOOPSFAQ_ERROR_BAD_PHP, $reqVer, $verNum));
$success = false;
}
}
return $success;
}
/**
*
* Verifies PHP version meets minimum requirements for this module
* @static
* @param XoopsModule $module
*
* @return bool true if meets requirements, false if not
*/
public static function checkVerPhp(XoopsModule $module)
{
xoops_loadLanguage('admin', $module->dirname());
// check for minimum PHP version
$success = true;
$verNum = PHP_VERSION;
$reqVer = $module->getInfo('min_php');
if (false !== $reqVer && '' !== $reqVer) {
if (version_compare($verNum, $reqVer, '<')) {
$module->setErrors(sprintf(_AM_APCAL_ERROR_BAD_PHP, $reqVer, $verNum));
$success = false;
}
}
return $success;
}
}