Initial commit

This commit is contained in:
2020-11-02 15:46:52 +01:00
commit 17f974127c
13788 changed files with 1921656 additions and 0 deletions

View File

@@ -0,0 +1,393 @@
<?php
/** This file is part of KCFinder project
*
* @desc GD extension class
* @package KCFinder
* @version 2.21
* @author Pavel Tzonkov <pavelc@users.sourceforge.net>
* @copyright 2010 KCFinder Project
* @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
* @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
* @link http://kcfinder.sunhater.com
*/
class gd {
/** GD resource
* @var resource */
protected $image;
/** Image width
* @var integer */
protected $width;
/** Image height
* @var integer */
protected $height;
/** Init error
* @var bool */
public $init_error = false;
/** Last builded image type constant (IMAGETYPE_XXX)
* @var integer */
public $type;
/** Returns an array. Element 0 - GD resource. Element 1 - width. Element 2 - height.
* Returns FALSE on failure. The only one parameter $image can be an instance of this class,
* a GD resource, an array(width, height) or path to image file.
* @param mixed $image
* @return array */
protected function build_image($image) {
if ($image instanceof gd) {
$width = $image->get_width();
$height = $image->get_height();
$image = $image->get_image();
} elseif (is_resource($image) && (get_resource_type($image) == "gd")) {
$width = @imagesx($image);
$height = @imagesy($image);
} elseif (is_array($image)) {
list($key, $width) = each($image);
list($key, $height) = each($image);
$image = imagecreatetruecolor($width, $height);
} elseif (false !== (list($width, $height, $type) = @getimagesize($image))) {
$image =
($type == IMAGETYPE_GIF) ? @imagecreatefromgif($image) : (
($type == IMAGETYPE_WBMP) ? @imagecreatefromwbmp($image) : (
($type == IMAGETYPE_JPEG) ? @imagecreatefromjpeg($image) : (
($type == IMAGETYPE_JPEG2000) ? @imagecreatefromjpeg($image) : (
($type == IMAGETYPE_PNG) ? imagecreatefrompng($image) : (
($type == IMAGETYPE_XBM) ? @imagecreatefromxbm($image) : false
)))));
if ($type == IMAGETYPE_PNG)
imagealphablending($image, false);
}
$return = (
is_resource($image) &&
(get_resource_type($image) == "gd") &&
isset($width) &&
isset($height) &&
(preg_match('/^[1-9][0-9]*$/', $width) !== false) &&
(preg_match('/^[1-9][0-9]*$/', $height) !== false)
)
? array($image, $width, $height)
: false;
if (($return !== false) && isset($type))
$this->type = $type;
return $return;
}
/** Parameter $image can be:
* 1. An instance of this class (copy instance).
* 2. A GD resource.
* 3. An array with two elements. First - width, second - height. Create a blank image.
* 4. A filename string. Get image form file.
* The non-required parameter $bigger_size is the bigger dimension (width or height) the image
* will be resized to. The other dimension (height or width) will be calculated autamaticaly
* @param mixed $image
* @param integer $bigger_size
* @return gd */
public function __construct($image, $bigger_size=null) {
$this->image = $this->width = $this->height = null;
$image_details = $this->build_image($image);
if ($image_details !== false)
list($this->image, $this->width, $this->height) = $image_details;
else
$this->init_error = true;
if (!is_null($this->image) &&
!is_null($bigger_size) &&
(preg_match('/^[1-9][0-9]*$/', $bigger_size) !== false)
) {
$image = $this->image;
list($width, $height) = $this->get_prop_size($bigger_size);
$this->image = imagecreatetruecolor($width, $height);
if ($this->type == IMAGETYPE_PNG) {
imagealphablending($this->image, false);
imagesavealpha($this->image, true);
}
$this->width = $width;
$this->height = $height;
$this->imagecopyresampled($image);
}
}
/** Returns the GD resource
* @return resource */
public function get_image() {
return $this->image;
}
/** Returns the image width
* @return integer */
public function get_width() {
return $this->width;
}
/** Returns the image height
* @return integer */
public function get_height() {
return $this->height;
}
/** Returns calculated proportional width from the given height
* @param integer $resized_height
* @return integer */
public function get_prop_width($resized_height) {
return intval(($this->width * $resized_height) / $this->height);
}
/** Returns calculated proportional height from the given width
* @param integer $resized_width
* @return integer */
public function get_prop_height($resized_width) {
return intval(($this->height * $resized_width) / $this->width);
}
/** Returns an array with calculated proportional width & height.
* The parameter $bigger_size is the bigger dimension (width or height) of calculated sizes.
* The other dimension (height or width) will be calculated autamaticaly
* @param integer $bigger_size
* @return array */
public function get_prop_size($bigger_size) {
if ($this->width > $this->height) {
$width = $bigger_size;
$height = $this->get_prop_height($width);
} elseif ($this->height > $this->width) {
$height = $bigger_size;
$width = $this->get_prop_width($height);
} else
$width = $height = $bigger_size;
return array($width, $height);
}
/** Resize image. Returns TRUE on success or FALSE on failure
* @param integer $width
* @param integer $height
* @return bool */
public function resize($width, $height) {
if (!$width) $width = 1;
if (!$height) $height = 1;
return (
(false !== ($img = new gd(array($width, $height)))) &&
$img->imagecopyresampled($this) &&
(false !== ($this->image = $img->get_image())) &&
(false !== ($this->width = $img->get_width())) &&
(false !== ($this->height = $img->get_height()))
);
}
/** Resize the given image source (GD, gd object or image file path) to fit in the own image.
* The outside ares will be cropped out. Returns TRUE on success or FALSE on failure
* @param mixed $src
* @return bool */
public function resize_crop($src) {
$image_details = $this->build_image($src);
if ($image_details !== false) {
list($src, $src_width, $src_height) = $image_details;
if (($src_width / $src_height) > ($this->width / $this->height)) {
$src_w = $this->get_prop_width($src_height);
$src_h = $src_height;
$src_x = intval(($src_width - $src_w) / 2);
$src_y = 0;
} else {
$src_w = $src_width;
$src_h = $this->get_prop_height($src_width);
$src_x = 0;
$src_y = intval(($src_height - $src_h) / 2);
}
return imagecopyresampled($this->image, $src, 0, 0, $src_x, $src_y, $this->width, $this->height, $src_w, $src_h);
} else
return false;
}
/** Resize image to fit in given resolution. Returns TRUE on success or FALSE on failure
* @param integer $width
* @param integer $height
* @return bool */
public function resize_fit($width, $height) {
if ((!$width && !$height) || (($width == $this->width) && ($height == $this->height)))
return true;
if (!$width || (($width / $height) > ($this->width / $this->height)))
$width = intval(($this->width * $height) / $this->height);
elseif (!$height || (($width / $height) < ($this->width / $this->height)))
$height = intval(($this->height * $width) / $this->width);
return $this->resize($width, $height);
}
/** Neka si predstavim vyobrazhaem pravoygylnik s razmeri $width i $height.
* Izobrazhenieto shte se preorazmeri taka che to shte izliza ot tozi pravoygylnik,
* no samo po edno (x ili y) izmerenie
* @param integer $width
* @param integer $height
* @return bool */
public function resize_overflow($width, $height) {
$big = (($this->width / $this->height) > ($width / $height))
? ($this->width * $height) / $this->height
: ($this->height * $width) / $this->width;
$big = intval($big);
$return = ($img = new gd($this->image, $big));
if ($return) {
$this->image = $img->get_image();
$this->width = $img->get_width();
$this->height = $img->get_height();
}
return $return;
}
public function gd_color() {
$args = func_get_args();
$expr_rgb = '/^rgb\(\s*(\d{1,3})\s*\,\s*(\d{1,3})\s*\,\s*(\d{1,3})\s*\)$/i';
$expr_hex1 = '/^\#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i';
$expr_hex2 = '/^\#?([0-9a-f])([0-9a-f])([0-9a-f])$/i';
$expr_byte = '/^([01]?\d?\d|2[0-4]\d|25[0-5])$/';
if (!isset($args[0]))
return false;
if (count($args[0]) == 3) {
list($r, $g, $b) = $args[0];
} elseif (preg_match($expr_rgb, $args[0])) {
list($r, $g, $b) = explode(" ", preg_replace($expr_rgb, "$1 $2 $3", $args[0]));
} elseif (preg_match($expr_hex1, $args[0])) {
list($r, $g, $b) = explode(" ", preg_replace($expr_hex1, "$1 $2 $3", $args[0]));
$r = hexdec($r);
$g = hexdec($g);
$b = hexdec($b);
} elseif (preg_match($expr_hex2, $args[0])) {
list($r, $g, $b) = explode(" ", preg_replace($expr_hex2, "$1$1 $2$2 $3$3", $args[0]));
$r = hexdec($r);
$g = hexdec($g);
$b = hexdec($b);
} elseif ((count($args) == 3) &&
preg_match($expr_byte, $args[0]) &&
preg_match($expr_byte, $args[1]) &&
preg_match($expr_byte, $args[2])
) {
list($r, $g, $b) = $args;
} else
return false;
return imagecolorallocate($this->image, $r, $g, $b);
}
public function fill_color($color) {
return $this->imagefilledrectangle(0, 0, $this->width - 1, $this->height - 1, $color);
}
/* G D M E T H O D S */
public function imagecopy(
$src,
$dst_x=0, $dst_y=0,
$src_x=0, $src_y=0,
$dst_w=null, $dst_h=null,
$src_w=null, $src_h=null
) {
$image_details = $this->build_image($src);
if ($image_details !== false) {
list($src, $src_width, $src_height) = $image_details;
if (is_null($dst_w)) $dst_w = $this->width - $dst_x;
if (is_null($dst_h)) $dst_h = $this->height - $dst_y;
if (is_null($src_w)) $src_w = $src_width - $src_x;
if (is_null($src_h)) $src_h = $src_height - $src_y;
return imagecopy($this->image, $src, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);
} else
return false;
}
public function imagecopyresampled(
$src,
$dst_x=0, $dst_y=0,
$src_x=0, $src_y=0,
$dst_w=null, $dst_h=null,
$src_w=null, $src_h=null
) {
$image_details = $this->build_image($src);
if ($image_details !== false) {
list($src, $src_width, $src_height) = $image_details;
if (is_null($dst_w)) $dst_w = $this->width - $dst_x;
if (is_null($dst_h)) $dst_h = $this->height - $dst_y;
if (is_null($src_w)) $src_w = $src_width - $src_x;
if (is_null($src_h)) $src_h = $src_height - $src_y;
return imagecopyresampled($this->image, $src, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
} else
return false;
}
public function imagefilledrectangle($x1, $y1, $x2, $y2, $color) {
$color = $this->gd_color($color);
if ($color === false) return false;
return imagefilledrectangle($this->image, $x1, $y1, $x2, $y2, $color);
}
public function imagepng($filename=null, $quality=null, $filters=null) {
if (is_null($filename) && !headers_sent())
header("Content-Type: image/png");
@imagesavealpha($this->image, true);
return imagepng($this->image, $filename, $quality, $filters);
}
public function imagejpeg($filename=null, $quality=75) {
if (is_null($filename) && !headers_sent())
header("Content-Type: image/jpeg");
return imagejpeg($this->image, $filename, $quality);
}
public function imagegif($filename=null) {
if (is_null($filename) && !headers_sent())
header("Content-Type: image/gif");
return imagegif($this->image, $filename);
}
}
?>

View File

@@ -0,0 +1,86 @@
<?php
/** This file is part of KCFinder project
*
* @desc Input class for GET, POST and COOKIE requests
* @package KCFinder
* @version 2.21
* @author Pavel Tzonkov <pavelc@users.sourceforge.net>
* @copyright 2010 KCFinder Project
* @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
* @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
* @link http://kcfinder.sunhater.com
*/
class input {
/** Filtered $_GET array
* @var array */
public $get;
/** Filtered $_POST array
* @var array */
public $post;
/** Filtered $_COOKIE array
* @var array */
public $cookie;
/** magic_quetes_gpc ini setting flag
* @var bool */
protected $magic_quotes_gpc;
/** magic_quetes_sybase ini setting flag
* @var bool */
protected $magic_quotes_sybase;
public function __construct() {
$this->magic_quotes_gpc = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc();
$this->magic_quotes_sybase = ini_get('magic_quotes_sybase');
$this->magic_quotes_sybase = $this->magic_quotes_sybase
? !in_array(strtolower(trim($this->magic_quotes_sybase)),
array('off', 'no', 'false'))
: false;
$_GET = $this->filter($_GET);
$_POST = $this->filter($_POST);
$_COOKIE = $this->filter($_COOKIE);
$this->get = &$_GET;
$this->post = &$_POST;
$this->cookie = &$_COOKIE;
}
/** Magic method to get non-public properties like public.
* @param string $property
* @return mixed */
public function __get($property) {
return property_exists($this, $property) ? $this->$property : null;
}
/** Filter the given subject. If magic_quotes_gpc and/or magic_quotes_sybase
* ini settings are turned on, the method will remove backslashes from some
* escaped characters. If the subject is an array, elements with non-
* alphanumeric keys will be removed
* @param mixed $subject
* @return mixed */
public function filter($subject) {
if ($this->magic_quotes_gpc) {
if (is_array($subject)) {
foreach ($subject as $key => $val)
if (!preg_match('/^[a-z\d_]+$/si', $key))
unset($subject[$key]);
else
$subject[$key] = $this->filter($val);
} elseif (is_scalar($subject))
$subject = $this->magic_quotes_sybase
? str_replace("\\'", "'", $subject)
: stripslashes($subject);
}
return $subject;
}
}
?>

View File

@@ -0,0 +1,60 @@
<?php
/** This file is part of KCFinder project. The class are taken from
* http://www.php.net/manual/en/function.ziparchive-addemptydir.php
*
* @desc Directory to ZIP file archivator
* @package KCFinder
* @version 2.21
* @author Pavel Tzonkov <pavelc@users.sourceforge.net>
* @copyright 2010 KCFinder Project
* @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
* @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
* @link http://kcfinder.sunhater.com
*/
class zipFolder {
protected $zip;
protected $root;
protected $ignored;
function __construct($file, $folder, $ignored=null) {
$this->zip = new ZipArchive();
$this->ignored = is_array($ignored)
? $ignored
: ($ignored ? array($ignored) : array());
if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE)
throw new Exception("cannot open <$file>\n");
$folder = rtrim($folder, '/');
if (strstr($folder, '/')) {
$this->root = substr($folder, 0, strrpos($folder, '/') + 1);
$folder = substr($folder, strrpos($folder, '/') + 1);
}
$this->zip($folder);
$this->zip->close();
}
function zip($folder, $parent=null) {
$full_path = "{$this->root}$parent$folder";
$zip_path = "$parent$folder";
$this->zip->addEmptyDir($zip_path);
$dir = new DirectoryIterator($full_path);
foreach ($dir as $file)
if (!$file->isDot()) {
$filename = $file->getFilename();
if (!in_array($filename, $this->ignored)) {
if ($file->isDir())
$this->zip($filename, "$zip_path/");
else
$this->zip->addFile("$full_path/$filename", "$zip_path/$filename");
}
}
}
}
?>

