summaryrefslogtreecommitdiffstats
path: root/fckeditor.install
blob: 8f6ce28258c06aee443d2b672a226c95c5374dd9 (plain)
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
<?php

/*
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 * @file
 * Implementation of hook_install()
 *
 * This will automatically install the database tables for the FCKeditor module for both the MySQL and PostgreSQL databases.
 *
 * If you are using another database, you will have to install the tables by hand, using the queries below as a reference.
 *
 * Note that the curly braces around table names are a drupal-specific feature to allow for automatic database table prefixing,
 * and will need to be removed.
 */

function fckeditor_install() {

  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {fckeditor_settings} (
                name varchar(128) NOT NULL default '',
                settings text,
                PRIMARY KEY (name)
               ) /*!40100 DEFAULT CHARACTER SET utf8 */;");

      db_query("CREATE TABLE {fckeditor_role} (
                name varchar(128) NOT NULL default '',
                rid tinyint(3) unsigned NOT NULL default '0',
                PRIMARY KEY (name,rid)
               ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;

    case 'pgsql':
      db_query("CREATE TABLE {fckeditor_settings} (
                name varchar(128) NOT NULL default '',
                settings text,
                PRIMARY KEY (name)
               );");

      db_query("CREATE TABLE {fckeditor_role} (
                name varchar(128) NOT NULL default '',
                rid smallint NOT NULL default '0',
                PRIMARY KEY (name,rid)
               );");
      break;
  }

  //create two default roles based on previous settings
  db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)",
  "Default", defined('DRUPAL_ANONYMOUS_RID') ? DRUPAL_ANONYMOUS_RID : 1);
  db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)",
  "Advanced", defined('DRUPAL_AUTHENTICATED_RID') ? DRUPAL_AUTHENTICATED_RID : 2);

  //insert settings for default role
  $arr = array();
  $arr['allow_user_conf'] = "f";
  $arr['min_rows'] = variable_get('fckeditor_minimum_rows', 1);
  $arr['excl_mode'] = variable_get('fckeditor_exclude_toggle', 0);

  //appearance
  $arr['default'] = "t";
  $arr['show_toggle'] = "t";
  $arr['popup'] = variable_get('fckeditor_popup', 0) ? "t" : "f";
  $arr['skin'] = "default";
  $arr['toolbar'] = variable_get('fckeditor_default_toolbar', 'DrupalBasic');
  $arr['expand'] = variable_get('fckeditor_toolbar_start_expanded', 1) ? "t" : "f";
  $arr['width'] = variable_get("fckeditor_width", "100%");
  $arr['lang'] = "en";
  $arr['auto_lang'] = "t";

  //security
  $arr['ss'] = "2";
  $arr['filters']['filter/0'] = 1;

  //output
  $arr['enter_mode'] = "p";
  $arr['shift_enter_mode'] = "br";
  $arr['font_format'] = 'p;div;pre;address;h1;h2;h3;h4;h5;h6';
  $arr['format_source'] = "t";
  $arr['format_output'] = "t";

  //css
  $arr['css_mode'] = "theme";
  $arr['css_path'] = variable_get("fckeditor_stylesheet", "");

  //upload
  //get permissions here like in _update_role_permissions
  $arr['upload_basic'] = variable_get("fckeditor_upload_basic", 0) ? "t" : "f";
  $arr['upload_advanced'] = variable_get('fckeditor_upload_advanced', 0) ? "t" : "f";
  $arr['user_choose'] = "f";

  db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Default", serialize($arr));

  //insert settings for advanced role
  $arr['toolbar'] = variable_get('fckeditor_advanced_toolbar', 'DrupalFiltered');
  db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Advanced", serialize($arr));

  $arr = array();

  //exclude by default some known textareas where HTML is not expected
  //edit-recipients //contact module
  //edit-reply //contact module
  //edit-description //taxonomy module
  //edit-synonyms //taxonomy module
  //edit-img-assist-textareas //img assist module
  $arr['excl_mode'] = 0;
  $arr['excl_fields'] = variable_get("fckeditor_exclude",
  "edit-user-mail-welcome-body\n".
  "edit-user-mail-admin-body\n".
  "edit-user-mail-approval-body\n".
  "edit-user-mail-pass-body\n".
  "edit-user-mail-register-admin-created-body\n".
  "edit-user-mail-register-no-approval-required-body\n".
  "edit-user-mail-register-pending-approval-body\n".
  "edit-user-mail-password-reset-body\n".
  "edit-user-mail-status-activated-body\n".
  "edit-user-mail-status-blocked-body\n".
  "edit-user-mail-status-deleted-body\n".
  "edit-pages\n".
  "edit-pathauto-ignore-words\n".
  "edit-recipients\n".
  "edit-reply\n".
  "edit-description\n".
  "edit-synonyms\n".
  "edit-img-assist-textareas\n".
  "edit-img-assist-paths\n".
  "edit-nodewords-description\n".
  "edit-relatedlinks-fieldset-relatedlinks\n".
  "edit-allowed-values-php\n".
  "edit-allowed-values\n".
  "edit-update-notify-emails\n".
  "edit-googleanalytics-pages\n".
  "edit-googleanalytics-codesnippet-before\n".
  "edit-googleanalytics-codesnippet-after\n".
  "edit-piwik-pages\n".
  "edit-piwik-codesnippet\n".
  "edit-feedburner-useragents\n".
  "edit-webform-*\n".
  "edit-target\n"
  );

  $arr['excl_paths'] = "admin/*/logintoboggan\n";

  //force by default simple toolbar on selected textareas
  $arr['simple_incl_fields'] =
  "edit-signature\n".
  "edit-site-mission\n".
  "edit-site-footer\n".
  "edit-site-offline-message\n".
  "edit-page-help\n".
  "edit-user-registration-help\n".
  "edit-user-picture-guidelines\n";
  db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "FCKeditor Global Profile", serialize($arr));
}

