Index: relativity.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/relativity/relativity.module,v retrieving revision 1.30 diff -u -F^f -r1.30 relativity.module --- relativity.module 4 Sep 2006 03:36:02 -0000 1.30 +++ relativity.module 7 Sep 2006 17:32:51 -0000 @@ -389,16 +389,7 @@ function relativity_settings($tab='') { '#default_value' => variable_get('relativity_enforce_parent_rules', 0), '#description' => t('If checked, nodes cannot be created without a parent if they require a parent to exist.'), ); - - $group['advanced_settings']['global_options']['relativity_nav_types'] = array( - '#type' => 'select', - '#title' => t('Allowable Ancestor Navigation Block Node types'), - '#default_value' => variable_get('relativity_nav_types', 'default'), - '#options' => relativity_node_list('none'), - '#description' => t('What types of nodes are allowed to be used in the navigation block?'), - '#size' => 5, - '#multiple' => TRUE, - ); + // Node Sorting Options @@ -668,29 +659,135 @@ function relativity_settings($tab='') { * Implementation of hook_block(). * * Generates navigation block to quickly jump to any of this node's ancestors. + * See http://api.drupal.org/api/4.7/function/block_example_block */ -function relativity_block($op = 'list', $delta = 0) { +function relativity_block($op = 'list', $delta = 0, $edit = array()) { // The $op parameter determines what piece of information is being requested. - if ($op == 'list') { - // If $op is "list", we just need to return a list of block descriptions. This - // is used to provide a list of possible blocks to the administrator. - $blocks[0]['info'] = t("Navigate through a node's ancestors"); - return $blocks; - } - else if ($op == 'view') { - // see if we're viewing a node - if (arg(0) == "node" && is_numeric(arg(1))) { - // see if it's a valid node - $node = node_load(arg(1)); - if (is_object($node) && node_access('view', $node)) { - $ancestors = relativity_load_ancestors($node); - if (is_array($ancestors) && count($ancestors) > 0) { - $block['subject'] = $node->title; - $block['content'] = theme('relativity_ancestors', $node, $ancestors); - } + switch ($op) { + case 'list': + // If $op is "list", we just need to return a list of block descriptions. + // This is used to provide a list of possible blocks to the administrator, + // end users will not see these descriptions. + $blocks[0]['info'] = t('Node relativity: ancestors'); + $blocks[1]['info'] = t('Node relativity: children'); + $blocks[2]['info'] = t('Node relativity: parent'); + return $blocks; + + case 'configure': + // If $op is "configure", we need to provide the administrator with a + // configuration form. The $delta parameter tells us which block is being + // configured. In this example, we'll allow the administrator to customize + // the text of the first block. + $form = array(); + switch($delta) { + // All we need to provide is a text field, Drupal will take care of + // the other block configuration options and the save button. + case 0: + $form['relativity_block_ancestors_subject'] = array( + '#type' => 'textfield', + '#title' => t('Block Title'), + '#size' => 60, + '#description' => t('The title of the "Node relativity: ancestors" block.'), + '#default_value' => variable_get('relativity_block_ancestors_subject', + variable_get('relativity_ancestors_label', t('Related Ancestors'))), + '#maxlength' => 250, + ); + break; + case 1: + $form['relativity_block_children_subject'] = array( + '#type' => 'textfield', + '#title' => t('Block Title'), + '#size' => 60, + '#description' => t('The title of the "Node relativity: children" block.'), + '#default_value' => variable_get('relativity_block_children_subject', + variable_get('relativity_children_label', t('Related Items'))), + '#maxlength' => 250, + ); + break; + case 2: + $form['relativity_block_parents_subject'] = array( + '#type' => 'textfield', + '#title' => t('Block Title'), + '#size' => 60, + '#description' => t('The title of the "Node relativity: parents" block.'), + '#default_value' => variable_get('relativity_block_parents_subject', + variable_get('relativity_parents_label', t('Related Parents'))), + '#maxlength' => 250, + ); + break; } - } - return $block; + + $form['relativity_nav_types'] = array( + '#type' => 'select', + '#title' => t('Allowable Relativity Block Node types'), + '#default_value' => variable_get('relativity_nav_types', 'default'), + '#options' => relativity_node_list('none'), + '#description' => t('What types of nodes are allowed to be used in the relativity block? This setting applies to all relativity blocks.'), + '#size' => 5, + '#multiple' => TRUE, + ); + + return $form; + + case 'save': + // If $op is "save", we need to save settings from the configuration form. + // Since the first block is the only one that allows configuration, we + // need to check $delta to make sure we only save it. + variable_set('relativity_nav_types', $edit['relativity_nav_types']); + switch($delta) { + case 0; + variable_set('relativity_block_ancestors_subject', $edit['relativity_block_ancestors_subject']); + break; + case 1; + variable_set('relativity_block_children_subject', $edit['relativity_block_children_subject']); + break; + case 2; + variable_set('relativity_block_parents_subject', $edit['relativity_block_parents_subject']); + break; + } + return; + + case 'view': default: + // If $op is "view", then we need to generate the block for display + // purposes. The $delta parameter tells us which block is being requested. + + // see if we're viewing a node + if (arg(0) == 'node' && is_numeric(arg(1))) { + // see if it's a valid node + $node = node_load(arg(1)); + if (is_object($node) && node_access('view', $node)) { + switch ($delta) { + case 0: + $ancestors = relativity_load_ancestors($node); + if (is_array($ancestors) && count($ancestors) > 0) { + $block = array('subject' => variable_get('relativity_block_ancestors_subject', + variable_get('relativity_ancestors_label', t('Related Ancestors'))), + 'content' => theme('relativity_ancestors', $node, $ancestors, 0), + ); + } + break; + case 1: + $content = theme('relativity_show_children', $node, 0); + if ($content) { + $block = array('subject' => variable_get('relativity_block_children_subject', + variable_get('relativity_children_label', t('Related Items'))), + 'content' => $content, + ); + } + break; + case 2: + $content = theme('relativity_show_parents', $node, 0); + if ($content) { + $block = array('subject' => variable_get('relativity_block_parents_subject', + variable_get('relativity_parents_label', t('Related Parents'))), + 'content' => $content, + ); + } + break; + } + } + } + return $block; } } @@ -1027,21 +1124,18 @@ function relativity_nodeapi(&$node, $op, if (variable_get('relativity_show_nav_above_body', FALSE)) { $ancestors = relativity_load_ancestors($node); if (is_array($ancestors) && count($ancestors) > 0) { - $ancestor_array = array('#title' => variable_get('relativity_ancestors_label', t('Related Ancestors')), - '#children' => theme('relativity_ancestors', $node, $ancestors)); - $node->body = theme('fieldset', $ancestor_array) . $node->body; + $ancestor_theme = theme('relativity_ancestors', $node, $ancestors); + $node->body = $ancestor_theme . $node->body; } } if (variable_get('relativity_show_nav_below_body', FALSE)) { - if (isset($ancestor_array)) { - $node->body = $node->body . theme('fieldset', $ancestor_array); + if (isset($ancestor_theme)) { + $node->body = $node->body . $ancestor_theme; } else { $ancestors = relativity_load_ancestors($node); if (is_array($ancestors) && count($ancestors) > 0) { - $ancestor_array = array('#title' => variable_get('relativity_ancestors_label', t('Related Ancestors')), - '#children' => theme('relativity_ancestors', $node, $ancestors)); - $node->body = $node->body . theme('fieldset', $ancestor_array); + $node->body = $node->body . theme('relativity_ancestors', $node, $ancestors); } } } @@ -1094,16 +1188,16 @@ function relativity_sort_types($types=NU /* * Theme functions: - * - theme_relativity_show_parents($node) - * - theme_relativity_show_children($node) + * - theme_relativity_show_parents($node, $fieldset=1) + * - theme_relativity_show_children($node, $fieldset=1) + * - theme_relativity_ancestors($node, $ancestors, $fieldset=1) + * - theme_relativity_ancestor($ancestor, $indent=0) * - theme_relativity_links($types, $parent, $op='view') * - theme_relativity_link($title, $target, $parent_nid=0, $extra='') - * - theme_relativity_ancestors($node, $ancestors) - * - theme_relativity_ancestor($ancestor, $indent=0) * - theme_relativity_bullets($items) */ -function theme_relativity_show_parents($node) { +function theme_relativity_show_parents($node, $fieldset=1) { $output = ''; // load all nodes associated with this one as the parent nid and show links to all of them. @@ -1117,20 +1211,20 @@ function theme_relativity_show_parents($ foreach(relativity_sort_types() as $type) { foreach($parent_nodes as $parent_node) { if ($parent_node->type == $type) { - $links .= ''; + $output .= ''; } } } } - if ($links) { - $output .= theme('fieldset', array('#title' => variable_get('relativity_parents_label', t('Related Ancestors')), '#children' => $links)); + if ($output && $fieldset) { + $output = theme('fieldset', array('#title' => variable_get('relativity_parents_label', t('Related Ancestors')), + '#children' => $output)); } - return $output; } -function theme_relativity_show_children($node) { +function theme_relativity_show_children($node, $fieldset=1) { $output = ''; // load all nodes associated with this one as the parent nid and show links to all of them. @@ -1146,27 +1240,64 @@ function theme_relativity_show_children( if ($child_node->type == $type) { switch(variable_get('relativity_render_'. $node->type .'_'. $child_node->type, 'title')) { case 'title': - $links .= ''; + $output .= ''; break; case 'teaser': - $links .= ''; + $output .= ''; break; case 'body': - $links .= ''; + $output .= ''; break; } } } } } - if ($links) { - $output .= theme('fieldset', array('#title' => variable_get('relativity_children_label', t('Related Items')), '#children' => $links)); + if ($output && $fieldset) { + $output = theme('fieldset', array('#title' => variable_get('relativity_children_label', t('Related Items')), + '#children' => $output)); + } + + return $output; +} + +function theme_relativity_ancestors($node, $ancestors, $fieldset=1) { + $output = ''; + $indent = 0; + + foreach($ancestors as $ancestor) { + if (is_array($ancestor)) { + foreach($ancestor as $sibling) { + $output .= theme('relativity_ancestor', $sibling, $indent); + } + $indent++; + } + else { + $output .= theme('relativity_ancestor', $ancestor, $indent++); + } + } + + if ($output && $fieldset) { + $output = theme('fieldset', array('#title' => variable_get('relativity_ancestors_label', t('Related Ancestors')), + '#children' => $output)); } return $output; } +function theme_relativity_ancestor($ancestor, $indent=0) { + if (!$ancestor->type||!$ancestor->title||!$ancestor->nid) { + return ''; + } + $output .= '
'; + $output .= node_get_name($ancestor->type) . ': ' . l($ancestor->title, 'node/'.$ancestor->nid); + $output .= '
'; + return $output; +} + + + /** * This function themes the output of the $types array. It should * print a list of links to attach a node. @@ -1253,34 +1384,6 @@ function theme_relativity_link($title, $ return $output; } -function theme_relativity_ancestors($node, $ancestors) { - $content = ''; - $indent = 0; - - foreach($ancestors as $ancestor) { - if (is_array($ancestor)) { - foreach($ancestor as $sibling) { - $content .= theme('relativity_ancestor', $sibling, $indent); - } - $indent++; - } - else { - $content .= theme('relativity_ancestor', $ancestor, $indent++); - } - } - return $content; -} - -function theme_relativity_ancestor($ancestor, $indent=0) { - if (!$ancestor->type||!$ancestor->title||!$ancestor->nid) { - return ''; - } - $content .= '
'; - $content .= node_get_name($ancestor->type) . ': ' . l($ancestor->title, 'node/'.$ancestor->nid); - $content .= '
'; - return $content; -} - function theme_relativity_bullets($items) { return ""; }