Using FCKeditor with CakePHP
FCKeditor is a powerful WYSIWYG editor that replaces the plain, old and boring textarea form element. It has file management functions (so you can upload images, flash and other files directly from it) and many more useful functions. To quote the FCKeditor website,
This HTML text editor brings to the web many of the powerful functionalities of desktop editors like MS Word. It's lightweight and doesn't require any kind of installation on the client computer.It is compatible with most internet browsers which include: IE 5.5+ (Windows), Firefox 1.0+, Mozilla 1.3+ and Netscape 7+. On the server side, we're going to use PHP.
The official FCKeditor site is fckeditor.net, where you can download the latest version.
From the editor/filemanager/browser/default/connectors, delete the asp, aspx, cfm, lasso, perl and py directories.
From the editor/filemanager/upload delete asp, aspx, cfm and lasso directories.
Now we've reduced the size of FCKeditor from 2.4 to 2.0 megabytes. You can also delete skins, plugins and languages that you don't want and also functionality you don't need (in dialog directory) but be careful not to break things.
In the app/webroot/js/fckconfig.js file, set:
Installation
Delete the unnecessary stuff (not required)
Since we're going to use php, it's safe to delete all other connectors.From the editor/filemanager/browser/default/connectors, delete the asp, aspx, cfm, lasso, perl and py directories.
From the editor/filemanager/upload delete asp, aspx, cfm and lasso directories.
Now we've reduced the size of FCKeditor from 2.4 to 2.0 megabytes. You can also delete skins, plugins and languages that you don't want and also functionality you don't need (in dialog directory) but be careful not to break things.
Copy stuff
Copy the editor directory, fckeditor.js, fckconfig.js, fckstyles.xml and fcktemplates.xml to your app/webroot/js directory.Configuration
Edit the app/webroot/.htaccess file and add the following two lines on the end:
AddType application/x-javascript .js
AddType text/css .css
I'm not going to go into FCKeditor configuration itself. Open the app/webroot/js/fckconfig.js file and figure it out yourself.Helper
Create the app/views/helpers/fck.phpHelper Class:
<?php
class FckHelper extends Helper
{
function load($id, $toolbar = 'Default') {
foreach (explode('/', $id) as $v) {
$did .= ucfirst($v);
}
return <<<FCK_CODE
<script type="text/javascript">
fckLoader_$did = function () {
var bFCKeditor_$did = new FCKeditor('$did');
bFCKeditor_$did.BasePath = '/js/';
bFCKeditor_$did.ToolbarSet = '$toolbar';
bFCKeditor_$did.ReplaceTextarea();
}
fckLoader_$did();
</script>
FCK_CODE;
}
}
?>
Usage
Now, all that is left is to include the fckeditor.js file on every page that is going to use it.
<?php echo $javascript->link('fckeditor'); ?>
Enable the fck helper in your controller
var $helpers = array('Html', 'Form', 'Javascript', 'Fck');
And finally, load the editor on the textarea fields that need it.
<div class="required">
<?php echo $form->labelTag( 'Comment/body', 'Body' );?>
<?php echo $html->textarea('Comment/body', array('cols' => '60', 'rows' => '10'));?>
<?php echo $fck->load('Comment/body'); ?>
<?php echo $html->tagErrorMsg('Comment/body', 'Please enter the Body.');?>
</div>
Enabling file browser/uploader
Create directories Image, Flash, Media, File in your app/webroot/files directory. Chmod them to 0777.In the app/webroot/js/fckconfig.js file, set:
var _FileBrowserLanguage = 'php';
var _QuickUploadLanguage = 'php';
To enable uploads from the 'Browse Server' window, edit the app/webroot/js/editor/filemanager/browser/default/connectors/php/config.php and set:
$Config['Enabled'] = true;
$Config['UserFilesPath'] = '/app/webroot/files/';
To enable quick uploads, edit the app/webroot/js/editor/filemanager/upload/php/config.php file and set:
$Config['Enabled'] = true;
$Config['UserFilesPath'] = '/app/webroot/files/';








