Cute Editor (WYSIWYG) Form_Element

For programming and general questions on Zend Framework

Cute Editor (WYSIWYG) Form_Element

Postby emile1986 on Sat Jun 11, 2011 1:40 pm

Hello all,

I'm trying to create a Zend_Form_Element for the Cute Editor WYSIWYG editor,
that i want to use in a project i'm currently working on. I have found that there
already exists a joomla plugin for that editor and used that as a base for creating
my Form_Element which resultst in this

Cute Editor Form Element
Code: Select all

<?php

require_once 'Zend/Registry.php';
require_once 'ZendX/JQuery/View/Helper/UiWidget.php';

class app_View_Helper_FormCuteEditor extends Zend_View_Helper_FormTextarea
{
        public function setView(Zend_View_Interface $view)
    {
        parent::setView($view);
        $this->CuteEditor = $this->view->CuteEditor();
        $this->CuteEditor->enable();
        return $this;
    }
   
    function onGetContent($editor)
    {
    return "document.getElementById('cuteeditor').getHTML();";
    }
   
    function onSetContent($editor, $html)
    {
    return "document.getElementById('cuteeditor').setHTML(".$html.");";
    }
   
    function onSave($editor)
    {
    return "document.getElementById('cuteeditor').value=document.getElementById('cuteeditor').getHTML();";
    }
   
