Commit 2196cf84 authored by Jon Stacey's avatar Jon Stacey

Clone of media_metadata from D6 branch and work by aaron (jmstacey).

parent b586cfcb
// $Id$
/** Changelog for media_metadatad.module **/
July 2009
-------------
* Clone initial module from D6 branch by aaron (jmstacey).
// $Id$
-------------------------------------------------------
Media Metadata Module
-------------------------------------------------------
; $Id$
name = Media Metadata
description = Provides metadata integration with the Media module.
package = "Media"
core = 7.x
dependencies[] = media
<?php
// $Id$
/**
* Implementation of hook_install().
*/
function media_metadata_install() {
drupal_install_schema('media_metadata');
}
/**
* Implementation of hook_uninstall().
*/
function media_metadata_uninstall() {
drupal_uninstall_schema('media_metadata');
// Remove all variables that live in our namespace.
db_query("DELETE FROM {variable} WHERE name LIKE 'media_metadata_%'");
}
/**
* Implementation of hook_schema().
*/
function media_metadata_schema() {
$schema['media_metadata'] = array(
'description' => 'Stores file resource metadata.',
'fields' => array(
'mid' => array(
'description' => 'The primary identifier for a metadata pair.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE
),
'fid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Primary Key: The {files}.fid.',
),
'name' => array(
'default' => '',
'description' => 'The metadata key name.',
'length' => 255,
'not null' => TRUE,
'type' => 'varchar',
),
'data' => array(
'type' => 'text',
'not null' => FALSE,
'description' => 'The value of metadata value pairs that are related to the file resource.',
),
),
'primary key' => array('mid'),
'indexes' => array('fid', 'name'),
);
return $schema;
}
<?php
// $Id$
/**
* @file
* This module provides metadata integration with the Media module.
*/
/**
* Returns the metadata keys associated with a file stream mimetype.
*
* The hook_media_metadata_keys of all implementing modules will be invoked
* with the mimetype to build a list of keys to be collected and saved for
* file resources of that mimetype.
*
* @param string $mimetype
* The file mimetype to return the keys. If '*' is passed, then only the
* keys stored for all mimetypes will be returned.
* @param boolean $exclusive
* If TRUE, then only the keys exclusive to that metadata will be returned.
* Otherwise, also include all metadata for the wildcard '*' mimetype.
* @param boolean $reset
* If TRUE, then rebuild the static cache of keys.
* @return array
* An array of unique metadata keys that will be saved for that mimetype.
*/
function media_metadata_keys($mimetype = '*', $exclusive = FALSE, $reset = FALSE) {
static $keys;
// Build our static cache.
if (is_null($keys)) {
$keys = array();
// Collect all metadata keys for the wildcard/all '*' mimetype.
$keys['*'] = module_invoke_all('media_metadata_keys', '*');
}
// If NULL is passed, assume it's the wildcard.
if (is_null($mimetype)) {
$mimetype = '*';
}
// Don't call module_invoke_all more than necessary; use the static variable.
if (isset($mimetype) && ($mimetype != '*') && ($reset || is_null($keys[$mimetype]))) {
// Build a unique array from all modules implementing hook_metadata_keys.
$keys[$mimetype] = array_unique(module_invoke_all('media_metadata_keys', $mimetype));
}
// Return either the keys for that mimetype, or the merged array of keys for
// the mimetype and for all '*' mimetypes, depending on $exclusive.
return ($exclusive || ($mimetype == '*')) ? $keys[$mimetype] : array_unique(array_merge($keys['*'], $keys[$mimetype]));
}
// @TODO: Add the file info here as well.
function media_metadata_form($form_state, $mimetype = '*') {
$form = module_invoke_all('media_metadata_form', $form_state, $mimetype);
$form['mimetype'] = array(
'#type' => 'value',
'#value' => $mimetype,
);
$form['#submit'] = array('media_metadata_form_submit');
}
function media_metadata_form_submit($form, &$form_state) {
$mimetype = $form_state['values']['mimetype'];
$keys = media_metadata_keys($mimetype);
$values = array();
foreach ($keys as $key) {
$values[$key] = $form_state['values'][$key];
}
// @TODO: Grab the file info and save the record.
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment