function swftools_generate_playlist in SWF Tools 6.2
Same name and namespace in other branches
- 5 swftools.module \swftools_generate_playlist()
- 6.3 swftools.module \swftools_generate_playlist()
- 6 swftools.module \swftools_generate_playlist()
Saves a playlist (xml file) to the playlist directory ready for the swf player to use.
Parameters
&$playlist_data: A formatted array of playlist data that will be converted to an xml file. NEED TO DOCUMENT THE STRUCTURE.
$playlist_name: An optional name for the playlist. If not specified a filename will be created.
$method: An array describing the selected player method.
&$vars: Array of variables. Not used by this function, but will be passed to the playlist generator functions.
Return value
A string containing the path to the playlist, or FALSE if the playlist generation failed. Note that $playlist_data and $vars can be manipulated by this function.
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 913
Code
function swftools_generate_playlist(&$playlist_data, $playlist_name, &$method, &$vars) {
// If no filename is supplied
if (!$playlist_name) {
// Initialise a string
$prename = '';
// Iterate through each element of $playlist_data['playlist']
foreach ($playlist_data['playlist'] as $data) {
// Build a string using all the filenames
$prename .= $data['filename'];
}
// Hash the resulting string of names and use as the filename
$playlist_name = md5($method->player['name'] . $prename) . '.xml';
}
// Turn the playlist name in to a full path
$playlist_name = swftools_get_playlist_path() . '/' . $playlist_name;
// If caching of xml playlist files has been disabled then delete the current playlist by this name
if (variable_get('swftools_playlist_caching', 'here') == 'always') {
file_delete($playlist_name);
}
elseif (is_file($playlist_name)) {
// Return path to the file
return file_create_url($playlist_name);
}
// Determine the name of the relevant hook to output the playlist in the appropriate format
$hook = $method->player['name'] . '_swftools_playlist';
// Check that the module implements this hook before trying to call it
if (module_hook($method->player['module'], $hook)) {
$playlist = module_invoke($method->player['module'], $hook, $playlist_data, $method, $vars);
}
else {
drupal_set_message(t('@title module does not support xml playlists.', array(
'@title' => $method->player['title'],
)), 'error');
}
// Try to open the playlist file ready to store the xml playlist
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;
}
// If the file was opened then try to write the playlist data to it
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;
}
// Close the file
fclose($handle);
// Return a url to the playlist
return file_create_url($playlist_name);
}