<?php
// $Id$

/**
 *  Implementation of hook_mapi_presenters()
 */
function mapi_onepixelout_mapi_presenters($op, $presenter, $filename, $data) {
  $presenter = drupal_get_path('module', 'mapi_onepixelout') .'/player.swf';
  
  switch ($op) {
    // list of presenters that the module can handle
    case 'list':
      // presenter must exist before it can be turned "on"
      if (is_file($presenter)) {
        return array('onepixelout');
      }
      break;
      
    // list of the extensions available for this presenter.
    case 'extensions':
      return array('mp3');
      
    // 
    case 'configure':
      break;
    
    // 
    case 'validate':
      break;
    
    // 
    case 'save':
      break;
    
    // This displays the presenter utilizing the data
    case 'display':
      // only display the presenter
      if (!is_file($presenter)) {
        return;
      }
      
      $variables = array('backcolor');

      $height = (!empty($data['height']) ? $data['height'] : 20);
      $width  = (!empty($data['width']) ? $data['width'] : 250);

      $base_url = url('', null, null, true);

      $filename = $base_url . $filename;
      $link = $base_url . $presenter;
      $flashvar = 'soundfile='. $filename;
      foreach ($variables as $key) {
        if (isset($data[$key])) {
          $flashvar .= "&{$key}=". $data[$key];
        }
      }
      
      $general = array(
        'param' => array('movie' => $link, 'wmode' => 'opaque', 'flashvars' => $flashvar),
        'var' => array('type' => 'application/x-shockwave-flash'),
      );
      $microsoft = array(
        'param' => array('src' => $link, 'wmode' => 'opaque', 'flashvars' => $flashvar),
        'var' => array('classid' => 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'),
      );

      return mapi_render_object($link, $width, $height, $general, $microsoft);
      
    // This outputs a playlist the jw_player understands
    case 'playlist':
      break;
  }
}