Removing translation directories
[project/fckeditor.git] / fckeditor.install
1 <?php
2
3 /*
4 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
5 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
6 *
7 * == BEGIN LICENSE ==
8 *
9 * Licensed under the terms of any of the following licenses at your
10 * choice:
11 *
12 * - GNU General Public License Version 2 or later (the "GPL")
13 * http://www.gnu.org/licenses/gpl.html
14 *
15 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
16 * http://www.gnu.org/licenses/lgpl.html
17 *
18 * - Mozilla Public License Version 1.1 or later (the "MPL")
19 * http://www.mozilla.org/MPL/MPL-1.1.html
20 *
21 * == END LICENSE ==
22 * @file
23 * Implementation of hook_install()
24 *
25 * This will automatically install the database tables for the FCKeditor module for both the MySQL and PostgreSQL databases.
26 *
27 * If you are using another database, you will have to install the tables by hand, using the queries below as a reference.
28 *
29 * Note that the curly braces around table names are a drupal-specific feature to allow for automatic database table prefixing,
30 * and will need to be removed.
31 */
32
33 function fckeditor_install() {
34
35 switch ($GLOBALS['db_type']) {
36 case 'mysql':
37 case 'mysqli':
38 db_query("CREATE TABLE {fckeditor_settings} (
39 name varchar(128) NOT NULL default '',
40 settings text,
41 PRIMARY KEY (name)
42 ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
43
44 db_query("CREATE TABLE {fckeditor_role} (
45 name varchar(128) NOT NULL default '',
46 rid tinyint(3) unsigned NOT NULL default '0',
47 PRIMARY KEY (name,rid)
48 ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
49 break;
50
51 case 'pgsql':
52 db_query("CREATE TABLE {fckeditor_settings} (
53 name varchar(128) NOT NULL default '',
54 settings text,
55 PRIMARY KEY (name)
56 );");
57
58 db_query("CREATE TABLE {fckeditor_role} (
59 name varchar(128) NOT NULL default '',
60 rid smallint NOT NULL default '0',
61 PRIMARY KEY (name,rid)
62 );");
63 break;
64 }
65
66 //create two default roles based on previous settings
67 db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)",
68 "Default", defined('DRUPAL_ANONYMOUS_RID') ? DRUPAL_ANONYMOUS_RID : 1);
69 db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)",
70 "Advanced", defined('DRUPAL_AUTHENTICATED_RID') ? DRUPAL_AUTHENTICATED_RID : 2);
71
72 //insert settings for default role
73 $arr = array();
74 $arr['allow_user_conf'] = "f";
75 $arr['min_rows'] = variable_get('fckeditor_minimum_rows', 1);
76 $arr['excl_mode'] = variable_get('fckeditor_exclude_toggle', 0);
77
78 //appearance
79 $arr['default'] = "t";
80 $arr['show_toggle'] = "t";
81 $arr['popup'] = variable_get('fckeditor_popup', 0) ? "t" : "f";
82 $arr['skin'] = "default";
83 $arr['toolbar'] = variable_get('fckeditor_default_toolbar', 'DrupalBasic');
84 $arr['expand'] = variable_get('fckeditor_toolbar_start_expanded', 1) ? "t" : "f";
85 $arr['width'] = variable_get("fckeditor_width", "100%");
86 $arr['lang'] = "en";
87 $arr['auto_lang'] = "t";
88
89 //security
90 $arr['ss'] = "2";
91 $arr['filters']['filter/0'] = 1;
92
93 //output
94 $arr['enter_mode'] = "p";
95 $arr['shift_enter_mode'] = "br";
96 $arr['font_format'] = 'p;div;pre;address;h1;h2;h3;h4;h5;h6';
97 $arr['format_source'] = "t";
98 $arr['format_output'] = "t";
99
100 //css
101 $arr['css_mode'] = "theme";
102 $arr['css_path'] = variable_get("fckeditor_stylesheet", "");
103
104 //upload
105 //get permissions here like in _update_role_permissions
106 $arr['upload_basic'] = variable_get("fckeditor_upload_basic", 0) ? "t" : "f";
107 $arr['upload_advanced'] = variable_get('fckeditor_upload_advanced', 0) ? "t" : "f";
108 $arr['user_choose'] = "f";
109
110 db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Default", serialize($arr));
111
112 //insert settings for advanced role
113 $arr['toolbar'] = variable_get('fckeditor_advanced_toolbar', 'DrupalFiltered');
114 db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Advanced", serialize($arr));
115
116 $arr = array();
117
118 //exclude by default some known textareas where HTML is not expected
119 //edit-recipients //contact module
120 //edit-reply //contact module
121 //edit-description //taxonomy module
122 //edit-synonyms //taxonomy module
123 //edit-img-assist-textareas //img assist module
124 $arr['excl_mode'] = 0;
125 $arr['excl_fields'] = variable_get("fckeditor_exclude",
126 "edit-user-mail-welcome-body\n".
127 "edit-user-mail-admin-body\n".
128 "edit-user-mail-approval-body\n".
129 "edit-user-mail-pass-body\n".
130 "edit-user-mail-register-admin-created-body\n".
131 "edit-user-mail-register-no-approval-required-body\n".
132 "edit-user-mail-register-pending-approval-body\n".
133 "edit-user-mail-password-reset-body\n".
134 "edit-user-mail-status-activated-body\n".
135 "edit-user-mail-status-blocked-body\n".
136 "edit-user-mail-status-deleted-body\n".
137 "edit-pages\n".
138 "edit-pathauto-ignore-words\n".
139 "edit-recipients\n".
140 "edit-reply\n".
141 "edit-description\n".
142 "edit-synonyms\n".
143 "edit-img-assist-textareas\n".
144 "edit-img-assist-paths\n".
145 "edit-nodewords-description\n".
146 "edit-relatedlinks-fieldset-relatedlinks\n".
147 "edit-allowed-values-php\n".
148 "edit-allowed-values\n".
149 "edit-update-notify-emails\n".
150 "edit-googleanalytics-pages\n".
151 "edit-googleanalytics-codesnippet-before\n".
152 "edit-googleanalytics-codesnippet-after\n".
153 "edit-piwik-pages\n".
154 "edit-piwik-codesnippet\n".
155 "edit-feedburner-useragents\n".
156 "edit-webform-*\n".
157 "edit-target\n"
158 );
159
160 $arr['excl_paths'] = "admin/*/logintoboggan\n";
161
162 //force by default simple toolbar on selected textareas
163 $arr['simple_incl_fields'] =
164 "edit-signature\n".
165 "edit-site-mission\n".
166 "edit-site-footer\n".
167 "edit-site-offline-message\n".
168 "edit-page-help\n".
169 "edit-user-registration-help\n".
170 "edit-user-picture-guidelines\n";
171 db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "FCKeditor Global Profile", serialize($arr));
172 }
173
174 /**
175 * Update from 5.x-1.x to 5.x-2.x
176 */
177 function fckeditor_update_2() {
178 $ret = array();
179
180 switch ($GLOBALS['db_type']) {
181 case 'mysql':
182 case 'mysqli':
183 $ret[] = update_sql("CREATE TABLE {fckeditor_settings} (
184 name varchar(128) NOT NULL default '',
185 settings text,
186 PRIMARY KEY (name)
187 ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
188
189 $ret[] = update_sql("CREATE TABLE {fckeditor_role} (
190 name varchar(128) NOT NULL default '',
191 rid tinyint(3) unsigned NOT NULL default '0',
192 PRIMARY KEY (name,rid)
193 ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
194 break;
195
196 case 'pgsql':
197 $ret[] = update_sql("CREATE TABLE {fckeditor_settings} (
198 name varchar(128) NOT NULL default '',
199 settings text,
200 PRIMARY KEY (name)
201 );");
202
203 $ret[] = update_sql("CREATE TABLE {fckeditor_role} (
204 name varchar(128) NOT NULL default '',
205 rid smallint NOT NULL default '0',
206 PRIMARY KEY (name,rid)
207 );");
208 break;
209 }
210
211 //create two default roles based on previous settings
212 db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)",
213 "Default", defined('DRUPAL_ANONYMOUS_RID') ? DRUPAL_ANONYMOUS_RID : 1);
214 db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)",
215 "Advanced", defined('DRUPAL_AUTHENTICATED_RID') ? DRUPAL_AUTHENTICATED_RID : 2);
216
217 //insert settings for default role
218 $arr = array();
219 $arr['allow_user_conf'] = "f";
220 $arr['min_rows'] = variable_get('fckeditor_minimum_rows', 1);
221 $arr['excl_mode'] = variable_get('fckeditor_exclude_toggle', 0);
222
223 //exclude by default some known textareas where HTML is not expected
224 //edit-recipients //contact module
225 //edit-reply //contact module
226 //edit-description //taxonomy module
227 //edit-synonyms //taxonomy module
228 //edit-img-assist-textareas //img assist module
229 $arr['excl_list'] = variable_get("fckeditor_exclude",
230 "edit-user-mail-welcome-body\n".
231 "edit-user-mail-admin-body\n".
232 "edit-user-mail-approval-body\n".
233 "edit-user-mail-pass-body\n".
234 "edit-recipients\n".
235 "edit-reply\n".
236 "edit-description\n".
237 "edit-synonyms\n".
238 "edit-img-assist-textareas\n".
239 "edit-nodewords-description\n"
240 );
241
242 //force by default simple toolbar on selected textareas
243 $arr['simple_incl_mode'] = 1;
244 $arr['simple_incl_list'] =
245 "edit-signature\n".
246 "edit-site-mission\n".
247 "edit-site-footer\n".
248 "edit-site-offline-message\n".
249 "edit-page-help\n".
250 "edit-user-registration-help\n".
251 "edit-user-picture-guidelines\n";
252
253 //appearance
254 $arr['default'] = "t";
255 $arr['popup'] = variable_get('fckeditor_popup', 0) ? "t" : "f";
256 $arr['show_toggle'] = ($arr['popup'] == "f") ? "t" : "f";
257 $arr['skin'] = "default";
258 $arr['toolbar'] = variable_get('fckeditor_default_toolbar', 'DrupalBasic');
259 $arr['expand'] = variable_get('fckeditor_toolbar_start_expanded', 1) ? "t" : "f";
260 $arr['width'] = variable_get("fckeditor_width", "100%");
261 $arr['lang'] = "en";
262 $arr['auto_lang'] = "t";
263
264 //output
265 $arr['enter_mode'] = "p";
266 $arr['shift_enter_mode'] = "br";
267 $arr['font_format'] = 'p;div;pre;address;h1;h2;h3;h4;h5;h6';
268 $arr['format_source'] = "t";
269 $arr['format_output'] = "t";
270
271 //css
272 $arr['css_mode'] = "theme";
273 $arr['css_path'] = variable_get("fckeditor_stylesheet", "");
274
275 //upload
276 //get permissions here like in _update_role_permissions
277 $arr['upload_basic'] = variable_get("fckeditor_upload_basic", 0) ? "t" : "f";
278 $arr['upload_advanced'] = variable_get('fckeditor_upload_advanced', 0) ? "t" : "f";
279 $arr['user_choose'] = "f";
280
281 db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Default", serialize($arr));
282
283 //insert settings for advanced role
284 $arr['toolbar'] = variable_get('fckeditor_advanced_toolbar', 'DrupalFiltered');
285 db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Advanced", serialize($arr));
286
287 $variable_result = db_query("SELECT rid, perm FROM {permission}");
288 while ($variable = db_fetch_object($variable_result)) {
289 if (false === strpos($variable->perm, "access fckeditor")) {
290 if (false !== strpos($variable->perm, "use default fckeditor")) {
291 db_query("UPDATE {permission} SET perm = '%s' WHERE rid = '%s'", str_replace("use default fckeditor", "access fckeditor", $variable->perm), $variable->rid);
292 }
293 else if (false !== strpos($variable->perm, "use advanced fckeditor")) {
294 db_query("UPDATE {permission} SET perm = '%s' WHERE rid = '%s'", str_replace("use advanced fckeditor", "access fckeditor", $variable->perm), $variable->rid);
295 }
296 }
297 }
298 return $ret;
299 }
300
301 /**
302 * Update from 5.x-2.0 to 5.x-2.1
303 *
304 */
305 function fckeditor_update_3() {
306 $ret = array();
307
308 $result = db_query('SELECT * FROM {fckeditor_settings}');
309 $global_profile_found = FALSE;
310 while ($data = db_fetch_object($result)) {
311 if ($data->name == "FCKeditor Global Profile") {
312 $global_profile_found = TRUE;
313 }
314 if ($data->settings) {
315 $settings = unserialize($data->settings);
316 }
317 if (isset($settings['excl_mode'], $settings['excl_list']) && !empty($settings['excl_list'])) {
318 switch ($settings['excl_mode']) {
319 case 0:
320 // normal exclusion based on the id
321 $settings['excl_fields'] = $settings['excl_list'];
322 $settings['excl_mode'] = 0;
323 break;
324 case 1:
325 //normal inclusion based on the id
326 $settings['excl_fields'] = $settings['excl_list'];
327 $settings['excl_mode'] = 1;
328 break;
329 case 2:
330 //path exclusion
331 $settings['excl_paths'] = $settings['excl_list'];
332 $settings['excl_mode'] = 0;
333 break;
334 case 3:
335 //path inclusion
336 $settings['excl_paths'] = $settings['excl_list'];
337 $settings['excl_mode'] = 1;
338 break;
339 }
340 unset($settings['excl_list']);
341 }
342 if (isset($settings['simple_incl_mode'], $settings['simple_incl_list']) && !empty($settings['simple_incl_list'])) {
343 switch ($settings['simple_incl_mode']) {
344 case 1:
345 //normal inclusion based on the id
346 $settings['simple_incl_fields'] = $settings['simple_incl_list'];
347 break;
348 case 3:
349 //path inclusion
350 $settings['simple_incl_paths'] = $settings['simple_incl_list'];
351 break;
352 }
353 unset($settings['simple_incl_mode']);
354 unset($settings['simple_incl_list']);
355 }
356
357 db_query("UPDATE {fckeditor_settings} SET settings='%s' WHERE name='%s'", serialize($settings), $data->name);
358 }
359
360 if (!$global_profile_found) {
361 db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "FCKeditor Global Profile", serialize(array()));
362 }
363 return $ret;
364 }
365
366 function fckeditor_update_5() {
367 $ret = array();
368 menu_rebuild();
369 return $ret;
370 }
371
372 /**
373 * Implementation of hook_uninstall()
374 */
375 function fckeditor_uninstall() {
376 db_query('DROP TABLE {fckeditor_settings}');
377 db_query('DROP TABLE {fckeditor_role}');
378
379 // Clean up variables left by 5.x-1.x
380 variable_del('fckeditor_popup');
381 variable_del('fckeditor_default_toolbar');
382 variable_del('fckeditor_advanced_toolbar');
383 variable_del('fckeditor_minimum_rows');
384 variable_del('fckeditor_toolbar_start_expanded');
385 variable_del('fckeditor_exclude_toggle');
386 variable_del('fckeditor_exclude');
387 variable_del('fckeditor_width');
388 variable_del('fckeditor_stylesheet');
389 variable_del('fckeditor_upload_basic');
390 variable_del('fckeditor_upload_advanced');
391 }