| 1 | | <?php |
| 2 | | // $Id: filter.install,v 1.9 2008/04/14 17:48:37 dries Exp $ |
| 3 | | |
| 4 | | /** |
| 5 | | * Implementation of hook_schema(). |
| 6 | | */ |
| 7 | 12 | function filter_schema() { |
| 8 | 134 | $schema['filters'] = array( |
| 9 | 134 | 'description' => t('Table that maps filters (HTML corrector) to input
formats (Filtered HTML).'), |
| 10 | | 'fields' => array( |
| 11 | | 'fid' => array( |
| 12 | 134 | 'type' => 'serial', |
| 13 | 134 | 'not null' => TRUE, |
| 14 | 134 | 'description' => t('Primary Key: Auto-incrementing filter ID.'), |
| 15 | 134 | ), |
| 16 | | 'format' => array( |
| 17 | 134 | 'type' => 'int', |
| 18 | 134 | 'not null' => TRUE, |
| 19 | 134 | 'default' => 0, |
| 20 | 134 | 'description' => t('Foreign key: The {filter_formats}.format to
which this filter is assigned.'), |
| 21 | 134 | ), |
| 22 | | 'module' => array( |
| 23 | 134 | 'type' => 'varchar', |
| 24 | 134 | 'length' => 64, |
| 25 | 134 | 'not null' => TRUE, |
| 26 | 134 | 'default' => '', |
| 27 | 134 | 'description' => t('The origin module of the filter.'), |
| 28 | 134 | ), |
| 29 | | 'delta' => array( |
| 30 | 134 | 'type' => 'int', |
| 31 | 134 | 'not null' => TRUE, |
| 32 | 134 | 'default' => 0, |
| 33 | 134 | 'size' => 'tiny', |
| 34 | 134 | 'description' => t('ID to identify which filter within module is
being referenced.'), |
| 35 | 134 | ), |
| 36 | | 'weight' => array( |
| 37 | 134 | 'type' => 'int', |
| 38 | 134 | 'not null' => TRUE, |
| 39 | 134 | 'default' => 0, |
| 40 | 134 | 'size' => 'tiny', |
| 41 | 134 | 'description' => t('Weight of filter within format.'), |
| 42 | | ) |
| 43 | 134 | ), |
| 44 | 134 | 'primary key' => array('fid'), |
| 45 | | 'unique keys' => array( |
| 46 | 134 | 'fmd' => array('format', 'module', 'delta'), |
| 47 | 134 | ), |
| 48 | | 'indexes' => array( |
| 49 | 134 | 'list' => array('format', 'weight', 'module', 'delta'), |
| 50 | 134 | ), |
| 51 | | ); |
| 52 | 134 | $schema['filter_formats'] = array( |
| 53 | 134 | 'description' => t('Stores input formats: custom groupings of filters,
such as Filtered HTML.'), |
| 54 | | 'fields' => array( |
| 55 | | 'format' => array( |
| 56 | 134 | 'type' => 'serial', |
| 57 | 134 | 'not null' => TRUE, |
| 58 | 134 | 'description' => t('Primary Key: Unique ID for format.'), |
| 59 | 134 | ), |
| 60 | | 'name' => array( |
| 61 | 134 | 'type' => 'varchar', |
| 62 | 134 | 'length' => 255, |
| 63 | 134 | 'not null' => TRUE, |
| 64 | 134 | 'default' => '', |
| 65 | 134 | 'description' => t('Name of the input format (Filtered HTML).'), |
| 66 | 134 | ), |
| 67 | | 'roles' => array( |
| 68 | 134 | 'type' => 'varchar', |
| 69 | 134 | 'length' => 255, |
| 70 | 134 | 'not null' => TRUE, |
| 71 | 134 | 'default' => '', |
| 72 | 134 | 'description' => t('A comma-separated string of roles; references
{role}.rid.'), // This is bad since you can't use joins, nor index. |
| 73 | 134 | ), |
| 74 | | 'cache' => array( |
| 75 | 134 | 'type' => 'int', |
| 76 | 134 | 'not null' => TRUE, |
| 77 | 134 | 'default' => 0, |
| 78 | 134 | 'size' => 'tiny', |
| 79 | 134 | 'description' => t('Flag to indicate whether format is cachable. (1
= cachable, 0 = not cachable)'), |
| 80 | 134 | ), |
| 81 | | 'weight' => array( |
| 82 | 134 | 'type' => 'int', |
| 83 | 134 | 'not null' => TRUE, |
| 84 | 134 | 'default' => 0, |
| 85 | 134 | 'size' => 'tiny', |
| 86 | 134 | 'description' => t('Weight of input format to use when listing.'), |
| 87 | | ) |
| 88 | 134 | ), |
| 89 | 134 | 'primary key' => array('format'), |
| 90 | | 'unique keys' => array( |
| 91 | 134 | 'name' => array('name'), |
| 92 | 134 | ), |
| 93 | | ); |
| 94 | | |
| 95 | 134 | $schema['cache_filter'] = drupal_get_schema_unprocessed('system',
'cache'); |
| 96 | 134 | $schema['cache_filter']['description'] = t('Cache table for the Filter
module to store already filtered pieces of text, identified by input format
and md5 hash of the text.'); |
| 97 | | |
| 98 | 134 | return $schema; |
| 99 | 0 | } |
| 100 | | |
| 101 | | /** |
| 102 | | * Add a weight column to the filter formats table. |
| 103 | | */ |
| 104 | 12 | function filter_update_7000() { |
| 105 | 0 | $ret = array(); |
| 106 | 0 | db_add_field($ret, 'filter_formats', 'weight', array('type' => 'int',
'not null' => TRUE, 'default' => 0, 'size' => 'tiny')); |
| 107 | 0 | return $ret; |
| 108 | 0 | } |
| 109 | | |
| 110 | | /** |
| 111 | | * Break out "escape HTML filter" option to its own filter. |
| 112 | | */ |
| 113 | 12 | function filter_update_7001() { |
| 114 | 0 | $ret = array(); |
| 115 | 0 | $result = db_query("SELECT format FROM {filter_formats}"); |
| 116 | 0 | while ($format = db_fetch_object($result)) { |
| 117 | | // Deprecated constants FILTER_HTML_STRIP = 1 and FILTER_HTML_ESCAPE =
2. |
| 118 | 0 | if (variable_get('filter_html_' . $format->format, 1) == 2) { |
| 119 | 0 | $ret[] = update_sql("INSERT INTO {filters} (format, module, delta,
weight) VALUES (" . $format->format . ", 'filter', 4, 0)"); |
| 120 | 0 | } |
| 121 | 0 | variable_del('filter_html_' . $format->format); |
| 122 | 0 | } |
| 123 | 0 | return $ret; |
| 124 | 0 | } |
| 125 | 12 | |