    public function formCuteEditor($name, $content, $width, $height, $col, $row, $buttons = true)
    {
    if (is_numeric( $width )) {
                        $width .= 'px';
                }
                if (is_numeric( $height )) {
                        $height .= 'px';
                }
               
                $content = str_replace("<", "<", $content);
                $content = str_replace(">", ">", $content);
                $content = str_replace("&", "&", $content);
                //$content = str_replace(" ", " ", $content);
                $content = str_replace(array(""","'"), array("\"", "'"), $content);
               
        //ToDo auto set editor direction
                //if ($language->isRTL()) {
                //}
               
                include_once(ROOT_PATH . "scripts/cuteeditor_files/include_CuteEditor.php");
                $editor = new CuteEditor();
                $name = "cuteeditor";
                $editor->ID = "cuteeditor";       
                $editor->Width = $this->params->get('width');
                $editor->Height = $this->params->get('height');
                $editor->Text = $content;
                $editor->FilesPath = ROOT_PATH . "scripts/cuteeditor_files";
                $templateitemList = $this->params->get( 'TemplateItemList');
               
                if ($templateitemList==""||$templateitemList==0)
                {
                        $editor->AutoConfigure = $this->params->def( 'AutoConfigure', 'Simple' );
                }else{
                        $editor->TemplateItemList=$templateitemList;
                }
                if ($this->params->def( 'EditorWysiwygModeCss', '' )=="")
                {
                        // establish the database connection
                        $db = Zend_Registry::get('dbconnection');
                        // select the template names from the site_templates table
                        $query = "SELECT template_name FROM site_templates";
                        $template = $db->fetchAll($query);
                        $file_path = $this->HTMLPath('templates/'. $template .'/css/');
                       
                        if (file_exists(ROOT_PATH . '/templates' . $template . '/css/editor.css')){
                                $content_css = $file_path . 'editor.css';
                        }else{
                                $content_css = $file_path . 'template.css';
                        }
                }
                $editor->EditorWysiwygModeCss      = $content_css;
                $editor->ThemeType              = $this->params->def( 'ThemeType', 'Office2007' );     
                $ImageGalleryPath                  = $this->params->def( 'ImageGalleryPath', ROOT_PATH .'/images/stories' );
                $FlashGalleryPath                  = $this->params->def( 'FlashGalleryPath', ROOT_PATH .'/images/stories/' );
                $MediaGalleryPath                  = $this->params->def( 'MediaGalleryPath', ROOT_PATH .'/images/stories/' );
                $FilesGalleryPath                  = $this->params->def( 'FilesGalleryPath', ROOT_PATH .'/images/stories/' );
                $TemplateGalleryPath      = $this->params->def( 'TemplateGalleryPath', ROOT_PATH .'/images/stories/' );
     
                //Sanitize image path
                $ImageGalleryPath      = preg_replace('/(^\/|\/$)/','',$ImageGalleryPath);
                $FlashGalleryPath      = preg_replace('/(^\/|\/$)/','',$FlashGalleryPath);
                $MediaGalleryPath      = preg_replace('/(^\/|\/$)/','',$MediaGalleryPath);
                $FilesGalleryPath      = preg_replace('/(^\/|\/$)/','',$FilesGalleryPath);
                $TemplateGalleryPath      = preg_replace('/(^\/|\/$)/','',$TemplateGalleryPath);
     
                $editor->ImageGalleryPath          = $this->HTMLPath($ImageGalleryPath);
                $editor->FlashGalleryPath          = $this->HTMLPath($FlashGalleryPath);
                $editor->MediaGalleryPath          = $this->HTMLPath($MediaGalleryPath);
                $editor->FilesGalleryPath          = $this->HTMLPath($FilesGalleryPath);
                $editor->TemplateGalleryPath      = $this->HTMLPath($TemplateGalleryPath);
                $editor->AbsoluteImageGalleryPath      = ROOT_PATH ."/". $ImageGalleryPath;
                $editor->AbsoluteFlashGalleryPath      = ROOT_PATH  ."/". $FlashGalleryPath;
                $editor->AbsoluteMediaGalleryPath      = ROOT_PATH  ."/". $MediaGalleryPath;
                $editor->AbsoluteFilesGalleryPath      = ROOT_PATH  ."/". $FilesGalleryPath;
                $editor->AbsoluteTemplateGalleryPath      = ROOT_PATH  ."/". $TemplateGalleryPath;
                $editor->CustomCulture      = $this->params->def( 'CustomCulture', 'en-US' );
                $editor->BreakElement      = $this->params->def( 'BreakElement', 'Div' );
                $editor->AccessKey              = $this->params->def( 'AccessKey', '' );
                $editor->AllowEditServerSideCode      = $this->params->def( 'AllowEditServerSideCode', 0 );
                $editor->BackColor              = $this->params->def( 'BackColor', '#ffffff' );
                $editor->BaseHref              = $this->params->def( 'BaseHref', '' );
                $editor->BorderColor              = $this->params->def( 'BorderColor', '#dddddd' );
                $editor->CodeViewTemplateItemList      = $this->params->def( 'CodeViewTemplateItemList', 'Print,Cut,Copy,Paste,Find,ToFullPage,FromFullPage,SelectAll,SelectNone' );
                $editor->DisableItemList      = $this->params->def( 'DisableItemList', '' );
                $editor->EditorBodyClass      = $this->params->def( 'EditorBodyClass', '' );
                $editor->EditorBodyId          = $this->params->def( 'EditorBodyId', '' );
                $editor->EditorBodyStyle      = $this->params->def( 'EditorBodyStyle', '' );
                $editor->EditorOnPaste          = $this->params->def( 'EditorOnPaste', 'ConfirmWord' );
                $editor->EnableAntiSpamEmailEncoder      = $this->params->def( 'EnableAntiSpamEmailEncoder', 1 );
                $editor->EnableContextMenu      = $this->params->def( 'EnableContextMenu', 1 );
                $editor->EnableObjectResizing  = $this->params->def( 'EnableObjectResizing', 1 );
                $editor->EnableStripScriptTags      = $this->params->def( 'EnableStripScriptTags', 1 );
                $editor->Focus                  = $this->params->def( 'Focus', 0 );
                $editor->FullPage              = $this->params->def( 'FullPage', 0 );
                $editor->MaintainAspectRatioWhenDraggingImage = $this->params->def( 'MaintainAspectRatioWhenDraggingImage', 1 );
                $editor->RemoveTBODYTag      = $this->params->def( 'RemoveTBODYTag', 1);
                $editor->ShowBottomBar          = $this->params->def( 'ShowBottomBar', 1 );
                $editor->ShowHtmlMode              = $this->params->def( 'ShowHtmlMode', 1 );
                $editor->ShowPreviewMode      = $this->params->def( 'ShowPreviewMode', 1 );
                $editor->ShowTagSelector  = $this->params->def( 'ShowTagSelector', 1 );
                $editor->TabSpaces              = $this->params->def( 'TabSpaces', '3' );
                $editor->ToggleBorder          = $this->params->def( 'ToggleBorder', 1 );
                $editor->URLType      = $this->params->def( 'URLType', 'Default' );
                $editor->UseFontTags          = $this->params->def( 'UseFontTags', 0 );
                $editor->UseHTMLEntities      = $this->params->def( 'UseHTMLEntities', 1 );
                $editor->UsePhysicalFormattingTags      = $this->params->def( 'UsePhysicalFormattingTags', 0 );
                $editor->UseSimpleAmpersand      = $this->params->def( 'UseSimpleAmpersand', 0 );
                $editor->XHTMLOutput          = $this->params->def( 'XHTMLOutput', 0 );
                $editor->CssClassStyleDropDownMenuNames       = $this->params->def( 'CssClassStyleDropDownMenuNames', '' );   
        $editor->CssClassStyleDropDownMenuList        = $this->params->def( 'CssClassStyleDropDownMenuList', '' );
                $editor->HelpUrl        = ROOT_PATH . "scripts/cuteeditor_files/Help/default.htm";
                $editor->Draw();
                return  $this->_displayButtons($name, $buttons);
    }
   
    function HTMLPath($input_path)
    {
    if(substr($input_path, 0, 1)!="/")
                {
                        $ThisFileName = basename($_SERVER['PHP_SELF']); // get the file name
                        $abspath = str_replace($ThisFileName,"",$_SERVER['PHP_SELF']);   // get the directory path
                    $input_path=$abspath.$input_path;
        $input_path = str_replace('/', '', $input_path);
                }
                return $input_path;
    }
   
    function onGetInsertMethod($name)
    {
   
    }
   
}


The problem that i have is that i don't know how i can port the onGetInsertMethod function from the joomla plugin to code that works with Zend Framework. The onGetInsertMethod function in the Joomla
plugin looks like this:

onGetInsertMethod
Code: Select all

function onGetInsertMethod($name)
        {
                $doc = & JFactory::getDocument();

                $js= "function jInsertEditorText( text ) {
                        var editor = document.getElementById('CE_".$name."_ID');
                        editor.PasteHTML(text);
                }";
                $doc->addScriptDeclaration($js);

                return true;
        }


Hope that someone can help me with this problem, many thanx in advance

Regards, Emile
emile1986
 
Posts: 57
Joined: Wed Mar 31, 2010 10:08 am

Re: Cute Editor (WYSIWYG) Form_Element

Postby sunfeather on Mon Mar 12, 2012 9:31 pm

I'm currently building a cms in which I wish to use cute editor. Did you get anywhere with this? If so, would you be willing to offer further guidance to a relative newbie.
Many thanks
Sunfeather
sunfeather
 
Posts: 1
Joined: Wed Mar 07, 2012 4:12 pm


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 2 guests