Stripping CVS keywords
[project/helpers.git] / helpers_node.module
CommitLineData
16595b10 1<?php
16595b10
K
2
3/**
4 * @file
5 * This is a library of useful node functions and methods.
6 * please insert the link if you have a patch for core to introduce a function from this lib to core.
7 */
8
9/**
10 * Implementation of hook_help().
11 */
70c45cc1
NW
12function helpers_node_help($path, $args) {
13 $output = null;
14 switch ($path) {
15 case 'admin/help#helpers_node':
16 $output .= t('A development library for nodes. Contains useful functions and methods for node manipulation and node queries.');
17 $output .= '<dl>';
18 $output .= '<dt>'.'is_node_page'.'</dt><dd>'. t('Find out if the current page is a node page.') .'</dd>';
19 $output .= '<dt>'.'node_load_current'.'</dt><dd>'. t('Grab the current "active" node.') .'</dd>';
20 $output .= '</dl>';
16595b10 21 }
70c45cc1 22 return $output;
16595b10
K
23}
24
25/**
26 * Find out if the current page is a node page.
27 * @return TRUE if the page is a node, FALSE if it is another page.
28 */
29function is_node_page() {
54b6baa1
NW
30 if (arg(0) == 'node' && is_numeric(arg(1))) {
31 return TRUE;
32 }
33 return FALSE;
16595b10
K
34}
35
36/**
70c45cc1 37 * Grab the current 'active' node.
16595b10
K
38 * An active node is the one node 123 as shown on page with path node/123, or
39 * its aliased path(s).
40 * @return $node object if the page is a node, empty $node object if it is not a
41 * node, or if we cannot see it, for any valid reason.
42 */
43function node_load_current() {
54b6baa1 44 if (is_node_page()) {
b3b541cd
NW
45 if (!is_object($node = menu_get_object())) {
46 $node = node_load(arg(1));
47 }
48 }
49 else {
50 $node = new stdClass();
54b6baa1 51 }
16595b10 52
54b6baa1 53 return $node;
16595b10 54}