123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- <?php
- function image_install() {
-
- $directory = file_default_scheme() . '://styles';
- file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
- }
- function image_uninstall() {
-
- file_unmanaged_delete_recursive(file_default_scheme() . '://styles');
- }
- function image_schema() {
- $schema = array();
- $schema['cache_image'] = drupal_get_schema_unprocessed('system', 'cache');
- $schema['cache_image']['description'] = 'Cache table used to store information about image manipulations that are in-progress.';
- $schema['image_styles'] = array(
- 'description' => 'Stores configuration options for image styles.',
- 'fields' => array(
- 'isid' => array(
- 'description' => 'The primary identifier for an image style.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'name' => array(
- 'description' => 'The style machine name.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- ),
- 'label' => array(
- 'description' => 'The style administrative name.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- ),
- ),
- 'primary key' => array('isid'),
- 'unique keys' => array(
- 'name' => array('name'),
- ),
- );
- $schema['image_effects'] = array(
- 'description' => 'Stores configuration options for image effects.',
- 'fields' => array(
- 'ieid' => array(
- 'description' => 'The primary identifier for an image effect.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'isid' => array(
- 'description' => 'The {image_styles}.isid for an image style.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'weight' => array(
- 'description' => 'The weight of the effect in the style.',
- 'type' => 'int',
- 'unsigned' => FALSE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'name' => array(
- 'description' => 'The unique name of the effect to be executed.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- ),
- 'data' => array(
- 'description' => 'The configuration data for the effect.',
- 'type' => 'blob',
- 'not null' => TRUE,
- 'size' => 'big',
- 'serialize' => TRUE,
- ),
- ),
- 'primary key' => array('ieid'),
- 'indexes' => array(
- 'isid' => array('isid'),
- 'weight' => array('weight'),
- ),
- 'foreign keys' => array(
- 'image_style' => array(
- 'table' => 'image_styles',
- 'columns' => array('isid' => 'isid'),
- ),
- ),
- );
- return $schema;
- }
- function image_field_schema($field) {
- return array(
- 'columns' => array(
- 'fid' => array(
- 'description' => 'The {file_managed}.fid being referenced in this field.',
- 'type' => 'int',
- 'not null' => FALSE,
- 'unsigned' => TRUE,
- ),
- 'alt' => array(
- 'description' => "Alternative image text, for the image's 'alt' attribute.",
- 'type' => 'varchar',
- 'length' => 512,
- 'not null' => FALSE,
- ),
- 'title' => array(
- 'description' => "Image title text, for the image's 'title' attribute.",
- 'type' => 'varchar',
- 'length' => 1024,
- 'not null' => FALSE,
- ),
- 'width' => array(
- 'description' => 'The width of the image in pixels.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- ),
- 'height' => array(
- 'description' => 'The height of the image in pixels.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- ),
- ),
- 'indexes' => array(
- 'fid' => array('fid'),
- ),
- 'foreign keys' => array(
- 'fid' => array(
- 'table' => 'file_managed',
- 'columns' => array('fid' => 'fid'),
- ),
- ),
- );
- }
- function image_update_dependencies() {
- $dependencies['image'][7002] = array(
-
-
- 'system' => 7020,
- );
- return $dependencies;
- }
- function image_update_7000() {
- if (!db_table_exists('image_styles')) {
- $schema = array();
- $schema['cache_image'] = system_schema_cache_7054();
- $schema['cache_image']['description'] = 'Cache table used to store information about image manipulations that are in-progress.';
- $schema['image_styles'] = array(
- 'description' => 'Stores configuration options for image styles.',
- 'fields' => array(
- 'isid' => array(
- 'description' => 'The primary identifier for an image style.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'name' => array(
- 'description' => 'The style name.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('isid'),
- 'unique keys' => array(
- 'name' => array('name'),
- ),
- );
- $schema['image_effects'] = array(
- 'description' => 'Stores configuration options for image effects.',
- 'fields' => array(
- 'ieid' => array(
- 'description' => 'The primary identifier for an image effect.',
- 'type' => 'serial',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'isid' => array(
- 'description' => 'The {image_styles}.isid for an image style.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'weight' => array(
- 'description' => 'The weight of the effect in the style.',
- 'type' => 'int',
- 'unsigned' => FALSE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'name' => array(
- 'description' => 'The unique name of the effect to be executed.',
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- ),
- 'data' => array(
- 'description' => 'The configuration data for the effect.',
- 'type' => 'blob',
- 'not null' => TRUE,
- 'size' => 'big',
- 'serialize' => TRUE,
- ),
- ),
- 'primary key' => array('ieid'),
- 'indexes' => array(
- 'isid' => array('isid'),
- 'weight' => array('weight'),
- ),
- 'foreign keys' => array(
- 'image_style' => array(
- 'table' => 'image_styles',
- 'columns' => array('isid' => 'isid'),
- ),
- ),
- );
- db_create_table('cache_image', $schema['cache_image']);
- db_create_table('image_styles', $schema['image_styles']);
- db_create_table('image_effects', $schema['image_effects']);
- }
- }
- function image_update_7001() {
-
-
-
- if (!db_table_exists('image_effects') && db_table_exists('image_effect')) {
- db_rename_table('image_effect', 'image_effects');
- }
- }
- function _image_update_7002_add_columns($table, $field_name) {
- $spec = array(
- 'type' => 'int',
- 'unsigned' => TRUE,
- );
- $spec['description'] = 'The width of the image in pixels.';
- db_add_field($table, $field_name . '_width', $spec);
- $spec['description'] = 'The height of the image in pixels.';
- db_add_field($table, $field_name . '_height', $spec);
- }
- function _image_update_7002_populate_dimensions($table, $field_name, &$last_fid) {
-
- $images_per_pass = 100;
-
- $query = db_select($table, NULL, array('fetch' => PDO::FETCH_ASSOC));
- $query->join('file_managed', NULL, $table . '.' . $field_name . '_fid = file_managed.fid');
- if ($last_fid) {
- $query->condition('file_managed.fid', $last_fid, '>');
- }
- $result = $query->fields('file_managed', array('fid', 'uri'))
- ->orderBy('file_managed.fid')
- ->range(0, $images_per_pass)
- ->execute();
- $count = 0;
- foreach ($result as $file) {
- $count++;
- $info = image_get_info($file['uri']);
- if (is_array($info)) {
- db_update($table)
- ->fields(array(
- $field_name . '_width' => $info['width'],
- $field_name . '_height' => $info['height'],
- ))
- ->condition($field_name . '_fid', $file['fid'])
- ->execute();
- }
- }
-
-
- $last_fid = ($count < $images_per_pass) ? NULL : $file['fid'];
- return $count;
- }
- function image_update_7002(array &$sandbox) {
- if (empty($sandbox)) {
-
- $sandbox = array(
- 'tables' => array(),
- 'total' => 0,
- 'processed' => 0,
- 'last_fid' => NULL,
- );
- $fields = _update_7000_field_read_fields(array(
- 'module' => 'image',
- 'storage_type' => 'field_sql_storage',
- 'deleted' => 0,
- ));
- foreach ($fields as $field) {
- $tables = array(
- _field_sql_storage_tablename($field),
- _field_sql_storage_revision_tablename($field),
- );
- foreach ($tables as $table) {
-
- _image_update_7002_add_columns($table, $field['field_name']);
-
- $count = db_select($table)->countQuery()->execute()->fetchField();
- if (!$count) {
- continue;
- }
- $sandbox['total'] += $count;
- $sandbox['tables'][$table] = $field['field_name'];
- }
- }
-
- if (empty($sandbox['tables'])) {
- $sandbox = array();
- return;
- }
- }
-
- $keys = array_keys($sandbox['tables']);
- $table = reset($keys);
- $sandbox['processed'] += _image_update_7002_populate_dimensions($table, $sandbox['tables'][$table], $sandbox['last_fid']);
-
- if (!$sandbox['last_fid']) {
- unset($sandbox['tables'][$table]);
- }
- $sandbox['#finished'] = count($sandbox['tables']) ? ($sandbox['processed'] / $sandbox['total']) : 1;
- }
- function image_update_7003() {
- variable_del('image_alt_length');
- variable_del('image_title_length');
- }
- function image_update_7004() {
- $alt_spec = array(
- 'type' => 'varchar',
- 'length' => 512,
- 'not null' => FALSE,
- );
- $title_spec = array(
- 'type' => 'varchar',
- 'length' => 1024,
- 'not null' => FALSE,
- );
- $fields = _update_7000_field_read_fields(array(
- 'module' => 'image',
- 'storage_type' => 'field_sql_storage',
- ));
- foreach ($fields as $field_name => $field) {
- $tables = array(
- _field_sql_storage_tablename($field),
- _field_sql_storage_revision_tablename($field),
- );
- $alt_column = $field['field_name'] . '_alt';
- $title_column = $field['field_name'] . '_title';
- foreach ($tables as $table) {
- db_change_field($table, $alt_column, $alt_column, $alt_spec);
- db_change_field($table, $title_column, $title_column, $title_spec);
- }
- }
- }
- function image_update_7005() {
- $field = array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The style administrative name.',
- );
- db_add_field('image_styles', 'label', $field);
-
-
- $styles = db_query('SELECT name FROM {image_styles}')->fetchCol();
- foreach ($styles as $style) {
- db_update('image_styles')
- ->fields(array('label' => $style))
- ->condition('name', $style)
- ->execute();
- }
- }
- function image_requirements($phase) {
- $requirements = array();
- if ($phase == 'runtime') {
-
- if (function_exists('imagegd2')) {
- $info = gd_info();
- $requirements['image_gd'] = array(
- 'value' => $info['GD Version'],
- );
-
- if (function_exists('imagefilter') && function_exists('imagerotate')) {
- $requirements['image_gd']['severity'] = REQUIREMENT_OK;
- }
- else {
- $requirements['image_gd']['severity'] = REQUIREMENT_WARNING;
- $requirements['image_gd']['description'] = t('The GD Library for PHP is enabled, but was compiled without support for functions used by the rotate and desaturate effects. It was probably compiled using the official GD libraries from http://www.libgd.org instead of the GD library bundled with PHP. You should recompile PHP --with-gd using the bundled GD library. See <a href="http://www.php.net/manual/book.image.php">the PHP manual</a>.');
- }
- }
- else {
- $requirements['image_gd'] = array(
- 'value' => t('Not installed'),
- 'severity' => REQUIREMENT_ERROR,
- 'description' => t('The GD library for PHP is missing or outdated. Check the <a href="@url">PHP image documentation</a> for information on how to correct this.', array('@url' => 'http://www.php.net/manual/book.image.php')),
- );
- }
- $requirements['image_gd']['title'] = t('GD library rotate and desaturate effects');
- }
- return $requirements;
- }
|