You are here

function _gallery_assist_node_view in Gallery Assist 7

Implements hook_node_view().

@todo: Missing a solution for cases - h = w.

File

./gallery_assist.module, line 1217
Extend drupal with gallery functionalities. Manage galleries.

Code

function _gallery_assist_node_view($node, $view_mode, $langcode) {

  //  dsm($view_mode);
  if (gallery_assist_on($node->type)) {
    if (isset($node->ga_items) && count($node->ga_items) > 0) {
      $conf = $node->ga_conf[$node->type];
      $conf['view_mode'] = $view_mode;
      $js_settings = array(
        'galleryAssist' => array(
          'settings' => array(
            'view_mode' => $view_mode,
            'teaser_items_per_row' => $conf['teaser_items_per_row'],
            'page_items_per_row' => $conf['page_items_per_row'],
          ),
        ),
      );
      drupal_add_js($js_settings, 'setting');
      $params = array();
      if (isset($_GET['page'])) {
        $params = array(
          'page' => $_GET['page'],
        );
      }
      $type_css = variable_get('gallery_assist_directory', FALSE) . '/css/gallery_assist.' . $node->type . '.css';
      if (file_exists($type_css)) {

        #drupal_add_css($type_css);
      }
      $style = image_style_load($conf['thumbnail_image_style']);
      $end = end($style['effects']);
      $width = $end['data']['width'];
      $height = $end['data']['height'];
      if ($end['name'] == 'image_scale_and_crop' || $end['name'] == 'image_crop' || $end['name'] == 'image_crop') {
        $width = $end['data']['width'];
        $height = $end['data']['height'];
      }
      $items = array();
      foreach ($node->ga_items as $item) {
        $info = image_get_info($item->opath);
        if ($info['width'] > $info['height']) {
          $info['dir'] = 'h';
          $info['new_width'] = $width;
          $f = $width * 100 / $info['width'];
          $info['new_height'] = $info['height'] * $f / 100;
          $info['top'] = $height > $info['new_height'] ? ($height - $info['new_height']) / 2 : 0;
        }
        $variables = array(
          'path' => $item->opath,
          'alt' => $item->palt,
          'title' => $item->ptitle,
          'getsize' => FALSE,
          'style_name' => $conf['thumbnail_image_style'],
        );
        if (isset($info['top']) && $info['top'] > 0) {
          $variables['attributes']['style'] = "margin-top:{$info['top']}px;";
        }
        $img = theme('image_style', $variables);
        $ibox_classes = '';
        if ($conf['ga_shadow'] == 1) {
          $ibox_classes .= ' withshadow';
        }
        if ($item->cover == 1) {
          $ibox_classes .= ' ga-cover';
        }
        $item->ptitle = strlen($item->ptitle) > 17 && $width <= 100 ? substr($item->ptitle, 0, 17) . '...' : $item->ptitle;
        $ititles = $node->ga_conf[$node->type]['show_title'] == 0 ? ' hidden' : '';
        $image = '<div class="ga-item ' . $node->type . '">';
        $image .= '<div class="ga-item-links">';
        $image .= l(t('edit'), "node/{$node->nid}/item/{$item->pid}/edit", array(
          'attributes' => array(
            'class' => array(
              'ga-item-link',
            ),
          ),
        ));

        //.'<a class="ga-item-link" href="">edit</a>';
        $image .= l(t('delete'), "node/{$node->nid}/{$item->pid}/delete", array(
          'attributes' => array(
            'class' => array(
              'ga-item-link',
            ),
          ),
        ));
        $image .= l(t('cover'), "node/{$node->nid}/cover/{$item->pid}", array(
          'attributes' => array(
            'class' => array(
              'ga-item-link',
            ),
          ),
        ));
        $image .= '</div>';
        $image .= '<div class="ga-item-box' . $ibox_classes . '">';
        $image .= l('<div class="ga-image-box">' . $img . '</div>', "node/{$node->nid}/item/{$item->pid}", array(
          'query' => $params,
          'html' => TRUE,
          'attributes' => array(),
        ));

        //        $image .= '<a href="#" style="display:block;">';
        //        $image .= '<div class="ga-image-box">'. $img .'</div>';
        //        $image .= '</a>';
        $image .= '</div>';
        $image .= '<div class="ga-item-title-box' . $ititles . '">' . $item->ptitle . '</div>';
        $image .= '</div>';
        $items[] = $image;
      }

      #drupal_add_css(variable_get('gallery_assist_directory', FALSE) ."/css/gallery_assist.{$node->type}.css");
      $vm = $view_mode == 'teaser' ? $view_mode : 'page';
      $attributes = array(
        'outer' => array(
          'class' => array(
            'gallery-container-outer',
            $node->type,
            $view_mode,
            $conf["{$vm}_container_float"] != 'none' ? 'f-' . $conf["{$vm}_container_float"] : '',
          ),
        ),
        'inner' => array(
          'class' => array(
            'gallery-container-inner',
            $node->type,
            $view_mode,
            $conf["{$vm}_container_align"],
          ),
          'style' => 'max-width:608px;',
        ),
      );
      $container = array(
        '<div ' . drupal_attributes($attributes['outer']) . '>',
        '<div class="ga-links" style="display:none;">here the link</div>',
        '  <div ' . drupal_attributes($attributes['inner']) . '>',
        implode('', $items),
        '  </div>',
        '</div>',
      );
      if ($view_mode != 'teaser') {
        $node->content['gallery_assist_pager'] = array(
          '#markup' => theme('pager', array(
            'tags' => NULL,
          )),
          '#weight' => $node->ga_conf[$node->type]['gallery_assist_weight'] * 1 - 0.5,
        );
      }
      $node->content['gallery_assist_container'] = array(
        '#markup' => implode('', $container),
        '#weight' => $node->ga_conf[$node->type]['gallery_assist_weight'] * 1,
      );

      //      switch ($view_mode) {
      //        case 'teaser':
      //          $js = array(
      //            'galleryAssist' => array(
      //              'teaser_items_per_row' => $conf['teaser_items_per_row'],
      //            )
      //          );
      //          drupal_add_js($js, 'settings');
      //          break;
      //        case 'full':
      //          $js = array(
      //            'page_items_per_row' => $conf['page_items_per_row'],
      //          );
      //          break;
      //      }
    }
  }
}