Repository navigation
Expand file tree
/
Copy pathwysiwyg.install
More file actions
506 lines (482 loc) · 15.3 KB
/
Copy pathwysiwyg.install
File metadata and controls
506 lines (482 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
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
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<?php
/**
* Implementation of hook_schema().
*/
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',
// Primary keys are implicitly not null.
'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;
}
/**
* Implementation of hook_install().
*/
function wysiwyg_install() {
drupal_install_schema('wysiwyg');
}
/**
* Implementation of hook_uninstall()
*/
function wysiwyg_uninstall() {
drupal_uninstall_schema('wysiwyg');
}
/**
* 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',
));
}
/**
* Retrieve a list of input formats to associate profiles to.
*/
function _wysiwyg_install_get_formats() {
$formats = array();
$result = db_query("SELECT format, name FROM {filter_formats}");
while ($format = db_fetch_object($result)) {
// Build a list of all formats.
$formats[$format->format] = $format->name;
// Fetch filters.
$result2 = db_query("SELECT module, delta FROM {filters} WHERE format = %d", $format->format);
while ($filter = db_fetch_object($result2)) {
// If PHP filter is enabled, remove this format.
if ($filter->module == 'php') {
unset($formats[$format->format]);
break;
}
}
}
return $formats;
}
/**
* Associate Wysiwyg profiles with input formats.
*
* Since there was no association yet, we can only assume that there is one
* profile only, and that profile must be duplicated and assigned to all input
* formats (except PHP code format). Also, input formats already have
* titles/names, so Wysiwyg profiles do not need an own.
*
* Because input formats are already granted to certain user roles only, we can
* remove our custom Wysiwyg profile permissions. A 1:1 relationship between
* input formats and permissions makes plugin_count obsolete, too.
*
* Since the resulting table is completely different, a new schema is installed.
*/
function wysiwyg_update_6001() {
$ret = array();
if (db_table_exists('wysiwyg')) {
return $ret;
}
// Install new schema.
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'),
));
// Fetch all input formats.
$formats = _wysiwyg_install_get_formats();
// Fetch all profiles.
$result = db_query("SELECT name, settings FROM {wysiwyg_profile}");
while ($profile = db_fetch_object($result)) {
$profile->settings = unserialize($profile->settings);
// Extract editor name from profile settings.
$profile->editor = $profile->settings['editor'];
// Clean-up.
unset($profile->settings['editor']);
unset($profile->settings['old_name']);
unset($profile->settings['name']);
unset($profile->settings['rids']);
// Sorry. There Can Be Only One. ;)
break;
}
if ($profile) {
// Rebuild profiles and associate with input formats.
foreach ($formats as $format => $name) {
// Insert profiles.
// We can't use update_sql() here because of curly braces in serialized
// array.
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))),
);
}
}
// Drop obsolete tables {wysiwyg_profile} and {wysiwyg_role}.
db_drop_table($ret, 'wysiwyg_profile');
db_drop_table($ret, 'wysiwyg_role');
return $ret;
}
/**
* Clear JS/CSS caches to ensure that clients load fresh copies.
*/
function wysiwyg_update_6200() {
$ret = array();
// Change query-strings on css/js files to enforce reload for all users.
_drupal_flush_css_js();
drupal_clear_css_cache();
drupal_clear_js_cache();
// Rebuild the menu to remove old admin/settings/wysiwyg/profile item.
menu_rebuild();
// Flush content caches.
cache_clear_all();
$ret[] = array(
'success' => TRUE,
'query' => 'Caches have been flushed.',
);
return $ret;
}
/**
* Create the {wysiwyg_user} table.
*/
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;
}
/**
* Update enabled font plugin buttons to default plugin in TinyMCE profiles.
*/
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);
// 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) {
// We can't use update_sql() here because of curly braces in serialized
// array.
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;
}
/**
* Update internal names of settings.
*/
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':
// 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_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;
}
/**
* Add primary index to {wysiwyg_user}.
*/
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;
}
/**
* Remove empty editor profiles and update existing profiles.
*/
function wysiwyg_update_6205() {
// Remove unused profiles.
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)) {
// Move profile state to its own section.
$settings = unserialize($profile->settings);
$editor = wysiwyg_get_editor($profile->editor);
if (!empty($settings['_profile_preferences'])) {
// Skip in case of re-run.
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;
}
/**
* Delete YUI profiles.
*/
function wysiwyg_update_6206() {
$ret = array();
db_query("DELETE FROM {wysiwyg} WHERE editor = 'yui'");
return $ret;
}