You are here

function simplenews_user_view in Simplenews 7

Same name and namespace in other branches
  1. 8.2 simplenews.module \simplenews_user_view()
  2. 8 simplenews.module \simplenews_user_view()
  3. 7.2 simplenews.module \simplenews_user_view()
  4. 3.x simplenews.module \simplenews_user_view()

Implements hook_user_view().

File

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

Code

function simplenews_user_view($account, $build_mode) {
  global $user;
  if ($user->uid == $account->uid || user_access('administer users')) {
    $account->content['simplenews'] = array(
      '#type' => 'user_profile_category',
      '#title' => t('Newsletters'),
    );

    // Collect newsletter to which the current user is subscribed.
    // 'hidden' newsletters are not listed.
    $newsletters = simplenews_category_get_visible();
    $subscription = simplenews_subscriber_load_by_mail($account->mail);
    foreach ($newsletters as $newsletter) {
      if (isset($subscription->newsletter_subscription[$newsletter->tid]) && $subscription->newsletter_subscription[$newsletter->tid]->status == TRUE) {
        $links[] = l(_simplenews_newsletter_name($newsletter), 'taxonomy/term/' . $newsletter->tid);
      }
    }
    if (isset($links)) {

      // @todo replace with theme('links', $links) to form a list of newsletters?
      $links = implode(', ', $links);
    }
    else {
      $links = t('None');
    }

    // When a user has no permission to subscribe and is not subscribed
    // we do not display the 'no subscriptions' message.
    if (user_access('subscribe to newsletters') || $links != t('None')) {
      $account->content['simplenews']['subscriptions'] = array(
        '#type' => 'user_profile_item',
        '#title' => t('Subscribed to'),
        '#markup' => $links,
      );
    }
    if (user_access('subscribe to newsletters')) {
      $account->content['simplenews']['my_newsletters'] = array(
        '#type' => 'user_profile_item',
        '#title' => '',
        '#markup' => t('Manage <a href="!url">subscriptions</a>', array(
          '!url' => url('user/' . $account->uid . '/edit/simplenews'),
        )),
      );
    }
  }
}