| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Implementation of hook_install(). 5 */ 6 function locale_install() { 7 // locales_source.source and locales_target.target are not used as binary 8 // fields; non-MySQL database servers need to ensure the field type is text 9 // and that LIKE produces a case-sensitive comparison. 10 11 // Create tables. 12 drupal_install_schema('locale'); 13 14 db_query("INSERT INTO {languages} (language, name, native, direction, enabled, weight, javascript) VALUES ('en', 'English', 'English', '0', '1', '0', '')"); 15 } 16 17 /** 18 * @defgroup updates-5.x-to-6.x Locale updates from 5.x to 6.x 19 * @{ 20 */ 21 22 /** 23 * {locales_meta} table became {languages}. 24 */ 25 function locale_update_6000() { 26 $ret = array(); 27 28 $schema['languages'] = array( 29 'fields' => array( 30 'language' => array( 31 'type' => 'varchar', 32 'length' => 12, 33 'not null' => TRUE, 34 'default' => '', 35 ), 36 'name' => array( 37 'type' => 'varchar', 38 'length' => 64, 39 'not null' => TRUE, 40 'default' => '', 41 ), 42 'native' => array( 43 'type' => 'varchar', 44 'length' => 64, 45 'not null' => TRUE, 46 'default' => '', 47 ), 48 'direction' => array( 49 'type' => 'int', 50 'not null' => TRUE, 51 'default' => 0, 52 ), 53 'enabled' => array( 54 'type' => 'int', 55 'not null' => TRUE, 56 'default' => 0, 57 ), 58 'plurals' => array( 59 'type' => 'int', 60 'not null' => TRUE, 61 'default' => 0, 62 ), 63 'formula' => array( 64 'type' => 'varchar', 65 'length' => 128, 66 'not null' => TRUE, 67 'default' => '', 68 ), 69 'domain' => array( 70 'type' => 'varchar', 71 'length' => 128, 72 'not null' => TRUE, 73 'default' => '', 74 ), 75 'prefix' => array( 76 'type' => 'varchar', 77 'length' => 128, 78 'not null' => TRUE, 79 'default' => '', 80 ), 81 'weight' => array( 82 'type' => 'int', 83 'not null' => TRUE, 84 'default' => 0, 85 ), 86 'javascript' => array( //Adds a column to store the filename of the JavaScript translation file. 87 'type' => 'varchar', 88 'length' => 32, 89 'not null' => TRUE, 90 'default' => '', 91 ), 92 ), 93 'primary key' => array('language'), 94 'indexes' => array( 95 'list' => array('weight', 'name'), 96 ), 97 ); 98 99 db_create_table($ret, 'languages', $schema['languages']); 100 101 // Save the languages 102 $ret[] = update_sql("INSERT INTO {languages} (language, name, native, direction, enabled, plurals, formula, domain, prefix, weight) SELECT locale, name, name, 0, enabled, plurals, formula, '', locale, 0 FROM {locales_meta}"); 103 104 // Save the language count in the variable table 105 $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1')); 106 variable_set('language_count', $count); 107 108 // Save the default language in the variable table 109 $default = db_fetch_object(db_query('SELECT * FROM {locales_meta} WHERE isdefault = 1')); 110 variable_set('language_default', (object) array('language' => $default->locale, 'name' => $default->name, 'native' => '', 'direction' => 0, 'enabled' => 1, 'plurals' => $default->plurals, 'formula' => $default->formula, 'domain' => '', 'prefix' => $default->locale, 'weight' => 0)); 111 112 $ret[] = update_sql("DROP TABLE {locales_meta}"); 113 return $ret; 114 } 115 116 /** 117 * Change locale column to language. The language column is added by 118 * update_fix_d6_requirements() in update.php to avoid a large number 119 * of error messages from update.php. All we need to do here is copy 120 * locale to language and then drop locale. 121 */ 122 function locale_update_6001() { 123 $ret = array(); 124 $ret[] = update_sql('UPDATE {locales_target} SET language = locale'); 125 db_drop_field($ret, 'locales_target', 'locale'); 126 return $ret; 127 } 128 129 /** 130 * Remove empty translations, we don't need these anymore. 131 */ 132 function locale_update_6002() { 133 $ret = array(); 134 $ret[] = update_sql("DELETE FROM {locales_target} WHERE translation = ''"); 135 return $ret; 136 } 137 138 /** 139 * Prune strings with no translations (will be automatically re-registered if still in use) 140 */ 141 function locale_update_6003() { 142 $ret = array(); 143 $ret[] = update_sql("DELETE FROM {locales_source} WHERE lid NOT IN (SELECT lid FROM {locales_target})"); 144 return $ret; 145 } 146 147 /** 148 * Fix remaining inconsistent indexes. 149 */ 150 function locale_update_6004() { 151 $ret = array(); 152 db_add_index($ret, 'locales_target', 'language', array('language')); 153 154 switch ($GLOBALS['db_type']) { 155 case 'pgsql': 156 db_drop_index($ret, 'locales_source', 'source'); 157 db_add_index($ret, 'locales_source', 'source', array(array('source', 30))); 158 break; 159 } 160 161 return $ret; 162 } 163 164 /** 165 * Change language setting variable of content types. 166 * 167 * Use language_content_type_<content_type> instead of language_<content_type> 168 * so content types such as 'default', 'count' or 'negotiation' will not 169 * interfere with language variables. 170 */ 171 function locale_update_6005() { 172 foreach (node_get_types() as $type => $content_type) { 173 // Default to NULL, so we can skip dealing with non-existent settings. 174 $setting = variable_get('language_'. $type, NULL); 175 if ($type == 'default' && is_numeric($setting)) { 176 // language_default was overwritten with the content type setting, 177 // so reset the default language and save the content type setting. 178 variable_set('language_content_type_default', $setting); 179 variable_del('language_default'); 180 drupal_set_message('The default language setting has been reset to its default value. Check the '. l('language configuration page', 'admin/settings/language') .' to configure it correctly.'); 181 } 182 elseif ($type == 'negotiation') { 183 // language_content_type_negotiation is an integer either if it is 184 // the negotiation setting or the content type setting. 185 // The language_negotiation setting is not reset, but 186 // the user is alerted that this setting possibly was overwritten 187 variable_set('language_content_type_negotiation', $setting); 188 drupal_set_message('The language negotiation setting was possibly overwritten by a content type of the same name. Check the '. l('language configuration page', 'admin/settings/language/configure') .' and the '. l('<em>'. $content_type->name ."</em> content type's multilingual support settings", 'admin/content/types/negotiation', array('html' => TRUE)) .' to configure them correctly.'); 189 } 190 elseif (!is_null($setting)) { 191 // Change the language setting variable for any other content type. 192 // Do not worry about language_count, it will be updated below. 193 variable_set('language_content_type_'. $type, $setting); 194 variable_del('language_'. $type); 195 } 196 } 197 // Update language count variable that might be overwritten. 198 $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1')); 199 variable_set('language_count', $count); 200 return array(); 201 } 202 203 /** 204 * Neutralize unsafe language names in the database. 205 */ 206 function locale_update_6006() { 207 $ret = array(); 208 $matches = db_result(db_query("SELECT 1 FROM {languages} WHERE native LIKE '%<%' OR native LIKE '%>%' OR name LIKE '%<%' OR name LIKE '%>%'")); 209 if ($matches) { 210 $ret[] = update_sql("UPDATE {languages} SET name = REPLACE(name, '<', ''), native = REPLACE(native, '<', '')"); 211 $ret[] = update_sql("UPDATE {languages} SET name = REPLACE(name, '>', ''), native = REPLACE(native, '>', '')"); 212 drupal_set_message('The language name in English and the native language name values 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'); 213 } 214 // Check if some langcode values contain potentially dangerous characters and 215 // warn the user if so. These are not fixed since they are referenced in other 216 // tables (e.g. {node}). 217 if (db_result(db_query("SELECT 1 FROM {languages} WHERE language LIKE '%<%' OR language LIKE '%>%' OR language LIKE '%\"%' OR language LIKE '%\\\\\%'"))) { 218 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'); 219 } 220 return $ret; 221 } 222 223 /** 224 * @} End of "defgroup updates-5.x-to-6.x" 225 */ 226 227 /** 228 * @defgroup updates-6.x-extra Locale updates for 6.x 229 * @{ 230 */ 231 232 /** 233 * Fix Drupal.formatPlural(). 234 */ 235 function locale_update_6007() { 236 locale_inc_callback('_locale_invalidate_js'); 237 return array(); 238 } 239 240 /** 241 * @} End of "defgroup updates-6.x-extra" 242 * The next series of updates should start at 7000. 243 */ 244 245 /** 246 * Implementation of hook_uninstall(). 247 */ 248 function locale_uninstall() { 249 // Delete all JavaScript translation files 250 $files = db_query('SELECT javascript FROM {languages}'); 251 while ($file = db_fetch_object($files)) { 252 if (!empty($file)) { 253 file_delete(file_create_path($file->javascript)); 254 } 255 } 256 257 // Clear variables. 258 variable_del('language_default'); 259 variable_del('language_count'); 260 variable_del('language_content_type_default'); 261 variable_del('language_content_type_negotiation'); 262 variable_del('locale_cache_strings'); 263 variable_del('locale_js_directory'); 264 variable_del('javascript_parsed'); 265 variable_del('language_negotiation'); 266 267 foreach (node_get_types() as $type => $content_type) { 268 variable_del("language_content_type_$type"); 269 } 270 271 // Switch back to English: with a $language->language value different from 272 // 'en' successive calls of t() might result in calling locale(), which in 273 // turn might try to query the unexisting {locales_source} and 274 // {locales_target} tables. 275 drupal_init_language(); 276 277 // Remove tables. 278 drupal_uninstall_schema('locale'); 279 } 280 281 /** 282 * Implementation of hook_schema(). 283 */ 284 function locale_schema() { 285 $schema['languages'] = array( 286 'description' => 'List of all available languages in the system.', 287 'fields' => array( 288 'language' => array( 289 'type' => 'varchar', 290 'length' => 12, 291 'not null' => TRUE, 292 'default' => '', 293 'description' => "Language code, e.g. 'de' or 'en-US'.", 294 ), 295 'name' => array( 296 'type' => 'varchar', 297 'length' => 64, 298 'not null' => TRUE, 299 'default' => '', 300 'description' => 'Language name in English.', 301 ), 302 'native' => array( 303 'type' => 'varchar', 304 'length' => 64, 305 'not null' => TRUE, 306 'default' => '', 307 'description' => 'Native language name.', 308 ), 309 'direction' => array( 310 'type' => 'int', 311 'not null' => TRUE, 312 'default' => 0, 313 'description' => 'Direction of language (Left-to-Right = 0, Right-to-Left = 1).', 314 ), 315 'enabled' => array( 316 'type' => 'int', 317 'not null' => TRUE, 318 'default' => 0, 319 'description' => 'Enabled flag (1 = Enabled, 0 = Disabled).', 320 ), 321 'plurals' => array( 322 'type' => 'int', 323 'not null' => TRUE, 324 'default' => 0, 325 'description' => 'Number of plural indexes in this language.', 326 ), 327 'formula' => array( 328 'type' => 'varchar', 329 'length' => 128, 330 'not null' => TRUE, 331 'default' => '', 332 'description' => 'Plural formula in PHP code to evaluate to get plural indexes.', 333 ), 334 'domain' => array( 335 'type' => 'varchar', 336 'length' => 128, 337 'not null' => TRUE, 338 'default' => '', 339 'description' => 'Domain to use for this language.', 340 ), 341 'prefix' => array( 342 'type' => 'varchar', 343 'length' => 128, 344 'not null' => TRUE, 345 'default' => '', 346 'description' => 'Path prefix to use for this language.', 347 ), 348 'weight' => array( 349 'type' => 'int', 350 'not null' => TRUE, 351 'default' => 0, 352 'description' => 'Weight, used in lists of languages.', 353 ), 354 'javascript' => array( 355 'type' => 'varchar', 356 'length' => 32, 357 'not null' => TRUE, 358 'default' => '', 359 'description' => 'Location of JavaScript translation file.', 360 ), 361 ), 362 'primary key' => array('language'), 363 'indexes' => array( 364 'list' => array('weight', 'name'), 365 ), 366 ); 367 368 $schema['locales_source'] = array( 369 'description' => 'List of English source strings.', 370 'fields' => array( 371 'lid' => array( 372 'type' => 'serial', 373 'not null' => TRUE, 374 'description' => 'Unique identifier of this string.', 375 ), 376 'location' => array( 377 'type' => 'varchar', 378 'length' => 255, 379 'not null' => TRUE, 380 'default' => '', 381 'description' => 'Drupal path in case of online discovered translations or file path in case of imported strings.', 382 ), 383 'textgroup' => array( 384 'type' => 'varchar', 385 'length' => 255, 386 'not null' => TRUE, 387 'default' => 'default', 388 'description' => 'A module defined group of translations, see hook_locale().', 389 ), 390 'source' => array( 391 'type' => 'text', 392 'mysql_type' => 'blob', 393 'not null' => TRUE, 394 'description' => 'The original string in English.', 395 ), 396 'version' => array( 397 'type' => 'varchar', 398 'length' => 20, 399 'not null' => TRUE, 400 'default' => 'none', 401 'description' => 'Version of Drupal, where the string was last used (for locales optimization).', 402 ), 403 ), 404 'primary key' => array('lid'), 405 'indexes' => array( 406 'source' => array(array('source', 30)), 407 ), 408 ); 409 410 $schema['locales_target'] = array( 411 'description' => 'Stores translated versions of strings.', 412 'fields' => array( 413 'lid' => array( 414 'type' => 'int', 415 'not null' => TRUE, 416 'default' => 0, 417 'description' => 'Source string ID. References {locales_source}.lid.', 418 ), 419 'translation' => array( 420 'type' => 'text', 421 'mysql_type' => 'blob', 422 'not null' => TRUE, 423 'description' => 'Translation string value in this language.', 424 ), 425 'language' => array( 426 'type' => 'varchar', 427 'length' => 12, 428 'not null' => TRUE, 429 'default' => '', 430 'description' => 'Language code. References {languages}.language.', 431 ), 432 'plid' => array( 433 'type' => 'int', 434 'not null' => TRUE, // This should be NULL for no referenced string, not zero. 435 'default' => 0, 436 'description' => 'Parent lid (lid of the previous string in the plural chain) in case of plural strings. References {locales_source}.lid.', 437 ), 438 'plural' => array( 439 'type' => 'int', 440 'not null' => TRUE, 441 'default' => 0, 442 'description' => 'Plural index number in case of plural strings.', 443 ), 444 ), 445 'primary key' => array('language', 'lid', 'plural'), 446 'indexes' => array( 447 'lid' => array('lid'), 448 'plid' => array('plid'), 449 'plural' => array('plural'), 450 ), 451 ); 452 453 return $schema; 454 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |