You are here

function jw_player_preset_settings in JW Player 7.2

Helper function to display JW Player preset settings.

Parameters

string $preset_machine_name: Value set of the preset's machine name.

Return value

array The preset settings stored in an array for rendering.

2 calls to jw_player_preset_settings()
jw_player_ctools_export_ui::list_build_row in plugins/export_ui/jw_player_ctools_export_ui.class.php
Build a row based on the item.
jw_player_field_formatter_settings_summary in ./jw_player.module
Implements hook_field_formatter_settings_summary().

File

./jw_player.module, line 366
Adds a theme function which allows theme developers to use the JW Player.

Code

function jw_player_preset_settings($preset_machine_name) {
  $summary = array();
  $presets = jw_player_preset_load();
  if (!isset($presets[$preset_machine_name])) {
    $summary['name'] = t('<strong>Error: "@name" preset cannot be found.</strong>', array(
      '@name' => $preset_machine_name,
    ));
    $summary['source'] = '';
    return $summary;
  }
  else {
    $preset = $presets[$preset_machine_name];
  }
  $preset_settings = $preset['settings'];

  // Name and description.
  $summary['name'] = t('Preset: @name', array(
    '@name' => $preset['preset_name'],
  ));
  if (!empty($preset['description'])) {
    $summary['description'] = t('Description: @desc', array(
      '@desc' => $preset['description'],
    ));
  }

  // Skin.
  if (!isset($preset_settings['preset_source']) || $preset_settings['preset_source'] == 'drupal') {
    $summary['source'] = t('Preset source: Drupal');
    if (!empty($preset_settings['skin'])) {
      $skin_label = drupal_ucfirst($preset_settings['skin']);
      $summary['skin'] = t('Skin: @skin', array(
        '@skin' => $skin_label,
      ));
    }

    // Dimensions and stretching.
    switch ($preset_settings['stretching']) {
      case 'exactfit':
        $stretch = 'exact fit';
        break;
      case 'uniform':
        $stretch = 'uniform';
        break;
      case 'fill':
        $stretch = 'fill';
        break;
      default:
        $stretch = '';
        break;
    }
    if (!empty($stretch)) {
      if (!empty($preset_settings['responsive'])) {
        $summary['dimensions'] = t('Dimensions: @width% width (@aspect_ratio), @stretch', array(
          '@width' => $preset_settings['width'],
          '@aspect_ratio' => $preset_settings['aspectratio'],
          '@stretch' => $stretch,
        ));
      }
      else {
        $summary['dimensions'] = t('Dimensions: @widthx@height, @stretch', array(
          '@width' => $preset_settings['width'],
          '@height' => $preset_settings['height'],
          '@stretch' => $stretch,
        ));
      }
    }
    else {
      if (!empty($preset_settings['responsive'])) {
        $summary['dimensions'] = t('Dimensions: @width% width (@aspect_ratio)', array(
          '@width' => $preset_settings['width'],
          '@aspect_ratio' => $preset_settings['aspectratio'],
        ));
      }
      else {
        $summary['dimensions'] = t('Dimensions: @widthx@height', array(
          '@width' => $preset_settings['width'],
          '@height' => $preset_settings['height'],
        ));
      }
    }

    // Enabled options.
    $enabled = array();
    if ($preset_settings['autostart']) {
      $enabled[] = t('Autostart');
    }
    if ($preset_settings['mute']) {
      $enabled[] = t('Mute');
    }
    if ($preset_settings['controls']) {
      $enabled[] = t('Controls');
    }
    if ($preset_settings['sharing']) {
      $enabled[] = t('Sharing');
    }
    if (!empty($enabled)) {
      $enabled_string = implode(', ', $enabled);
      $summary['enabled'] = t('Enabled options: @enabled', array(
        '@enabled' => $enabled_string,
      ));
    }

    // Sharing sites.
    if (isset($preset_settings['sharing_sites_show'])) {
      $sharing_sites = array_intersect_key(jw_player_sharing_sites(), array_filter($preset_settings['sharing_sites_show']));
      if (!empty($sharing_sites)) {
        $sharing_order = array_intersect_key($preset_settings['sharing_sites_order'], array_filter($preset_settings['sharing_sites_show']));
        $sharing_weights = array();
        foreach ($sharing_order as $key => $value) {
          $sharing_weights[$key] = $value['weight'];
        }
        asort($sharing_weights);
        $sharing_sorted = array_merge(array_flip(array_keys($sharing_weights)), $sharing_sites);
        $sharing_sorted_string = implode(', ', $sharing_sorted);
        $summary['sharing'] = t('Sharing sites: @sharing', array(
          '@sharing' => $sharing_sorted_string,
        ));
      }
    }
  }
  else {
    $summary['source'] = t('Preset source: JW Player');
  }
  return $summary;
}