You are here

theme.inc in Imagefield Crop 7.3

File

theme/theme.inc
View source
<?php

function theme_imagefield_crop_widget($variables) {
  $element = $variables['element'];
  $output = '';
  $output .= '<div class="imagefield-crop-widget form-managed-file clearfix">';
  if (isset($element['presets'])) {
    $output .= drupal_render($element['presets']);
    $output .= drupal_render($element['variants']);
  }
  if (isset($element['preview'])) {
    $output .= '<div class="imagefield-crop-preview">';
    $output .= drupal_render($element['preview']);
    $output .= '</div>';
  }
  if (isset($element['cropbox'])) {
    $output .= '<div class="imagefield-crop-cropbox">';
    $output .= drupal_render($element['cropbox']);
    $output .= '</div>';
  }
  if (isset($element['crop_config'])) {
    $output .= drupal_render($element['crop_config']);
  }
  $output .= '</div>';
  $output .= drupal_render_children($element);
  return $output;
}
function theme_imagefield_crop_preview($variables) {
  $output = '';
  if (!empty($variables['element']['#imagefield_crop'])) {
    $preview = $variables['element']['#imagefield_crop'];
    foreach ($preview as $preset) {
      $preview_style = array();
      $style = array(
        'overflow:hidden',
      );
      $clases = array(
        'jcrop-preview-wrapper',
      );
      $style[] = 'width:' . $preset['#width'] . 'px';
      $style[] = 'height:' . $preset['#height'] . 'px';
      $clases[] = 'preview-' . $preset['#name'];
      if (!empty($preset['#crop_config']->data->active)) {
        $clases[] = 'active';
      }
      $output .= '<div class="' . implode(' ', $clases) . '" style="' . implode(';', $style) . '">';
      $output .= theme('image', array(
        'path' => $variables['element']['#path'],
        'alt' => 'jcrop-preview',
        'attributes' => array(
          'class' => 'jcrop-preview',
          'style' => 'display:none',
        ),
      ));
      $output .= '</div>';
    }
  }
  return $output;
}

/**
 * Implements theme_imagefield_crop_preset_list().
 * Used to show all presets as table.
 * @param $variables
 * @return string
 */
function theme_imagefield_crop_preset_list($variables) {
  $presets = $variables['presets'];
  $header = array(
    t('Preset name'),
    array(
      'data' => t('Operations'),
      'colspan' => 2,
    ),
  );
  $rows = array();
  foreach ($presets as $pid => $name) {
    if ($name == 'Free crop') {
      continue;
    }
    $row = array();
    $row[] = l($name, 'admin/config/media/imagefield-crop-preset-list/' . $pid . '/edit');
    $row[] = l('edit', 'admin/config/media/imagefield-crop-preset-list/' . $pid . '/edit');
    $row[] = l('delete', 'admin/config/media/imagefield-crop-preset-list/' . $pid . '/delete');
    $rows[] = $row;
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'colspan' => 4,
        'data' => t('There are currently no presets . <a href="!url">Add a new one</a>.', array(
          '!url' => url('admin/config/media/imagefield-crop-preset-list/add'),
        )),
      ),
    );
  }
  return theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
}