You are here

function asset_js_preview in Asset 6

Same name and namespace in other branches
  1. 5 asset.module \asset_js_preview()

Menu Callback from javascript to print an assets preview

2 calls to asset_js_preview()
asset_wizard_form in ./asset_wizard.inc
Main form builder function for the asset wizard.
asset_wizard_form in inc/asset_wizard.inc
Main form builder function for the asset wizard.
1 string reference to 'asset_js_preview'
asset_menu in ./asset.module
Implementation of hook_menu()

File

./asset.module, line 388

Code

function asset_js_preview($aid, $show_details = true, $return = false) {
  if (!isset($aid)) {
    exit;
  }
  $asset = asset_load($aid);
  $formatters = asset_get_formatters();
  if (isset($formatters[$asset->type][$asset->extension][0])) {
    $format = $formatters[$asset->type][$asset->extension][0];
  }
  elseif (isset($formatters[$asset->type]['*'][0])) {
    $format = $formatters[$asset->type]['*'][0];
  }
  else {
    $format = $formatters['*']['*'][0];
  }
  $output .= asset_preview($asset->aid);
  if ($show_details) {
    $details[t('File Size')] = format_size($asset->filesize);
    if (!empty($asset->author)) {
      $details[t('Author')] = $asset->author;
    }
    $details = array_merge($details, (array) module_invoke($format['module'], 'asset_formatter', 'details', $asset, $format));
    foreach ($details as $label => $value) {
      $output .= '<div><strong>' . check_plain($label) . '</strong>: ' . check_plain($value) . '</div>';
    }
  }
  if ($return) {
    return $output;
  }
  print $output;
  exit;
}