REFERENCE: Booktree module

The current release of the booktree module is located here.

This is the code for the Drupal 5.1.2 booktree module:

<?php
// $Id: booktree.module,v 1.6 2007/02/09 11:58:44 uccio Exp $
// Tested with drupal 5.0.b2 over IIS with PHP 4 and Mysql 4.18nt

function booktree_help($section) {
switch ($section) {
case 'admin/modules#description':
// This description is shown in the listing at admin/modules.
return t('This module create a tree rappresentation of one book');
case 'booktree':
// Here is some help text for a custom page.
return t('A tree index of book.');
}
}


function booktree_perm() {
return array('access booktree');
}


function booktree_menu($may_cache) {
$items = array();

if ($may_cache) {
$items[] = array('path' => 'booktree', 'title' => t('booktree'),
'callback' => 'booktree_indice',
'access' => user_access('access booktree'));

$items[] = array('path' => 'admin/settings/booktree',
'title' => t('Settings of BookTree'),
'type' => MENU_NORMAL_ITEM,
'description' => t('Manage the tree-view of book.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('booktree_configure'),
'access' => user_access('administer site configuration'),
'weight' => 2,
);

}

return $items;
}


function booktree_configure() {
$form = array();
$form['booktree_start'] = array(
'#type' => 'textfield',
'#title' => t('Root Node ID'),
'#required' => TRUE,
'#default_value' => variable_get('booktree_start', 15),
'#description' => t('Start point of the tree (the root).')

);

$form['booktree_deep'] = array(
'#type' => 'textfield',
'#title' => t('Deep Max'),
'#required' => TRUE,
'#default_value' => variable_get('booktree_deep', 5),
'#description' => t('Max deep of the tree with the root.')

);
$form['booktree_trim'] = array(
'#type' => 'textfield',
'#title' => t('Trimmer'),
'#required' => TRUE,
'#default_value' => variable_get('booktree_trim', 5),
'#description' => t('Max lenght of title.')

);
return system_settings_form($form);





}




function booktree_indice() {
$node = node_load(array('nid' =>variable_get('booktree_start', 1)));
$content = "<p>$node->body</p>";
$content .="<ul>\n";
$children = db_query(db_rewrite_sql('SELECT distinct n.nid, b.weight, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight, n.title'), $node->nid);
$ricursione=1;
$maxricursione=variable_get('booktree_deep', 5)+2;
$trimval=variable_get('booktree_trim', 35);
$content .= booktree_mostra_figli($node->nid,$node->title,$ricursione,$maxricursione,$trimval);
print theme('page', $content);



}

function booktree_mostra_figli( $nid,$tit,$ricursione,$maxricursione,$trimval ) {
if ($ricursione<$maxricursione)
{
$children = db_query(db_rewrite_sql('SELECT distinct n.nid, b.weight, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE b.parent = %d ORDER BY b.weight, n.title'), $nid);
$content .= "<li>" . l(truncate_utf8($tit, $trimval, TRUE, TRUE),'node/'.$nid , $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE ) ."</li>";
$content .="<ul>\n";
$ricursione++;
while ($child = db_fetch_object($children)) {
$content .= booktree_mostra_figli($child->nid,$child->title,$ricursione,$maxricursione,$trimval);}
$content .="</ul>\n";
return $content;}
else {
return '';
}
}
?>

 

Comments

booktree_mostra_figli

I haven't programmed in php, but I recognize ~95% of the syntax and items in this code (from C). I don't recognize where the html indenting is done, but it must be in the booktree_mostra_figli function. Mostly this needs good comments, spacing and indenting for readability, and minor translation from italian member names. What kind of environment do you use for debugging? Hit or miss, inserting test code, or is there some IDE that you use to debug? Maybe we can get together sometime and clean this up. Maybe I'll find a reference and bone up on php.

code review

Mark would monday 9am at the 16th willamette coffee joint work with your schedule for module/PHP analysis?

I have been tyring get the eclipse IDE system going for a number of different languages and general web development.  There is an eclipse PHP IDE project underway that I would like to use. 

 My understanding is that it is that eclipse is one of the best open source IDE frameworks you may want to take a peak at it.  

attachment extensions

Sorry, I didn't notice the "code review" comment until this morning. Pick another day, 9 am is usually good for me.

I haven't been able to fix the blocking of attachments with other file extensions. I am trying to attach .tif and .m files to Orthologia twist description and notes. I DID succesfully (at least apparently) add these, and other, extensions to the Settings|File upload list, and they appear correctly there. But on trying to attach a file, the old list of allowed extensions is displayed (in a failure message). I looked at other settings, but it sure appears that this is where the list of allowed extensions is stored. Too bad that you can't choose to have no restrictions, or only block particular extensions.

Post new comment

Security question, designed to stop automated spam bots