any wrong code with this?

filefield_display.info

; $Id: filefield_display.info,v 1.1 2007/07/26 19:06:52 nedjo Exp $
name = File Field Display
description = Adds display options for file fields.
dependencies[] = content
package = CCK
version = 6.x-1.0
core = 6.x

; Information added by drupal.org packaging script on 2008-01-28
version = "6.x-1.x-dev"
core = "6.x"
project = "filefield_display"
datestamp = "1201488309"

filefield_display.module

<?php
// $Id: mediafield_display.module,v 1.2.2.6 2008/01/28 02:18:40 colan Exp $

/**
 * @file
 * Provides display handlers for audio fields.
 *
 * When enabled, this module enables display alternatives for audio fields
 * provided by Media Field and link fields containing audio files. These
 * options are available in CCK field display administration and also in Views
 * field configuration.
 */

/**
 * Implementation of hook_field_formatter_info().
 */
function filefield_display_field_formatter_info() {
  $formatters = array();
  if (module_exists('filefield')) {
    $path = drupal_get_path('module', 'filefield_display') .'/players/';
    if (file_exists($path .'1pixelout.swf')) {
      $formatters['1pixelout'] = array(
        'label' => t('1 Pixel Out player'),
        'field types' => array('file', 'link'),
      );
      $formatters['1pixelout_plus'] = array(
        'label' => t('1 Pixel Out player plus download link'),
        'field types' => array('file'),
      );
    }
    if (file_exists($path .'button.swf')) {
      $formatters['button'] = array(
        'label' => t('Button player'),
        'field types' => array('file', 'link'),
      );
      $formatters['button_plus'] = array(
        'label' => t('Button player plus download link'),
        'field types' => array('file'),
      );

    }
  }
  return $formatters;
}

/**
 * Implementation of hook_field_formatter().
 */
function filefield_display_field_formatter($field, $item, $formatter) {
  global $base_url;

  switch ($field['type']) {
    case 'file':
      require_once(drupal_get_path('module', 'filefield') .'/field_file.inc');
      if (!isset($item['fid']) || empty($item['fid'])) {
        return '';
      }
      $file = _field_file_load($item['fid']);
      $file_url = check_url($base_url .'/'. $file['filepath']);
      $file_title = check_plain($file['description']);
      $attributes = array();
      $query = $fragment = NULL;
      break;
    case 'link':
      if (empty($item['url']) && ($field['url'] != 'optional' || empty($item['title']))) {
        return '';
      }

      $attributes = array();
      $item['attributes'] = unserialize($item['attributes']);
      // Add attributes defined at the widget level
      if (is_array($item['attributes'])) {
        foreach($item['attributes'] as $attribute => $attbvalue) {
          if (isset($item['attributes'][$attribute]) && $field['attributes'][$attribute] == 'user') {
            $attributes[$attribute] = $attbvalue;
          }
        }
      }
      // Add attributes defined at the field level
      if (is_array($field['attributes'])) {
        foreach($field['attributes'] as $attribute => $attbvalue) {
          if (!empty($attbvalue) && $attbvalue != 'default' && $attbvalue != 'user') {
            $attributes[$attribute] = $attbvalue;
          }
        }
      }

      // Replace URL tokens
      if (module_exists('token') && $field['enable_tokens']) {
        $item['url'] = token_replace($item['url'], 'node', $node);
      }

      $type = link_validate_url($item['url']);
      $file_url = $url = link_cleanup_url($item['url']);
      
      // Separate out the anchor if any
      if (strpos($url, '#') !== FALSE) {
        $fragment = substr($url, strpos($url, '#') + 1);
        $url = substr($url, 0, strpos($url, '#'));
      }
      // Separate out the query string if any
      if (strpos($url, '?') !== FALSE) {
        $query = substr($url, strpos($url, '?') + 1);
        $url = substr($url, 0, strpos($url, '?'));
      }

      // Build the title
      if (strlen(trim($item['title'])) || ($field['title'] == 'value' && strlen(trim($field['title_value'])))) {
        // Use the title defined at the field level
        if ($field['title'] == 'value' && strlen(trim($field['title_value']))) {
          $file_title = $field['title_value'];
        }
        // Use the title defined by the user at the widget level
        else {
          $file_title = $item['title'];
        }
        // Replace tokens
        if (module_exists('token') && ($field['title'] == 'value' || $field['enable_tokens'])) {
          $file_title = token_replace($file_title, 'node', $node);
        }

        $file_title = check_plain($file_title);
      }

      break;
  }

  switch ($formatter) {
    case '1pixelout':
    case 'button':
      $output = theme('filefield_display_'. $formatter, $file_title, $file_url, $item, $field);
      break;
    case '1pixelout_plus':
    case 'button_plus':
      $output = theme('filefield_display_'. substr($formatter, 0, strlen($formatter) - 5), $file_title, $file_url, $item, $field);
      $output .= l(t('Download'), $file_url, $attributes, $query, $fragment);
      break;
  }

  return $output;
}

