You are here

function swftools_generate_playlist in SWF Tools 6

Same name and namespace in other branches
  1. 5 swftools.module \swftools_generate_playlist()
  2. 6.3 swftools.module \swftools_generate_playlist()
  3. 6.2 swftools.module \swftools_generate_playlist()

Saves a playlist/xml file to a directory ready for the browser callback. Data must be formatted correctly, see docs (link to come) Returns a fully qualified url to the playlist file

1 call to swftools_generate_playlist()
swf in ./swftools.module
Return output, which might be embed markup, or pre-flash markup that includes the appropriate jQuery added to the <head>

File

./swftools.module, line 751

Code

function swftools_generate_playlist(&$playlist_data, $playlist_name, &$method, &$vars) {

  // It pays to pass your own filename, if possible, to avoid too much md5 hashing.
  if (!$playlist_name) {
    $prename = '';
    foreach ($playlist_data['playlist'] as $data) {
      $prename .= $data['filename'];
    }
    $playlist_name = md5($method->player['name'] . $prename) . '.xml';
  }
  $playlist_name = swftools_get_playlist_path() . "/{$playlist_name}";
  if (variable_get('swftools_playlist_caching', 'here') == 'always') {

    // Settings dictate we should always overwrite the playlist.
    file_delete($playlist_name);
  }
  elseif (is_file($playlist_name)) {

    // Return a fully qualified url to the playlist
    return file_create_url($playlist_name);
  }

  // Get the playlist/xml formatted to the player's taste.
  $func = 'swftools_' . $method->player['name'] . '_playlist';
  if (function_exists($func)) {
    $playlist = call_user_func($func, $playlist_data, $method, $vars);
  }
  else {
    drupal_set_message(t('@title module does not support xml playlists.', array(
      '@title' => $method->player['title'],
    )), 'error');
  }

  // Open file.
  if (!($handle = fopen($playlist_name, 'a'))) {
    drupal_set_message(t('An error occurred trying to create file %playlist_name.', array(
      '%playlist_name' => $playlist_name,
    )), 'error');
    return FALSE;
  }

  // And write to the file.
  if (fwrite($handle, $playlist) === FALSE) {
    drupal_set_message(t('An error occurred trying to create file %playlist_name.', array(
      '%playlist_name' => $playlist_name,
    )), 'error');
    return FALSE;
  }
  fclose($handle);

  // Return a fully qualified url to the playlist
  return file_create_url($playlist_name);
}