--- wymeditor/wymeditor.module 2008-10-08 21:42:52.000000000 +0200 +++ wymeditor.ok/wymeditor.module 2008-11-09 16:01:10.000000000 +0100 @@ -13,11 +13,9 @@ function wymeditor_form_alter(&$form, $form_state, $form_id) { global $user; global $language; - // Check if the form has an input format selection group - $format_types = _wymeditor_input_format_alter($form); - - if ($key = array_search('WYMeditor', $format_types)) { + $format_infos = _wymeditor_input_format_alter($form); + if (isset($format_infos[0]['key'])) { $rids = array(); $filename = array(); if (count($user->roles) == 1) { @@ -73,7 +71,11 @@ } drupal_add_js($js_file); drupal_add_js($module_path .'/filters-format.js'); - drupal_add_js(array('wymeditor_key' => array($key), 'wymeditor_path' => array(url(drupal_get_path('module', 'wymeditor')))), 'setting'); + foreach($format_infos as $k => $tab) { + $t_key[] = $tab['key']; + $t_textarea[] = $tab['textarea']; + } + drupal_add_js(array('wymeditor_key' => $t_key,'wymeditor_area' => $t_textarea,'wymeditor_path' => array(url(drupal_get_path('module', 'wymeditor')))), 'setting'); } // Alter filter format @@ -142,36 +144,36 @@ * Helper; Alter the input format so it can be accessed by the jquery system */ function _wymeditor_input_format_alter(&$form) { - if ($format_types == NULL) { - static $format_types = array(); + if ($format_infos == NULL) { + static $format_infos = array(); } - if (is_array($form)) { foreach (element_children($form) as $key) { - if (is_array($form[$key]['format'])) { - // The common point for the filter system is the declaration of the function - // 'filter_form_validate' on the '#validate' atribute of Form API - if (is_array($form[$key]['format']['#element_validate']) && in_array('filter_form_validate', $form[$key]['format']['#element_validate'])) { - $form[$key]['format']['#attributes'] = array('class' => 'filter-formats'); - if (!$format_types) { - $formats = array(); - foreach ($form[$key]['format'] as $key => $e) { - if ($e['#type'] == 'radio' && $e['#parents'][0] == 'format') { - $formats[$key] = $e['#title']; + if(!isset($form[$key]['#type']) || ($form[$key]['#type']=='fieldset' && !isset($form[$key]['#element_validate']))) { + // This function is recursive to find all input formats groups + _wymeditor_input_format_alter(&$form[$key]); + } else { + if($form[$key]['#type']=='textarea') { + $textarea = $key; + } + else if ($form[$key]['#type']=='fieldset' && is_array($form[$key]['#element_validate']) + && in_array('filter_form_validate', $form[$key]['#element_validate'])) { + + $form[$key]['#attributes'] = array('class' => 'filter-formats'); + $format = array(); + foreach ($form[$key] as $a => $e) { + if ($e['#type'] == 'radio' && $e['#parents'][0] == $key && $e['#title'] == 'WYMeditor') { + $format['textarea'] = 'edit-'.str_replace('_','-',$textarea); + $format['key'] = $a; + $format_infos[]= $format; + } } } - $format_types = $formats; - } } - } - - // This function is recursive to find all input formats groups - _wymeditor_input_format_alter(&$form[$key]); - } + } } - - return $format_types; -} + return $format_infos; +} /** * Implementation of hook_nodeapi @@ -181,8 +183,9 @@ case 'presave': if ($node->files) { $path = file_directory_path(); - foreach ($node->files as $file) { - $node->body = str_replace(file_create_url(substr($file['filepath'], strrpos($file['filepath'], 'temp'))), file_create_url($path .'/'. $file['filename']), $node->body); + $files = $node->files; + foreach ($files as $file) { + $node->body = str_replace(file_create_url(substr($file->filepath, strrpos($file->filepath, 'temp'))), file_create_url($path .'/'. $file->filename), $node->body); } } break; @@ -419,6 +422,12 @@ + "",'; } + if (module_exists('imce')) { + $link = '+ "
" + + "IMCE" + + "
"'; + } + $filepath = file_directory_path() .'/js'; $module_path = drupal_get_path('module', 'wymeditor'); $js_file = $filepath .'/jquery.wymeditor.init.'. implode('-', $filename) .'.js'; @@ -431,8 +440,9 @@ .'dialogImageHtml: "" + "" - + "