예제 #1
0
 function replaceTextArea($fieldName, $options, $input_html, $settings = array())
 {
     //Convert textarea html into wysiwygpro html
     list($model, $field) = explode(strpos('/', $fieldName) !== false ? '/' : '.', $fieldName);
     //Configure WYSIWYGPro
     $editor = new wysiwygPro();
     $editor->name = 'data[' . $model . '][' . $field . ']';
     $editor->value = isset($this->data[$model][$field]) ? $this->data[$model][$field] : '';
     $editor->clearFontMenu();
     $editor->clearSizeMenu();
     $empty = Set::normalize($this->defaults);
     $settings = Set::normalize($settings);
     if (!empty($settings['directories'])) {
         foreach ($settings['directories'] as $sd) {
             $empty['directories'][] = $sd;
         }
         unset($settings['directories']);
     }
     $settings = Set::merge($empty, $settings);
     $this->directory_permissions = $settings['_directory_permissions'];
     foreach ($settings as $st => $val) {
         if (!is_scalar($st)) {
             trigger_error('Invalid setting match: ' . print_r($st, 1));
         } elseif (!array_key_exists($st, $this->special_settings)) {
             //Normal
             if (substr($st, 0, 1) == '_') {
                 continue;
             } elseif (method_exists($editor, $st)) {
                 //Single arg functions
                 if (!is_array($val)) {
                     $val = array($val);
                 }
                 call_user_func_array(array($editor, $st), $val);
             } elseif (property_exists($editor, $st)) {
                 //Variable
                 $editor->{$st} = $val;
             } else {
                 trigger_error($st . ' is not a WYSIWYGPro method or property and the helper is not yet configured to handle this function');
             }
         } else {
             //Special handlers
             if ($st == 'directories') {
                 foreach ($val as $args) {
                     $this->addDirectory($editor, $args);
                 }
             } else {
                 trigger_error($st . ' is a special setting that has not been handled yet.');
             }
         }
     }
     //Get all the HTML the way that Cake wanted to build it
     //But move the error after the label and before the editor for better read-ability
     //The Helper::output function is not used because $editor->display immediately outputs the editor HTML
     list($begin, $junk) = explode('<textarea', $input_html);
     $error = $this->Form->error($fieldName);
     echo $begin . (empty($error) ? '' : $error) . '<div class="wysiwygpro">';
     //Output the editor
     if (!$settings['_inline_headers']) {
         $this->addHeaders($editor->fetchHeadContent());
     }
     $editor->display($settings['_editor_width'], $settings['_editor_height']);
     //width, height
     echo '</div></div>';
 }