You are here

function theme_rotating_banner in Rotating Banner 7.2

Same name and namespace in other branches
  1. 7 rotating_banner.module \theme_rotating_banner()
1 theme call to theme_rotating_banner()
rotating_banner_block_view in ./rotating_banner.module
Implements hook_block_view().

File

./rotating_banner.module, line 437

Code

function theme_rotating_banner($variables) {
  $banner = $variables['banner'];
  $slides = $variables['slides'];

  #print $banner->rbid;
  $settings = $banner->settings;
  if (is_string($settings)) {
    $settings = unserialize($settings);
  }
  $fluid = $settings['fluid'];

  // This is kinda annoying, but this actually needs to be 0 for it to not show.
  if (!$settings['cycle']['timeout']) {
    $settings['cycle']['timeout'] = 0;
  }
  $path = drupal_get_path('module', 'rotating_banner');
  $banners = array();
  $id = 'rotating-banner-' . $banner->rbid;
  $banners[$id] = $settings;
  drupal_add_js(array(
    'rotatingBanners' => $banners,
  ), 'setting');

  // The prefix will be added later based on the contained slides and the layout type
  $element = array(
    '#prefix' => '<div class="rotating-banner" id="' . $id,
    '#suffix' => '</div>',
  );
  $element['#attached']['css'][] = $path . '/rotating_banner.css';
  $element['#attached']['js'][] = $path . '/includes/jquery.easing.js';
  $element['#attached']['js'][] = $path . '/includes/jquery.cycle.js';
  $element['#attached']['js'][] = $path . '/rotating_banner.js';

  // Add sweet effects
  $element['#attached']['libraries'][] = 'effects';

  // We set the max-height here because the controls shouldn't be affected by overflow:hidden;
  if (!$fluid) {
    $rbStyle = "max-height: {$settings['height']}" . 'px;';
  }
  else {
    $rbStyle = "max-height: auto;";
  }
  $element['slides'] = array(
    '#prefix' => '<div class="rb-slides" style="' . $rbStyle . '">' . "\n\t",
    '#suffix' => '</div>',
  );

  // These values are to set the w/h for fluid banners and the height for static banners
  $smallest = NULL;
  $ratio = NULL;
  $ratioPointer = NULL;
  foreach ($slides as $k => $slide) {
    $first_slide = FALSE;
    if ($k == 0) {
      $first_slide = TRUE;
    }
    $file = file_load($slide->fid);
    if ($file) {
      $size = getimagesize($file->uri);
      if ($size[0] < $smallest || $smallest == NULL) {
        $smallest = $size[0];
      }

      // Determine if the slide has the smallest w/h ratio
      if ($size[0] / $size[1] < $ratio || $ratio == NULL) {
        $ratio = $size[0] / $size[1];
        $ratioPointer = $k;
      }
    }
    $link = $slide->link;
    $textboxes = $slide->textboxes;
    $layout = $slide->layout;
    $element['slides']['slide_' . $k] = array(
      '#theme' => 'rotating_banner_slide',
      '#banner' => $banner,
      '#background_image' => $file,
      '#textboxes' => $textboxes,
      '#link' => $link,
      '#layout' => $layout,
      '#tallest' => false,
      '#first' => $first_slide,
    );
  }
  $element['slides']['slide_' . $ratioPointer]['#tallest'] = 'tallest';

  // If the banner is static, we set the width, and if fluid it is a max-width.
  if (!$fluid) {
    $style = 'width: ';
    $element['#prefix'] = '<div class="static-wrapper"><div class="rotating-banner" id="' . $id;
    $element['#suffix'] = '</div></div>';
  }
  else {
    $style = 'max-width: ';
  }

  // If the banner is fluid or doesn't have a set width, we need to use the width of the narrowest slide that we calculated earlier
  if ($fluid || $settings['width'] <= 0) {
    if ($smallest) {
      $style .= $smallest . "px;";
    }
    $element['#prefix'] = $element['#prefix'] . '" style="' . $style . '">' . "\n\t";
  }
  else {
    $style .= $settings['width'] . "px;";
    $element['#prefix'] = $element['#prefix'] . '" style="' . $style . '">' . "\n\t";
  }
  if (isset($settings['controls'])) {
    $content = $settings['controls'] == 'prev_next' ? '<a href="#" class="prev">' . t('Prev') . '</a><a href="#" class="next">' . t('Next') . '</a>' : '';
    $element['controls'] = array(
      '#markup' => '<div class="' . $settings['controls'] . ' controls">' . $content . '</div>',
    );
  }
  return $element;
}