View File

@@ -0,0 +1,161 @@
<?php
/** This file is part of KCFinder project
*
* @desc Directory helper class
* @package KCFinder
* @version 2.21
* @author Pavel Tzonkov <pavelc@users.sourceforge.net>
* @copyright 2010 KCFinder Project
* @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
* @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
* @link http://kcfinder.sunhater.com
*/
class dir {
/** Checks if the given directory is really writable. The standard PHP
* function is_writable() does not work properly on Windows servers
* @param string $dir
* @return bool */
static function isWritable($dir) {
$dir = path::normalize($dir);
if (!is_dir($dir))
return false;
$i = 0;
do {
$file = "$dir/is_writable_" . md5($i++);
} while (file_exists($file));
if (!@touch($file))
return false;
unlink($file);
return true;
}
/** Recursively delete the given directory. Returns TRUE on success.
* If $firstFailExit parameter is true (default), the method returns the
* path to the first failed file or directory which cannot be deleted.
* If $firstFailExit is false, the method returns an array with failed
* files and directories which cannot be deleted. The third parameter
* $failed is used for internal use only.
* @param string $dir
* @param bool $firstFailExit
* @param array $failed
* @return mixed */
static function prune($dir, $firstFailExit=true, array $failed=null) {
if ($failed === null) $failed = array();
$files = self::content($dir);
if ($files === false) {
if ($firstFailExit)
return $dir;
$failed[] = $dir;
return $failed;
}
foreach ($files as $file) {
if (is_dir($file)) {
$failed_in = self::prune($file, $firstFailExit, $failed);
if ($failed_in !== true) {
if ($firstFailExit)
return $failed_in;
if (is_array($failed_in))
$failed = array_merge($failed, $failed_in);
else
$failed[] = $failed_in;
}
} elseif (!@unlink($file)) {
if ($firstFailExit)
return $file;
$failed[] = $file;
}
}
if (!@rmdir($dir)) {
if ($firstFailExit)
return $dir;
$failed[] = $dir;
}
return count($failed) ? $failed : true;
}
/** Get the content of the given directory. Returns an array with filenames
* or FALSE on failure
* @param string $dir
* @param array $options
* @return mixed */
static function content($dir, array $options=null) {
$defaultOptions = array(
'types' => "all", // Allowed: "all" or possible return values
// of filetype(), or an array with them
'addPath' => true, // Whether to add directory path to filenames
'pattern' => '/./', // Regular expression pattern for filename
'followLinks' => true
);
if (!is_dir($dir) || !is_readable($dir))
return false;
if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN")
$dir = str_replace("\\", "/", $dir);
$dir = rtrim($dir, "/");
$dh = @opendir($dir);
if ($dh === false)
return false;
if ($options === null)
$options = $defaultOptions;
foreach ($defaultOptions as $key => $val)
if (!isset($options[$key]))
$options[$key] = $val;
$files = array();
while (($file = @readdir($dh)) !== false) {
$type = filetype("$dir/$file");
if ($options['followLinks'] && ($type === "link")) {
$lfile = "$dir/$file";
do {
$ldir = dirname($lfile);
$lfile = @readlink($lfile);
if (substr($lfile, 0, 1) != "/")
$lfile = "$ldir/$lfile";
$type = filetype($lfile);
} while ($type == "link");
}
if ((($type === "dir") && (($file == ".") || ($file == ".."))) ||
!preg_match($options['pattern'], $file)
)
continue;
if (($options['types'] === "all") || ($type === $options['types']) ||
((is_array($options['types'])) && in_array($type, $options['types']))
)
$files[] = $options['addPath'] ? "$dir/$file" : $file;
}
closedir($dh);
usort($files, "dir::fileSort");
return $files;
}
static function fileSort($a, $b) {
if (function_exists("mb_strtolower")) {
$a = mb_strtolower($a);
$b = mb_strtolower($b);
} else {
$a = strtolower($a);
$b = strtolower($b);
}
if ($a == $b) return 0;
return ($a < $b) ? -1 : 1;
}
}
?>