/**
 * Update from 5.x-1.x to 5.x-2.x
 */
function fckeditor_update_2() {
  $ret = array();

  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {fckeditor_settings} (
                name varchar(128) NOT NULL default '',
                settings text,
                PRIMARY KEY (name)
               ) /*!40100 DEFAULT CHARACTER SET utf8 */;");

      $ret[] = update_sql("CREATE TABLE {fckeditor_role} (
                name varchar(128) NOT NULL default '',
                rid tinyint(3) unsigned NOT NULL default '0',
                PRIMARY KEY (name,rid)
               ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;

    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {fckeditor_settings} (
                name varchar(128) NOT NULL default '',
                settings text,
                PRIMARY KEY (name)
               );");

      $ret[] = update_sql("CREATE TABLE {fckeditor_role} (
                name varchar(128) NOT NULL default '',
                rid smallint NOT NULL default '0',
                PRIMARY KEY (name,rid)
               );");
      break;
  }

  //create two default roles based on previous settings
  db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)",
  "Default", defined('DRUPAL_ANONYMOUS_RID') ? DRUPAL_ANONYMOUS_RID : 1);
  db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)",
  "Advanced", defined('DRUPAL_AUTHENTICATED_RID') ? DRUPAL_AUTHENTICATED_RID : 2);

  //insert settings for default role
  $arr = array();
  $arr['allow_user_conf'] = "f";
  $arr['min_rows'] = variable_get('fckeditor_minimum_rows', 1);
  $arr['excl_mode'] = variable_get('fckeditor_exclude_toggle', 0);

  //exclude by default some known textareas where HTML is not expected
  //edit-recipients //contact module
  //edit-reply //contact module
  //edit-description //taxonomy module
  //edit-synonyms //taxonomy module
  //edit-img-assist-textareas //img assist module
  $arr['excl_list'] = variable_get("fckeditor_exclude",
  "edit-user-mail-welcome-body\n".
  "edit-user-mail-admin-body\n".
  "edit-user-mail-approval-body\n".
  "edit-user-mail-pass-body\n".
  "edit-recipients\n".
  "edit-reply\n".
  "edit-description\n".
  "edit-synonyms\n".
  "edit-img-assist-textareas\n".
 "edit-nodewords-description\n"
);

  //force by default simple toolbar on selected textareas
  $arr['simple_incl_mode'] = 1;
  $arr['simple_incl_list'] =
  "edit-signature\n".
  "edit-site-mission\n".
  "edit-site-footer\n".
  "edit-site-offline-message\n".
  "edit-page-help\n".
  "edit-user-registration-help\n".
  "edit-user-picture-guidelines\n";

  //appearance
  $arr['default'] = "t";
  $arr['popup'] = variable_get('fckeditor_popup', 0) ? "t" : "f";
  $arr['show_toggle'] = ($arr['popup'] == "f") ? "t" : "f";
  $arr['skin'] = "default";
  $arr['toolbar'] = variable_get('fckeditor_default_toolbar', 'DrupalBasic');
  $arr['expand'] = variable_get('fckeditor_toolbar_start_expanded', 1) ? "t" : "f";
  $arr['width'] = variable_get("fckeditor_width", "100%");
  $arr['lang'] = "en";
  $arr['auto_lang'] = "t";

  //output
  $arr['enter_mode'] = "p";
  $arr['shift_enter_mode'] = "br";
  $arr['font_format'] = 'p;div;pre;address;h1;h2;h3;h4;h5;h6';
  $arr['format_source'] = "t";
  $arr['format_output'] = "t";

  //css
  $arr['css_mode'] = "theme";
  $arr['css_path'] = variable_get("fckeditor_stylesheet", "");

  //upload
  //get permissions here like in _update_role_permissions
  $arr['upload_basic'] = variable_get("fckeditor_upload_basic", 0) ? "t" : "f";
  $arr['upload_advanced'] = variable_get('fckeditor_upload_advanced', 0) ? "t" : "f";
  $arr['user_choose'] = "f";

  db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Default", serialize($arr));

  //insert settings for advanced role
  $arr['toolbar'] = variable_get('fckeditor_advanced_toolbar', 'DrupalFiltered');
  db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Advanced", serialize($arr));

  $variable_result = db_query("SELECT rid, perm FROM {permission}");
  while ($variable = db_fetch_object($variable_result)) {
    if (false === strpos($variable->perm, "access fckeditor")) {
      if (false !== strpos($variable->perm, "use default fckeditor")) {
        db_query("UPDATE {permission} SET perm = '%s' WHERE rid = '%s'", str_replace("use default fckeditor", "access fckeditor", $variable->perm), $variable->rid);
      }
      else if (false !== strpos($variable->perm, "use advanced fckeditor")) {
        db_query("UPDATE {permission} SET perm = '%s' WHERE rid = '%s'", str_replace("use advanced fckeditor", "access fckeditor", $variable->perm), $variable->rid);
      }
    }
  }
  return $ret;
}

