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