You are here

function quotes_view in Quotes 7

Same name and namespace in other branches
  1. 5 quotes.module \quotes_view()
  2. 6 quotes.module \quotes_view()

Implements hook_view().

File

./quotes.module, line 750
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 quotes_view($node, $view_mode) {
  global $user;

  // Breadcrumb navigation.
  if (node_is_page($node)) {
    $build = array();
    $breadcrumb = array();
    $breadcrumb[] = l(t('Home'), variable_get('site_frontpage', 'node'));

    // Get the menu title.
    $menu_info = menu_get_item('quotes');
    $menu_title = $menu_info['title'];
    $breadcrumb[] = l($menu_title, 'quotes');
    $username = $user->uid ? $user->name : variable_get('anonymous', t('Anonymous'));
    $breadcrumb[] = l(t("!name's !menu", array(
      '!menu' => $menu_title,
      '!name' => $username,
    )), "quotes/{$node->uid}");
    drupal_set_breadcrumb($breadcrumb);
  }
  $format = variable_get('quotes_format', filter_default_format());
  $variables['node'] = $node;

  // Format to use for author and citation.
  $variables['format'] = $format;

  // Are we in a quotes_block.
  $in_block = isset($node->in_block) && $node->in_block;

  // We do not want the title in the quotes block.
  if ($in_block && isset($node->show_titles) && $node->show_titles == 0) {
    $node->title = '';
  }
  if (!$in_block && empty($node->title)) {
    quotes_form_alter($form, $formstate, $form_id = NULL);
  }

  // Add author if present.
  theme_quotes_author($variables);
  $node = $variables['node'];

  // Add citation if present.
  $variables['node'] = $node;
  theme_quotes_citation($variables);
  $node = $variables['node'];

  // Now the links.
  if ($node->type == 'quotes') {

    // Some links are not done in blocks.
    // Get the menu title.
    $menu_info = menu_get_item('quotes');
    $menu_title = $menu_info['title'];
    if (!(arg(0) == 'quotes' && arg(1) == $node->uid)) {
      $name = $node->uid ? $node->name : variable_get('anonymous', t('Anonymous'));

      // Note: links already get check_plain, so the text is safe.
      if (!$in_block && variable_get('quotes_showlink', TRUE)) {
        if ($node->uid != $user->uid) {
          $links['quotes_usernames_quotes'] = array(
            'title' => t("!name's !menu", array(
              '!menu' => $menu_title,
              '!name' => $name,
            )),
            'href' => "quotes/{$node->uid}",
            'attributes' => array(
              'title' => t("View !name's !menu.", array(
                '!menu' => $menu_title,
                '!name' => $name,
              )),
            ),
          );
          $node->content['links']['quotes'] = array(
            '#theme' => 'links__node__quotes',
            '#links' => $links,
            '#attributes' => array(
              'class' => array(
                'links',
                'inline',
              ),
            ),
          );
        }
      }
      if (!$in_block && variable_get('quotes_edit_link', TRUE)) {
        if (user_access('edit own quotes') && $node->uid == $user->uid || user_access('administer quotes')) {
          $links['quotes_edit_link'] = array(
            'title' => t('Edit !menu', array(
              '!menu' => drupal_strtolower($menu_title),
            )),
            'href' => 'node/' . $node->nid . '/edit',
            'attributes' => array(
              'title' => t('Edit this !menu', array(
                '!menu' => drupal_strtolower($menu_title),
              )),
            ),
          );
          $node->content['links']['quotes'] = array(
            '#theme' => 'links__node__quotes',
            '#links' => $links,
            '#attributes' => array(
              'class' => array(
                'links',
                'inline',
              ),
            ),
          );
        }
      }
    }
  }
  return $node;
}