/**
 * Update from 5.x-2.0 to 5.x-2.1
 *
 */
function fckeditor_update_3() {
  $ret = array();

  $result = db_query('SELECT * FROM {fckeditor_settings}');
  $global_profile_found = FALSE;
  while ($data = db_fetch_object($result)) {
    if ($data->name == "FCKeditor Global Profile") {
      $global_profile_found = TRUE;
    }
    if ($data->settings) {
      $settings = unserialize($data->settings);
    }
    if (isset($settings['excl_mode'], $settings['excl_list']) && !empty($settings['excl_list'])) {
      switch ($settings['excl_mode']) {
        case 0:
          // normal exclusion based on the id
          $settings['excl_fields'] = $settings['excl_list'];
          $settings['excl_mode'] = 0;
          break;
        case 1:
          //normal inclusion based on the id
          $settings['excl_fields'] = $settings['excl_list'];
          $settings['excl_mode'] = 1;
          break;
        case 2:
          //path exclusion
          $settings['excl_paths'] = $settings['excl_list'];
          $settings['excl_mode'] = 0;
          break;
        case 3:
          //path inclusion
          $settings['excl_paths'] = $settings['excl_list'];
          $settings['excl_mode'] = 1;
          break;
      }
      unset($settings['excl_list']);
    }
    if (isset($settings['simple_incl_mode'], $settings['simple_incl_list']) && !empty($settings['simple_incl_list'])) {
      switch ($settings['simple_incl_mode']) {
        case 1:
          //normal inclusion based on the id
          $settings['simple_incl_fields'] = $settings['simple_incl_list'];
          break;
        case 3:
          //path inclusion
          $settings['simple_incl_paths'] = $settings['simple_incl_list'];
          break;
      }
      unset($settings['simple_incl_mode']);
      unset($settings['simple_incl_list']);
    }

    db_query("UPDATE {fckeditor_settings} SET settings='%s' WHERE name='%s'", serialize($settings), $data->name);
  }

  if (!$global_profile_found) {
    db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "FCKeditor Global Profile", serialize(array()));
  }
  return $ret;
}

function fckeditor_update_5() {
  $ret = array();
  menu_rebuild();
  return $ret;
}

/**
 * Implementation of hook_uninstall()
 */
function fckeditor_uninstall() {
  db_query('DROP TABLE {fckeditor_settings}');
  db_query('DROP TABLE {fckeditor_role}');

  // Clean up variables left by 5.x-1.x
  variable_del('fckeditor_popup');
  variable_del('fckeditor_default_toolbar');
  variable_del('fckeditor_advanced_toolbar');
  variable_del('fckeditor_minimum_rows');
  variable_del('fckeditor_toolbar_start_expanded');
  variable_del('fckeditor_exclude_toggle');
  variable_del('fckeditor_exclude');
  variable_del('fckeditor_width');
  variable_del('fckeditor_stylesheet');
  variable_del('fckeditor_upload_basic');
  variable_del('fckeditor_upload_advanced');
}