You are here

function image_block in Image 5

Same name and namespace in other branches
  1. 5.2 image.module \image_block()
  2. 6 image.module \image_block()

Implementation of hook_block.

Offers 2 blocks: latest image and random image

File

./image.module, line 451

Code

function image_block($op = 'list', $delta = 0) {
  switch ($op) {
    case 'list':
      $block[0]['info'] = t('Latest image');
      $block[1]['info'] = t('Random image');
      return $block;
    case 'view':
      if (user_access('access content')) {
        switch ($delta) {
          case 0:
            $images = image_get_latest();
            $block['subject'] = t('Latest image');
            $block['content'] = l(image_display($images[0], IMAGE_THUMBNAIL), 'node/' . $images[0]->nid, array(), NULL, NULL, FALSE, TRUE);
            break;
          case 1:
            $images = image_get_random();
            $block['subject'] = t('Random image');
            $block['content'] = l(image_display($images[0], IMAGE_THUMBNAIL), 'node/' . $images[0]->nid, array(), NULL, NULL, FALSE, TRUE);
            break;
        }
      }
      return $block;
  }
}