function _wysiwyg_tinymce_migrate_settings in Wysiwyg 6.2
Same name and namespace in other branches
- 7.2 editors/tinymce.inc \_wysiwyg_tinymce_migrate_settings()
Callback to migrate settings between known TinyMCE versions.
1 string reference to '_wysiwyg_tinymce_migrate_settings'
- wysiwyg_tinymce_editor in editors/
tinymce.inc - Plugin implementation of hook_editor().
File
- editors/
tinymce.inc, line 951 - Editor integration functions for TinyMCE.
Code
function _wysiwyg_tinymce_migrate_settings(&$settings, $editor, $profile_version, $installed_version) {
$version_diff = version_compare($installed_version, $profile_version);
// Default to no changes needed.
$migrated_version = TRUE;
if ($version_diff === 1) {
// Upgrading, starting at the profile version going up.
if (version_compare($profile_version, '3.4b1', '<') && version_compare($installed_version, '3.4b1', '>=')) {
if (isset($settings['apply_source_formatting'])) {
$settings['indent'] = $settings['apply_source_formatting'];
unset($settings['apply_source_formatting']);
}
$migrated_version = '3.4b1';
}
if (version_compare($profile_version, '4', '<') && version_compare($installed_version, '4', '>=')) {
if (isset($settings['buttons']['advimage']['advimage']) && $settings['buttons']['advimage']['advimage']) {
$settings['image_advtab'] = TRUE;
}
if (isset($settings['theme']) && ($settings['theme'] === 'advanced' || $settings['theme'] === 'simple')) {
$settings['theme'] = 'modern';
}
if (isset($settings['theme_advanced_blockformats'])) {
$formats = array();
foreach (explode(',', $settings['theme_advanced_blockformats']) as $block) {
switch ($block[0]) {
case 'p':
$formats[] = 'Paragraph=p';
break;
case 'h':
$formats[] = 'Heading ' . $block[1] . '=' . $block;
break;
default:
$formats[] = strtoupper($block[0]) . substr($block, 1) . '=' . $block;
}
}
$settings['block_formats'] = implode(';', $formats);
unset($settings['theme_advanced_blockformats']);
}
$settings['resize'] = FALSE;
if (!empty($settings['theme_advanced_resizing'])) {
if (!empty($settings['theme_advanced_resize_horizontal'])) {
$settings['resize'] = 'both';
}
else {
$settings['resize'] = TRUE;
}
}
unset($settings['theme_advanced_resizing'], $settings['theme_advanced_resize_horizontal'], $settings['theme_advanced_toolbar_location'], $settings['theme_advanced_toolbar_align'], $settings['theme_advanced_statusbar_location'], $settings['theme_advanced_styles']);
$fixed_buttons = array();
foreach ($settings['buttons'] as $plugin => $buttons) {
foreach ($buttons as $button => $enabled) {
$converted = _wysiwyg_tinymce_3_to_4_plugin_remap($plugin, $button);
if ($converted) {
$fixed_buttons[$converted[0]][$converted[1]] = $enabled;
}
}
}
$settings['buttons'] = $fixed_buttons;
$migrated_version = '4.0.0';
}
if (version_compare($profile_version, '4.5.0', '<') && version_compare($installed_version, '4.5.0', '>=')) {
// The list buttons now require the lists plugin.
if (!empty($settings['buttons']['default']['bullist'])) {
$settings['buttons']['lists']['bullist'] = 1;
}
if (!empty($settings['buttons']['default']['numlist'])) {
$settings['buttons']['lists']['numlist'] = 1;
}
unset($settings['buttons']['default']['bullist'], $settings['buttons']['default']['numlist']);
$migrated_version = '4.5.0';
}
}
else {
// Downgrading, starting at the profile version going down.
if (version_compare($profile_version, '4.5.0', '>=') && version_compare($installed_version, '4.5.0', '<')) {
unset($settings['buttons']['toc']);
if (!empty($settings['buttons']['lists']['bullist'])) {
$settings['buttons']['default']['bullist'] = 1;
}
if (!empty($settings['buttons']['lists']['numlist'])) {
$settings['buttons']['default']['numlist'] = 1;
}
unset($settings['buttons']['lists']);
$migrated_version = '4.5.0';
}
if (version_compare($profile_version, '4.3.0', '>=') && version_compare($installed_version, '4.3.0', '<')) {
unset($settings['buttons']['codesample']);
$migrated_version = '4.2.7';
}
if (version_compare($profile_version, '4', '>=') && version_compare($installed_version, '4', '<')) {
if (isset($settings['theme']) && $settings['theme'] === 'modern') {
$settings['theme'] = 'advanced';
}
if (!isset($settings['block_formats'])) {
$formats = array();
foreach (explode(';', $settings['block_formats']) as $block) {
$parts = explode('=', $block, 2);
$formats[] = $parts[1];
}
$settings['theme_advanced_blockformats'] = implode(',', $formats);
unset($settings['block_formats']);
}
$settings['theme_advanced_resizing'] = $settings['theme_advanced_resize_horizontal'] = FALSE;
if ($settings['resize'] == 'both' || $settings['resize'] == TRUE) {
$settings['theme_advanced_resizing'] = TRUE;
if ($settings['resize'] == 'both') {
$settings['theme_advanced_resize_horizontal'] = TRUE;
}
}
unset($settings['resize']);
$fixed_buttons = array();
foreach ($settings['buttons'] as $plugin => $buttons) {
foreach ($buttons as $button => $enabled) {
$converted = _wysiwyg_tinymce_4_to_3_plugin_remap($plugin, $button);
if (is_array($converted[0])) {
foreach ($converted as $sub_converted) {
$fixed_buttons[$sub_converted[0]][$sub_converted[1]] = $enabled;
}
}
else {
if ($converted) {
$fixed_buttons[$converted[0]][$converted[1]] = $enabled;
}
}
}
}
$settings['buttons'] = $fixed_buttons;
if (!empty($settings['image_advtab'])) {
$settings['buttons']['advimage']['advimage'] = 1;
unset($settings['image_advtab']);
}
$migrated_version = '4.0';
}
if (version_compare($profile_version, '3.4b1', '>=') && version_compare($installed_version, '3.4b1', '<')) {
if (isset($settings['indent'])) {
$settings['apply_source_formatting'] = $settings['indent'];
unset($settings['indent']);
}
$migrated_version = '3.4b1';
}
}
return $migrated_version;
}