It would be great if this module included an API for other modules to leverage the swfobject library so that there isn't code duplication. You could implement this into your blocks pretty easily. Here's how I did it in a module I pulled together:

/**
 * generate javasript code 
 * @$url is a web accessible address
 * @$params is an array of parameters to build the html
 */
function swfobject_create($url, $params = null, $load_js = true) {
  
  static $swf_loaded;
  
  if (!($load_js)) {
  	
    if ( !(file_exists(drupal_get_path('module','swfobject') . "/swfobject.js")) ) {
      // display error if javascript isn't present
      drupal_set_message(t("You need to download the swfobject.js file and place it in the swfobject module directory. Please see the README.txt"), 'error');
      $swf_loaded = false;
    } else {
      drupal_add_js(drupal_get_path('module','swfobject') . "/swfobject.js");   
      $swf_loaded = true;      
    }     
  }

  $width = $params['width'] ? $params['width'] : "100%" ;
  $height = $params['height'] ? $params['height'] : "100%" ;
  $message = $params['no_flash'] ? $params['no_flash'] : t('Sorry, you need to install flash to see this content.');
  
  $name = str_replace(".swf", "", basename($url));
  
  $html  = "<div id='flashcontent_". $name . "'>$message</div>\n";
  $html .= "<script>var so = new SWFObject('". $url . "', 'movie', '". $width ."','" . $height ."','" . $name . "'); \n"; 
  
  if ($params) {
    foreach ($params as $key => $value) {
      if (($key != "width") && ($key != "height") && ($key != "no_flash")) {
        $html .= " so.addParam('$key', '$value'); \n";
      }
    }
  }
  $html .= " so.write('flashcontent_". $name . "'); \n</script>";

 return $html;
}

Then developers can call it with:

$params = array('width' => '100', 'height' => '200', 'no_flash' => 'Sorry, you need flash installed to view this content');
print swfobject_create($url, $params);

Comments

zroger’s picture

This seems like a good idea. I am pretty busy at work so it may take a little while to get this in.

Thanks

arthurf’s picture

I've added my swfobject_api module to cvs. I think it would make sense to merge these modules. I'd be willing to do the work to integrate them if you'd like. I've also talked with Geoff (creator of swfobject) and he is going to dual license swfobject so that it can be included in the drupal repo.

zroger’s picture

I am currently working on a 5.0 release for swfobject that will include more ways to use swfobject. I am planning on implementing:

  • A node type, for easy creation of a single page for displaying a movie like a photo gallery or splash page
  • An input filter much like the img_assist filter
  • Possibly a way to attach a movie to a node like upload.module
  • As well as a simplified theme function so any module/theme can make a call like
      print theme('swfobject','file.swf', $options);
    

All of these features will also be backported to the 4.7 branch.

arthurf’s picture

sounds great. anything i can do to help you in this process? I'd be glad to help out if you'd like.

arthurf’s picture

I've done a 5.0 port of the swfobject_api module which implements:

   $url = "myflashfile.swf"; //path to flash file
   $params = array('width' => 100, 'height' => 100 );
   print theme("swfobject_api", $url, $params); 

Which makes the theming easier. I'd be happy to port this to or integrate it with your module.

Zen’s picture

What is the status of the API functionality and the D5 port? @rz If you do not have the time to maintain this module, please commit any work you've done to HEAD and let arthurf assume co-maintainership, if he is still interested.

Thanks,
-K