You are here

function quotes_page in Quotes 7

Same name and namespace in other branches
  1. 6 quotes.module \quotes_page()

Menu callback that displays a page of quotes restricted to a certain user.

Parameters

array $arg1: The user object (from menu) of the user's quotes to be displayed.

string $arg2:

  • 'feed', a feed is requested.
  • '- FIND -', author selection requested.

Return value

array A renderable array to display a page of quotes.

1 call to quotes_page()
quotes_myquotes in ./quotes.module
Menu callback that generates a list of quotes created by the current user.
1 string reference to 'quotes_page'
quotes_menu in ./quotes.module
Implements hook_menu().

File

./quotes.module, line 1940
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_page($arg1 = NULL, $arg2 = NULL) {
  if (is_null($arg1)) {
    global $user;
  }
  else {
    $user = user_load($arg1);
  }

  // Breadcrumb navigation. The default is wrong because of a core menu bug.
  $breadcrumb = array();
  $breadcrumb[] = l(t('Home'), variable_get('site_frontpage', 'node'));
  $menu_info = menu_get_item('quotes');
  $menu_title = $menu_info['title'];
  $breadcrumb[] = l($menu_title, 'quotes');
  drupal_set_breadcrumb($breadcrumb);
  if (isset($arg2)) {

    // Requesting an author.
    return quotes_author($arg2);
  }
  $query = db_select('node', 'n')
    ->extend('PagerDefault');
  $nr_alias = $query
    ->join('node_revision', 'nr', 'nr.vid = n.vid');
  $query
    ->fields('n', array(
    'nid',
  ))
    ->condition('n.status', '1')
    ->condition('n.type', 'quotes');
  $menu_title = '';
  $url = url('quotes/feed', array(
    'absolute' => TRUE,
  ));
  if (isset($arg1)) {
    $account = user_load($arg1);
    if ($account) {
      if ($account->uid) {
        $name = isset($account->realname) ? $account->realname : $account->name;
        $menu_info = menu_get_item('quotes');
        $menu_title = $menu_info['title'];
        drupal_set_title(t("!name's !menu", array(
          '!menu' => $menu_title,
          '!name' => $name,
        )), PASS_THROUGH);
        $url = url('quotes/' . $account->uid . '/feed', array(
          'absolute' => TRUE,
        ));
        $query
          ->condition('n.uid', $account->uid);
      }
      else {
        $name = DRUPAL_ANONYMOUS_RID;
      }
    }
  }
  $name = isset($name) ? $name : '';
  $query
    ->orderBy('n.sticky', 'DESC')
    ->orderBy('n.created', 'DESC')
    ->addTag('node_access');
  $nids = $query
    ->limit(variable_get('quotes_per_page', 10))
    ->execute()
    ->fetchCol();
  if ($nids) {
    if (isset($arg1) && !$account) {
      drupal_set_message(t('Sorry, the account ID supplied is invalid.'));
    }
  }
  else {
    if (!$arg1) {
      drupal_set_message(t('You have not created any quotes.'));
    }
    else {
      drupal_set_message(t('!author has not created any quotes or you do not have permission to view them.', array(
        '!author' => theme('username', array(
          'account' => $account,
        )),
      )));
    }
  }
  $nodes = node_load_multiple($nids);

  // Reset node value if required.
  foreach ($nodes as $node) {

    // Undo sticky flag.
    if ($node->sticky) {
      $node->sticky = 0;
    }

    // Since this is a Page View, use the nid for empty titles.
    if (empty($node->title)) {
      $node->title = $node->nid;
    }
  }
  $build['quotes_list'][] = node_view_multiple($nodes, $view_mode = 'full', $language = NULL);
  if ($name) {
    drupal_add_feed($url, t("RSS - Favorite @title of !name", array(
      '!name' => $name,
      '@title' => $menu_title,
    )));
  }
  else {
    drupal_add_feed($url, t("RSS - Famous and not so famous quotes"));
  }
  $build['pager'] = array(
    '#theme' => 'pager',
    '#weight' => 5,
  );
  return $build;
}