I have modified my configuration to allow multiple users to have different folders (not just limited to users, its possible to set as many parameters as required to have countless combinations of "root" folders)
I tried to achieve this with minimal disruption to the FCKEditor code.
It's a PHP solution which makes use of $_SERVER['PATH_INFO'].
Here's what I did:
Step 1)
When I create the instance of FCKEditor, I supply an extra parameter to the Config object.
I called it DynamicParams but it could be called ConnectorParams, InstanceParams etc.
NOTE: the values in the parameter can be used to do more than just enhance the connector so it should have a fairly generic name.
Here's an example, with user:
var oFCKeditor = new FCKeditor('editor', '100%', '400');
oFCKeditor.Config.DynamicParams = 'mode:user;id:$user_id';
oFCKeditor.ReplaceTextarea();
Some other examples of the extra parameter:
oFCKeditor.Config.DynamicParams = 'mode:homepage';
oFCKeditor.Config.DynamicParams = 'mode:folder;id:2';
oFCKeditor.Config.DynamicParams = 'mode:page;id:mypage';
Step 2)
This is the only real change to the FCKEditor code.
In the file fck_startup.js I add a single line:
window.onload=function(){
FCKScriptLoader.OnEmpty=function(){
FCKConfig.LoadHiddenField();
---> FCKScriptLoader.AddScript('../fckconfig.php/' + FCKConfig.DynamicParams + '/'); <---
LoadStyles();
};
FCKScriptLoader.AddScript('../fckconfig.js');
};
What this does is call a php file which *dynamically* generates a javascript config file.
The magic here is the fact that I add my new parameter into the PATH_INFO - you will see below how this helps us a lot!
Step 3)
The benefit of the dynamic javascript config file is that you could return different configs based on your new parameter.
In this step, remove the configuration items from fckconfig.js that you would like to be dynamically generated.
I removed all items after:
FCKConfig.ToolbarCanCollapse = true ;
Step 4)
Create fckconfig.php (same folder as fckconfig.js) and paste in the javascript config items you removed from above.
TIP: Here you can be smart and generate different toolbars for different users, based on your new parameter info!
Here's where I add the extra parameter to the PATH_INFO of the connector.
This way, when FCKeditor calls the connector, the extra parameters are snuck in before it does its ?Command= etc.
So when the call is made it will be something like:
connector.php/mode:user;id:214/?Command=Files&...
NOTE: $_SERVER['PATH_INFO'] still includes /'s e.g. /mode:user;id:214/ so I can just echo it after connector.php
FCKConfig.ToolbarSets = new Object() ;
FCKConfig.ToolbarSets["Default"] = [
..
FCKConfig.LinkUploadURL =
FCKConfig.BasePath +
"filemanager/browser/default/browser.html?Connector=" +
FCKConfig.BasePath +
..
FCKConfig.ImageBrowserURL =
FCKConfig.BasePath +
"filemanager/browser/default/browser.html?Type=Image&Connector=" +
FCKConfig.BasePath +
Step 5)
We are almost there, we just need to modify the config.php of the connector to extract the PATH_INFO parameter then decide what the configuration should be.
I also crete the folders if they dont exist, and add a symlink to a shared Image folder (this should be a readonly folder)
$path_info = trim($_SERVER['PATH_INFO'], '/');
$params = split(';', $path_info);
foreach ($params as $param_and_value) {
list($param, $value) = split(':', $param_and_value);
$DynamicParams[$param] = $value;
}
// now use the information to decide the appropriate paths
switch($DynamicParams['mode']) {
case 'user':
$config['UserFilesPath'] = '/public/user/' . $DynamicParams['id'];
$folders_ok = init_fckeditor_folders($config['UserFilesPath']);
break;
case 'page':
$config['UserFilesPath'] = '/public/page/' . $DynamicParams['id'];
$folders_ok = init_fckeditor_folders($config['UserFilesPath']);
break;
default:
$config['UserFilesPath'] = '/public/unknown';
$folders_ok = init_fckeditor_folders($config['UserFilesPath']);
break;
}
// ------------------------------------------------------------------------- //
function init_fckeditor_folders($resource_dir) {
$base_dir = BASE_DIR . 'htdocs' . $resource_dir;
// see if the base dir exists
if(!file_exists($base_dir)) {
$success = @mkdir($base_dir);
if(!$success) return false;
}
$resource_folders = array('File', 'Flash', 'Image', 'Media');
foreach($resource_folders as $resource_folder) {
if(!file_exists($folder = $base_dir . '/' . $resource_folder)) {
$success = @mkdir($folder);
if(!$success) return false;
}
}
// see if we have the symlinks to shared files
foreach(array('Image') as $shared_resource) {
if(!file_exists($folder = $base_dir . '/' . $shared_resource . '/shared')) {
$target = BASE_DIR . 'htdocs/public/shared/' . $shared_resource;
symlink($target, $folder);
}
}
return true;
}
// ------------------------------------------------------------------------- //
Step 6)
Thats it, you are done! I welcome any feedback and I'd like to hear how you use different modes to generate custom configs etc.
Ally
I tried to achieve this with minimal disruption to the FCKEditor code.
It's a PHP solution which makes use of $_SERVER['PATH_INFO'].
Here's what I did:
Step 1)
When I create the instance of FCKEditor, I supply an extra parameter to the Config object.
I called it DynamicParams but it could be called ConnectorParams, InstanceParams etc.
NOTE: the values in the parameter can be used to do more than just enhance the connector so it should have a fairly generic name.
Here's an example, with user:
var oFCKeditor = new FCKeditor('editor', '100%', '400');
oFCKeditor.Config.DynamicParams = 'mode:user;id:$user_id';
oFCKeditor.ReplaceTextarea();
Some other examples of the extra parameter:
oFCKeditor.Config.DynamicParams = 'mode:homepage';
oFCKeditor.Config.DynamicParams = 'mode:folder;id:2';
oFCKeditor.Config.DynamicParams = 'mode:page;id:mypage';
Step 2)
This is the only real change to the FCKEditor code.
In the file fck_startup.js I add a single line:
window.onload=function(){
FCKScriptLoader.OnEmpty=function(){
FCKConfig.LoadHiddenField();
---> FCKScriptLoader.AddScript('../fckconfig.php/' + FCKConfig.DynamicParams + '/'); <---
LoadStyles();
};
FCKScriptLoader.AddScript('../fckconfig.js');
};
What this does is call a php file which *dynamically* generates a javascript config file.
The magic here is the fact that I add my new parameter into the PATH_INFO - you will see below how this helps us a lot!
Step 3)
The benefit of the dynamic javascript config file is that you could return different configs based on your new parameter.
In this step, remove the configuration items from fckconfig.js that you would like to be dynamically generated.
I removed all items after:
FCKConfig.ToolbarCanCollapse = true ;
Step 4)
Create fckconfig.php (same folder as fckconfig.js) and paste in the javascript config items you removed from above.
TIP: Here you can be smart and generate different toolbars for different users, based on your new parameter info!
Here's where I add the extra parameter to the PATH_INFO of the connector.
This way, when FCKeditor calls the connector, the extra parameters are snuck in before it does its ?Command= etc.
So when the call is made it will be something like:
connector.php/mode:user;id:214/?Command=Files&...
NOTE: $_SERVER['PATH_INFO'] still includes /'s e.g. /mode:user;id:214/ so I can just echo it after connector.php
<?php header("Content-type: text/plain"); $path_info = $_SERVER['PATH_INFO']; ?>
FCKConfig.ToolbarSets = new Object() ;
FCKConfig.ToolbarSets["Default"] = [
..
FCKConfig.LinkUploadURL =
FCKConfig.BasePath +
"filemanager/browser/default/browser.html?Connector=" +
FCKConfig.BasePath +
"filemanager/browser/default/connectors/php/connector.php<?echo $path_info; ?>" ;
..
FCKConfig.ImageBrowserURL =
FCKConfig.BasePath +
"filemanager/browser/default/browser.html?Type=Image&Connector=" +
FCKConfig.BasePath +
"filemanager/browser/default/connectors/php/connector.php<?echo $path_info; ?>" ;
Step 5)
We are almost there, we just need to modify the config.php of the connector to extract the PATH_INFO parameter then decide what the configuration should be.
I also crete the folders if they dont exist, and add a symlink to a shared Image folder (this should be a readonly folder)
$path_info = trim($_SERVER['PATH_INFO'], '/');
$params = split(';', $path_info);
foreach ($params as $param_and_value) {
list($param, $value) = split(':', $param_and_value);
$DynamicParams[$param] = $value;
}
// now use the information to decide the appropriate paths
switch($DynamicParams['mode']) {
case 'user':
$config['UserFilesPath'] = '/public/user/' . $DynamicParams['id'];
$folders_ok = init_fckeditor_folders($config['UserFilesPath']);
break;
case 'page':
$config['UserFilesPath'] = '/public/page/' . $DynamicParams['id'];
$folders_ok = init_fckeditor_folders($config['UserFilesPath']);
break;
default:
$config['UserFilesPath'] = '/public/unknown';
$folders_ok = init_fckeditor_folders($config['UserFilesPath']);
break;
}
// ------------------------------------------------------------------------- //
function init_fckeditor_folders($resource_dir) {
$base_dir = BASE_DIR . 'htdocs' . $resource_dir;
// see if the base dir exists
if(!file_exists($base_dir)) {
$success = @mkdir($base_dir);
if(!$success) return false;
}
$resource_folders = array('File', 'Flash', 'Image', 'Media');
foreach($resource_folders as $resource_folder) {
if(!file_exists($folder = $base_dir . '/' . $resource_folder)) {
$success = @mkdir($folder);
if(!$success) return false;
}
}
// see if we have the symlinks to shared files
foreach(array('Image') as $shared_resource) {
if(!file_exists($folder = $base_dir . '/' . $shared_resource . '/shared')) {
$target = BASE_DIR . 'htdocs/public/shared/' . $shared_resource;
symlink($target, $folder);
}
}
return true;
}
// ------------------------------------------------------------------------- //
Step 6)
Thats it, you are done! I welcome any feedback and I'd like to hear how you use different modes to generate custom configs etc.
Ally
RE: Multi User Folders - mcukstorm php connec
I have had a play and i believe i may have a slightly simpler and generic solution.
When constructing the editor most integration classes allow the setting of extra configurations options, my PHP one is no exception. So you could set the path to the ImageBrowserURL in the PHP file constructing the FCKEditor and add an extra bit to the URL, like &ExtraParams=mode:user:userid:233 this would be passed to the file browser, then you just need to insert two lines to get that data sent to the connector. /filemanager/browser/default/js/common.js
add below line 60:
oConnector.ExtraParams = GetUrlParam( 'ExtraParams') ;
add below line 69:
sUrl += '&ExtraParams=' + this.ExtraParams ;
you can now get the information passed in the ExtraParams in the connector/config.php using $_GET['ExtraParams']