<?php
//$Id: imagefield_gallery_lightbox2.module,v 1.7 2008/05/04 16:09:20 eclipsegc Exp $
/**
* implementation of hook_enable()
*/
function imagefield_gallery_scrollbox_enable() {
imagefield_gallery_scrollbox_settings();
}
/**
* Implementation of imagefield_gallery_hook_settings()
* function checks to see if the proper key existings
* in the imagefield_gallery_galleries variable, and
* if it does, does nothing, and if it doesn't it adds
* the proper settings to the variable.
*/
function imagefield_gallery_scrollbox_settings() {
$settings['scrollbox'] = t('Scrollbox Gallery');
}
}
/**
* imagefield_gallery_hook_details is meant to keep track of
* all of our stylistic variables for a given gallery type
* these variables then need to be rendered in an acceptable
* fashion for display on the content types admin page
*/
function imagefield_gallery_scrollbox_details($type) {
$output = '';
$headers =
array(t('Attribute'), t
('Value'));
$rows[] =
array(t('Thumbnail Width'),
$styles[$type]['width'] .
'px');
$rows[] =
array(t('Thumbnail Height'),
$styles[$type]['height'] .
'px');
$rows[] =
array(t('Thumbnail Top Margin'),
$styles[$type]['margins']['top'] .
'px');
$rows[] =
array(t('Thumbnail Right Margin'),
$styles[$type]['margins']['right'] .
'px');
$rows[] =
array(t('Thumbnail Bottom Margin'),
$styles[$type]['margins']['bottom'] .
'px');
$rows[] =
array(t('Thumbnail Left Margin'),
$styles[$type]['margins']['left'] .
'px');
$rows[] =
array(t('Thumbnail Borders'),
$styles[$type]['border']['border_width'] .
' '.
$styles[$type]['border']['border_style'] .
' '.
$styles[$type]['border']['color_style_textfield']);
$output .=
theme('table',
$headers,
$rows);
return $output;
}
/**
* implementation of imagefield_gallery_hook_content_types()
*/
function imagefield_gallery_scrollbox_content_types
($form =
array(),
$var =
array(),
$type,
$cache =
array()) {
'#type' => 'fieldset',
'#title' =>
t('@type settings',
array('@type' =>
$type)),
'#collapsible' => FALSE,
'#description' =>
t('Please select the gallery style you would like for the @type content type.',
array('@type' =>
$type)),
'#tree' => TRUE,
'#attributes' =>
array('class' =>
'scrollbox_fieldset'),
);
$form[$type]['gallery'] =
array(
'#type' => 'select',
'#title' =>
t('@type gallery type',
array('@type' =>
$type)),
'#default_value' =>
isset($var[$type]['gallery']) ?
$var[$type]['gallery'] :
'none',
imagefield_gallery_get_gallery_types(),
),
'#tree' => TRUE,
);
$form[$type]['images'] =
array(
'#type' => 'fieldset',
'#title' =>
t('@type image settings',
array('@type' =>
$type)),
'#collapsible' => FALSE,
'#description' =>
t('Select the imagecache settings you would like to use (if any) for the @type content type',
array('@type' =>
$type)),
'#tree' => TRUE,
);
$form[$type]['images']['thumbnail'] =
array(
'#type' => 'select',
'#title' =>
t('@type thumbnail',
array('@type' =>
$type)),
'#default_value' =>
isset($var[$type]['images']['thumbnail']) ?
$var[$type]['images']['thumbnail'] :
'none',
'#options' => $cache,
'#tree' => TRUE,
);
$form[$type]['images']['preview'] =
array(
'#type' => 'select',
'#title' =>
t('@type preview',
array('@type' =>
$type)),
'#default_value' =>
isset($var[$type]['images']['preview']) ?
$var[$type]['images']['preview'] :
'none',
'#options' => $cache,
'#tree' => TRUE,
);
return $form;
}
/**
* implementation of imagefield_gallery_hook_content_types_validate()
*/
function imagefield_gallery_scrollbox_content_types_validate($form_id, $form_values, $form) {
$types = imagefield_gallery_nodetypes();
foreach ($types as $type) {
if (is_array($form_values[$type['type']]) &&
$form_values[$type['type']]['gallery'] !=
'none') {
if ($form_values[$type['type']]['images']['thumbnail'] == 'none' || $form_values[$type['type']]['images']['preview'] == 'none') {
form_set_error('', t
('You must select an imagecache setting for the @type content type!',
array('@type' =>
$type['type'])));
}
}
}
}
/**
* implementation of imagefield_gallery_hook_admin_validate()
*/
function imagefield_gallery_scrollbox_admin_validate($form_id, $form_values) {
$types = imagefield_gallery_nodetypes();
foreach ($types as $type) {
if (!
empty($form_values['scrollbox'][$type['type']]['width'])) {
if (!
is_numeric($form_values['scrollbox'][$type['type']]['width'])) {
form_set_error('', t
('The @type width value must be a number!',
array('@type' =>
$type['type'])));
}
}
if (!
empty($form_values['scrollbox'][$type['type']]['height'])) {
if (!
is_numeric($form_values['scrollbox'][$type['type']]['height'])) {
form_set_error('', t
('The @type height value must be a number!',
array('@type' =>
$type['type'])));
}
}
if (!
empty($form_values['scrollbox'][$type['type']]['margins']['top'])) {
if (!
is_numeric($form_values['scrollbox'][$type['type']]['margins']['top'])) {
form_set_error('', t
('The @type top margin value must be a number!',
array('@type' =>
$type['type'])));
}
}
if (!
empty($form_values['scrollbox'][$type['type']]['margins']['right'])) {
if (!
is_numeric($form_values['scrollbox'][$type['type']]['margins']['right'])) {
form_set_error('', t
('The @type right margin value must be a number!',
array('@type' =>
$type['type'])));
}
}
if (!
empty($form_values['scrollbox'][$type['type']]['margins']['bottom'])) {
if (!
is_numeric($form_values['scrollbox'][$type['type']]['margins']['bottom'])) {
form_set_error('', t
('The @type bottom margin value must be a number!',
array('@type' =>
$type['type'])));
}
}
if (!
empty($form_values['scrollbox'][$type['type']]['margins']['left'])) {
if (!
is_numeric($form_values['scrollbox'][$type['type']]['margins']['left'])) {
form_set_error('', t
('The @type left margin value must be a number!',
array('@type' =>
$type['type'])));
}
}
if (!
empty($form_values['scrollbox'][$type['type']]['border']['color_style_textfield'])) {
if (!
preg_match('/^#[0-9A-Fa-f]{6}$/',
$form_values['scrollbox'][$type['type']]['border']['color_style_textfield'])) {
form_set_error('', t
('The @type border color value must be a hexidecimal number!',
array('@type' =>
$type['type'])));
}
}
}
}
/**
* implementation of imagefield_gallery_hook_admin()
* @param $type
* the node type so that the validate and submit functions
* can operate more easily. '#tree' => TRUE is highly
* recommended in this case to eliminate potential
* conflicts in naming convention.
*
* this entire form function will be used to help create
* the css for this gallery type. the imagefield_gallery_lightbox2_css
* variable stores all the css for this gallery type by node type.
* this function is a fairly good example of what you should be
* striving for in creating your own admin pages.
*
* also, you'll noted that the primary form elements are all contained
* within $form['lightbox2']. It is imperative that you also name a
* containing form element with the same naming convention as your module.
*
*/
function imagefield_gallery_scrollbox_admin($type) {
$form['variable'] =
array(
'#type' => 'value',
'#value' => 'scrollbox',
);
$form['scrollbox'] =
array(
'#type' => 'fieldset',
'#title' =>
t('Lightbox2 @type Attributes',
array('@type' =>
$type)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
'#attributes' =>
array('class' =>
'scrollbox_admin_fieldset'),
);
$form['scrollbox'][$type] =
array(
'#type' => 'fieldset',
'#title' =>
t('Thumbnail Attributes'),
'#collapsible' => FALSE,
'#description' =>
t('Set the width and height, in pixels, you desire your thumbnails to be.'),
'#tree' => TRUE,
'#attributes' =>
array('class' =>
'scrollbox_thumbnail_fieldset'),
);
$form['scrollbox'][$type]['width'] =
array(
'#type' => 'textfield',
'#title' =>
t('Thumbnail Width'),
'#size' => 10,
'#maxlength' => 4,
'#default_value' =>
isset($var[$type]['width']) ?
$var[$type]['width'] :
100,
'#required' => TRUE,
'#tree' => TRUE,
);
$form['scrollbox'][$type]['height'] =
array(
'#type' => 'textfield',
'#title' =>
t('Thumbnail Height'),
'#size' => 10,
'#maxlength' => 4,
'#default_value' =>
isset($var[$type]['height']) ?
$var[$type]['height'] :
100,
'#required' => TRUE,
'#tree' => TRUE,
);
$form['scrollbox'][$type]['margins'] =
array(
'#prefix' => '<div style="clear:both"></div>',
'#type' => 'fieldset',
'#title' =>
t('Margin Attributes'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
'#attributes' =>
array('class' =>
'scrollbox_margin_fieldset'),
);
$form['scrollbox'][$type]['margins']['top'] =
array(
'#type' => 'textfield',
'#title' =>
t('Top Margin'),
'#default_value' =>
isset($var[$type]['margins']['top']) ?
$var[$type]['margins']['top'] :
10,
'#size' => '5',
'#maxlength' => 3,
'#required' => TRUE,
'#tree' => TRUE,
);
$form['scrollbox'][$type]['margins']['right'] =
array(
'#type' => 'textfield',
'#title' =>
t('Right Margin'),
'#default_value' =>
isset($var[$type]['margins']['right']) ?
$var[$type]['margins']['right'] :
10,
'#size' => '5',
'#maxlength' => 3,
'#required' => TRUE,
'#tree' => TRUE,
);
$form['scrollbox'][$type]['margins']['bottom'] =
array(
'#type' => 'textfield',
'#title' =>
t('Bottom Margin'),
'#default_value' =>
isset($var[$type]['margins']['bottom']) ?
$var[$type]['margins']['bottom'] :
10,
'#size' => '5',
'#maxlength' => 3,
'#required' => TRUE,
'#tree' => TRUE,
);
$form['scrollbox'][$type]['margins']['left'] =
array(
'#type' => 'textfield',
'#title' =>
t('Left Margin'),
'#default_value' =>
isset($var[$type]['margins']['left']) ?
$var[$type]['margins']['left'] :
10,
'#size' => '5',
'#maxlength' => 3,
'#required' => TRUE,
'#tree' => TRUE,
);
$form['scrollbox'][$type]['border'] =
array(
'#type' => 'fieldset',
'#title' =>
t('Border Attributes'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
);