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

Contents of /contributions/modules/nodequeue_builder/nodequeue_builder.module

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


Revision 1.4 - (show annotations) (download) (as text)
Tue Jan 9 22:49:49 2007 UTC (2 years, 10 months ago) by tbarregren
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +4 -4 lines
File MIME type: text/x-php
Put the copyright notice right.
1 <?php
2
3 /* $Id: nodequeue_builder.module,v 1.3 2007/01/09 22:40:06 tbarregren Exp $ */
4
5 /* Node Queue Builder - a Drupal module that allows privileged users to add
6 * selected nodes to a node queue.
7 *
8 * Copyright (C) 2007 Thomas Barregren.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 */
24
25
26 /**
27 * The name of the default view provided by this module.
28 */
29 define('NODEQUEUE_BUILDER_DEFAULT_VIEW', 'nodequeue_builder');
30
31 /**
32 * The default number of nodes per page.
33 */
34 define('NODEQUEUE_BUILDER_DEFAULT_LIMIT', 10);
35
36 /**
37 * The path to the settings page.
38 */
39 define('NODEQUEUE_BUILDER_PATH_SETTINGS', 'admin/content/nodequeue/builder/settings');
40
41 /**
42 * The path to the builder page.
43 */
44 define('NODEQUEUE_BUILDER_PATH_BUILDER', 'admin/content/nodequeue/builder');
45
46 /**
47 * The permission for administrating Node Queue Builder.
48 */
49 define('NODEQUEUE_BUILDER_PERM_ADMINISTER', 'administer nodequeue_builder');
50
51 /**
52 * Implementation of hook_help().
53 *
54 * Returns various help texts.
55 */
56 function nodequeue_builder_help($section='admin/help#nodequeue_builder') {
57 switch ($section) {
58 case NODEQUEUE_BUILDER_PATH_SETTINGS:
59 return _nodequeue_builder_help_admin();
60 case NODEQUEUE_BUILDER_PATH_BUILDER:
61 return _nodequeue_builder_help_builder();
62 case 'admin/help#nodequeue_builder':
63 return _nodequeue_builder_help_help();
64 }
65 }
66
67 /**
68 * Implementation of hook_perm().
69 */
70 function nodequeue_builder_perm()
71 {
72 return array(NODEQUEUE_BUILDER_PERM_ADMINISTER);
73 }
74
75 /**
76 * Implementation of hook_menu().
77 */
78 function nodequeue_builder_menu($may_cache) {
79 $items = array();
80 if ($may_cache) {
81
82 // Node queue Builder administration
83 $items[] = array(
84 'path' => NODEQUEUE_BUILDER_PATH_SETTINGS,
85 'access' => user_access(NODEQUEUE_BUILDER_PERM_ADMINISTER),
86 'callback' => 'drupal_get_form',
87 'callback arguments' => array('nodequeue_builder_admin'),
88 'title' => t('Settings'),
89 'description' => t('Settings for Node Queue Builder'),
90 'type' => MENU_LOCAL_TASK
91 );
92
93 }
94 else {
95
96 // Node Queue Builder itself
97 $items[] = array(
98 'path' => NODEQUEUE_BUILDER_PATH_BUILDER,
99 'access' => user_access('administer nodequeue'),
100 'callback' => 'drupal_get_form',
101 'callback arguments' => array('nodequeue_builder_builder'),
102 'title' => t('Build'),
103 'description' => t('Select and add nodes to a node queue'),
104 'type' => MENU_LOCAL_TASK
105 );
106
107 }
108 return $items;
109 }
110
111 /**
112 * Returns the settoings form.
113 */
114 function nodequeue_builder_admin()
115 {
116
117 // Add a selector with possible views that can be used as node list by the builder.
118 $form['nodequeue_builder_view'] = array(
119 '#type' => 'select',
120 '#title' => 'Builder\'s view',
121 '#description' => 'Select the ' . l('view' , 'admin/build/views') . ' that will provide the builder\'s node list.',
122 '#options' => _nodequeue_builder_list_views(),
123 '#default_value' => variable_get('nodequeue_builder_view', NODEQUEUE_BUILDER_DEFAULT_VIEW),
124 '#multiple' => false,
125 '#required' => true
126 );
127
128 // Add a selector with possible number of nodes to show on each page
129 $form['nodequeue_builder_limit'] = array(
130 '#type' => 'select',
131 '#title' => 'Nodes per builder page',
132 '#description' => 'The number of nodes to display per page in the builder.',
133 '#options' => array(10 => 10, 20 => 20, 50 => 50, 100 => 100, 0 => 'All nodes'),
134 '#default_value' => variable_get('nodequeue_builder_limit', NODEQUEUE_BUILDER_DEFAULT_LIMIT),
135 '#multiple' => false,
136 '#required' => true
137 );
138
139 // Return system settings form.
140 return system_settings_form($form);
141
142 }
143
144 /**
145 * Returns the builder form.
146 */
147 function nodequeue_builder_builder()
148 {
149
150 // Load the view that will provide the node list.
151 $view_name = variable_get('nodequeue_builder_view', NODEQUEUE_BUILDER_DEFAULT_VIEW);
152 $view = views_get_view($view_name);
153
154 // Handle the case that the view has been removed.
155 if(!isset($view)) {
156
157 // Set an error message
158 $message = t('The view "!view" is no longer avaiable.', array('!view' => $view_name));
159 watchdog('nodequeue_builder', $message, WATCHDOG_ERROR);
160 drupal_set_message($message, 'error');
161
162 // Present an explanation
163 $form['message'] = array(
164 '#value' => t(
165 '<p>Node Queue Builder uses the view "!view" as its source of nodes. But it is no longer avaiable.</p>
166 <p>Please, <a href="!views-url">add "!view"</a> or <a href="!settings-url">select another view</a>.</p>',
167 array(
168 '!view' => $view_name,
169 '!views-url' => url('http://drupal/admin/build/views/add'),
170 '!settings-url' => url(NODEQUEUE_BUILDER_PATH_SETTINGS))
171 )
172 );
173
174 // Nothing more to do.
175 return $form;
176
177 }
178
179 // Get the number of nodes to be shown on each page.
180 $limit = $view_name = variable_get('nodequeue_builder_limit', NODEQUEUE_BUILDER_DEFAULT_LIMIT);
181
182 // Let views module make the query.
183 $view = views_build_view('result', $view, array(), $limit > 0, $limit);
184 $result = $view['result'];
185
186 // Form for selecting nodes to be added.
187 while ($node = db_fetch_object($result)) {
188 $node = node_load($node->nid);
189 $nodes[$node->nid] = '';
190 $form['title'][$node->nid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed)));
191 $form['name'][$node->nid] = array('#value' => node_get_types('name', $node));
192 $form['created'][$node->nid] = array('#value' => format_date($node->created, 'small'));
193 $form['username'][$node->nid] = array('#value' => theme('username', $node));
194 }
195 $form['nid'] = array('#type' => 'checkboxes', '#options' => $nodes);
196
197 // Pager
198 $form['pager'] = array('#value' => theme('pager', NULL, $limit, 0));
199
200 // Form for selecting a queue to be updated.
201 $form['add'] = array(
202 '#type' => 'fieldset',
203 '#title' => t('Add to node queue'),
204 '#prefix' => '<div class="container-inline">',
205 '#suffix' => '</div>'
206 );
207 $form['add']['qid'] = array('#type' => 'select', '#options' => _nodequeue_builder_list_queues());
208 $form['add']['submit'] = array('#type' => 'submit', '#value' => t('Update'));
209
210 // Return the form.
211 return $form;
212
213 }
214
215 /**
216 * Theme the table of avaiable nodes to build a queue from.
217 */
218 function theme_nodequeue_builder_builder($form) {
219
220 // Render the queue selection and update button
221 $output .= drupal_render($form['add']);
222
223 // Render the table with the nodes to select from
224 $header = array(theme('table_select_header_cell'), t('Title'), t('Type'), t('Created'), t('Author'));
225 if (isset($form['title']) && is_array($form['title'])) {
226 foreach (element_children($form['title']) as $key) {
227 $row = array();
228 $row[] = drupal_render($form['nid'][$key]);
229 $row[] = drupal_render($form['title'][$key]);
230 $row[] = drupal_render($form['name'][$key]);
231 $row[] = drupal_render($form['created'][$key]);
232 $row[] = drupal_render($form['username'][$key]);
233 $rows[] = $row;
234 }
235 }
236 else {
237 $rows[] = array(array('data' => t('No nodes available.'), 'colspan' => '6'));
238 }
239 $output .= theme('table', $header, $rows);
240
241 // Render the pager
242 if ($form['pager']['#value']) {
243 $output .= drupal_render($form['pager']);
244 }
245
246 $output .= drupal_render($form);
247
248 // Return the HTML
249 return $output;
250
251 }
252
253 function nodequeue_builder_builder_submit($form_id, $form_values) {
254 $qid = $form_values['qid'];
255 foreach ($form_values['nid'] as $nid)
256 nodequeue_queue_add($qid, $nid);
257 return "admin/content/nodequeue/view/$qid";
258 }
259
260 /**
261 * Implementation of hook_views_default_views().
262 */
263 function nodequeue_builder_views_default_views()
264 {
265 $view = new stdClass();
266 $view->name = NODEQUEUE_BUILDER_DEFAULT_VIEW;
267 $view->description = 'Nodes avaiable for Node Queue Builder';
268 $view->access = array ();
269 $view->view_args_php = '';
270 $view->sort = array(
271 array(
272 'tablename' => 'node',
273 'field' => 'sticky',
274 'sortorder' => 'DESC',
275 'options' => ''
276 ),
277 array(
278 'tablename' => 'node',
279 'field' => 'created',
280 'sortorder' => 'DESC',
281 'options' => 'normal'
282 )
283 );
284 $view->argument = array();
285 $view->field = array();
286 $view->filter = array(
287 array(
288 'tablename' => 'node',
289 'field' => 'type',
290 'operator' => 'OR',
291 'options' => '',
292 'value' => array (0 => 'story')
293 ),
294 array(
295 'tablename' => 'node',
296 'field' => 'status',
297 'operator' => '=',
298 'options' => '',
299 'value' => '1'
300 ),
301 array (
302 'tablename' => 'node',
303 'field' => 'distinct',
304 'operator' => '=',
305 'options' => '',
306 'value' => array ()
307 )
308 );
309 $view->exposed_filter = array();
310 $view->requires = array(node);
311 $views[$view->name] = $view;
312 return $views;
313 }
314
315
316 /* PRIVATE DECLARATIONS *******************************************************
317 *
318 * Following declarations are private to this module. They can change and be
319 * removed at any time. Don't depend on them!
320 *****************************************************************************/
321
322 /**
323 * Returns an array of avaiable views.
324 * */
325 function _nodequeue_builder_list_views()
326 {
327 $views = array(NODEQUEUE_BUILDER_DEFAULT_VIEW => NODEQUEUE_BUILDER_DEFAULT_VIEW);
328 $result = db_query("SELECT name FROM {view_view} ORDER BY name");
329 while ($view = db_fetch_object($result)) {
330 $views[$view->name] = $view->name;
331 }
332 return $views;
333 }
334
335 /**
336 * Returns an array of avaiable queues.
337 */
338 function _nodequeue_builder_list_queues()
339 {
340 $queues = nodequeue_handler_queuelist();
341 return isset($queues) ? $queues : array();
342 }
343
344 /**
345 * Returns short help text about the settings page.
346 */
347 function _nodequeue_builder_help_admin() {
348 return t('
349 <p>Settings for the Node Queue Builder. For more information, see the !help.</p>
350 ',
351 array('!help' => l(t('help page'), 'admin/help/nodequeue_builder'))
352 );
353 }
354
355 /**
356 * Returns short help text about the builder page.
357 */
358 function _nodequeue_builder_help_builder() {
359 return t('
360 <p>Add checked nodes to the selected queue. For more information, see the !help.</p>
361 ',
362 array('!help' => l(t('help page'), 'admin/help/nodequeue_builder'))
363 );
364 }
365
366 /**
367 * Returns full help text.
368 */
369 function _nodequeue_builder_help_help() {
370 $version = str_replace(array('$Re'.'vision:', ' $'), array('', ''), '$Revision: 1.3 $');
371 $year = substr('$Date: 2007/01/09 22:40:06 $', 7, 4);
372 return '
373 <!-- Copyright (C) ' . $year . ' Thomas Barregren <mailto:thomas@webbredaktoren.se> -->
374 <style type="text/css" media="all">
375 code,
376 kbd
377 {
378 padding: 1px;
379 font-family: "Bitstream Vera Sans Mono", Monaco, "Lucida Console", monospace;
380 background-color: #EDF1F3;
381 }
382 </style>
383 ' . t( '
384 <p>TODO</p>
385 <!--break-->
386 <h2>Background</h2>
387 <p>TODO</p>
388 <h2>Install</h2>
389 <ol>
390 <li>TODO</li>
391 </ol>
392 <h2>Configuration</h2>
393 <ol>
394 <li>TODO</li>
395 </ol>
396 <h2>Usage</h2>
397 <ol>
398 <li>TODO</li>
399 </ol>
400 <h2>License</h2>
401 <p>Node Queue Builder revision !version. Copyright &copy; !year <a href="mailto:thomas@webbredaktoren.se">Thomas Barregren</a>.</p>
402 <p>Node Queue Builder is free software; you can redistribute it and/or modify it under the terms of the <a href="http://www.gnu.org/licenses/gpl.html#SEC1">GNU General Public License</a> as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.</p>
403 <p>Node Queue Builder is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the <a href="http://www.gnu.org/licenses/gpl.html#SEC1">GNU General Public License</a> for more details.</p>
404 <p>You should have received a copy of the <a href="http://www.gnu.org/licenses/gpl.html#SEC1">GNU General Public License</a> along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.</p>
405 ',
406 array('!version' => $version, '!year' => $year)
407 );
408 }

  ViewVC Help
Powered by ViewVC 1.1.2