Newer
Older
<?php
// $Id$
/**
* @file
* Editor integration functions for FCKeditor.
*/
/**
* Plugin implementation of hook_editor().
*/
function wysiwyg_fckeditor_editor() {
$editor = array();
$editor['fckeditor'] = array(
'title' => 'FCKeditor',
'vendor url' => 'http://www.fckeditor.net',
'download url' => 'http://www.fckeditor.net/download',
'library path' => wysiwyg_get_path('fckeditor'),
'libraries' => array(
'' => array(
'title' => 'Default',
'files' => array('fckeditor.js'),
),
),
'version callback' => 'wysiwyg_fckeditor_version',
'themes callback' => 'wysiwyg_fckeditor_themes',
'settings callback' => 'wysiwyg_fckeditor_settings',
'plugin callback' => 'wysiwyg_fckeditor_plugins',
'versions' => array(
2.6 => array(
'js files' => array('fckeditor-2.6.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_fckeditor_version($editor) {
$library = $editor['library path'] .'/fckeditor.js';
$library = fopen($library, 'r');
$max_lines = 100;
while ($max_lines && $line = fgets($library, 60)) {
if (preg_match('@^FCKeditor.prototype.Version\s*= \'([\d\.]+)@', $line, $version)) {
fclose($library);
return $version[1];
}
$max_lines--;
}
fclose($library);
}
/**
* 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
Daniel Kudwien
committed
* Drupal.settings.wysiwyg.configs.{editor}
*/
function wysiwyg_fckeditor_settings($editor, $config, $theme) {
$settings = array(
'EditorPath' => base_path() . $editor['library path'] .'/',
Daniel Kudwien
committed
'SkinPath' => base_path() . $editor['library path'] .'/editor/skins/'. $theme .'/',
Daniel Kudwien
committed
'Width' => '100%',
'Height' => 420,
'LinkBrowser' => FALSE,
'LinkUpload' => FALSE,
Daniel Kudwien
committed
'ImageBrowser' => FALSE,
'ImageUpload' => FALSE,
Daniel Kudwien
committed
'FlashBrowser' => FALSE,
'FlashUpload' => FALSE,
);
Daniel Kudwien
committed
if (isset($config['block_formats'])) {
$settings['FontFormats'] = strtr($config['block_formats'], array(',' => ';'));
Daniel Kudwien
committed
}
if (isset($config['apply_source_formatting'])) {
$settings['FormatSource'] = $config['apply_source_formatting'];
Daniel Kudwien
committed
}
if (isset($config['preformatted'])) {
$settings['FormatOutput'] = $config['preformatted'];
Daniel Kudwien
committed
}
Daniel Kudwien
committed
if (isset($config['css_setting'])) {
if ($config['css_setting'] == 'theme') {
$css = path_to_theme() .'/style.css';
if (file_exists($css)) {
$settings['EditorAreaCSS'] = base_path() . $css;
Daniel Kudwien
committed
}
}
else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
$settings['EditorAreaCSS'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
Daniel Kudwien
committed
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
if (!empty($config['buttons'])) {
// Use our custom toolbar set.
$settings['CustomConfigurationsPath'] = wysiwyg_get_path('editors/js/fckeditor.config.js', TRUE);
$settings['ToolbarSet'] = 'Wysiwyg';
// Populate our custom toolbar set for fckeditor.config.js.
$settings['buttons'] = array();
$plugins = wysiwyg_get_plugins($editor['name']);
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') {
$settings['buttons'][] = $button;
}
}
}
}
// For now, all buttons are placed into one row.
if (!empty($settings['buttons'])) {
$settings['buttons'] = array($settings['buttons']);
}
}
return $settings;
}
/**
* 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_fckeditor_themes($editor, $profile) {
return array('default', 'office2003', 'silver');
}
/**
* Return internal plugins for FCKeditor; semi-implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_fckeditor_plugins($editor) {
return array(
Daniel Kudwien
committed
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
'default' => array(
'buttons' => array(
'Bold' => t('Bold'), 'Italic' => t('Italic'), 'Underline' => t('Underline'),
'StrikeThrough' => t('Strike-through'),
'JustifyLeft' => t('Align left'), 'JustifyCenter' => t('Align center'), 'JustifyRight' => t('Align right'), 'JustifyFull' => t('Justify'),
'UnorderedList' => t('Bullet list'), 'OrderedList' => t('Numbered list'),
'Outdent' => t('Outdent'), 'Indent' => t('Indent'),
'Undo' => t('Undo'), 'Redo' => t('Redo'),
'Link' => t('Link'), 'Unlink' => t('Unlink'), 'Anchor' => t('Anchor'),
'Image' => t('Image'),
'TextColor' => t('Forecolor'), 'BGColor' => t('Backcolor'),
'Superscript' => t('Superscript'), 'Subscript' => t('Subscript'),
'Blockquote' => t('Blockquote'), 'Source' => t('Source code'),
'Rule' => t('Horizontal rule'),
'Cut' => t('Cut'), 'Copy' => t('Copy'), 'Paste' => t('Paste'),
'PasteText' => t('Paste Text'), 'PasteWord' => t('Paste from Word'),
'ShowBlocks' => t('Show blocks'),
'RemoveFormat' => t('Remove format'),
'SpecialChar' => t('Character map'),
'About' => t('About'),
'FontFormat' => t('HTML block format'), 'FontName' => t('Font'), 'FontSize' => t('Font size'), 'Style' => t('Font style'),
'Table' => t('Table'),
'Find' => t('Search'), 'Replace' => t('Replace'), 'SelectAll' => t('Select all'),
'CreateDiv' => t('Create DIV container'),
'Flash' => t('Flash'), 'Smiley' => t('Smiley'),
'FitWindow' => t('FitWindow'),
'SpellCheck' => t('Check spelling'),
),
'internal' => TRUE,
),