/**
 * Theme a 1pixelout audio file.
 */
function theme_filefield_display_1pixelout($file_title, $file_url, $item, $field) {
  global $base_url;

  // Set the URL for the player.
  $url = $base_url . '/' . drupal_get_path('module', 'filefield_display') .
         '/players/1pixelout.swf';

  // Set some Flash variables.
  $options = array();
  $options['soundFile'] = $file_url;
  $flashvars = drupal_query_string_encode($options);

  // This is a fix for http://drupal.org/node/158687.
  $flashvars = str_replace('http%3A/%252F', 'http://', $flashvars);

$output = <<<EOT
<object type="application/x-shockwave-flash" data="$url" width="290" height="24">
  <param name="movie" value="$url" />
  <param name="wmode" value="transparent" />
  <param name="menu" value="false" />
  <param name="quality" value="high" />
  <param name="FlashVars" value="$flashvars" />
</object>
EOT;

  return $output;
}

/**
 * Theme a button audio file.
 */
function theme_filefield_display_button($file_title, $file_url, $item, $field) {
  global $base_url;

  $options = array();
  $options['song_url'] = $file_url;
  $options['song_title'] = check_plain($file_title);
  // str_replace() is to fix issue in Drupal 5.2.
  $url = $base_url .'/'. drupal_get_path('module', 'filefield_display') .'/players/button.swf?'. str_replace('http%3A/%252F', 'http://', drupal_query_string_encode($options));

$output = <<<EOT
<object type="application/x-shockwave-flash" data="$url" width="17" height="17">';
  <param name="movie" value="$url" />
  <param name="wmode" value="transparent" />
  <param name="quality" value="high" />
</object>
EOT;

  return $output;
}

any wrong code with this?

Comments

vm’s picture

I don't believe what you are doing needs to be done you can use the swftools.module for 6.x and accomplish the same task.

Anonymous’s picture

actually i modify before... for suport drupal 5.

i got the modify version for support:
-audio & video node type.
-teaser view & full view. (the most important reason to me)
-full setting the jw player. (the most important reason to me)

but swftool just only can do a part of setting for jw player.

i very like the mediafield_display module.
i can change every setting via the code.

so i hope to get mediafield_display version 6.

that a mediafield_display modify version for support drupal 5:

<?php
// $Id: mediafield_display.module,v 1.2.2.6 2008/01/28 02:18:40 colan Exp $

/**
 * @file
 * Provides display handlers for audio & video fields.
 *
 * When enabled, this module enables display alternatives for audio & video fields
 * provided by Media Field and link fields containing audio & video files. These
 * options are available in CCK field display administration and also in Views
 * field configuration.
 */

/**
 * Implementation of hook_field_formatter_info().
 */
