You are here

function template_preprocess_simplenews_block in Simplenews 7.2

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

Process variables to format the simplenews block.

Collect data and apply access restrictions.

See also

simplenews-block.tpl.php

File

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

Code

function template_preprocess_simplenews_block(&$variables) {
  global $user;
  $newsletter_id = $variables['newsletter_id'];
  $newsletter = simplenews_newsletter_load($newsletter_id);

  // Set default values in case of missing permission.
  $variables['form'] = '';
  $variables['subscription_link'] = '';
  $variables['newsletter_link'] = '';
  $variables['issue_list'] = '';
  $variables['rssfeed'] = '';

  // Block content variables
  $variables['message'] = check_plain(variable_get('simplenews_block_m_' . $newsletter_id, t('Stay informed on our latest news!')));
  if (user_access('subscribe to newsletters')) {
    module_load_include('inc', 'simplenews', 'simplenews.subscription');
    $variables['form'] = drupal_get_form('simplenews_block_form_' . $newsletter_id);
    $variables['subscription_link'] = l(t('Manage my subscriptions'), 'newsletter/subscriptions');
  }

  // @todo replace path
  $variables['newsletter_link'] = l(t('Previous issues'), 'newsletter/' . $newsletter_id);
  $recent = simplenews_recent_newsletters($newsletter_id, variable_get('simplenews_block_i_' . $newsletter_id, 5));
  $variables['issue_list'] = '';
  if ($recent) {
    $variables['issue_list'] = theme('item_list', array(
      'items' => $recent,
      'title' => t('Previous issues'),
      'type' => 'ul',
    ));
  }
  $variables['rssfeed'] = theme('feed_icon', array(
    'url' => 'newsletter/feed/' . $newsletter_id,
    'title' => t('@newsletter feed', array(
      '@newsletter' => $newsletter->name,
    )),
  ));

  // Block content control variables
  $variables['use_form'] = variable_get('simplenews_block_f_' . $newsletter_id, 1);
  $variables['use_issue_link'] = variable_get('simplenews_block_l_' . $newsletter_id, 1);
  $variables['use_issue_list'] = variable_get('simplenews_block_i_status_' . $newsletter_id, 0);
  $variables['use_rss'] = variable_get('simplenews_block_r_' . $newsletter_id, 1);

  // Additional variables
  $variables['subscribed'] = empty($user->uid) ? FALSE : simplenews_user_is_subscribed($user->mail, $newsletter_id) == TRUE;
  $variables['user'] = !empty($user->uid);
}