--- wymeditor/wymeditor.module 2008-10-08 21:42:52.000000000 +0200 +++ wymeditor.new/wymeditor.module 2008-11-10 15:12:12.000000000 +0100 @@ -8,74 +8,92 @@ */ /** + * Implementation of hook_elements(). + */ +function wymeditor_elements() { + return array( 'textarea' => array('#process' => array('wymeditor_textarea')),'radio'=>array('#process' => array('wymeditor_textarea')) ); +} + +/** + * Inline image/link insertion to textareas. + */ +function wymeditor_textarea($element) { + static $textarea; + if($element['#type']=='textarea') + $textarea = $element['#id']; + if($element['#type']=='radio' && $element['#title']=='WYMeditor') { + $element['#attributes']=array('class'=>'wymradio'); + wymeditor_element($element['#id'],$textarea); + } + return $element; +} + +/** * Implementation of hook_form_alter(). */ -function wymeditor_form_alter(&$form, $form_state, $form_id) { +function wymeditor_element($radio,$textarea) { 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)) { - $rids = array(); - $filename = array(); - if (count($user->roles) == 1) { - foreach ($user->roles as $rid => $role) { - $filename[] = $rid; - $rids[] = $rid; - } - } - else { - foreach ($user->roles as $rid => $role) { - $filename[] = $rid; - $rids[] = $rid; - } + $rids = array(); + $filename = array(); + if (count($user->roles) == 1) { + foreach ($user->roles as $rid => $role) { + $filename[] = $rid; + $rids[] = $rid; } - - $module_path = drupal_get_path('module', 'wymeditor'); - $settings = $buttons = $plugins = array(); - foreach ($rids as $rid) { - $wym_profiles = _wymeditor_get_profiles($rid); - $settings[] = unserialize($wym_profiles[0]['settings']); - } - foreach ($settings as $setting) { - if ($setting['button']['enable']) { - $button_enable = 1; - foreach ($setting['button']['buttons'] as $button => $value) { + } + else { + foreach ($user->roles as $rid => $role) { + $filename[] = $rid; + $rids[] = $rid; + } + } + $module_path = drupal_get_path('module', 'wymeditor'); + $settings = $buttons = $plugins = array(); + foreach ($rids as $rid) { + $wym_profiles = _wymeditor_get_profiles($rid); + $settings[] = unserialize($wym_profiles[0]['settings']); + } + foreach ($settings as $setting) { + if ($setting['button']['enable']) { + $button_enable = 1; + foreach ($setting['button']['buttons'] as $button => $value) { if ($value == $button) $buttons[$value] = $value; - } - } - foreach ($setting['plugin']['plugins'] as $plugin => $value) { - if ($plugin === $value && !is_numeric($value)) $plugins[$plugin] = $plugin; - } + } } - if (!file_exists(file_directory_path() .'/js/jquery.wymeditor.init.'. implode('-', $filename) .'.js')) { - $js_file = wymeditor_javascript($button_enable, $buttons, $plugins, $filename); - } - else { - $js_file = file_directory_path() .'/js/jquery.wymeditor.init.'. implode('-', $filename) .'.js'; - } - // add this file for run after the filters-format.js - drupal_add_js('misc/textarea.js'); - // Include the javascript and css files - drupal_add_css($module_path .'/wymeditor/skins/default/skin.css'); - // add the css for format the filter format - drupal_add_css($module_path .'/wymeditor.css'); - drupal_add_js($module_path .'/wymeditor/jquery.wymeditor.js'); - drupal_add_js($module_path .'/wymeditor/jquery.wymeditor.pack.js'); - drupal_add_js($module_path .'/wymeditor/lang/'. $language->language .'.js'); - - if (count($plugins) > 0) { - foreach ($plugins as $plugin) { - drupal_add_js($module_path .'/wymeditor/plugins/'. $plugin .'/jquery.wymeditor.'. $plugin .'.js'); - } + foreach ($setting['plugin']['plugins'] as $plugin => $value) { + if ($plugin === $value && !is_numeric($value)) $plugins[$plugin] = $plugin; } - 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'); } + if (!file_exists(file_directory_path() .'/js/jquery.wymeditor.init.'. implode('-', $filename) .'.js')) { + $js_file = wymeditor_javascript($button_enable, $buttons, $plugins, $filename); + } + else { + $js_file = file_directory_path() .'/js/jquery.wymeditor.init.'. implode('-', $filename) .'.js'; + } + // add this file for run after the filters-format.js + drupal_add_js('misc/textarea.js'); + // Include the javascript and css files + drupal_add_css($module_path .'/wymeditor/skins/default/skin.css'); + // add the css for format the filter format + drupal_add_css($module_path .'/wymeditor.css'); + drupal_add_js($module_path .'/wymeditor/jquery.wymeditor.js'); + drupal_add_js($module_path .'/wymeditor/jquery.wymeditor.pack.js'); + drupal_add_js($module_path .'/wymeditor/lang/'. $language->language .'.js'); + if (count($plugins) > 0) { + foreach ($plugins as $plugin) { + drupal_add_js($module_path .'/wymeditor/plugins/'. $plugin .'/jquery.wymeditor.'. $plugin .'.js'); + } + } + drupal_add_js($js_file); + drupal_add_js($module_path .'/filters-format.js'); + drupal_add_js(array('wymeditor_radio' => array($radio=>$textarea)), 'setting'); +} +/** + * Implementation of hook_form_alter(). + */ +function wymeditor_form_alter(&$form, $form_state, $form_id) { // Alter filter format if ($form_id == 'filter_admin_format_form' && $form['name']['#default_value'] == 'WYMeditor') { $form['name']['#attributes'] = array('readonly' => TRUE); @@ -139,41 +157,6 @@ } /** - * 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 (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']; - } - } - $format_types = $formats; - } - } - } - - // This function is recursive to find all input formats groups - _wymeditor_input_format_alter(&$form[$key]); - } - } - - return $format_types; -} - -/** * Implementation of hook_nodeapi */ function wymeditor_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { @@ -181,8 +164,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 +403,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 +421,9 @@ .'dialogImageHtml: "" + "" - + "