You are here

function theme_asset_bonus_swfobject in Asset 5

Same name and namespace in other branches
  1. 5.2 contrib/asset_bonus/asset_bonus.module \theme_asset_bonus_swfobject()
  2. 6 asset_bonus/asset_bonus.module \theme_asset_bonus_swfobject()
  3. 6 contrib/asset_bonus/asset_bonus.module \theme_asset_bonus_swfobject()
1 theme call to theme_asset_bonus_swfobject()
asset_bonus_swfobject_preview in asset_bonus/asset_bonus.module

File

asset_bonus/asset_bonus.module, line 256

Code

function theme_asset_bonus_swfobject($asset, $options = array()) {
  $embed_id = 'embed-' . preg_replace('/[^A-Za-z_-]/', '-', substr($asset->filename, 0, strlen($asset->filename) - 4));
  $div_id = 'swfobject-' . preg_replace('/[^A-Za-z_-]/', '-', substr($asset->filename, 0, strlen($asset->filename) - 4));
  $embed_id = 'swfobject-object-' . $asset->aid;
  $div_id = 'swfobject-' . $asset->aid;
  $addVariable = '';
  $addParam = '';

  // build a list of addVariable statements for each flashVar
  foreach ((array) $options['vars'] as $k => $v) {
    $addVariable .= "oSwf.addVariable('{$k}', '{$v}');\n";
  }
  if ($asset->extension == "flv") {
    $addVariable .= "oSwf.addVariable('file', '" . $asset->url . "');";
    $addParam .= "oSwf.addParam('allowfullscreen', 'true');\n";
    $asset->url = base_path() . drupal_get_path('module', 'asset_bonus') . '/swfobject/flvplayer.swf';
    if (arg(2) != "edit" && ($options['height'] == "112.5" || $options['height'] == "100")) {

      // Set a default width/height if none is available or when we're looking at an asset gallery (panels)
      $options['width'] = 204;
      $options['height'] = 145;
    }
    elseif (arg(2) == "edit") {

      // Set a static width/height to keep the asset cck gui clean
      $options['width'] = 120;
      $options['height'] = 80;
    }
  }
  elseif (substr($asset->url, 0, 4) != "http") {
    $asset->url = '/' . $asset->url;
  }
  if (!empty($options['width'])) {
    $addVariable .= "oSwf.addVariable('width', '{$options['width']}');\n";
  }
  if (!empty($options['height'])) {
    $addVariable .= "oSwf.addVariable('height', '{$options['height']}');\n";
  }

  // build a list of addParam statements for known params
  if ($options['transparent']) {
    $addParam .= "oSwf.addParam('wmode', 'transparent');\n";
  }
  if (empty($options['version'])) {
    $options['version'] = "0";
  }

  // We're not using drupal_add_js(drupal_get_path('module','asset_bonus').'/swfobject/swfobject.js') because of caching issues
  $swfobject = base_path() . drupal_get_path('module', 'asset_bonus') . '/swfobject/swfobject.js';
  $output = <<<OUT
  <script type="text/javascript" src="{<span class="php-variable">$swfobject</span>}"></script>
  <div id="{<span class="php-variable">$div_id</span>}" class="asset-swfobject">Video placeholder</div>
  <script type="text/javascript" defer="defer">
    var oSwf = new SWFObject("{<span class="php-variable">$asset</span>-&gt;<span class="php-function-or-constant property member-of-variable">url</span>}","{<span class="php-variable">$embed_id</span>}","{<span class="php-variable">$options</span>[<span class="php-string">'width'</span>]}","{<span class="php-variable">$options</span>[<span class="php-string">'height'</span>]}","{<span class="php-variable">$options</span>[<span class="php-string">'version'</span>]}","{<span class="php-variable">$options</span>[<span class="php-string">'bgcolor'</span>]}");
    {<span class="php-variable">$addVariable</span>}
    {<span class="php-variable">$addParam</span>}
    oSwf.write("{<span class="php-variable">$div_id</span>}");
    oSwf = null;
  </script>
OUT;
  return $output;
}