You are here

function simplenews_block_view in Simplenews 7

Same name and namespace in other branches
  1. 7.2 simplenews.module \simplenews_block_view()

Implements hook_block_view().

File

./simplenews.module, line 1186
Simplenews node handling, sent email, newsletter block and general hooks

Code

function simplenews_block_view($delta = '') {

  // Special block for multi
  if ($delta == 0) {
    if (user_access('subscribe to newsletters')) {
      module_load_include('inc', 'simplenews', 'includes/simplenews.subscription');

      // render block only if permitted
      $block = array(
        'subject' => t('Newsletters'),
        'content' => theme('simplenews_multi_block'),
      );
      return $block;
    }
    return NULL;
  }
  else {
    $newsletters = simplenews_categories_load_multiple(array(), array(
      'block' => '1',
      'show_all' => FALSE,
    ));

    // Only display a block if $delta is a valid newsletter term id.
    if (in_array($delta, array_keys($newsletters))) {

      // $delta is validated, the block can be displayed.
      $block = array(
        'subject' => check_plain(_simplenews_newsletter_name($newsletters[$delta])),
        'content' => theme(array(
          'simplenews_block__' . $delta,
          'simplenews_block',
        ), array(
          'tid' => $delta,
        )),
      );
      return $block;
    }
  }
}