View source
<?php
function locale_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {locales_meta} (\n locale varchar(12) NOT NULL default '',\n name varchar(64) NOT NULL default '',\n enabled int NOT NULL default '0',\n isdefault int NOT NULL default '0',\n plurals int NOT NULL default '0',\n formula varchar(128) NOT NULL default '',\n PRIMARY KEY (locale)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {locales_source} (\n lid int NOT NULL auto_increment,\n location varchar(255) NOT NULL default '',\n source blob NOT NULL,\n PRIMARY KEY (lid),\n KEY source (source(30))\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {locales_target} (\n lid int NOT NULL default '0',\n translation blob NOT NULL,\n locale varchar(12) NOT NULL default '',\n plid int NOT NULL default '0',\n plural int NOT NULL default '0',\n KEY lid (lid),\n KEY lang (locale),\n KEY plid (plid),\n KEY plural (plural)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
db_query("CREATE TABLE {locales_meta} (\n locale varchar(12) NOT NULL default '',\n name varchar(64) NOT NULL default '',\n enabled int NOT NULL default '0',\n isdefault int NOT NULL default '0',\n plurals int NOT NULL default '0',\n formula varchar(128) NOT NULL default '',\n PRIMARY KEY (locale)\n )");
db_query("CREATE TABLE {locales_source} (\n lid serial,\n location varchar(255) NOT NULL default '',\n source text NOT NULL,\n PRIMARY KEY (lid)\n )");
db_query("CREATE TABLE {locales_target} (\n lid int NOT NULL default '0',\n translation text NOT NULL,\n locale varchar(12) NOT NULL default '',\n plid int NOT NULL default '0',\n plural int NOT NULL default '0'\n )");
db_query("CREATE INDEX {locales_target}_lid_idx ON {locales_target} (lid)");
db_query("CREATE INDEX {locales_target}_locale_idx ON {locales_target} (locale)");
db_query("CREATE INDEX {locales_target}_plid_idx ON {locales_target} (plid)");
db_query("CREATE INDEX {locales_target}_plural_idx ON {locales_target} (plural)");
db_query("CREATE INDEX {locales_source}_source_idx ON {locales_source} (source)");
break;
}
db_query("INSERT INTO {locales_meta} (locale, name, enabled, isdefault) VALUES ('en', 'English', '1', '1')");
}
function locale_uninstall() {
db_query('DROP TABLE {locales_meta}');
db_query('DROP TABLE {locales_source}');
db_query('DROP TABLE {locales_target}');
}
function locale_update_1() {
$ret = array();
$matches = db_result(db_query("SELECT 1 FROM {locales_meta} WHERE name LIKE '%<%' OR name LIKE '%>%'"));
if ($matches) {
$ret[] = update_sql("UPDATE {locales_meta} SET name = REPLACE(name, '<', '')");
$ret[] = update_sql("UPDATE {locales_meta} SET name = REPLACE(name, '>', '')");
drupal_set_message('The language name in English of all the existing custom languages of your site have been sanitized for security purposes. Visit the <a href="' . url('admin/settings/language') . '">Languages</a> page to check these and fix them if necessary.', 'warning');
}
if (db_result(db_query("SELECT 1 FROM {locales_meta} WHERE locale LIKE '%<%' OR locale LIKE '%>%' OR locale LIKE '%\"%' OR locale LIKE '%\\\\\\%'"))) {
drupal_set_message('Some of your custom language code values contain invalid characters. You should examine the <a href="' . url('admin/settings/language') . '">Languages</a> page. These must be fixed manually.', 'error');
}
return $ret;
}