| 1 |
<?php
|
| 2 |
// $Id: textimage.install,v 1.8 2009/05/12 23:45:01 deciphered Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Implementation of hook_requirements().
|
| 10 |
*/
|
| 11 |
function textimage_requirements($phase) {
|
| 12 |
// Ensure translations don't break at install time
|
| 13 |
$t = get_t();
|
| 14 |
|
| 15 |
$requirements['textimage_gd'] = array('title' => $t('GD library'));
|
| 16 |
if (drupal_function_exists('imagegd2')) {
|
| 17 |
$info = gd_info();
|
| 18 |
$requirements['textimage_gd']['value'] = $info['GD Version'];
|
| 19 |
|
| 20 |
// Check FreeType support
|
| 21 |
if (drupal_function_exists('imagettftext') && $info["FreeType Support"]) {
|
| 22 |
if (!module_exists('color') && !module_exists('imageapi_gd')) {
|
| 23 |
$requirements['textimage_gd']['severity'] = REQUIREMENT_OK;
|
| 24 |
}
|
| 25 |
else {
|
| 26 |
$requirements = array();
|
| 27 |
}
|
| 28 |
}
|
| 29 |
else {
|
| 30 |
$requirements['textimage_gd']['severity'] = REQUIREMENT_ERROR;
|
| 31 |
$requirements['textimage_gd']['description'] = t('The GD library for PHP is enabled, but was compiled without FreeType support. Please check the <a href="@url">PHP image documentation</a> for information on how to correct this.', array('@url' => 'http://www.php.net/manual/en/ref.image.php'));
|
| 32 |
}
|
| 33 |
}
|
| 34 |
|
| 35 |
else {
|
| 36 |
$requirements['textimage_gd'] = array(
|
| 37 |
'value' => $t('Not installed'),
|
| 38 |
'severity' => REQUIREMENT_ERROR,
|
| 39 |
'description' => $t('The GD library for PHP is missing or outdated. Please check the <a href="@url">PHP image documentation</a> for information on how to correct this.', array('@url' => 'http://www.php.net/manual/en/image.setup.php')),
|
| 40 |
);
|
| 41 |
}
|
| 42 |
|
| 43 |
return $requirements;
|
| 44 |
}
|
| 45 |
|
| 46 |
/**
|
| 47 |
* Implementation of hook_schema().
|
| 48 |
*/
|
| 49 |
function textimage_schema() {
|
| 50 |
$schema['textimage_preset'] = array(
|
| 51 |
'fields' => array(
|
| 52 |
'pid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 53 |
'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
|
| 54 |
'description' => array('type' => 'text', 'size' => 'medium', 'not null' => TRUE),
|
| 55 |
'settings' => array('type' => 'text', 'not null' => TRUE),
|
| 56 |
),
|
| 57 |
'primary key' => array('pid'),
|
| 58 |
);
|
| 59 |
|
| 60 |
$schema['textimage_image'] = array(
|
| 61 |
'fields' => array(
|
| 62 |
'pid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 63 |
'file' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
|
| 64 |
'data' => array('type' => 'text', 'not null' => TRUE),
|
| 65 |
),
|
| 66 |
'primary key' => array('file'),
|
| 67 |
);
|
| 68 |
|
| 69 |
return $schema;
|
| 70 |
}
|
| 71 |
|
| 72 |
/**
|
| 73 |
* Implementation of hook_install().
|
| 74 |
*/
|
| 75 |
function textimage_install() {
|
| 76 |
drupal_install_schema('textimage');
|
| 77 |
}
|
| 78 |
|
| 79 |
/**
|
| 80 |
* Implementation of hook_uninstall().
|
| 81 |
*/
|
| 82 |
function textimage_uninstall() {
|
| 83 |
include_once(drupal_get_path('module', 'textimage') . '/textimage_admin.inc');
|
| 84 |
|
| 85 |
drupal_uninstall_schema('textimage');
|
| 86 |
|
| 87 |
$path = realpath(file_directory_path() . '/textimage');
|
| 88 |
if ($path != FALSE) {
|
| 89 |
_textimage_recursive_delete($path);
|
| 90 |
}
|
| 91 |
|
| 92 |
db_query("DELETE from {variable} WHERE name LIKE '%%textimage_%%'");
|
| 93 |
}
|
| 94 |
|
| 95 |
/**
|
| 96 |
* Implementation of hook_update_N().
|
| 97 |
*
|
| 98 |
* Install the textimage tables and seperate variable names for captcha specific variables
|
| 99 |
*/
|
| 100 |
function textimage_update_1() {
|
| 101 |
$ret = array();
|
| 102 |
|
| 103 |
$schema['textimage_preset'] = array(
|
| 104 |
'fields' => array(
|
| 105 |
'pid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 106 |
'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
|
| 107 |
'settings' => array('type' => 'text', 'not null' => TRUE),
|
| 108 |
),
|
| 109 |
'primary key' => array('pid'),
|
| 110 |
);
|
| 111 |
db_create_table($ret, 'textimage_preset', $schema['textimage_preset']);
|
| 112 |
|
| 113 |
return $ret;
|
| 114 |
}
|
| 115 |
|
| 116 |
function textimage_update_2() {
|
| 117 |
$ret = array();
|
| 118 |
|
| 119 |
$schema['textimage_image'] = array(
|
| 120 |
'fields' => array(
|
| 121 |
'pid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 122 |
'file' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
|
| 123 |
'data' => array('type' => 'text', 'not null' => TRUE),
|
| 124 |
),
|
| 125 |
'primary key' => array('file'),
|
| 126 |
);
|
| 127 |
db_create_table($ret, 'textimage_image', $schema['textimage_image']);
|
| 128 |
|
| 129 |
include_once(drupal_get_path('module', 'textimage') . '/textimage_admin.inc');
|
| 130 |
foreach (textimage_get_presets() as $preset) {
|
| 131 |
$path = realpath(file_directory_path() . '/textimage/' . $preset->name);
|
| 132 |
|
| 133 |
if (is_dir($path)) {
|
| 134 |
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
|
| 135 |
foreach ($files as $file => $object) {
|
| 136 |
$file = str_replace($path . '/', '', $file);
|
| 137 |
$args = explode('/', $file);
|
| 138 |
|
| 139 |
$filename = urldecode(array_pop($args));
|
| 140 |
$additional_text = $args;
|
| 141 |
|
| 142 |
preg_match('/\.([a-z]+)$/i', $filename, $matches);
|
| 143 |
$format = $matches[1];
|
| 144 |
if ($format == 'jpg') {
|
| 145 |
$format = 'jpeg';
|
| 146 |
}
|
| 147 |
|
| 148 |
$text = preg_replace('/\.([a-z]+)$/i', '', $filename);
|
| 149 |
|
| 150 |
db_query(
|
| 151 |
"INSERT {textimage_image} (pid, file, data) VALUES (%d, '%s', '%s')",
|
| 152 |
$preset['pid'], file_directory_path() . '/textimage/' . $preset->name . '/' . $file,
|
| 153 |
serialize(array('format' => $format, 'text' => $text, 'additional_text' => $additional_text))
|
| 154 |
);
|
| 155 |
}
|
| 156 |
}
|
| 157 |
}
|
| 158 |
|
| 159 |
return $ret;
|
| 160 |
}
|
| 161 |
|
| 162 |
function textimage_update_3() {
|
| 163 |
$ret = array();
|
| 164 |
|
| 165 |
include_once(drupal_get_path('module', 'textimage') . '/textimage_admin.inc');
|
| 166 |
$presets = textimage_get_presets();
|
| 167 |
foreach ($presets as $preset) {
|
| 168 |
if ($preset->settings['text']['angle'] != 0) {
|
| 169 |
$preset->settings['text']['angle'] = -$preset->settings['text']['angle'];
|
| 170 |
_textimage_preset_update($preset->pid, $preset->name, $preset->description, $preset->settings);
|
| 171 |
}
|
| 172 |
}
|
| 173 |
|
| 174 |
return $ret;
|
| 175 |
}
|
| 176 |
|
| 177 |
function textimage_update_4() {
|
| 178 |
$ret = array();
|
| 179 |
|
| 180 |
db_add_field($ret = array(), 'textimage_preset', 'description', array('type' => 'text', 'size' => 'medium', 'not null' => TRUE));
|
| 181 |
|
| 182 |
include_once(drupal_get_path('module', 'textimage') .'/textimage_admin.inc');
|
| 183 |
$presets = textimage_get_presets();
|
| 184 |
foreach ($presets as $preset) {
|
| 185 |
// Update font settings.
|
| 186 |
if (!isset($preset->settings['font'])) {
|
| 187 |
$preset->settings['font'] = array(
|
| 188 |
'file' => $preset->settings['text']['font'],
|
| 189 |
'size' => $preset->settings['text']['size'],
|
| 190 |
'color' => array(
|
| 191 |
'hex' => $preset->settings['text']['color'],
|
| 192 |
'opacity' => 100,
|
| 193 |
),
|
| 194 |
);
|
| 195 |
unset($preset->settings['text']['font']);
|
| 196 |
unset($preset->settings['text']['size']);
|
| 197 |
unset($preset->settings['text']['color']);
|
| 198 |
}
|
| 199 |
|
| 200 |
// Update margin settings
|
| 201 |
if (!isset($preset->settings['text']['margin'])) {
|
| 202 |
$preset->settings['text']['margin'] = array(
|
| 203 |
'top' => $preset->settings['text']['margin_top'],
|
| 204 |
'right' => $preset->settings['text']['margin_right'],
|
| 205 |
'bottom' => $preset->settings['text']['margin_bottom'],
|
| 206 |
'left' => $preset->settings['text']['margin_left'],
|
| 207 |
);
|
| 208 |
unset($preset->settings['text']['margin_top']);
|
| 209 |
unset($preset->settings['text']['margin_right']);
|
| 210 |
unset($preset->settings['text']['margin_bottom']);
|
| 211 |
unset($preset->settings['text']['margin_left']);
|
| 212 |
}
|
| 213 |
|
| 214 |
// Update stroke settings.
|
| 215 |
if (!isset($preset->settings['text']['stroke'])) {
|
| 216 |
$preset->settings['text']['stroke'] = array(
|
| 217 |
'width' => $preset->settings['text']['stroke_width'],
|
| 218 |
'color' => $preset->settings['text']['stroke_color'],
|
| 219 |
);
|
| 220 |
unset($preset->settings['text']['stroke_width']);
|
| 221 |
unset($preset->settings['text']['stroke_color']);
|
| 222 |
}
|
| 223 |
|
| 224 |
// Update Preview text.
|
| 225 |
if (!isset($preset->settings['preview']['text']['default'])) {
|
| 226 |
$preset->settings['preview']['text']['default'] = $preset->settings['preview']['text'];
|
| 227 |
unset($preset->settings['preview']['text']);
|
| 228 |
}
|
| 229 |
|
| 230 |
// Update description.
|
| 231 |
if (isset($preset->settings['description'])) {
|
| 232 |
$preset->description = $preset->settings['description'];
|
| 233 |
unset($preset->settings['description']);
|
| 234 |
}
|
| 235 |
|
| 236 |
_textimage_preset_update($preset->pid, $preset->name, $preset->description, $preset->settings);
|
| 237 |
}
|
| 238 |
|
| 239 |
return $ret;
|
| 240 |
}
|