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

Contents of /contributions/modules/ddblock/ddblock.module

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


Revision 1.11 - (show annotations) (download) (as text)
Sun Sep 13 09:33:54 2009 UTC (2 months, 1 week ago) by ppblaauw
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +1023 -300 lines
File MIME type: text/x-php
by ppblaauw: Dev release (Additional pager functionality and bug fixes), see CHANGELOG.txt
1 <?php
2 // $Id: ddblock.module,v 1.10 2009/02/26 14:18:29 ppblaauw Exp $
3
4
5 /**
6 * @file
7 * Enables your site to display dynamic content in a block.
8 */
9
10 /**
11 * Implementation of hook_help().
12 */
13 function ddblock_help($path, $arg) {
14 switch ($path) {
15 case "admin/help#ddblock":
16 $output = '<p>'. t('Display content dynamically in a block using the jQuery Cycle plugin and the jQuery Easing plugin') .'</p>';
17 $output .='<p>'. t('There are three methods to provide content for a dynamic display block. An input folder with images, a node from a content type or by making an instance of any block to use the block content of the original block as content for the dynamic display block') .'</p>';
18 return $output;
19 }
20 }
21
22 function ddblock_init_js_css() {
23 // get module path to dynamic display block module
24 $ddblock_path = drupal_get_path('module', 'ddblock');
25
26 //add jcycle plugin
27 drupal_add_js($ddblock_path .'/js/jquery.cycle.all.min.js', 'module');
28
29 //add easing plugin
30 drupal_add_js($ddblock_path .'/js/jquery.easing.1.1.1.js', 'module');
31
32 // add ddblock js file
33 drupal_add_js($ddblock_path .'/js/json2.pack.js', 'module');
34
35 // add ddblock js file
36 drupal_add_js($ddblock_path .'/js/ddblock.js', 'module');
37
38 // add Cascading style sheet
39 drupal_add_css($ddblock_path .'/ddblock.css', 'module', 'all', TRUE);
40 };
41
42
43 /**
44 * Implementation of hook_menu().
45 */
46 function ddblock_menu() {
47
48 // add ddblock
49 $items['admin/settings/ddblock'] = array(
50 'title' => t('Dynamic display block'),
51 'description' => t('Configure settings for dynamic display block module.'),
52 'page callback' => 'drupal_get_form',
53 'page arguments' => array('ddblock_block_add_form'),
54 'access arguments' => array('administer dynamic display blocks'),
55 'type' => MENU_NORMAL_ITEM,
56 'file' => 'ddblock.admin.inc',
57 );
58
59 // list tab in settings page.
60 $items['admin/settings/ddblock/list'] = array(
61 'title' => t('List'),
62 'page arguments' => array('ddblock_block_add_form'),
63 'access arguments' => array('administer dynamic display blocks'),
64 'type' => MENU_DEFAULT_LOCAL_TASK,
65 'weight' => -10,
66 );
67
68 // Settings tab in settings page.
69 $items['admin/settings/ddblock/settings'] = array(
70 'title' => t('Settings'),
71 'page arguments' => array('ddblock_settings_form'),
72 'access arguments' => array('administer dynamic display blocks'),
73 'type' => MENU_LOCAL_TASK,
74 'weight' => 10,
75 'file' => 'ddblock.admin.inc',
76 );
77
78 // Edit dynamic display block.
79 $items['admin/settings/ddblock/edit/%'] = array(
80 'title' => t('Edit dynamic display block'),
81 'page callback' => 'drupal_get_form',
82 'page arguments' => array('ddblock_block_edit_form', 4),
83 'access arguments' => array('administer dynamic display blocks'),
84 'type' => MENU_CALLBACK,
85 'file' => 'ddblock.admin.inc',
86 );
87
88 // Delete dynamic display block or instance.
89 $items['admin/settings/ddblock/delete/%'] = array(
90 'title' => t('Delete dynamic display block'),
91 'page callback' => 'drupal_get_form',
92 'page arguments' => array('ddblock_block_confirm_delete_form', 4),
93 'access arguments' => array('administer dynamic display blocks'),
94 'type' => MENU_CALLBACK,
95 'file' => 'ddblock.admin.inc',
96 );
97
98 // Add ddblock instance.
99 $items['admin/settings/ddblock/instances'] = array(
100 'title' => t('Instances'),
101 'description' => t('Create and delete instances of blocks.'),
102 'page callback' => 'ddblock_instances',
103 'access callback' => 'user_access',
104 'access arguments' => array('administer blocks'),
105 'type' => MENU_LOCAL_TASK,
106 'weight' => -1,
107 );
108
109 // Ahah update nodes to choose of content type.
110 $items['ddblock/js/select_nodes'] = array(
111 'page callback' => 'ddblock_select_nodes_js',
112 'access arguments' => array('access content'),
113 'type' => MENU_CALLBACK,
114 );
115
116 return $items;
117 }
118
119 /**
120 * Implementation of hook_perm().
121 */
122 function ddblock_perm() {
123 return array('administer dynamic display blocks', 'view dynamic display blocks');
124 }
125
126 /**
127 * Implementation of hook_block().
128 */
129 function ddblock_block($op='list', $delta=0, $edit = array()) {
130 switch ($op) {
131 // show info in block list on block administration page.
132 case 'list':
133 $blocks = ddblock_get_blocks(NULL);
134 $list = array();
135 foreach ($blocks as $block) {
136 $list[$block->delta] = array('info' => check_plain($block->title));
137 // Don't cache blocks.
138 $list[$block->delta]['cache'] = BLOCK_NO_CACHE;
139 }
140 return $list;
141
142 // the configuration page of the block.
143 case 'configure':
144 // if block is a ddblock instance invoke configure option of original block.
145 // with form_alter the ddblock settings are added.
146 $block = ddblock_get_blocks($delta);
147 if ($block->enabled) {
148 $module = $block->module;
149 $delta_original = $block->delta_original;
150 return module_invoke($module, 'block', $op, $delta_original);
151 }
152
153 // if block is a ddblock invoke the block configure page.
154 return ddblock_block_configure($delta);
155
156 // save configuraton settings.
157 case 'save':
158 //all blocks are instances of ddblock.
159 $module = 'ddblock';
160 ddblock_set_configuration_settings($module, $delta, $edit);
161 return;
162
163 // show block content (this is set to default).
164 case 'view': default:
165 //all blocks are instances of ddblock.
166 $module = 'ddblock';
167
168 if (user_access('view dynamic display blocks')) {
169 $block['subject'] = ddblock_subject($module, $delta);
170 $block['content'] = ddblock_content($module, $delta);
171 if (!empty($block['content'])) {
172 return $block;
173 }
174 }
175 return;
176 }
177 }
178
179 /**
180 * Return all or one dynamic display block.
181 *
182 * @param $delta
183 * Optional. Retreive a single block based on this delta. If none specified,
184 * all blocks are returned.
185 * @param $reset
186 * Optional. Boolean value to reset the interal cache of this function.
187 * @return
188 * array of dynamic display blocks.
189 */
190 function ddblock_get_blocks($delta = NULL, $reset = FALSE) {
191 static $blocks;
192
193 if (!isset($blocks) || $reset) {
194 $blocks = array();
195 $result = db_query("SELECT * FROM {ddblock_block}");
196 while ($block = db_fetch_object($result)) {
197 $blocks[$block->delta] = $block;
198 }
199 }
200
201 return is_numeric($delta) ? $blocks[$delta] : $blocks;
202 }
203
204 /**
205 * Block configuration page of dynamic display block blocks added to standard block configuration page.
206 *
207 * @param $delta
208 * Blocknumber of the block.
209 *
210 * @return
211 * form with configuration settings.
212 */
213 function ddblock_block_configure($delta) {
214
215 // get saved or default configuration settings.
216 $configuration_settings = ddblock_get_configuration_settings('ddblock', $delta);
217
218 $container = _ddblock_get_variable($configuration_settings['container'], 'img');
219 $content_type = _ddblock_get_variable($configuration_settings['content_type'], 'none');
220 $custom_jquery = _ddblock_get_variable($configuration_settings['custom_jquery'], '');
221 // get folder relative to the drupal folder settings
222 $folder = _ddblock_get_variable($configuration_settings['folder'], 'images/ddblock');
223 $fx = _ddblock_get_variable($configuration_settings['fx'], "fade");
224 $height = _ddblock_get_variable($configuration_settings['height'], 195);
225 $ignore_files = _ddblock_get_variable($configuration_settings['ignore_files'], '');
226 $image_height = _ddblock_get_variable($configuration_settings['image_height'], 183);
227 $image_width = _ddblock_get_variable($configuration_settings['image_width'], 183);
228 $imgcache_toggle = _ddblock_get_variable($configuration_settings['imgcache_toggle'], 0);
229 $imgcache_slide = _ddblock_get_variable($configuration_settings['imgcache_slide'], '<none>');
230 $imgcache_pager_item = _ddblock_get_variable($configuration_settings['imgcache_pager_item'], '<none>');
231 $input_type = _ddblock_get_variable($configuration_settings['input_type'], 'images');
232 $max_image = _ddblock_get_variable($configuration_settings['max_image'], 5);
233 $next = _ddblock_get_variable($configuration_settings['next'], 0);
234 $nodes = _ddblock_get_variable($configuration_settings['nodes'], '');
235 $node_body_teaser = _ddblock_get_variable($configuration_settings['node_body_teaser'], 'body');
236 $order = _ddblock_get_variable($configuration_settings['order'], 'asc');
237 $overflow = _ddblock_get_variable($configuration_settings['overflow'], 1);
238 $pause = _ddblock_get_variable($configuration_settings['pause'], 1);
239 $pager_toggle = _ddblock_get_variable($configuration_settings['pager_toggle'], 0);
240 $pager = _ddblock_get_variable($configuration_settings['pager'], 'none');
241 $pager_event = _ddblock_get_variable($configuration_settings['pager_event'], 'click');
242 $pager2 = _ddblock_get_variable($configuration_settings['pager2'], 0);
243 $pager2_event = _ddblock_get_variable($configuration_settings['pager2_event'], 'click');
244 $pager2_position = _ddblock_get_variable($configuration_settings['pager2_position'], array('slide' => 'slide', 'pager' => 0));
245 $pager2_slide_prev = _ddblock_get_variable($configuration_settings['pager2_slide_prev'], '');
246 $pager2_slide_next = _ddblock_get_variable($configuration_settings['pager2_slide_next'], '');
247 $pager2_slide_hide = _ddblock_get_variable($configuration_settings['pager2_slide_hide'], 1);
248 $pager2_pager_prev = _ddblock_get_variable($configuration_settings['pager2_pager_prev'], 'prev');
249 $pager2_pager_next = _ddblock_get_variable($configuration_settings['pager2_pager_next'], 'next');
250 $pager2_pager_hide = _ddblock_get_variable($configuration_settings['pager2_pager_hide'], 1);
251 $pager_fast = _ddblock_get_variable($configuration_settings['pager_fast'], 1);
252 $pager_pause = _ddblock_get_variable($configuration_settings['pager_pause'], 1);
253 if (($pager == 'number-pager') || ($pager2 == 1)) {
254 $pager_height = _ddblock_get_variable($configuration_settings['pager_height'], 25);
255 $pager_width = _ddblock_get_variable($configuration_settings['pager_width'], 195);
256 }
257 else {
258 $pager_height = _ddblock_get_variable($configuration_settings['pager_height'], 63);
259 $pager_width = _ddblock_get_variable($configuration_settings['pager_width'], 195);
260 }
261 $speed = _ddblock_get_variable($configuration_settings['speed'], 500);
262 $timeout = _ddblock_get_variable($configuration_settings['timeout'], 5000);
263 $width = _ddblock_get_variable($configuration_settings['width'], 195);
264
265 // get module path to dynamic display block module
266 $ddblock_path = drupal_get_path('module', 'ddblock');
267 // add ddblock js file
268 drupal_add_js($ddblock_path .'/js/ddblock.admin.js', 'module');
269
270 // Need this for AJAX.
271 $form['#cache'] = TRUE;
272
273 // content settings: what to use as content for the dynamic display block.
274 $form['content'] = array(
275 '#type' => 'fieldset',
276 '#collapsible' => TRUE,
277 '#title' => t('Content settings'),
278 '#prefix' => '<div id="ddblock-content-settings">',
279 '#suffix' => '</div>',
280 '#weight' => -3,
281 );
282
283 $options = array('images' => t('Image folder'), 'nodes' => t('Content type'));
284 $form['content']['input_type'] = array(
285 '#type' => 'select',
286 '#title' => t('Input type'),
287 '#default_value' => $input_type,
288 '#options' => $options,
289 '#multiple' => FALSE,
290 '#required' => TRUE,
291 '#description' => t("Input of the dynamic display block."),
292 '#weight' => -7,
293
294 );
295
296 // image folder settings.
297 $form['content']['image_folder'] = array(
298 '#type' => 'fieldset',
299 '#collapsible' => TRUE,
300 '#title' => t('Image folder settings'),
301 '#prefix' => '<div id="ddblock-image-folder-settings-wrapper">',
302 '#suffix' => '</div>',
303 '#weight' => -6,
304 );
305
306 $form['content']['image_folder']['folder'] = array(
307 '#type' => 'textfield',
308 '#title' => t('Image Folder'),
309 '#default_value' => $folder,
310 '#size' => 25,
311 '#maxlength' => 100,
312 '#required' => FALSE,
313 '#description' => t("The folder containing image files to be used as the content of dynamic display block. The folder is relative to the drupal files path in admin > settings > file-system. e.g. <strong>images/ddblock</strong>."),
314 );
315
316 $form['content']['image_folder']['ignore_files'] = array(
317 '#type' => 'textfield',
318 '#title' => t('Ignore files'),
319 '#default_value' => $ignore_files,
320 '#required' => FALSE,
321 '#description' => t("Ignore these files to be shown. e.g. ignore file with _thumbnail, _preview in the file_name.<br />
322 You can use a comma seprated list"),
323 );
324
325
326 $form['content']['image_folder']['max_image'] = array(
327 '#type' => 'textfield',
328 '#title' => t('Number of images'),
329 '#default_value' => $max_image,
330 '#required' => FALSE,
331 '#description' => t("The number of images to show in the block."),
332 );
333
334 // content type settings.
335 $form['content']['content_types'] = array(
336 '#type' => 'fieldset',
337 '#collapsible' => TRUE,
338 '#title' => t('Content type settings'),
339 '#prefix' => '<div id="ddblock-content-types-settings-wrapper">',
340 '#suffix' => '</div>',
341 '#weight' => -5,
342 );
343
344 //get possible content types from settings.
345 $node_types = variable_get('ddblock_node_type', array());
346 foreach ($node_types as $key => $value ) {
347 if ($value) {
348 $content_types[$key] = $value;
349 }
350 }
351
352 // add a none option to the content types to choose from.
353 $content_types['none'] = t("None");
354
355 $form['content']['content_types']['content_type'] = array(
356 '#type' => 'select',
357 '#title' => t('Content Type'),
358 '#default_value' => $content_type,
359 '#options' => $content_types,
360 '#description' => t("The nodes of the content type to be used as content of dynamic display block."),
361 '#attributes' => array('class' => 'content-type-select'),
362 '#ahah' => array(
363 'path' => 'ddblock/js/select_nodes',
364 'wrapper' => 'select-nodes-wrapper',
365 'effect' => 'slide',
366 ),
367 );
368
369 ddblock_select_nodes_form($form, $content_type, $nodes);
370
371 $options = array('body' => t('Body'),
372 'teaser' => t('Teaser'),
373 );
374 $form['content']['content_types']['node_body_teaser'] = array(
375 '#type' => 'radios',
376 '#title' => t('Node content'),
377 '#default_value' => $node_body_teaser,
378 '#options' => $options,
379 '#multiple' => FALSE,
380 '#required' => TRUE,
381 '#description' => t("Show node body or teaser"),
382 );
383
384
385 // if image cache module exist make it possible to use image cache presets
386 if ((module_exists('imagecache')) && (is_array(imagecache_presets()))) {
387 $imgcache_options = array('<none>' => '<none>');
388 // get imagecache presets using imagecache function
389 foreach (imagecache_presets() as $preset) {
390 $name = $preset['presetname'];
391 $imgcache_options[$name] = $name;
392 }
393 $imgcache_slide_desc = t("Imagecache preset to use for slide image");
394 $imgcache_pager_item_desc = t("Imagecache preset to use for pager-item image. Only for themes that use an image in the pager");
395
396 // Image cache toggle
397 $form['block_settings']['imgcache_toggle'] = array(
398 '#type' => 'checkbox',
399 '#title' => t('Use imagecache presets'),
400 '#default_value' => $imgcache_toggle,
401 '#required' => FALSE,
402 '#description' => t("Use imagecache presets for images"),
403 '#weight' => -5,
404 );
405
406 // Image cache settings.
407 $form['block_settings']['imgcache'] = array(
408 '#type' => 'fieldset',
409 '#collapsible' => TRUE,
410 '#title' => t('Image cache preset settings'),
411 '#prefix' => '<div id="ddblock-imgcache-settings-wrapper"'. $extra .'>',
412 '#suffix' => '</div>',
413 '#weight' => -4,
414 );
415
416 $form['block_settings']['imgcache']['imgcache_slide'] = array(
417 '#type' => 'select',
418 '#title' => t('Imagecache slide image'),
419 '#default_value' => $imgcache_slide,
420 '#options' => $imgcache_options,
421 '#multiple' => FALSE,
422 '#required' => FALSE,
423 '#description' => $imgcache_slide_desc,
424 '#weight' => 1,
425 );
426
427 $form['block_settings']['imgcache']['imgcache_pager_item'] = array(
428 '#type' => 'select',
429 '#title' => t('Imagecache pager-item image'),
430 '#default_value' => $imgcache_pager_item,
431 '#options' => $imgcache_options,
432 '#multiple' => FALSE,
433 '#required' => FALSE,
434 '#description' => $imgcache_pager_item_desc,
435 '#weight' => 2,
436 );
437
438 }
439
440 // content container settings.
441 $form['content']['content_container'] = array(
442 '#type' => 'fieldset',
443 '#collapsible' => TRUE,
444 '#title' => t('Content container settings'),
445 '#weight' => -4,
446 );
447
448 $form['content']['content_container']['container'] = array(
449 '#type' => 'textfield',
450 '#title' => t('Content container'),
451 '#default_value' => $container,
452 '#required' => FALSE,
453 '#description' => t("Container of the content to show, eg. img, to show images."),
454 );
455
456 $form['content']['content_container']['overflow'] = array(
457 '#type' => 'checkbox',
458 '#title' => t('Overflow hidden'),
459 '#default_value' => $overflow,
460 '#required' => FALSE,
461 '#description' => t("Hide the overflow of the container"),
462 );
463
464 $form['content']['content_container']['height'] = array(
465 '#type' => 'textfield',
466 '#title' => t('Height'),
467 '#default_value' => $height,
468 '#required' => FALSE,
469 '#description' => t("Height of the content to show"),
470 );
471
472 $form['content']['content_container']['width'] = array(
473 '#type' => 'textfield',
474 '#title' => t('Width'),
475 '#default_value' => $width,
476 '#required' => FALSE,
477 '#description' => t("Width of the content to show"),
478 );
479
480 // Image settings.
481 $form['content']['images'] = array(
482 '#type' => 'fieldset',
483 '#collapsible' => TRUE,
484 '#title' => t('Image settings'),
485 '#description' => t('Set to 0 (zero) for both the height and the width to be able to use the original image size or imagecache presets'),
486 '#weight' => -3,
487 );
488 $form['content']['images']['image_height'] = array(
489 '#type' => 'textfield',
490 '#title' => t('Height'),
491 '#default_value' => $image_height,
492 '#required' => FALSE,
493 '#description' => t("Height of the image to show"),
494 );
495
496 $form['content']['images']['image_width'] = array(
497 '#type' => 'textfield',
498 '#title' => t('Width'),
499 '#default_value' => $image_width,
500 '#required' => FALSE,
501 '#description' => t("Width of the image to show"),
502 );
503
504 //wrapper for ddblock block settings
505 $form['block_settings']['#prefix'] = '<div id="ddblock-block-settings">';
506 $form['block_settings']['#suffix'] = '</div>';
507
508 $form['block_settings']['settings'] = array(
509 '#type' => 'fieldset',
510 '#collapsible' => TRUE,
511 '#title' => t('Settings'),
512 '#weight' => -2,
513 );
514
515 $options =_ddblock_get_effects();
516 $form['block_settings']['settings']['fx'] = array(
517 '#type' => 'select',
518 '#title' => t('Transition Effect'),
519 '#default_value' => $fx,
520 '#options' => $options,
521 '#multiple' => FALSE,
522 '#required' => TRUE,
523 '#description' => t("The transition effect between content.<br />(all for random effect per slide, none for no effect)<br />Multiple effects can be set in the Custom jQuery Cycle Plugin Settings."),
524 );
525
526 $options = drupal_map_assoc(array(0, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 15000, 20000));
527
528 $form['block_settings']['settings']['speed'] = array(
529 '#type' => 'select',
530 '#title' => t('Speed'),
531 '#default_value' => $speed,
532 '#options' => $options,
533 '#required' => TRUE,
534 '#description' => t("Speed of the transitions (1000 = 1 second, 0 = direct)."),
535 );
536
537 $options = drupal_map_assoc(array(0, 250, 500, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 15000, 20000, 30000));
538 $form['block_settings']['settings']['timeout'] = array(
539 '#type' => 'select',
540 '#title' => t('Timeout'),
541 '#default_value' => $timeout,
542 '#options' => $options,
543 '#required' => TRUE,
544 '#description' => t("The time (in milliseconds) between transitions (1000 = 1 second, 0 to disable auto advance)."),
545 );
546
547 $options = array(
548 'none' => t('None'),
549 'asc' => t('Ascending'),
550 'desc' => t('Descending'),
551 'random' => t('Random'),
552 );
553 $form['block_settings']['settings']['order'] = array(
554 '#type' => 'radios',
555 '#title' => t('Sort Order'),
556 '#default_value' => $order,
557 '#options' => $options,
558 '#multiple' => FALSE,
559 '#required' => TRUE,
560 '#description' => t("The display order of the content. None for using the original content order."),
561 );
562
563 $form['block_settings']['settings']['pause'] = array(
564 '#type' => 'checkbox',
565 '#title' => t('Pause'),
566 '#default_value' => $pause,
567 '#description' => t("Enable users to pause the cycle by hovering on the content."),
568 );
569
570 $form['block_settings']['settings']['next'] = array(
571 '#type' => 'checkbox',
572 '#title' => t('Next'),
573 '#default_value' => $next,
574 '#description' => t("Enable users to advanced to the next content by clicking on the content."),
575 );
576
577 // pager settings toggle
578 $form['block_settings']['settings']['pager_toggle'] = array(
579 '#type' => 'checkbox',
580 '#title' => t('Use Pager'),
581 '#default_value' => $pager_toggle,
582 '#required' => FALSE,
583 '#description' => t("Use a pager to select slides"),
584 );
585
586 // pager settings.
587 // show fields when using pager
588 $extra = (empty($pager_toggle)) ? ' style="display:none"' : '';
589 $form['block_settings']['settings']['pager_settings'] = array(
590 '#type' => 'fieldset',
591 '#collapsible' => TRUE,
592 '#collapsed' => FALSE,
593 '#prefix' => '<div id="ddblock-pager-settings-wrapper"'. $extra .'>',
594 '#suffix' => '</div>',
595 '#title' => t('Pager settings'),
596 );
597
598 if ($input_type == 'images') {
599 $options = array(
600 'none' => t('None'),
601 'number-pager' => t('Number pager'),
602 'image-pager' => t('Image pager'),
603 );
604 }
605 else {
606 $options = array(
607 'none' => t('None'),
608 'number-pager' => t('Number Pager'),
609 );
610 }
611
612 $form['block_settings']['settings']['pager_settings']['pager'] = array(
613 '#type' => 'select',
614 '#title' => t('Pager'),
615 '#default_value' => $pager,
616 '#options' => $options,
617 '#required' => TRUE,
618 '#description' => t("Add a pager to the block."),
619 );
620
621 $options = array(
622 'click' => t('Click'),
623 'mouseover' => t('Mouseover'),
624 );
625
626 $form['block_settings']['settings']['pager_settings']['pager_event'] = array(
627 '#type' => 'select',
628 '#title' => t('Pager event'),
629 '#default_value' => $pager_event,
630 '#options' => $options,
631 '#required' => FALSE,
632 '#description' => t("The event on which the pager reacts."),
633 );
634
635 $form['block_settings']['settings']['pager_settings']['pager_height'] = array(
636 '#type' => 'textfield',
637 '#title' => t('Height'),
638 '#default_value' => $pager_height,
639 '#required' => FALSE,
640 '#description' => t("Height of the pager"),
641 );
642
643 $form['block_settings']['settings']['pager_settings']['pager_width'] = array(
644 '#type' => 'textfield',
645 '#title' => t('Width'),
646 '#default_value' => $pager_width,
647 '#required' => FALSE,
648 '#description' => t("Width of the pager"),
649 );
650 $form['block_settings']['settings']['pager_settings']['pager_fast'] = array(
651 '#type' => 'checkbox',
652 '#title' => t('Fast Pager'),
653 '#default_value' => $pager_fast,
654 '#required' => FALSE,
655 '#description' => t("Use fast pager event when clicked or hovered."),
656 );
657
658 $form['block_settings']['settings']['pager_settings']['pager_pause'] = array(
659 '#type' => 'checkbox',
660 '#title' => t('Pager pause'),
661 '#default_value' => $pager_pause,
662 '#required' => FALSE,
663 '#description' => t("Pause the slideshow when pager hovered."),
664 );
665
666 /* $form['block_settings']['settings']['pager2'] = array(
667 '#type' => 'checkbox',
668 '#title' => t('Prev/Next Pager'),
669 '#default_value' => $pager2,
670 '#required' => FALSE,
671 '#description' => t("Add a previous/next pager."),
672 );
673
674 // pager settings.
675 // show fields when using pager
676 $extra = (empty($pager2)) ? ' style="display:none"' : '';
677 $form['block_settings']['settings']['pager2_settings'] = array(
678 '#type' => 'fieldset',
679 '#collapsible' => TRUE,
680 '#collapsed' => FALSE,
681 '#prefix' => '<div id="ddblock-pager2-settings-wrapper"'. $extra .'>',
682 '#suffix' => '</div>',
683 '#title' => t('Prev/next pager settings'),
684 );
685
686 $options = array(
687 'click' => t('Click'),
688 'mouseover' => t('Mouseover'),
689 );
690
691 $form['block_settings']['settings']['pager2_settings']['pager2_event'] = array(
692 '#type' => 'select',
693 '#title' => t('Pager event'),
694 '#default_value' => $pager2_event,
695 '#options' => $options,
696 '#required' => FALSE,
697 '#description' => t("The event on which the prev/next pager reacts."),
698 );
699
700 $form['block_settings']['settings']['pager2_settings']['pager2_slide_prev'] = array(
701 '#type' => 'textfield',
702 '#title' => t('Prev text on slide'),
703 '#default_value' => $pager2_slide_prev,
704 '#size' => 30,
705 '#required' => FALSE,
706 '#description' => t("Caption for the prev pager on the slide.<br />Can also be empty if you use an image to go to the previous slide."),
707 );
708
709 $form['block_settings']['settings']['pager2_settings']['pager2_slide_next'] = array(
710 '#type' => 'textfield',
711 '#title' => t('Next text on slide'),
712 '#default_value' => $pager2_slide_next,
713 '#size' => 30,
714 '#required' => FALSE,
715 '#description' => t("Caption for the next pager on the slide.<br />Can also be empty if you use an image to go to the next slide."),
716 );
717
718 $form['block_settings']['settings']['pager2_settings']['pager2_pager_prev'] = array(
719 '#type' => 'textfield',
720 '#title' => t('Prev text in pager'),
721 '#default_value' => $pager2_pager_prev,
722 '#size' => 30,
723 '#required' => FALSE,
724 '#description' => t("Caption for the prev pager on the slide.<br />Can also be empty if you use an image to go to the previous slide."),
725 );
726
727 $form['block_settings']['settings']['pager2_settings']['pager2_pager_next'] = array(
728 '#type' => 'textfield',
729 '#title' => t('Next text in pager'),
730 '#default_value' => $pager2_pager_next,
731 '#size' => 30,
732 '#required' => FALSE,
733 '#description' => t("Caption for the next pager on the slide.<br />Can also be empty if you use an image to go to the next slide."),
734 );
735 */
736 // pager settings togg;e
737 $form['block_settings']['settings']['pager2'] = array(
738 '#type' => 'checkbox',
739 '#title' => t('Use Prev/Next Pager'),
740 '#default_value' => $pager2,
741 '#required' => FALSE,
742 '#description' => t("Use a Prev/Next Pager to select slides"),
743 );
744
745 // pager2 settings.
746 //show fields when using pager
747 $extra = (empty($pager2)) ? ' style="display:none"' : '';
748 $form['block_settings']['settings']['pager2_settings'] = array(
749 '#type' => 'fieldset',
750 '#collapsible' => TRUE,
751 '#collapsed' => FALSE,
752 '#prefix' => '<div id="ddblock-pager2-settings-wrapper"'. $extra .'>',
753 '#suffix' => '</div>',
754 '#title' => t('Prev/next pager settings'),
755 );
756
757 $form['block_settings']['settings']['pager2_settings']['pager2_event'] = array(
758 '#type' => 'select',
759 '#title' => t('Pager event'),
760 '#default_value' => $pager2_event,
761 '#prefix' => '<div id="ddblock-pager2-event-wrapper">',
762 '#suffix' => '</div>',
763 '#options' => $options,
764 '#required' => FALSE,
765 '#description' => t("The event on which the prev/next pager reacts."),
766 );
767
768 $options = array(
769 'pager' => t('Pager'),
770 'slide' => t('Slide'),
771 );
772
773 $form['block_settings']['settings']['pager2_settings']['pager2_position'] = array(
774 '#type' => 'checkboxes',
775 '#title' => t('Pager position'),
776 '#default_value' => $pager2_position,
777 '#prefix' => '<div id="ddblock-pager2-position-wrapper">',
778 '#suffix' => '</div>',
779 '#options' => $options,
780 '#multiple' => TRUE,
781 '#required' => FALSE,
782 '#description' => t("Possible position for the prev/next pager.<br />The position must be supported by the template used to be effective."),
783 );
784
785
786 // pager2 settings pager.
787 //show fields when using pager pager
788 $extra = (empty($pager2)) ? ' style="display:none"' : '';
789 $form['block_settings']['settings']['pager2_settings']['pager2_pager'] = array(
790 '#type' => 'fieldset',
791 '#collapsible' => TRUE,
792 '#collapsed' => FALSE,
793 '#prefix' => '<div id="ddblock-pager2-pager-settings-wrapper"'. $extra .'>',
794 '#suffix' => '</div>',
795 '#title' => t('Pager Pager'),
796 );
797
798
799 $form['block_settings']['settings']['pager2_settings']['pager2_pager']['pager2_pager_prev'] = array(
800 '#type' => 'textfield',
801 '#title' => t('Prev text in pager'),
802 '#default_value' => $pager2_pager_prev,
803 '#prefix' => '<div id="ddblock-pager2-pager-prev-text-wrapper">',
804 '#size' => 30,
805 '#suffix' => '</div>',
806 '#required' => FALSE,
807 '#description' => t("Caption for the prev pager in the pager.<br />Can also be empty if you use an image to go to the previous slide."),
808 );
809
810 $form['block_settings']['settings']['pager2_settings']['pager2_pager']['pager2_pager_next'] = array(
811 '#type' => 'textfield',
812 '#title' => t('Next text in pager'),
813 '#default_value' => $pager2_pager_next,
814 '#prefix' => '<div id="ddblock-pager2-pager-next-text-wrapper">',
815 '#size' => 30,
816 '#suffix' => '</div>',
817 '#required' => FALSE,
818 '#description' => t("Caption for the next pager in the pager.<br />Can also be empty if you use an image to go to the next slide."),
819 );
820
821 // hide prev/next pager when no prev/next slide available
822 $form['block_settings']['settings']['pager2_settings']['pager2_pager']['pager2_pager_hide'] = array(
823 '#type' => 'checkbox',
824 '#title' => t('Prev/Next Hide'),
825 '#default_value' => $pager2_pager_hide,
826 '#required' => FALSE,
827 '#description' => t("Hide Prev/Next Pager when no slide available."),
828 );
829
830 // pager2 settings slide.
831 //show fields when using slide pager
832 $extra = (empty($pager2)) ? ' style="display:none"' : '';
833 $form['block_settings']['settings']['pager2_settings']['pager2_slide'] = array(
834 '#type' => 'fieldset',
835 '#collapsible' => TRUE,
836 '#collapsed' => FALSE,
837 '#prefix' => '<div id="ddblock-pager2-slide-settings-wrapper"'. $extra .'>',
838 '#suffix' => '</div>',
839 '#title' => t('Slide Pager'),
840 );
841
842
843 $options = array(
844 'click' => t('Click'),
845 'mouseover' => t('Mouseover'),
846 );
847
848 $form['block_settings']['settings']['pager2_settings']['pager2_slide']['pager2_slide_prev'] = array(
849 '#type' => 'textfield',
850 '#title' => t('Prev text on slide'),
851 '#default_value' => $pager2_slide_prev,
852 '#prefix' => '<div id="ddblock-pager2-slide-prev-text-wrapper">',
853 '#size' => 30,
854 '#suffix' => '</div>',
855 '#required' => FALSE,
856 '#description' => t("Caption for the prev pager on the slide.<br />Can also be empty if you use an image to go to the previous slide."),
857 );
858
859 $form['block_settings']['settings']['pager2_settings']['pager2_slide']['pager2_slide_next'] = array(
860 '#type' => 'textfield',
861 '#title' => t('Next text on slide'),
862 '#default_value' => $pager2_slide_next,
863 '#prefix' => '<div id="ddblock-pager2-slide-next-text-wrapper">',
864 '#size' => 30,
865 '#suffix' => '</div>',
866 '#required' => FALSE,
867 '#description' => t("Caption for the next pager on the slide.<br />Can also be empty if you use an image to go to the next slide."),
868 );
869
870 // hide prev/next pager when no prev/next slide available
871 $form['block_settings']['settings']['pager2_settings']['pager2_slide']['pager2_slide_hide'] = array(
872 '#type' => 'checkbox',
873 '#title' => t('Prev/Next Hide'),
874 '#default_value' => $pager2_slide_hide,
875 '#required' => FALSE,
876 '#description' => t("Hide Prev/Next Pager when no slide available."),
877 );
878
879
880
881 // collapsed or not collapsed depending on value for custom settings.
882 if ($custom_jquery) {
883 $collapsed = FALSE;
884 }
885 else {
886 $collapsed = TRUE;
887 }
888
889 $form['block_settings']['settings']['custom'] = array(
890 '#type' => 'fieldset',
891 '#collapsible' => TRUE,
892 '#collapsed' => $collapsed,
893 '#title' => t('Custom jQuery Cycle Plugin Settings'),
894 '#weight' => 1,
895 '#description' => t('If you use custom jQuery options, they will override your other settings.'),
896 );
897
898 $form['block_settings']['settings']['custom']['custom_jquery'] = array(
899 '#type' => 'textarea',
900 '#title' => t('Custom Options'),
901 '#default_value' => $custom_jquery,
902 '#cols' => 60,
903 '#rows' => 10,
904 '#required' => FALSE,
905 '#description' => t('Use valid JSON syntax, with double quotes for key/and string value pairs.<br />The total script needs to be enclosed in curly brackets.<br />No comma allowed after the last statement like in an array.<br />e.g.<br />{"fx":"fade",<br />"startingSlide":2,<br />"autostop":1}'),
906 );
907
908 $form['#redirect'] = 'admin/settings/ddblock/list';
909
910 return $form;
911 }
912
913 /**
914 * Build the node selection form element.
915 *
916 * This function is also called when generating a new set of options during the
917 * AJAX callback, so an array is returned that can be used to replace an existing
918 * form element.
919 *
920 * @param $form
921 * form to add elements to.
922 * @param $content_type
923 * selected content type.
924 * @param $nodes
925 * Existing nodes added to the block.
926 *
927 * @return
928 * form fields.
929 */
930 function ddblock_select_nodes_form(&$form, $content_type, $nodes) {
931
932 // Wrapper for nodes select box.
933 $form['content']['content_types']['select_nodes'] = array(
934 '#type' => 'hidden',
935 '#value' => -1,
936 '#prefix' => '<div id="select-nodes-wrapper">',
937 );
938 // no content type selected (show text 'No content type selected').
939 if ($content_type == 'none') {
940 $form['content']['content_types']['select_nodes']['#prefix'] .= '<em>'. t('No content type selected.') .'</em>';
941 $form['content']['content_types']['select_nodes']['#suffix'] = '</div>';
942
943 unset($form['content']['content_types']['nodes']);
944
945 }
946 // add select box to select a node.
947 else {
948 if (user_access('administer dynamic display blocks')) {
949
950 // get all nodes of a content type which are not added yet to the block.
951 $options = _ddblock_get_content_type_nodes($content_type);
952 $form['content']['content_types']['nodes'] = array(
953 '#type' => 'select',
954 '#title' => t('Node'),
955 '#default_value' => $nodes,
956 '#description' => t('The node to show in the Dynamic display block'),
957 '#options' => $options,
958 '#attributes' => array('class' => 'content-type-select'),
959 '#suffix' => '</div>',
960 );
961 }
962 }
963
964 return $form;
965 }
966
967 /**
968 * Implementation of hook_form_alter().
969 *
970 * Used to add dynamic display block configuration settings to dynamic display block instances.
971 */
972 function ddblock_form_alter(&$form, &$form_state, $form_id) {
973 $module = arg(4);
974 $delta = arg(5);
975
976 if ((isset($delta) && ($module == 'ddblock'))
977 && (user_access('administer dynamic display blocks'))
978 && (user_access('administer blocks'))
979 && ($form_id == 'block_admin_configure')) {
980
981 // get original block_settings.
982 $block = ddblock_get_blocks($delta);
983 $module_original = $block->module;
984 $delta_original = $block->delta_original;
985
986 // check if module enabled in the dynamic display block settings.
987 $block_enabled = FALSE;
988 $blocks = ddblock_get_ddblock_enabled_module_blocks();
989 foreach ($blocks as $block) {
990 if (($block['module'] == $module_original) && ($block['delta'] == $delta_original)) {
991 $block_enabled = TRUE;
992 }
993 }
994 if ($block_enabled) {
995
996 // get module path to dynamic display block module
997 $ddblock_path = drupal_get_path('module', 'ddblock');
998 // add ddblock js file
999 drupal_add_js($ddblock_path .'/js/ddblock.admin.js', 'module');
1000 drupal_add_js($ddblock_path .'/js/jquery.selectboxes.js', 'module');
1001
1002 // get settings.
1003 $configuration_settings = ddblock_get_configuration_settings($module, $delta);
1004
1005 $advanced =_ddblock_get_variable($configuration_settings['advanced'], 1);
1006 $container = _ddblock_get_variable($configuration_settings['container'], 'div.slide');
1007 $custom_jquery = _ddblock_get_variable($configuration_settings['custom_jquery'], '');
1008 $debug_info = _ddblock_get_variable($configuration_settings['debug_info'], 'none');
1009 $fx = _ddblock_get_variable($configuration_settings['fx'], "fade");
1010 $height = _ddblock_get_variable($configuration_settings['height'], 195);
1011 $image_height = _ddblock_get_variable($configuration_settings['image_height'], 195);
1012 $image_width = _ddblock_get_variable($configuration_settings['image_width'], 195);
1013 $imgcache_toggle = _ddblock_get_variable($configuration_settings['imgcache_toggle'], 0);
1014 $imgcache_slide = _ddblock_get_variable($configuration_settings['imgcache_slide'], '<none>');
1015 $imgcache_pager_item = _ddblock_get_variable($configuration_settings['imgcache_pager_item'], '<none>');
1016 $next = _ddblock_get_variable($configuration_settings['next'], 0);
1017 $order = _ddblock_get_variable($configuration_settings['order'], 'asc');
1018 $output = _ddblock_get_variable($configuration_settings['output'], 'view_content');
1019 $overflow = _ddblock_get_variable($configuration_settings['overflow'], 1);
1020 $pager_toggle = _ddblock_get_variable($configuration_settings['pager_toggle'], 0);
1021 $pager = _ddblock_get_variable($configuration_settings['pager'], 'none');
1022 $pager_event = _ddblock_get_variable($configuration_settings['pager_event'], 'click');
1023 $pager2 = _ddblock_get_variable($configuration_settings['pager2'], 0);
1024 $pager2_event = _ddblock_get_variable($configuration_settings['pager2_event'], 'click');
1025 $pager2_position = _ddblock_get_variable($configuration_settings['pager2_position'], 'slide');
1026 $pager2_slide_prev = _ddblock_get_variable($configuration_settings['pager2_slide_prev'], '');
1027 $pager2_slide_next = _ddblock_get_variable($configuration_settings['pager2_slide_next'], '');
1028 $pager2_slide_hide = _ddblock_get_variable($configuration_settings['pager2_slide_hide'], 1);
1029 $pager2_pager_prev = _ddblock_get_variable($configuration_settings['pager2_pager_prev'], '');
1030 $pager2_pager_next = _ddblock_get_variable($configuration_settings['pager2_pager_next'], '');
1031 $pager2_pager_hide = _ddblock_get_variable($configuration_settings['pager2_pager_hide'], 1);
1032 $pager_fast = _ddblock_get_variable($configuration_settings['pager_fast'], 1);
1033 $pager_pause = _ddblock_get_variable($configuration_settings['pager_pause'], 1);
1034 if (($pager == 'number-pager') || ($pager2 == 1)) {
1035 $pager_height = _ddblock_get_variable($configuration_settings['pager_height'], 25);
1036 $pager_width = _ddblock_get_variable($configuration_settings['pager_width'], 195);
1037 }
1038 else {
1039 $pager_height = _ddblock_get_variable($configuration_settings['pager_height'], 63);
1040 $pager_width = _ddblock_get_variable($configuration_settings['pager_width'], 195);
1041 }
1042 $pager_container = _ddblock_get_variable($configuration_settings['pager_container'], '.custom-pager-item');
1043 $pager_position = _ddblock_get_variable($configuration_settings['pager_position'], 'top');
1044 $pause = _ddblock_get_variable($configuration_settings['pause'], 1);
1045 $slide_text = _ddblock_get_variable($configuration_settings['slide_text'], 1);
1046 $slide_text_jquery = _ddblock_get_variable($configuration_settings['slide_text_jquery'], 0);
1047 $slide_text_after_effect = _ddblock_get_variable($configuration_settings['slide_text_after_effect'], 'fadeIn');
1048 $slide_text_after_speed = _ddblock_get_variable($configuration_settings['slide_text_after_speed'], 1000);
1049 $slide_text_before_effect = _ddblock_get_variable($configuration_settings['slide_text_before_effect'], 'fadeOut');
1050 $slide_text_before_speed = _ddblock_get_variable($configuration_settings['slide_text_before_speed'], 250);
1051 $slide_text_container = _ddblock_get_variable($configuration_settings['slide_text_container'], 'div.slide-text');
1052 $slide_text_position =_ddblock_get_variable($configuration_settings['slide_text_position'], 'bottom');
1053 $speed = _ddblock_get_variable($configuration_settings['speed'], 500);
1054 $template = _ddblock_get_variable($configuration_settings['template'], 'none');
1055 if ($template == 'custom') {
1056 $custom_template = _ddblock_get_variable($configuration_settings['custom_template'], '');
1057 }
1058 $timeout = _ddblock_get_variable($configuration_settings['timeout'], 5000);
1059 $widget = _ddblock_get_variable($configuration_settings['widget'], 'default');
1060 $width = _ddblock_get_variable($configuration_settings['width'], 195);
1061
1062 // set pager variable for javascript
1063 $settings['ddblockCustomTemplate'] = array(
1064 'pager' => $pager,
1065 'pagerPosition' => $pager_position,
1066 );
1067
1068 drupal_add_js($settings, 'setting');
1069
1070 // hide fields when using advanced settings
1071 $extra = (!empty($advanced)) ? ' style="display:none"' : '';
1072
1073 $form['module'] = array(
1074 '#type' => 'hidden',
1075 '#value' => $module,
1076 );
1077 $form['delta'] = array(
1078 '#type' => 'value',
1079 '#value' => $delta,
1080 );
1081 $form['input_type'] = array(
1082 '#type' => 'hidden',
1083 '#value' => 'instance',
1084 );
1085
1086 // widget setting: Enable the dynamic display block setting for this block.
1087 $options = array(
1088 'default' => t('Default'),
1089 'cycle' => t('Cycleblock'),
1090 );
1091
1092 //wrapper for ddblock instance settings
1093 $form['block_settings']['#prefix'] = '<div id="ddblock-instance-settings">';
1094 $form['block_settings']['#suffix'] = '</div>';
1095
1096 $form['block_settings']['widget'] = array(
1097 '#type' => 'radios',
1098 '#title' => t('Display Method'),
1099 '#default_value' => $widget,
1100 '#options' => $options,
1101 '#required' => TRUE,
1102 '#description' => t("Choose a way to display content."),
1103 '#weight' => -11,
1104 );
1105
1106 // advanced settings togg;e
1107 $form['block_settings']['advanced'] = array(
1108 '#type' => 'checkbox'<