| 1 |
<?php |
<?php |
| 2 |
// $Id: booktree.module,v 1.11.2.5 2009/08/10 21:57:57 uccio Exp $ |
// $Id: booktree.module,v 1.11.2.6 2009/09/14 20:11:36 uccio Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* The booktree module fot drupal render a simple tree of books |
* The booktree module is usefull to draw a simple tree index of drupal books |
| 7 |
* |
* |
| 8 |
*/ |
*/ |
| 9 |
|
|
| 69 |
'#required' => TRUE, |
'#required' => TRUE, |
| 70 |
'#default_value' => variable_get('booktree_trim', 45), |
'#default_value' => variable_get('booktree_trim', 45), |
| 71 |
'#description' => t('Max length of title.') |
'#description' => t('Max length of title.') |
|
|
|
| 72 |
); |
); |
| 73 |
return system_settings_form($form); |
return system_settings_form($form); |
| 74 |
|
|
| 88 |
$booktree_start = arg(1); |
$booktree_start = arg(1); |
| 89 |
arg(2) ? $maxricursione = arg(2)+2 : $maxricursione=variable_get('booktree_deep', 5)+2; |
arg(2) ? $maxricursione = arg(2)+2 : $maxricursione=variable_get('booktree_deep', 5)+2; |
| 90 |
arg(3) ? $trimval = arg(3) : $trimval = 256; |
arg(3) ? $trimval = arg(3) : $trimval = 256; |
| 91 |
} |
} |
| 92 |
else { |
else { |
| 93 |
$booktree_start = variable_get('booktree_start', 1); |
$booktree_start = variable_get('booktree_start', 1); |
| 94 |
$maxricursione = variable_get('booktree_deep', 5)+2; |
$maxricursione = variable_get('booktree_deep', 5)+2; |
| 95 |
$trimval = variable_get('booktree_trim', 35); |
$trimval = variable_get('booktree_trim', 35); |
| 96 |
} |
} |
| 97 |
|
|
| 98 |
$node = node_load(array('nid' => $booktree_start)); |
$node = node_load(array('nid' => $booktree_start)); |
| 99 |
drupal_set_title(check_plain($node->title)); |
drupal_set_title(check_plain($node->title)); |
| 100 |
$content = '<p>'. check_markup($node->body, $node->format, FALSE) .'</p>'; |
$content = '<p>'. check_markup($node->body, $node->format, FALSE) .'</p>'; |
| 101 |
$ricursione = 1; |
$ricursione = 1; |
| 102 |
$content .= booktree_mostra_figli($node->book['mlid'], $node->nid, $node->title, $ricursione, $maxricursione, $trimval, $node->book['mlid']); |
$content .= _booktree_mostra_figli($node->book['mlid'], $node->nid, $node->title, $ricursione, $maxricursione, $trimval, $node->book['mlid']); |
| 103 |
return $content; |
return $content; |
| 104 |
} |
} |
| 105 |
|
|
| 106 |
function booktree_mostra_figli( $mlid, $nid, $tit, $ricursione, $maxricursione, $trimval, $mlid_start) { |
|
| 107 |
|
function booktree_render_tree($nid = NULL) { |
| 108 |
|
if ($nid) { |
| 109 |
|
drupal_add_css(drupal_get_path('module', 'booktree') .'/booktree.css', 'module', 'all', FALSE); |
| 110 |
|
$maxricursione = variable_get('booktree_deep', 5)+2; |
| 111 |
|
$node = node_load($nid); |
| 112 |
|
return _booktree_mostra_figli($node->book['mlid'], $node->nid, $node->title, 1, $maxricursione, 256, $node->book['mlid']); |
| 113 |
|
|
| 114 |
|
} |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
function _booktree_mostra_figli( $mlid, $nid, $tit, $ricursione, $maxricursione, $trimval, $mlid_start) { |
| 118 |
if ($ricursione<$maxricursione) { |
if ($ricursione<$maxricursione) { |
| 119 |
$sql= "SELECT DISTINCT n.nid as nid, m.plid as plid, m.mlid as mlid, n.title as title ,m.weight |
$sql= "SELECT DISTINCT n.nid as nid, m.plid as plid, m.mlid as mlid, n.title as title ,m.weight |
| 120 |
FROM {book} as b |
FROM {book} as b |
| 130 |
} |
} |
| 131 |
$ricursione++; |
$ricursione++; |
| 132 |
while ($child = db_fetch_object($children)) { |
while ($child = db_fetch_object($children)) { |
| 133 |
$c .= booktree_mostra_figli($child->mlid, $child->nid, $child->title, $ricursione, $maxricursione, $trimval, $mlid_start); |
$c .= _booktree_mostra_figli($child->mlid, $child->nid, $child->title, $ricursione, $maxricursione, $trimval, $mlid_start); |
| 134 |
} |
} |
| 135 |
//now write content only if necessary |
//now write content only if necessary |
| 136 |
if (strlen($c) > 2) { |
if (strlen($c) > 2) { |
| 141 |
else { |
else { |
| 142 |
return ''; |
return ''; |
| 143 |
} |
} |
| 144 |
} |
} |
|
|
|
|
function booktree_render_tree($nid = NULL) { |
|
|
if ($nid) { |
|
|
drupal_add_css(drupal_get_path('module', 'booktree') .'/booktree.css', 'module', 'all', FALSE); |
|
|
$maxricursione = variable_get('booktree_deep', 5)+2; |
|
|
$node = node_load($nid); |
|
|
return booktree_mostra_figli($node->book['mlid'], $node->nid, $node->title, 1, $maxricursione, 256, $node->book['mlid']); |
|
|
|
|
|
} |
|
|
} |
|