You are here

function node_expire_outdated_nodes in Node expire 5

Same name and namespace in other branches
  1. 6 node_expire.inc \node_expire_outdated_nodes()

List all currently expired nodes

1 string reference to 'node_expire_outdated_nodes'
node_expire_menu in ./node_expire.module
Implementation of hook_menu().

File

./node_expire.module, line 569
Alerts administrators of possibly outdated materials and optionally unpublishes them.

Code

function node_expire_outdated_nodes() {

  // Prepare for the content
  $header = array(
    array(
      'data' => t('Title'),
      'field' => 'b.title',
    ),
    array(
      'data' => t('Last Updated'),
      'field' => 'b.changed',
      'width' => '150px',
    ),
    array(
      'data' => t('Expiration Date'),
      'field' => 'a.expire',
      'sort' => 'asc',
      'width' => '150px',
    ),
    array(
      'data' => t('Owner'),
      'field' => 'c.name',
    ),
    array(
      'data' => t('Operations'),
      'colspan' => '2',
    ),
  );

  // Figure out what documents are old
  $query = db_query("SELECT a.nid, b.title, b.changed, a.expire, IF(c.name = '' OR c.name IS NULL, '%s', c.name) as name FROM {node_expire} a LEFT JOIN {node} b ON " . "a.nid = b.nid LEFT JOIN {users} c ON b.uid = c.uid WHERE a.expire <= NOW() AND a.expiremode != 'none' AND b.status = 1" . tablesort_sql($header), variable_get('anonymous', 'Anonymous'));
  $rows = array();
  while ($row = db_fetch_object($query)) {
    $rows[] = array(
      $row->title,
      format_date($row->changed, 'small'),
      $row->expire == '0000-00-00 00:00:00' ? 'Never' : format_date(strtotime($row->expire), 'small'),
      $row->name,
      array(
        'data' => l(t('view'), 'node/' . $row->nid),
        'align' => 'center',
        'width' => '50px',
      ),
      array(
        'data' => l(t('edit'), 'node/' . $row->nid . '/edit'),
        'align' => 'center',
        'width' => '50px',
      ),
    );
  }

  // No results? Everything must be current.
  if (count($rows) == 0) {
    $rows[] = array(
      array(
        'data' => t('No nodes are expired!'),
        'colspan' => '5',
        'align' => 'center',
      ),
    );
  }
  return theme('table', $header, $rows);
}