function mediafield_display_field_formatter_info() {
  $formatters = array();
  if (module_exists('audiofield')) {
    $path = drupal_get_path('module', 'mediafield_display') .'/players/mediaplayer/';
    if (file_exists($path .'mediaplayer.swf')) {
      $formatters['audio_mediaplayer_teaser'] = array(
        'label' => t('player_teaser'),
        'field types' => array('file_audio', 'link'),
      );
      $formatters['audio_mediaplayer_teaser_plus'] = array(
        'label' => t('player_teaser + download'),
        'field types' => array('file_audio'),
      );
	  $formatters['audio_mediaplayer_full'] = array(
        'label' => t('player_full'),
        'field types' => array('file_audio', 'link'),
      );
      $formatters['audio_mediaplayer_full_plus'] = array(
        'label' => t('player_full + download'),
        'field types' => array('file_audio'),
      );
    }
  }
  if (module_exists('videofield')) {
    $path = drupal_get_path('module', 'mediafield_display') .'/players/mediaplayer/';
    if (file_exists($path .'mediaplayer.swf')) {
      $formatters['video_mediaplayer_teaser'] = array(
        'label' => t('player_teaser'),
        'field types' => array('file_video', 'link'),
      );
      $formatters['video_mediaplayer_teaser_plus'] = array(
        'label' => t('player_teaser + download'),
        'field types' => array('file_video'),
      );
	  $formatters['video_mediaplayer_full'] = array(
        'label' => t('player_full'),
        'field types' => array('file_video', 'link'),
      );
      $formatters['video_mediaplayer_full_plus'] = array(
        'label' => t('player_full + download'),
        'field types' => array('file_video'),
      );
    }
  }
  return $formatters;
}

/**
 * Implementation of hook_field_formatter().
 */
function mediafield_display_field_formatter($field, $item, $formatter) {
  global $base_url;

  switch ($field['type']) {
    case 'file_audio':
      require_once(drupal_get_path('module', 'audiofield') .'/multimediafile.inc');
      if (!isset($item['fid']) || empty($item['fid'])) {
        return '';
      }
      $file = _field_file_load($item['fid']);
      $file_url = check_url($base_url .'/'. $file['filepath']);
      $file_title = check_plain($file['description']);
      $attributes = array();
      $query = $fragment = NULL;
      break;
	case 'file_video':
      require_once(drupal_get_path('module', 'videofield') .'/multimediafile.inc');
      if (!isset($item['fid']) || empty($item['fid'])) {
        return '';
      }
      $file = _field_file_load($item['fid']);
      $file_url = check_url($base_url .'/'. $file['filepath']);
      $file_title = check_plain($file['description']);
      $attributes = array();
      $query = $fragment = NULL;
      break;
    case 'link':
      if (empty($item['url']) && ($field['url'] != 'optional' || empty($item['title']))) {
        return '';
      }

      $attributes = array();
      $item['attributes'] = unserialize($item['attributes']);
      // Add attributes defined at the widget level
      if (is_array($item['attributes'])) {
        foreach($item['attributes'] as $attribute => $attbvalue) {
          if (isset($item['attributes'][$attribute]) && $field['attributes'][$attribute] == 'user') {
            $attributes[$attribute] = $attbvalue;
          }
        }
      }
      // Add attributes defined at the field level
      if (is_array($field['attributes'])) {
        foreach($field['attributes'] as $attribute => $attbvalue) {
          if (!empty($attbvalue) && $attbvalue != 'default' && $attbvalue != 'user') {
            $attributes[$attribute] = $attbvalue;
          }
        }
      }

      // Replace URL tokens
      if (module_exists('token') && $field['enable_tokens']) {
        $item['url'] = token_replace($item['url'], 'node', $node);
      }

      $type = link_validate_url($item['url']);
      $file_url = $url = link_cleanup_url($item['url']);
      
      // Separate out the anchor if any
      if (strpos($url, '#') !== FALSE) {
        $fragment = substr($url, strpos($url, '#') + 1);
        $url = substr($url, 0, strpos($url, '#'));
      }
      // Separate out the query string if any
      if (strpos($url, '?') !== FALSE) {
        $query = substr($url, strpos($url, '?') + 1);
        $url = substr($url, 0, strpos($url, '?'));
      }

      // Build the title
      if (strlen(trim($item['title'])) || ($field['title'] == 'value' && strlen(trim($field['title_value'])))) {
        // Use the title defined at the field level
        if ($field['title'] == 'value' && strlen(trim($field['title_value']))) {
          $file_title = $field['title_value'];
        }
        // Use the title defined by the user at the widget level
        else {
          $file_title = $item['title'];
        }
        // Replace tokens
        if (module_exists('token') && ($field['title'] == 'value' || $field['enable_tokens'])) {
          $file_title = token_replace($file_title, 'node', $node);
        }

        $file_title = check_plain($file_title);
      }

      break;
  }

  switch ($formatter) {
    case 'audio_mediaplayer_teaser':
      $output = theme('mediafield_display_'. $formatter, $file_title, $file_url, $item, $field);
      break;
    case 'audio_mediaplayer_teaser_plus':
      $output = theme('mediafield_display_'. substr($formatter, 0, strlen($formatter) - 5), $file_title, $file_url, $item, $field);
      $output .= l(t('Download'), $file_url, $attributes, $query, $fragment);
      break;
	case 'audio_mediaplayer_full':
      $output = theme('mediafield_display_'. $formatter, $file_title, $file_url, $item, $field);
      break;
    case 'audio_mediaplayer_full_plus':
      $output = theme('mediafield_display_'. substr($formatter, 0, strlen($formatter) - 5), $file_title, $file_url, $item, $field);
      $output .= l(t('Download'), $file_url, $attributes, $query, $fragment);
      break;
	case 'video_mediaplayer_teaser':
      $output = theme('mediafield_display_'. $formatter, $file_title, $file_url, $item, $field);
      break;
    case 'video_mediaplayer_teaser_plus':
      $output = theme('mediafield_display_'. substr($formatter, 0, strlen($formatter) - 5), $file_title, $file_url, $item, $field);
      $output .= l(t('Download'), $file_url, $attributes, $query, $fragment);
      break;
	case 'video_mediaplayer_full':
      $output = theme('mediafield_display_'. $formatter, $file_title, $file_url, $item, $field);
      break;
    case 'video_mediaplayer_full_plus':
      $output = theme('mediafield_display_'. substr($formatter, 0, strlen($formatter) - 5), $file_title, $file_url, $item, $field);
      $output .= l(t('Download'), $file_url, $attributes, $query, $fragment);
      break;
  }
  return $output;
}

