You are here

function theme_quotes_block in Quotes 7

Themeable function that displays a block of quotes.

1 call to theme_quotes_block()
quotes_block_view in ./quotes.module
Implements hook_block_view().

File

./quotes.module, line 1703
The quotes module allows users to maintain a list of quotes that can be displayed in any number of administrator-defined quote blocks.

Code

function theme_quotes_block(&$variables) {
  $nodes = $variables['nodes'];
  $block = $variables['block'];
  $view_text = $block['view_text'];
  $more_text = $block['more_text'];
  $rand_freq = $block['rand_freq'];
  if (isset($variables['content'])) {
    $content = $variables['content'];
  }
  else {
    $content = array();
  }
  foreach ($nodes as $quote) {

    // This is necessary for shared objects because PHP doesn't copy objects,
    // but passes them by reference.  So when the objects are cached it can
    // result in the wrong output being displayed on subsequent calls.  The
    // cloning and unsetting of $node->content prevents the block output from
    // being the same as the node output.
    $quote = clone $quote;
    unset($quote->content);

    // Save first node title for possible block title below.
    if (!isset($blk_title)) {
      $blk_title = filter_xss($quote->title);
      $blk_nid = $quote->nid;
      $blk_uid = $quote->uid;
    }
    $block['delta'] = $block['bid'];
    $block['module'] = 'quotes';

    // Set $teaser to false so the length is properly processed.
    $quote->max_length = $block['max_length'];
    $quote->in_block = TRUE;
    $quote->show_titles = $block['show_titles'];
    $quote->more_text = $more_text;
    $quote->view_text = $view_text;
    $quote->show_citation = $block['show_citation'];

    // Get the format for author and citation.
    $format = variable_get('quotes_format', filter_default_format());
    $quote->content = array(
      '#prefix' => '<div class= "block-quotes clearfix">',
      '#suffix' => '</div>',
    );

    // Do we want titles?
    switch ($block['show_titles']) {
      case '1':

        // Link to node.
        $quote->content['title'] = array(
          '#markup' => '<h3>' . drupal_get_path_alias(l($quote->title, 'node/' . $quote->nid)) . '</h3>',
        );
        break;
      case '2':

        // Plain text.
        $quote->content['title'] = array(
          '#markup' => '<h3>' . t(check_plain($quote->title)) . '</h3>',
        );
        break;
    }

    // Is the comments installed and enambled, if so do we wish to display
    // a link to access them?
    if (module_exists('comment') && isset($quote->comment) == COMMENT_NODE_OPEN && !empty($view_text)) {
      $quote->content['view_link'] = array(
        '#prefix' => '<div class="quotes-view-link">',
        '#suffix' => '</div>',
        '#markup' => drupal_get_path_alias(l($view_text, 'node/' . $quote->nid)),
      );
    }
    $content[] = node_view($quote, 'full');
  }
  $_quotes_subs = array(
    '%' . t('interval') => format_interval($block['cron_interval'] * $block['cron_step'], 1),
    '%' . t('bid') => $block['bid'],
    '%' . t('title') => $blk_title,
    '%' . t('nid') => $blk_nid,
    '%' . t('user') => theme('username', array(
      'account' => user_load($blk_uid),
    )),
  );
  $block['content'] = $content;
  $block['subject'] = strtr($block['name'], $_quotes_subs);
  $variables['block'] = $block;
  $variables['nodes'] = '';
}