Newer
Older
<?php
/**
* @file
* Installation functions for Wysiwyg module.
*/
/**
* Implementation of hook_schema().
*/
function wysiwyg_schema() {
Daniel Kudwien
committed
$schema['wysiwyg'] = array(
Daniel Kudwien
committed
'description' => 'Stores Wysiwyg profiles.',
'fields' => array(
'description' => 'The {filter_format}.format of the text format.',
'type' => 'varchar',
'length' => 255,
Daniel Kudwien
committed
// 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',
Aaron Bauman
committed
'serialize' => TRUE,
Daniel Kudwien
committed
'primary key' => array('format'),
'foreign keys' => array(
'format' => array(
Daniel Kudwien
committed
'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,
Henrik Danielsson
committed
'not null' => TRUE,
Daniel Kudwien
committed
),
'status' => array(
'description' => 'Boolean indicating whether the format is enabled by default.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
),
),
Henrik Danielsson
committed
'primary key' => array('uid', 'format'),
Daniel Kudwien
committed
'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;
}
/**
Daniel Kudwien
committed
* Implementation of hook_enable().
Daniel Kudwien
committed
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(
Daniel Kudwien
committed
'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;
}
Daniel Kudwien
committed
/**
* Implements hook_update_last_removed().
Daniel Kudwien
committed
*/
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;
Daniel Kudwien
committed
}
/**
* 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'));
}
Daniel Kudwien
committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/**
* 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,
));
}
}
Henrik Danielsson
committed
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/**
* 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();
}
}
}
Henrik Danielsson
committed
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/**
* 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();
}
}
}
Henrik Danielsson
committed
/**
* 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'),
),
)
);
}