View source
<?php
function wysiwyg_schema() {
$schema['wysiwyg'] = array(
'description' => 'Stores Wysiwyg profiles.',
'fields' => array(
'format' => array(
'description' => 'The {filter_formats}.format of the text format.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'editor' => array(
'description' => 'Internal name of the editor attached to the text format.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'settings' => array(
'description' => 'Configuration settings for the editor.',
'type' => 'text',
'size' => 'normal',
'serialize' => TRUE,
),
),
'primary key' => array(
'format',
),
'foreign keys' => array(
'format' => array(
'table' => 'filter_formats',
'columns' => array(
'format' => 'format',
),
),
),
);
$schema['wysiwyg_user'] = array(
'description' => 'Stores user preferences for wysiwyg profiles.',
'fields' => array(
'uid' => array(
'description' => 'The {users}.uid of the user.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'format' => array(
'description' => 'The {filter_formats}.format of the text format.',
'type' => 'int',
'not null' => TRUE,
),
'status' => array(
'description' => 'Boolean indicating whether the format is enabled by default.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
),
'primary key' => array(
'uid',
'format',
),
'indexes' => array(
'format' => array(
'format',
),
),
'foreign keys' => array(
'uid' => array(
'table' => 'users',
'columns' => array(
'uid' => 'uid',
),
),
'format' => array(
'table' => 'filter_formats',
'columns' => array(
'format' => 'format',
),
),
),
);
return $schema;
}
function wysiwyg_install() {
drupal_install_schema('wysiwyg');
}
function wysiwyg_uninstall() {
drupal_uninstall_schema('wysiwyg');
}
function wysiwyg_enable() {
module_disable(array(
'ckeditor',
'editarea',
'editonpro',
'editor',
'fckeditor',
'freerte',
'htmlarea',
'htmlbox',
'jwysiwyg',
'markitup',
'nicedit',
'openwysiwyg',
'pegoeditor',
'quicktext',
'tinymce',
'tinymce_autoconf',
'tinytinymce',
'whizzywig',
'widgeditor',
'wymeditor',
'xstandard',
'yui_editor',
));
}
function _wysiwyg_install_get_formats() {
$formats = array();
$result = db_query("SELECT format, name FROM {filter_formats}");
while ($format = db_fetch_object($result)) {
$formats[$format->format] = $format->name;
$result2 = db_query("SELECT module, delta FROM {filters} WHERE format = %d", $format->format);
while ($filter = db_fetch_object($result2)) {
if ($filter->module == 'php') {
unset($formats[$format->format]);
break;
}
}
}
return $formats;
}
function wysiwyg_update_6001() {
$ret = array();
if (db_table_exists('wysiwyg')) {
return $ret;
}
db_create_table($ret, 'wysiwyg', array(
'fields' => array(
'format' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'editor' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'settings' => array(
'type' => 'text',
'size' => 'normal',
),
),
'primary key' => array(
'format',
),
));
$formats = _wysiwyg_install_get_formats();
$result = db_query("SELECT name, settings FROM {wysiwyg_profile}");
while ($profile = db_fetch_object($result)) {
$profile->settings = unserialize($profile->settings);
$profile->editor = $profile->settings['editor'];
unset($profile->settings['editor']);
unset($profile->settings['old_name']);
unset($profile->settings['name']);
unset($profile->settings['rids']);
break;
}
if ($profile) {
foreach ($formats as $format => $name) {
db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $format, $profile->editor, serialize($profile->settings));
$ret[] = array(
'success' => TRUE,
'query' => strtr('Wysiwyg profile %profile converted and associated with input format %format.', array(
'%profile' => check_plain($profile->name),
'%format' => check_plain($name),
)),
);
}
}
db_drop_table($ret, 'wysiwyg_profile');
db_drop_table($ret, 'wysiwyg_role');
return $ret;
}
function wysiwyg_update_6200() {
$ret = array();
_drupal_flush_css_js();
drupal_clear_css_cache();
drupal_clear_js_cache();
menu_rebuild();
cache_clear_all();
$ret[] = array(
'success' => TRUE,
'query' => 'Caches have been flushed.',
);
return $ret;
}
function wysiwyg_update_6201() {
$ret = array();
if (!db_table_exists('wysiwyg_user')) {
db_create_table($ret, 'wysiwyg_user', array(
'description' => 'Stores user preferences for wysiwyg profiles.',
'fields' => array(
'uid' => array(
'description' => 'The {users}.uid of the user.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'format' => array(
'description' => 'The {filter_formats}.format of the text format.',
'type' => 'int',
'not null' => FALSE,
),
'status' => array(
'description' => 'Boolean indicating whether the format is enabled by default.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
),
'indexes' => array(
'uid' => array(
'uid',
),
'format' => array(
'format',
),
),
'foreign keys' => array(
'uid' => array(
'table' => 'users',
'columns' => array(
'uid' => 'uid',
),
),
'format' => array(
'table' => 'filter_formats',
'columns' => array(
'format' => 'format',
),
),
),
));
}
return $ret;
}
function wysiwyg_update_6202() {
$ret = array();
$results = db_query("SELECT format, settings FROM {wysiwyg} WHERE editor = 'tinymce'");
while ($profile = db_fetch_object($results)) {
$settings = unserialize($profile->settings);
$changed = FALSE;
foreach (array(
'formatselect',
'fontselect',
'fontsizeselect',
'styleselect',
) as $button) {
if (isset($settings['buttons']['font'][$button])) {
$settings['buttons']['default'][$button] = $settings['buttons']['font'][$button];
unset($settings['buttons']['font'][$button]);
$changed = TRUE;
}
}
if ($changed) {
db_query("UPDATE {wysiwyg} SET settings='%s' WHERE format = '%s'", array(
serialize($settings),
$profile->format,
));
}
}
$ret[] = array(
'success' => TRUE,
'query' => 'TinyMCE profiles have been updated.',
);
return $ret;
}
function wysiwyg_update_6203() {
$ret = array();
$results = db_query('SELECT format, editor, settings FROM {wysiwyg}');
while ($profile = db_fetch_object($results)) {
$settings = unserialize($profile->settings);
$changed = FALSE;
switch ($profile->editor) {
case 'tinymce':
if (isset($settings['path_loc'])) {
$settings['theme_advanced_statusbar_location'] = $settings['path_loc'];
unset($settings['path_loc']);
$changed = TRUE;
}
if (isset($settings['toolbar_loc'])) {
$settings['theme_advanced_toolbar_location'] = $settings['toolbar_loc'];
unset($settings['toolbar_loc']);
$changed = TRUE;
}
if (isset($settings['toolbar_align'])) {
$settings['theme_advanced_toolbar_align'] = $settings['toolbar_align'];
unset($settings['toolbar_align']);
$changed = TRUE;
}
if (isset($settings['block_formats'])) {
$settings['theme_advanced_blockformats'] = $settings['block_formats'];
unset($settings['block_formats']);
$changed = TRUE;
}
if (isset($settings['css_classes'])) {
$settings['theme_advanced_styles'] = $settings['css_classes'];
unset($settings['css_classes']);
$changed = TRUE;
}
if (isset($settings['resizing'])) {
$settings['theme_advanced_resizing'] = $settings['resizing'];
unset($settings['resizing']);
$changed = TRUE;
}
break;
case 'ckeditor':
if (isset($settings['apply_source_formatting'])) {
$settings['simple_source_formatting'] = $settings['apply_source_formatting'];
unset($settings['apply_source_formatting']);
$changed = TRUE;
}
if (isset($settings['resizing'])) {
$settings['resize_enabled'] = $settings['resizing'];
unset($settings['resizing']);
$changed = TRUE;
}
if (isset($settings['toolbar_loc'])) {
$settings['toolbarLocation'] = $settings['toolbar_loc'];
unset($settings['toolbar_loc']);
$changed = TRUE;
}
if (isset($settings['paste_auto_cleanup_on_paste'])) {
$settings['forcePasteAsPlainText'] = $settings['paste_auto_cleanup_on_paste'];
unset($settings['paste_auto_cleanup_on_paste']);
$changed = TRUE;
}
if (isset($settings['css_classes'])) {
$settings['stylesSet'] = $settings['css_classes'];
unset($settings['css_classes']);
$changed = TRUE;
}
break;
case 'fckeditor':
if (isset($settings['apply_source_formatting'])) {
$settings['FormatSource'] = $settings['FormatOutput'] = $settings['apply_source_formatting'];
unset($settings['apply_source_formatting']);
$changed = TRUE;
}
if (isset($settings['paste_auto_cleanup_on_paste'])) {
$settings['ForcePasteAsPlainText'] = $settings['paste_auto_cleanup_on_paste'];
unset($settings['paste_auto_cleanup_on_paste']);
$changed = TRUE;
}
if (isset($settings['block_formats'])) {
$settings['FontFormats'] = strtr($settings['block_formats'], array(
',' => ';',
));
unset($settings['block_formats']);
$changed = TRUE;
}
break;
case 'yui':
if (isset($settings['resizing'])) {
$settings['autoHeight'] = $settings['resizing'];
unset($settings['resizing']);
$changed = TRUE;
}
break;
case 'openwysiwyg':
if (isset($settings['path_loc'])) {
$settings['StatusBarEnabled'] = $settings['path_loc'] != 'none';
unset($settings['path_loc']);
$changed = TRUE;
}
break;
default:
}
if ($changed) {
db_query("UPDATE {wysiwyg} SET settings='%s' WHERE format = '%s'", array(
serialize($settings),
$profile->format,
));
}
}
$ret[] = array(
'success' => TRUE,
'query' => 'Editor profiles have been updated.',
);
return $ret;
}
function wysiwyg_update_6204() {
$ret = array();
db_drop_index($ret, 'wysiwyg_user', 'uid');
db_drop_index($ret, 'wysiwyg_user', 'format');
db_change_field($ret, 'wysiwyg_user', 'format', 'format', array(
'type' => 'int',
'not null' => TRUE,
), array(
'primary key' => array(
'uid',
'format',
),
'indexes' => array(
'uid' => array(
'uid',
),
),
));
return $ret;
}
function wysiwyg_update_6205() {
db_query("DELETE FROM {wysiwyg} WHERE editor = ''");
$result = db_query('SELECT format, editor, settings FROM {wysiwyg}');
drupal_load('module', 'wysiwyg');
while ($profile = db_fetch_object($result)) {
$settings = unserialize($profile->settings);
$editor = wysiwyg_get_editor($profile->editor);
if (!empty($settings['_profile_preferences'])) {
continue;
}
$preferences = array(
'default' => $settings['default'],
'show_toggle' => $settings['show_toggle'],
'user_choose' => $settings['user_choose'],
'version' => NULL,
);
unset($settings['default'], $settings['show_toggle'], $settings['user_choose']);
if (!empty($settings['library'])) {
$prefereces['library'] = $settings['library'];
unset($settings['library']);
}
if ($editor['installed']) {
$preferences['version'] = $editor['installed version'];
}
$settings['_profile_preferences'] = $preferences;
db_query("UPDATE {wysiwyg} SET settings='%s' WHERE format = %d", array(
serialize($settings),
$profile->format,
));
}
$ret[] = array(
'success' => TRUE,
'query' => 'Editor profiles have been updated.',
);
return $ret;
}