web/drupal/modules/fckeditor/fckeditor.install
branchdrupal
changeset 74 0ff3ba646492
equal deleted inserted replaced
73:fcf75e232c5b 74:0ff3ba646492
       
     1 <?php
       
     2 // $Id: fckeditor.install,v 1.2.2.25 2009/02/16 11:58:52 wwalc Exp $
       
     3 
       
     4 /*
       
     5  * FCKeditor - The text editor for Internet - http://www.fckeditor.net
       
     6  * Copyright (C) 2003-2008 Frederico Caldeira Knabben
       
     7  *
       
     8  * == BEGIN LICENSE ==
       
     9  *
       
    10  * Licensed under the terms of any of the following licenses at your
       
    11  * choice:
       
    12  *
       
    13  *  - GNU General Public License Version 2 or later (the "GPL")
       
    14  *    http://www.gnu.org/licenses/gpl.html
       
    15  *
       
    16  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
       
    17  *    http://www.gnu.org/licenses/lgpl.html
       
    18  *
       
    19  *  - Mozilla Public License Version 1.1 or later (the "MPL")
       
    20  *    http://www.mozilla.org/MPL/MPL-1.1.html
       
    21  *
       
    22  * == END LICENSE ==
       
    23  *
       
    24  * @file
       
    25  * Implementation of hook_install()
       
    26  *
       
    27  * This will automatically install the database tables for the FCKeditor module for both the MySQL and PostgreSQL databases.
       
    28  *
       
    29  * If you are using another database, you will have to install the tables by hand, using the queries below as a reference.
       
    30  *
       
    31  * Note that the curly braces around table names are a drupal-specific feature to allow for automatic database table prefixing,
       
    32  * and will need to be removed.
       
    33  *
       
    34  */
       
    35 
       
    36 function fckeditor_install() {
       
    37 
       
    38   drupal_install_schema('fckeditor');
       
    39 
       
    40   //create two default roles based on previous settings
       
    41   db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)",
       
    42   "Default", defined('DRUPAL_ANONYMOUS_RID') ? DRUPAL_ANONYMOUS_RID : 1);
       
    43   db_query("INSERT INTO {fckeditor_role} (name, rid) VALUES ('%s', %d)",
       
    44   "Advanced", defined('DRUPAL_AUTHENTICATED_RID') ? DRUPAL_AUTHENTICATED_RID : 2);
       
    45 
       
    46   //insert settings for default role
       
    47   $arr = array();
       
    48   $arr['allow_user_conf'] = "f";
       
    49   $arr['min_rows'] = variable_get('fckeditor_minimum_rows', 1);
       
    50   $arr['excl_mode'] = variable_get('fckeditor_exclude_toggle', 0);
       
    51   $arr['filebrowser'] = 'none';
       
    52   $arr['quickupload'] = 'f';
       
    53 
       
    54   //appearance
       
    55   $arr['default'] = "t";
       
    56   $arr['show_toggle'] = "t";
       
    57   $arr['popup'] = variable_get('fckeditor_popup', 0) ? "t" : "f";
       
    58   $arr['skin'] = "default";
       
    59   $arr['toolbar'] = variable_get('fckeditor_default_toolbar', 'DrupalBasic');
       
    60   $arr['expand'] = variable_get('fckeditor_toolbar_start_expanded', 1) ? "t" : "f";
       
    61   $arr['width'] = variable_get("fckeditor_width", "100%");
       
    62   $arr['lang'] = "en";
       
    63   $arr['auto_lang'] = "t";
       
    64 
       
    65   //output
       
    66   $arr['enter_mode'] = "p";
       
    67   $arr['shift_enter_mode'] = "br";
       
    68   $arr['font_format'] = 'p;div;pre;address;h1;h2;h3;h4;h5;h6';
       
    69   $arr['format_source'] = "t";
       
    70   $arr['format_output'] = "t";
       
    71 
       
    72   //security
       
    73   $arr['ss'] = "2";
       
    74   $arr['filters']['filter/0'] = 1;
       
    75 
       
    76   //css
       
    77   $arr['css_mode'] = "theme";
       
    78   $arr['css_path'] = variable_get("fckeditor_stylesheet", "");
       
    79 
       
    80   //upload
       
    81   //get permissions here like in _update_role_permissions
       
    82   $arr['upload_basic'] = variable_get("fckeditor_upload_basic", 0) ? "t" : "f";
       
    83   $arr['upload_advanced'] = variable_get('fckeditor_upload_advanced', 0) ? "t" : "f";
       
    84   $arr['user_choose'] = "f";
       
    85 
       
    86   db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Default", serialize($arr));
       
    87 
       
    88   //insert settings for advanced role
       
    89   $arr['toolbar'] = variable_get('fckeditor_advanced_toolbar', 'DrupalFiltered');
       
    90   db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "Advanced", serialize($arr));
       
    91 
       
    92   $arr = array();
       
    93 
       
    94   //exclude by default some known textareas where HTML is not expected
       
    95   //edit-recipients //contact module
       
    96   //edit-reply //contact module
       
    97   //edit-description //taxonomy module
       
    98   //edit-synonyms //taxonomy module
       
    99   //edit-img-assist-textareas //img assist module
       
   100   $arr['excl_mode'] = 0;
       
   101   $arr['excl_fields'] = variable_get("fckeditor_exclude",
       
   102   "edit-user-mail-welcome-body\n".
       
   103   "edit-user-mail-admin-body\n".
       
   104   "edit-user-mail-approval-body\n".
       
   105   "edit-user-mail-pass-body\n".
       
   106   "edit-user-mail-register-admin-created-body\n".
       
   107   "edit-user-mail-register-no-approval-required-body\n".
       
   108   "edit-user-mail-register-pending-approval-body\n".
       
   109   "edit-user-mail-password-reset-body\n".
       
   110   "edit-user-mail-status-activated-body\n".
       
   111   "edit-user-mail-status-blocked-body\n".
       
   112   "edit-user-mail-status-deleted-body\n".
       
   113   "edit-pages\n".
       
   114   "edit-pathauto-ignore-words\n".
       
   115   "edit-recipients\n".
       
   116   "edit-reply\n".
       
   117   "edit-description\n".
       
   118   "edit-synonyms\n".
       
   119   "edit-img-assist-textareas\n".
       
   120   "edit-img-assist-paths\n".
       
   121   "edit-nodewords-description\n".
       
   122   "edit-relatedlinks-fieldset-relatedlinks\n".
       
   123   "edit-allowed-values-php\n".
       
   124   "edit-allowed-values\n".
       
   125   "edit-update-notify-emails\n".
       
   126   "edit-googleanalytics-pages\n".
       
   127   "edit-googleanalytics-codesnippet-before\n".
       
   128   "edit-googleanalytics-codesnippet-after\n".
       
   129   "edit-piwik-pages\n".
       
   130   "edit-piwik-codesnippet\n".
       
   131   "edit-feedburner-useragents\n".
       
   132   "edit-webform-*\n".
       
   133   "edit-target\n"
       
   134   );
       
   135 
       
   136   $arr['excl_paths'] = "admin/*/logintoboggan\n".
       
   137   "admin/settings/actions/configure/*\n";
       
   138 
       
   139   //force by default simple toolbar on selected textareas
       
   140   $arr['simple_incl_mode'] = 1;
       
   141   $arr['simple_incl_fields'] =
       
   142   "edit-signature\n".
       
   143   "edit-site-mission\n".
       
   144   "edit-site-footer\n".
       
   145   "edit-site-offline-message\n".
       
   146   "edit-page-help\n".
       
   147   "edit-user-registration-help\n".
       
   148   "edit-user-picture-guidelines\n";
       
   149 
       
   150   db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "FCKeditor Global Profile", serialize($arr));
       
   151 }
       
   152 
       
   153 /**
       
   154 * Implementation of hook_schema().
       
   155 */
       
   156 function fckeditor_schema() {
       
   157   $schema['fckeditor_settings'] = array(
       
   158     'description' => 'Stores FCKeditor profile settings',
       
   159     'fields' => array(
       
   160       'name'    => array(
       
   161         'type' => 'varchar',
       
   162         'not null' => TRUE,
       
   163         'default' => '',
       
   164         'length' => 128,
       
   165         'description' => 'Name of the FCKeditor profile',
       
   166       ),
       
   167       'settings'    => array(
       
   168         'type' => 'text',
       
   169         'description' => 'Profile settings',
       
   170       ),
       
   171     ),
       
   172     'primary key' => array('name'),
       
   173   );
       
   174   $schema['fckeditor_role'] = array(
       
   175     'description' => 'Stores FCKeditor profile assignments',
       
   176     'fields' => array(
       
   177       'name'    => array(
       
   178         'type' => 'varchar',
       
   179         'not null' => TRUE,
       
   180         'default' => '',
       
   181         'length' => 128,
       
   182         'description' => 'Name of the FCKeditor role',
       
   183       ),
       
   184       'rid' => array(
       
   185         'type' => 'int',
       
   186         'not null' => TRUE,
       
   187         'default' => 0,
       
   188         'description' => 'Drupal role id',
       
   189       ),
       
   190     ),
       
   191     'primary key' => array('name', 'rid'),
       
   192   );
       
   193 
       
   194   return $schema;
       
   195 }
       
   196 
       
   197 /**
       
   198  * Update from 6.x-1.0 to 6.x-1.1
       
   199  *
       
   200  */
       
   201 function fckeditor_update_6110() {
       
   202   $ret = array();
       
   203 
       
   204   $result = db_query('SELECT * FROM {fckeditor_settings}');
       
   205   $global_profile_found = FALSE;
       
   206   while ($data = db_fetch_object($result)) {
       
   207     if ($data->name == "FCKeditor Global Profile") {
       
   208       $global_profile_found = TRUE;
       
   209     }
       
   210     if ($data->settings) {
       
   211       $settings = unserialize($data->settings);
       
   212     }
       
   213     if (isset($settings['excl_mode'], $settings['excl_list']) && !empty($settings['excl_list'])) {
       
   214       switch ($settings['excl_mode']) {
       
   215         case 0:
       
   216           // normal exclusion based on the id
       
   217           $settings['excl_fields'] = $settings['excl_list'];
       
   218           $settings['excl_mode'] = 0;
       
   219           break;
       
   220         case 1:
       
   221           //normal inclusion based on the id
       
   222           $settings['excl_fields'] = $settings['excl_list'];
       
   223           $settings['excl_mode'] = 1;
       
   224           break;
       
   225         case 2:
       
   226           //path exclusion
       
   227           $settings['excl_paths'] = $settings['excl_list'];
       
   228           $settings['excl_mode'] = 0;
       
   229           break;
       
   230         case 3:
       
   231           //path inclusion
       
   232           $settings['excl_paths'] = $settings['excl_list'];
       
   233           $settings['excl_mode'] = 1;
       
   234           break;
       
   235       }
       
   236       unset($settings['excl_list']);
       
   237     }
       
   238     if (isset($settings['simple_incl_mode'], $settings['simple_incl_list']) && !empty($settings['simple_incl_list'])) {
       
   239       switch ($settings['simple_incl_mode']) {
       
   240         case 1:
       
   241           //normal inclusion based on the id
       
   242           $settings['simple_incl_fields'] = $settings['simple_incl_list'];
       
   243           break;
       
   244         case 3:
       
   245           //path inclusion
       
   246           $settings['simple_incl_paths'] = $settings['simple_incl_list'];
       
   247           break;
       
   248       }
       
   249       unset($settings['simple_incl_mode']);
       
   250       unset($settings['simple_incl_list']);
       
   251     }
       
   252 
       
   253     db_query("UPDATE {fckeditor_settings} SET settings='%s' WHERE name='%s'", serialize($settings), $data->name);
       
   254   }
       
   255 
       
   256   if (!$global_profile_found) {
       
   257     db_query("INSERT INTO {fckeditor_settings} (name, settings) VALUES ('%s', '%s')", "FCKeditor Global Profile", serialize(array()));
       
   258   }
       
   259   return $ret;
       
   260 }
       
   261 
       
   262 /**
       
   263  * Update from 6.x-1.2 to 6.x-1.3
       
   264  *
       
   265  */
       
   266 function fckeditor_update_6130() {
       
   267   $ret = array();
       
   268 
       
   269   $result = db_query("SELECT * FROM {fckeditor_settings} WHERE name <> 'FCKeditor Global Profile'");
       
   270   $hasimce = module_exists('imce');
       
   271   while (($data = db_fetch_object($result))) {
       
   272     if ($data->settings) {
       
   273       $settings = unserialize($data->settings);
       
   274 
       
   275       // Rewrite imce, upload_basic and upload_advanced settings to filebrowser and quickupload
       
   276       $imce = ($hasimce && isset($settings['imce']) && $settings['imce'] == 't');
       
   277       $upload_basic = (isset($settings['upload_basic']) && $settings['upload_basic'] == 't');
       
   278       $upload_advanced = (isset($settings['upload_advanced']) && $settings['upload_advanced'] == 't');
       
   279 
       
   280       if ($imce) {
       
   281         $settings['filebrowser'] = 'imce';
       
   282       }
       
   283       elseif ($upload_advanced) {
       
   284         $settings['filebrowser'] = 'builtin';
       
   285       }
       
   286       else {
       
   287         $settings['filebrowser'] = 'none';
       
   288       }
       
   289 
       
   290       $settings['quickupload'] = $upload_basic ? 't' : 'f';
       
   291 
       
   292       unset($settings['imce'], $settings['upload_basic'], $settings['upload_advanced']);
       
   293 
       
   294       // unfortunately, update_sql is not an option, as serialize($settings) will contain curly braces which will
       
   295       // be replaced. update_sql does not support arguments like db_query() does.
       
   296 
       
   297       db_query("UPDATE {fckeditor_settings} SET settings='%s' WHERE name='%s'", serialize($settings), $data->name);
       
   298     }
       
   299   }
       
   300 
       
   301   return $ret;
       
   302 }
       
   303 
       
   304 /**
       
   305  * Implementation of hook_uninstall()
       
   306  */
       
   307 function fckeditor_uninstall() {
       
   308   drupal_uninstall_schema('fckeditor');
       
   309 }