[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/audiofield/ -> audiofield.module (source)

   1  <?php
   2  /**
   3   * Implementation of hook_init().
   4   *
   5   * Load required includes.
   6   */
   7  function audiofield_init() {
   8    module_load_include('inc', 'audiofield', 'audiofield_widget');
   9  }
  10  /**
  11   * Implementation of hook_menu().
  12   */
  13  function audiofield_menu() {
  14    
  15    $items['admin/settings/audiofield'] = array(
  16      'title' => 'Audio Field',
  17      'description' => 'Configure Audiofield.',
  18      'page callback' => 'drupal_get_form',
  19      'page arguments' => array('audiofield_admin_settings_form'),
  20      'access arguments' => array('administer site configuration'),
  21      'type' => MENU_NORMAL_ITEM,
  22    );
  23        return $items;
  24  }
  25  
  26  /**
  27   * Implementation of hook_perm().
  28   */
  29   function audiofield_perm() {
  30    return array('download own audio files' , 'download all audio files');
  31  }
  32  
  33  /**
  34   * Implementation of hook_filefield_sources_widgets().
  35   *
  36   * This returns a list of widgets that are compatible with FileField Sources.
  37   */
  38  function audiofield_filefield_sources_widgets() {
  39    return array('audiofield_widget');
  40  }
  41  
  42  function audiofield_admin_settings_form() {
  43    global $base_path;
  44    global $base_url;
  45  
  46    $audio_players=audiofield_players();
  47    $players=array();
  48    foreach ($audio_players as $id => $player) {
  49      if (file_exists($player['path'])) {
  50        foreach ($player['filetypes'] as $filetype) {
  51          $players[$filetype][$id] = $player['name'] . '<br/>' . call_user_func($player['callback'], $base_path . $player['path'] , "");
  52        }
  53      }
  54      else{
  55        $download_players .= '<li>Download ' . l($player['name'], $player['download_link']) . '</li>';
  56      }
  57    }
  58    //MP3 Players list
  59    if (!empty($players)) {
  60      $form['audiofield_audioplayer'] = array(
  61        '#type' => 'radios',
  62        '#title' => t('MP3 Audio Players'),
  63        '#options' => $players['mp3'],
  64        '#default_value' => variable_get('audiofield_audioplayer', 0),
  65     );
  66    }
  67    unset($players['mp3']);
  68  
  69    //Other players list (wav, wma,...)
  70    foreach ($players as $filetype => $type_player) {
  71      $form['audiofield_audioplayer_' . $filetype] = array(
  72        '#type' => 'radios',
  73        '#title' => $filetype . t(' Audio Players'),
  74        '#options' => $type_player,
  75        '#default_value' => variable_get('audiofield_audioplayer_' . $filetype, 0),
  76      );
  77     }
  78  
  79    $form['audiofield_players_dir'] = array(
  80      '#type' => 'textfield',
  81      '#title' => t('Audio Players Directory'),
  82      '#description' => t('Download and extract audio players in this directory'),
  83      '#default_value' => variable_get('audiofield_players_dir', 'sites/all/libraries/player'),
  84    );
  85  
  86    if (!empty($download_players)) {
  87      $form['audiofield_downloadaudioplayer'] = array(
  88        '#type' => 'item',
  89        '#title' => t('Download and install audio players'),
  90        '#value' => '<ul class="audiofield-download-players">' . $download_players . '</ul>',
  91      );
  92    }
  93  
  94    return system_settings_form($form);
  95  }
  96  
  97  
  98  /**
  99   * Implementation of hook_elements().
 100   */
 101  function audiofield_elements() {
 102    $elements = array();
 103    $filefield_elements = filefield_elements();
 104    $elements['audiofield_widget'] = $filefield_elements['filefield_widget'];
 105  
 106    $elements['audiofield_widget']['#value_callback'] = 'audiofield_widget_value';
 107    return $elements;
 108  }
 109  
 110  /**
 111   * Implementation of hook_theme().
 112   */
 113  function audiofield_theme() {
 114    $theme= array(
 115        'audiofield_widget' => array(
 116        'arguments' => array('element' => NULL),
 117        'file' => 'audiofield_widget.inc',
 118        ),
 119        // Themes for the formatters.
 120        'audiofield_formatter_audiofield_embedded' => array(
 121        'arguments' => array('element' => NULL),
 122        'file' => 'audiofield_formatter.inc',
 123        ),
 124        // Themes for the players.
 125        'audiofield_players_wpaudioplayer' => array(
 126          'arguments' => array('player_path'=> NULL, 'audio_file' => NULL),
 127        ),
 128        'audiofield_players_xspf_slim' => array(
 129          'arguments' => array('player_path'=> NULL, 'audio_file' => NULL),
 130        ),
 131        'audiofield_players_premium_beat_single_track' => array(
 132          'arguments' => array('player_path'=> NULL, 'audio_file' => NULL),
 133        ),
 134        'audiofield_players_premium_beat_thin' => array(
 135          'arguments' => array('player_path'=> NULL, 'audio_file' => NULL),
 136        ),
 137        'audiofield_players_premium_beat_mini' => array(
 138          'arguments' => array('player_path'=> NULL, 'audio_file' => NULL),
 139        ),
 140    );
 141  
 142    return $theme;
 143  }
 144  
 145  function audiofield_widget_info() {
 146    return array(
 147      'audiofield_widget' => array(
 148        'label' => t('Audio Upload'),
 149        'field types' => array('filefield'),
 150        'multiple values' => CONTENT_HANDLE_CORE,
 151        'callbacks' => array('default value' => CONTENT_CALLBACK_CUSTOM),
 152        'description' => t('Widget for uploading audios.'),
 153      ),
 154    );
 155  }
 156  
 157  /**
 158   * Implementation of CCK's hook_widget_settings().
 159   */
 160  function audiofield_widget_settings($op, $widget) {
 161    switch ($op) {
 162      case 'form':
 163        return audiofield_widget_settings_form($widget);
 164      case 'save':
 165        return audiofield_widget_settings_save($widget);
 166    }
 167  }
 168  
 169  /**
 170   * Implementation of CCK's hook_widget().
 171   * 
 172   * Assign default properties to item and delegate to audiofield.
 173   */
 174  function audiofield_widget(&$form, &$form_state, $field, $items, $delta = 0) {
 175    // Start with the audiofield widget as a basic start.
 176    // Note that audiofield needs to modify $form by reference.
 177    $element = filefield_widget($form, $form_state, $field, $items, $delta);
 178  
 179    return $element;
 180  }
 181  
 182  
 183  //==========================================//
 184  // DEFINING A FORMATTER
 185  //==========================================//
 186  
 187  
 188  /**
 189   * Implementation of hook_field_formatter_info().
 190   *   
 191   * All fields should have a 'default' formatter.
 192   * Any number of other formatters can be defined as well.
 193   * It's nice for there always to be a 'plain' option
 194   * for the raw value, but that is not required.
 195   * 
 196   */
 197  function audiofield_field_formatter_info() {
 198    $formatters = array(
 199      'audiofield_embedded' => array(
 200        'label' => t('Audio'),
 201        'field types' => array('filefield'),
 202        'description' => t('Displays audio embedded in a web page.'),
 203      ),
 204    );
 205  
 206    return $formatters;
 207  }
 208  
 209  
 210  /**
 211   * Implementation of CCK's hook_default_value().
 212   */
 213  function audiofield_default_value(&$form, &$form_state, $field, $delta) {
 214    return filefield_default_value($form, $form_state, $field, $delta);
 215  }
 216  
 217  /**
 218   * Implementation of hook_form_[form_id]_alter().
 219   *
 220   * Modify the add new field form to change the default formatter.
 221   */
 222  function audiofield_form_content_field_overview_form_alter(&$form, &$form_state) {
 223    $form['#submit'][] = 'audiofield_form_content_field_overview_submit';
 224  }
 225  
 226  /**
 227   * Submit handler to set a new field's formatter to "audiofield_embedded".
 228   */
 229  function audiofield_form_content_field_overview_submit(&$form, &$form_state) {
 230    if (isset($form_state['fields_added']['_add_new_field']) && isset($form['#type_name'])) {
 231      $new_field = $form_state['fields_added']['_add_new_field'];
 232      $node_type = $form['#type_name'];
 233      $field = content_fields($new_field, $node_type);
 234      if ($field['widget']['module'] == 'audiofield') {
 235        foreach ($field['display_settings'] as $display_type => $display_settings) {
 236          if ($field['display_settings'][$display_type]['format'] == 'default') {
 237            $field['display_settings'][$display_type]['format'] = 'audiofield_embedded';
 238          }
 239        }
 240        content_field_instance_update($field);
 241      }
 242    }
 243  }
 244  
 245  /**
 246   * Get the object for the suitable player for the parameter resource
 247  */
 248  function audiofield_get_player($audio_url, $op) {
 249     global $base_path;
 250    
 251     $audio_players=audiofield_players();
 252     $variable_name = 'audiofield_audioplayer' . ($op == 'mp3' ? '' : "_$op");
 253     $player = $audio_players[variable_get($variable_name, '')];
 254     if (empty($player)) {
 255       return audiofield_embeddedplayer($audio_url);
 256     }
 257      return call_user_func($player['callback'], $base_path . $player['path'], $audio_url);
 258  }
 259  
 260  /**
 261   * Implementation of hook_audiofield_players().
 262   */
 263  function audiofield_players() {
 264    $players=module_invoke_all('audiofield_players');
 265      
 266      $players['wpaudioplayer']=array(
 267          'path' => variable_get('audiofield_players_dir', 'sites/all/libraries/player') . "/audio-player/player.swf",
 268          'name' => 'WordPress Audio Player',
 269          'download_link' => 'http://wpaudioplayer.com/download',
 270          'filetypes' => array('mp3'),
 271          'callback' => 'audiofield_wpaudioplayer',
 272      );
 273      
 274      $players['xspf_slim']=array(
 275          'path' => variable_get('audiofield_players_dir', 'sites/all/libraries/player') . "/xspf_player_slim.swf",
 276          'name' => 'XSPF Slim Player',
 277          'download_link' => 'http://sourceforge.net/projects/musicplayer/files/musicplayer/slim-player-0.2.3b/xspf_player_slim-correct-0.2.3.zip/download',
 278          'filetypes' => array('mp3'),
 279          'callback' => 'audiofield_xspf_slim',
 280      );
 281      
 282      $players['premium_beat_single_track']=array(
 283          'path' => variable_get('audiofield_players_dir', 'sites/all/libraries/player') . "/playerSinglePackage/playerSingle.swf",
 284          'name' => 'Premium Beat Single Player',
 285          'download_link' => 'http://www.premiumbeat.com/flash_resources/free_flash_music_player/single_track_flash_mp3_player.php',
 286          'filetypes' => array('mp3'),
 287          'callback' => 'audiofield_premium_beat_single_track',
 288      );
 289      
 290      $players['premium_beat_thin']=array(
 291          'path' => variable_get('audiofield_players_dir', 'sites/all/libraries/player') . "/OriginalThinMusicPlayer.swf",
 292          'name' => 'Premium Beat Thin Player',
 293          'download_link' => 'http://www.premiumbeat.com/flash_music_players/original/thin/',
 294          'filetypes' => array('mp3'),
 295          'callback' => 'audiofield_premium_beat_thin',
 296      );
 297      
 298      $players['premium_beat_mini']=array(
 299          'path' => variable_get('audiofield_players_dir', 'sites/all/libraries/player') . "/LWMusicPlayer.swf",
 300          'name' => 'Premium Beat Mini Player',
 301          'download_link' => 'http://www.premiumbeat.com/flash_music_players/original/mini/',
 302          'filetypes' => array('mp3'),
 303          'callback' => 'audiofield_premium_beat_mini',
 304      );
 305      
 306      if (module_exists('flowplayer')) {
 307          $players['flowplayer']=array(
 308              'path' => drupal_get_path('module', 'flowplayer') . '/flowplayer/flowplayer.swf',
 309              'name' => 'Flowplayer',
 310              'download_link' => 'http://drupal.org/project/flowplayer',
 311              'filetypes' => array('mp3'),
 312              'callback' => 'audiofield_flowplayer',
 313          );
 314      }
 315  
 316      return $players;
 317  }
 318  
 319  /* Audio Callback Functions */
 320  
 321  function audiofield_embeddedplayer($audio_file) {
 322    return '<embed height="15" src="' . $audio_file . '" autostart="false"></embed>';
 323  }
 324  function audiofield_wpaudioplayer($player_path, $audio_file) {
 325    return theme('audiofield_players_wpaudioplayer',$player_path, $audio_file);
 326  }
 327  
 328  function theme_audiofield_players_wpaudioplayer($player_path, $audio_file){
 329    return '<object id="audioplayer2" height="24" width="290" data="' . $player_path . '" type="application/x-shockwave-flash">
 330                            <param value="' . $player_path . '" name="movie"/>
 331                            <param value="playerID=2&amp;bg=0xCDDFF3&amp;leftbg=0x357DCE&amp;lefticon=0xF2F2F2&amp;rightbg=0xF06A51&amp;rightbghover=0xAF2910&amp;righticon=0xF2F2F2&amp;righticonhover=0xFFFFFF&amp;text=0x357DCE&amp;slider=0x357DCE&amp;track=0xFFFFFF&amp;border=0xFFFFFF&amp;loader=0xAF2910&amp;soundFile=' . $audio_file . '" name="FlashVars"/>
 332                            <param value="high" name="quality"/>
 333                            <param value="false" name="menu"/>
 334                            <param value="wmode" name="transparent"/>
 335                            </object>';
 336  }
 337  
 338  function audiofield_xspf_slim($player_path, $audio_file) {
 339    return theme('audiofield_players_xspf_slim',$player_path, $audio_file);
 340  }
 341  function theme_audiofield_players_xspf_slim($player_path, $audio_file){
 342    return '<object type="application/x-shockwave-flash" width="175" height="14"
 343            data="' . $player_path . '?song_url=' . $audio_file . '">
 344            <param name="movie" value="' . $player_path . '?song_url=' . $audio_file .'" />
 345            </object>';
 346  }
 347  
 348  function audiofield_premium_beat_single_track($player_path, $audio_file) {
 349    return theme('audiofield_players_premium_beat_single_track',$player_path, $audio_file);
 350  }
 351  function theme_audiofield_players_premium_beat_single_track($player_path, $audio_file){
 352    return '<object><param name="autoplay" value="true" />
 353            <param name="controller"value="true" /> 
 354            <embed src="' . $player_path . '"  width="192" height="80" float="left" wmode="transparent" flashvars="mediaPath=' . $audio_file .'"    
 355            autostart="true" loop="false"  controller="true" bgcolor="#FF9900" pluginspage="http://www.macromedia.com/go/getflashplayer" >
 356            </embed></object>';
 357  }
 358  
 359  function audiofield_premium_beat_thin($player_path, $audio_file) {
 360    return theme('audiofield_players_premium_beat_thin',$player_path, $audio_file);
 361  }
 362  function theme_audiofield_players_premium_beat_thin($player_path, $audio_file){
 363    return '<object><param name="autoplay" value="true" />
 364          <param name="controller"value="true" /> 
 365          <embed src="' . $player_path . '"  width="220" height="21" float="left" wmode="transparent" flashvars="mediaPath=' . $audio_file .'&defaultVolume=100" autostart="true" loop="false"  controller="true" bgcolor="#FF9900" pluginspage="http://www.macromedia.com/go/getflashplayer" >
 366          </embed></object>';
 367  }
 368  
 369  function audiofield_premium_beat_mini($player_path, $audio_file) {
 370    return theme('audiofield_players_premium_beat_mini',$player_path, $audio_file);
 371  }
 372  function theme_audiofield_players_premium_beat_mini($player_path, $audio_file){
 373    return '<object><param name="autoplay" value="true" />
 374          <param name="controller"value="true" /> 
 375          <embed src="' . $player_path . '"  width="65" height="21" float="left" wmode="transparent" flashvars="mediaPath=' . $audio_file .'&defaultVolume=100" autostart="true" loop="false"  controller="true" bgcolor="#FF9900" pluginspage="http://www.macromedia.com/go/getflashplayer" >
 376          </embed></object>';
 377  }
 378  
 379  if (module_exists('flowplayer')) {
 380  function audiofield_flowplayer($player_path, $audio_file) {
 381    return theme('flowplayer', $audio_file, 'audiofield', array('style' => 'height: 24px',));
 382  }
 383  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7