You are here

function fckeditor_update_2 in FCKeditor - WYSIWYG HTML editor 5.2

Update from 5.x-1.x to 5.x-2.x

File

./fckeditor.install, line 177

Code

function fckeditor_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {fckeditor_settings} (\n                name varchar(128) NOT NULL default '',\n                settings text,\n                PRIMARY KEY (name)\n               ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $ret[] = update_sql("CREATE TABLE {fckeditor_role} (\n                name varchar(128) NOT NULL default '',\n                rid tinyint(3) unsigned NOT NULL default '0',\n                PRIMARY KEY (name,rid)\n               ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {fckeditor_settings} (\n                name varchar(128) NOT NULL default '',\n                settings text,\n                PRIMARY KEY (name)\n               );");
      $ret[] = update_sql("CREATE TABLE {fckeditor_role} (\n                name varchar(128) NOT NULL default '',\n                rid smallint NOT NULL default '0',\n                PRIMARY KEY (name,rid)\n               );");
      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;
}