You are here

function gallery_assist_item_pager in Gallery Assist 6

Build the pager for this module.

Parameters

$node: A object containing the node data.

$extras: A array reserved to send to this module options or conditions.

2 calls to gallery_assist_item_pager()
gallery_assist_display_item_default in ./gallery_assist.module
Build the output to display each gallery image. Call the own pager and the theme.
gallery_assist_edit_one in ./gallery_assist.module
Allow to edit each Gallery Assist Item separately.

File

./gallery_assist.module, line 4159
Drupal content type with gallery functionality.

Code

function gallery_assist_item_pager($node, $extras = NULL) {
  $conf = $node->gallconf[$node->type];
  $my_total = count($node->gallitems);
  if (count($node->gallitems) <= 1) {
    return;
  }
  $data = array();
  $i = 0;
  foreach ($node->gallitems as $k => $v) {
    ++$i;
    $data[$i] = $node->gallitems[$k];
    $node->gallitems[$k]->counter = $i;
  }
  $my_page = isset($node->gallitems[$node->pid]->counter) ? $node->gallitems[$node->pid]->counter : 1;
  $max_vis = $conf['pager_visibles'] < $my_total ? $conf['pager_visibles'] : $my_total + 2;
  $my_quantity = $my_total > $my_quantity ? $max_vis : $my_total;
  $my_short = $my_total > $my_quantity - 2 ? 1 : 0;
  $my_odd = $my_quantity & 1;
  $my_n = $my_odd == 1 ? 0 : 1;
  $my_middle = ceil($my_quantity / 2);
  $my_attributes = array(
    'class' => $node->type . ' pager',
  );
  if ($conf['gap_align'] !== 'node') {
    switch ($conf['gap_align']) {
      case 'left':
        $my_attributes['style'] = $conf['pager_align'] == 'left' ? 'text-align:left;' : 'text-align:' . $conf['pager_align'];
        break;
      case 'center':
        $my_attributes['style'] = $conf['pager_align'] == 'center' ? 'text-align:center;' : 'text-align:' . $conf['pager_align'];
        break;
      case 'right':
        $my_attributes['style'] = $conf['pager_align'] == 'right' ? 'text-align:right;' : 'text-align:' . $conf['pager_align'];
        break;
    }
  }
  $my_active_opts = array(
    'attributes' => array(
      'class' => $node->type . ' active',
    ),
    'html' => TRUE,
  );
  $theme = variable_get('theme_default', FALSE);
  $my_pager_layout = $conf['pager_layout'];
  $my_grafic_previous_path = file_exists(drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/previous.png') ? drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/previous.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/previous.png';
  $my_grafic_previous = theme('image', $my_grafic_previous_path, '', t('go to the previous'));
  $my_grafic_next_path = file_exists(drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/next.png') ? drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/next.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/next.png';
  $my_grafic_next = theme('image', $my_grafic_next_path, '', t('go to the next'));
  if ($conf['pager_format'] == 0) {
    $my_grafic_first_path = file_exists(drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/first.png') ? drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/first.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/first.png';
    $my_grafic_first = theme('image', $my_grafic_first_path, '', t('go to the first'));
    $my_grafic_hellip_path = file_exists(drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/hellip.png') ? drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/hellip.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/hellip.png';
    $my_grafic_hellip = theme('image', $my_grafic_hellip_path);
    $my_grafic_last_path = file_exists(drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/last.png') ? drupal_get_path('theme', $theme) . '/ga_pager/' . $my_pager_layout . '/last.png' : drupal_get_path('module', 'gallery_assist') . '/ga_pager/default/last.png';
    $my_grafic_last = theme('image', $my_grafic_last_path, '', t('go to the last'));
    $my_first = $conf['pager_symbol'] == 0 ? t('« first') : $my_grafic_first;
    $my_last = $conf['pager_symbol'] == 0 ? t('last »') : $my_grafic_last;
    $my_hellip = $conf['pager_symbol'] == 0 ? '&hellip;' : $my_grafic_hellip;
  }
  $my_previous = $conf['pager_symbol'] == 0 || $my_quantity == 0 ? t('‹ previous') : $my_grafic_previous;
  $my_next = $conf['pager_symbol'] == 0 || $my_quantity == 0 ? t('next ›') : $my_grafic_next;
  $link_helper = $node->type == 'gallery_assist' ? '' : '_' . $node->type;
  $my_pager_paths = $extras == 'edit-one' ? 'node/ga_edit_one' . $link_helper . '/' . $node->nid . '/' : 'node/' . $node->nid . '/';
  $get_values = array();
  $get_values = $_GET;
  unset($get_values['q']);
  $my_active_opts['query'] = $get_values;

  // $link = l('[edit]', 'node/ga_edit_one/'. $item->nid .'/'. $item->pid, array('query' => $get_values));
  if ($my_quantity > 0) {
    $before[] = array(
      'class' => $node->type . ' pager-first',
      'data' => $my_page > 1 ? l($my_first, $my_pager_paths . $data[1]->pid, $my_active_opts) : $my_first,
    );
  }
  $before[] = array(
    'class' => $node->type . ' pager-previous',
    'data' => $my_page == 1 ? l($my_previous, $my_pager_paths . $data[$my_total]->pid, $my_active_opts) : l($my_previous, $my_pager_paths . $data[$my_page - 1]->pid, $my_active_opts),
  );
  if ($my_quantity > 0 && $conf['pager_format'] == 0) {
    $before[] = array(
      'class' => $node->type . ' pager-ellipsis',
      'data' => $my_short == 1 && $my_page > $my_middle ? $my_hellip : '&nbsp;&nbsp;&nbsp;',
    );
  }
  $c = 1;
  $links = array();
  foreach ($data as $k => $v) {
    if ($c == $my_page) {
      $my_clss = 'pager-current';
      if (function_exists('imagecache_preset') && is_numeric($conf['pager_presetid'])) {
        $my_mini = theme('imagecache', $conf['pager_presetname'], $data[$c]->opath, '', $c . ' / ' . $my_total, array(
          'class' => $node->type . ' pager-thumbnail ic-on',
        ), FALSE);
      }
      else {
        $my_mini = theme('image', file_create_url($data[$c]->thmb_path), '', $c . ' / ' . $my_total, array(
          'height' => $conf['pager_t_active_height'],
          'class' => $node->type . ' gallery-assist-thumbnail',
        ), FALSE);
      }
      $my_pager_layout_def = $extras == 'edit-one' ? 1 : $conf['pager_symbol'];
      $my_data = $my_pager_layout_def == 1 ? $my_mini : $c;
    }
    else {
      $my_clss = 'pager-item';
      if (function_exists('imagecache_preset') && is_numeric($conf['pager_presetid'])) {
        $my_mini = theme('imagecache', $conf['pager_presetname'], $data[$c]->opath, '', $c . ' / ' . $my_total, array(
          'class' => $node->type . ' pager-thumbnail ic-off',
        ), FALSE);
      }
      else {
        $my_mini = theme('image', file_create_url($data[$c]->thmb_path), '', $c . ' / ' . $my_total, array(
          'height' => $conf['pager_t_height'],
          'id' => 'pager-icon',
          'class' => $node->type . ' gallery-assist-thumbnail',
        ), FALSE);
      }
      $my_pager_layout_def = $extras == 'edit-one' ? 1 : $conf['pager_symbol'];
      $my_symbol = $my_pager_layout_def == 1 ? $my_mini : $c;
      $my_data = l($my_symbol, $my_pager_paths . $data[$c]->pid, $my_active_opts);
    }
    $links[] = array(
      'class' => $node->type . ' ' . $my_clss,
      'data' => $my_data,
    );
    $c++;
  }
  $mylinks = $links;
  if ($my_short == 1 && $my_total > $my_quantity) {
    if ($my_page > $my_total - $my_quantity) {
      if ($my_page + $my_middle - $my_odd < $my_total) {
        $mysmall = array_slice($links, $my_page - $my_middle, $my_quantity, TRUE);
      }
      else {
        $mysmall = array_slice($links, $my_total - $my_quantity, $my_quantity, TRUE);
      }
    }
    elseif ($my_page <= $my_quantity) {
      if ($my_page >= $my_middle) {
        $mysmall = array_slice($links, $my_page - $my_middle, $my_quantity, TRUE);
      }
      else {
        $mysmall = array_slice($links, 0, $my_quantity, TRUE);
      }
    }
    else {
      $mysmall = array_slice($links, $my_page - $my_middle, $my_middle + $my_middle - $my_odd, TRUE);
    }
  }
  else {
    $mysmall = array(
      '',
    );
  }
  $my_after_data = $my_short == 1 && $my_page + $my_middle + $my_n <= $my_total ? $my_hellip : '&nbsp;&nbsp;&nbsp;';
  if ($my_quantity > 0 && $conf['pager_format'] == 0) {
    $after[] = array(
      'class' => $node->type . ' pager-ellipsis',
      'data' => $my_after_data,
    );
  }
  $next_image = $my_page == $my_total ? $data[1]->pid : $data[$my_page + 1]->pid;
  $after[] = array(
    'class' => $node->type . ' pager-next',
    'data' => $my_page == $my_total ? l($my_next, $my_pager_paths . $data[1]->pid, $my_active_opts) : l($my_next, $my_pager_paths . $data[$my_page + 1]->pid, $my_active_opts),
  );
  if ($my_quantity > 0 && $conf['pager_format'] == 0) {
    $after[] = array(
      'class' => $node->type . ' pager-last',
      'data' => $my_page == count($node->gallitems) ? $my_last : l($my_last, $my_pager_paths . $data[$my_total]->pid, $my_active_opts),
    );
  }
  $mylinks = $my_short == 1 ? $mysmall : $links;
  $links = array_merge($before, $mylinks, $after);

  //  $output = theme('item_list', $links, NULL, 'ul', $my_attributes);
  $output = array(
    'all' => theme('item_list', $links, NULL, 'ul', $my_attributes),
    'next' => $next_image,
  );
  return $output;
}