You are here

function theme_asset_bonus_swfobject in Asset 5.2

Same name and namespace in other branches
  1. 5 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 contrib/asset_bonus/asset_bonus.module

File

contrib/asset_bonus/asset_bonus.module, line 273

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;
  $add_variable = '';
  $add_param = '';

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

    // if (arg(2)!="edit" && (arg(0)!="node" || $options['width']==0)) {
    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;
  }

  // build a list of addParam statements for known params
  if ($options['transparent']) {
    $add_param .= "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';
  $url = file_create_url($asset->file['filepath']);
  $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">
    var oSwf = new SWFObject("{<span class="php-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">$add_variable</span>}
    {<span class="php-variable">$add_param</span>}
    oSwf.write("{<span class="php-variable">$div_id</span>}");
    oSwf = null;
  </script>
OUT;
  return $output;
}