/**
 * Theme audio_mediaplayer_teaser
 */
function theme_mediafield_display_audio_mediaplayer_teaser($file_title, $file_url, $item, $field) {
  global $base_url;

  // Set the URL for the player.
  $url->player = $base_url . '/' . drupal_get_path('module', 'mediafield_display') . '/players/mediaplayer/mediaplayer.swf';
  $url->swfobject = $base_url . '/' . drupal_get_path('module', 'mediafield_display') . '/players/mediaplayer/swfobject.js';

  // Set some Flash variables.
  $options = array();
  $options['File'] = $file_url;
  $flashvars = drupal_query_string_encode($options);

  // This is a fix for http://drupal.org/node/158687.
  $flashvars = str_replace('http%3A/%252F', 'http://', $flashvars);
  $flashvars = str_replace('File=', '', $flashvars);

$output = <<<EOT
<script type="text/javascript" src="$url->swfobject"></script>

<div id="$flashvars"><a href="http://www.adobe.com/go/getflashplayer">Get the Flash Player</a> to play this object.</div>

<script type="text/javascript">
var so = new SWFObject('$url->player','mpl','200','20','8');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addVariable('height','20');
so.addVariable('width','200');
so.addVariable('file','$flashvars');
so.addVariable('backcolor','0x456bbb');
so.addVariable('frontcolor','0xffffff');
so.addVariable('lightcolor','0xD2DDF1');
so.addVariable('showicons','false');
so.addVariable('usefullscreen','false');
so.addVariable('showdownload','false');
so.write('$flashvars');
</script>
EOT;

  return $output;
}

/**
 * Theme audio_mediaplayer_full
 */
