Commit eb714832 authored by sun's avatar sun

#321216 by sun: Replaced Wysiwyg Editor module with Wysiwyg module.

parent 94b665fa
......@@ -10,6 +10,7 @@ Wysiwyg 6.x-x.x, xxxx-xx-xx
Wysiwyg 6.x-0.4, 2008-10-14
---------------------------
#321216 by sun: Replaced Wysiwyg Editor module with Wysiwyg module.
#321086 by sun: Fixed (old-style) Teaser break plugin breaks TinyMCE 3.
#316507 by sun: Code clean-up; editor settings should be cloned for init, too.
#282717 by sun: Fixed FCKeditor default settings while FCKeditor maintainers get
......
......@@ -148,12 +148,12 @@ function wysiwyg_tinymce_settings($editor, $config, $theme) {
// later.
$init['extensions'] = array();
// $init['extended_valid_elements'] are just stacked, unique'd later, and
// transformed into a comma-separated string in wysiwyg_editor_add_settings().
// transformed into a comma-separated string in wysiwyg_add_editor_settings().
// @todo Needs a complete plugin API redesign using arrays for
// tag => attributes definitions and array_merge_recursive().
$init['extended_valid_elements'] = array();
$plugins = wysiwyg_editor_get_plugins($editor['name']);
$plugins = wysiwyg_get_plugins($editor['name']);
foreach ($config['buttons'] as $plugin => $buttons) {
foreach ($buttons as $button => $enabled) {
// Iterate separately over buttons and extensions properties.
......
<?php
// $Id$
/**
* @file
* Integrate Wysiwyg editors into Drupal.
......@@ -12,7 +11,7 @@
*
* @todo Move into hook_menu(), resp. FAPI functions.
*/
function wysiwyg_editor_admin($arg = '', $name = '') {
function wysiwyg_admin($arg = '', $name = '') {
switch ($arg) {
case 'add':
$breadcrumb[] = l(t('Home'), NULL);
......@@ -22,27 +21,27 @@ function wysiwyg_editor_admin($arg = '', $name = '') {
$breadcrumb[] = l(t('Wysiwyg Profiles'), 'admin/settings/wysiwyg/profile');
drupal_set_breadcrumb($breadcrumb);
$profile = new stdClass;
return drupal_get_form('wysiwyg_editor_profile_form', $profile);
return drupal_get_form('wysiwyg_profile_form', $profile);
case 'edit':
drupal_set_title(t('Edit Wysiwyg Editor profile'));
return drupal_get_form('wysiwyg_editor_profile_form', wysiwyg_editor_load_profile($name));
return drupal_get_form('wysiwyg_profile_form', wysiwyg_load_profile($name));
case 'delete':
wysiwyg_editor_profile_delete($name);
wysiwyg_profile_delete($name);
drupal_set_message(t('Wysiwyg profile %name has been deleted.', array('%name' => $name)));
drupal_goto('admin/settings/wysiwyg/profile');
break;
default:
return wysiwyg_editor_profile_overview();
return wysiwyg_profile_overview();
}
}
/**
* Return an HTML form for profile configuration.
*/
function wysiwyg_editor_profile_form($form_state, $profile) {
function wysiwyg_profile_form($form_state, $profile) {
// Merge in defaults.
settype($profile, 'array');
$profile += array(
......@@ -172,10 +171,10 @@ function wysiwyg_editor_profile_form($form_state, $profile) {
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
'#theme' => 'wysiwyg_editor_admin_button_table',
'#theme' => 'wysiwyg_admin_button_table',
);
$plugins = wysiwyg_editor_get_plugins($profile->settings['editor']);
$plugins = wysiwyg_get_plugins($profile->settings['editor']);
// Generate the button list.
foreach ($plugins as $name => $meta) {
if (isset($meta['buttons']) && is_array($meta['buttons'])) {
......@@ -354,11 +353,11 @@ function wysiwyg_editor_profile_form($form_state, $profile) {
}
/**
* Form submit callback for wysiwyg_editor_profile_form_build().
* Submit callback for Wysiwyg profile form.
*
* @see wysiwyg_editor_profile_form()
* @see wysiwyg_profile_form()
*/
function wysiwyg_editor_profile_form_submit($form, &$form_state) {
function wysiwyg_profile_form_submit($form, &$form_state) {
// Count enabled plugins for this profile.
$plugin_count = 0;
foreach ($form_state['values']['buttons'] as $plugin => $buttons) {
......@@ -373,8 +372,8 @@ function wysiwyg_editor_profile_form_submit($form, &$form_state) {
// Delete existing profile(s) with the current profile name.
if (!empty($form_state['values']['old_name'])) {
db_query("DELETE FROM {wysiwyg_editor_profile} WHERE name = '%s' OR name = '%s'", $form_state['values']['name'], $form_state['values']['old_name']);
db_query("DELETE FROM {wysiwyg_editor_role} WHERE name = '%s' OR name = '%s'", $form_state['values']['name'], $form_state['values']['old_name']);
db_query("DELETE FROM {wysiwyg_profile} WHERE name = '%s' OR name = '%s'", $form_state['values']['name'], $form_state['values']['old_name']);
db_query("DELETE FROM {wysiwyg_role} WHERE name = '%s' OR name = '%s'", $form_state['values']['name'], $form_state['values']['old_name']);
}
// Remove FAPI values.
......@@ -382,16 +381,16 @@ function wysiwyg_editor_profile_form_submit($form, &$form_state) {
unset($form_state['values']['submit'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token']);
// Insert new profile data.
db_query("INSERT INTO {wysiwyg_editor_profile} (name, settings, plugin_count) VALUES ('%s', '%s', %d)", $form_state['values']['name'], serialize($form_state['values']), $plugin_count);
db_query("INSERT INTO {wysiwyg_profile} (name, settings, plugin_count) VALUES ('%s', '%s', %d)", $form_state['values']['name'], serialize($form_state['values']), $plugin_count);
foreach ($form_state['values']['rids'] as $rid => $value) {
db_query("INSERT INTO {wysiwyg_editor_role} (name, rid) VALUES ('%s', %d)", $form_state['values']['name'], $rid);
db_query("INSERT INTO {wysiwyg_role} (name, rid) VALUES ('%s', %d)", $form_state['values']['name'], $rid);
}
if (isset($form_state['values']['old_name'])) {
drupal_set_message(t('Wysiwyg Editor profile %name has been updated.', array('%name' => $form_state['values']['name'])));
drupal_set_message(t('Wysiwyg profile %name has been updated.', array('%name' => $form_state['values']['name'])));
}
else {
drupal_set_message(t('Wysiwyg Editor profile %name has been created.', array('%name' => $form_state['values']['name'])));
drupal_set_message(t('Wysiwyg profile %name has been created.', array('%name' => $form_state['values']['name'])));
}
drupal_goto('admin/settings/wysiwyg/profile');
}
......@@ -399,7 +398,7 @@ function wysiwyg_editor_profile_form_submit($form, &$form_state) {
/**
* Layout for the buttons in the Wysiwyg Editor profile form.
*/
function theme_wysiwyg_editor_admin_button_table(&$form) {
function theme_wysiwyg_admin_button_table(&$form) {
$buttons = array();
// Flatten forms array.
......@@ -432,7 +431,7 @@ function theme_wysiwyg_editor_admin_button_table(&$form) {
/**
* Display overview of setup Wysiwyg Editor profiles; menu callback.
*/
function wysiwyg_editor_profile_overview() {
function wysiwyg_profile_overview() {
$output = '';
$usable = TRUE;
......@@ -470,7 +469,7 @@ function wysiwyg_editor_profile_overview() {
return $output;
}
$profiles = wysiwyg_editor_load_profile();
$profiles = wysiwyg_load_profile();
if ($profiles) {
$roles = user_roles(FALSE, 'access wysiwyg editor');
$header = array(t('Profile'), t('Editor'), t('Roles'), t('Operations'));
......@@ -491,8 +490,8 @@ function wysiwyg_editor_profile_overview() {
/**
* Remove a profile from the database.
*/
function wysiwyg_editor_profile_delete($name) {
db_query("DELETE FROM {wysiwyg_editor_profile} WHERE name = '%s'", $name);
db_query("DELETE FROM {wysiwyg_editor_role} WHERE name = '%s'", $name);
function wysiwyg_profile_delete($name) {
db_query("DELETE FROM {wysiwyg_profile} WHERE name = '%s'", $name);
db_query("DELETE FROM {wysiwyg_role} WHERE name = '%s'", $name);
}
<?php
// $Id$
/**
* hook_wysiwyg_plugin(). Return an array of editor plugins.
*
* Each wysiwyg editor as well as each contrib module implementing an editor
* plugin has to return an associative array of available plugins. Each module
* can add one or more plugins and editor buttons.
*
* Notes for TinyMCE:
* A module is able to override almost all TinyMCE initialization settings.
* However, modules should only make use of that if a plugin really needs to,
* because customized configuration settings may clash with overrides by another
* module. TinyMCE automatically assigns the baseURL of your plugin to the plugin
* object. If you need to load or access additional files from your plugin
* directory, retrieve the path via this.baseURL. tinyMCE.baseURL returns the
* path of TinyMCE and not your module. For example:
* @code
* initInstance: function(inst) {
* tinyMCE.importCSS(inst.getDoc(), this.baseURL + '/myplugin.css');
* },
* @endcode
*
* @param string $editor
* An (lowercase) editor name to return plugins for.
* @return array
* An associative array having internal plugin names as keys, an array of
* plugin meta-information as values:
* - type: 'external' (optional); if omitted, wysiwyg editors will likely
* search for the plugin in their own plugins folder.
* - title: A human readable title of the plugin.
* - description: A (one-line) description of the plugin.
* - path: The patch to the javascript plugin.
* - callback: A Drupal menu callback returning the plugin UI. A plugin
* should return a callback *or* a path.
* - icon: An icon (usually 16x16 pixels) for the plugin button (optional).
* - ... Any other custom editor settings (optional).
*
* @todo Move this template into hooks.php.
*/
function hook_wysiwyg_plugin($editor) {
switch ($editor) {
case 'tinymce':
return array(
'myplugin' => array(
'type' => 'external',
'title' => t('My plugin title'),
'description' => t('My plugin title'),
// Regular callback URL for external TinyMCE plugins.
'path' => drupal_get_path('module', 'mymodule') .'/myplugin',
// Wysiwyg wrapper plugin AJAX callback.
'callback' => url('myplugin/browse'),
'icon' => drupal_get_path('module', 'mymodule') .'/myplugin/myplugin.png',
'extended_valid_elements' => array('tag[attribute1|attribute2=default_value]'),
// Might need to be set later on; after retrieving customized editor
// layout.
'theme_advanced_buttons1' => array(t('Button title (optional)') => 'myplugin'),
),
);
}
}
/* $Id$ */
/* TinyMCE */
/* TinyMCE 2.x */
.mceToolbarTop a, .mceToolbarBottom a { float: left; }
.mceSeparatorLine { float: left; margin-top: 3px; }
.mceSelectList { float: left; margin-bottom: 1px; }
......
; $Id$
name = Wysiwyg
description = Allows users to edit contents with client-side editors.
package = User interface
core = 6.x
<?php
// $Id$
/**
* Implementation of hook_schema().
*/
function wysiwyg_schema() {
$schema = array();
$schema['wysiwyg_profile'] = array(
'description' => t('Stores Wysiwyg Editor profiles.'),
'fields' => array(
'name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
'settings' => array('type' => 'text', 'size' => 'normal'),
'plugin_count' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
),
'primary key' => array('name'),
);
$schema['wysiwyg_role'] = array(
'description' => t('Stores user role access permissions for Wysiwyg Editor profiles.'),
'fields' => array(
'name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
'rid' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
),
'primary key' => array('name', 'rid'),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function wysiwyg_install() {
drupal_install_schema('wysiwyg');
// Import data from old editor modules.
wysiwyg_migrate_wysiwyg_editor();
wysiwyg_migrate_tinymce();
}
/**
* Implementation of hook_uninstall()
*/
function wysiwyg_uninstall() {
drupal_uninstall_schema('wysiwyg');
}
/**
* Migrate from Wysiwyg Editor.
*/
function wysiwyg_migrate_wysiwyg_editor() {
if (db_table_exists('wysiwyg_editor_profile')) {
// Import Wysiwyg Editor profiles.
db_query('INSERT INTO {wysiwyg_profile} (name, settings, plugin_count) SELECT name, settings, plugin_count FROM {wysiwyg_editor_profile}');
// Import Wysiwyg Editor profile role associations.
db_query('INSERT INTO {wysiwyg_role} (name, rid) SELECT name, rid FROM {wysiwyg_editor_role}');
// Disable Wysiwyg Editor module.
module_disable(array('wysiwyg_editor'));
drupal_set_message(t('Wysiwyg Editor module can be safely uninstalled now.'));
}
}
/**
* Migrate from TinyMCE.
*/
function wysiwyg_migrate_tinymce() {
if (db_table_exists('tinymce_settings')) {
$schema = db_result(db_query("SELECT schema_version FROM {system} WHERE name = 'tinymce'"));
if ($schema >= 1) {
// Import TinyMCE settings.
db_query('INSERT INTO {wysiwyg_profile} (name, settings) SELECT name, settings FROM {tinymce_settings}');
// Import TinyMCE profile role associations.
db_query('INSERT INTO {wysiwyg_role} (name, rid) SELECT name, rid FROM {tinymce_role}');
// Migrate profile configurations.
// Convert buttons/plugins into an associative array and fix plugin count.
$profiles = db_query("SELECT name, settings, plugin_count FROM {wysiwyg_profile}");
while ($profile = db_fetch_array($profiles)) {
$settings = unserialize($profile['settings']);
if (isset($settings['form_id'])) {
$old_buttons = (isset($settings['buttons']) ? $settings['buttons'] : array());
$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_profile} SET settings = '%s', plugin_count = %d WHERE name = '%s'", serialize($settings), $plugin_count, $profile['name']);
}
}
// Disable TinyMCE module.
module_disable(array('tinymce'));
drupal_set_message(t('TinyMCE module can be safely uninstalled now.'));
}
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.'));
}
}
}
This diff is collapsed.
......@@ -5,13 +5,13 @@
/**
* Implementation of hook_wysiwyg_plugin().
*/
function wysiwyg_editor_wysiwyg_plugin($editor, $version) {
function wysiwyg_wysiwyg_plugin($editor, $version) {
switch ($editor) {
case 'tinymce':
if ($version < 3) {
return array(
'wysiwyg' => array(
'path' => drupal_get_path('module', 'wysiwyg_editor') .'/plugins/break/editor_plugin.js',
'path' => drupal_get_path('module', 'wysiwyg') .'/plugins/break/editor_plugin.js',
'buttons' => array('break' => t('Teaser break')),
'url' => 'http://drupal.org/project/wysiwyg',
),
......
; $Id$
name = Wysiwyg Editor
description = Allows users to edit contents with client-side editors.
name = Wysiwyg Editor (UNINSTALL)
description = Please uninstall this module after running update.php.
package = User interface
core = 6.x
<?php
// $Id$
/**
* Implementation of hook_schema().
*/
......@@ -27,15 +26,6 @@ function wysiwyg_editor_schema() {
return $schema;
}
/**
* Implementation of hook_install().
*/
function wysiwyg_editor_install() {
drupal_install_schema('wysiwyg_editor');
// Import data from old editor modules.
wysiwyg_editor_migrate_tinymce();
}
/**
* Implementation of hook_uninstall()
*/
......@@ -43,57 +33,6 @@ function wysiwyg_editor_uninstall() {
drupal_uninstall_schema('wysiwyg_editor');
}
/**
* Migrate from TinyMCE.
*/
function wysiwyg_editor_migrate_tinymce() {
if (db_table_exists('tinymce_settings')) {
$schema = db_result(db_query("SELECT schema_version FROM {system} WHERE name = 'tinymce'"));
if ($schema >= 1) {
// Import TinyMCE settings.
db_query('INSERT INTO {wysiwyg_editor_profile} (name, settings) SELECT name, settings FROM {tinymce_settings}');
// Import TinyMCE profile role assignments.
db_query('INSERT INTO {wysiwyg_editor_role} (name, rid) SELECT name, rid FROM {tinymce_role}');
// 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.'));
}
}
}
/**
* Convert buttons and plugins into associative array and fix plugin count for old profiles.
*
* Note: This update is required for wysiwyg_editor_migrate_tinymce().
*/
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 = (isset($settings['buttons']) ? $settings['buttons'] : array());
$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;
}
/**
* Add editor key to wysiwyg profiles.
*/
......@@ -112,3 +51,20 @@ function wysiwyg_editor_update_6002() {
return $ret;
}
/**
* Enable Wysiwyg module.
*/
function wysiwyg_editor_update_6003() {
$ret = array();
if (!module_exists('wysiwyg')) {
// Load Wysiwyg module.
module_enable(array('wysiwyg'));
// Invoke module installation.
module_invoke('wysiwyg', 'install');
// Disable Wysiwyg Editor module.
module_disable(array('wysiwyg_editor'));
$ret[] = array('success' => TRUE, 'query' => t('Wysiwyg Editor module has been disabled and replaced with Wysiwyg module. Your Wysiwyg profiles should have been migrated.'));
}
return $ret;
}
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