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