about_this_node_get_info

Definition

about_this_node_get_info($node)
about_this_node/about_this_node.module, line 110

Description

Gather information about the node and return it as a keyed array

Code

<?php
function about_this_node_get_info($node) {
  $node_info = array();

  // "Constant" strings
  $label_yes	= t('Yes');
  $label_no	= t('No');
  $label_by	= t('by');
  $label_on	= t('on');
  
  // Node ID
  $node_info['node_id'] = array(
    'label' => t('Node ID (NID):'),
    'value' => $node->nid,
  );

  // Node type
  $node_info['node_type'] = array(
    'label' => t('Node type:'),
    'value' => node_get_types('name', $node),
  );

  // Gather author info
  $author_uid = $node->uid;
  $author = '';
  $author_output = '';
  if ($author_uid == '0') { // Check if author is anonymous
    $author_output = variable_get('anonymous', t('Anonymous'));
  }
  else {
    $author = user_load(array('uid' => $author_uid));
    $author_output = l($author->name, 'user/' . $author_uid);
  }

  // Author name/time
  $node_info['created'] = array(
    'label' => t('Created:'),
    'value' => array(
      'created_on' => array(
        'label' => $label_on,
        'value' => $node->created,
      ),
      'created_by' => array(
        'label' => $label_by,
        'value' => $author_output,
      ),
    ),
  );

  // Gather last updated author info
  $update_author_uid = db_result(db_query('SELECT nr.uid FROM {node_revisions} nr INNER JOIN {node} n ON n.vid = nr.vid WHERE n.nid = %d', $node->nid));
  $update_author = '';
  $update_author_output = '';
  if ($update_author_uid == '0') { // Check if author is anonymous
    $update_author_output = variable_get('anonymous', t('Anonymous'));
  }
  else {
    $update_author = user_load(array('uid' => $update_author_uid));
    $update_author_output = l($update_author->name, 'user/' . $update_author_uid);
  }

  // Last updated author name/time
  $node_info['updated'] = array(
    'label' => t('Last updated:'),
  );

  // Check if node has never been updated
  if ($node->created == $node->changed) {
    $node_info['updated']['value'] = t('Never');
  }
  else {
    $node_info['updated']['value'] = array(
      'updated_on' => array(
        'label' => $label_on,
        'value' => $node->changed,
      ),
      'updated_by' => array(
        'label' => $label_by,
        'value' => $update_author_output,
      ),
    );
  }

  // Published status
  $node_info['published'] = array(
    'label' => t('Published:'),
  );
  if ($node->status == 1) {
    $node_info['published']['value'] = $label_yes;
  }
  else {
    $node_info['published']['value'] = $label_no;
  }

  // Promoted to front page status
  $node_info['promoted'] = array(
    'label' => t('Promoted:'),
  );
  if ($node->promote == 1) {
    $node_info['promoted']['value'] = $label_yes;
  }
  else {
    $node_info['promoted']['value'] = $label_no;
  }

  // Sticky status
  $node_info['stickied'] = array(
    'label' => t('Stickied:'),
  );
  if ($node->sticky == 1) {
    $node_info['stickied']['value'] = $label_yes;
  }
  else {
    $node_info['stickied']['value'] = $label_no;
  }

  // Commenting status
  $node_info['commenting'] = array(
    'label' => t('Commenting:'),
  );
  if (module_exists('comment')) {
    if ($node->comment == 0) {
      $node_info['commenting']['value'] = t('Disabled');
    }
    else if ($node->comment == 1) {
      $node_info['commenting']['value'] = t('Read only');
    }
    else {
      $node_info['commenting']['value'] = t('Read/Write');
    }
  }
  else {
    $node_info['commenting']['value'] = t('Module not enabled');
  }

  return $node_info;
}
?>