View File

@@ -0,0 +1,202 @@
<?php
/** This file is part of KCFinder project
*
* @desc File helper class
* @package KCFinder
* @version 2.21
* @author Pavel Tzonkov <pavelc@users.sourceforge.net>
* @copyright 2010 KCFinder Project
* @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
* @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
* @link http://kcfinder.sunhater.com
*/
class file {
static $MIME = array(
'ai' => 'application/postscript',
'aif' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'avi' => 'video/x-msvideo',
'bin' => 'application/macbinary',
'bmp' => 'image/bmp',
'cpt' => 'application/mac-compactpro',
'css' => 'text/css',
'csv' => 'text/x-comma-separated-values',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'doc' => 'application/msword',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'dvi' => 'application/x-dvi',
'dxr' => 'application/x-director',
'eml' => 'message/rfc822',
'eps' => 'application/postscript',
'flv' => 'video/x-flv',
'gif' => 'image/gif',
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'hqx' => 'application/mac-binhex40',
'htm' => 'text/html',
'html' => 'text/html',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'js' => 'application/x-javascript',
'log' => 'text/plain',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mif' => 'application/vnd.mif',
'mov' => 'video/quicktime',
'movie' => 'video/x-sgi-movie',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'mpe' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpga' => 'audio/mpeg',
'oda' => 'application/oda',
'pdf' => 'application/pdf',
'php' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
'php4' => 'application/x-httpd-php',
'phps' => 'application/x-httpd-php-source',
'phtml' => 'application/x-httpd-php',
'png' => 'image/png',
'ppt' => 'application/powerpoint',
'ps' => 'application/postscript',
'psd' => 'application/x-photoshop',
'qt' => 'video/quicktime',
'ra' => 'audio/x-realaudio',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'rtf' => 'text/rtf',
'rtx' => 'text/richtext',
'rv' => 'video/vnd.rn-realvideo',
'shtml' => 'text/html',
'sit' => 'application/x-stuffit',
'smi' => 'application/smil',
'smil' => 'application/smil',
'swf' => 'application/x-shockwave-flash',
'tar' => 'application/x-tar',
'tgz' => 'application/x-tar',
'text' => 'text/plain',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'txt' => 'text/plain',
'wav' => 'audio/x-wav',
'wbxml' => 'application/wbxml',
'wmlc' => 'application/wmlc',
'word' => 'application/msword',
'xht' => 'application/xhtml+xml',
'xhtml' => 'application/xhtml+xml',
'xl' => 'application/excel',
'xls' => 'application/excel',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'xml' => 'text/xml',
'xsl' => 'text/xml',
'zip' => 'application/x-zip'
);
/** Checks if the given file is really writable. The standard PHP function
* is_writable() does not work properly on Windows servers.
* @param string $dir
* @return bool */
static function isWritable($filename) {
$filename = path::normalize($filename);
if (!is_file($filename) || (false === ($fp = @fopen($filename, 'a+'))))
return false;
fclose($fp);
return true;
}
/** Get the extension from filename
* @param string $file
* @param bool $toLower
* @return string */
static function getExtension($filename, $toLower=true) {
return preg_match('/^.*\.([^\.]*)$/s', $filename, $patt)
? ($toLower ? strtolower($patt[1]) : $patt[1]) : "";
}
/** Get MIME type of the given filename. If Fileinfo PHP extension is
* available the MIME type will be fetched by the file's content. The
* second parameter is optional and defines the magic file path. If you
* skip it, the default one will be loaded.
* If Fileinfo PHP extension is not available the MIME type will be fetched
* by filename extension regarding $MIME property. If the file extension
* does not exist there, returned type will be application/octet-stream
* @param string $filename
* @param string $magic
* @return string */
static function getMimeType($filename, $magic=null) {
if (class_exists("finfo")) {
$finfo = ($magic === null)
? new finfo(FILEINFO_MIME)
: new finfo(FILEINFO_MIME, $magic);
if ($finfo) {
$mime = $finfo->file($filename);
$mime = substr($mime, 0, strrpos($mime, ";"));
return $mime;
}
}
$ext = self::getExtension($filename, true);
return isset(self::$MIME[$ext]) ? self::$MIME[$ext] : "application/octet-stream";
}
/** Get inexistant filename based on the given filename. If you skip $dir
* parameter the directory will be fetched from $filename and returned
* value will be full filename path. The third parameter is optional and
* defines the template, the filename will be renamed to. Default template
* is {name}({sufix}){ext}. Examples:
*
* file::getInexistantFilename("/my/directory/myfile.txt");
* If myfile.txt does not exist - returns the same path to the file
* otherwise returns "/my/directory/myfile(1).txt"
*
* file::getInexistantFilename("myfile.txt", "/my/directory");
* returns "myfile.txt" or "myfile(1).txt" or "myfile(2).txt" etc...
*
* file::getInexistantFilename("myfile.txt", "/dir", "{name}[{sufix}]{ext}");
* returns "myfile.txt" or "myfile[1].txt" or "myfile[2].txt" etc...
*
* @param string $filename
* @param string $dir
* @param string $tpl
* @return string */
static function getInexistantFilename($filename, $dir=null, $tpl=null) {
if ($tpl === null) $tpl = "{name}({sufix}){ext}";
$fullPath = ($dir === null);
if ($fullPath)
$dir = path::normalize(dirname($filename));
else {
$fdir = dirname($filename);
$dir = strlen($fdir)
? path::normalize("$dir/$fdir")
: path::normalize($dir);
}
$filename = basename($filename);
$ext = self::getExtension($filename, false);
$name = strlen($ext) ? substr($filename, 0, -strlen($ext) - 1) : $filename;
$tpl = str_replace('{name}', $name, $tpl);
$tpl = str_replace('{ext}', (strlen($ext) ? ".$ext" : ""), $tpl);
$i = 1; $file = "$dir/$filename";
while (file_exists($file))
$file = "$dir/" . str_replace('{sufix}', $i++, $tpl);
return $fullPath
? $file
: (strlen($fdir)
? "$fdir/" . basename($file)
: basename($file));
}
}
?>

