You are here

function photos_node_load in Album Photos 7.3

Same name and namespace in other branches
  1. 8.5 photos.module \photos_node_load()
  2. 8.4 photos.module \photos_node_load()
  3. 6.0.x photos.module \photos_node_load()

Implements hook_node_load().

File

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

Code

function photos_node_load($nodes, $types) {
  $info = array();
  foreach ($nodes as $nid => $node) {
    if ($node->type == 'photos') {
      $query = db_select('photos_album')
        ->fields('photos_album')
        ->condition('pid', $node->nid);
      $result = $query
        ->execute();
      foreach ($result as $a) {
        if ($a->pid) {

          // Check if album data is corrupt to prevent unserialize notice.
          if ($a->data != 'N;') {
            $info['album'] = unserialize($a->data);
          }
          $info['album']['pid'] = $a->pid;
          $info['album']['count'] = $a->count;
          if ($a->fid && ($image = db_query('SELECT * FROM {file_managed} WHERE fid = :fid', array(
            ':fid' => $a->fid,
          ))
            ->fetchObject())) {
            $image = photos_get_info(0, $image);
            $info['album']['cover']['fid'] = $a->fid;
            $thumb = variable_get('photos_title_0', FALSE);
            $info['album']['cover']['url'] = $image->uri;
            $title = check_plain($node->title);
            $style_name = variable_get('photos_cover_imagesize', 'thumbnail');
            $cover_view = theme('image_style', array(
              'style_name' => $style_name,
              'path' => $image->uri,
              'alt' => $title,
              'title' => $title,
            ));
            $info['album']['cover']['view'] = l($cover_view, 'photos/album/' . $node->nid, array(
              'html' => TRUE,
              'attributes' => array(
                'title' => $title,
              ),
            ));
          }
          else {
            $query = db_select('file_managed', 'f');
            $query
              ->join('photos_image', 'p', 'p.fid = f.fid');
            $query
              ->fields('f');
            $query
              ->condition('p.pid', $node->nid);
            $image = $query
              ->execute()
              ->fetchObject();
            if (isset($image->fid)) {
              $image = photos_get_info($image->fid, $image);
              $thumb = variable_get('photos_display_list_imagesize', 'thumbnail');
              $info['album']['cover']['url'] = $image->uri;
              $info['album']['cover']['fid'] = $image->fid;
              $title = check_plain($node->title);
              $style_name = variable_get('photos_cover_imagesize', 'thumbnail');
              $cover_view = theme('image_style', array(
                'style_name' => $style_name,
                'path' => $image->uri,
                'alt' => $title,
                'title' => $title,
              ));
              $info['album']['cover']['view'] = l($cover_view, 'photos/album/' . $node->nid, array(
                'html' => TRUE,
                'attributes' => array(
                  'title' => $title,
                ),
              ));
            }
          }
          $nodes[$nid]->album = $info['album'];
        }
      }
    }
    if (variable_get('photos_node_' . $node->type, 0)) {
      $query = db_select('photos_count', 'c')
        ->fields('c', array(
        'cid',
        'value',
      ))
        ->condition('c.cid', $node->nid)
        ->condition('c.type', 'node_node');
      $result = $query
        ->execute();
      foreach ($result as $photo) {
        if ($photo->cid) {
          $nodes[$nid]->subalbum['count'] = $photo->value;
        }
      }
    }
  }
}