263 lines
8.1 KiB
Plaintext
263 lines
8.1 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
/**
|
|
* @file
|
|
* Install, update and uninstall functions for the filter module.
|
|
*/
|
|
|
|
/**
|
|
* Implement hook_schema().
|
|
*/
|
|
function filter_schema() {
|
|
$schema['filter'] = array(
|
|
'description' => 'Table that maps filters (HTML corrector) to text formats (Filtered HTML).',
|
|
'fields' => array(
|
|
'format' => array(
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.',
|
|
),
|
|
'module' => array(
|
|
'type' => 'varchar',
|
|
'length' => 64,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The origin module of the filter.',
|
|
),
|
|
'name' => array(
|
|
'type' => 'varchar',
|
|
'length' => 32,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'Name of the filter being referenced.',
|
|
),
|
|
'weight' => array(
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'size' => 'tiny',
|
|
'description' => 'Weight of filter within format.',
|
|
),
|
|
'status' => array(
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'Filter enabled status. (1 = enabled, 0 = disabled)',
|
|
),
|
|
'settings' => array(
|
|
'type' => 'text',
|
|
'not null' => FALSE,
|
|
'size' => 'big',
|
|
'serialize' => TRUE,
|
|
'description' => 'A serialized array of name value pairs that store the filter settings for the specific format.',
|
|
),
|
|
),
|
|
'primary key' => array('format', 'name'),
|
|
'unique keys' => array(
|
|
'fmn' => array('format', 'module', 'name'),
|
|
),
|
|
'indexes' => array(
|
|
'list' => array('format', 'weight', 'module', 'name'),
|
|
),
|
|
);
|
|
$schema['filter_format'] = array(
|
|
'description' => 'Stores text formats: custom groupings of filters, such as Filtered HTML.',
|
|
'fields' => array(
|
|
'format' => array(
|
|
'type' => 'serial',
|
|
'not null' => TRUE,
|
|
'description' => 'Primary Key: Unique ID for format.',
|
|
),
|
|
'name' => array(
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'Name of the text format (Filtered HTML).',
|
|
),
|
|
'roles' => array(
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'A comma-separated string of roles; references {role}.rid.', // This is bad since you can't use joins, nor index.
|
|
),
|
|
'cache' => array(
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'size' => 'tiny',
|
|
'description' => 'Flag to indicate whether format is cacheable. (1 = cacheable, 0 = not cacheable)',
|
|
),
|
|
'weight' => array(
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'size' => 'tiny',
|
|
'description' => 'Weight of text format to use when listing.',
|
|
)
|
|
),
|
|
'primary key' => array('format'),
|
|
'unique keys' => array(
|
|
'name' => array('name'),
|
|
),
|
|
);
|
|
|
|
$schema['cache_filter'] = drupal_get_schema_unprocessed('system', 'cache');
|
|
$schema['cache_filter']['description'] = 'Cache table for the Filter module to store already filtered pieces of text, identified by text format and md5 hash of the text.';
|
|
|
|
return $schema;
|
|
}
|
|
|
|
/**
|
|
* Add a weight column to the filter formats table.
|
|
*/
|
|
function filter_update_7000() {
|
|
$ret = array();
|
|
db_add_field($ret, 'filter_formats', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* Break out "escape HTML filter" option to its own filter.
|
|
*/
|
|
function filter_update_7001() {
|
|
$ret = array();
|
|
$result = db_query("SELECT format FROM {filter_formats}");
|
|
foreach ($result as $format) {
|
|
// Deprecated constants FILTER_HTML_STRIP = 1 and FILTER_HTML_ESCAPE = 2.
|
|
if (variable_get('filter_html_' . $format->format, 1) == 2) {
|
|
$ret[] = update_sql("INSERT INTO {filters} (format, module, delta, weight) VALUES (" . $format->format . ", 'filter', 4, 0)");
|
|
}
|
|
variable_del('filter_html_' . $format->format);
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* Rename {filters} table to {filter} and {filter_formats} table to {filter_format}.
|
|
*/
|
|
function filter_update_7002() {
|
|
$ret = array();
|
|
db_rename_table($ret, 'filters', 'filter');
|
|
db_rename_table($ret, 'filter_formats', 'filter_format');
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* Remove hardcoded numeric deltas from all filters in core.
|
|
*/
|
|
function filter_update_7003() {
|
|
$ret = array();
|
|
// Get an array of the renamed filter deltas, organized by module.
|
|
$renamed_deltas = array(
|
|
'filter' => array(
|
|
'0' => 'filter_html',
|
|
'1' => 'filter_autop',
|
|
'2' => 'filter_url',
|
|
'3' => 'filter_htmlcorrector',
|
|
'4' => 'filter_html_escape',
|
|
),
|
|
'php' => array(
|
|
'0' => 'php_code',
|
|
),
|
|
);
|
|
|
|
// Rename field 'delta' to 'name'.
|
|
db_drop_unique_key($ret, 'filter', 'fmd');
|
|
db_drop_index($ret, 'filter', 'list');
|
|
db_change_field($ret, 'filter', 'delta', 'name',
|
|
array(
|
|
'type' => 'varchar',
|
|
'length' => 32,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'Name of the filter being referenced.',
|
|
),
|
|
array(
|
|
'unique keys' => array(
|
|
'fmn' => array('format', 'module', 'name'),
|
|
),
|
|
'indexes' => array(
|
|
'list' => array('format', 'weight', 'module', 'name'),
|
|
),
|
|
)
|
|
);
|
|
|
|
// Loop through each filter and make changes to the core filter table.
|
|
foreach ($renamed_deltas as $module => $deltas) {
|
|
foreach ($deltas as $old_delta => $new_delta) {
|
|
$ret[] = update_sql("UPDATE {filter} SET name = '" . $new_delta . "' WHERE module = '" . $module . "' AND name = '" . $old_delta . "'");
|
|
}
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
/**
|
|
* Move filter settings storage into {filter} table.
|
|
*
|
|
* - Remove {filter}.fid.
|
|
* - Add (format, name) as primary key for {filter}.
|
|
* - Add {filter}.status.
|
|
* - Add {filter}.settings.
|
|
*/
|
|
function filter_update_7004() {
|
|
$ret = array();
|
|
db_drop_field($ret, 'filter', 'fid');
|
|
db_add_primary_key($ret, 'filter', array('format', 'name'));
|
|
db_add_field($ret, 'filter', 'status',
|
|
array(
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'Filter enabled status. (1 = enabled, 0 = disabled)',
|
|
)
|
|
);
|
|
db_add_field($ret, 'filter', 'settings',
|
|
array(
|
|
'type' => 'text',
|
|
'not null' => FALSE,
|
|
'size' => 'big',
|
|
'serialize' => TRUE,
|
|
'description' => 'A serialized array of name value pairs that store the filter settings for the specific format.',
|
|
)
|
|
);
|
|
|
|
// Enable all existing filters ({filter} contained only enabled previously).
|
|
$ret[] = update_sql("UPDATE {filter} SET status = 1");
|
|
|
|
// Move filter settings from system variables into {filter}.settings.
|
|
$filters = db_query("SELECT * FROM {filter} WHERE module = :name", array(':name' => 'filter'));
|
|
foreach ($filters as $filter) {
|
|
$settings = array();
|
|
if ($filter->name == 'filter_html') {
|
|
if ($setting = variable_get("allowed_html_{$filter->format}", NULL)) {
|
|
$settings['allowed_html'] = $setting;
|
|
variable_del("allowed_html_{$filter->format}");
|
|
}
|
|
if ($setting = variable_get("filter_html_help_{$filter->format}", NULL)) {
|
|
$settings['filter_html_help'] = $setting;
|
|
variable_del("filter_html_help_{$filter->format}");
|
|
}
|
|
if ($setting = variable_get("filter_html_nofollow_{$filter->format}", NULL)) {
|
|
$settings['filter_html_nofollow'] = $setting;
|
|
variable_del("filter_html_nofollow_{$filter->format}");
|
|
}
|
|
}
|
|
elseif ($filter->name == 'filter_url') {
|
|
if ($setting = variable_get("filter_url_length_{$filter->format}", NULL)) {
|
|
$settings['filter_url_length'] = $setting;
|
|
variable_del("filter_url_length_{$filter->format}");
|
|
}
|
|
}
|
|
if (!empty($settings)) {
|
|
$ret[] = update_sql("UPDATE {filter} SET settings = '" . serialize($settings) . "' WHERE format = {$filter->format} AND name = '{$filter->name}'");
|
|
}
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
|