summaryrefslogtreecommitdiffstats
path: root/modules/filter/filter.install
blob: fb0bf3e43b06f0ca54a78a64598127afe7ffef4a (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
<?php
// $Id$

/**
 * Implementation of hook_schema().
 */
function filter_schema() {
  $schema['filter'] = array(
    'description' => 'Table that maps filters (HTML corrector) to input formats (Filtered HTML).',
    'fields' => array(
      'fid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Auto-incrementing filter ID.',
      ),
      '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.',
      ),
      'delta' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'ID to identify which filter within module is being referenced.',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Weight of filter within format.',
      )
    ),
    'primary key' => array('fid'),
    'unique keys' => array(
      'fmd' => array('format', 'module', 'delta'),
    ),
    'indexes' => array(
      'list' => array('format', 'weight', 'module', 'delta'),
    ),
  );
  $schema['filter_format'] = array(
    'description' => 'Stores input 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 input 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 cachable. (1 = cachable, 0 = not cachable)',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'Weight of input 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 input 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}");
  while ($format = db_fetch_object($result)) {
    // 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;
}