View File

@@ -0,0 +1,91 @@
<?php
/** This file is part of KCFinder project
*
* @desc HTTP cache helper class
* @package KCFinder
* @version 2.21
* @author Pavel Tzonkov <pavelc@users.sourceforge.net>
* @copyright 2010 KCFinder Project
* @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
* @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
* @link http://kcfinder.sunhater.com
*/
class httpCache {
const DEFAULT_TYPE = "text/html";
const DEFAULT_EXPIRE = 604800; // in seconds
/** Cache a file. The $type parameter might define the MIME type of the file
* or path to magic file to autodetect the MIME type. If you skip $type
* parameter the method will try with the default magic file. Autodetection
* of MIME type requires Fileinfo PHP extension used in file::getMimeType()
* @param string $file
* @param string $type
* @param integer $expire
* @param array $headers */
static function file($file, $type=null, $expire=null, array $headers=null) {
$mtime = @filemtime($file);
if ($mtime !== false) self::checkMTime($mtime);
if ($type === null) {
$magic = ((substr($type, 0, 1) == "/") || preg_match('/^[a-z]\:/i', $type))
? $type : null;
$type = file::getMimeType($file, $magic);
if (!$type) $type = null;
}
self::content(@file_get_contents($file), $mtime, $type, $expire, $headers, false);
}
/** Cache the given $content with $mtime modification time.
* @param binary $content
* @param integer $mtime
* @param string $type
* @param integer $expire
* @param array $headers
* @param bool $checkMTime */
static function content($content, $mtime, $type=null, $expire=null, array $headers=null, $checkMTime=true) {
if ($checkMTime) self::checkMTime($mtime);
if ($type === null) $type = self::DEFAULT_TYPE;
if ($expire === null) $expire = self::DEFAULT_EXPIRE;
$size = strlen($content);
$expires = gmdate("D, d M Y H:i:s", time() + $expire) . " GMT";
header("Content-Type: $type");
header("Expires: $expires");
header("Cache-Control: max-age=$expire");
header("Pragma: !invalid");
header("Content-Length: $size");
if ($headers !== null) foreach ($headers as $header) header($header);
echo $content;
}
/** Check if given modification time is newer than client-side one. If not,
* the method will tell the client to get the content from its own cache.
* Afterwards the script process will be terminated. This feature requires
* the PHP to be configured as Apache module.
* @param integer $mtime */
static function checkMTime($mtime) {
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $mtime) . " GMT");
$headers = function_exists("getallheaders")
? getallheaders()
: (function_exists("apache_request_headers")
? apache_request_headers()
: false);
if (is_array($headers) && isset($headers['If-Modified-Since'])) {
$client_mtime = explode(';', $headers['If-Modified-Since']);
$client_mtime = strtotime($client_mtime[0]);
if ($client_mtime >= $mtime) {
header('HTTP/1.1 304 Not Modified');
die;
}
}
}
}
?>

