You are here

function shoutbox_display_posts in Shoutbox 6.2

Same name and namespace in other branches
  1. 7.2 shoutbox.module \shoutbox_display_posts()
  2. 7 shoutbox.module \shoutbox_display_posts()

Output existing shoutbox posts as html.

Parameters

$show_amount: The number of posts to show.

$wrap: Whether or not to wrap posts in <div id="shoutbox-posts">

$pager: Whether or not to use pager_query() instead of db_query_range(), defaults to FALSE.

Return value

An array containing the count, an array of themed rows, all shouts themed not in a table, and an array of raw shouts

2 calls to shoutbox_display_posts()
shoutbox_js_view in ./shoutbox.module
Javascript callback. Prints out shouts only.
shoutbox_view in ./shoutbox.module
View the shoutbox

File

./shoutbox.module, line 513
Shout box module displays a block for users to create short messages for the whole site. Uses AHAH to update the database and display content.

Code

function shoutbox_display_posts($show_amount, $wrap = TRUE, $pager = FALSE) {
  $rows = array();
  $raw = array();
  $contexts = array();

  // Figure out if we should display it in ascending or descending order.
  $ascending = variable_get('shoutbox_ascending', TRUE);

  // Determine the shout context
  shoutbox_invoke('context', $blank, $contexts);

  // Allow other modules to alter the query
  $query = db_rewrite_sql("SELECT shoutbox.* FROM {shoutbox} shoutbox ORDER BY created DESC", 'shoutbox', 'shout_id', $contexts);
  if (!$pager) {
    $result = db_query_range($query, 0, $show_amount);
  }
  else {
    $result = pager_query($query, $show_amount, 1);
  }
  while ($shout = db_fetch_object($result)) {
    if ($shout->moderate == 0 || _shoutbox_user_access('moderate shoutbox') || _shoutbox_is_user_owned($shout)) {

      // Filter shout
      _shoutbox_sanitize_shout($shout);

      // Add edit/delete links depending on user's permissions.
      $shoutlinks = _shoutbox_get_links($shout);

      // Allow other modules to alter the shout before it's viewed
      shoutbox_invoke('view', $shout);

      // Theme the shoutbox post
      $post = theme('shoutbox_post', $shout, $shoutlinks);

      // Add themed rows
      $rows[] = array(
        theme('shoutbox_post', $shout, $shoutlinks, FALSE),
      );

      // Store the raw shout
      $raw[] = $shout;
    }
  }
  $output_data['count'] = count($rows);
  $output_data['rows'] = $ascending ? $rows : array_reverse($rows);
  $output_data['raw'] = $raw;
  return $output_data;
}