Commit a090395c authored by sun's avatar sun

#152046 by sun: Added hook_wysiwyg_plugin().

parent 9eca41dc
......@@ -6,6 +6,7 @@ Wysiwyg x.x-x.x, xxxx-xx-xx
Wysiwyg 6.x-0.x, xxxx-xx-xx
---------------------------
#152046 by sun: Added hook_wysiwyg_plugin().
#268562 by sun: Code clean-up.
#60667 by sun: Fixed wrong editor profile is loaded when user is granted access
to more than one profile.
......
/* $Id$ */
.wysiwyg-break {
display: block;
border: 0;
border-top: 1px dotted #ccc;
margin-top: 1em;
width: 100%;
height: 12px;
background: #fff url(images/breaktext.gif) no-repeat center top;
}
// $Id$
// Import plugin language.
tinyMCE.importPluginLanguagePack('wysiwyg', 'en');
var TinyMCE_wysiwygBreakPlugin = {
getInfo: function() {
return {
longname: 'Teaser break',
author: 'Nathan Haug',
authorurl: 'http://www.quicksketch.org',
infourl: 'http://drupal.org/project/wysiwyg'
};
},
initInstance: function(inst) {
tinyMCE.importCSS(inst.getDoc(), this.baseURL + '/break.css');
},
getControlHTML: function (control_name) {
switch (control_name) {
case 'break':
return tinyMCE.getButtonHTML(control_name, 'lang_break_desc', '{$pluginurl}/images/break.gif', 'break', false, 'null');
}
return '';
},
execCommand: function(editor_id, element, command, user_interface, value) {
switch (command) {
case 'break':
var classValue = '';
var template = new Array();
var inst = tinyMCE.getInstanceById(editor_id);
var focusElm = inst.getFocusElement();
// Check whether selection is an image and belongs to this plugin.
if (focusElm != null && focusElm.nodeName.toLowerCase() == 'img') {
classValue = this.getAttrib(focusElm, 'class');
if (classValue != 'wysiwyg-break') {
return true;
}
}
html = '<img src="' + tinyMCE.getParam('theme_href') + '/images/spacer.gif" alt="&lt;--break-&gt;" title="&lt;--break--&gt;" class="wysiwyg-break" />';
tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html);
return true;
}
// Pass to next handler in chain.
return false;
},
cleanup: function(type, content) {
switch (type) {
case 'insert_to_editor':
// Parse all <!--break--> tags and replace them with images.
var startPos = 0;
while ((startPos = content.indexOf('<!--break-->', startPos)) != -1) {
// Insert image.
var contentAfter = content.substring(startPos + 12);
content = content.substring(0, startPos);
content += '<img src="' + tinyMCE.getParam('theme_href') + '/images/spacer.gif" alt="&lt;--break-&gt;" title="&lt;--break--&gt;" class="wysiwyg-break" />';
content += contentAfter;
startPos++;
}
break;
case 'get_from_editor':
// Parse all img tags and replace them with <!--break-->.
var startPos = -1;
while ((startPos = content.indexOf('<img', startPos + 1)) != -1) {
var endPos = content.indexOf('/>', startPos);
var attribs = parseAttributes(content.substring(startPos + 4, endPos));
if (attribs['class'] == 'wysiwyg-break') {
endPos += 2;
chunkBefore = content.substring(0, startPos);
chunkAfter = content.substring(endPos);
content = chunkBefore + '<!--break-->' + chunkAfter;
}
}
break;
}
// Pass through to next handler in chain
return content;
/**
* Local function that parses the break image in and out.
*/
function parseAttributes (attribute_string) {
var attributeName = '', attributeValue = '', withInName, withInValue;
var attributes = new Array();
var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
if (attribute_string == null || attribute_string.length < 2) {
return null;
}
withInName = withInValue = false;
for (var i = 0; i < attribute_string.length; i++) {
var chr = attribute_string.charAt(i);
if ((chr == '"' || chr == "'") && !withInValue) {
withInValue = true;
}
else if ((chr == '"' || chr == "'") && withInValue) {
withInValue = false;
var pos = attributeName.lastIndexOf(' ');
if (pos != -1) {
attributeName = attributeName.substring(pos+1);
}
attributes[attributeName.toLowerCase()] = attributeValue.substring(1).toLowerCase();
attributeName = '';
attributeValue = '';
}
else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue) {
withInName = true;
}
if (chr == '=' && withInName) {
withInName = false;
}
if (withInName) {
attributeName += chr;
}
if (withInValue) {
attributeValue += chr;
}
}
return attributes;
}
},
handleNodeChange: function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
tinyMCE.switchClass(editor_id + '_wysiwyg_break', 'mceButtonNormal');
if (node == null) {
return;
}
do {
if (node.nodeName.toLowerCase() == 'img' && this.getAttrib(node, 'class').indexOf('wysiwyg-break') == 0) {
tinyMCE.switchClass(editor_id + '_wysiwyg_break', 'mceButtonSelected');
}
} while ((node = node.parentNode));
return true;
},
getAttrib: function(elm, name) {
return elm.getAttribute(name) ? elm.getAttribute(name) : '';
}
};
tinyMCE.addPlugin('wysiwyg', TinyMCE_wysiwygBreakPlugin);
// $Id$
// Import plugin language.
tinyMCE.importPluginLanguagePack('wysiwyg', 'en');
var TinyMCE_wysiwygBreakPlugin = {
getInfo: function() {
return {
longname: 'Teaser break',
author: 'Nathan Haug',
authorurl: 'http://www.quicksketch.org',
infourl: 'http://drupal.org/project/wysiwyg'
};
},
initInstance: function(inst) {
tinyMCE.importCSS(inst.getDoc(), this.baseURL + '/break.css');
},
getControlHTML: function (control_name) {
switch (control_name) {
case 'break':
return tinyMCE.getButtonHTML(control_name, 'lang_break_desc', '{$pluginurl}/images/break.gif', 'break', false, 'null');
}
return '';
},
execCommand: function(editor_id, element, command, user_interface, value) {
switch (command) {
case 'break':
var classValue = '';
var template = new Array();
var inst = tinyMCE.getInstanceById(editor_id);
var focusElm = inst.getFocusElement();
// Check whether selection is an image and belongs to this plugin.
if (focusElm != null && focusElm.nodeName.toLowerCase() == 'img') {
classValue = this.getAttrib(focusElm, 'class');
if (classValue != 'wysiwyg-break') {
return true;
}
}
html = '<img src="' + tinyMCE.getParam('theme_href') + '/images/spacer.gif" alt="&lt;--break-&gt;" title="&lt;--break--&gt;" class="wysiwyg-break" />';
tinyMCE.execInstanceCommand(editor_id, 'mceInsertContent', false, html);
return true;
}
// Pass to next handler in chain.
return false;
},
cleanup: function(type, content) {
switch (type) {
case 'insert_to_editor':
// Parse all <!--break--> tags and replace them with images.
var startPos = 0;
while ((startPos = content.indexOf('<!--break-->', startPos)) != -1) {
// Insert image.
var contentAfter = content.substring(startPos + 12);
content = content.substring(0, startPos);
content += '<img src="' + tinyMCE.getParam('theme_href') + '/images/spacer.gif" alt="&lt;--break-&gt;" title="&lt;--break--&gt;" class="wysiwyg-break" />';
content += contentAfter;
startPos++;
}
break;
case 'get_from_editor':
// Parse all img tags and replace them with <!--break-->.
var startPos = -1;
while ((startPos = content.indexOf('<img', startPos + 1)) != -1) {
var endPos = content.indexOf('/>', startPos);
var attribs = parseAttributes(content.substring(startPos + 4, endPos));
if (attribs['class'] == 'wysiwyg-break') {
endPos += 2;
chunkBefore = content.substring(0, startPos);
chunkAfter = content.substring(endPos);
content = chunkBefore + '<!--break-->' + chunkAfter;
}
}
break;
}
// Pass through to next handler in chain
return content;
/**
* Local function that parses the break image in and out.
*/
function parseAttributes (attribute_string) {
var attributeName = '', attributeValue = '', withInName, withInValue;
var attributes = new Array();
var whiteSpaceRegExp = new RegExp('^[ \n\r\t]+', 'g');
if (attribute_string == null || attribute_string.length < 2) {
return null;
}
withInName = withInValue = false;
for (var i = 0; i < attribute_string.length; i++) {
var chr = attribute_string.charAt(i);
if ((chr == '"' || chr == "'") && !withInValue) {
withInValue = true;
}
else if ((chr == '"' || chr == "'") && withInValue) {
withInValue = false;
var pos = attributeName.lastIndexOf(' ');
if (pos != -1) {
attributeName = attributeName.substring(pos+1);
}
attributes[attributeName.toLowerCase()] = attributeValue.substring(1).toLowerCase();
attributeName = '';
attributeValue = '';
}
else if (!whiteSpaceRegExp.test(chr) && !withInName && !withInValue) {
withInName = true;
}
if (chr == '=' && withInName) {
withInName = false;
}
if (withInName) {
attributeName += chr;
}
if (withInValue) {
attributeValue += chr;
}
}
return attributes;
}
},
handleNodeChange: function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
tinyMCE.switchClass(editor_id + '_wysiwyg_break', 'mceButtonNormal');
if (node == null) {
return;
}
do {
if (node.nodeName.toLowerCase() == 'img' && this.getAttrib(node, 'class').indexOf('wysiwyg-break') == 0) {
tinyMCE.switchClass(editor_id + '_wysiwyg_break', 'mceButtonSelected');
}
} while ((node = node.parentNode));
return true;
},
getAttrib: function(elm, name) {
return elm.getAttribute(name) ? elm.getAttribute(name) : '';
}
};
tinyMCE.addPlugin('wysiwyg', TinyMCE_wysiwygBreakPlugin);
// $Id$
tinyMCE.addToLang('break', {
title: 'Insert teaser break',
desc: 'Separate teaser and body of this content'
});
......@@ -228,46 +228,44 @@ function wysiwyg_editor_profile_form($edit) {
'#theme' => 'wysiwyg_editor_admin_button_table',
);
$metadata = _wysiwyg_editor_get_buttons(FALSE);
$plugins = _wysiwyg_editor_get_buttons(TRUE);
// Generate the button list.
foreach ($metadata as $name => $meta) {
foreach ($plugins as $name => $meta) {
if (isset($meta['buttons']) && is_array($meta['buttons'])) {
foreach ($meta['buttons'] as $button) {
if ($name != 'default') {
$img_src = drupal_get_path('module', 'wysiwyg_editor') ."/tinymce/jscripts/tiny_mce/plugins/$name/images/$name.gif";
// Handle plugins that have more than one button.
if (!file_exists($img_src)) {
$img_src = drupal_get_path('module', 'wysiwyg_editor') ."/tinymce/jscripts/tiny_mce/plugins/$name/images/$button.gif";
}
foreach ($meta['buttons'] as $button => $title) {
$img_src = $meta['path'] ."/images/$name.gif";
// Handle plugins that have more than one button.
if (!file_exists($img_src)) {
$img_src = $meta['path'] ."/images/$button.gif";
}
else {
$img_src = drupal_get_path('module', 'wysiwyg_editor') ."/tinymce/jscripts/tiny_mce/themes/advanced/images/$button.gif";
}
$b = file_exists($img_src) ? '<img src="'. base_path() . $img_src .'" title="'. $button .'" style="border: 1px solid grey; vertical-align: middle;" />' : $button;
if ($name == 'default') {
$title = $b;
$b = file_exists($img_src) ? '<img src="'. base_path() . $img_src .'" title="'. $button .'" style="border: 1px solid grey; vertical-align: middle;" />' : '';
if (isset($meta['url'])) {
$title = $b .' '. l($title, $meta['url'], array('target' => '_blank'));
}
else {
$title = isset($metadata[$name]['longname']) ? $metadata[$name]['longname'] : $name;
if (isset($metadata[$name]['infourl'])) {
$title = '<a href="'. $metadata[$name]['infourl'] .'" target="_blank">'. $title .'</a>';
}
$title = $b .' &#8211; '. $title;
$title = $b .' '. $title;
}
$form_value = isset($edit->settings['buttons'][$name .'-'. $button]) ? $edit->settings['buttons'][$name .'-'. $button] : NULL;
$form['buttons'][$name .'-'. $button] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $form_value);
$form['buttons'][$name][$button] = array(
'#type' => 'checkbox',
'#title' => $title,
'#default_value' => isset($edit->settings['buttons'][$name][$button]) ? $edit->settings['buttons'][$name][$button] : NULL,
);
}
}
else {
$title = $metadata[$name]['longname'] ? $metadata[$name]['longname'] : $name;
if ($metadata[$name]['infourl']) {
$title = '<a href="'. $metadata[$name]['infourl'] .'" target="_blank">'. $title .'</a>';
else if (isset($meta['extensions']) && is_array($meta['extensions'])) {
foreach ($meta['extensions'] as $extension => $title) {
if (isset($meta['url'])) {
$title = l($title, $meta['url'], array('target' => '_blank'));
}
else {
$title = $title;
}
$form['buttons'][$name][$extension] = array(
'#type' => 'checkbox',
'#title' => $title,
'#default_value' => isset($edit->settings['buttons'][$name][$extension]) ? $edit->settings['buttons'][$name][$extension] : NULL,
);
}
$form_value = isset($edit->settings['buttons'][$name]) ? $edit->settings['buttons'][$name] : NULL;
$form['buttons'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $form_value);
}
}
......@@ -414,8 +412,13 @@ function wysiwyg_editor_profile_form($edit) {
*/
function wysiwyg_editor_profile_form_submit($form_id, &$form_values) {
// Count enabled plugins for this profile.
$plugin_count = 0;
foreach ($form_values['buttons'] as $plugin => $buttons) {
$form_values['buttons'][$plugin] = array_filter($form_values['buttons'][$plugin]);
$plugin_count += count($form_values['buttons'][$plugin]);
}
$form_values['buttons'] = array_filter($form_values['buttons']);
$plugin_count = count($form_values['buttons']);
// Filter enabled roles for this profile.
$form_values['rids'] = array_filter($form_values['rids']);
......@@ -449,8 +452,10 @@ function theme_wysiwyg_editor_admin_button_table($form) {
$buttons = array();
// Flatten forms array.
foreach (element_children($form) as $key) {
$buttons[] = drupal_render($form[$key]);
foreach (element_children($form) as $name) {
foreach (element_children($form[$name]) as $button) {
$buttons[] = drupal_render($form[$name][$button]);
}
}
// Split checkboxes into rows with 3 columns.
......
; $Id$
name = Wysiwyg Editor
description = Allows users to edit contents with client-side editors.
package = User Interface
......@@ -62,6 +62,9 @@ function wysiwyg_editor_migrate_tinymce() {
// Disable TinyMCE module.
module_disable(array('tinymce'));
// Update configuration.
wysiwyg_editor_update_5001();
}
else {
drupal_set_message(t('To migrate your existing TinyMCE settings to Wysiwyg Editor, please update TinyMCE module to the latest official release, and re-install Wysiwyg Editor module.'));
......@@ -87,3 +90,28 @@ function wysiwyg_editor_update_5000() {
return $ret;
}
/**
* Convert buttons and plugins into associative array.
* Fix plugin count for old profiles.
*/
function wysiwyg_editor_update_5001() {
$ret = array();
$profiles = db_query("SELECT name, settings, plugin_count FROM {wysiwyg_editor_profile}");
while ($profile = db_fetch_array($profiles)) {
$settings = unserialize($profile['settings']);
if (isset($settings['form_id'])) {
$old_buttons = $settings['buttons'];
$settings['buttons'] = array();
$plugin_count = 0;
foreach ($old_buttons as $old_button => $enabled) {
list($plugin, $button) = explode('-', $old_button, 2);
$settings['buttons'][$plugin][$button] = 1;
$plugin_count++;
}
// We can't use update_sql() here because of curly braces in serialized array.
db_query("UPDATE {wysiwyg_editor_profile} SET settings = '%s', plugin_count = %d WHERE name = '%s'", serialize($settings), $plugin_count, $profile['name']);
}
}
return $ret;
}
......@@ -13,6 +13,9 @@ Drupal.wysiwygEditorInit = function () {
var config = Drupal.wysiwygEditorCloneObject(Drupal.settings.wysiwygEditor.configs[theme]);
tinyMCE.init(config);
}
for (var plugin in Drupal.settings.wysiwygEditor.plugins) {
tinyMCE.loadPlugin(plugin, Drupal.settings.wysiwygEditor.plugins[plugin]);
}
}
/**
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment