123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- <?php
- function filter_schema() {
- $schema['filter'] = array(
- 'description' => 'Table that maps filters (HTML corrector) to text formats (Filtered HTML).',
- 'fields' => array(
- 'format' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- '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,
- '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' => 'blob',
- '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'),
- 'indexes' => array(
- 'list' => array('weight', 'module', 'name'),
- ),
- );
- $schema['filter_format'] = array(
- 'description' => 'Stores text formats: custom groupings of filters, such as Filtered HTML.',
- 'fields' => array(
- 'format' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique machine name of the format.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'Name of the text format (Filtered HTML).',
- 'translatable' => TRUE,
- ),
- 'cache' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'size' => 'tiny',
- 'description' => 'Flag to indicate whether format is cacheable. (1 = cacheable, 0 = not cacheable)',
- ),
- 'status' => array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 1,
- 'size' => 'tiny',
- 'description' => 'The status of the text format. (1 = enabled, 0 = disabled)',
- ),
- 'weight' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Weight of text format to use when listing.',
- ),
- ),
- 'primary key' => array('format'),
- 'unique keys' => array(
- 'name' => array('name'),
- ),
- 'indexes' => array(
- 'status_weight' => array('status', 'weight'),
- ),
- );
- $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 hash of the text.';
- return $schema;
- }
- function filter_install() {
-
-
-
-
- $plain_text_format = array(
- 'format' => 'plain_text',
- 'name' => 'Plain text',
- 'weight' => 10,
- 'filters' => array(
-
- 'filter_html_escape' => array(
- 'weight' => 0,
- 'status' => 1,
- ),
-
- 'filter_url' => array(
- 'weight' => 1,
- 'status' => 1,
- ),
-
- 'filter_autop' => array(
- 'weight' => 2,
- 'status' => 1,
- ),
- ),
- );
- $plain_text_format = (object) $plain_text_format;
- filter_format_save($plain_text_format);
-
- variable_set('filter_fallback_format', $plain_text_format->format);
- }
- function filter_update_dependencies() {
-
-
-
- $dependencies['filter'][7005] = array(
- 'user' => 7007,
- );
- return $dependencies;
- }
- function filter_update_7000() {
- db_rename_table('filter_formats', 'filter_format');
-
- db_add_field('filter_format', 'status', array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 1,
- 'size' => 'tiny',
- 'description' => 'The status of the text format. (1 = enabled, 0 = disabled)',
- ));
- db_add_field('filter_format', 'weight', array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Weight of text format to use when listing.',
- ), array(
- 'indexes' => array(
- 'status_weight' => array('status', 'weight'),
- ),
- ));
- }
- function filter_update_7001() {
- $result = db_query("SELECT format FROM {filter_format}")->fetchCol();
- $insert = db_insert('filters')->fields(array('format', 'module', 'delta', 'weight'));
- foreach ($result as $format_id) {
-
- if (variable_get('filter_html_' . $format_id, 1) == 2) {
- $insert->values(array(
- 'format' => $format_id,
- 'module' => 'filter',
- 'delta' => 4,
- 'weight' => 0,
- ));
- }
- variable_del('filter_html_' . $format_id);
- }
- $insert->execute();
- }
- function filter_update_7003() {
-
-
- db_rename_table('filters', 'd6_upgrade_filter');
-
- $filter_table = 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,
- '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' => 'blob',
- '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'),
- 'indexes' => array(
- 'list' => array('weight', 'module', 'name'),
- ),
- );
- db_create_table('filter', $filter_table);
-
- $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',
- ),
- );
-
-
- foreach ($renamed_deltas as $module => $deltas) {
- foreach ($deltas as $old_delta => $new_name) {
- $query = db_select('d6_upgrade_filter')
- ->fields('d6_upgrade_filter', array('format', 'weight'))
- ->condition('module', $module)
- ->condition('delta', $old_delta)
- ->distinct();
- foreach ($query->execute() as $record) {
-
- $settings = array();
- if ($new_name == 'filter_html') {
- if ($setting = variable_get("allowed_html_{$record->format}", NULL)) {
- $settings['allowed_html'] = $setting;
- variable_del("allowed_html_{$record->format}");
- }
- if ($setting = variable_get("filter_html_help_{$record->format}", NULL)) {
- $settings['filter_html_help'] = $setting;
- variable_del("filter_html_help_{$record->format}");
- }
- if ($setting = variable_get("filter_html_nofollow_{$record->format}", NULL)) {
- $settings['filter_html_nofollow'] = $setting;
- variable_del("filter_html_nofollow_{$record->format}");
- }
- }
- elseif ($new_name == 'filter_url') {
- if ($setting = variable_get("filter_url_length_{$record->format}", NULL)) {
- $settings['filter_url_length'] = $setting;
- variable_del("filter_url_length_{$record->format}");
- }
- }
- db_insert('filter')
- ->fields(array(
- 'format' => $record->format,
- 'module' => $module,
- 'name' => $new_name,
- 'weight' => $record->weight,
- 'settings' => serialize($settings),
- 'status' => 1,
- ))
- ->execute();
- }
- db_delete('d6_upgrade_filter')
- ->condition('module', $module)
- ->condition('delta', $old_delta)
- ->execute();
- }
- }
- }
- function filter_update_7005() {
-
- $all_roles = array_keys(user_roles());
- $default_format = variable_get('filter_default_format', 1);
- $result = db_query("SELECT * FROM {filter_format}");
- foreach ($result as $format) {
-
-
-
- $format_roles = ($format->format == $default_format ? $all_roles : explode(',', $format->roles));
- foreach ($format_roles as $format_role) {
- if (in_array($format_role, $all_roles)) {
- _update_7000_user_role_grant_permissions($format_role, array('use text format ' . $format->format), 'filter');
- }
- }
- }
-
- db_drop_field('filter_format', 'roles');
-
-
-
- $start_name = 'Plain text';
- $format_name = $start_name;
- while ($format = db_query('SELECT format FROM {filter_format} WHERE name = :name', array(':name' => $format_name))->fetchField()) {
- $id = empty($id) ? 2 : $id + 1;
- $format_name = $start_name . ' ' . $id;
- }
-
- $format_id = db_insert('filter_format')
- ->fields(array(
- 'name' => $format_name,
- 'cache' => 1,
- 'weight' => 1,
- 'status' => 1,
- ))
- ->execute();
-
-
- db_insert('filter')
- ->fields(array(
- 'format',
- 'name',
- 'weight',
- 'status',
- 'module',
- 'settings',
- ))
- ->values(array(
- 'format' => $format_id,
- 'name' => 'filter_html_escape',
- 'weight' => 0,
- 'status' => 1,
- 'module' => 'filter',
- 'settings' => serialize(array()),
- ))
- ->values(array(
- 'format' => $format_id,
- 'name' => 'filter_url',
- 'weight' => 1,
- 'status' => 1,
- 'module' => 'filter',
- 'settings' => serialize(array()),
- ))
- ->values(array(
- 'format' => $format_id,
- 'name' => 'filter_autop',
- 'weight' => 2,
- 'status' => 1,
- 'module' => 'filter',
- 'settings' => serialize(array()),
- ))
- ->execute();
- variable_set('filter_fallback_format', $format_id);
- drupal_set_message('A new <em>Plain text</em> format has been created which will be available to all users. You can configure this text format on the <a href="' . url('admin/config/content/formats/' . $format) . '">text format configuration page</a>.');
-
-
- db_update('filter_format')
- ->fields(array('weight' => -1))
- ->condition('format', $default_format)
- ->execute();
-
-
-
- }
- function filter_update_7008() {
-
- $permissions = array();
- foreach (db_query('SELECT format FROM {filter_format}')->fetchCol() as $format_id) {
- if ($format_id != variable_get('filter_fallback_format')) {
- $permissions[] = 'use text format ' . $format_id;
- }
- }
-
-
-
- if ($roles = user_roles(FALSE, 'administer filters')) {
- foreach ($roles as $rid => $name) {
- _update_7000_user_role_grant_permissions($rid, $permissions, 'filter');
- }
- }
- }
- function filter_update_7009() {
- $schema = system_schema_cache_7054();
- db_drop_table('cache_filter');
- db_create_table('cache_filter', $schema);
- }
- function filter_update_7010() {
- db_change_field('filter_format', 'format', 'format', array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique machine name of the format.',
- ));
- db_change_field('filter', 'format', 'format', array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'description' => 'Foreign key: The {filter_format}.format to which this filter is assigned.',
- ));
- }
|