Skip to content

Commit

Permalink
Unstable. First config refactoring for multiple users implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nightsh committed Oct 27, 2013
1 parent 41b2edb commit e0a730c
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 12 deletions.
106 changes: 106 additions & 0 deletions FinderConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* Description of FinderConfig
*
* Parses ini files to a FinderConfig Object
*
* The main instance of FinderConfig is a Singleton (and could only exist once)
* The instance could have multiple instances of FinderConfig within it self, so
* that multi dimentional array's can be parsed as a multy layered object
*
* @author niele
*
* @todo extract the path to the ini file and make it variable
*
*/
class FinderConfig
{
/**
* Path to default config file
*/
const DEFAULT_CONFIG_FILE = 'config.ini';



/**
* PlaceHolder for self (Singleton)
*
* @var FinderConfig
*/
public static $instance;



/**
* Get the Instance of self
*
* @return FinderConfig
*/
public static function getInstance()
{
if (null == self::$instance) {
self::$instance = new self;
}

return self::$instance;
}



/**
* Constructor Class
*
* @param array $config
* @access private
*/
private function __construct(array $options=array())
{
if (empty($options)) {
$options = parse_ini_file(
APPLICATION_PATH . self::DEFAULT_CONFIG_FILE,
true
);
}

$this->setConfig($options);
}



/**
* Set config options, sets recurivly if it's a multydimentional array
*
* @param array $options
* @access private
* @return FinderConfig
*/
private function setConfig(array $options=array())
{
foreach ($options as $key => $value) {

if (is_array($value) && !empty($value)) {
$value = new self($value);
}

$this->$key = $value;
}

return $this;
}



/**
* Magic method get
*
* This gets triggered if there is a call made to an undefined property in
* the FinderConfig instance or subInstance, so we throw an Exception
*
* @param string $name
* @throws Exception
*/
public function __get($name)
{
throw new Exception('call to undefined property: ' . $name);
}
}
46 changes: 46 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
disabled = false
theme = dark
uploadURL = /kcfinder/upload
uploadDir =

deny_zip_download = false
deny_update_check = false
deny_extension_rename = false

[types]
;(F)CKeditor types
files =
flash = swf
images = *img

;TinyMCE types
file =
media = swf flv avi mpg mpeg qt mov wmv asf rm
image = *img

[multiple_users]
enabled = true
lock_to_home = false
rw_homes = false
token_src = users.json
request_method = get

[image]
image_driver_priority = imagick gmagick gd
jpeg_quality = 90
thumbs_dir = .thumbs

max_image_width = 0
max_image_height = 0

thumb_width = 100
thumb_height = 100

watermark =


[access]
dir_permissions = 0755
file_permissions = 0644


12 changes: 12 additions & 0 deletions config.local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$publicDir = $_SERVER['DOCUMENT_ROOT'];
$publicUrl = 'http://'.$_SERVER['HTTP_HOST'];

$_LOCALS = array(
'theme' => 'dark',

'uploadURL' => $publicUrl . '/RES/uploads',
'uploadDir' => $publicDir . '/RES/uploads'
);

38 changes: 33 additions & 5 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
// you are using session configuration.
// See http://kcfinder.sunhater.com/install for setting descriptions

$_CONFIG = array(
$publicDir = $_SERVER['DOCUMENT_ROOT'];
$publicUrl = 'http://'.$_SERVER['HTTP_HOST'];

$_DEFAULTS = array(


// GENERAL SETTINGS

'disabled' => false,
'theme' => "dark",
'uploadURL' => "/kcfinder/upload",
'uploadDir' => "",
'disabled' => false,
'theme' => "dark",
'uploadURL' => "$publicUrl/RES/uploads",
'uploadDir' => "$publicDir/RES/uploads",

'types' => array(

Expand All @@ -39,6 +42,13 @@
'image' => "*img",
),

'multipleUsers' => array(
'enabled' => true,
'lockToHome' => false,
'rwHomes' => false,
'tokenJson' => 'users.json',
'requestMethod' => 'get'
),

// IMAGE SETTINGS

Expand Down Expand Up @@ -119,4 +129,22 @@
//'_sessionPath' => "/my/path",
);

/* Include a local config, if any
*
* This is the best place to override default settings, and add any
* business logic to the configuration. It is not advisable to hack the
* main config structure, although it may provide a quick and painless
* solution :-)
**/

if (file_exists(dirname(__FILE__) . '/config.local.php')) {
require_once dirname(__FILE__) . '/config.local.php';
}

if (isset($_LOCALS)) {
$_CONFIG = array_merge($_DEFAULTS, $_LOCALS);
} else {
$_CONFIG =& $_DEFAULTS;
}

?>
25 changes: 19 additions & 6 deletions core/browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class browser extends uploader {
public function __construct() {
parent::__construct();

//$this->errorMsg($this->post['token']);

if (isset($this->post['dir'])) {
$dir = $this->checkInputDir($this->post['dir'], true, false);
if ($dir === false) unset($this->post['dir']);
Expand All @@ -45,7 +47,7 @@ public function __construct() {
!@mkdir("$thumbsDir/{$this->type}", $this->config['dirPerms'])
)
)
$this->errorMsg("Cannot access or create thumbnails folder.");
$this->errorMsg("Cannot access or create thumbnails folder ($thumbsDir).");

$this->thumbsDir = $thumbsDir;
$this->thumbsTypeDir = "$thumbsDir/{$this->type}";
Expand Down Expand Up @@ -130,7 +132,18 @@ protected function act_init() {
if (!is_array($tree['dirs']) || !count($tree['dirs']))
unset($tree['dirs']);
$files = $this->getFiles($this->session['dir']);
$dirWritable = dir::isWritable("{$this->config['uploadDir']}/{$this->session['dir']}");

// Check if multiple users is enabled
if ($this->config->multipleUsers == true) {
$user = $_COOKIE['username'];
$uploadsTree = $this->getTree($this->session['dir']);
if (in_array($user, $uploadsTree)) {
$dirWritable = dir::isWritable("{$this->config['uploadDir']}/{$this->session['dir']}");
}
} else {
$dirWritable = dir::isWritable("{$this->config['uploadDir']}/{$this->session['dir']}");
}

$data = array(
'tree' => &$tree,
'files' => &$files,
Expand All @@ -155,9 +168,9 @@ protected function act_thumb() {
if ($image->initError)
$this->sendDefaultThumb($file);
list($tmp, $tmp, $type) = getimagesize($file);
if (in_array($type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)) &&
($image->width <= $this->config['thumbWidth']) &&
($image->height <= $this->config['thumbHeight'])
if (in_array($type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))
&& ($image->width <= $this->config['thumbWidth'])
&& ($image->height <= $this->config['thumbHeight'])
) {
$mime =
($type == IMAGETYPE_GIF) ? "gif" : (
Expand Down Expand Up @@ -722,7 +735,7 @@ protected function getFiles($dir) {
in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_PNG, IMAGETYPE_JPEG));
}
}

$stat = stat($file);
if ($stat === false) continue;
$name = basename($file);
Expand Down
2 changes: 1 addition & 1 deletion core/uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -725,4 +725,4 @@ protected function get_htaccess() {
}
}

?>
?>

0 comments on commit e0a730c

Please sign in to comment.