function theme_mediafield_display_audio_mediaplayer_full($file_title, $file_url, $item, $field) {
  global $base_url;

  // Set the URL for the player.
  $url->player = $base_url . '/' . drupal_get_path('module', 'mediafield_display') . '/players/mediaplayer/mediaplayer.swf';
  $url->logo = $base_url . '/' . drupal_get_path('module', 'mediafield_display') . '/players/mediaplayer/player-logo.png';
  $url->swfobject = $base_url . '/' . drupal_get_path('module', 'mediafield_display') . '/players/mediaplayer/swfobject.js';

  // Set some Flash variables.
  $options = array();
  $options['File'] = $file_url;
  $flashvars = drupal_query_string_encode($options);

  // This is a fix for http://drupal.org/node/158687.
  $flashvars = str_replace('http%3A/%252F', 'http://', $flashvars);
  $flashvars = str_replace('File=', '', $flashvars);

$output = <<<EOT
<script type="text/javascript" src="$url->swfobject"></script>

<div id="$flashvars"><a href="http://www.adobe.com/go/getflashplayer">Get the Flash Player</a> to play this object.</div>

<script type="text/javascript">
var so = new SWFObject('$url->player','mpl','300','65','8');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addVariable('height','65');
so.addVariable('width','300');
so.addVariable('file','$flashvars');
so.addVariable('showeq', 'true');
so.addVariable('backcolor','0x456bbb');
so.addVariable('frontcolor','0xffffff');
so.addVariable('lightcolor','0xD2DDF1');
so.addVariable('logo','$url->logo');
so.addVariable('displayheight','65');
so.addVariable('showicons','false');
so.addVariable('usefullscreen','false');
so.addVariable('showdownload','false');
so.write('$flashvars');
</script>
EOT;

  return $output;
}

/**
 * Theme video_mediaplayer_teaser
 */
function theme_mediafield_display_video_mediaplayer_teaser($file_title, $file_url, $item, $field) {
  global $base_url;

  // Set the URL for the player.
  $url->player = $base_url . '/' . drupal_get_path('module', 'mediafield_display') . '/players/mediaplayer/mediaplayer.swf';
  $url->swfobject = $base_url . '/' . drupal_get_path('module', 'mediafield_display') . '/players/mediaplayer/swfobject.js';

  // Set some Flash variables.
  $options = array();
  $options['File'] = $file_url;
  $flashvars = drupal_query_string_encode($options);

  // This is a fix for http://drupal.org/node/158687.
  $flashvars = str_replace('http%3A/%252F', 'http://', $flashvars);
  $flashvars = str_replace('File=', '', $flashvars);

$output = <<<EOT
<script type="text/javascript" src="$url->swfobject"></script>

<div id="$flashvars"><a href="http://www.adobe.com/go/getflashplayer">Get the Flash Player</a> to play this object.</div>

<script type="text/javascript">
var so = new SWFObject('$url->player','mpl','200','150','8');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addVariable('height','150');
so.addVariable('width','200');
so.addVariable('file','$flashvars');
so.addVariable('backcolor','0x456bbb');
so.addVariable('frontcolor','0xffffff');
so.addVariable('lightcolor','0xD2DDF1');
so.addVariable('displayheight','150');
so.addVariable('usefullscreen','false');
so.addVariable('showdownload','false');
so.write('$flashvars');
</script>
EOT;

  return $output;
}

/**
 * Theme video_mediaplayer_full
 */
function theme_mediafield_display_video_mediaplayer_full($file_title, $file_url, $item, $field) {
  global $base_url;

  // Set the URL for the player.
  $url->player = $base_url . '/' . drupal_get_path('module', 'mediafield_display') . '/players/mediaplayer/mediaplayer.swf';
  $url->logo = $base_url . '/' . drupal_get_path('module', 'mediafield_display') . '/players/mediaplayer/player-logo.png';
  $url->swfobject = $base_url . '/' . drupal_get_path('module', 'mediafield_display') . '/players/mediaplayer/swfobject.js';

  // Set some Flash variables.
  $options = array();
  $options['File'] = $file_url;
  $flashvars = drupal_query_string_encode($options);

  // This is a fix for http://drupal.org/node/158687.
  $flashvars = str_replace('http%3A/%252F', 'http://', $flashvars);
  $flashvars = str_replace('File=', '', $flashvars);

$output = <<<EOT
<script type="text/javascript" src="$url->swfobject"></script>

<div id="$flashvars"><a href="http://www.adobe.com/go/getflashplayer">Get the Flash Player</a> to play this object.</div>

<script type="text/javascript">
var so = new SWFObject('$url->player','mpl','480','360','8');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addVariable('height','360');
so.addVariable('width','480');
so.addVariable('file','$flashvars');
so.addVariable('backcolor','0x456bbb');
so.addVariable('frontcolor','0xffffff');
so.addVariable('lightcolor','0xD2DDF1');
so.addVariable('logo','$url->logo');
so.addVariable('displayheight','360');
so.addVariable('showdownload','false');
so.write('$flashvars');
</script>
EOT;

  return $output;
}