'swftools_flowplayer', 'title' => t('FlowPlayer'), 'download' => 'http://www.tucows.com/download.html?software_id=519713&t=2', 'width' => 320, 'height' => 263, 'library' => 'sites/all/libraries/' . $shared_file, ); // FlowPlayer support various actions with the same player and info. $methods['video']['flowplayer'] = $flowplayer; $methods['video_list']['flowplayer'] = $flowplayer; $methods['audio']['flowplayer'] = $flowplayer; $methods['audio_list']['flowplayer'] = $flowplayer; $methods['media_list']['flowplayer'] = $flowplayer; $methods['image_list']['flowplayer'] = $flowplayer; return $methods; } /** * Implementation of hook_menu(). */ function swftools_flowplayer_menu() { $items['admin/settings/swftools/flowplayer'] = array( 'title' => 'FlowPlayer', 'description' => 'Settings for '. l('FlowPlayer', 'http://www.tucows.com/download.html?software_id=519713&t=2') .'.', 'access arguments' => array('administer flash'), 'page callback' => 'drupal_get_form', 'page arguments' => array('swftools_flowplayer_admin_form'), 'file' => 'swftools_flowplayer.admin.inc', ); return $items; } /** * Implementation of hook_swftools_preprocess_[player](). */ function swftools_flowplayer_swftools_preprocess_flowplayer(&$data) { // Pad out the user parameters (like those passed through swf(), with our // configured defaults, allowing the user parameters to dominate. $defaults = _swftools_flowplayer_flashvars(); // Merge defaults and user supplied values, letting user supplied values dominate $data['flashvars'] = array_merge($defaults, $data['flashvars']); // If an image is set then use it if ($data['flashvars']['image']) { // Retrieve path data $source = swftools_get_url_and_path($data['flashvars']['image']); // If a path was returned then assign it to the flashvar if ($source) { $data['flashvars']['image'] = $source['fileurl']; } } // if ($vars->params['width']) {$flashvars['width'] = $vars->params['width'];} // if ($vars->params['height']) {$flashvars['height'] = $vars->params['height'];} /* FlowPlayer doesn't like "" when JSON is generated, so we have to construct it ourselves here * and assign it to the variable config. * Build an array of FlowPlayer configuration settings, then call drupal_to_js to convert * to JSON format, and then run through str_replac to make FlowPlayer happy! */ // Initialise array of FlowPlayer configuration settings $flowplayer = array(); // Are we handling a playlist? if ($data['othervars']['playlist_data']) { // Initialise array to hold data $playlist = array(); // Get file paths out of existing array and start to form FlowPlayer format foreach ($data['othervars']['playlist_data']['playlist'] as $play) { $playlist[] = "{ url: '".$play['fileurl']."' }"; } // Implode the array to create a flashvar ready for later $flowplayer['playList'] = '[ '. implode(', ', $playlist) .' ]'; } else { // If not a playlist simply assign file_url to videoFile $flowplayer['videoFile'] = $data['othervars']['file_url']; } // Find out what configuration settings are available $available_settings = swftools_flowplayer_swftools_variable_mapping(); // See which ones have been set in othervars and copy to flowplayer array foreach ($available_settings['flowplayer'] as $setting => $value) { if (isset($data['flashvars'][$setting])) { $flowplayer[$setting] = $data['flashvars'][$setting]; unset($data['flashvars'][$setting]); } } /** * FlowPlayer uses 'loop' as the parameter to control looping * This is already used as flash parameter so using loop in a * filter means it isn't passed in the flashvars array. So copy * whatever value we have in the parameter to flowplayer array */ if (isset($data['othervars']['loop']) && $data['othervars']['loop']) { $flowplayer['loop'] = $data['othervars']['loop']; } // Merge $data['othervars'] in to flashvars //$flowplayer = array_merge($flowplayer, $data['othervars']); // Convert to JSON $data['flashvars']['config'] = drupal_to_js($flowplayer); // Replace " with ', and remove quotes from around true and false, to satisfy FlowPlayer $data['flashvars']['config'] = str_replace(array('"', "'false'", "'true'", "'[", "]'"), array("'", "false", "true", "[", "]"), $data['flashvars']['config']); // If we had a playlist then the ' has been escaped, so reverse it where it occurs in the playlist if (isset($playlist) && $playlist) { $data['flashvars']['config'] = str_replace(array("url: \'", "\' }"), array("url: '", "' }"), $data['flashvars']['config']); } } /** * This function is called from flowplayer_swftools_flashvars() which is called from swf() * It will return the default flashvar configuration, just prior to any overrides * passed into swf(). We start with the settings defined on admin/swf/wijering * which are returned by _swftools_flowplayer_settings(). Then we prepare these values for output * to html (eg. '1' become 'true') and we unset undefined flashvars to prevent their output. * */ function _swftools_flowplayer_flashvars() { // Cache this static $flashvars = array(); // If defaults not already retrieved then fetch now if (!count($flashvars)) { // Get saved settings for this method. $defaults = _swftools_flowplayer_settings(); // Unset values defined as default, and set booleans properly foreach ($defaults AS $key => $value) { if (!$value || $value == 'default') { unset($defaults[$key]); } else if (in_array($key, array('usePlayOverlay', 'hideControls', 'showFullScreenButton', 'showPlayListButtons', 'autoPlay', 'loop'))) { $defaults[$key] = _swftools_tf($value); } } } // Returning resulting defaults return $defaults; } function swftools_flowplayer_swftools_playlist_flowplayer($data) { $xml = ' '. $xml_data['header']['title'] .' '; foreach ($data['othervars']['playlist_data']['playlist'] AS $track => $details) { if (!isset($details['background']) && strtolower(substr($details['fileurl'], -3, 3)) == 'mp3') { if ($data['flashvars']['image']) { $source = swftools_get_url_and_path($data['flashvars']['image']); $details['background'] = "". $source['fileurl'] ."\n";; } else { //$details['background'] = url(drupal_get_path('module', 'swftools') . '/' . SWFTOOLS_DEFAULT_BG, array('absolute' => TRUE)); $details['background'] = ''; } } $xml .= "\n"; $xml .= "". $details['title'] ."\n"; $xml .= "\n"; $xml .= "". $details['fileurl'] ."\n"; $xml .= $details['background']; $xml .= "". $details['fileurl'] ."\n"; $xml .= "\n"; } $xml .= ' '; return $xml; } /* * Implementation of hook_swftools_variable_mapping. * We don't map anything to flashvars, but we want to know what * settings are available * */ function swftools_flowplayer_swftools_variable_mapping() { return array( 'flowplayer' => array( 'videoFile' => 'flashvars', 'autoPlay' => 'flashvars', 'initialVolumePercentage' => 'flashvars', 'usePlayOverlay' => 'flashvars', 'controlBarGloss' => 'flashvars', 'hideControls' => 'flashvars', 'loop' => 'flashvars', 'fullscreen' => 'flashvars', 'showFullScreenButton' => 'flashvars', 'showPlayListButtons' => 'flashvars', ), ); } /** * These are the default settings as they are stored in the database and displayed * on the settings page. */ function _swftools_flowplayer_settings() { // Define the settings list. $defaults = array( 'player' => 'flowplayer/FlowPlayerClassic.swf', 'usePlayOverlay' => 'default', 'hideControls' => 'default', 'controlBarGloss' => 'default', 'showFullScreenButton' => 'default', 'showPlayListButtons' => 'default', 'autoPlay' => 'default', 'loop' => 'default', 'initialVolumePercentage' => '', ); // Retrieve settings from database, if available $saved_settings = variable_get('swftools_flowplayer', $defaults); // Return resulting defaults return $saved_settings; } /** * Implementation of hook_help */ function swftools_flowplayer_help($path, $arg) { switch ($path) { case 'admin/settings/swftools/flowplayer': return '

'.t('These are the settings for the FlowPlayer media player. For details of what each parameter does refer to the FlowPlayer documentation. It is possible that you do not need to change any of these settings and blank values will defer to friendly defaults. Note that the label in (brackets) is the configuration setting name and corresponds to the documentation page. If content is embedded using the SWF Tools filter then each parameter can be over-ridden by specifying a new value in the filter string.', array('@flowplayer' => 'http://flowplayer.org/v2/player/index.html')).'

'; } }