I have built a Laravel 3 application, it involves a lot of per-user content management.
For prototype and internal testing I got away with plain configuration of KCFinder, now we're about to start a closed beta.
Firstly, I must lock the KCFinder behind Laravel applications Auth system.
Secondly, I must configure the KCF with a per-user settings.
While it may seem like those are two questions, I doubt they are.
My Laravel is installed in /srv/http/
, KCFinder in /srv/http/public/php/kcfinder/
.
KCFinder exposes two incoming files - browse.php
and upload.php
. These files include core/autoload.php
, that ultimately ties the KCF together.
I tried requiring Laravel's public/index.php
inside it, then tried to access something KCF (/php/kcfinder/browse.php
) through browser. Got redirected to a mix of the request path and Laravel applications root route: /php/kcfinder/browser
.
How could I prevent the Routing from Laravel and be able to use Laravel inside the KCF scope?
P.S. I did try to go the Bundle way, but apparently KCF is so poorly written that it appears that in order to Bundle it up, I'll have to rewrite everything there.
I managed to do it with a very, very dirty hack.
In /srv/http/public/php/kcfinder/core/autoload.php
I appended the lines:
require '../../../paths.php';
require path('sys').'core.php';
\Laravel\Bundle::start(DEFAULT_BUNDLE);
$KCFinderRoot = addslashes(realpath(dirname(__FILE__). '/../') . DS);
\Laravel\Autoloader::map(array(
'browser' => $KCFinderRoot . 'core/browser.php',
'uploader' => $KCFinderRoot . 'core/uploader.php',
'type_img' => $KCFinderRoot . 'core/types/type_img.php',
'type_mime' => $KCFinderRoot . 'core/types/type_mime.php',
'gd' => $KCFinderRoot . 'lib/class_gd.php',
'input' => $KCFinderRoot . 'lib/class_input.php',
'zipFolder' => $KCFinderRoot . 'lib/class_zipFolder.php',
'dir' => $KCFinderRoot . 'lib/helper_dir.php',
'file' => $KCFinderRoot . 'lib/helper_file.php',
'httpCache' => $KCFinderRoot . 'lib/helper_httpCache.php',
'path' => $KCFinderRoot . 'lib/helper_path.php',
'text' => $KCFinderRoot . 'lib/helper_text.php',
));
if (!\Laravel\Auth::check())
{
die('no user :(');
}
Wherever KCF had some file inclusions, I had to squeeze in $KCFinderRoot
, in some methods even requiring to global
them before.
In KCF's config I added:
// ...
'uploadURL' => "/useruploads/" . sha1(Auth::user()->id . Auth::user()->email),
'uploadDir' => path('public') . "useruploads/" . sha1(Auth::user()->id . Auth::user()->email),
// ...
The end result works like I wanted it to, except I have no idea how "smart" this is.
P.S. In the following days I'm going to try to bundle, IoC this up while leaving KCF files intact.