You are here

function _classified_list_nodes in Classified Ads 6.3

Same name and namespace in other branches
  1. 7.3 classified.module \_classified_list_nodes()

Prepare a node listing from a DB query resource.

Parameters

resource $q: A query returning node information, at least:

  • node.title
  • node.nid
  • node.body
  • node.format
  • classified_node.expires

Return value

string The listing.

2 calls to _classified_list_nodes()
_classified_page_term in ./classified.module
Page callback for classified/<tid>.
_classified_page_user_ads in ./classified.module
Page callback for user/<uid>/classified

File

./classified.module, line 389
A pure D6 classified ads module inspired by the ed_classified module.

Code

function _classified_list_nodes($q) {
  $rows = array();
  $now = $_SERVER['REQUEST_TIME'];
  $list_body = _classified_get('list-body');
  switch ($list_body) {
    case 'empty':
    case 'body':
      $header = array(
        t('Contents'),
        t('Expires'),
      );
      $date_format = _classified_get('date-format');
      break;
    case 'node':
      $header = NULL;
  }
  while (is_object($node = db_fetch_object($q))) {
    switch ($list_body) {
      case 'empty':
        $cell = l($node->title, 'node/' . $node->nid);
        $row = array(
          $cell,
          strftime($date_format, $node->expires),
        );
        break;
      case 'body':
        $cell = array(
          'data' => l($node->title, 'node/' . $node->nid, array(
            'attributes' => array(
              'class' => 'classified-list-title',
            ),
          )) . check_markup($node->body, $node->format),
        );
        $row = array(
          $cell,
          strftime($date_format, $node->expires),
        );
        break;
      case 'node':
        $node = node_load($node->nid);
        $node->build_mode = 'ad list';
        $cell = node_view($node);
        $row = array(
          $cell,
        );
        break;
    }
    if ($list_body != 'node') {
      foreach ($row as $index => $cell) {
        if (!is_array($cell)) {
          $cell = array(
            'data' => $cell,
          );
        }
        if ($node->expires < $now || !$node->status) {
          $cell += array(
            'class' => 'node-unpublished',
          );
        }
        $row[$index] = $cell;
      }
    }
    $rows[] = $row;
  }
  $ret = theme('table', $header, $rows);
  return $ret;
}