imagefield_gallery_scrollbox.module

  1. <?php
  2. //$Id: imagefield_gallery_lightbox2.module,v 1.7 2008/05/04 16:09:20 eclipsegc Exp $
  3.  
  4. /**
  5.  * implementation of hook_enable()
  6.  */
  7.  
  8. function imagefield_gallery_scrollbox_enable() {
  9.   imagefield_gallery_scrollbox_settings();
  10. }
  11.  
  12. /**
  13.  * Implementation of imagefield_gallery_hook_settings()
  14.  * function checks to see if the proper key existings
  15.  * in the imagefield_gallery_galleries variable, and
  16.  * if it does, does nothing, and if it doesn't it adds
  17.  * the proper settings to the variable.
  18.  */
  19.  
  20. function imagefield_gallery_scrollbox_settings() {
  21.   $settings = variable_get('imagefield_gallery_galleries', array());
  22.   if (!array_key_exists('scrollbox', $settings)) {
  23.     $settings['scrollbox'] = t('Scrollbox Gallery');
  24.     variable_set('imagefield_gallery_galleries', $settings);
  25.   }
  26. }
  27.  
  28. /**
  29.  * imagefield_gallery_hook_details is meant to keep track of
  30.  * all of our stylistic variables for a given gallery type
  31.  * these variables then need to be rendered in an acceptable
  32.  * fashion for display on the content types admin page
  33.  */
  34.  
  35. function imagefield_gallery_scrollbox_details($type) {
  36.   $output = '';
  37.   $styles = variable_get('imagefield_gallery_scrollbox_css', array());
  38.   $headers = array(t('Attribute'), t('Value'));
  39.   $rows = array();
  40.   $rows[] = array(t('Thumbnail Width'), $styles[$type]['width'] .'px');
  41.   $rows[] = array(t('Thumbnail Height'), $styles[$type]['height'] .'px');
  42.   $rows[] = array(t('Thumbnail Top Margin'), $styles[$type]['margins']['top'] .'px');
  43.   $rows[] = array(t('Thumbnail Right Margin'), $styles[$type]['margins']['right'] .'px');
  44.   $rows[] = array(t('Thumbnail Bottom Margin'), $styles[$type]['margins']['bottom'] .'px');
  45.   $rows[] = array(t('Thumbnail Left Margin'), $styles[$type]['margins']['left'] .'px');
  46.   $rows[] = array(t('Thumbnail Borders'), $styles[$type]['border']['border_width'] .' '. $styles[$type]['border']['border_style'] .' '. $styles[$type]['border']['color_style_textfield']);
  47.  
  48.   $output .= theme('table', $headers, $rows);
  49.   return $output;
  50. }
  51.  
  52. /**
  53.  * implementation of imagefield_gallery_hook_content_types()
  54.  */
  55.  
  56. function imagefield_gallery_scrollbox_content_types($form = array(), $var = array(), $type, $cache = array()) {
  57.   drupal_add_css(drupal_get_path('module', 'imagefield_gallery_scrollbox') .'/css/content_types.css');
  58.  
  59.   $form[$type] = array(
  60.     '#type' => 'fieldset',
  61.     '#title' => t('@type settings', array('@type' => $type)),
  62.     '#collapsible' => FALSE,
  63.     '#description' => t('Please select the gallery style you would like for the @type content type.', array('@type' => $type)),
  64.     '#tree' => TRUE,
  65.     '#attributes' => array('class' => 'scrollbox_fieldset'),
  66.   );
  67.   $form[$type]['gallery'] = array(
  68.     '#type' => 'select',
  69.     '#title' => t('@type gallery type', array('@type' => $type)),
  70.     '#default_value' => isset($var[$type]['gallery']) ? $var[$type]['gallery'] : 'none',
  71.     '#options' => array(
  72.       imagefield_gallery_get_gallery_types(),
  73.     ),
  74.     '#tree' => TRUE,
  75.   );
  76.   $form[$type]['images'] = array(
  77.     '#type' => 'fieldset',
  78.     '#title' => t('@type image settings', array('@type' => $type)),
  79.     '#collapsible' => FALSE,
  80.     '#description' => t('Select the imagecache settings you would like to use (if any) for the @type content type', array('@type' => $type)),
  81.     '#tree' => TRUE,
  82.   );
  83.   $form[$type]['images']['thumbnail'] = array(
  84.     '#type' => 'select',
  85.     '#title' => t('@type thumbnail', array('@type' => $type)),
  86.     '#default_value' => isset($var[$type]['images']['thumbnail']) ? $var[$type]['images']['thumbnail'] : 'none',
  87.     '#options' => $cache,
  88.     '#tree' => TRUE,
  89.   );
  90.   $form[$type]['images']['preview'] = array(
  91.     '#type' => 'select',
  92.     '#title' => t('@type preview', array('@type' => $type)),
  93.     '#default_value' => isset($var[$type]['images']['preview']) ? $var[$type]['images']['preview'] : 'none',
  94.     '#options' => $cache,
  95.     '#tree' => TRUE,
  96.   );
  97.   return $form;
  98. }
  99.  
  100. /**
  101.  * implementation of imagefield_gallery_hook_content_types_validate()
  102.  */
  103.  
  104. function imagefield_gallery_scrollbox_content_types_validate($form_id, $form_values, $form) {
  105.   $types = imagefield_gallery_nodetypes();
  106.   foreach ($types as $type) {
  107.     if (is_array($form_values[$type['type']]) && $form_values[$type['type']]['gallery'] != 'none') {
  108.       if ($form_values[$type['type']]['images']['thumbnail'] == 'none' || $form_values[$type['type']]['images']['preview'] == 'none') {
  109.         form_set_error('', t('You must select an imagecache setting for the @type content type!', array('@type' => $type['type'])));
  110.       }
  111.     }
  112.   }
  113. }
  114.  
  115. /**
  116.  * implementation of imagefield_gallery_hook_admin_validate()
  117.  */
  118.  
  119. function imagefield_gallery_scrollbox_admin_validate($form_id, $form_values) {
  120.   $types = imagefield_gallery_nodetypes();
  121.   foreach ($types as $type) {
  122.     if (!empty($form_values['scrollbox'][$type['type']]['width'])) {
  123.       if (!is_numeric($form_values['scrollbox'][$type['type']]['width'])) {
  124.         form_set_error('', t('The @type width value must be a number!', array('@type' => $type['type'])));
  125.       }
  126.     }
  127.     if (!empty($form_values['scrollbox'][$type['type']]['height'])) {
  128.       if (!is_numeric($form_values['scrollbox'][$type['type']]['height'])) {
  129.         form_set_error('', t('The @type height value must be a number!', array('@type' => $type['type'])));
  130.       }
  131.     }
  132.     if (!empty($form_values['scrollbox'][$type['type']]['margins']['top'])) {
  133.       if (!is_numeric($form_values['scrollbox'][$type['type']]['margins']['top'])) {
  134.         form_set_error('', t('The @type top margin value must be a number!', array('@type' => $type['type'])));
  135.       }
  136.     }
  137.     if (!empty($form_values['scrollbox'][$type['type']]['margins']['right'])) {
  138.       if (!is_numeric($form_values['scrollbox'][$type['type']]['margins']['right'])) {
  139.         form_set_error('', t('The @type right margin value must be a number!', array('@type' => $type['type'])));
  140.       }
  141.     }
  142.     if (!empty($form_values['scrollbox'][$type['type']]['margins']['bottom'])) {
  143.       if (!is_numeric($form_values['scrollbox'][$type['type']]['margins']['bottom'])) {
  144.         form_set_error('', t('The @type bottom margin value must be a number!', array('@type' => $type['type'])));
  145.       }
  146.     }
  147.     if (!empty($form_values['scrollbox'][$type['type']]['margins']['left'])) {
  148.       if (!is_numeric($form_values['scrollbox'][$type['type']]['margins']['left'])) {
  149.         form_set_error('', t('The @type left margin value must be a number!', array('@type' => $type['type'])));
  150.       }
  151.     }
  152.     if (!empty($form_values['scrollbox'][$type['type']]['border']['color_style_textfield'])) {
  153.       if (!preg_match('/^#[0-9A-Fa-f]{6}$/', $form_values['scrollbox'][$type['type']]['border']['color_style_textfield'])) {
  154.         form_set_error('', t('The @type border color value must be a hexidecimal number!', array('@type' => $type['type'])));
  155.       }
  156.     }
  157.   }
  158. }
  159.  
  160. /**
  161.  * implementation of imagefield_gallery_hook_admin()
  162.  * @param $type
  163.  *   the node type so that the validate and submit functions
  164.  *   can operate more easily.  '#tree' => TRUE is highly
  165.  *   recommended in this case to eliminate potential
  166.  *   conflicts in naming convention.
  167.  *
  168.  * this entire form function will be used to help create
  169.  * the css for this gallery type.  the imagefield_gallery_lightbox2_css
  170.  * variable stores all the css for this gallery type by node type.
  171.  * this function is a fairly good example of what you should be
  172.  * striving for in creating your own admin pages.
  173.  *
  174.  * also, you'll noted that the primary form elements are all contained
  175.  * within $form['lightbox2'].  It is imperative that you also name a
  176.  * containing form element with the same naming convention as your module.
  177.  *
  178.  */
  179.  
  180. function imagefield_gallery_scrollbox_admin($type) {
  181.   drupal_add_css(drupal_get_path('module', 'imagefield_gallery_scrollbox') .'/css/admin.css');
  182.   $var = variable_get('imagefield_gallery_scrollbox_css', array());
  183.   $form['variable'] = array(
  184.     '#type' => 'value',
  185.     '#value' => 'scrollbox',
  186.   );
  187.   $form['scrollbox'] = array(
  188.     '#type' => 'fieldset',
  189.     '#title' => t('Lightbox2 @type Attributes', array('@type' => $type)),
  190.     '#collapsible' => TRUE,
  191.     '#collapsed' => TRUE,
  192.     '#tree' => TRUE,
  193.     '#attributes' => array('class' => 'scrollbox_admin_fieldset'),
  194.   );
  195.   $form['scrollbox'][$type] = array(
  196.     '#type' => 'fieldset',
  197.     '#title' => t('Thumbnail Attributes'),
  198.     '#collapsible' => FALSE,
  199.     '#description' => t('Set the width and height, in pixels, you desire your thumbnails to be.'),
  200.     '#tree' => TRUE,
  201.     '#attributes' => array('class' => 'scrollbox_thumbnail_fieldset'),
  202.   );
  203.   $form['scrollbox'][$type]['width'] = array(
  204.     '#type' => 'textfield',
  205.     '#title' => t('Thumbnail Width'),
  206.     '#size' => 10,
  207.     '#maxlength' => 4,
  208.     '#default_value' => isset($var[$type]['width']) ? $var[$type]['width'] : 100,
  209.     '#required' => TRUE,
  210.     '#tree' => TRUE,
  211.   );
  212.   $form['scrollbox'][$type]['height'] = array(
  213.     '#type' => 'textfield',
  214.     '#title' => t('Thumbnail Height'),
  215.     '#size' => 10,
  216.     '#maxlength' => 4,
  217.     '#default_value' => isset($var[$type]['height']) ? $var[$type]['height'] : 100,
  218.     '#required' => TRUE,
  219.     '#tree' => TRUE,
  220.   );
  221.   $form['scrollbox'][$type]['margins'] = array(
  222.     '#prefix' => '<div style="clear:both"></div>',
  223.     '#type' => 'fieldset',
  224.     '#title' => t('Margin Attributes'),
  225.     '#collapsible' => TRUE,
  226.     '#collapsed' => TRUE,
  227.     '#tree' => TRUE,
  228.     '#attributes' => array('class' => 'scrollbox_margin_fieldset'),
  229.   );
  230.   $form['scrollbox'][$type]['margins']['top'] = array(
  231.     '#type' => 'textfield',
  232.     '#title' => t('Top Margin'),
  233.     '#default_value' => isset($var[$type]['margins']['top']) ? $var[$type]['margins']['top'] : 10,
  234.     '#size' => '5',
  235.     '#maxlength' => 3,
  236.     '#required' => TRUE,
  237.     '#tree' => TRUE,
  238.   );
  239.   $form['scrollbox'][$type]['margins']['right'] = array(
  240.     '#type' => 'textfield',
  241.     '#title' => t('Right Margin'),
  242.     '#default_value' => isset($var[$type]['margins']['right']) ? $var[$type]['margins']['right'] : 10,
  243.     '#size' => '5',
  244.     '#maxlength' => 3,
  245.     '#required' => TRUE,
  246.     '#tree' => TRUE,
  247.   );
  248.   $form['scrollbox'][$type]['margins']['bottom'] = array(
  249.     '#type' => 'textfield',
  250.     '#title' => t('Bottom Margin'),
  251.     '#default_value' => isset($var[$type]['margins']['bottom']) ? $var[$type]['margins']['bottom'] : 10,
  252.     '#size' => '5',
  253.     '#maxlength' => 3,
  254.     '#required' => TRUE,
  255.     '#tree' => TRUE,
  256.   );
  257.   $form['scrollbox'][$type]['margins']['left'] = array(
  258.     '#type' => 'textfield',
  259.     '#title' => t('Left Margin'),
  260.     '#default_value' => isset($var[$type]['margins']['left']) ? $var[$type]['margins']['left'] : 10,
  261.     '#size' => '5',
  262.     '#maxlength' => 3,
  263.     '#required' => TRUE,
  264.     '#tree' => TRUE,
  265.   );
  266.  
  267.   $form['scrollbox'][$type]['border'] = array(
  268.     '#type' => 'fieldset',
  269.     '#title' => t('Border Attributes'),
  270.     '#collapsible' => TRUE,
  271.     '#collapsed' => TRUE,
  272.     '#tree' => TRUE,
  273.   );