/[drupal]/contributions/modules/booktree/booktree.module
ViewVC logotype

Contents of /contributions/modules/booktree/booktree.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.12 - (show annotations) (download) (as text)
Mon Jan 26 21:37:53 2009 UTC (10 months ago) by uccio
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-7--1
Changes since 1.11: +13 -16 lines
File MIME type: text/x-php
New: Initial port to drupal 7.x
Issue: db_abstraction layer not work propely(db_rewrite_sql and placeholders)
1 <?php
2 // $Id: booktree.module,v 1.11.2.1 2008/10/12 21:26:16 uccio Exp $
3
4
5
6 function booktree_help($path, $arg) {
7 $output = '';
8 switch ($path) {
9 case "admin/help#booktree":
10 $output = '<p>'. t('This module create a tree rappresentation of one book.') .'</p>';
11 break;
12 }
13 return $output;
14 }
15
16 function booktree_perm() {
17 return array('access booktree');
18 }
19
20
21 function booktree_menu() {
22
23
24 $items['booktree'] = array(
25 'title' => t('BookTree'),
26 'description' => t('Book Index.'),
27 'page callback' => 'booktree_indice',
28 'access arguments' => array('access booktree'),
29 'type' => MENU_NORMAL_ITEM,
30 );
31
32 $items['admin/settings/booktree'] = array(
33 'title' => t('Settings of BookTree'),
34 'description' => t('Manage the tree-view of book.'),
35 'page callback' => 'drupal_get_form',
36 'page arguments' => array('booktree_configure'),
37 'access arguments' => array('access administration pages'),
38 'type' => MENU_NORMAL_ITEM,
39 );
40
41 return $items;
42 }
43
44
45 function booktree_configure() {
46 $form = array();
47 $form['booktree_start'] = array(
48 '#type' => 'textfield',
49 '#title' => t('Root Node ID'),
50 '#required' => TRUE,
51 '#default_value' => variable_get('booktree_start', 5),
52 '#description' => t('Start point of the tree (the root).')
53
54 );
55
56 $form['booktree_deep'] = array(
57 '#type' => 'textfield',
58 '#title' => t('Deep Max'),
59 '#required' => TRUE,
60 '#default_value' => variable_get('booktree_deep', 5),
61 '#description' => t('Max deep of the tree with the root.')
62
63 );
64 $form['booktree_trim'] = array(
65 '#type' => 'textfield',
66 '#title' => t('Trimmer'),
67 '#required' => TRUE,
68 '#default_value' => variable_get('booktree_trim', 45),
69 '#description' => t('Max lenght of title.')
70
71 );
72 return system_settings_form($form);
73
74 }
75
76
77 /*
78 * This will output the book from the start point specified in the
79 * arguments, or take the default in the configuration
80 * The arguments are in the order: start node/depth/max title length
81 * If only two arguments are present then the max title length is set to 256
82 */
83
84 function booktree_indice() {
85 drupal_add_css(drupal_get_path('module', 'booktree') .'/booktree.css', 'module', 'all', FALSE);
86 if (arg(1)) {
87 $booktree_start = arg(1);
88 arg(2) ? $maxricursione = arg(2)+2 : $maxricursione=variable_get('booktree_deep', 5)+2;
89 arg(3) ? $trimval = arg(3) : $trimval = 256;
90 }
91 else {
92 $booktree_start = variable_get('booktree_start', 1);
93 $maxricursione = variable_get('booktree_deep', 5)+2;
94 $trimval = variable_get('booktree_trim', 35);
95 }
96
97 $node = node_load($booktree_start);
98 drupal_set_title($node->title);
99 $content = "<p>$node->body</p>";
100 $ricursione = 1;
101 $content .= booktree_mostra_figli($node->book['mlid'],$node->nid,$node->title,$ricursione,$maxricursione,$trimval,$node->book['mlid']);
102 return $content;
103 }
104
105 function booktree_mostra_figli( $mlid,$nid,$tit,$ricursione,$maxricursione,$trimval,$mlid_start) {
106 if ($ricursione<$maxricursione){
107 $c = '';
108 $content = '';
109 $sql= "SELECT DISTINCT n.nid as nid, m.plid as plid, m.mlid as mlid, n.title as title
110 FROM {book} as b
111 inner join {menu_links} as m ON b.mlid = m.mlid
112 inner join {node} as n ON n.nid = b.nid
113 WHERE m.plid = $mlid
114 ORDER by m.weight, n.title
115 ";
116 $children = db_query($sql);
117 //Now hide a root book node
118 if ($mlid != $mlid_start) {
119 $content .= "<li class=\"booktree\">" . l(truncate_utf8($tit, $trimval, TRUE, TRUE),'node/'.$nid , $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE ) ."</li>";
120 }
121 $ricursione++;
122 while ($child = db_fetch_object($children)) {
123 $c .= booktree_mostra_figli($child->mlid,$child->nid,$child->title,$ricursione,$maxricursione,$trimval,$mlid_start);
124 }
125 //now write content only if necessary
126 if (strlen($c) > 2){
127 $content .= "<ul class=\"booktree\">\n". $c. "</ul>\n";
128 }
129 return $content;
130 }
131 else{
132 return '';
133 }
134 }

  ViewVC Help
Powered by ViewVC 1.1.2