You are here

function simplenews_block in Simplenews 5

Same name and namespace in other branches
  1. 6.2 simplenews.module \simplenews_block()
  2. 6 simplenews.module \simplenews_block()

Implementation of hook_block().

File

./simplenews.module, line 644

Code

function simplenews_block($op = 'list', $delta = 0, $edit = array()) {
  list($type, $tid) = explode('-', $delta);
  switch ($op) {
    case 'list':
      $blocks = array();
      foreach (taxonomy_get_tree(variable_get('simplenews_vid', '')) as $newsletter) {
        $blocks['newsletter-' . $newsletter->tid] = array(
          'info' => t('Newsletter: @title', array(
            '@title' => $newsletter->name,
          )),
        );
      }
      return $blocks;
    case 'configure':
      $form['simplenews_block_' . $delta]['simplenews_block_m_status_' . $tid] = array(
        '#type' => 'checkbox',
        '#title' => t('Display block message'),
        '#return_value' => 1,
        '#default_value' => variable_get('simplenews_block_m_status_' . $tid, 1),
      );
      $form['simplenews_block_' . $delta]['simplenews_block_m_' . $tid] = array(
        '#type' => 'textfield',
        '#title' => t('Block message'),
        '#size' => 60,
        '#maxlength' => 128,
        '#default_value' => variable_get('simplenews_block_m_' . $tid, t('Stay informed on our latest news!')),
      );
      $form['simplenews_block_' . $delta]['simplenews_block_f_' . $tid] = array(
        '#type' => 'checkbox',
        '#title' => t('Display subscription form'),
        '#return_value' => 1,
        '#description' => t('If selected a subscription form is displayed, if not selected a link to the subscription page is displayed.'),
        '#default_value' => variable_get('simplenews_block_f_' . $tid, 1),
      );
      $form['simplenews_block_' . $delta]['simplenews_block_l_' . $tid] = array(
        '#type' => 'checkbox',
        '#title' => t('Display link to previous issues'),
        '#return_value' => 1,
        '#default_value' => variable_get('simplenews_block_l_' . $tid, 1),
        '#description' => t('Links (to previous issues, previous issues and RSS-feed) are only displayed to users who have "view links in block" privileges.'),
      );
      $form['simplenews_block_' . $delta]['simplenews_block_i_status_' . $tid] = array(
        '#type' => 'checkbox',
        '#title' => t('Display previous issues'),
        '#return_value' => 1,
        '#default_value' => variable_get('simplenews_block_i_status_' . $tid, 0),
      );
      $form['simplenews_block_' . $delta]['simplenews_block_i_' . $tid] = array(
        '#type' => 'select',
        '#title' => t('Number of issues to display'),
        '#options' => drupal_map_assoc(array(
          1,
          2,
          3,
          4,
          5,
          6,
          7,
          8,
          9,
          10,
        )),
        '#default_value' => variable_get('simplenews_block_i_' . $tid, 5),
      );
      $form['simplenews_block_' . $delta]['simplenews_block_r_' . $tid] = array(
        '#type' => 'checkbox',
        '#title' => t('Display RSS-feed icon'),
        '#return_value' => 1,
        '#default_value' => variable_get('simplenews_block_r_' . $tid, 1),
      );
      return $form;
    case 'save':
      variable_set('simplenews_block_m_status_' . $tid, $edit['simplenews_block_m_status_' . $tid]);
      variable_set('simplenews_block_m_' . $tid, $edit['simplenews_block_m_' . $tid]);
      variable_set('simplenews_block_f_' . $tid, $edit['simplenews_block_f_' . $tid]);
      variable_set('simplenews_block_l_' . $tid, $edit['simplenews_block_l_' . $tid]);
      variable_set('simplenews_block_i_status_' . $tid, $edit['simplenews_block_i_status_' . $tid]);
      variable_set('simplenews_block_i_' . $tid, $edit['simplenews_block_i_' . $tid]);
      variable_set('simplenews_block_r_' . $tid, $edit['simplenews_block_r_' . $tid]);
      break;
    case 'view':
      if ($type == 'newsletter') {
        if ($newsletter = taxonomy_get_term($tid)) {
          $block['subject'] = check_plain($newsletter->name);
          $block['content'] = theme('simplenews_block', _simplenews_block($newsletter->tid));
        }
      }
      return $block;
  }
}