View File

@@ -0,0 +1,144 @@
<?php
/** This file is part of KCFinder project
*
* @desc Path helper class
* @package KCFinder
* @version 2.21
* @author Pavel Tzonkov <pavelc@users.sourceforge.net>
* @copyright 2010 KCFinder Project
* @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
* @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
* @link http://kcfinder.sunhater.com
*/
class path {
/** Get the absolute URL path of the given one. Returns FALSE if the URL
* is not valid or the current directory cannot be resolved (getcwd())
* @param string $path
* @return string */
static function rel2abs_url($path) {
if (substr($path, 0, 1) == "/") return $path;
$dir = @getcwd();
if (!isset($_SERVER['DOCUMENT_ROOT']) || ($dir === false))
return false;
$dir = self::normalize($dir);
$doc_root = self::normalize($_SERVER['DOCUMENT_ROOT']);
if (substr($dir, 0, strlen($doc_root)) != $doc_root)
return false;
$return = self::normalize(substr($dir, strlen($doc_root)) . "/$path");
if (substr($return, 0, 1) !== "/")
$return = "/$return";
return $return;
}
/** Resolve full filesystem path of given URL. Returns FALSE if the URL
* cannot be resolved
* @param string $url
* @return string */
static function url2fullPath($url) {
$url = self::normalize($url);
$uri = isset($_SERVER['SCRIPT_NAME'])
? $_SERVER['SCRIPT_NAME'] : (isset($_SERVER['PHP_SELF'])
? $_SERVER['PHP_SELF']
: false);
$uri = self::normalize($uri);
if (substr($url, 0, 1) !== "/") {
if ($uri === false) return false;
$url = dirname($uri) . "/$url";
}
if (isset($_SERVER['DOCUMENT_ROOT'])) {
return self::normalize($_SERVER['DOCUMENT_ROOT'] . "/$url");
} else {
if ($uri === false) return false;
if (isset($_SERVER['SCRIPT_FILENAME'])) {
$scr_filename = self::normalize($_SERVER['SCRIPT_FILENAME']);
return self::normalize(substr($scr_filename, 0, -strlen($uri)) . "/$url");
}
$count = count(explode('/', $uri)) - 1;
for ($i = 0, $chdir = ""; $i < $count; $i++)
$chdir .= "../";
$chdir = self::normalize($chdir);
$dir = getcwd();
if (($dir === false) || !@chdir($chdir))
return false;
$rdir = getcwd();
chdir($dir);
return ($rdir !== false) ? self::normalize($rdir . "/$url") : false;
}
}
/** Normalize the given path. On Windows servers backslash will be replaced
* with slash. Remobes unnecessary doble slashes and double dots. Removes
* last slash if it exists. Examples:
* path::normalize("C:\\any\\path\\") returns "C:/any/path"
* path::normalize("/your/path/..//home/") returns "/your/home"
* @param string $path
* @return string */
static function normalize($path) {
if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN") {
$path = preg_replace('/([^\\\])\\\([^\\\])/', "$1/$2", $path);
if (substr($path, -1) == "\\") $path = substr($path, 0, -1);
if (substr($path, 0, 1) == "\\") $path = "/" . substr($path, 1);
}
$path = preg_replace('/\/+/s', "/", $path);
$path = "/$path";
if (substr($path, -1) != "/")
$path .= "/";
$expr = '/\/([^\/]{1}|[^\.\/]{2}|[^\/]{3,})\/\.\.\//s';
while (preg_match($expr, $path))
$path = preg_replace($expr, "/", $path);
$path = substr($path, 0, -1);
$path = substr($path, 1);
return $path;
}
/** Encode URL Path
* @param string $path
* @return string */
static function urlPathEncode($path) {
$path = self::normalize($path);
$encoded = "";
foreach (explode("/", $path) as $dir)
$encoded .= rawurlencode($dir) . "/";
$encoded = substr($encoded, 0, -1);
return $encoded;
}
/** Decode URL Path
* @param string $path
* @return string */
static function urlPathDecode($path) {
$path = self::normalize($path);
$decoded = "";
foreach (explode("/", $path) as $dir)
$decoded .= rawurldecode($dir) . "/";
$decoded = substr($decoded, 0, -1);
return $decoded;
}
}
?>

