Hi, this is my HTML_Quickform_element extension for the FCKEditor.
I hope copy/paste worked out well.
It has all the normal element features I think, plus a specific method:
setFckProps(). The arguments are:
- The Basepath (absolute path from root tested only)
- Name of the toolbarset
- Width
- Height
- The config options, an associaltive array with as key the exact configkey, like 'GeckoUseSpan'and stuff. Write it wrong and it is ignored. Everything in fckconfig.js until StylesXmlPath is supported ... you can add extra in the private var array $_aFckConfigProps.
A note on the skinpath. If a relative path is given, it will be preceded by the set basepath.
If any options in the method is set to NULL, the default value will be kept.
Anyone wanna test it please?
I hope copy/paste worked out well.
It has all the normal element features I think, plus a specific method:
setFckProps(). The arguments are:
- The Basepath (absolute path from root tested only)
- Name of the toolbarset
- Width
- Height
- The config options, an associaltive array with as key the exact configkey, like 'GeckoUseSpan'and stuff. Write it wrong and it is ignored. Everything in fckconfig.js until StylesXmlPath is supported ... you can add extra in the private var array $_aFckConfigProps.
A note on the skinpath. If a relative path is given, it will be preceded by the set basepath.
If any options in the method is set to NULL, the default value will be kept.
<?php /** * Custom HTML_Quickform elementtype voor FCKEditor textarea * * This elementtype buidls an FCK Editor instance for PEAR::HTML_Quick_websitform * class * * @author Jordi Backx */ class HTML_Quickform_fckeditor extends HTML_Quickform_element { /** * Path to FCK class * * @var string Path to PHP FCK class * @access private */ var $_sFckBasePath = NULL; /** * Toolbar * * @var string Requested toolbarset * @access private */ var $_sToolbarSet = NULL; /** * Height of editor * * @var string Height * @access private */ var $_sHeight = NULL; /** * Width of editor * * @var string Width * @access private */ var $_sWidth = NULL; /** * FCK properties * * @var array Set of FCK only properties * @access private */ var $_aFckConfigProps = array('CustomConfigurationsPath' => NULL ,'EditorAreaCSS' => NULL ,'Debug' => NULL ,'SkinPath' => NULL ,'PluginsPath' => NULL ,'AutoDetectLanguage' => NULL ,'DefaultLanguage' => NULL ,'EnableXHTML' => NULL ,'EnableSourceXHTML' => NULL ,'GeckoUseSPAN' => NULL ,'StartupFocus' => NULL ,'ForcePasteAsPlainText' => NULL ,'ForceSimpleAmpersand' => NULL ,'TabSpaces' => NULL ,'UseBROnCarriageReturn' => NULL ,'LinkShowTargets' => NULL ,'LinkTargets' => NULL ,'LinkDefaultTarget' => NULL ,'ToolbarStartExpanded' => NULL ,'ToolbarCanCollapse' => NULL ,'StylesXmlPath' => NULL ); /** * Class constructor * * @param string $sElementName Name attribute of element * @param mixed $mElementLabel Label attribute of element * @param mixed $mAttributes Other non-FCK optional attributes * * @access public * @return void */ function HTML_Quickform_fckeditor($sElementName = NULL ,$mElementLabel = NULL ,$mAttributes = NULL) { HTML_Quickform_element::HTML_Quickform_element($sElementName, $mElementLabel, $mAttributes); $this->_persistantFreeze = TRUE; $this->_type = 'fckeditor'; }// End constructor /** * Set properties for FCKEditor instance * * @param string $sFckBasePath Basepath * @param string $sFckStylesXMLPath Path to XML styles * @param string $sToolbarSet Toolbar * @param string $sWidth Width of the editor * @param string $sHeight Height of the editor * @param mixed $mFckRequestedAttrs Set of FCK only attributes * @access public * @return void */ function setFCKProps ($sFckBasePath = NULL ,$sToolbarSet = NULL ,$sWidth = NULL ,$sHeight = NULL ,$mFckRequestedAttrs = NULL) { /* * Set the paths */ $this->_sFckBasePath = $sFckBasePath; /* * Set public FCK attributes */ $this->_sWidth = $sWidth; $this->_sHeight = $sHeight; $this->_sToolbarSet = $sToolbarSet; /* * Set configuration array if not NULL */ if ($mFckRequestedAttrs !== NULL) { // Collect keys of requested attributes $aFckRequestedAttrKeys = array_keys($mFckRequestedAttrs); // Search in supported attribute array for the keys foreach ($this->_aFckConfigProps as $sFckProp => $sFckValue) { $mArraySearchResult = array_search($sFckProp, $aFckRequestedAttrKeys); if ($mArraySearchResult === FALSE) { unset($this->_aFckConfigProps[$sFckProp]); } else { $this->_aFckConfigProps[$sFckProp] = $mFckRequestedAttrs[$sFckProp]; } } } else { // No properties requested $this->_aFckConfigProps[$sFckProp] = NULL; } } /** * Register name atribute * * @param string $sName Name attribute of element * @access public * @return void */ function setName($sName) { $this->updateAttributes(array('name' => $sName)); }// End function setName /** * Naam teruggeven (name attribute) * * @access public * @return string Name attribute element */ function getName() { return $this->getAttribute('name'); }// End function getName /** * Waarde/inhoud registreren (value attribute) * * @param string $sWaarde Value attribute of element * @access public * @return void */ function setValue($sValue) { $this->updateAttributes(array('value' => $sValue)); }// End function setValue /** * Waarde/inhoud teruggeven(value attribute) * * @access public * @return string Value attribute element */ function getValue() { return $this->getAttribute('value'); }// End function getValue /** * HTML code genereren en teruggeven * * @access public * @return string HTML code element */ function toHtml() { if ($this->_flagFrozen) { return $this->getFrozenHtml(); } else { /* * FCK editor aanmaken */ // FCKeditor klasse inladen require_once('mod_fckeditor.inc.php'); // instantiëring $oFCKeditor = new FCKeditor($this->getAttribute('name')); // Parameters instellen if ($this->_sToolbarSet !== NULL) { $oFCKeditor->BasePath = $this->_sFckBasePath; } if ($this->_sToolbarSet !== NULL) { $oFCKeditor->ToolbarSet = $this->_sToolbarSet; } if ($this->_sWidth !== NULL) { $oFCKeditor->Width = $this->_sWidth; } if ($this->_sHeight !== NULL) { $oFCKeditor->Height = $this->_sHeight; } if ($this->_aFckConfigProps !== NULL) { $oFCKeditor->Config = $this->_aFckConfigProps; // If a relative path is given, then precede it with the editor's baspath (like in fckconfig.js)' if (isset($oFCKeditor->Config['SkinPath']) && substr($oFCKeditor->Config['SkinPath'], 0, 1) != '/') { $oFCKeditor->Config['SkinPath'] = $this->_sFckBasePath.$oFCKeditor->Config['SkinPath']; } } $oFCKeditor->Value = $this->getValue(); // Generate the HTML code for the editor $sFCKCode = $oFCKeditor->CreateHTML(); // Verwijderen FCKEditor object //unset($oFCKeditor); /* * return code */ return $this->_gettabs().$sFCKCode; } }// End function toHtml /** * Inhoud teruggeven zonder HTML tags * * @access public * @return string Teskt inhoud element */ function getFrozenHtml() { $sValue = htmlspecialchars($this->getValue()); if ($this->getAttribute('wrap') == 'off') { $sHtml = $this->_getTabs(). '<pre>' .$sValue. '</pre>' . "\n"; } else { $sHtml = nl2br($sValue). "\n"; } return $sHtml.$this->_getPersistantData(); }// End function getFrozenHtml } ?>
Anyone wanna test it please?
RE: PEAR::HTML_Quickform_fckeditor: it works!
The file (with the above code) may be anything you like of course.
And of course, require_once the Quickform class.
RE: PEAR::HTML_Quickform_fckeditor: it works!
In that case try :
That way $pippo is a reference to the element in your QF form object instead of a copy without any relationship with the form object.
You dont'need the CustomConfigurationsPath property if you don't use your own extra config file.
RE: PEAR::HTML_Quickform_fckeditor: it works!
I'm using fckeditor 2.2, the last I found on the web, on a debian sarge with apache2, PHP4, PEAR 1.4.9 and PEAR::HTML_QuickForm 3.2.5.
I have unzipped fckeditor in /var/www/prove/fckeditor where /var/www is the apache2 root; I've pasted the code you posted on this thread and saved it in /var/www/prove/fckeditor/HTML_Quickform_fckeditor.php.
Furthermore I've created /var/www/prove/pippo.php having the following code:
When I load pippo.php I have the following error code:
Fatal error: Class html_quickform_fckeditor: Cannot inherit from undefined class html_quickform_element in /var/www/prove/FCKeditor/HTML_Quickform_fckeditor.php on line 38
So I have added at the top of HTML_Quickform_fckeditor.php
require_once 'HTML/QuickForm/element.php';
Now, loading pippo.php I have no error but I can't view any bar. If I remove from the $sProp array the key CustomConfigurationsPath I get the error “Error loading /var/www/prove/FCKeditor/fckstyles.xml”
If I remove stylesXmlPath too all seems to work but I can't have any customized bar.
Any way I found fckdeitor a very good project.
Thank you very much indeed
Piviul
RE: PEAR::HTML_Quickform_fckeditor: it works!
Hi Piviul,
I have tried your code and got it working after some changes.
You fed absolute filepaths to HTML_Quickform::registerElementType, the $sFCKBasePath and the StylesXmlPath property. The first should be relative from the script location. The last two should be the absolute paths from the documentroot of the webserver.
I have added the modified code below. I used a 'test' subdirectory directly below the documentroot. The browser pointed tot http://127.0.0.1/test/pippo.php to run my test.
BTW: I added the requirement for element.php as a warning in the Wiki, thanks.
Jordi
======= code =======
<?php require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/element.php'; /* * MOD: Relative path from script location * to class file */ HTML_Quickform::registerElementType('fckeditor','fckeditor/HTML_Quickform_fckeditor.php','HTML_Quickform_fckeditor'); $form1 = new HTML_QuickForm('Form','POST'); /* * MOD: Absolute path from docroot */ $sFCKBasePath = '/test/fckeditor/'; // BasePath $sToolbarSet = 'Default'; // Toolbarset $sWidth = '800'; // Width $sHeight = '300'; // Height $sProp=array( 'SkinPath' => 'editor/skins/office2003/', 'DefaultLanguage' => 'it', /* * MOD: Absolute path from docroot */ 'StylesXmlPath' => '/test/fckeditor/fckstyles.xml', 'UseBROnCarriageReturn' => 'true', 'StartupFocus' => 'false', 'CustomConfigurationsPath' => 'fckconfig.js', 'EditorAreaCSS' => 'fck_editorarea.css' ); $pippo =& $form1->addElement('fckeditor', 'pippo', 'Testo prova:'); $pippo->setFCKProps($sFCKBasePath,$sToolbarSet,$sWidth,$sHeight,$sProp); $form1->display(); ?>
Output from HTML_QuickForm = Source
First thank you for creating the sub class for HTML Quickform. I am using version 2.4 of FCKEditor and when the page is presented to the broswer all that is where the editor should be is the word Source
Site Structure
root
/admin/
/fckeditor/
HTML_Quickform::registerElementType('fckeditor','../fckeditor/HTML_Quickform_fckeditor.php','HTML_Quickform_fckeditor');
require_once 'HTML/QuickForm/select.php';
require_once("../fckeditor/fckeditor.php");
// HTML/QUICKFORM/Elelment.php is included in fceditor.php above
$sFCKBasePath = '../fckeditor/';
$sToolbarSet = 'Default'; // Toolbarset
$sWidth = '400'; // Width
$sHeight = '300'; // Height
$sProp=array(
'SkinPath' => 'editor/skins/office2003/',
'DefaultLanguage' => 'en',
/*
* MOD: Absolute path from docroot
*/
'StylesXmlPath' => '../fckeditor/fckstyles.xml',
'UseBROnCarriageReturn' => 'true',
'StartupFocus' => 'false',
'EditorAreaCSS' => 'fck_editorarea.css'
);
$fck = $form->addElement('fckeditor', 'answer', 'Answer: ');
$fck->setFCKProps($sFCKBasePath,$sToolbarSet,$sWidth,$sHeight,$sProp);