You are here

function campaignmonitor_block_view in Campaign Monitor 7

Implements hook_block_view().

File

./campaignmonitor.module, line 181
Module that plugs in Campaign Monitor functionality to your Drupal web site.

Code

function campaignmonitor_block_view($delta) {
  $block = array();
  if (CAMPAIGNMONITOR_ARCHIVE_DELTA == $delta) {

    // Connect to Campaign Monitor and get past campaigns.
    $campaigns = CampaignMonitor::getConnector()
      ->getCampaigns();
    if ($campaigns) {
      $content = '<ul>';
      foreach ($campaigns as $campaign) {
        $content .= '<li>' . l($campaign['Name'], $campaign['Link']) . ' ' . format_date($campaign['Sent'], 'short') . '</li>';
      }
      $content .= '</ul>';

      // Build block.
      $block['subject'] = t('Newsletter archive');
      $block['content'] = array(
        '#markup' => $content,
      );
    }
    else {
      drupal_set_message(t('Unable to fetch campaigns from Campaign monitor.'), 'error');
    }
  }
  else {

    // Get lists form Campaign Monitor.
    $lists = CampaignMonitor::getConnector()
      ->getLists();
    if ($lists) {
      $block['subject'] = t('%name', array(
        '%name' => $lists[$delta]['name'],
      ));
      if (campaignmonitor_is_list_enabled($delta)) {
        $block['content'] = drupal_get_form('campaignmonitor_subscribe_form', $delta);
      }
      else {
        $block['content'] = t('The Campaign monitor list "@list" is not enabled.', array(
          '@list' => $lists[$delta]['name'],
        ));
      }

      // Add some basic styling of form elements.
      drupal_add_css(drupal_get_path('module', 'campaignmonitor') . '/css/campaignmonitor.theme.css');
    }
    else {
      drupal_set_message(t('Unable to fetch lists from Campaign monitor.'), 'error');
    }
  }
  return $block;
}