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

Contents of /contributions/modules/nodelist/nodelist.module

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


Revision 1.13 - (show annotations) (download) (as text)
Mon Feb 26 09:52:34 2007 UTC (2 years, 8 months ago) by wmostrey
Branch: MAIN
CVS Tags: HEAD
Changes since 1.12: +3 -3 lines
File MIME type: text/x-php
#120005 by hedroom. Fixing custom content types not showing up.
1 <?php
2 /* $Id: nodelist.module,v 1.12 2007/01/23 12:49:31 wmostrey Exp $ */
3
4 /**
5 * Implementation of hook_help()
6 */
7 function nodelist_help($section = 'admin/help#nodelist') {
8 }
9
10 /**
11 * Implementation of hook_menu()
12 */
13 function nodelist_menu($may_cache) {
14 $items = array();
15
16 $items[] = array(
17 'path' => 'admin/settings/nodelist',
18 'title' => t('nodelist'),
19 'description' => t('Describes what the settings generally do.'),
20 'callback' => 'drupal_get_form',
21 'callback arguments' => array('nodelist_admin_settings'),
22 'access' => user_access('administer site configuration'),
23 'type' => MENU_NORMAL_ITEM, // optional
24 );
25
26 if ($may_cache) {
27 $items[] = array('title' => t('node list'),
28 'access' => user_access('access content'),
29 'path' => 'node/list',
30 'callback' => 'nodelist_page',
31 'type' => MENU_SUGGESTED_ITEM);
32 }
33 else {
34 if (arg(0) == 'vocabulary' && arg(1) && arg(2) == 'list') {
35 $items[] = array('title' => t('node list'),
36 'access' => user_access('access content'),
37 'path' => 'vocabulary/' . arg(1) . '/list',
38 'callback' => 'nodelist_page',
39 'callback arguments' => array('vocab', arg(1)),
40 'type' => MENU_CALLBACK);
41 }
42 else if (arg(0) == 'taxonomy' && arg(1) == 'term' && arg(2) && arg(3) == 'list') {
43 $items[] = array('title' => t('node list'),
44 'access' => user_access('access content'),
45 'path' => 'taxonomy/term/' . arg(2) . '/list',
46 'callback' => 'nodelist_page',
47 'callback arguments' => array('term', arg(2)),
48 'type' => MENU_CALLBACK);
49 }
50 }
51 return $items;
52 }
53
54 /**
55 * Implementation of hook_nodeapi()
56 */
57 function nodelist_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
58 switch ($op) {
59 case 'delete':
60 case 'insert':
61 case 'update':
62 cache_clear_all('nodelist:', TRUE);
63 }
64 }
65
66 /**
67 * Implementation of hook_page();
68 */
69 function nodelist_page($type = NULL, $id = NULL) {
70 //
71 // Determine the appropriate page title
72 //
73 switch ($type) {
74 case 'vocab':
75 $title = db_fetch_object(db_query('SELECT name FROM {vocabulary} WHERE vid = %d', $id));
76 drupal_set_title(t(variable_get('nodelist_vocab_page_title', 'node list: %id'), array('%id' => $title->name)));
77 break;
78
79 case 'term':
80 $title = db_fetch_object(db_query('SELECT name FROM {term_data} WHERE tid = %d', $id));
81 drupal_set_title(t(variable_get('nodelist_term_page_title', 'node list: %id'), array('%id' => $title->name)));
82 break;
83
84 default:
85 drupal_set_title(variable_get('nodelist_page_title', t('node list')));
86 }
87
88 print theme('page', nodelist_render($type, $id));
89 }
90
91 /**
92 * Render the node list. This function can be called
93 * from any page or block.
94 *
95 * @param $type Either 'vocab', 'term', or NULL
96 * @param $id The identifier for the type -- i.e. the vid, tid, or NULL
97 * @return An HTML-formatted string ready for printing to the screen
98 */
99 function nodelist_render($type = NULL, $id = NULL) {
100 $node_types = variable_get('nodelist_types', array());
101 $show_authors = variable_get('nodelist_show_authors', 0);
102 $show_dates = variable_get('nodelist_show_date', 0);
103 $show_children = variable_get('nodelist_show_children', 0);
104
105 if (!count($node_types)) {
106 drupal_set_message(t('Please select which node types to list.'), 'error');
107 drupal_goto('admin/settings/nodelist');
108 }
109
110 switch ($type) {
111 case 'vocab':
112 $type_join_sql = " LEFT JOIN {term_node} tn ON n.nid = tn.nid LEFT JOIN {term_data} td ON td.tid = tn.tid";
113 $type_where_sql = " AND td.vid = '" . db_escape_string($id) . "'";
114 break;
115
116 case 'term':
117 $type_join_sql = " LEFT JOIN {term_node} tn ON n.nid = tn.nid";
118 if ($show_children) {
119 $type_join_sql.= " LEFT JOIN {term_hierarchy} th ON tn.tid = th.tid";
120 }
121 $type_where_sql = " AND tn.tid = '" . db_escape_string($id) . "'";
122 if ($show_children) {
123 $type_where_sql.= " OR (th.parent = '" . db_escape_string($id) . "' AND tn.tid != '" . db_escape_string($id) . "')";
124 }
125 break;
126 }
127
128 $sql = "SELECT n.nid, n.title, n.created" . ($show_authors ? ", u.name" : "") . " FROM {node} n
129 " . $type_join_sql . "
130 " . ($show_authors ? " LEFT JOIN {users} u ON n.uid = u.uid" : "") . "
131 WHERE n.status=1 AND n.moderate=0 AND n.type IN ('" . implode("', '", $node_types) . "')
132 " . $type_where_sql . "
133 ORDER BY n.title, n.created";
134 $sql = db_rewrite_sql($sql);
135 $md5 = md5($sql);
136
137
138 //
139 // Different users have different permissions, and this affects the result of this function.
140 // To speed things up (at the expense of some database storage), we cache the result of
141 // this function with the md5 of the sql as the key. Theoretically, many users will
142 // share the same permissions, thus the sql will be the same for many people.
143 //
144 if ($cached == cache_get('nodelist:'.$md5)) {
145 $output = $cached->data;
146 }
147 else {
148 $result = db_query($sql);
149
150 //
151 // Organize the nodes
152 //
153 $sorted = array();
154 while ($row = db_fetch_object($result)) {
155 //
156 // The regular expression printed here is the result of calling
157 // character_class_regexp(array('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nd', 'Nl', 'No'))
158 // from as defined at http://acko.net/dumpx/ucd-charclass.phps. This regular
159 // expression matches Unicode letters and numbers within preg_replace().
160 // However, strtolower() does not recognize international Unicode characters,
161 // so upper- and lower-case variants will be listed separately.
162 //
163 $key = strtolower(preg_replace('/^.*?([\x{30}-\x{39}\x{41}-\x{5a}\x{61}-\x{7a}\x{aa}\x{b2}\x{b3}\x{b5}\x{b9}\x{ba}\x{bc}-\x{be}\x{c0}-\x{d6}\x{d8}-\x{f6}\x{f8}-\x{241}\x{250}-\x{2c1}\x{2c6}-\x{2d1}\x{2e0}-\x{2e4}\x{2ee}\x{37a}\x{386}\x{388}-\x{38a}\x{38c}\x{38e}-\x{3a1}\x{3a3}-\x{3ce}\x{3d0}-\x{3f5}\x{3f7}-\x{481}\x{48a}-\x{4ce}\x{4d0}-\x{4f9}\x{500}-\x{50f}\x{531}-\x{556}\x{559}\x{561}-\x{587}\x{5d0}-\x{5ea}\x{5f0}-\x{5f2}\x{621}-\x{63a}\x{640}-\x{64a}\x{660}-\x{669}\x{66e}\x{66f}\x{671}-\x{6d3}\x{6d5}\x{6e5}\x{6e6}\x{6ee}-\x{6fc}\x{6ff}\x{710}\x{712}-\x{72f}\x{74d}-\x{76d}\x{780}-\x{7a5}\x{7b1}\x{904}-\x{939}\x{93d}\x{950}\x{958}-\x{961}\x{966}-\x{96f}\x{97d}\x{985}-\x{98c}\x{98f}\x{990}\x{993}-\x{9a8}\x{9aa}-\x{9b0}\x{9b2}\x{9b6}-\x{9b9}\x{9bd}\x{9ce}\x{9dc}\x{9dd}\x{9df}-\x{9e1}\x{9e6}-\x{9f1}\x{9f4}-\x{9f9}\x{a05}-\x{a0a}\x{a0f}\x{a10}\x{a13}-\x{a28}\x{a2a}-\x{a30}\x{a32}\x{a33}\x{a35}\x{a36}\x{a38}\x{a39}\x{a59}-\x{a5c}\x{a5e}\x{a66}-\x{a6f}\x{a72}-\x{a74}\x{a85}-\x{a8d}\x{a8f}-\x{a91}\x{a93}-\x{aa8}\x{aaa}-\x{ab0}\x{ab2}\x{ab3}\x{ab5}-\x{ab9}\x{abd}\x{ad0}\x{ae0}\x{ae1}\x{ae6}-\x{aef}\x{b05}-\x{b0c}\x{b0f}\x{b10}\x{b13}-\x{b28}\x{b2a}-\x{b30}\x{b32}\x{b33}\x{b35}-\x{b39}\x{b3d}\x{b5c}\x{b5d}\x{b5f}-\x{b61}\x{b66}-\x{b6f}\x{b71}\x{b83}\x{b85}-\x{b8a}\x{b8e}-\x{b90}\x{b92}-\x{b95}\x{b99}\x{b9a}\x{b9c}\x{b9e}\x{b9f}\x{ba3}\x{ba4}\x{ba8}-\x{baa}\x{bae}-\x{bb9}\x{be6}-\x{bf2}\x{c05}-\x{c0c}\x{c0e}-\x{c10}\x{c12}-\x{c28}\x{c2a}-\x{c33}\x{c35}-\x{c39}\x{c60}\x{c61}\x{c66}-\x{c6f}\x{c85}-\x{c8c}\x{c8e}-\x{c90}\x{c92}-\x{ca8}\x{caa}-\x{cb3}\x{cb5}-\x{cb9}\x{cbd}\x{cde}\x{ce0}\x{ce1}\x{ce6}-\x{cef}\x{d05}-\x{d0c}\x{d0e}-\x{d10}\x{d12}-\x{d28}\x{d2a}-\x{d39}\x{d60}\x{d61}\x{d66}-\x{d6f}\x{d85}-\x{d96}\x{d9a}-\x{db1}\x{db3}-\x{dbb}\x{dbd}\x{dc0}-\x{dc6}\x{e01}-\x{e30}\x{e32}\x{e33}\x{e40}-\x{e46}\x{e50}-\x{e59}\x{e81}\x{e82}\x{e84}\x{e87}\x{e88}\x{e8a}\x{e8d}\x{e94}-\x{e97}\x{e99}-\x{e9f}\x{ea1}-\x{ea3}\x{ea5}\x{ea7}\x{eaa}\x{eab}\x{ead}-\x{eb0}\x{eb2}\x{eb3}\x{ebd}\x{ec0}-\x{ec4}\x{ec6}\x{ed0}-\x{ed9}\x{edc}\x{edd}\x{f00}\x{f20}-\x{f33}\x{f40}-\x{f47}\x{f49}-\x{f6a}\x{f88}-\x{f8b}\x{1000}-\x{1021}\x{1023}-\x{1027}\x{1029}\x{102a}\x{1040}-\x{1049}\x{1050}-\x{1055}\x{10a0}-\x{10c5}\x{10d0}-\x{10fa}\x{10fc}\x{1100}-\x{1159}\x{115f}-\x{11a2}\x{11a8}-\x{11f9}\x{1200}-\x{1248}\x{124a}-\x{124d}\x{1250}-\x{1256}\x{1258}\x{125a}-\x{125d}\x{1260}-\x{1288}\x{128a}-\x{128d}\x{1290}-\x{12b0}\x{12b2}-\x{12b5}\x{12b8}-\x{12be}\x{12c0}\x{12c2}-\x{12c5}\x{12c8}-\x{12d6}\x{12d8}-\x{1310}\x{1312}-\x{1315}\x{1318}-\x{135a}\x{1369}-\x{137c}\x{1380}-\x{138f}\x{13a0}-\x{13f4}\x{1401}-\x{166c}\x{166f}-\x{1676}\x{1681}-\x{169a}\x{16a0}-\x{16ea}\x{16ee}-\x{16f0}\x{1700}-\x{170c}\x{170e}-\x{1711}\x{1720}-\x{1731}\x{1740}-\x{1751}\x{1760}-\x{176c}\x{176e}-\x{1770}\x{1780}-\x{17b3}\x{17d7}\x{17dc}\x{17e0}-\x{17e9}\x{17f0}-\x{17f9}\x{1810}-\x{1819}\x{1820}-\x{1877}\x{1880}-\x{18a8}\x{1900}-\x{191c}\x{1946}-\x{196d}\x{1970}-\x{1974}\x{1980}-\x{19a9}\x{19c1}-\x{19c7}\x{19d0}-\x{19d9}\x{1a00}-\x{1a16}\x{1d00}-\x{1dbf}\x{1e00}-\x{1e9b}\x{1ea0}-\x{1ef9}\x{1f00}-\x{1f15}\x{1f18}-\x{1f1d}\x{1f20}-\x{1f45}\x{1f48}-\x{1f4d}\x{1f50}-\x{1f57}\x{1f59}\x{1f5b}\x{1f5d}\x{1f5f}-\x{1f7d}\x{1f80}-\x{1fb4}\x{1fb6}-\x{1fbc}\x{1fbe}\x{1fc2}-\x{1fc4}\x{1fc6}-\x{1fcc}\x{1fd0}-\x{1fd3}\x{1fd6}-\x{1fdb}\x{1fe0}-\x{1fec}\x{1ff2}-\x{1ff4}\x{1ff6}-\x{1ffc}\x{2070}\x{2071}\x{2074}-\x{2079}\x{207f}-\x{2089}\x{2090}-\x{2094}\x{2102}\x{2107}\x{210a}-\x{2113}\x{2115}\x{2119}-\x{211d}\x{2124}\x{2126}\x{2128}\x{212a}-\x{212d}\x{212f}-\x{2131}\x{2133}-\x{2139}\x{213c}-\x{213f}\x{2145}-\x{2149}\x{2153}-\x{2183}\x{2460}-\x{249b}\x{24ea}-\x{24ff}\x{2776}-\x{2793}\x{2c00}-\x{2c2e}\x{2c30}-\x{2c5e}\x{2c80}-\x{2ce4}\x{2cfd}\x{2d00}-\x{2d25}\x{2d30}-\x{2d65}\x{2d6f}\x{2d80}-\x{2d96}\x{2da0}-\x{2da6}\x{2da8}-\x{2dae}\x{2db0}-\x{2db6}\x{2db8}-\x{2dbe}\x{2dc0}-\x{2dc6}\x{2dc8}-\x{2dce}\x{2dd0}-\x{2dd6}\x{2dd8}-\x{2dde}\x{3005}-\x{3007}\x{3021}-\x{3029}\x{3031}-\x{3035}\x{3038}-\x{303c}\x{3041}-\x{3096}\x{309d}-\x{309f}\x{30a1}-\x{30fa}\x{30fc}-\x{30ff}\x{3105}-\x{312c}\x{3131}-\x{318e}\x{3192}-\x{3195}\x{31a0}-\x{31b7}\x{31f0}-\x{31ff}\x{3220}-\x{3229}\x{3251}-\x{325f}\x{3280}-\x{3289}\x{32b1}-\x{32bf}\x{3400}\x{4db5}\x{4e00}\x{9fbb}\x{a000}-\x{a48c}\x{a800}\x{a801}\x{a803}-\x{a805}\x{a807}-\x{a80a}\x{a80c}-\x{a822}\x{ac00}\x{d7a3}\x{f900}-\x{fa2d}\x{fa30}-\x{fa6a}\x{fa70}-\x{fad9}\x{fb00}-\x{fb06}\x{fb13}-\x{fb17}\x{fb1d}\x{fb1f}-\x{fb28}\x{fb2a}-\x{fb36}\x{fb38}-\x{fb3c}\x{fb3e}\x{fb40}\x{fb41}\x{fb43}\x{fb44}\x{fb46}-\x{fbb1}\x{fbd3}-\x{fd3d}\x{fd50}-\x{fd8f}\x{fd92}-\x{fdc7}\x{fdf0}-\x{fdfb}\x{fe70}-\x{fe74}\x{fe76}-\x{fefc}\x{ff10}-\x{ff19}\x{ff21}-\x{ff3a}\x{ff41}-\x{ff5a}\x{ff66}-\x{ffbe}\x{ffc2}-\x{ffc7}\x{ffca}-\x{ffcf}\x{ffd2}-\x{ffd7}\x{ffda}-\x{ffdc}\x{10000}-\x{1000b}\x{1000d}-\x{10026}\x{10028}-\x{1003a}\x{1003c}\x{1003d}\x{1003f}-\x{1004d}\x{10050}-\x{1005d}\x{10080}-\x{100fa}\x{10107}-\x{10133}\x{10140}-\x{10178}\x{1018a}\x{10300}-\x{1031e}\x{10320}-\x{10323}\x{10330}-\x{1034a}\x{10380}-\x{1039d}\x{103a0}-\x{103c3}\x{103c8}-\x{103cf}\x{103d1}-\x{103d5}\x{10400}-\x{1049d}\x{104a0}-\x{104a9}\x{10800}-\x{10805}\x{10808}\x{1080a}-\x{10835}\x{10837}\x{10838}\x{1083c}\x{1083f}\x{10a00}\x{10a10}-\x{10a13}\x{10a15}-\x{10a17}\x{10a19}-\x{10a33}\x{10a40}-\x{10a47}\x{1d400}-\x{1d454}\x{1d456}-\x{1d49c}\x{1d49e}\x{1d49f}\x{1d4a2}\x{1d4a5}\x{1d4a6}\x{1d4a9}-\x{1d4ac}\x{1d4ae}-\x{1d4b9}\x{1d4bb}\x{1d4bd}-\x{1d4c3}\x{1d4c5}-\x{1d505}\x{1d507}-\x{1d50a}\x{1d50d}-\x{1d514}\x{1d516}-\x{1d51c}\x{1d51e}-\x{1d539}\x{1d53b}-\x{1d53e}\x{1d540}-\x{1d544}\x{1d546}\x{1d54a}-\x{1d550}\x{1d552}-\x{1d6a5}\x{1d6a8}-\x{1d6c0}\x{1d6c2}-\x{1d6da}\x{1d6dc}-\x{1d6fa}\x{1d6fc}-\x{1d714}\x{1d716}-\x{1d734}\x{1d736}-\x{1d74e}\x{1d750}-\x{1d76e}\x{1d770}-\x{1d788}\x{1d78a}-\x{1d7a8}\x{1d7aa}-\x{1d7c2}\x{1d7c4}-\x{1d7c9}\x{1d7ce}-\x{1d7ff}\x{20000}\x{2a6d6}\x{2f800}-\x{2fa1d}]).*/u', '$1', $row->title));
164 $sorted[$key][strtolower($row->title)][$row->nid] = l($row->title, 'node/' . $row->nid);
165 $show_dates && $sorted[$key][strtolower($row->title)][$row->nid] .= ' <span class="created">' . format_date($row->created) . "</span>\n";
166 $show_authors && $sorted[$key][strtolower($row->title)][$row->nid] .= ' <span class="author">' . $row->name . "</span>\n";
167 }
168
169
170 //
171 // Sort and display the nodes
172 //
173 ksort($sorted);
174
175 $list = array();
176 foreach (array_keys($sorted) AS $key) {
177 $list[] = '<a href="' . $_SERVER['REQUEST_URI'] . "#$type-$id-$key\">$key</a> ";
178 }
179 $output .= '<div class="node-list-index">' . theme('item_list', $list) . "</div>\n";
180
181 foreach ($sorted AS $key => $group) {
182 ksort($group);
183
184 $list = array();
185 foreach ($group AS $item => $duplicates) {
186 ksort($duplicates);
187 foreach ($duplicates AS $li) {
188 $list[] = $li;
189 }
190 }
191
192 $output .= '<div class="node-list">' . theme('item_list', $list, "<a name=\"$type-$id-$key\"></a>$key") . "</div>\n";
193 }
194
195 cache_set('nodelist:'.$md5, $table='cache', $output);
196 }
197
198 return $output;
199 }
200
201
202 /**
203 * Implementation of hook_settings()
204 */
205 function nodelist_admin_settings() {
206
207 $form['nodelist_page_title'] = array(
208 '#type' => 'textfield',
209 '#title' => t('Page title for all nodes'),
210 '#default_value' => variable_get('nodelist_page_title', t('Content list')),
211 '#size' => 32,
212 '#maxlength' => 128,
213 '#required' => TRUE,
214 );
215
216 $form['nodelist_vocab_page_title'] = array(
217 '#type' => 'textfield',
218 '#title' => t('Page title for nodes in a vocabulary'),
219 '#default_value' => variable_get('nodelist_vocab_page_title', t('Content list for for <em>%id</em>')),
220 '#size' => 32,
221 '#maxlength' => 128,
222 '#required' => TRUE,
223 );
224
225 $form['nodelist_term_page_title'] = array(
226 '#type' => 'textfield',
227 '#title' => t('Page title for nodes in a taxonomy term'),
228 '#default_value' => variable_get('nodelist_term_page_title', t('Content list for <em>%id</em>')),
229 '#size' => 32,
230 '#maxlength' => 128,
231 '#required' => TRUE,
232 );
233
234
235 $form['nodelist_show_authors'] = array(
236 '#type' => 'checkbox',
237 '#title' => t('Show node author'),
238 '#default_value' => variable_get('nodelist_show_authors', 0),
239 );
240
241 $form['nodelist_show_date'] = array(
242 '#type' => 'checkbox',
243 '#title' => t('Show date of node creation'),
244 '#default_value' => variable_get('nodelist_show_date', 0),
245 );
246
247 $form['nodelist_show_children'] = array(
248 '#type' => 'checkbox',
249 '#title' => t('Include node children when using therm hierarchy'),
250 '#default_value' => variable_get('nodelist_show_children', 0),
251 );
252
253 $node_types = node_get_types('names');
254
255 $form['nodelist_types'] = array(
256 '#type' => 'select',
257 '#title' => t('Node types to include'),
258 '#default_value' => variable_get('nodelist_types',array()),
259 '#options' => $node_types,
260 '#multiple' => TRUE,
261 );
262
263 return system_settings_form($form);
264 }
265 ?>

  ViewVC Help
Powered by ViewVC 1.1.2