You are here

function _photos_node_view in Album Photos 7.3

Same name and namespace in other branches
  1. 6.2 photos.module \_photos_node_view()

Page and Teaser display settings.

1 call to _photos_node_view()
photos_node_view in ./photos.module
Implements hook_node_view().

File

./photos.module, line 696
Implementation of photos.module.

Code

function _photos_node_view($node, $display, $view_mode) {
  $album = '';
  if ($display != 0) {
    $default_order = variable_get('photos_display_imageorder', 'timestamp|desc');
    $order = explode('|', isset($node->album['imageorder']) ? $node->album['imageorder'] : $default_order);
    $order = _photos_order_value_change($order[0], $order[1]);
    $default_style = variable_get('photos_display_' . $view_mode . '_imagesize', 'thumbnail');
    $style_name = isset($node->album[$view_mode . '_imagesize']) ? $node->album[$view_mode . '_imagesize'] : $default_style;
  }
  switch ($display) {
    case 0:

      // Display none.
      break;
    case 1:

      // Display cover.
      $album = '';
      if (isset($node->album['cover'])) {
        if (FALSE && isset($node->album['cover']['fid'])) {
          $album .= photos_get_info($node->album['cover']['fid'], 0, array(
            'href' => 'photos/album/' . $node->nid,
            'style_name' => $style_name,
            'colorbox' => TRUE,
            'pid' => $node->nid,
          ));
        }
        else {

          // URL backwards compatibility -- @todo remove in D8 cleanup.
          $image = new stdClass();
          $image->view = theme('image', array(
            'style_name' => $style_name,
            'path' => $node->album['cover']['url'],
          ));
          $image->href = 'photos/album/' . $node->nid;
          $image->uri = $node->album['cover']['url'];
          $image->pid = $node->nid;
          $image->title = $node->title;
          $album .= theme('photos_imagehtml', array(
            'image' => $image,
            'style_name' => $style_name,
          ));
        }
      }
      break;
    case 2:

      // Display thumbnails.
      $column = isset($_GET['field']) ? check_plain($_GET['field']) : 0;
      $sort = isset($_GET['sort']) ? check_plain($_GET['sort']) : 0;
      $limit = isset($node->album[$view_mode . '_viewnum']) ? $node->album[$view_mode . '_viewnum'] : variable_get('photos_display_' . $view_mode . '_viewnum', 10);
      $term = _photos_order_value($column, $sort, $limit, $order);
      $query = db_select('file_managed', 'f');
      $query
        ->join('photos_image', 'p', 'p.fid = f.fid');
      $query
        ->join('users', 'u', 'u.uid = f.uid');
      $query
        ->fields('f', array(
        'uri',
        'filemime',
        'timestamp',
        'filename',
        'filesize',
      ))
        ->fields('p')
        ->fields('u', array(
        'uid',
        'name',
      ));
      $query
        ->condition('p.pid', $node->nid);
      $query
        ->orderBy($term['order']['column'], $term['order']['sort']);
      $query
        ->range(0, $term['limit']);
      $result = $query
        ->execute();
      $i = 0;

      // Necessary when upgrading from D6 to D7.
      $image_styles = image_style_options(FALSE);
      if (!isset($image_styles[$style_name])) {
        $style_name = variable_get('photos_display_teaser_imagesize', 'thumbnail');
      }
      $album = '';

      // Thumbnails.
      foreach ($result as $data) {
        $album .= photos_get_info(0, $data, array(
          'href' => 'photos/image/' . $data->fid,
          'style_name' => $style_name,
          'colorbox' => TRUE,
          'pid' => $node->nid,
        ));
        ++$i;
      }

      // More link.
      if ($i >= $limit) {
        $album .= theme('more_link', array(
          'url' => 'photos/album/' . $node->nid,
          'title' => t('Album view'),
        ));
      }
      $node->content['album-thumbnails'] = array(
        '#markup' => $album,
      );
      break;
  }
  return $album;
}