You are here

function theme_asset_bonus_swfobject in Asset 6

Same name in this branch
  1. 6 asset_bonus/asset_bonus.module \theme_asset_bonus_swfobject()
  2. 6 contrib/asset_bonus/asset_bonus.module \theme_asset_bonus_swfobject()
Same name and namespace in other branches
  1. 5.2 contrib/asset_bonus/asset_bonus.module \theme_asset_bonus_swfobject()
  2. 5 asset_bonus/asset_bonus.module \theme_asset_bonus_swfobject()
2 theme calls to theme_asset_bonus_swfobject()
asset_bonus_swfobject_preview in contrib/asset_bonus/asset_bonus.module
asset_bonus_swfobject_preview in asset_bonus/asset_bonus.module

File

asset_bonus/asset_bonus.module, line 265

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') . '/3rdparty/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') . '/3rdparty/swfobject/swfobject.js';
  $output = <<<OUT
\t<script type="text/javascript" src="{<span class="php-variable">$swfobject</span>}"></script>
\t<div id="{<span class="php-variable">$div_id</span>}" class="asset-swfobject">Video placeholder</div>
\t<script type="text/javascript" defer="defer">
\tvar 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>]}");
\t{<span class="php-variable">$addVariable</span>}
\t{<span class="php-variable">$addParam</span>}
\toSwf.write("{<span class="php-variable">$div_id</span>}");
    oSwf = null;
  </script>
OUT;
  return $output;
}