You are here

function osmplayer_media_colorbox_preprocess in MediaFront 7.2

Preprocess a colorbox to add a mediafront preset to it.

1 string reference to 'osmplayer_media_colorbox_preprocess'
osmplayer_theme_registry_alter in players/osmplayer/osmplayer.module
Implementation of hook_theme_registry_alter.

File

players/osmplayer/osmplayer.module, line 182

Code

function osmplayer_media_colorbox_preprocess(&$variables) {
  static $colorbox_params = null;

  // Get the settings.
  $settings =& $variables['display_settings'];

  // Set the width and height based on the mediafront preset size.
  if ($colorbox_params) {
    $settings['fixed_width'] = intval($colorbox_params['width']) + OSMPLAYER_COLORBOX_XPADDING;
    $settings['fixed_height'] = intval($colorbox_params['height']) + OSMPLAYER_COLORBOX_YPADDING;
    return;
  }
  $file_id = $variables['file_id'];
  if ($file_id != NULL) {
    $file = file_load($file_id);
    $view = file_view_file($file, $settings['colorbox_view_mode'], $variables['langcode']);

    // If the theme is a mediafront_player, then we need to add our files.
    if ($view['#theme'] == 'mediafront_player') {

      // Get the displays settings.
      $preset = '';
      $displays = file_displays($file->type, $settings['colorbox_view_mode']);
      foreach ($displays as $formatter_type => $display) {
        if (!empty($display['status'])) {
          if (!empty($display['settings']['preset'])) {
            $preset = $display['settings']['preset'];
          }
          break;
        }
      }

      // If no preset is defined, then get the first one.
      if (!$preset) {
        $presets = mediafront_preset_get_presets();
        $preset = array_shift($presets);
        $preset = $preset['name'];
      }

      // Get the preset parameters and add the core javascript files.
      $params = mediafront_get_preset_params($preset);

      // Set a static width if it is 100%.
      $params['width'] = $params['width'] == '100%' ? '500px' : $params['width'];

      // Add the width and height to the modal.
      $settings['fixed_width'] = intval($params['width']) + OSMPLAYER_COLORBOX_XPADDING;
      $settings['fixed_height'] = intval($params['height']) + OSMPLAYER_COLORBOX_YPADDING;
      osmplayer_add_core_files($params);
      $colorbox_params = $params;
    }
  }
}