'); // I don't know what the best delimiter is. Needs to be used in js split(). define('FLASHEMBED_DEBUG', FALSE); /* * TODO * * 1. Generate XML to be passed to any of the players (they all support it). * */ /** * Load the required jQuery. */ function flashembed_init() { $path = drupal_get_path('module', 'flashembed'); // module_invoke('jstools', 'add_js', $path . '/tools/jquery.flash.js'); drupal_add_js($path .'/tools/jquery.flash.js', 'module'); flashembed_js_player(variable_get('embedflash_version', 8)); } /** * Generate the HTML element that will be displayed if the javascript is * not enabled, or Flash is not available. * * @param $filepath * The file to be displayed in the player (or a displayed swf file if $type = EMBED_SWF * @param $width * Flashplayer width * @param $width * Flashplayer width * @param $height * Flashplayer height * @param $mime * The file mime - required if $type is not passed. * @param $type * The desired Flash player type (FLASHEMBED_MP3, FLASHEMBED_FLV etc) * Required if $mime is not passed. * @param $params * Optional parameters * @param $preview * An image that will be displayed if the Flash cannot be embedded. * @param $name * Text that will be displayed as a link (pre-embedding) * */ function flashembed_content($filepath, $params = array(), $preview = NULL, $name = NULL, $type = NULL, $markup = NULL) { // We alway use absolute paths because flash embedding has issues with relative paths sometimes (I've found). global $base_url; if (!strstr($filepath, $base_url)) { $file_url = $base_url .'/'. $filepath; } $pathinfo = pathinfo($filepath); if ($type) { $swf = $type; // Force the player that is used. } else { // Determine the flashplayer based on mime; $swf = flashembed_swf_by_mime($pathinfo['extension']); } // Hack the mp3 player to a fixed height. if ($swf == FLASHEMBED_MP3 && !isset($params['height'])) { $params['height'] = 50; } if ($pathinfo['extension'] == 'swf') { // If the file to play is swf, then *it's* the player. $params['src'] = $file_url; } else { $params['src'] = $base_url .'/'. drupal_get_path('module', 'flashembed') .'/tools/'. $swf .'.swf'; } $flashvars['file'] = $file_url; $flashvars['autostart'] = 'false'; // Merge parameters with defaults. $params = flashembed_params($params); return theme('flashembed_content', $params, $flashvars, $name); } function theme_flashembed_content($params, $flashvars, $name = NULL, $preview = NULL, $markup = NULL) { // Build the Flash file parameter argument and assign it to the embedding parameters. $params['flashvars'] = flashembed_build_flashvars($flashvars); // Build the "rel" (for ) attribute. $rel = flashembed_build_params($params); // This is quite 'alpha'. $output = '
'; $output .= ''; if ($preview) { $output .= ''; } if ($name) { $output .= $name; } $output .= "
\n"; return $output; } /** * These are the default flash parameters. * */ function flashembed_params($params) { $defaults = array( 'src' => '', 'height' => 200, 'width' => 200, 'version' => 7, 'transparency' => variable_get('flashembed_transparency', 'false'), 'bgcolor' => variable_get('flashembed_background', '#000'), 'flashvars' => 'autostart=false', ); return array_merge($defaults, $params); } /** * This is the paramater string which will be in the rel attribute of the link. * On page ready, the header jQuery will use this to pass parameters to the * embedded flash markup (whatever you call it). * */ function flashembed_build_params($params) { // Get the order right, not sure about this but let's see. return $params['src'] . FLASHEMBED_REL_DELIM . $params['width'] . FLASHEMBED_REL_DELIM . $params['height'] . FLASHEMBED_REL_DELIM . $params['bgcolor'] . FLASHEMBED_REL_DELIM . $params['quality'] . FLASHEMBED_REL_DELIM . $params['flashvars']; } /** * "flashvars" is a parameter like height and width, which are actually * passed into the flash player. * */ function flashembed_build_flashvars($vars) { return 'file='. $vars['file'] .'&autostart='. $vars['autostart']; } /** * The jQuery code that will try to replace all elements after the page loads. * At the moment it only runs once (hook_init). * */ function flashembed_js_player($version) { // static $has_run; // if ($has_run) {return;} $js = " $(document).ready(function(){ $('.flashembed-player').flash(null, { version: ". $version ." }, function(htmlOptions) { var params = $(this).attr('rel').split('". FLASHEMBED_REL_DELIM ."'); htmlOptions.src = params[0]; htmlOptions.width = params[1]; htmlOptions.height = params[2]; htmlOptions.bgcolor = params[3]; htmlOptions.quality = params[4]; htmlOptions.flashvars = params[5]; this.innerHTML = '
'+this.innerHTML+'
'; ". ((FLASHEMBED_DEBUG) ? "alert($.fn.flash.transform(htmlOptions)); " : "") ." $(this).addClass('flash-replaced').prepend($.fn.flash.transform(htmlOptions)); }); }); "; drupal_add_js($js, 'inline', 'header'); // $has_run = true; } /** * Using the mime type, return the most appropriate flash player * */ function flashembed_swf_by_mime($mime, $file_name = NULL) { switch(strtolower($mime)) { case 'flv': case 'swf': return FLASHEMBED_FLV; case 'mp3': return FLASHEMBED_MP3; case 'gif': case 'png': case 'jpeg': case 'jpg': return FLASHEMBED_IMG; default: return FALSE; } } /** * Passed a node (with upload.module attachments), and returns an array of markup. * */ function flashembed_upload_render_all(&$node, $params = array()) { $embed_array = array(); foreach ($node->files AS $f => $file) { $embed_array[$f] = flashembed_upload_render($file, $params); } return theme(flashembed_upload_render_all, $embed_array); } function theme_flashembed_upload_render_all(&$embed_array) { return implode($embed_array); } /** * Passed a file object (upload.module format), and return markup. * */ function flashembed_upload_render(&$file, $params = array()) { $embed = flashembed_content($file->filepath, NULL, $file->filename, NULL, NULL, NULL); return theme(flashembed_upload_render, $embed); } function theme_flashembed_upload_render(&$embed) { return $embed; }