Index: editors/ckeditor.inc =================================================================== RCS file: editors/ckeditor.inc diff -N editors/ckeditor.inc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ editors/ckeditor.inc 25 Sep 2009 10:08:31 -0000 @@ -0,0 +1,256 @@ + 'CKeditor', + 'vendor url' => 'http://ckeditor.com', + 'download url' => 'http://ckeditor.com', + 'libraries' => array( + '' => array( + 'title' => 'Default', + 'files' => array('ckeditor.js'), + ), + 'src' => array( + 'title' => 'Source', + 'files' => array('ckeditor_source.js'), + ), + ), + 'version callback' => 'wysiwyg_ckeditor_version', + 'themes callback' => 'wysiwyg_ckeditor_themes', + 'settings callback' => 'wysiwyg_ckeditor_settings', + 'plugin callback' => 'wysiwyg_ckeditor_plugins', + 'plugin settings callback' => 'wysiwyg_ckeditor_plugin_settings', + 'versions' => array( + '3.0.3665' => array( + 'js files' => array('ckeditor-3.0.js'), + ), + ), + ); + return $editor; +} + +/** + * Detect editor version. + * + * @param $editor + * An array containing editor properties as returned from hook_editor(). + * + * @return + * The installed editor version. + */ +function wysiwyg_ckeditor_version($editor) { + $library = $editor['library path'] . '/ckeditor.js'; + $library = fopen($library, 'r'); + $max_lines = 8; + while ($max_lines && $line = fgets($library, 140)) { + // version:'CKEditor 3.0 SVN',revision:'3665' + // version:'3.0 RC',revision:'3753' + if (preg_match('@version:\'(?:CKEditor )?([\d\.]+)(?:.+revision:\'([\d]+))?@', $line, $version)) { + fclose($library); + return $version[1] . '.' . $version[2]; + } + $max_lines--; + } + fclose($library); +} + +/** + * Determine available editor themes or check/reset a given one. + * + * @param $editor + * A processed hook_editor() array of editor properties. + * @param $profile + * A wysiwyg editor profile. + * + * @return + * An array of theme names. The first returned name should be the default + * theme name. + */ +function wysiwyg_ckeditor_themes($editor, $profile) { + return array('default'); +} + +/** + * Return runtime editor settings for a given wysiwyg profile. + * + * @param $editor + * A processed hook_editor() array of editor properties. + * @param $config + * An array containing wysiwyg editor profile settings. + * @param $theme + * The name of a theme/GUI/skin to use. + * + * @return + * A settings array to be populated in + * Drupal.settings.wysiwyg.configs.{editor} + */ +function wysiwyg_ckeditor_settings($editor, $config, $theme) { + $settings = array( + 'basePath' => base_path() . $editor['library path'] . '/', + 'SkinPath' => base_path() . $editor['library path'] . '/editor/skins/' . $theme . '/', + 'Width' => '100%', + 'Height' => 420, + // By default, CKeditor converts most characters into HTML entities. Since + // it does not support a custom definition, but Drupal supports Unicode, we + // disable at least the additional character sets. CKeditor always converts + // XML default characters '&', '<', '>'. + // @todo Check whether completely disabling ProcessHTMLEntities is an option. + 'IncludeLatinEntities' => FALSE, + 'IncludeGreekEntities' => FALSE, + ); + if (isset($config['block_formats'])) { + $settings['FontFormats'] = strtr($config['block_formats'], array(',' => ';')); + } + if (isset($config['apply_source_formatting'])) { + $settings['FormatOutput'] = $settings['FormatSource'] = $config['apply_source_formatting']; + } + + if (isset($config['css_setting'])) { + if ($config['css_setting'] == 'theme') { + // CKeditor only supports one CSS file currently. + $settings['contentsCss'] = reset(wysiwyg_get_css()); + } + else if ($config['css_setting'] == 'self' && isset($config['css_path'])) { + $settings['contentsCss'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme())); + } + } + + if (!empty($config['buttons'])) { + $settings['toolbar'] = array(); + $plugins = wysiwyg_get_plugins($editor['name']); + $groups = wysiwyg_ckeditor_buttons_groups(); + + // I think this code needs rewriting because it's too many foreaches imho.. + foreach ($config['buttons'] as $plugin => $buttons) { + foreach ($buttons as $button => $enabled) { + // Iterate separately over buttons and extensions properties. + foreach (array('buttons', 'extensions') as $type) { + // Skip unavailable plugins. + if (!isset($plugins[$plugin][$type][$button])) { + continue; + } + // Add buttons. + if ($type == 'buttons') { + foreach ($groups as $gid => $group){ + if (in_array($button, $group)){ + // add button to it's grop + $grouped[$gid][] = $button; + // exit from this foreach, because button can be only in one group + continue 2; + } + } + // if this button not listed in groups array then let's store this button in another array + $ungroped[] = $button; + } + // Allow plugins to add or override global configuration settings. + if (!empty($plugins[$plugin]['options'])) { + $settings = array_merge($settings, $plugins[$plugin]['options']); + } + } + } + } + // array must be with ordered keys without missings + foreach ($grouped as $n => $gr){ + $settings['toolbar'][] = $gr; + } + // add ungroped buttons + if (isset($ungroped)){ + $settings['toolbar'][] = $ungroped; + } + } + return $settings; +} + +/** + * Build a JS settings array of native external plugins that need to be loaded separately. + */ +function wysiwyg_ckeditor_plugin_settings($editor, $profile, $plugins) { + $settings = array(); + foreach ($plugins as $name => $plugin) { + // Register all plugins that need to be loaded. + if (!empty($plugin['load'])) { + $settings[$name] = array(); + // Add path for native external plugins; internal ones do not need a path. + if (empty($plugin['internal']) && isset($plugin['path'])) { + $settings[$name]['path'] = base_path() . $plugin['path']; + } + if (!empty($plugin['languages'])) { + $settings[$name]['languages'] = $plugin['languages']; + } + } + } + return $settings; +} + +/** + * Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin(). + */ +function wysiwyg_ckeditor_plugins($editor) { + $plugins = array( + 'default' => array( + 'buttons' => array( + 'Source' => t('Source'), + 'Save' => t('Save'), 'NewPage' => t('NewPage'), 'Preview' => t('Preview'), + 'Templates' => t('Templates'), + 'Cut' => t('Cut'), 'Copy' => t('Copy'), 'Paste' => t('Paste'), 'PasteText' => t('PasteText'), 'PasteFromWord' => t('PasteFromWord'), + 'Print' => t('Print'), 'SpellChecker' => t('SpellChecker'), 'Scayt' => t('Scayt'), + 'Undo' => t('Undo'), 'Redo' => t('Redo'), + 'Find' => t('Find'), 'Replace' => t('Replace'), + 'SelectAll' => t('SelectAll'), 'RemoveFormat' => t('RemoveFormat'), + 'Form' => t('Form'), 'Checkbox' => t('Checkbox'), 'Radio' => t('Radio'), 'TextField' => t('TextField'), 'Textarea' => t('Textarea'), 'Select' => t('Select'), 'Button' => t('Button'), 'ImageButton' => t('ImageButton'), 'HiddenField' => t('HiddenField'), + 'Bold' => t('Bold'), 'Italic' => t('Italic'), 'Underline' => t('Underline'), 'Strike' => t('Strike'), + 'Subscript' => t('Subscript'), 'Superscript' => t('Superscript'), + 'BulletedList' => t('BulletedList'), 'NumberedList' => t('NumberedList'), + 'Outdent' => t('Outdent'), 'Indent' => t('Indent'), 'Blockquote' => t('Blockquote'), + 'JustifyLeft' => t('JustifyLeft'), 'JustifyCenter' => t('JustifyCenter'), 'JustifyRight' => t('JustifyRight'), 'JustifyBlock' => t('JustifyBlock'), + 'Link' => t('Link'), 'Unlink' => t('Unlink'), 'Anchor' => t('Anchor'), + 'Image' => t('Image'), 'Flash' => t('Flash'), 'Table' => t('Table'), 'HorizontalRule' => t('HorizontalRule'), 'Smiley' => t('Smiley'), 'SpecialChar' => t('SpecialChar'), 'PageBreak' => t('PageBreak'), + 'TextColor' => t('TextColor'), 'BGColor' => t('BGColor'), + 'Maximize' => t('Maximize'), 'ShowBlocks' => t('ShowBlocks'), + 'Styles' => t('Styles'), 'Format' => t('Format'), 'Font' => t('Font'), 'FontSize' => t('FontSize'), + 'About' => t('About'), + ), + 'internal' => TRUE, + ), + ); + return $plugins; +} + +/** + * Return array of groups for buttons in CKEditor + * @return array + */ +function wysiwyg_ckeditor_buttons_groups() { + $groups = array( + array('Source'), + array('Save', 'NewPage', 'Preview'), + array('Templates'), + array('Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord'), + array('Print', 'SpellChecker', 'Scayt'), + array('Undo', 'Redo'), + array('Find', 'Replace'), + array('SelectAll', 'RemoveFormat'), + array('Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'), + array('Bold', 'Italic', 'Underline', 'Strike'), + array('Subscript', 'Superscript'), + array('BulletedList', 'NumberedList'), + array('Outdent', 'Indent', 'Blockquote'), + array('JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'), + array('Link', 'Unlink', 'Anchor'), + array('Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'), + array('TextColor', 'BGColor' ), + array('Maximize', 'ShowBlocks'), + array('Styles', 'Format', 'Font', 'FontSize'), + array('About') + ); + return $groups; +} \ No newline at end of file Index: editors/js/ckeditor-3.0.js =================================================================== RCS file: editors/js/ckeditor-3.0.js diff -N editors/js/ckeditor-3.0.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ editors/js/ckeditor-3.0.js 25 Sep 2009 10:08:31 -0000 @@ -0,0 +1,34 @@ +// $Id: ckeditor-2.6.js,v 1.16 2009/06/04 00:53:10 sun Exp $ + +/** + * Attach this editor to a target element. + */ +Drupal.wysiwyg.editor.attach.ckeditor = function(context, params, settings) { + // Apply editor instance settings. + CKEDITOR.config.customConfig = ''; + + // Attach editor. + CKEDITOR.replace(params.field, settings); +}; + +/** + * Detach a single or all editors. + * + * @todo 3.x: editor.prototype.getInstances() should always return an array + * containing all instances or the passed in params.field instance, but + * always return an array to simplify all detach functions. + */ +Drupal.wysiwyg.editor.detach.ckeditor = function(context, params) { + if (typeof params != 'undefined') { + var instance = CKEDITOR.instances[params.field]; + if (instance) { + instance.destroy(); + } + } + else { + for (var instanceName in CKEDITOR.instances) { + CKEDITOR.instances[instanceName].destroy(); + } + } +}; +