| 1 |
<?php
|
| 2 |
// $Id: typogrify.install,v 1.1.2.2 2009/05/30 12:37:29 mikl Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file typogrify.install
|
| 6 |
* Upgrade hooks for the Typogrify module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Upgrade Typogrify settings to the new format.
|
| 11 |
*/
|
| 12 |
function typogrify_update_7000() {
|
| 13 |
$ret = array();
|
| 14 |
$current_settings = array();
|
| 15 |
|
| 16 |
// Iterate over the current settings, and try to match them to the old
|
| 17 |
// ones.
|
| 18 |
$search_query = db_query("SELECT name FROM {variable} WHERE name LIKE 'typogrify_%';");
|
| 19 |
while ($row = db_fetch_array($search_query)) {
|
| 20 |
$match = array();
|
| 21 |
|
| 22 |
if (preg_match('/^typogrify_settings_(\d+)$/', $row['name'], $match)) {
|
| 23 |
$current_settings[$match[1]]['has_new_settings'] = TRUE;
|
| 24 |
}
|
| 25 |
elseif (preg_match('/^typogrify_is_([_\w]+)_on_(\d+)$/', $row['name'], $match)) {
|
| 26 |
$current_settings[$match[2]][$match[1]] = variable_get($row['name'], NULL);
|
| 27 |
}
|
| 28 |
elseif (preg_match('/^typogrify_use_([\w]+)_ligature_(\d+)$/', $row['name'], $match)) {
|
| 29 |
$current_settings[$match[2]]['ligatures'][$match[1]] = variable_get($row['name'], NULL);
|
| 30 |
}
|
| 31 |
elseif (preg_match('/^typogrify_use_unicode_for_([|<>=-]+)_(\d+)$/', $row['name'], $match)) {
|
| 32 |
$current_settings[$match[2]]['arrows'][$match[1]] = variable_get($row['name'], NULL);
|
| 33 |
}
|
| 34 |
|
| 35 |
// Unless it's the new settings, delete the setting.
|
| 36 |
if (strpos($row['name'], 'typogrify_settings_') !== 0) {
|
| 37 |
variable_del($row['name']);
|
| 38 |
}
|
| 39 |
}
|
| 40 |
|
| 41 |
// Iterate over all the filter formats, snap up the old settings and
|
| 42 |
// save new ones based on the old and the default settings.
|
| 43 |
$filter_query = db_query("SELECT format FROM {filter_format} WHERE 1");
|
| 44 |
while ($format = db_result($filter_query)) {
|
| 45 |
if (isset($current_settings[$format])) {
|
| 46 |
$settings = $current_settings[$format];
|
| 47 |
}
|
| 48 |
else {
|
| 49 |
$settings = array();
|
| 50 |
}
|
| 51 |
|
| 52 |
// The matching stuff above doesn't pick up the old Marksmarty
|
| 53 |
// settings, so we'll grab those here.
|
| 54 |
$marksmarty_on = variable_get('marksmarty_is_smarty_on_' . $format, NULL);
|
| 55 |
if (!is_null($marksmarty_on)) {
|
| 56 |
$settings['smartypants_enabled'] = $marksmarty_on;
|
| 57 |
variable_del('marksmarty_is_smarty_on_' . $format);
|
| 58 |
}
|
| 59 |
$marksmarty_hyphens = variable_get('marksmarty_smarty_hyphens_' . $format, NULL);
|
| 60 |
if (!is_null($marksmarty_hyphens)) {
|
| 61 |
$settings['smartypants_hyphens'] = $marksmarty_hyphens;
|
| 62 |
variable_del('marksmarty_smarty_hyphens_' . $format);
|
| 63 |
}
|
| 64 |
|
| 65 |
// Format already has settings and not the new settings format.
|
| 66 |
if (!empty($settings) && !$settings['has_new_settings']) {
|
| 67 |
// Transform the words we extracted from the variable names in to
|
| 68 |
// the real setting names.
|
| 69 |
if (isset($settings['amp'])) {
|
| 70 |
$settings['wrap_ampersand'] = $settings['amp'];
|
| 71 |
unset($settings['amp']);
|
| 72 |
}
|
| 73 |
if (isset($settings['caps'])) {
|
| 74 |
$settings['wrap_caps'] = $settings['caps'];
|
| 75 |
unset($settings['caps']);
|
| 76 |
}
|
| 77 |
if (isset($settings['initial_quotes'])) {
|
| 78 |
$settings['wrap_initial_quotes'] = $settings['initial_quotes'];
|
| 79 |
unset($settings['initial_quotes']);
|
| 80 |
}
|
| 81 |
if (isset($settings['widont'])) {
|
| 82 |
$settings['widont_enabled'] = $settings['widont'];
|
| 83 |
unset($settings['widont']);
|
| 84 |
}
|
| 85 |
|
| 86 |
// Then merge in our default settings.
|
| 87 |
module_load_include('php', 'typogrify', 'unicode-conversion');
|
| 88 |
$settings += _typogrify_default_settings();
|
| 89 |
|
| 90 |
// Save the upgraded settings to the database.
|
| 91 |
variable_set('typogrify_settings_' . $format, $settings);
|
| 92 |
}
|
| 93 |
}
|
| 94 |
return $ret;
|
| 95 |
}
|
| 96 |
|