summaryrefslogtreecommitdiffstats
path: root/filefield_meta
diff options
context:
space:
mode:
authorandrew morton2008-07-31 01:02:15 +0000
committerandrew morton2008-07-31 01:02:15 +0000
commite7327264155eb8a18004d7371df0cc039c357a14 (patch)
treefe5a7a04b6f830afa65bea52ff0cb07e044bbc94 /filefield_meta
parentac83a9cf7594fe36578229a636d5cea70b7d4bef (diff)
#289284 by drewish, Update filefield_meta to D6. The metadata is loaded
into $file->data now but still stored in the filefield_meta table for future views use. There's no display of the data at this point.
Diffstat (limited to 'filefield_meta')
-rw-r--r--filefield_meta/filefield_meta.info2
-rw-r--r--filefield_meta/filefield_meta.install51
-rw-r--r--filefield_meta/filefield_meta.module101
3 files changed, 68 insertions, 86 deletions
diff --git a/filefield_meta/filefield_meta.info b/filefield_meta/filefield_meta.info
index 4971ff7..e4844a2 100644
--- a/filefield_meta/filefield_meta.info
+++ b/filefield_meta/filefield_meta.info
@@ -4,5 +4,5 @@ description = Add metadata gathering and storage to FileField.
dependencies[] = filefield
dependencies[] = getid3
package = CCK
-core = 5.x
+core = 6.x
php = 5.2
diff --git a/filefield_meta/filefield_meta.install b/filefield_meta/filefield_meta.install
index 755cfb3..03f1561 100644
--- a/filefield_meta/filefield_meta.install
+++ b/filefield_meta/filefield_meta.install
@@ -9,17 +9,48 @@
* Implementation of hook_install().
*/
function filefield_meta_install() {
- db_query('CREATE TABLE {filefield_meta} (
- fid INT UNSIGNED NOT NULL,
- width INT UNSIGNED NOT NULL,
- height INT unsigned NOT NULL,
- duration FLOAT(53),
- PRIMARY KEY (fid)
- )
- ');
+ drupal_install_schema('filefield_meta');
}
function filefield_meta_uninstall() {
- db_query('DROP TABLE IF EXISTS {filefield_meta_backup}');
- db_query('ALTER TABLE {filefield_meta} RENAME TO {filefield_meta_bak}');
+ drupal_uninstall_schema('filefield_meta');
+}
+
+/**
+ * Implementation of hook_schema().
+ */
+function filefield_meta_schema() {
+ // The primary field/index.
+ $schema['filefield_meta'] = array(
+ 'description' => t('The table for meta data about filefield files.'),
+ 'fields' => array(
+ 'fid' => array(
+ 'description' => t('The file id.'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ ),
+ 'width' => array(
+ 'description' => t('Width of a video or image file in pixels.'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => FALSE,
+ ),
+ 'height' => array(
+ 'description' => t('Height of a video or image file in pixels.'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => FALSE,
+ ),
+ 'duration' => array(
+ 'description' => t('The duration of audio or video files, in seconds.'),
+ 'type' => 'float',
+ 'size' => 'normal',
+ 'not null' => FALSE,
+ ),
+ ),
+ 'primary key' => array('fid'),
+ );
+
+ return $schema;
}
diff --git a/filefield_meta/filefield_meta.module b/filefield_meta/filefield_meta.module
index 759ef72..85e8fd6 100644
--- a/filefield_meta/filefield_meta.module
+++ b/filefield_meta/filefield_meta.module
@@ -5,93 +5,44 @@
* FileField Meta: Add Video Support to File Field.
*/
-/**
- * Implementation of hook_filefield
- *
- * @param op
- * - file_save
- * - file_delete
- * - file_prepare
- * - file_validate
- * - file_load
- * - file_form
- * - delete
- *
- * @param node
- * @param field
- * @param file
- * @param form
- */
-
-define('FILEFIELD_META_MINIMUM_PHP', '5.2');
-
-/**
- * Implementation of hook_requirements().
- */
-function filefield_meta_requirements($phase) {
- $requirements = array();
- // Ensure translations don't break at install time
- $t = get_t();
-
- if (version_compare(phpversion(), FILEFIELD_META_MINIMUM_PHP) < 0) {
- $requirements['filefield_meta_php'] = array(
- 'title' => $t('FileField Meta PHP'),
- 'description' => $t('FileField Meta requires at least PHP %version.', array('%version' => FILEFIELD_META_MINIMUM_PHP)),
- 'severity' => REQUIREMENT_ERROR
- );
- }
-
- return $requirements;
+function filefield_meta_file_insert($file) {
+ filefield_meta($file);
+ $record = array_merge(array('fid' => $file->fid), $file->data);
+ drupal_write_record('filefield_meta', $record);
}
-function filefield_meta_filefield($op, &$node, $field, &$file, &$form = NULL) {
- $args = func_get_args();
-
- switch($op) {
- case 'file_form':
- $form['file_preview']['#value'] = '';
- $form['url']['#value'] .= '<br />'. t('width: !w; height: !h; duration: !d',
- array('!w' => $file['width'], '!h' => $file['height'], '!d' => $file['duration'])
- );
- $form['width'] = array('#type' => 'hidden', '#value' => $file['width']);
- $form['height'] = array('#type' => 'hidden', '#value' => $file['height']);
- $form['duration'] = array('#type' => 'hidden', '#value' => $file['duration']);
- break;
-
- case 'file_prepare':
- filefield_meta($file);
- return $file;
- break;
-
- case 'file_save':
- db_query('INSERT INTO {filefield_meta} (fid, width, height, duration) VALUES (%d, %d, %d, %d)', $file['fid'], $file['width'], $file['height'], $file['duration']);
- break;
+function filefield_meta_file_update($file) {
+ filefield_meta_file_delete($file);
+ filefield_meta($file);
+ $record = array_merge(array('fid' => $file->fid), $file->data);
+ drupal_write_record('filefield_meta', $record);
+}
- case 'file_delete':
- db_query('DELETE FROM {filefield_meta} WHERE fid = %d', $file['fid']);
- break;
+function filefield_meta_file_delete($file) {
+ db_query('DELETE FROM {filefield_meta} WHERE fid = %d', $file->fid);
+}
- case 'file_load':
- $meta = db_fetch_array(db_query('SELECT * FROM {filefield_meta} WHERE fid = %d', $file['fid']));
- if ($meta) {
- return $meta;
- }
- break;
+function filefield_meta_file_load(&$file) {
+ if ($meta = db_fetch_array(db_query('SELECT * FROM {filefield_meta} WHERE fid = %d', $file->fid))) {
+ $file->data = is_array($file->data) ? array_merge($meta, $file->data) : $meta;
+ }
+ else {
+ filefield_meta($file);
}
}
function filefield_meta(&$file) {
- $info = getid3_analyze($file['filepath']);
- $file['width'] = $file['height'] = $file['duration'] = 0;
+ $info = getid3_analyze($file->filepath);
+ $file->data['width'] = $file->data['height'] = $file->data['duration'] = 0;
if (isset($info['video']['resolution_x'])) {
- $file['width'] = $info['video']['resolution_x'];
- $file['height'] = $info['video']['resolution_y'];
+ $file->data['width'] = $info['video']['resolution_x'];
+ $file->data['height'] = $info['video']['resolution_y'];
}
else if (isset($info['video']['streams'])) {
foreach($info['video']['streams'] as $stream) {
- $file['width'] = max($file['width'], $stream['resolution_x']);
- $file['height'] = max($file['height'], $stream['resolution_y']);
+ $file->data['width'] = max($file->data['width'], $stream['resolution_x']);
+ $file->data['height'] = max($file->data['height'], $stream['resolution_y']);
}
}
- $file['duration'] = $info['playtime_seconds'];
+ $file->data['duration'] = $info['playtime_seconds'];
};