[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/swftools/swfobject2/ -> swfobject2.module (source)

   1  <?php
   2  // $Id: swfobject2.module,v 1.4.2.1 2009/04/21 22:01:11 stuartgreenfield Exp $
   3  
   4  /**
   5   * SWF Tools - SWFObject2
   6   *
   7   * Enables the use of swfobject.js which provides image replacement
   8   * for Flash content. swfobject.js must be downloaded separately. (Add
   9   * the contents of the zip file to swftools/shared/swfobject2)
  10   * This module produces standards compliant mark that will pass W3C
  11   * validation
  12   *
  13   */
  14  
  15  function swfobject2_swftools_methods() {
  16    $methods = array();
  17    $methods[SWFTOOLS_EMBED_METHOD]['swfobject2_replace'] = array(
  18      'name'        => 'swfobject2_replace',
  19      'module'      => 'swfobject2',
  20      'shared_file' => 'swfobject2/swfobject.js',
  21      'title'       => t('SWFObject 2 - JavaScript'),
  22      'download'    => 'http://code.google.com/p/swfobject/',
  23    );
  24    return $methods;
  25  }
  26  
  27  /**
  28   * Implementation of swftools_embed hook
  29   * Returns the markup for the page, plus set necessary javascript.
  30   *
  31   * $methods and $vars should never be empty - unless the only reason for this call
  32   * is to push the javascript into the header of the page in which case you don't
  33   * add any paramters as all. This is useful for filtered nodes where the body is
  34   * not regenerated every time.
  35   */
  36  function swfobject2_swftools_embed($action = 'add_js', $methods = FALSE, $vars = FALSE, $html_alt = '') {
  37  
  38    // Set flag to indicate if the javascript has been added to the header
  39    static $swfobject2_has_run;
  40  
  41    // Output javascript to the header to load the SWF Object code
  42    if (!$swfobject2_has_run) {
  43      // Add swfobject.js
  44      drupal_add_js(swftools_get_player_path() . '/swfobject2/swfobject.js');
  45      $swfobject2_has_run = TRUE;
  46      if ($action == 'add_js') {
  47        // Exit early having put the javascript in the header.
  48        return;
  49      }
  50    }
  51  
  52    // Initialise a counter to give each div a unique id
  53    static $unique_id = 0;
  54    $unique_id++;
  55  
  56    // Construct a unique id for each div by using time() combined with $unique_id
  57    // This is necessary to prevent clashes between cached content
  58    $id = time() . $unique_id;
  59    
  60    // Anything in $vars->params will be output - we don't want src_path
  61    unset($vars->params['src_path']);
  62  
  63    // Unset flashvars string - we can use the array format and let drupal_to_js handle things
  64    unset($vars->params['flashvars']);
  65    
  66    // See if we should make the player accessible
  67    $accessible_html = swfobject2_wijering4_accessible($methods->player['name'], $vars, 'swf'.$id);
  68   
  69    // Generate js string ready for output to the page header
  70    // swfObject takes parameters swfURL, id, width, height, version, expressinstall, flashvars, params, attributes
  71    // At the moment expressInstall isn't enabled
  72    $swf_js = t('swfobject.embedSWF("!url", "!id", "!width", "!height", "!version", "", !flashvars, !params, !attributes);', array(
  73      '!url' => $vars->params['src'],
  74      '!id' => 'swfobject2-id-'. $id,
  75      '!width' => $vars->params['width'],
  76      '!height' => $vars->params['height'],
  77      '!version' => $vars->params['version'],
  78      '!flashvars' => drupal_to_js($vars->flashvars),
  79      '!params' => drupal_to_js($vars->params),
  80      '!attributes' => drupal_to_js(array('id' => 'swf'.$id)),
  81    ));
  82    
  83    // Generate the html markup ready to receive the substitution
  84    $html  = '<div id="swfobject2-id-'. $id .'" class="swftools swfobject2">' . "\n";
  85    $html .= $html_alt . "\n";
  86    $html .= '</div>' . "\n";
  87  
  88    // Although SWF Object 2 recommends adding js to the page header that will prevent cached filters being used
  89    // So we add js to the page body in order that it gets cached too
  90    $html .= '<script type="text/javascript">' . "\n";
  91    $html .= $swf_js . "\n";
  92    $html .= '</script>'  . "\n";
  93    $html .= $accessible_html;
  94  
  95    // Return html markup
  96    return $html;
  97  }
  98  
  99  
 100  /**
 101   * Determine if accessible links should be added below the Wijering player.
 102   * 
 103   * @param $player
 104   *   The name of the player being rendered.
 105   * @param $vars
 106   *   The array of variables being processed.
 107   * @param $id
 108   *   The id for the object being added.
 109   * @return
 110   *   An empty string, or markup containing the accessible links.
 111   */
 112  function swfobject2_wijering4_accessible($player, &$vars, $id) {
 113  
 114    // If not wijering4_mediaplayer then just return
 115    if ($player != 'wijering4_mediaplayer') {
 116      return '';
 117    }  
 118  
 119    // Call wijering4 to get accessible result
 120    return wijering4_accessible($vars, $id);
 121    
 122  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7