summaryrefslogtreecommitdiffstats
path: root/filefield_meta
diff options
context:
space:
mode:
authorJakob Petsovits2008-06-03 03:27:58 +0000
committerJakob Petsovits2008-06-03 03:27:58 +0000
commit490f07d90cadbc820f31b12e13ced7b22f4b7d87 (patch)
tree56730d7f309253ce93a8645a4ac96acd941e6e4d /filefield_meta
parent4589bd9415669c08cb4686e2cc492dec03a69f45 (diff)
Resync HEAD from DRUPAL-5--2. Your turn now, Crell!
Diffstat (limited to 'filefield_meta')
-rw-r--r--filefield_meta/filefield_meta.info5
-rw-r--r--filefield_meta/filefield_meta.install21
-rw-r--r--filefield_meta/filefield_meta.module96
3 files changed, 122 insertions, 0 deletions
diff --git a/filefield_meta/filefield_meta.info b/filefield_meta/filefield_meta.info
new file mode 100644
index 0000000..bb223d9
--- /dev/null
+++ b/filefield_meta/filefield_meta.info
@@ -0,0 +1,5 @@
+; $Id$
+name = FileField - Meta
+description = Add metadata gathering and storage to filefield.
+dependencies = content filefield getid3
+package = CCK
diff --git a/filefield_meta/filefield_meta.install b/filefield_meta/filefield_meta.install
new file mode 100644
index 0000000..8d45e77
--- /dev/null
+++ b/filefield_meta/filefield_meta.install
@@ -0,0 +1,21 @@
+<?php
+// $Id$
+
+/**
+ * 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)
+ )
+ ');
+}
+
+function filefield_meta_uninstall() {
+ db_query('DROP TABLE IF EXISTS {filefield_meta_backup}');
+ db_query('ALTER TABLE {filefield_meta} RENAME TO {filefield_meta_bak}');
+}
diff --git a/filefield_meta/filefield_meta.module b/filefield_meta/filefield_meta.module
new file mode 100644
index 0000000..732e6c8
--- /dev/null
+++ b/filefield_meta/filefield_meta.module
@@ -0,0 +1,96 @@
+<?php // $Id$
+
+/**
+ * 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_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;
+
+ case 'file_delete':
+ db_query('DELETE FROM {filefield_meta} WHERE fid = %d', $file['fid']);
+ break;
+
+ 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) {
+ $info = getid3_analyze($file['filepath']);
+ $file['width'] = $file['height'] = $file['duration'] = 0;
+ if (isset($info['video']['resolution_x'])) {
+ $file['width'] = $info['video']['resolution_x'];
+ $file['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['duration'] = $info['playtime_seconds'];
+};