123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- <?php
- /**
- * @file
- * Installation functions for Wysiwyg module.
- */
- /**
- * Implementation of hook_schema().
- */
- function wysiwyg_schema() {
- $schema['wysiwyg'] = array(
- 'description' => 'Stores Wysiwyg profiles.',
- 'fields' => array(
- 'format' => array(
- 'description' => 'The {filter_format}.format of the text format.',
- 'type' => 'varchar',
- 'length' => 255,
- // Primary keys are implicitly not null.
- 'not null' => TRUE,
- ),
- '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_format',
- '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_format}.format of the text format.',
- 'type' => 'varchar',
- 'length' => 255,
- '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(
- 'uid' => array('uid'),
- ),
- 'foreign keys' => array(
- 'uid' => array(
- 'table' => 'users',
- 'columns' => array('uid' => 'uid'),
- ),
- 'format' => array(
- 'table' => 'filter_format',
- 'columns' => array('format' => 'format'),
- ),
- ),
- );
- return $schema;
- }
- /**
- * Implementation of hook_enable().
- */
- function wysiwyg_enable() {
- // Disable conflicting, obsolete editor integration modules whenever this
- // module is enabled. This is crude, but the only way to ensure no conflicts.
- 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',
- ));
- }
- /**
- * Implements hook_update_dependencies().
- */
- function wysiwyg_update_dependencies() {
- // Ensure that format columns are only changed after Filter module has changed
- // the primary records.
- $dependencies['wysiwyg'][7000] = array(
- 'filter' => 7010,
- );
- return $dependencies;
- }
- /**
- * Implements hook_update_last_removed().
- */
- function wysiwyg_update_last_removed() {
- // Users should upgrade to the latest 6.x-2.x release before upgrading to
- // 7.x-2.x. Some 7xxx functions duplicate work from 6xxx functions in 6.x-2.x
- // because both branches are supported in parallel, but changes will only be
- // applied once anyway because of safeguards.
- return 6202;
- }
- /**
- * Change {wysiwyg}.format into a string.
- */
- function wysiwyg_update_7000() {
- db_drop_primary_key('wysiwyg');
- db_change_field('wysiwyg', 'format', 'format', array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- ));
- db_add_primary_key('wysiwyg', array('format'));
- }
- /**
- * Create the {wysiwyg_user} table.
- */
- function wysiwyg_update_7200() {
- if (!db_table_exists('wysiwyg_user')) {
- db_create_table('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_format}.format of the text format.',
- 'type' => 'varchar',
- 'length' => 255,
- '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_format',
- 'columns' => array('format' => 'format'),
- ),
- ),
- ));
- }
- else {
- db_change_field('wysiwyg_user', 'format', 'format', array(
- 'description' => 'The {filter_format}.format of the text format.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => FALSE,
- ));
- }
- }
- /**
- * Update enabled font plugin buttons to default plugin in TinyMCE profiles.
- */
- function wysiwyg_update_7201() {
- $query = db_select('wysiwyg', 'w')
- ->fields('w', array('format', 'settings'))
- ->condition('editor', 'tinymce');
- foreach ($query->execute() as $profile) {
- $settings = unserialize($profile->settings);
- // Move enabled 'font' buttons into 'default' plugin buttons.
- $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_update('wysiwyg')
- ->condition('format', $profile->format)
- ->fields(array(
- 'settings' => serialize($settings),
- ))
- ->execute();
- }
- }
- }
- /**
- * Update internal names of settings.
- */
- function wysiwyg_update_7202() {
- $query = db_select('wysiwyg', 'w')
- ->fields('w', array('format', 'editor', 'settings'));
- foreach ($query->execute() as $profile) {
- $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':
- // The resizing setting is triggering autoHeight instead of resize.
- 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:
- // Do not touch any other profiles since the extra settings won't hurt.
- }
- if ($changed) {
- db_update('wysiwyg')
- ->condition('format', $profile->format)
- ->fields(array(
- 'settings' => serialize($settings),
- ))
- ->execute();
- }
- }
- }
- /**
- * Add primary index to {wysiwyg_user}.
- */
- function wysiwyg_update_7203() {
- db_drop_index('wysiwyg_user', 'uid');
- db_drop_index('wysiwyg_user', 'format');
- db_change_field('wysiwyg_user', 'format', 'format',
- array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- ),
- array(
- 'primary key' => array('uid', 'format'),
- 'indexes' => array(
- 'uid' => array('uid'),
- ),
- )
- );
- }
- /**
- * Remove empty editor profiles and update existing profiles.
- */
- function wysiwyg_update_7204() {
- // Remove unused profiles.
- $query = db_delete('wysiwyg')
- ->condition('editor', '')
- ->execute();
- $query = db_select('wysiwyg', 'w')
- ->fields('w', array('format', 'editor', 'settings'));
- foreach ($query->execute() as $profile) {
- // Clear the editing caches.
- if (module_exists('ctools')) {
- ctools_include('object-cache');
- ctools_object_cache_clear_all('wysiwyg_profile', 'format' . $profile->format);
- }
- cache_clear_all('wysiwyg_profile:format' . $profile->format, 'cache');
- // Move profile state to its own section.
- $settings = unserialize($profile->settings);
- if (!empty($settings['_profile_preferences'])) {
- // Skip in case of re-run.
- continue;
- }
- $preferences = array(
- 'add_to_summaries' => $settings['add_to_summaries'],
- 'default' => $settings['default'],
- 'show_toggle' => $settings['show_toggle'],
- 'user_choose' => $settings['user_choose'],
- 'version' => NULL,
- );
- unset($settings['add_to_summaries'], $settings['default'], $settings['show_toggle'], $settings['user_choose']);
- if (!empty($settings['library'])) {
- $prefereces['library'] = $settings['library'];
- unset($settings['library']);
- }
- $editor = wysiwyg_get_editor($profile->editor);
- if ($editor['installed']) {
- $preferences['version'] = $editor['installed version'];
- }
- $settings['_profile_preferences'] = $preferences;
- db_update('wysiwyg')
- ->condition('format', $profile->format)
- ->fields(array(
- 'settings' => serialize($settings),
- ))
- ->execute();
- }
- wysiwyg_profile_cache_clear();
- }
|