You are here

function photos_block_view in Album Photos 7.3

Implements hook_block_view().

File

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

Code

function photos_block_view($delta = '') {
  $block = array();
  $count = variable_get('photos_block_num_' . $delta, 10);
  switch ($delta) {
    case 'latest_images':
      if (user_access('view photo') && ($content = _photos_block_image('latest', $count, 'photos/image'))) {
        $block['subject'] = t('Recent images');
        $block['content'] = $content;
      }
      return $block;
    case 'user_images':
      if (arg(0) == 'photos') {
        switch (arg(1)) {
          case 'image':
            $uid = db_query('SELECT uid FROM {file_managed} WHERE fid = :uid', array(
              ':uid' => arg(2),
            ))
              ->fetchField();
            break;
          case 'user':
            $uid = arg(2);
        }
      }
      if (arg(0) == 'node' && is_numeric(arg(1))) {
        $uid = db_query('SELECT uid FROM {node} WHERE nid = :nid', array(
          ':nid' => arg(1),
        ))
          ->fetchField();
      }
      if (!isset($uid)) {
        global $user;
        $uid = $user->uid;
      }
      if ($uid && ($content = _photos_block_image('user', $count, 'photos/user/' . $uid . '/image', $uid))) {
        $block['subject'] = t('%name\'s images', array(
          '%name' => $content[1],
        ));
        $block['content'] = $content[0];
      }
      return $block;
    case 'information_pager':

      // @todo add support for sub album pager.
      if (arg(0) == 'photos' && arg(1) == 'image' && is_numeric(arg(2)) && isset($_GET['photos_sub'])) {
        $fid = arg(2);
        $pager_type = 'sub';
        $pager_id = (int) $_GET['photos_sub'];
      }
      elseif (arg(0) == 'photos' && arg(1) == 'image' && is_numeric(arg(2))) {
        $fid = arg(2);
        $pager_type = 'pid';
      }
      elseif (arg(0) == 'photos' && arg(1) == 'user' && is_numeric(arg(2)) && is_numeric(arg(4))) {
        $fid = arg(4);
        $uid = arg(2);
        $pager_id = arg(2);
        $pager_type = 'uid';
      }
      if (isset($fid)) {
        $query = db_select('photos_image', 'p');
        $query
          ->join('file_managed', 'f', 'f.fid = p.fid');
        $query
          ->join('node', 'n', 'n.nid = p.pid');
        $query
          ->join('users', 'u', 'f.uid = u.uid');
        $query
          ->fields('p', array(
          'count',
          'comcount',
          'exif',
          'des',
        ))
          ->fields('f', array(
          'uri',
          'timestamp',
          'filemime',
          'fid',
        ))
          ->fields('n', array(
          'nid',
          'title',
        ))
          ->fields('u', array(
          'name',
          'picture',
          'uid',
        ))
          ->condition('p.fid', $fid);
        $query
          ->addTag('node_access');
        $image = $query
          ->execute()
          ->fetchObject();
        if ($image) {
          if ($pager_type == 'pid') {
            $pager_id = $image->nid;
          }
          $image->pager = photos_image_pager($fid, $pager_id, $pager_type);
          $item = array();
          if (variable_get('photos_print_sizes', 0) < 2) {
            $all_sizes_link = variable_get('photos_print_sizes', 0);
            if ($all_sizes_link < 2) {

              // Display full page or colorbox.
              $colorbox = array();
              if ($all_sizes_link == 1) {
                $colorbox = array(
                  'query' => array(
                    'iframe' => 'true',
                    'height' => 650,
                    'width' => 850,
                  ),
                  'attributes' => array(
                    'class' => array(
                      'colorbox-load',
                    ),
                  ),
                );
              }
              $item[] = l(t('Copy image to share code'), 'photos/zoom/' . $image->fid, $colorbox);
            }
          }
          if ($image->exif && variable_get('photos_exif', 0)) {
            $item[] = l(t('View image Exif information'), 'photos/zoom/' . $image->fid . '/exif', array(
              'query' => array(
                'iframe' => 'true',
                'height' => 650,
                'width' => 850,
              ),
              'attributes' => array(
                'class' => array(
                  'colorbox-load',
                ),
              ),
            ));
          }
          if (variable_get('photos_slide', 0) && module_exists('dfgallery')) {
            $image->slide_url = url('photos/album/' . $image->nid . '/slide');
          }
          $image->links = theme('item_list', array(
            'items' => $item,
          ));
          if (variable_get('photos_block_num_information_pager', 0)) {
            $query = db_select('node', 'n');
            $query
              ->join('photos_node', 'a', 'a.nid = n.nid');
            $query
              ->join('users', 'u', 'u.uid = n.uid');
            $query
              ->fields('n', array(
              'nid',
              'title',
            ))
              ->fields('u', array(
              'uid',
              'name',
            ))
              ->condition('a.fid', $image->fid)
              ->orderBy('n.nid', 'DESC')
              ->range(0, 10);
            $result = $query
              ->execute();
            foreach ($result as $node) {
              $image->sub_album[$node->nid] = $node;
              $image->sub_album[$node->nid]->geturl = url('photos/data/sub_album/' . $node->nid . '/block_new/json.json');
              $image->sub_album[$node->nid]->url = url('photos/sub_album/' . $node->nid);
              $image->sub_album[$node->nid]->user = $image->name;
              $image->sub_album[$node->nid]->info = t('!name in !time to create', array(
                '!name' => $node->name,
                '!time' => format_date($image->timestamp, 'small'),
              ));
            }
          }
          $block['subject'] = t('Photo information');
          $block['content'] = theme('photos_imageblock', array(
            'image' => $image,
          ));
        }
      }
      return $block;
    case 'random_images':
      if (user_access('view photo') && ($content = _photos_block_image('rand', $count))) {
        $block['subject'] = t('Random images');
        $block['content'] = $content;
      }
      return $block;
  }
}