You are here

function quotes_author in Quotes 5

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

Menu callback that selects quotes based on author.

Parameters

$author: The name or aid of the author of the quotes.

Return value

An HTML-formatted list of quotes.

1 string reference to 'quotes_author'
quotes_menu in ./quotes.module
Implementation of hook_menu().

File

./quotes.module, line 1409

Code

function quotes_author($author = NULL) {
  if (!$author) {

    // If no author given, display a selection list.
    return drupal_get_form('quotes_author_form');
  }
  elseif ($author == t('unspecified')) {
    $aid = 0;
    $auth = array(
      'name' => $author,
      'bio' => '',
    );
  }
  else {

    // See whether we have a name or an id.
    if (is_numeric($author)) {
      $aid = $author;
      $auth = db_fetch_array(db_query("SELECT name, bio FROM {quotes_authors} WHERE aid=%d", $aid));
      $author = $auth['name'];
    }
    else {
      $auth = db_fetch_array(db_query("SELECT aid, bio FROM {quotes_authors} WHERE name LIKE('%s%')", $author));
      $aid = $auth['aid'];
    }
    if (!$aid) {
      return t("I couldn't locate that author.") . drupal_get_form('quotes_author_form');
    }
  }

  // Unspecified author.
  $limit = variable_get('quotes_per_page', 10);
  drupal_set_title(decode_entities(t('Quotes by @name', array(
    '@name' => $author,
  ))));
  if ($auth['bio']) {
    $output = '<div class="quotes-header-bio clear-block">' . check_markup($auth['bio']) . '</div>';
  }
  $result = pager_query(db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {node_revisions} nr USING (vid) INNER JOIN {quotes} q USING (vid) WHERE q.aid='%d' AND n.status=1 AND n.type='quotes' ORDER BY n.sticky DESC, n.created DESC"), $limit, 0, NULL, $aid);
  $output .= '<div class="quotes">';
  while ($node = db_fetch_object($result)) {
    $output .= node_view(node_load($node->nid), FALSE);
  }
  $output .= theme('pager', NULL, $limit);
  return $output . '</div>';
}