Re: Cute Editor Zend_Form_Element

  •  06-10-2011, 10:08 AM

    Re: Cute Editor Zend_Form_Element

    I'm now trying to port the joomla plugin to a zend_form_element but i'm stuck on the onGetInsertMethod function which looks like this

    onGetInsertMethod
    1. function onGetInsertMethod($name)   
    2. {   
    3.    $doc = & JFactory::getDocument();   
    4.    $js= "function jInsertEditorText( text ) {   
    5.       var editor = document.getElementById('CE_".$name."_ID');   
    6.       editor.PasteHTML(text);   
    7.    }";   
    8.    $doc->addScriptDeclaration($js);   
    9.    return true;   
    10. }  
     
    Hopefully someone knows how i can port that function to work with zend framework. This is what i have so far:
     
    Zend_Form_Element_CuteEditor
    1. <?php   
    2.   
    3. require_once 'Zend/Registry.php';   
    4. require_once 'ZendX/JQuery/View/Helper/UiWidget.php';   
    5.   
    6. class app_View_Helper_FormCuteEditor extends Zend_View_Helper_FormTextarea   
    7. {   
    8.     public function setView(Zend_View_Interface $view)   
    9.     {   
    10.         parent::setView($view);   
    11.         $this->CuteEditor = $this->view->CuteEditor();   
    12.         $this->CuteEditor->enable();   
    13.         return $this;   
    14.     }   
    15.        
    16.     function onGetContent($editor)   
    17.     {   
    18.         return "document.getElementById('cuteeditor').getHTML();";   
    19.     }   
    20.        
    21.     function onSetContent($editor$html)   
    22.     {   
    23.         return "document.getElementById('cuteeditor').setHTML(".$html.");";   
    24.     }   
    25.        
    26.     function onSave($editor)   
    27.     {   
    28.         return "document.getElementById('cuteeditor').value=document.getElementById('cuteeditor').getHTML();";   
    29.     }   
    30.        
    31.     public function formCuteEditor($name$content$width$height$col$row$buttons = true)   
    32.     {   
    33.         if (is_numeric$width )) {   
    34.             $width .= 'px';   
    35.         }   
    36.         if (is_numeric$height )) {   
    37.             $height .= 'px';   
    38.         }   
    39.            
    40.         $content = str_replace("&lt;""<"$content);   
    41.         $content = str_replace("&gt;"">"$content);   
    42.         $content = str_replace("&amp;""&"$content);   
    43.         //$content = str_replace("&nbsp;", " ", $content);   
    44.         $content = str_replace(array("&quot;","&#039;"), array("\"""'"), $content);   
    45.            
    46.         //ToDo auto set editor direction   
    47.         //if ($language->isRTL()) {   
    48.         //}   
    49.            
    50.         include_once(ROOT_PATH . "scripts/cuteeditor_files/include_CuteEditor.php");   
    51.         $editor = new CuteEditor();   
    52.         $name = "cuteeditor";   
    53.         $editor->ID = "cuteeditor";         
    54.         $editor->Width = $this->params->get('width');   
    55.         $editor->Height = $this->params->get('height');   
    56.         $editor->Text = $content;   
    57.         $editor->FilesPath = ROOT_PATH . "scripts/cuteeditor_files";   
    58.         $templateitemList = $this->params->get( 'TemplateItemList');   
    59.            
    60.         if ($templateitemList==""||$templateitemList==0)   
    61.         {   
    62.             $editor->AutoConfigure = $this->params->def( 'AutoConfigure''Simple' );   
    63.         }else{   
    64.             $editor->TemplateItemList=$templateitemList;    
    65.         }   
    66.         if ($this->params->def( 'EditorWysiwygModeCss''' )=="")   
    67.         {   
    68.             // establish the database connection   
    69.             $db = Zend_Registry::get('dbconnection');   
    70.             // select the template names from the site_templates table   
    71.             $query = "SELECT template_name FROM site_templates";   
    72.             $template = $db->fetchAll($query);   
    73.             $file_path = $this->HTMLPath('templates/'$template .'/css/');   
    74.                
    75.             if (file_exists(ROOT_PATH . '/templates' . $template . '/css/editor.css')){   
    76.                 $content_css = $file_path . 'editor.css';   
    77.             }else{   
    78.                 $content_css = $file_path . 'template.css';   
    79.             }   
    80.         }   
    81.         $editor->EditorWysiwygModeCss                  = $content_css;   
    82.         $editor->ThemeType                             = $this->params->def( 'ThemeType''Office2007' );       
    83.         $ImageGalleryPath                             = $this->params->def( 'ImageGalleryPath', ROOT_PATH .'/images/stories' );   
    84.         $FlashGalleryPath                             = $this->params->def( 'FlashGalleryPath', ROOT_PATH .'/images/stories/' );   
    85.         $MediaGalleryPath                             = $this->params->def( 'MediaGalleryPath', ROOT_PATH .'/images/stories/' );   
    86.         $FilesGalleryPath                             = $this->params->def( 'FilesGalleryPath', ROOT_PATH .'/images/stories/' );   
    87.         $TemplateGalleryPath                          = $this->params->def( 'TemplateGalleryPath', ROOT_PATH .'/images/stories/' );   
    88.          
    89.         //Sanitize image path   
    90.         $ImageGalleryPath                             = preg_replace('/(^\/|\/$)/','',$ImageGalleryPath);   
    91.         $FlashGalleryPath                             = preg_replace('/(^\/|\/$)/','',$FlashGalleryPath);   
    92.         $MediaGalleryPath                             = preg_replace('/(^\/|\/$)/','',$MediaGalleryPath);   
    93.         $FilesGalleryPath                             = preg_replace('/(^\/|\/$)/','',$FilesGalleryPath);   
    94.         $TemplateGalleryPath                          = preg_replace('/(^\/|\/$)/','',$TemplateGalleryPath);   
    95.         
    96.         $editor->ImageGalleryPath                      = $this->HTMLPath($ImageGalleryPath);   
    97.         $editor->FlashGalleryPath                      = $this->HTMLPath($FlashGalleryPath);   
    98.         $editor->MediaGalleryPath                      = $this->HTMLPath($MediaGalleryPath);   
    99.         $editor->FilesGalleryPath                      = $this->HTMLPath($FilesGalleryPath);   
    100.         $editor->TemplateGalleryPath               = $this->HTMLPath($TemplateGalleryPath);   
    101.         $editor->AbsoluteImageGalleryPath              = ROOT_PATH ."/"$ImageGalleryPath;   
    102.         $editor->AbsoluteFlashGalleryPath              = ROOT_PATH  ."/"$FlashGalleryPath;   
    103.         $editor->AbsoluteMediaGalleryPath              = ROOT_PATH  ."/"$MediaGalleryPath;   
    104.         $editor->AbsoluteFilesGalleryPath              = ROOT_PATH  ."/"$FilesGalleryPath;   
    105.         $editor->AbsoluteTemplateGalleryPath       = ROOT_PATH  ."/"$TemplateGalleryPath;   
    106.         $editor->CustomCulture                         = $this->params->def( 'CustomCulture''en-US' );   
    107.         $editor->BreakElement                          = $this->params->def( 'BreakElement''Div' );   
    108.         $editor->AccessKey                             = $this->params->def( 'AccessKey''' );   
    109.         $editor->AllowEditServerSideCode           = $this->params->def( 'AllowEditServerSideCode', 0 );   
    110.         $editor->BackColor                             = $this->params->def( 'BackColor''#ffffff' );   
    111.         $editor->BaseHref                              = $this->params->def( 'BaseHref''' );   
    112.         $editor->BorderColor                       = $this->params->def( 'BorderColor''#dddddd' );   
    113.         $editor->CodeViewTemplateItemList              = $this->params->def( 'CodeViewTemplateItemList''Print,Cut,Copy,Paste,Find,ToFullPage,FromFullPage,SelectAll,SelectNone' );   
    114.         $editor->DisableItemList                   = $this->params->def( 'DisableItemList''' );   
    115.         $editor->EditorBodyClass                   = $this->params->def( 'EditorBodyClass''' );   
    116.         $editor->EditorBodyId                          = $this->params->def( 'EditorBodyId''' );   
    117.         $editor->EditorBodyStyle                       = $this->params->def( 'EditorBodyStyle''' );   
    118.         $editor->EditorOnPaste                         = $this->params->def( 'EditorOnPaste''ConfirmWord' );   
    119.         $editor->EnableAntiSpamEmailEncoder            = $this->params->def( 'EnableAntiSpamEmailEncoder', 1 );   
    120.         $editor->EnableContextMenu                     = $this->params->def( 'EnableContextMenu', 1 );   
    121.         $editor->EnableObjectResizing                  = $this->params->def( 'EnableObjectResizing', 1 );   
    122.         $editor->EnableStripScriptTags                 = $this->params->def( 'EnableStripScriptTags', 1 );   
    123.         $editor->Focus                                 = $this->params->def( 'Focus', 0 );   
    124.         $editor->FullPage                              = $this->params->def( 'FullPage', 0 );   
    125.         $editor->MaintainAspectRatioWhenDraggingImage = $this->params->def( 'MaintainAspectRatioWhenDraggingImage', 1 );   
    126.         $editor->RemoveTBODYTag                    = $this->params->def( 'RemoveTBODYTag', 1);   
    127.         $editor->ShowBottomBar                         = $this->params->def( 'ShowBottomBar', 1 );   
    128.         $editor->ShowHtmlMode                          = $this->params->def( 'ShowHtmlMode', 1 );   
    129.         $editor->ShowPreviewMode                       = $this->params->def( 'ShowPreviewMode', 1 );   
    130.         $editor->ShowTagSelector                       = $this->params->def( 'ShowTagSelector', 1 );   
    131.         $editor->TabSpaces                             = $this->params->def( 'TabSpaces''3' );   
    132.         $editor->ToggleBorder                          = $this->params->def( 'ToggleBorder', 1 );   
    133.         $editor->URLType                               = $this->params->def( 'URLType''Default' );   
    134.         $editor->UseFontTags                           = $this->params->def( 'UseFontTags', 0 );   
    135.         $editor->UseHTMLEntities                       = $this->params->def( 'UseHTMLEntities', 1 );   
    136.         $editor->UsePhysicalFormattingTags             = $this->params->def( 'UsePhysicalFormattingTags', 0 );   
    137.         $editor->UseSimpleAmpersand                = $this->params->def( 'UseSimpleAmpersand', 0 );   
    138.         $editor->XHTMLOutput                           = $this->params->def( 'XHTMLOutput', 0 );   
    139.         $editor->CssClassStyleDropDownMenuNames       = $this->params->def( 'CssClassStyleDropDownMenuNames''' );      
    140.         $editor->CssClassStyleDropDownMenuList        = $this->params->def( 'CssClassStyleDropDownMenuList''' );   
    141.         $editor->HelpUrl                               = ROOT_PATH . "scripts/cuteeditor_files/Help/default.htm";   
    142.         $editor->Draw();   
    143.         return  $this->_displayButtons($name$buttons);   
    144.     }   
    145.        
    146.     function HTMLPath($input_path)   
    147.     {   
    148.         if(substr($input_path, 0, 1)!="/")   
    149.         {   
    150.             $ThisFileName = basename($_SERVER['PHP_SELF']); // get the file name   
    151.             $abspath = str_replace($ThisFileName,"",$_SERVER['PHP_SELF']);   // get the directory path   
    152.             $input_path=$abspath.$input_path;   
    153.             $input_path = str_replace('/'''$input_path);   
    154.         }   
    155.         return $input_path;   
    156.     }   
    157.        
    158.     function onGetInsertMethod($name)   
    159.     {   
    160.            
    161.     }   
    162. }  
     
    Regards, Emile
View Complete Thread