| 1 |
<?php
|
| 2 |
/* $Id: globalnode.module,v 1.3 2007/05/06 02:35:09 daryl Exp $ */
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Implementation of hook_help().
|
| 10 |
*/
|
| 11 |
/**
|
| 12 |
* Display help and module information
|
| 13 |
* @param section which section of the site we're displaying help
|
| 14 |
* @return help text for section
|
| 15 |
*/
|
| 16 |
function globalnode_help($section='') {
|
| 17 |
|
| 18 |
$output = '';
|
| 19 |
|
| 20 |
switch ($section = '') {
|
| 21 |
case "admin/help#globalnode":
|
| 22 |
$output = '<p>'. t("Lets you put some info about nodes into the global scope."). '</p>';
|
| 23 |
break;
|
| 24 |
case "admin/modules/#description":
|
| 25 |
$output = '<p>' . t('globalnode help') . '</p>';
|
| 26 |
break;
|
| 27 |
}
|
| 28 |
|
| 29 |
return $output;
|
| 30 |
}
|
| 31 |
|
| 32 |
function globalnode_menu($may_cache){
|
| 33 |
$items[] = array(
|
| 34 |
'path' => 'admin/settings/globalnode',
|
| 35 |
'title' => t('GlobalNode settings'),
|
| 36 |
'callback' => 'drupal_get_form',
|
| 37 |
'callback arguments' => 'globalnode_admin',
|
| 38 |
'access' => user_access('access administration pages'),
|
| 39 |
'type' => MENU_NORMAL_ITEM,
|
| 40 |
);
|
| 41 |
return $items;
|
| 42 |
}
|
| 43 |
|
| 44 |
function globalnode_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
|
| 45 |
if($op != 'view'){
|
| 46 |
return;
|
| 47 |
}
|
| 48 |
if(!is_object($GLOBALS['globalnode'])){
|
| 49 |
$attributes = variable_get('globalnode_attributes', '');
|
| 50 |
|
| 51 |
if($attributes) {
|
| 52 |
$attributes = str_replace(', ', "\n", $attributes);
|
| 53 |
$attributes = str_replace(',', "\n", $attributes);
|
| 54 |
$attributes = str_replace(';', "\n", $attributes);
|
| 55 |
$attributes = array_unique(split("\r\n", $attributes));
|
| 56 |
|
| 57 |
$GLOBALS['globalnode'] = new stdClass();
|
| 58 |
$GLOBALS['globalnode']->list = false;
|
| 59 |
foreach($attributes as $att){
|
| 60 |
if($att && $node->$att){
|
| 61 |
$GLOBALS['globalnode']->$att = $node->$att;
|
| 62 |
}
|
| 63 |
}
|
| 64 |
}
|
| 65 |
}
|
| 66 |
//In node list contexts, it might be nice to know that we're in
|
| 67 |
//list context, as we may behave differently in these cases.
|
| 68 |
//So if there's already a globalnode object, set the list
|
| 69 |
//attribute to true.
|
| 70 |
else{
|
| 71 |
$GLOBALS['globalnode']->list = true;
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
function globalnode_admin(){
|
| 76 |
$form['globalnode_attributes'] = array(
|
| 77 |
'#id' => 'globalnode_attributes',
|
| 78 |
'#type' => 'textarea',
|
| 79 |
'#title' => t('Attributes'),
|
| 80 |
'#rows' => 6,
|
| 81 |
'#cols' => 40,
|
| 82 |
'#default_value' => variable_get('globalnode_attributes', ''),
|
| 83 |
'#description' => 'Enter node object attributes (e.g. "type" or "created") that should be added to the global scope on node load, one per line.'
|
| 84 |
);
|
| 85 |
return system_settings_form($form);
|
| 86 |
}
|