Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

I have found and fixed minor bug with Image Upload #127

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions core/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
list($ns, $class) = $path;

if ($ns == "kcfinder") {
if (in_array($class, array("uploader", "browser", "minifier", "session")))
require "core/class/$class.php";

if ($class == "uploader")
require "core/class/uploader.php";
elseif ($class == "browser")
require "core/class/browser.php";
elseif ($class == "minifier")
require "core/class/minifier.php";

elseif (file_exists("core/types/$class.php"))
require "core/types/$class.php";
elseif (file_exists("lib/class_$class.php"))
Expand All @@ -31,3 +37,5 @@
require "lib/helper_$class.php";
}
});

?>
2 changes: 2 additions & 0 deletions core/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,5 @@ public function gc($maxlifetime) {


// PUT YOUR ADDITIONAL CODE HERE

?>
137 changes: 62 additions & 75 deletions core/class/browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@ protected function act_upload() {
header("Content-Type: text/plain; charset={$this->charset}");

if (!$this->config['access']['files']['upload'] ||
(!isset($_POST['dir']) && !isset($_GET['dir']))
!isset($_POST['dir'])
)
$this->errorMsg("Unknown error.");

$dir = isset($_GET['dir']) ? $this->getDir() : $this->postDir();
$dir = $this->postDir();

if (!dir::isWritable($dir))
$this->errorMsg("Cannot access or write to upload folder.");
Expand All @@ -299,28 +299,6 @@ protected function act_upload() {
return $this->moveUploadFile($this->file, $dir);
}

protected function act_dragUrl() {
if (!$this->config['access']['files']['upload'] ||
!isset($_GET['dir']) ||
!isset($_POST['url']) ||
!isset($_POST['type'])
)
$this->errorMsg("Unknown error.");

$dir = $this->getDir();

if (!dir::isWritable($dir))
$this->errorMsg("Cannot access or write to upload folder.");

if (is_array($_POST['url']))
foreach ($_POST['url'] as $url)
$this->downloadURL($url, $dir);
else
$this->downloadURL($_POST['url'], $dir);

return true;
}

protected function act_download() {
$dir = $this->postDir();
if (!isset($_POST['dir']) ||
Expand Down Expand Up @@ -653,9 +631,62 @@ protected function act_check4Update() {
)
return json_encode(array('version' => $this->session['checkVersion']));

$ver = phpGet::get("http://kcfinder.sunhater.com/checkVersion.php");
$protocol = "http";
$host = "kcfinder.sunhater.com";
$port = 80;
$path = "/checkVersion.php";

$url = "$protocol://$host:$port$path";
$pattern = '/^\d+\.\d+$/';
$responsePattern = '/^[A-Z]+\/\d+\.\d+\s+\d+\s+OK\s*([a-zA-Z0-9\-]+\:\s*[^\n]*\n)*\s*(.*)\s*$/';

// file_get_contents()
if (ini_get("allow_url_fopen") &&
(false !== ($ver = file_get_contents($url))) &&
preg_match($pattern, $ver)

// HTTP extension
) {} elseif (
function_exists("http_get") &&
(false !== ($ver = @http_get($url))) &&
(
(
preg_match($responsePattern, $ver, $match) &&
false !== ($ver = $match[2])
) || true
) &&
preg_match($pattern, $ver)

// Curl extension
) {} elseif (
function_exists("curl_init") &&
(false !== ( $curl = @curl_init($url) )) &&
( @ob_start() || (@curl_close($curl) && false)) &&
( @curl_exec($curl) || (@curl_close($curl) && false)) &&
((false !== ( $ver = @ob_get_clean() )) || (@curl_close($curl) && false)) &&
( @curl_close($curl) || true ) &&
preg_match($pattern, $ver)

// Socket extension
) {} elseif (function_exists('socket_create')) {
$cmd =
"GET $path " . strtoupper($protocol) . "/1.1\r\n" .
"Host: $host\r\n" .
"Connection: Close\r\n\r\n";

if ((false !== ( $socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP) )) &&
(false !== @socket_connect($socket, $host, $port) ) &&
(false !== @socket_write($socket, $cmd, strlen($cmd)) ) &&
(false !== ( $ver = @socket_read($socket, 2048) )) &&
preg_match($responsePattern, $ver, $match)
)
$ver = $match[2];

if (isset($socket) && is_resource($socket))
@socket_close($socket);
}

if (isset($ver) && preg_match('/^\d+\.\d+$/', $ver)) {
if (isset($ver) && preg_match($pattern, $ver)) {
$this->session['checkVersion'] = $ver;
$this->session['checkVersionTime'] = time();
return json_encode(array('version' => $ver));
Expand Down Expand Up @@ -684,6 +715,9 @@ protected function moveUploadFile($file, $dir) {
} elseif (function_exists('chmod'))
chmod($target, $this->config['filePerms']);

$target = $this->checkUploadedFileMime($target);
// $target = basename($uploadedFilePath);

$this->makeThumb($target);
return "/" . basename($target);
}
Expand Down Expand Up @@ -886,53 +920,6 @@ protected function errorMsg($message, array $data=null) {
protected function htmlData($str) {
return htmlentities($str, null, strtoupper($this->charset));
}

protected function downloadURL($url, $dir) {

if (!preg_match(phpGet::$urlExpr, $url, $match))
return;

if ((isset($match[7]) && strlen($match[7])))
$furl = explode("&", $match[7]);

$filename = isset($furl)
? basename($furl[0])
: "web_image.jpg";

$file = tempnam(sys_get_temp_dir(), $filename);

if (phpGet::get($url, $file))
$this->moveUploadFile(array(
'name' => $filename,
'tmp_name' => $file,
'error' => UPLOAD_ERR_OK
), $dir);
else
@unlink($file);
}

protected function getLangs() {
if (isset($this->session['langs']))
return $this->session['langs'];

$files = dir::content("lang", array(
'pattern' => '/^[a-z]{2,3}(\-[a-z]{2})?\.php$/',
'types' => "file"
));

$langs = array();
if (is_array($files))
foreach ($files as $file) {
include $file;
$id = substr(basename($file), 0, -4);
$langs[$id] = isset($lang['_native'])
? $lang['_native']
: (isset($lang['_lang'])
? $lang['_lang']
: $id);
}

$this->session['langs'] = $langs;
return $langs;
}
}

?>
9 changes: 6 additions & 3 deletions core/class/minifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ class minifier {
);

public function __construct($type=null) {
$this->config = require("conf/config.php");
require "conf/config.php";
$this->config = $_CONFIG;
$type = strtolower($type);
if (isset($this->mime[$type]))
$this->type = $type;
if (isset($this->config["_{$this->type}MinCmd"]))
$this->minCmd = $this->config["_{$this->type}MinCmd"];
if (isset($_CONFIG["_{$this->type}MinCmd"]))
$this->minCmd = $_CONFIG["_{$this->type}MinCmd"];
}

public function minify($cacheFile=null, $dir=null) {
Expand Down Expand Up @@ -109,3 +110,5 @@ public function minify($cacheFile=null, $dir=null) {

}
}

?>
76 changes: 0 additions & 76 deletions core/class/session.php

This file was deleted.

Loading