You are here

media_media_mover.module in D7 Media 6

This module provides integration for Media Mover module with the Media module

File

media_media_mover/media_media_mover.module
View source
<?php

/**
 * @file
 * This module provides integration for Media Mover module
 * with the Media module
 */

/**
 * Implementation of hook_media_register
 * @return
 *   array
 */
function media_media_mover_media_register() {
  $registration = array();
  $registration['media_mover_all'] = array(
    'name' => 'All Media Mover files',
    'description' => t('Provides all Media Mover files'),
    'uri' => 'file',
    'kind' => 'resource',
    'callbacks' => array(
      'resource' => 'media_media_mover_all_files',
    ),
    'fields' => array(
      'attachments',
      'filefield',
    ),
  );
  $registration['media_mover_user'] = array(
    // human readable name
    'name' => 'My Media Mover files',
    'description' => 'Provides Media Mover generated files for this user',
    'uri' => 'file',
    'kind' => 'resource',
    'description' => t('Integrate Users Media Mover files'),
    'callbacks' => array(
      'resource' => 'media_media_mover_user_files',
    ),
    'fields' => array(
      'attachments',
      'filefield',
    ),
  );
  return $registration;
}
function media_media_mover_formatter_form($node_type, $field, $file_extension, $uri) {
  if ($uri) {
    $form['display'] = array(
      '#type' => 'item',
      '#value' => l($uri, $uri),
    );
    $form['list'] = array(
      '#type' => 'checkbox',
      '#title' => 'List file',
      '#default_value' => TRUE,
    );
  }
  return $form;
}

/**
 * Retrives all media mover files for reuse
 *
 * @param unknown_type $node_type
 * @param unknown_type $field
 * @param unknown_type $uid
 * @return unknown
 */
function media_media_mover_all_files($node_type, $field, $uid) {
  $files = array();
  $results = db_query('SELECT complete_file FROM {media_mover_files} ');
  while ($file = db_fetch_array($results)) {
    $files[] = array(
      'uri' => $file['complete_file'],
      'filename' => basename($file['complete_file']),
      'meta' => '',
    );
  }
  return array(
    t('Media Mover') => array(
      t('All Media Mover files') => media_resource_display_user_files_form($files, t('All Media Mover files')),
    ),
  );
}

/**
 * Retrives users media mover files
 *
 * @param unknown_type $node_type
 * @param unknown_type $field
 * @param unknown_type $uid
 * @return unknown
 */
function media_media_mover_user_files($node_type, $field, $uid) {
  global $user;
  $files = array();
  $results = db_query('SELECT complete_file FROM {media_mover_files} mmf LEFT JOIN {node} n ON mmf.nid = n.nid LEFT JOIN {users} u ON u.uid = n.uid WHERE u.uid = %d ORDER BY n.created DESC', $user->uid);
  while ($file = db_fetch_array($results)) {
    $files[] = array(
      'uri' => $file['complete_file'],
      'filename' => basename($file['complete_file']),
      'meta' => '',
    );
  }
  return array(
    t('My files') => array(
      t('Media Mover files') => media_resource_display_user_files_form($files, t('My Media Mover files')),
    ),
  );
}

Functions

Namesort descending Description
media_media_mover_all_files Retrives all media mover files for reuse
media_media_mover_formatter_form
media_media_mover_media_register Implementation of hook_media_register
media_media_mover_user_files Retrives users media mover files