View File

@@ -0,0 +1,69 @@
<?php
/** This file is part of KCFinder project
*
* @desc Text processing helper class
* @package KCFinder
* @version 2.21
* @author Pavel Tzonkov <pavelc@users.sourceforge.net>
* @copyright 2010 KCFinder Project
* @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
* @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
* @link http://kcfinder.sunhater.com
*/
class text {
/** Replace repeated white spaces to single space
* @param string $string
* @return string */
static function clearWhitespaces($string) {
return trim(preg_replace('/\s+/s', " ", $string));
}
/** Normalize the string for HTML attribute value
* @param string $string
* @return string */
static function htmlValue($string) {
return str_replace('"', "&quot;", $string);
}
/** Normalize the string for JavaScript string value
* @param string $string
* @return string */
static function jsValue($string) {
return preg_replace('/\r?\n/', "\\n", str_replace('"', "\\\"", str_replace("'", "\\'", $string)));
}
/** Normalize the string for XML tag content data
* @param string $string
* @param bool $cdata */
static function xmlData($string, $cdata=false) {
$string = str_replace("]]>", "]]]]><![CDATA[>", $string);
if (!$cdata)
$string = "<![CDATA[$string]]>";
return $string;
}
/** Returns compressed content of given CSS code
* @param string $code
* @return string */
static function compressCSS($code) {
$code = self::clearWhitespaces($code);
$code = preg_replace('/ ?\{ ?/', "{", $code);
$code = preg_replace('/ ?\} ?/', "}", $code);
$code = preg_replace('/ ?\; ?/', ";", $code);
$code = preg_replace('/ ?\> ?/', ">", $code);
$code = preg_replace('/ ?\, ?/', ",", $code);
$code = preg_replace('/ ?\: ?/', ":", $code);
$code = str_replace(";}", "}", $code);
return $code;
}
}
?>