You are here

function _photos_block_image in Album Photos 7.3

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

Photos - extends block view.

2 calls to _photos_block_image()
photos_block_view in ./photos.module
Implements hook_block_view().
photos_page_default in inc/photos.page.inc
Default page, list recent photos and galleries.

File

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

Code

function _photos_block_image($type, $limit, $url = 'photos/image', $uid = 0, $sort = array(
  'column' => 'f.fid',
  'order' => 'DESC',
)) {
  $query = db_select('file_managed', 'f');
  $query
    ->join('photos_image', 'p', 'p.fid = f.fid');
  $query
    ->join('node', 'n', 'n.nid = p.pid');
  $query
    ->join('users', 'u', 'u.uid = f.uid');
  $query
    ->fields('f', array(
    'uri',
    'filemime',
    'timestamp',
    'filename',
  ))
    ->fields('u', array(
    'uid',
    'name',
  ))
    ->fields('n', array(
    'nid',
  ))
    ->fields('p');
  $query
    ->condition('n.status', 1);
  if ($type == 'user') {
    $query
      ->condition('f.uid', $uid);
  }
  if ($type == 'rand') {
    $query
      ->orderRandom();
  }
  else {
    $query
      ->orderBy($sort['column'], $sort['order']);
  }
  $query
    ->range(0, $limit);
  $query
    ->addTag('node_access');
  $result = $query
    ->execute();
  $view = array();
  $images = array();
  foreach ($result as $image) {
    $image = photos_get_info(0, $image);
    $image->href = $url . '/' . $image->fid;
    $images[] = $image;
  }
  if (isset($images[0]->fid)) {
    $content = theme('photos_block', array(
      'images' => $images,
      'type' => 'image',
    ));
    if ($url && count($image) >= $limit) {
      $content .= theme('more_link', array(
        'url' => url($url),
        'title' => t('View more'),
      ));
    }
    if ($type == 'user') {
      return array(
        $content,
        $images[0]->name,
      );
    }
    else {
      return $content;
    }
  }
}