http://blog.beamstyle.com.hk/?p=170
Warning (512): Method FormHelper::labelTag does not exist [CORE/cake/libs/view/helper.php, line 143]
Code | Context
$this = FormHelper
FormHelper::$helpers = array
FormHelper::$fieldset = array
FormHelper::$__options = array
FormHelper::$fields = array
FormHelper::$requestType = NULL
FormHelper::$base = "/cake"
FormHelper::$webroot = "/cake/"
FormHelper::$themeWeb = NULL
FormHelper::$here = "/cake/document"
FormHelper::$params = array
FormHelper::$action = "index"
FormHelper::$plugin = NULL
FormHelper::$data = NULL
FormHelper::$namedArgs = NULL
FormHelper::$argSeparator = NULL
FormHelper::$validationErrors = NULL
FormHelper::$tags = array
FormHelper::$__tainted = NULL
FormHelper::$__cleaned = NULL
FormHelper::$_log = NULL
FormHelper::$Html = HtmlHelper object
$method = "labelTag"
$params = array(
"Comment/body",
"Body"
)
function set__($name, $value) {}
function call__($method, $params) {
trigger_error(sprintf(__('Method %1$s::%2$s does not exist', true), get_class($this), $method), E_USER_WARNING);
Helper::call__() - CORE/cake/libs/view/helper.php, line 143
Overloadable::__call() - CORE/cake/libs/overloadable_php5.php, line 52
FormHelper::labelTag() - [internal], line ??
include - APP/views/document/index.ctp, line 4
View::_render() - CORE/cake/libs/view/view.php, line 666
View::render() - CORE/cake/libs/view/view.php, line 376
Controller::render() - CORE/cake/libs/controller/controller.php, line 803
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 230
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 194
[main] - APP/webroot/index.php, line 88
Warning (512): Method HtmlHelper::textarea does not exist [CORE/cake/libs/view/helper.php, line 143]
Code | Context
$this = HtmlHelper
HtmlHelper::$tags = array
HtmlHelper::$base = "/cake"
HtmlHelper::$here = "/cake/document"
HtmlHelper::$params = array
HtmlHelper::$action = "index"
HtmlHelper::$data = NULL
HtmlHelper::$_crumbs = array
HtmlHelper::$__docTypes = array
HtmlHelper::$helpers = NULL
HtmlHelper::$webroot = "/cake/"
HtmlHelper::$themeWeb = NULL
HtmlHelper::$plugin = NULL
HtmlHelper::$namedArgs = NULL
HtmlHelper::$argSeparator = NULL
HtmlHelper::$validationErrors = NULL
HtmlHelper::$__tainted = NULL
HtmlHelper::$__cleaned = NULL
HtmlHelper::$_log = NULL
$method = "textarea"
$params = array(
"Comment/body",
array(
"cols" => "60",
"rows" => "10"
)
)
function set__($name, $value) {}
function call__($method, $params) {
trigger_error(sprintf(__('Method %1$s::%2$s does not exist', true), get_class($this), $method), E_USER_WARNING);
Helper::call__() - CORE/cake/libs/view/helper.php, line 143
Overloadable::__call() - CORE/cake/libs/overloadable_php5.php, line 52
HtmlHelper::textarea() - [internal], line ??
include - APP/views/document/index.ctp, line 5
View::_render() - CORE/cake/libs/view/view.php, line 666
View::render() - CORE/cake/libs/view/view.php, line 376
Controller::render() - CORE/cake/libs/controller/controller.php, line 803
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 230
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 194
[main] - APP/webroot/index.php, line 88
Warning (512): Method HtmlHelper::tagErrorMsg does not exist [CORE/cake/libs/view/helper.php, line 143]
http://www.asecondsystem.com/2009/09/14/integrating-ck-editor-with-cakephp/
Hope this save a lot of time from being wasted.
editor/filemanager/browser/default/connectorsandeditor/filemanager/uploadIn v2.6.4, these folders are found in:
editor/filemanager/connectorsand the upload files are integrated.Post 20 looks semi useful but I'm stuck where Post 21 is stuck
The editor comes up however the contents of Fck does not replace the textarea before calling the action (onsubmit event)
I'd like to see a complete form. People have time to write and submit complete helpers, but not complete forms. I'm wondering if there is a "onsubmit" attribute that is assumed we know about in the construction of the forms.
The solution is very simple. Leverage the cake session. 1st you'll need to implement some cake authentication (there are lots of tutorials on this). Then put the following code in the fck connector/config.php file:
$Config['Enabled'] = false ;session_name(<value of Session.cookie in core.php>);
session_start();
if('admin' == $_SESSION['auth']){
$Config['Enabled'] = true ;
}
in my example I do $this->Session->write('auth','admin'); in my cake application. So when user is logged in, admin is set - thus he/she can upload via fck. If you do not do something like this, you are leaving a pretty big security hole open. hope this helps someone.
I then try to use it like this:
$fck->load('Item/description', 700, 400, "ItemDescription");
but when the page loads I get the following error:
ToolbarSet "ItemDescription" doesn't exist
Can anyone help me out here? I've checked the obvious things like spelling etc., but I don't really know what I'm doing so any help would be appreciated!
Thanks!
Sharon
I downloaded FCK editor and copied the editor directory, fckeditor.js, fckconfig.js, fckstyles.xml and fcktemplates.xml to my app/webroot/js directory, I also wrote the AddType application/x-javascript .js and
AddType text/css .css lines in t he .htaccess at the very end of the file (After < / IfModule>). I am using XAMPP as testing environment. Thanks!
Anyhow, this helper is a work in progress and I will update it as it improves, but I like it because it is so simple to use.
Here we go:
In your controller:
Controller Class:
<?phpvar $helpers = array('Fck');
?>
The helper: fck.php
Helper Class:
<?php
<?php class FckHelper extends Helper {
var $helpers = Array('Html');
function startup(&$model) {
pr(&$model); die;
$this->controller = &$controller;
if(isset($controller->max_cache_age)){
$this->max_cache_age = $controller->max_cache_age;
}
$this->cache_location = CACHE.'thumbs'.DS;
}
function input($field, $width = 400) {
$field = explode('.', $field);
if(empty($field[1])) {
// need to know how to call a model from a helper
} else {
$model = $field[0];
$controller = $field[1];
}
require_once WWW_ROOT.DS.'js'.DS.'fckeditor'.DS.'fckeditor.php';
$oFCKeditor = new FCKeditor('data['.$model.']['.$controller.']') ;
$oFCKeditor->BasePath = DS.'js'.DS.'fckeditor'.DS ;
$oFCKeditor->Value = $this->data[$model][$controller];
$oFCKeditor->Height = $width;
$oFCKeditor->Create();
}
}
?>
?>
Then, all you need to do in your view is:
View Template:
echo $fck->input('Page.content');
I am not sure if other FCK helpers do this, however mine will remember the content just like the form helper does.
I will submit improves as I make this more cakie, if anyone can help please feel free to submit a patch.
Helper Class:
<?php
<?php class FckHelper extends Helper {
var $helpers = Array('Html');
function input($field, $width = 400) {
$field = explode('.', $field);
if(empty($field[1])) {
// need to know how to call a model from a helper
} else {
$model = $field[0];
$controller = $field[1];
}
require_once WWW_ROOT.DS.'js'.DS.'fckeditor'.DS.'fckeditor.php';
$oFCKeditor = new FCKeditor('data['.$model.']['.$controller.']') ;
$oFCKeditor->BasePath = DS.'js'.DS.'fckeditor'.DS ;
$oFCKeditor->Value = $this->data[$model][$controller];
$oFCKeditor->Height = $width;
$oFCKeditor->Create();
}
}
?>
?>
Thank you! I just had to adjust $oFCKeditor->BasePath in helpers/fck.php and it worked perfectly. :)
Only when trying to use any popup iframe I'm getting the missing controller error for JsController.
Any ideas how to fix it?
I have the same problem. Anyone has a solution?
Sorry for my bad English but I've a little adapted this script for Cake 1.2 :
Helper Class:
<?php class FckHelper extends Helper {
var $helpers = Array('Html');
function load($id, $toolbar = 'Default') {
$did = '';
foreach (explode('.', $id) as $v) {
$did .= ucfirst($v);
}
$basePath = '/js/fckeditor/';
$basePath = $this->Html->url($basePath);
return <<<FCK_CODE
<script type="text/javascript">
fckLoader_{$did} = function () {
var bFCKeditor_{$did} = new FCKeditor('{$did}');
bFCKeditor_{$did}.BasePath = '{$basePath}';
bFCKeditor_{$did}.ToolbarSet = '{$toolbar}';
bFCKeditor_{$did}.ReplaceTextarea();
}
fckLoader_{$did}();
</script>
FCK_CODE;
}
}
?>
Usage : $fck->load('Model.field');
For the filemanager, here is my code that work correctly (put it in good place in the .../connector/php/config.php file):
$userFolder = 'files'; // -> /app/webroot/files/
// Path to user files relative to the document root.
$Config['UserFilesPath'] = str_replace(strstr($_SERVER['PHP_SELF'], '/app/webroot/'), "/{$userFilesFolder}/", $_SERVER['PHP_SELF']) ;
// Fill the following value it you prefer to specify the absolute path for the
// user files directory. Useful if you are using a virtual directory, symbolic
// link or alias. Examples: 'C:\\MySite\\userfiles\\' or '/root/mysite/userfiles/'.
// Attention: The above 'UserFilesPath' must point to the same directory.
$separator = ereg('/', __FILE__) ? '/' : '\\';
$tofind = $separator . 'app' . $separator . 'webroot' . $separator;
$toadd = $tofind . $userFolder . $separator;
$Config['UserFilesAbsolutePath'] = str_replace(strstr(__FILE__, $tofind), $toadd, __FILE__) ;
I have a little code for delete uploaded files with the filemanager.
The explications are on my website (in French) : http://seebz.be/blog/33-supprimer-un-fichier-du-filemanager-de-fckeditor.html
Thanks
View:
echo $javascript->link('/fck/fckeditor.js', true);
echo $fck->load(null, '500', '900', null); ?>
echo $form->input('Content.body', array('type' => 'textarea', 'label' => 'Page Content<br />'));
echo $fck->editor('Content.body');
Helper:
class FckHelper extends AppHelper
{
var $helpers = array('Javascript');
function load( $template = 'default', $height = '300', $width = '650', $toolbar = 'Default' )
{
$jsDS = '/'; //because \' only suxx in javascript
$js = $this->webroot . 'js' . $jsDS . 'fck' . $jsDS;
$skinDir = $js . 'editor' . $jsDS . 'skins' . $jsDS;
$templateDir = $skinDir . (is_dir( $skinDir . $template ) ? $template : 'default') . $jsDS;
$code = "fckLoader = function ( ID ) {";
$code .= " var bFCKeditor = new FCKeditor( ID );";
$code .= " bFCKeditor.BasePath = '" . $js . "';";
$code .= " bFCKeditor.ToolbarSet = '" . $toolbar . "';";
$code .= " bFCKeditor.SkinPath = '" . $templateDir . "';";
$code .= " bFCKeditor.Height = " . $height . ";";
$code .= " bFCKeditor.Width = " . $width . ";";
$code .= " bFCKeditor.ReplaceTextarea();";
$code .= " }";
$this->Javascript->link('fck/fckeditor.js', true); // add it to the header
return $this->Javascript->codeBlock($code);
}
function editor( $fieldName )
{
$seperator = (strstr($fieldName, '.') ? '.' : '/');
$id = Inflector::camelize( str_replace($seperator, '_', $fieldName) );
$code = "fckLoader('" . $id . "');";
return $this->Javascript->codeBlock($code);
}
}
// Path to user files relative to the document root. cakephp mod::
$Config['UserFilesPath'] = preg_replace('/js\/editor\/filemanager\/connectors\/php\/connector\.php(.*)$/','',$_SERVER['REQUEST_URI']) . 'files/';
// Fill the following value it you prefer to specify the absolute path for the
// user files directory. Useful if you are using a virtual directory, symbolic
// link or alias. Examples: 'C:\\MySite\\userfiles\\' or '/root/mysite/userfiles/'.
// Attention: The above 'UserFilesPath' must point to the same directory.
$Config['UserFilesAbsolutePath'] = '../../../../../files/' ;
I used the code from posting 11 by Hajo (thanks for his ground work), but replaced
withreturn $this->Javascript->link('fckeditor/fckeditor.js') . $this->Javascript->codeBlock($code);
Notice that I renamed the folder where the javascripts resides, as it seemed that cake 1.2 got crazy when the script (minus the js extension) and folder name is equal, he always wanted to open the js action.$this->Javascript->link('fck/fckeditor.js', false); // add it to the header
return $this->Javascript->codeBlock($code);
Also remember to alter the second line of the load function to reflect your path name (and with it the fckeditor basepath), as you will get in further trouble when fckeditor tries to load the html file to the editor box (I got the "need JSController" error).
In the view I use the following code before the form creation:
In the form I use the following code:<?php echo $fck->load(null, '500', '900', null); ?>
Hope this helps, as it works for me fine.echo $form->input('source_html', array('type' => 'textarea'));
echo $fck->editor('Emailad.source_html'); // Emailad is the model name used in the form creation, the editor function will transfer it to EmailadSourceHtml, which is the actual form field name.
I think for Cake 1.2 it should work off the form helper, i.e. $form->fck etc.
Anyone up for writing it?
Im using fckedit in a website, im using the helper from above (at least one of them im not sure if the original version).
The problem is, i have my webserver setup on localhost for working before deploying. The address of the website is something like: http://localhost/site
The path is something like: D:/www/site
The cake is inside 'site' directory. I have set up in a config.php file i found in fckeditor directory (i couldnt find the exact path specified in the article, maybe its because im using fckedit 2.5), i set up the upload path to:
/app/webroot/files/. Now comes the problem: the files DO get upload, but not inside the 'site' (site/app/webroot/....'), but in the root of my localhost , the structure of dirs app/webroot/files is created in D:/www.
I guess the problems comes from the fckedit PHP config setting: /app/webroot/files , / being here localhost and not localhost/site.
I hope i have been clear enough, maybe someone has some ideeas. Thanks.
PS: im using windows but i used / in path because after posting , the other slashes are just removed
EDIT: Forgot to mention it, i think it could be easily solved if we could use the $html->url function of cake when specifying the directories in the config.php file of fckedit, but i dont know how to access it.
Thanks in Advance.
Kipp
View Template:
Título:
<?php echo $html->textarea('Venta/titulo', array('rows'=>'10')) ?>
<?php echo $html->tagErrorMsg('Venta/titulo', 'El campo título es requerido.') ?>
<?php echo $fck->load('Venta/titulo','800','150'); ?>
</p>
<p>
Situación:
<?php echo $html->input('Venta/situacion', array('size' => '40'))?>
<?php echo $html->tagErrorMsg('Venta/situacion', 'El campo título es requerido.') ?>
</p>
<p>
Descripción:
<?php echo $html->textarea('Venta/descripcion', array('rows'=>'10')) ?>
<?php echo $html->tagErrorMsg('Venta/descripcion', 'Cuerpo de la Venta requerido.') ?>
<?php echo $fck->load('Venta/descripcion','800','300'); ?>
How could i disable in the first Fck Box the bars or buttons that i don´t want to be enabled?
Ej: box 1 i dont want pictures nor justify settings or font
types...
Thanks in advance
structure:
/app/webroot/fckeditor
- fckeditor.js
- editor (DIR)
....
use:
$fck->load(); in the body tag
$fck->editor(
Helper Class:
<?php
class FckHelper extends AppHelper
{
var $helpers = array('Javascript');
function load( $template = 'default', $height = '300', $width = '650', $toolbar = 'Default' )
{
$jsDS = '/'; //because \' only suxx in javascript
$js = $this->webroot . 'js' . $jsDS . 'fckeditor' . $jsDS;
$skinDir = $js . 'editor' . $jsDS . 'skins' . $jsDS;
$templateDir = $skinDir . (is_dir( $skinDir . $template ) ? $template : 'default') . $jsDS;
$code = "fckLoader = function ( ID ) {";
$code .= " var bFCKeditor = new FCKeditor( ID );";
$code .= " bFCKeditor.BasePath = '" . $js . "';";
$code .= " bFCKeditor.ToolbarSet = '" . $toolbar . "';";
$code .= " bFCKeditor.SkinPath = '" . $templateDir . "';";
$code .= " bFCKeditor.Height = " . $height . ";";
$code .= " bFCKeditor.Width = " . $width . ";";
$code .= " bFCKeditor.ReplaceTextarea();";
$code .= " }";
return $this->Javascript->link('fckeditor/fckeditor.js') . $this->Javascript->codeBlock($code);
}
function editor( $fieldName )
{
$seperator = (strstr($fieldName, '.') ? '.' : '/');
$id = Inflector::camelize( str_replace($seperator, '_', $fieldName) );
$code = "fckLoader('" . $id . "');";
return $this->Javascript->codeBlock($code);
}
}
?>
/app/webroot/files/
to
/files/
In helpers/fck.php, replace:
foreach (explode('/', $id) as $v) {
$did .= ucfirst($v);
}
With:
foreach (explode('[', str_replace(']','', $id)) as $v) {
$did .= ucfirst($v);
}
Replace:
var bFCKeditor_$did = new FCKeditor('$did');
With:
var bFCKeditor_$did = new FCKeditor('$id');
And in the view, instead of:
load('Comment/body'); ?>
Use:
load('data[Comment][body]'); ?>
Hope this helps!
Eric
This line:
$output .= "$(id).value = fileUrl;n";
To this line:
$output .= "document.getElementById('".$htmlAttributes['id']."').value = fileUrl;\n";
Can someone explain how to pass Session variables to the editor filemanager browser default connectors php config.php ?
1. Include the fckeditor.php in your Cake vendors directory
/app
/app/etc
/cake
/cake/etc
/vendors
/vendors/fckeditor.php
This file comes packaged with FCKeditor in the root of the zipped package.
2. Include the fckeditor.php include via vendors
// include required vendors
vendor('fckeditor');
Do this prior to component / controller stuff.
Apologies, hope this helps.
Thanks for this little titbit, very informative!
I don't know if this will be useful to someone but I've gone for the PHP integration approach.
Reference on the wiki:
http://wiki.fckeditor.net/Developer%27s_Guide/Integration/PHP
I've actually put this in to a form component that I use to complete repeitive tasks that might be required on any particular page that includes a form (hence the reference to $this->controller).
From the component / controller level:
NOTES:
- $id - is a unique id that I pass from the controller in case there is a requirement for more than one editor on a page
- ToolbarSet = Cake - I've created a cut down version of the toolbar in my custom configuration file that I've called Cake
At the helper / view level:
NOTES:
- $field_name - In the format data[Model][field] - $value - I obtain this using HTML helpers tagValue function
Which leads me to the pesky h() function. The tagValue function employs the h() function in a capacity I can only assume is in replacement of htmlentities. Generally a fantastic shortcut but in this instance creating havoc for the content I'm attempting to insert in to my FCKeditor area. So:
WARNING: Beware h() in $html->tagValue('Model/field');
Additional Stuff:
My custom toolbar
Thanks again Marko!
load('Comment/body', 500, 300); ?>
Helper class:
class FckHelper extends HtmlHelper {
var $Width = 500;
var $Height = 300;
function load($id, $width=null, $height=null, $toolbar = 'Default') {
$did = Inflector::camelize(str_replace('/', '_', $id));
if($width){ $this->Width = $width; }
if($height){ $this->Height = $height; }
$js = $this->webroot.'js/';
return<<
var bFCKeditor_$did = new FCKeditor('$did');
bFCKeditor_$did.BasePath = '$js';
bFCKeditor_$did.ToolbarSet = '$toolbar';
bFCKeditor_$did.Width = $this->Width;
bFCKeditor_$did.Height = $this->Height;
bFCKeditor_$did.ReplaceTextarea();
}
fckLoader_$did();
FCK_CODE;
}
function fileBrowserInput($fieldName, $htmlAttributes = array(), $return = false) {
$output = $this->input($fieldName, $htmlAttributes, $return);
if (!isset($htmlAttributes['id'])) {
$htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
}
$output .= '';
$output .= "// $output .= "function openFileBrowser(id){\n";
$output .= "var fck = new FCKeditor(id);\n";
$output .= "fck.BasePath = '".$this->webroot."js/'\n";
$output .= "var url = fck.BasePath + 'editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/php/connector.php';\n";
$output .= "var sOptions = 'toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes';\n";
$output .= "sOptions += ',width=640';\n";
$output .= "sOptions += ',height=480';\n";
$output .= "window.SetUrl = function(fileUrl){\n";
$output .= "\$(id).value = fileUrl;\n";
$output .= "}\n";
$output .= "var oWindow = window.open( url, 'FCKBrowseWindow', sOptions ) ;\n";
$output .= "}\n";
$output .= "//]]>\n";
$output .= '';
$output .= 'select an image...';
return $output;
}
}
?>
<?php
class FckHelper extends HtmlHelper {
function load($id, $toolbar = 'Default') {
$did = Inflector::camelize(str_replace('/', '_', $id));
$js = $this->webroot.'js/';
return<<<FCK_CODE
<script type="text/javascript">
fckLoader_$did = function () {
var bFCKeditor_$did = new FCKeditor('$did');
bFCKeditor_$did.BasePath = '$js';
bFCKeditor_$did.ToolbarSet = '$toolbar';
bFCKeditor_$did.ReplaceTextarea();
}
fckLoader_$did();
</script>
FCK_CODE;
}
function fileBrowserInput($fieldName, $htmlAttributes = array(), $return = false) {
$output = $this->input($fieldName, $htmlAttributes, $return);
if (!isset($htmlAttributes['id'])) {
$htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);
}
$output .= '<script type="text/javascript">';
$output .= "//<![CDATA[\n";
$output .= "function openFileBrowser(id){\n";
$output .= "var fck = new FCKeditor(id);\n";
$output .= "fck.BasePath = '".$this->webroot."js/'\n";
$output .= "var url = fck.BasePath + 'editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/php/connector.php';\n";
$output .= "var sOptions = 'toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes';\n";
$output .= "sOptions += ',width=640';\n";
$output .= "sOptions += ',height=480';\n";
$output .= "window.SetUrl = function(fileUrl){\n";
$output .= "\$(id).value = fileUrl;\n";
$output .= "}\n";
$output .= "var oWindow = window.open( url, 'FCKBrowseWindow', sOptions ) ;\n";
$output .= "}\n";
$output .= "//]]>\n";
$output .= '</script>';
$output .= '<a href="#" onclick="openFileBrowser(\''.$htmlAttributes['id'].'\'); return false;">select an image...</a>';
return $output;
}
}
?>
But I can't seem to make it work.
The textarea returns every time with a 404 error.
What could I be doing wrong? Please help.
Using the extended script, by Wouter Verweirder, solved my problems. Don't know what's wrong with the original one.
Thanx Wouter!!
Comments are closed for articles over a year old