Par Nicolas SUPRIN, mercredi 9 avril 2008 à 15:52 | PEAR | #124 | rss
J'ai créé une classe prête à l'emploi pour utiliser l'éditeur FCKeditor en tant qu'élément de formulaire HTML_QuickForm.
Pré-requis
Il vous faudra une version PHP supérieure à 5.1.1, FCKeditor 2.6 ou supérieur, et HTML_QuickForm.
Pour utiliser cette classe, vous devez donc télécharger FCKeditor 2.6, et le placer dans un répertoire de l'arborescence web de votre appli /home/tagada/www/FCKeditor, et sera donc accessible depuis http://www.tagada.com/FCKeditor.
La classe HTML_QuickForm_FCKeditor
///geshi php <?php require_once 'HTML/QuickForm/element.php'; class HTML_QuickForm_FCKeditor extends HTML_QuickForm_element { /** * FCKeditor * * @var FCKeditor */ private $O_FCKEditor = null;
/** * valeur, contenu du FCK * * @var string */ private $S_value = ''; /** * Constructeur * * @param string $S_name * @param string $S_label * @param array $A_attributes */ public function __construct($S_name = 'FCKeditor', $S_label = '', $A_attributes = array()) { // si la classe FCKeditor n'est pas chargée if (!class_exists('FCKeditor')) { throw new Exception('you must include fckeditor.php'); } // appel du constructeur parent parent::HTML_QuickForm_element($S_name, $S_label, $A_attributes); $this->_persistantFreeze = false; $this->_type = '';
// creation du fckeditor; $this->O_FCKEditor = new FCKeditor($S_name); $this->setBasePath(); $this->setWidth( 600); $this->setHeight( 400); } /** * Applique le nom qui va bien * * @param string $S_name */ public function setName($S_name) {
$this->updateAttributes(array('name' => $S_name));
}
/**
* Retourne le nom qui va bien aussi
*
* @return string
*/
public function getName() {
return $this->getAttribute('name');
}
/** * Set the web base path * * @param string $S_path * @return Toodate_HTML_QuickForm_FCKeditor */ public function setBasePath($S_path = '/FCKeditor/') { $this->O_FCKEditor->BasePath = $S_path; return $this; } /** * Set value * * @param string $S_value */ public function setValue($S_value) { $this->S_value = $S_value; $this->O_FCKEditor->Value = $S_value; } /** * getValue * * @return string */ public function getValue() { return $this->S_value; } /** * Applique la hauteur * * @param int $I_height * @return Toodate_HTML_QuickForm_FCKeditor */ public function setHeight($I_height) { $this->O_FCKEditor->Height = $I_height; return $this; } /** * Applique la largeur * * @param int $I_width * @return Toodate_HTML_QuickForm_FCKeditor */ public function setWidth($I_width) { $this->O_FCKEditor->Width = $I_width; return $this; } /** * Set the toobar set * * @param string $S_toolbarSet * @return Toodate_HTML_QuickForm_FCKeditor */ public function setToolbarSet($S_toolbarSet) { $this->O_FCKEditor->ToolbarSet = $S_toolbarSet; return $this; } /** * Set la config * * @param string $S_name * @param string $S_value */ public function addConfig($S_name, $S_value) { $this->O_FCKEditor->Config$S_name = $S_value; } /** * Retourne la config * * @return array */ public function getConfig() { return $this->O_FCKEditor->Config; } /** * retourne le html qui va bien * * @return string */ public function toHtml() { ob_start(); $this->O_FCKEditor->Create(); $S_html = ob_get_contents(); ob_end_clean(); return $S_html; } }





Il manque les sauts de ligne, non ?
Aucun trackback.
Pour faire un trackback sur ce billet : http://blog.cactuscrew.com/tb.php?id=124&chk=jtn5vx