#824710 by TwoD: CKEditor not disabled upon enabling.
[project/wysiwyg.git] / wysiwyg.install
1 <?php
2 // $Id$
3
4 /**
5 * Implementation of hook_schema().
6 */
7 function wysiwyg_schema() {
8 $schema['wysiwyg'] = array(
9 'description' => t('Stores Wysiwyg profiles.'),
10 'fields' => array(
11 'format' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
12 'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
13 'settings' => array('type' => 'text', 'size' => 'normal'),
14 ),
15 'primary key' => array('format'),
16 );
17 return $schema;
18 }
19
20 /**
21 * Implementation of hook_enable().
22 */
23 function wysiwyg_enable() {
24 // Disable conflicting, obsolete editor integration modules whenever this
25 // module is enabled. This is crude, but the only way to ensure no conflicts.
26 module_disable(array(
27 'ckeditor',
28 'editarea',
29 'editonpro',
30 'editor',
31 'fckeditor',
32 'freerte',
33 'htmlarea',
34 'htmlbox',
35 'jwysiwyg',
36 'markitup',
37 'nicedit',
38 'openwysiwyg',
39 'pegoeditor',
40 'quicktext',
41 'tinymce',
42 'tinymce_autoconf',
43 'tinytinymce',
44 'whizzywig',
45 'widgeditor',
46 'wymeditor',
47 'xstandard',
48 'yui_editor',
49 ));
50 }
51
52 /**
53 * Retrieve a list of input formats to associate profiles to.
54 */
55 function _wysiwyg_install_get_formats() {
56 $formats = array();
57 $result = db_query("SELECT format, name FROM {filter_formats}");
58 while ($format = db_fetch_object($result)) {
59 // Build a list of all formats.
60 $formats[$format->format] = $format->name;
61 // Fetch filters.
62 $result2 = db_query("SELECT module, delta FROM {filters} WHERE format = %d", $format->format);
63 while ($filter = db_fetch_object($result2)) {
64 // If PHP filter is enabled, remove this format.
65 if ($filter->module == 'php') {
66 unset($formats[$format->format]);
67 break;
68 }
69 }
70 }
71 return $formats;
72 }
73
74 /**
75 * Associate Wysiwyg profiles with input formats.
76 *
77 * Since there was no association yet, we can only assume that there is one
78 * profile only, and that profile must be duplicated and assigned to all input
79 * formats (except PHP code format). Also, input formats already have
80 * titles/names, so Wysiwyg profiles do not need an own.
81 *
82 * Because input formats are already granted to certain user roles only, we can
83 * remove our custom Wysiwyg profile permissions. A 1:1 relationship between
84 * input formats and permissions makes plugin_count obsolete, too.
85 *
86 * Since the resulting table is completely different, a new schema is installed.
87 */
88 function wysiwyg_update_6001() {
89 $ret = array();
90 if (db_table_exists('wysiwyg')) {
91 return $ret;
92 }
93 // Install new schema.
94 db_create_table($ret, 'wysiwyg', array(
95 'fields' => array(
96 'format' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
97 'editor' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
98 'settings' => array('type' => 'text', 'size' => 'normal'),
99 ),
100 'primary key' => array('format'),
101 ));
102
103 // Fetch all input formats.
104 $formats = _wysiwyg_install_get_formats();
105
106 // Fetch all profiles.
107 $result = db_query("SELECT name, settings FROM {wysiwyg_profile}");
108 while ($profile = db_fetch_object($result)) {
109 $profile->settings = unserialize($profile->settings);
110 // Extract editor name from profile settings.
111 $profile->editor = $profile->settings['editor'];
112 // Clean-up.
113 unset($profile->settings['editor']);
114 unset($profile->settings['old_name']);
115 unset($profile->settings['name']);
116 unset($profile->settings['rids']);
117 // Sorry. There Can Be Only One. ;)
118 break;
119 }
120
121 if ($profile) {
122 // Rebuild profiles and associate with input formats.
123 foreach ($formats as $format => $name) {
124 // Insert profiles.
125 // We can't use update_sql() here because of curly braces in serialized
126 // array.
127 db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $format, $profile->editor, serialize($profile->settings));
128 $ret[] = array(
129 'success' => TRUE,
130 'query' => strtr('Wysiwyg profile %profile converted and associated with input format %format.', array('%profile' => check_plain($profile->name), '%format' => check_plain($name))),
131 );
132 }
133 }
134
135 // Drop obsolete tables {wysiwyg_profile} and {wysiwyg_role}.
136 db_drop_table($ret, 'wysiwyg_profile');
137 db_drop_table($ret, 'wysiwyg_role');
138
139 return $ret;
140 }
141
142 /**
143 * Clear JS/CSS caches to ensure that clients load fresh copies.
144 */
145 function wysiwyg_update_6200() {
146 $ret = array();
147 // Change query-strings on css/js files to enforce reload for all users.
148 _drupal_flush_css_js();
149
150 drupal_clear_css_cache();
151 drupal_clear_js_cache();
152
153 // Rebuild the menu to remove old admin/settings/wysiwyg/profile item.
154 menu_rebuild();
155
156 // Flush content caches.
157 cache_clear_all();
158
159 $ret[] = array(
160 'success' => TRUE,
161 'query' => 'Caches have been flushed.',
162 );
163 return $ret;
164 }
165