View source
<?php
function xbbcode_schema() {
$schema['xbbcode_custom_tags'] = array(
'description' => 'Custom tags created manually',
'fields' => array(
'name' => array(
'description' => 'Identifies the tag, and serves also to recognize it in text',
'type' => 'varchar',
'not null' => TRUE,
'length' => 32,
),
'replacewith' => array(
'description' => 'The code that this tag should be replaced with when filtering',
'type' => 'text',
'size' => 'normal',
'not null' => TRUE,
),
'description' => array(
'description' => 'Describes the use of this tag for the help text',
'type' => 'text',
'size' => 'normal',
'not null' => TRUE,
),
'sample' => array(
'description' => 'A sample of how this tag is to be used',
'type' => 'text',
'size' => 'normal',
'not null' => TRUE,
),
'dynamic' => array(
'description' => 'Whether this code should be evaluated as PHP rather than HTML',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'selfclosing' => array(
'description' => 'Whether the tag requires a closing tag or not',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'multiarg' => array(
'description' => 'Whether the tag accepts multiple named attributes rather than a single option string',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'name',
),
);
$schema['xbbcode_handlers'] = array(
'description' => 'The module that each tag will be handled by, per-format',
'fields' => array(
'name' => array(
'description' => 'Identifies the tag, and serves also to recognize it in text',
'type' => 'varchar',
'not null' => TRUE,
'length' => 32,
),
'format' => array(
'description' => 'Format ID - distinguishes the different format settings. -1 for global settings.',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
),
'module' => array(
'description' => 'The system name of the module that handles this tag',
'type' => 'varchar',
'not null' => TRUE,
'length' => 32,
),
'weight' => array(
'description' => 'Tags are prioritized by weight, then by name',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
),
'enabled' => array(
'description' => 'Whether this tag is currently enabled',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
),
),
'primary key' => array(
'name',
'format',
),
);
return $schema;
}
function xbbcode_install() {
drupal_install_schema('xbbcode');
$format_exists = db_result(db_query("SELECT COUNT(*) FROM {filter_formats} WHERE name = 'BBCode'"));
if (!$format_exists) {
db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('BBCode', '', 0)");
$format = db_result(db_query("SELECT format FROM {filter_formats} WHERE name='BBCode'"));
db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, 'xbbcode', 0, 1), (%d, 'filter', 0, 0), (%d, 'filter', 1, 2), (%d, 'filter', 2, 3)", $format, $format, $format, $format);
variable_set("filter_html_{$format}", FILTER_HTML_ESCAPE);
drupal_set_message(t('A <a href="@url">BBCode</a> input format has been created and assigned the additional filters HTML Filter, Line break converter, URL Filter.', array(
'@url' => url('admin/settings/filters/' . $format),
)));
}
else {
$format = db_result(db_query("SELECT format FROM {filter_formats} WHERE name='BBCode'"));
drupal_set_message(t('An existing format named <a href="@url">BBCode</a> has been detected. Please adjust its settings manually.', array(
'@url' => url('admin/settings/filters/' . $format),
)));
}
}
function xbbcode_update_1() {
$sql = '
CREATE TABLE
{xbbcode_handlers}
(
name VARCHAR(32),
format INT(4) NOT NULL DEFAULT -1,
module VARCHAR(32),
weight INT(2) NOT NULL DEFAULT 0,
enabled BOOLEAN NOT NULL DEFAULT TRUE,
PRIMARY KEY (name,format)
);';
$ret[] = update_sql($sql);
drupal_set_message(t("Table {xbbcode_handlers} created."), 'status');
return $ret;
}
function xbbcode_update_2() {
$ret[] = update_sql("ALTER TABLE {xbbcode_tags} RENAME {xbbcode_custom_tags};");
return $ret;
}
function xbbcode_update_3() {
$ret[] = update_sql("UPDATE {xbbcode_handlers} SET module='xbbcode_highlighter' WHERE module='highlighter';");
$ret[] = update_sql("UPDATE {xbbcode_handlers} SET module='xbbcode_basic' WHERE module='basicbb';");
$ret[] = update_sql("UPDATE {xbbcode_handlers} SET module='xbbcode_list' WHERE module='bblist';");
return $ret;
}
function xbbcode_update_6000() {
$ret[] = update_sql('UPDATE {xbbcode_handlers} SET format = 0 WHERE format = -1');
}