'HostCMS.Старт v. 7.0.x', 'url' => 'http://www.hostcms.ru/download/7/HostCMS.Free_7.0.tar.gz' ); $versions[] = array( 'name' => 'HostCMS.Старт v. 6.9.9', 'url' => 'http://www.hostcms.ru/download/6/HostCMS.Free_6.9.tar.gz' ); ?>
* $array = array('fruit' => 'apple', 'baz' => 'quz');
* // Return 'apple'
* $value = Core_Array::get($array, 'fruit');
*
* // Return NULL
* $value = Core_Array::get($array, 'foo');
*
* // Return 'bar'
* $value = Core_Array::get($array, 'foo', 'bar');
*
* @param array $array array
* @param string $key key
* @param mixed $defaultValue default value
* @param mixed $filter filter, e.g. 'str'|'string'|'strval', 'int'|'integer'|'intval', 'float'|'floatval', 'bool'|'boolean'|'boolval', 'trim'
* @return mixed
*/
static public function get($array, $key, $defaultValue = NULL, $filter = NULL)
{
return self::_filter(
is_array($array) && array_key_exists($key, $array)
? $array[$key]
: $defaultValue,
$filter
);
}
/**
* Filter Value
* @param mixed $value
* @param mixed $filter filter, e.g. 'str'|'string'|'strval', 'int'|'integer'|'intval', 'float'|'floatval', 'bool'|'boolean'|'boolval', 'trim'
* @return mixed
*/
static protected function _filter($value, $filter)
{
if (!is_null($filter))
{
switch ($filter)
{
case 'str':
case 'string':
case 'strval':
$value = is_scalar($value)
? strval($value)
: '';
break;
case 'trim':
$value = is_scalar($value)
? trim($value)
: '';
break;
case 'int':
case 'integer':
case 'intval':
$value = is_scalar($value)
? intval($value)
: 0;
break;
case 'float':
case 'floatval':
$value = is_scalar($value)
? floatval($value)
: 0.0;
break;
case 'bool':
case 'boolean':
case 'boolval':
$value = is_scalar($value)
? (function_exists('boolval')
? boolval($value)
: (bool)$value
)
: FALSE;
break;
case 'array':
$value = is_array($value)
? $value
: array();
break;
default:
throw new Core_Exception('Core_Array wrong \'%name\' filter name', array('%name' => $filter));
}
}
return $value;
}
}
/**
* File helper
*
* @package HostCMS
* @version 7.x
* @author Hostmake LLC
* @copyright © 2005-2012 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
*/
class Core_File
{
/**
* Moves an uploaded file to a new location
* @param string $fileName Path to the source file.
* @param string $destinaftion The destination path.
* @param int $chmod The mode parameter consists of three octal number components specifying access, e.g. 0644
*/
static public function moveUploadedFile($fileName, $destination, $chmod = CHMOD_FILE)
{
if (is_uploaded_file($fileName))
{
if (move_uploaded_file($fileName, $destination))
{
chmod($destination, $chmod);
}
else
{
throw new Core_Exception("Move uploaded file '%fileName' error.",
array('%fileName' => Core_Exception::cutRootPath($fileName)));
}
}
else
{
throw new Core_Exception("The file '%fileName' is not uploaded file.",
array('%fileName' => Core_Exception::cutRootPath($fileName)));
}
}
/**
* Copies file
* @param string $source The source path.
* @param string $destination The destination path.
* @param int $chmod The mode parameter consists of three octal number components specifying access, e.g. 0644
* @return bool
*/
static public function copy($source, $destination, $chmod = CHMOD_FILE)
{
if (is_file($source))
{
// Create destination dir
self::mkdir(dirname($destination), CHMOD, TRUE);
if ($source != $destination)
{
if (copy($source, $destination))
{
chmod($destination, $chmod);
return TRUE;
}
else
{
throw new Core_Exception("Copy file '%source' error.",
array('%source' => Core_Exception::cutRootPath($source)));
}
}
return TRUE;
}
else
{
throw new Core_Exception("The file '%source' does not exist.",
array('%source' => Core_Exception::cutRootPath($source)));
}
}
/**
* Copies directory
* @param string $source The source directory.
* @param string $target The destination directory.
* @return bool
*/
static public function copyDir($source, $target)
{
$source = self::pathCorrection($source);
$target = self::pathCorrection($target);
if (is_dir($source) && !is_link($source))
{
if (!is_dir($target))
{
self::mkdir($target);
}
if ($dh = @opendir($source))
{
while (($file = @readdir($dh)) !== FALSE)
{
if ($file != '.' && $file!='..')
{
clearstatcache();
is_file($source . DIRECTORY_SEPARATOR . $file)
? self::copy($source . DIRECTORY_SEPARATOR . $file, $target . DIRECTORY_SEPARATOR . $file)
: self::copyDir($source . DIRECTORY_SEPARATOR . $file, $target . DIRECTORY_SEPARATOR . $file);
}
}
@closedir($dh);
}
else
{
throw new Core_Exception("Open dir '%source' error.",
array('%source' => Core_Exception::cutRootPath($source)));
}
}
else
{
return FALSE;
}
return TRUE;
}
/**
* Copy or move uploaded file
* @param string $source The source path.
* @param string $destination The destination path.
* @param int $chmod The mode parameter consists of three octal number components specifying access, e.g. 0644
* @see Core_File::moveUploadedFile()
* @see Core_File::copy()
*/
static public function upload($source, $destination, $chmod = CHMOD_FILE)
{
return is_uploaded_file($source)
? self::moveUploadedFile($source, $destination, $chmod)
: self::copy($source, $destination, $chmod);
}
/**
* Renames a file or directory
* @param string $oldname The old name.
* @param string $newname The new name.
*/
static public function rename($oldname, $newname)
{
if (is_file($oldname))
{
if (!rename($oldname, $newname))
{
throw new Core_Exception("Rename file '%oldname' error.",
array('%oldname' => Core_Exception::cutRootPath($oldname)));
}
}
else
{
throw new Core_Exception("The file '%oldname' does not exist.",
array('%oldname' => Core_Exception::cutRootPath($oldname)));
}
}
/**
* Deletes a file
* @param string $fileName Path to the file.
*/
static public function delete($fileName)
{
if (is_file($fileName))
{
if (!unlink($fileName))
{
throw new Core_Exception("Delete file '%fileName' error.",
array('%fileName' => Core_Exception::cutRootPath($fileName)));
}
}
else
{
throw new Core_Exception("The file '%fileName' does not exist.",
array('%fileName' => Core_Exception::cutRootPath($fileName)));
}
}
/**
* Deletes a directory with files and subdirectories
* @param string $dirname Path to the directory.
*/
static public function deleteDir($dirname)
{
$dirname = realpath(self::pathCorrection($dirname) . DIRECTORY_SEPARATOR);
// Forbidden to delete home directory
if (strtolower($dirname) == strtolower(CMS_FOLDER))
{
throw new Core_Exception("Forbidden to delete home directory.");
}
if ($dirname !== FALSE && strpos($dirname, CMS_FOLDER) !== 0)
{
throw new Core_Exception("Forbidden to delete directory out of CMS_FOLDER.");
}
if (is_dir($dirname) && !is_link($dirname))
{
if ($dh = @opendir($dirname))
{
while (($file = readdir($dh)) !== FALSE)
{
if ($file != '.' && $file != '..')
{
clearstatcache();
$pathName = $dirname . DIRECTORY_SEPARATOR . $file;
if (is_file($pathName))
{
self::delete($pathName);
}
elseif (is_dir($pathName))
{
self::deleteDir($pathName);
}
}
}
closedir($dh);
clearstatcache();
if (is_dir($dirname) && !@rmdir($dirname))
{
return FALSE;
}
}
}
else
{
return FALSE;
}
return TRUE;
}
/**
* Binary-safe file write
* @param string $fileName Path to the file.
* @param string $content The string that is to be written.
* @param int $chmod The mode parameter consists of three octal number components specifying access, e.g. 0644
*/
static public function write($fileName, $content, $chmod = CHMOD_FILE)
{
if (($handle = fopen($fileName, 'w')) && flock($handle, LOCK_EX))
{
if (fwrite($handle, $content) === FALSE)
{
flock($handle, LOCK_UN);
fclose($handle);
throw new Core_Exception("File '%fileName' write error.",
array('%fileName' => Core_Exception::cutRootPath($fileName)));
}
flock($handle, LOCK_UN);
fclose($handle);
@chmod($fileName, $chmod);
return TRUE;
}
else
{
throw new Core_Exception("File '%fileName' open error .",
array('%fileName' => Core_Exception::cutRootPath($fileName)));
}
}
static public function read($fileName)
{
if (is_file($fileName))
{
return file_get_contents($fileName);
}
else
{
throw new Core_Exception("The file '%fileName' does not exist.",
array('%fileName' => Core_Exception::cutRootPath($fileName)));
}
}
/**
* Makes directory
* @param string $pathname The directory path.
* @param int $chmod The mode parameter consists of three octal number components specifying access, e.g. 0644
* @param int $recursive Allows the creation of nested directories specified in the pathname. Defaults to FALSE.
*/
static public function mkdir($pathname, $chmod = CHMOD, $recursive = FALSE)
{
if (!is_dir($pathname) && !is_link($pathname))
{
if (mkdir($pathname, $chmod, $recursive))
{
chmod($pathname, $chmod);
}
else
{
throw new Core_Exception("The directory '%pathname' does not create.",
array('%pathname' => Core_Exception::cutRootPath($pathname)));
}
}
}
static public function getExtension($path)
{
return strtolower(substr(strrchr($path, "."), 1));
}
static public function isValidExtension($path, array $aExtensions, $case = FALSE)
{
$sExtension = self::getExtension($path);
if ($case)
{
return in_array($sExtension, $aExtensions);
}
else
{
foreach ($aExtensions AS $extension)
{
if (strtolower($sExtension) == strtolower($extension))
{
return TRUE;
}
}
}
return FALSE;
}
static public function convertfileNameToLocalEncoding($fileName)
{
return @iconv("UTF-8", "Windows-1251//IGNORE//TRANSLIT", $fileName);
}
static public function convertfileNameFromLocalEncoding($fileName)
{
return @iconv("Windows-1251", "UTF-8//IGNORE//TRANSLIT", $fileName);
}
static public function flush()
{
flush();
ob_get_length() !== FALSE && ob_flush();
}
}
/**
* Exceptions
*
* @package HostCMS
* @version 7.x
* @author Hostmake LLC
* @copyright © 2005-2012 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
*/
class Core_Exception extends Exception
{
/**
* Constructor.
* Exception $previous = NULL just for PHP 5.3.0+
*/
public function __construct($message = NULL, array $values = array(), $code = 0, $bShowDebugTrace = TRUE, $status = 0, $log = TRUE)
{
if (!is_null($message) && !empty($values))
{
$values = array_map('htmlspecialchars', $values);
$message = str_replace(array_keys($values), array_values($values), $message);
}
if ($bShowDebugTrace)
{
$aDebugTrace = $this->getDebugTrace();
foreach ($aDebugTrace AS $aTrace)
{
$message .= "\n