4 * Implementation of hook_install().
6 function wysiwyg_install() {
7 switch ($GLOBALS['db_type']) {
10 db_query("CREATE TABLE {wysiwyg} (
11 format int NOT NULL default '0',
12 editor varchar(128) NOT NULL default '',
15 ) /*!40100 DEFAULT CHARACTER SET utf8 */");
19 db_query("CREATE TABLE {wysiwyg} (
20 format int NOT NULL default '0',
21 editor varchar(128) NOT NULL default '',
30 * Implementation of hook_uninstall()
32 function wysiwyg_uninstall() {
33 db_query('DROP TABLE {wysiwyg}');
37 * Implementation of hook_enable().
39 function wysiwyg_enable() {
40 // Disable conflicting, obsolete editor integration modules whenever this
41 // module is enabled. This is crude, but the only way to ensure no conflicts.
69 * Retrieve a list of input formats to associate profiles to.
71 function _wysiwyg_install_get_formats() {
73 $result = db_query("SELECT format, name FROM {filter_formats}");
74 while ($format = db_fetch_object($result)) {
75 // Build a list of all formats.
76 $formats[$format->format
] = $format->name
;
78 $result2 = db_query("SELECT module, delta FROM {filters} WHERE format = %d", $format->format
);
79 while ($filter = db_fetch_object($result2)) {
80 // If PHP filter is enabled, remove this format.
81 if ($filter->module
== 'filter' && $filter->delta
== 1) {
82 unset($formats[$format->format
]);
91 * Associate Wysiwyg profiles with input formats.
93 * Since there was no association yet, we can only assume that there is one
94 * profile only, and that profile must be duplicated and assigned to all input
95 * formats (except PHP code format). Also, input formats already have
96 * titles/names, so Wysiwyg profiles do not need an own.
98 * Because input formats are already granted to certain user roles only, we can
99 * remove our custom Wysiwyg profile permissions. A 1:1 relationship between
100 * input formats and permissions makes plugin_count obsolete, too.
102 * Since the resulting table is completely different, a new schema is installed.
104 function wysiwyg_update_5001() {
106 if (db_table_exists('wysiwyg')) {
109 // Install new schema.
110 switch ($GLOBALS['db_type']) {
113 $ret[] = update_sql("CREATE TABLE {wysiwyg} (
114 format int NOT NULL default '0',
115 editor varchar(128) NOT NULL default '',
118 ) /*!40100 DEFAULT CHARACTER SET utf8 */");
122 $ret[] = update_sql("CREATE TABLE {wysiwyg} (
123 format int NOT NULL default '0',
124 editor varchar(128) NOT NULL default '',
131 // Fetch all input formats.
132 $formats = _wysiwyg_install_get_formats();
134 // Fetch all profiles.
135 $result = db_query("SELECT name, settings FROM {wysiwyg_profile}");
136 while ($profile = db_fetch_object($result)) {
137 $profile->settings
= unserialize($profile->settings
);
138 // Extract editor name from profile settings.
139 $profile->editor
= $profile->settings
['editor'];
141 unset($profile->settings
['editor']);
142 unset($profile->settings
['old_name']);
143 unset($profile->settings
['name']);
144 unset($profile->settings
['rids']);
145 // Sorry. There Can Be Only One. ;)
150 // Rebuild profiles and associate with input formats.
151 foreach ($formats as
$format => $name) {
153 // We can't use update_sql() here because of curly braces in serialized
155 db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $format, $profile->editor
, serialize($profile->settings
));
158 'query' => strtr('Wysiwyg profile %profile converted and associated with input format %format.', array('%profile' => check_plain($profile->name
), '%format' => check_plain($name))),
163 // Drop obsolete tables {wysiwyg_profile} and {wysiwyg_role}.
164 $ret[] = update_sql("DROP TABLE {wysiwyg_profile}");
165 $ret[] = update_sql("DROP TABLE {wysiwyg_role}");
171 * Clear JS/CSS caches to ensure that clients load fresh copies.
173 function wysiwyg_update_5200() {
175 drupal_clear_css_cache();
177 // Rebuild the menu to remove old admin/settings/wysiwyg/profile item.
180 // Flush content caches.
185 'query' => 'Caches have been flushed.',
191 * Update enabled font plugin buttons to default plugin in TinyMCE profiles.
193 function wysiwyg_update_5201() {
195 $results = db_query("SELECT format, settings FROM {wysiwyg} WHERE editor = 'tinymce'");
197 while ($profile = db_fetch_object($results)) {
198 $settings = unserialize($profile->settings
);
199 // Move enabled 'font' buttons into 'default' plugin buttons.
201 foreach (array('formatselect', 'fontselect', 'fontsizeselect', 'styleselect') as
$button) {
202 if (isset($settings['buttons']['font'][$button])) {
203 $settings['buttons']['default'][$button] = $settings['buttons']['font'][$button];
204 unset($settings['buttons']['font'][$button]);
209 // We can't use update_sql() here because of curly braces in serialized
211 db_query("UPDATE {wysiwyg} SET settings='%s' WHERE format = '%s'", array(serialize($settings), $profile->format
));
216 'query' => 'TinyMCE profiles have been updated.',