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

Added ability to pass config manually #96

Open
wants to merge 1 commit 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
16 changes: 9 additions & 7 deletions core/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
list($ns, $class) = $path;

if ($ns == "kcfinder") {
$dir = dirname(__FILE__);

if (in_array($class, array("uploader", "browser", "minifier", "session")))
require "core/class/$class.php";
elseif (file_exists("core/types/$class.php"))
require "core/types/$class.php";
elseif (file_exists("lib/class_$class.php"))
require "lib/class_$class.php";
elseif (file_exists("lib/helper_$class.php"))
require "lib/helper_$class.php";
require $dir . "/../core/class/$class.php";
elseif (file_exists($dir . "/../core/types/$class.php"))
require $dir . "/../core/types/$class.php";
elseif (file_exists($dir . "/../lib/class_$class.php"))
require $dir . "/../lib/class_$class.php";
elseif (file_exists($dir . "/../lib/helper_$class.php"))
require $dir . "/../lib/helper_$class.php";
}
});
18 changes: 9 additions & 9 deletions core/class/browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class browser extends uploader {
protected $thumbsDir;
protected $thumbsTypeDir;

public function __construct() {
parent::__construct();
public function __construct($config = array()) {
parent::__construct($config);

// SECURITY CHECK INPUT DIRECTORY
if (isset($_POST['dir'])) {
Expand Down Expand Up @@ -691,10 +691,10 @@ protected function moveUploadFile($file, $dir) {
protected function sendDefaultThumb($file=null) {
if ($file !== null) {
$ext = file::getExtension($file);
$thumb = "themes/{$this->config['theme']}/img/files/big/$ext.png";
$thumb = dirname(__FILE__) . "/../../themes/{$this->config['theme']}/img/files/big/$ext.png";
}
if (!isset($thumb) || !file_exists($thumb))
$thumb = "themes/{$this->config['theme']}/img/files/big/..png";
$thumb = dirname(__FILE__) . "/../../themes/{$this->config['theme']}/img/files/big/..png";
header("Content-Type: image/png");
readfile($thumb);
die;
Expand Down Expand Up @@ -734,8 +734,8 @@ protected function getFiles($dir) {
if ($stat === false) continue;
$name = basename($file);
$ext = file::getExtension($file);
$bigIcon = file_exists("themes/{$this->config['theme']}/img/files/big/$ext.png");
$smallIcon = file_exists("themes/{$this->config['theme']}/img/files/small/$ext.png");
$bigIcon = file_exists(dirname(__FILE__) . "/../../themes/{$this->config['theme']}/img/files/big/$ext.png");
$smallIcon = file_exists(dirname(__FILE__) . "/../../themes/{$this->config['theme']}/img/files/small/$ext.png");
$thumb = file_exists("$thumbDir/$name");
$return[] = array(
'name' => stripcslashes($name),
Expand Down Expand Up @@ -857,14 +857,14 @@ protected function output($data=null, $template=null) {
if ($template === null)
$template = $this->action;

if (file_exists("tpl/tpl_$template.php")) {
if (file_exists(dirname(__FILE__) . "/../../tpl/tpl_$template.php")) {
ob_start();
$eval = "unset(\$data);unset(\$template);unset(\$eval);";
$_ = $data;
foreach (array_keys($data) as $key)
if (preg_match('/^[a-z\d_]+$/i', $key))
$eval .= "\$$key=\$_['$key'];";
$eval .= "unset(\$_);require \"tpl/tpl_$template.php\";";
$eval .= "unset(\$_);require dirname(__FILE__) . \"/../../tpl/tpl_$template.php\";";
eval($eval);
return ob_get_clean();
}
Expand Down Expand Up @@ -915,7 +915,7 @@ protected function getLangs() {
if (isset($this->session['langs']))
return $this->session['langs'];

$files = dir::content("lang", array(
$files = dir::content(dirname(__FILE__) . "/../../lang", array(
'pattern' => '/^[a-z]{2,3}(\-[a-z]{2})?\.php$/',
'types' => "file"
));
Expand Down
4 changes: 2 additions & 2 deletions core/class/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class session {
public $values;
protected $config;

public function __construct($configFile) {
public function __construct($configFile, $config) {

// Start session if it is not already started
if (!session_id())
session_start();

$config = require($configFile);
$config = $config + require($configFile);

// _sessionVar option is set
if (isset($config[self::SESSION_VAR])) {
Expand Down
12 changes: 6 additions & 6 deletions core/class/uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __get($property) {
return property_exists($this, $property) ? $this->$property : null;
}

public function __construct() {
public function __construct($config = array()) {

// SET CMS INTEGRATION PROPERTY
if (isset($_GET['cms']) &&
Expand All @@ -103,12 +103,12 @@ public function __construct() {
)
$this->cms = $_GET['cms'];

// LINKING UPLOADED FILE
// LINKING UPLOADED FILE
if (count($_FILES))
$this->file = &$_FILES[key($_FILES)];

// CONFIG & SESSION SETUP
$session = new session("conf/config.php");
$session = new session(dirname(__FILE__) . "/../../conf/config.php", $config);
$this->config = $session->getConfig();
$this->session = &$session->values;

Expand Down Expand Up @@ -221,7 +221,7 @@ public function __construct() {
foreach ($this->langInputNames as $key)
if (isset($_GET[$key]) &&
preg_match('/^[a-z][a-z\._\-]*$/i', $_GET[$key]) &&
file_exists("lang/" . strtolower($_GET[$key]) . ".php")
file_exists(dirname(__FILE__) . "/../../lang/" . strtolower($_GET[$key]) . ".php")
) {
$this->lang = $_GET[$key];
break;
Expand Down Expand Up @@ -655,7 +655,7 @@ protected function makeThumb($file, $overwrite=true) {
}

protected function localize($langCode) {
require "lang/{$langCode}.php";
require dirname(__FILE__) . "/../../lang/{$langCode}.php";
setlocale(LC_ALL, $lang['_locale']);
$this->charset = $lang['_charset'];
$this->dateTimeFull = $lang['_dateTimeFull'];
Expand Down Expand Up @@ -761,6 +761,6 @@ protected function callBack_default($url, $message) {
}

protected function get_htaccess() {
return file_get_contents("conf/upload.htaccess");
return file_get_contents(dirname(__FILE__) . "/../../conf/upload.htaccess");
}
}
4 changes: 2 additions & 2 deletions js/080.files.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ _.showFiles = function(callBack, selected) {
icon = ".image";
else if (!icon.length || !file.smallIcon)
icon = ".";
icon = "themes/" + _.theme + "/img/files/small/" + icon + ".png";
icon = _.baseUrl + "themes/" + _.theme + "/img/files/small/" + icon + ".png";

f = $('<tr class="file"><td class="name thumb"></td><td class="time"></td><td class="size"></td></tr>');
f.appendTo(c.find('table'));
Expand All @@ -74,7 +74,7 @@ _.showFiles = function(callBack, selected) {
} else {
icon = file.bigIcon ? $.$.getFileExtension(file.name) : ".";
if (!icon.length) icon = ".";
icon = "themes/" + _.theme + "/img/files/big/" + icon + ".png";
icon = _.baseUrl + "themes/" + _.theme + "/img/files/big/" + icon + ".png";
}
f = $('<div class="file"><div class="thumb"></div><div class="name"></div><div class="time"></div><div class="size"></div></div>');
f.appendTo(c);
Expand Down
4 changes: 2 additions & 2 deletions tpl/tpl_browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<head>
<title>KCFinder: /<?php echo $this->session['dir'] ?></title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
<?php INCLUDE "tpl/tpl_css.php" ?>
<?php INCLUDE "tpl/tpl_javascript.php" ?>
<?php INCLUDE dirname(__FILE__) . "/tpl_css.php" ?>
<?php INCLUDE dirname(__FILE__) . "/tpl_javascript.php" ?>
</head>
<body>
<div id="resizer"></div>
Expand Down
4 changes: 2 additions & 2 deletions tpl/tpl_css.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<link href="css/index.php" rel="stylesheet" type="text/css" />
<link href="<?php echo $this->config['baseUrl'] ?>css/index.php" rel="stylesheet" type="text/css" />
<style type="text/css">
div.file{width:<?php echo $this->config['thumbWidth'] ?>px;}
div.file .thumb{width:<?php echo $this->config['thumbWidth'] ?>px;height:<?php echo $this->config['thumbHeight'] ?>px}
</style>
<link href="themes/<?php echo $this->config['theme'] ?>/css.php" rel="stylesheet" type="text/css" />
<link href="<?php echo $this->config['baseUrl'] ?>themes/<?php echo $this->config['theme'] ?>/css.php" rel="stylesheet" type="text/css" />
7 changes: 4 additions & 3 deletions tpl/tpl_javascript.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
NAMESPACE kcfinder;
?>
<script src="js/index.php" type="text/javascript"></script>
<script src="js_localize.php?lng=<?php echo $this->lang ?>" type="text/javascript"></script>
<script src="<?php echo $this->config['baseUrl'] ?>js/index.php" type="text/javascript"></script>
<script src="<?php echo $this->config['baseUrl'] ?>js_localize.php?lng=<?php echo $this->lang ?>" type="text/javascript"></script>
<?php
IF ($this->opener['name'] == "tinymce"):
?>
Expand All @@ -12,7 +12,7 @@

IF (file_exists("themes/{$this->config['theme']}/js.php")):
?>
<script src="themes/<?php echo $this->config['theme'] ?>/js.php" type="text/javascript"></script>
<script src="<?php echo $this->config['baseUrl'] ?>themes/<?php echo $this->config['theme'] ?>/js.php" type="text/javascript"></script>
<?php
ENDIF;
?>
Expand All @@ -31,6 +31,7 @@
_.cms = "<?php echo text::jsValue($this->cms) ?>";
_.dropUploadMaxFilesize = <?php echo isset($this->config['_dropUploadMaxFilesize']) ? intVal($this->config['_dropUploadMaxFilesize']) : "10485760" ?>;
_.langs = <?= json_encode($this->getLangs()) ?>;
_.baseUrl = "<?php echo text::jsValue($this->config['baseUrl']) ?>";
$.$.kuki.domain = "<?php echo text::jsValue($this->config['cookieDomain']) ?>";
$.$.kuki.path = "<?php echo text::jsValue($this->config['cookiePath']) ?>";
$.$.kuki.prefix = "<?php echo text::jsValue($this->config['cookiePrefix']) ?>";
Expand Down