gallery_assist.admin.inc in Gallery Assist 7
Same filename in this branch
Same filename and directory in other branches
GA module administration forms.
File
gallery_assist.admin.incView source
<?php
/**
* @file
* GA module administration forms.
*/
/**
* Provide to administrators resumed information of all concerning to GA.
*
* @return
* A string.
*/
function gallery_assist_info() {
$build = array();
// About GA assignments (content types with assigned gallery functionality).
$content_types = node_type_get_names();
$line = array();
foreach ($content_types as $type => $name) {
if (variable_get("gallery_assist_{$type}", 0) == 1) {
$line[] = l($name, "admin/config/media/gallery_assist/assignments/{$type}");
}
}
$build['assignments'] = array(
'#markup' => '<h3>Content types with assigned gallery functionality</h3>' . implode(', ', $line),
);
// About current JQuery.
$build['ga_jquery_info'] = array(
'#markup' => '<h3>Used JQuery version</h3> <span id="ga-jq-version">JQuery-</span><script type="text/javascript">jQuery("#ga-jq-version").append(jQuery().jquery);</script>',
);
// About GA modules state.
$build['ga_modules'] = array(
'#markup' => '<h3>GA Modules</h3>',
);
$output = array();
$result = db_select('system', 's')
->fields('s')
->condition('s.name', 'gallery_assist_' . '%', 'LIKE')
->execute();
foreach ($result as $record) {
$record->info = unserialize($record->info);
$name = "{$record->info['name']}-{$record->info['version']}";
$output[] = $record->status == 1 ? "<strong>{$name}</strong> (enabled)" : $name . ' (disabled)';
}
$build['ga_modules']['#markup'] .= implode('<br />', $output);
return drupal_render($build);
}
/**
* Form builder; Manage GA content types specific settings.
*
* @param $cero
* @param $form_state
* An associative array containing the current state of the form.
* @param $type
* String containing the machine name of the content type.
* @param $name
* String containing the redeable name of the content type.
*
* @ingroup forms
* @see gallery_assist_assignments_form_submit()
* @see gallery_assist_assignments_form_validate()
*/
function gallery_assist_assignments_form($cero, &$form_state, $type = 'gallery_assist', $name = 'Galery Assist') {
$settings = variable_get("gallery_assist_{$type}_data", array());
$form = array();
$form['gallery_assist_settings_set'] = array(
'#type' => 'vertical_tabs',
);
$weight = 10;
$form['gallery_assist_settings'] = array(
'#type' => 'fieldset',
'#title' => "<span title=" . '"open all"' . " class=" . '"toogle-fieldsets status-closed ga-pointer"' . "></span> Gallery settings on {$name}",
#'#description' => '<span class="toogle-fieldsets status-closed ga-pointer">[+]</span>'
'#weight' => 0,
);
$form['upload'] = array(
'#type' => 'fieldset',
'#title' => 'Upload',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
// '#tree' => TRUE,
'#weight' => $weight++,
'#group' => 'gallery_assist_settings_set',
);
$form['upload'] += _gallery_assist_upload_settings_form($settings);
$form['elements'] = array(
'#type' => 'fieldset',
'#title' => 'Elements',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
// '#tree' => TRUE,
'#weight' => $weight++,
'#group' => 'gallery_assist_settings_set',
);
$form['elements'] += _gallery_assist_elements_settings_form($settings);
// Image styles.
$form['size_styles'] = array(
'#type' => 'fieldset',
'#title' => 'Sizes / Image styles',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
// '#tree' => TRUE,
'#weight' => $weight++,
'#group' => 'gallery_assist_settings_set',
);
$form['size_styles'] += _gallery_assist_size_styles_form($settings);
// Elements.
$form['elements'] = array(
'#type' => 'fieldset',
'#title' => 'Elements',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
// '#tree' => TRUE,
'#weight' => $weight++,
'#group' => 'gallery_assist_settings_set',
);
$form['elements'] += _gallery_assist_elements_settings_form($settings);
// Layout.
$form['gallery_style'] = array(
'#type' => 'fieldset',
'#title' => 'Style',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
// '#tree' => TRUE,
'#weight' => $weight++,
'#group' => 'gallery_assist_settings_set',
);
$form['gallery_style'] += _gallery_assist_gallery_style_form($settings);
// Pager.
$form['pager'] = array(
'#type' => 'fieldset',
'#title' => 'Pager',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
// '#tree' => TRUE,
'#weight' => $weight++,
'#group' => 'gallery_assist_settings_set',
);
$form['pager'] += _gallery_assist_pager_form($settings);
$form['others'] = array(
'#type' => 'fieldset',
'#title' => 'Miscellaneous',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
// '#tree' => TRUE,
'#weight' => $weight++,
'#group' => 'gallery_assist_settings_set',
);
$form['others']['mytest'] = array(
'#type' => 'textfield',
'#title' => 'Test field',
'#default_value' => '',
);
$form['others']['mytest2'] = array(
'#type' => 'textfield',
'#title' => 'Test field 2',
'#default_value' => '',
);
$form['others']['type'] = array(
'#type' => 'hidden',
'#value' => $type,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Process GA content types specific settings form submissions.
*/
function gallery_assist_assignments_form_submit($form, &$form_state) {
// if (!preg_match('/^rgb/', $form_state['values']['thm_border_color'], $match)
// || !preg_match('/^#/', $form_state['values']['thm_border_color'], $match)) {
// form_set_error('thm_border_color', 'Please');
// }
$settings = variable_get("gallery_assist_{$form_state['values']['type']}_data", array());
$new = array();
$i = 0;
foreach ($form_state['values'] as $k => $v) {
if (array_key_exists($k, $settings)) {
$new[$k] = $v;
$i++;
}
}
variable_set("gallery_assist_{$form_state['values']['type']}_data", $new);
drupal_set_message('The new configuration was successfully saved. ' . $i . ' items has ben changed');
// Save assignment css file.
$type = $form_state['values']['type'];
// $settings['thm_border'] = 1;
// $settings['thm_border_color'] = '#000';
// $settings['thm_margin'] = 10;
// $settings['thm_padding'] = 20;
// $settings['page_container_float'] = 'none';
// $settings['icon_image_style'] = $form_state['values']['icon_image_style'];
// $settings['thumbnail_image_style'] = $form_state['values']['thumbnail_image_style'];
// $settings['preview_image_style'] = $form_state['values']['preview_image_style'];
$thm = array(
'style' => image_style_load($settings['thumbnail_image_style']),
);
$end = end($thm['style']['effects']);
$thm['width'] = $end['data']['width'];
$thm['height'] = $end['data']['height'];
$settings['thumbnail_size'] = $thm['width'] >= $thm['height'] ? $thm['width'] : $thm['height'];
$rows = ceil($settings['teaser_items_per_row'] * $settings['teaser_rows_per_page'] / $settings['teaser_items_per_row']);
$ct_width = ($settings['thm_border'] + $settings['thm_margin'] + $settings['thm_padding']) * 2 * 3 + $thm['width'] * $settings['teaser_items_per_row'];
$ct_height = ($settings['thm_border'] + $settings['thm_margin'] + $settings['thm_padding']) * 2 * 3 + $thm['width'] * $settings['page_items_per_row'];
$settings['ga_container_width'] = $ct_width;
$rows = ceil($settings['page_items_per_row'] * $settings['page_rows_per_page'] / $settings['page_items_per_row']);
$cp_width = ($settings['thm_border'] + $settings['thm_margin'] + $settings['thm_padding']) * 2 * 3 + $thm['width'] * $settings['page_items_per_row'];
$cp_height = ($settings['thm_border'] + $settings['thm_margin'] + $settings['thm_padding']) * 2 * 3 + $thm['width'] * $rows;
$classes = array(
'container_class' => '.gallery-container.' . $type,
);
// Create or replace the css file.
$css_path = variable_get('gallery_assist_directory', FALSE) . '/css';
$destination = $css_path . '/' . $type . '.gallery_assist.css';
// Float.
// Teaser view.
$settings['float_margin_value'] = '10px;';
if ($settings['teaser_container_float'] != 'none') {
$settings['t_float'] = "float:{$settings['teaser_container_float']};";
if ($settings['teaser_container_float'] == 'right') {
$settings['t_float_margin'] = 'margin-left:';
}
if ($settings['teaser_container_float'] == 'left') {
$settings['t_float_margin'] = 'margin-right:';
}
$settings['t_float_margin'] .= 0;
//$settings['float_margin_value'];
}
// Page view.
if ($settings['page_container_float'] != 'none') {
if ($settings['ga_page_float'] == 'right') {
$settings['p_float_margin'] = 'margin-left:';
}
if ($settings['page_container_float'] == 'left') {
$settings['p_float_margin'] = 'margin-right:';
}
$settings['p_float'] = "float:{$settings['page_container_float']};";
$settings['p_float'] .= $settings['p_float_margin'] . $settings['float_margin_value'];
}
$css = array();
$css[] = '/* CSS file for the content type ' . $type . ' assignment. */';
$css[] = $classes['container_class'] . '.teaser {
width:' . $ct_width . 'px;
height:' . $ct_height . 'px;
border:5px solid red;
}';
$css[] = $classes['container_class'] . '.full {
' . (isset($settings['p_float']) && $settings['p_float'] ? $settings['p_float'] : '') . 'width:' . $cp_width . 'px;
height:' . $cp_height . 'px;
border:5px solid green;
}';
$css[] = $classes['container_class'] . ' .ga-image-box{
float:left;
width:' . $thm['width'] . 'px;
height:' . $thm['height'] . 'px;
border:' . $settings['thm_border'] . 'px solid ' . $settings['thm_border_color'] . ';
margin:' . $settings['thm_margin'] . 'px;
padding:' . $settings['thm_padding'] . 'px;
text-align:center;
}';
$css[] = '.gallery-assist-pager-top, .gallery-assist-pager-bottom {
/*padding:0 ' . $settings['thm_padding'] . 'px;*/
width:' . ($cp_width + ($settings['thm_padding'] + $settings['thm_margin'] + 5) / 2) . 'px;
}';
$css[] = '';
$data = implode("\n", $css);
file_prepare_directory($css_path, 1);
file_save_data($data, $destination, FILE_EXISTS_REPLACE);
drupal_set_message(t('A CSS file for the content type @assignment has been created.', array(
'@assignment' => node_type_get_name($type),
)));
}
/**
* Validate the GA assignments form submition.
*/
function gallery_assist_assignments_form_validate($form, &$form_state) {
if (!empty($form_state['values']['thm_border_color'])) {
if (!preg_match('/^rgb/', $form_state['values']['thm_border_color'], $match) || !preg_match('/^#/', $form_state['values']['thm_border_color'], $match)) {
// form_set_error('thm_border_color', 'Please');
$form_state['values']['thm_border_color'] = check_plain($form_state['values']['thm_border_color']);
}
}
}
/**
* Form builder; Manage GA global settings.
*
* @param $cero
* Placeholder array.
* @param $form_state
* An associative array containing the current state of the form.
*
* @ingroup forms
* @see gallery_assist_global_form_submit()
*/
function gallery_assist_global_form($cero, $form_state) {
$form = array();
$form['cache'] = array(
'#type' => 'fieldset',
'#title' => 'Caching',
'#collapsible' => TRUE,
);
$form['cache']['cacheforce'] = array(
'#type' => 'checkbox',
'#title' => t('Enable global cache for GA.'),
'#default_value' => variable_get("gallery_assist_cacheforce", FALSE),
'#description' => t('Force GA to cache the whole module data.<br />This option overwrite all assignments cache settings.'),
);
$form['cache']['cacheforce_is'] = array(
'#type' => 'hidden',
'#value' => variable_get("gallery_assist_cacheforce", FALSE),
);
$form['assignation'] = array(
'#type' => 'fieldset',
'#title' => 'Gallery functionality on content types',
'#collapsible' => TRUE,
);
$content_types = node_type_get_names();
$content_types_assignation = gallery_assist_check_assignation($content_types);
$form['assignation']['assigned'] = array(
'#type' => 'checkboxes',
'#options' => $content_types,
'#default_value' => $content_types_assignation,
'#description' => 'Assign the gallery functionality to the following content types',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save',
);
$form['gareset'] = array(
'#type' => 'submit',
'#value' => 'Reset',
);
return $form;
}
/**
* Process GA global settings form submissions.
*/
function gallery_assist_global_form_submit($form, &$form_state) {
$changes = FALSE;
//Assignation
foreach ($form_state['values']['assigned'] as $key => $value) {
if ($value == '0') {
if (variable_get("gallery_assist_{$key}", 0) == 1) {
variable_set("gallery_assist_{$key}", 0);
variable_set("gallery_assist_{$key}_data", array());
$changes = TRUE;
}
}
else {
if (variable_get("gallery_assist_{$key}", 0) == 0) {
variable_set("gallery_assist_{$key}", 1);
module_load_include('inc', 'gallery_assist', 'gallery_assist_variables');
variable_set("gallery_assist_{$key}_data", gallery_assist_default_settings());
$changes = TRUE;
}
}
}
if ($changes) {
menu_rebuild();
}
if ($form_state['values']['cacheforce'] != $form_state['values']['cacheforce_is']) {
variable_set("gallery_assist_cacheforce", $form_state['values']['cacheforce']);
}
}
/**
* Subforms.
*/
/**
* Upload settings subform.
*/
function _gallery_assist_upload_settings_form($settings) {
$form = array();
$form['upload_extensions'] = array(
'#type' => 'textfield',
'#title' => 'Allowed file extensions',
'#default_value' => $settings['upload_extensions'],
'#size' => 25,
'#max_length' => 150,
);
$form['upload_resolution'] = array(
'#type' => 'textfield',
'#title' => 'Images resolution',
'#default_value' => $settings['upload_resolution'],
'#size' => 25,
'#max_length' => 50,
);
$form['upload_file_size'] = array(
'#type' => 'textfield',
'#title' => 'Files upload size limit',
'#default_value' => $settings['upload_file_size'],
'#size' => 25,
'#max_length' => 15,
);
$form['upload_user_size'] = array(
'#type' => 'textfield',
'#title' => 'User upload size limit',
'#default_value' => $settings['upload_user_size'],
'#size' => 25,
'#max_length' => 15,
);
return $form;
}
/**
* Size styles subform.
*/
function _gallery_assist_size_styles_form($settings) {
$form = array();
$options = drupal_map_assoc(array_keys(image_styles()));
$form['icon_image_style'] = array(
'#type' => 'select',
'#title' => 'Icon',
'#options' => $options,
'#default_value' => $settings['icon_image_style'],
'#description' => 'cccccc',
);
$form['thumbnail_image_style'] = array(
'#type' => 'select',
'#title' => 'Thumbnail',
'#options' => $options,
'#default_value' => $settings['thumbnail_image_style'],
'#description' => '',
);
$form['preview_image_style'] = array(
'#type' => 'select',
'#title' => 'Preview',
'#options' => $options,
'#default_value' => $settings['preview_image_style'],
'#description' => '',
);
return $form;
}
/**
* Gallery specific node settings subform.
*/
function _gallery_assist_gallery_style_form($settings) {
$form = array();
// Teaser style.
$form['teaser'] = array(
'#type' => 'fieldset',
'#title' => 'Teaser',
'#prefix' => '<div class="ga-float-left" style="">',
'#suffix' => '</div>',
);
// Page style.
$form['page'] = array(
'#type' => 'fieldset',
'#title' => 'Page',
'#prefix' => '<div class="ga-float-left" style="">',
'#suffix' => '</div>',
);
// Page style.
$form['preview'] = array(
'#type' => 'fieldset',
'#title' => 'Preview',
'#prefix' => '<div class="ga-float-left" style="">',
'#suffix' => '</div>',
);
$options = drupal_map_assoc(array(
'center' => t('center'),
'left' => t('left'),
'right' => t('right'),
));
$form['teaser']['teaser_container_align'] = array(
'#type' => 'select',
'#title' => 'Container align',
'#options' => $options,
'#default_value' => $settings['teaser_container_align'],
'#description' => '',
);
$form['page']['page_container_align'] = array(
'#type' => 'select',
'#title' => 'Container align',
'#options' => $options,
'#default_value' => $settings['page_container_align'],
'#description' => '',
);
$form['preview']['preview_container_align'] = array(
'#type' => 'select',
'#title' => 'Container align',
'#options' => $options,
'#default_value' => $settings['preview_container_align'],
'#description' => '',
);
$options = drupal_map_assoc(array(
'none' => t('none'),
'left' => t('left'),
'right' => t('right'),
));
$form['teaser']['teaser_container_float'] = array(
'#type' => 'select',
'#title' => 'Container float',
'#options' => $options,
'#default_value' => $settings['teaser_container_float'],
'#description' => '',
);
$form['page']['page_container_float'] = array(
'#type' => 'select',
'#title' => 'Container float',
'#options' => $options,
'#default_value' => $settings['page_container_float'],
'#description' => '',
);
$form['preview']['preview_container_float'] = array(
'#type' => 'select',
'#title' => 'Container float',
'#options' => $options,
'#default_value' => $settings['preview_container_float'],
'#description' => '',
);
$form['teaser']['teaser_hide_container'] = array(
'#type' => 'checkbox',
'#title' => 'Hide container',
'#default_value' => $settings['teaser_hide_container'],
'#description' => '',
);
$form['page']['page_hide_container'] = array(
'#type' => 'checkbox',
'#title' => 'Hide container',
'#default_value' => $settings['page_hide_container'],
'#description' => '',
);
$form['page']['page_pager_enable'] = array(
'#type' => 'checkbox',
'#title' => 'Hide pager',
'#default_value' => $settings['page_pager_enable'],
'#description' => '',
);
$options = drupal_map_assoc(range(1, 20, 1));
$form['page']['page_pager_quantity'] = array(
'#type' => 'select',
'#title' => 'Pager no. items',
'#options' => $options,
'#default_value' => $settings['page_pager_quantity'],
'#description' => '',
);
$form['preview']['display_download_link'] = array(
'#type' => 'checkbox',
'#title' => 'Download link',
'#default_value' => $settings['display_download_link'],
'#description' => '',
);
return $form;
}
/**
* Pager subform.
*/
function _gallery_assist_pager_form($settings) {
$form = array();
$options = array(
'0' => t('numeric'),
'1' => t('graphic'),
);
$form['pager_type'] = array(
'#type' => 'select',
'#title' => 'Type',
'#options' => $options,
'#default_value' => $settings['pager_type'],
'#description' => '',
'#prefix' => '<div class="ga-float-left" style="">',
);
$options = array(
'default' => t('default'),
);
$options = gallery_assist_pager_options();
$form['pager_theme'] = array(
'#type' => 'select',
'#title' => 'Theme',
'#options' => $options,
'#default_value' => $settings['pager_theme'],
'#description' => '',
);
$options = array(
'top' => t('top'),
'bottom' => t('bottom'),
);
$form['pager_position'] = array(
'#type' => 'select',
'#title' => 'Position',
'#options' => $options,
'#default_value' => $settings['pager_position'],
'#description' => '',
);
$options = array(
'center' => t('center'),
'left' => t('left'),
'right' => t('right'),
);
$form['pager_align'] = array(
'#type' => 'select',
'#title' => 'Align',
'#options' => $options,
'#default_value' => $settings['pager_align'],
'#description' => '',
'#suffix' => '</div>',
);
$options = array(
'0' => t('full'),
'1' => t('short'),
);
$form['pager_format'] = array(
'#type' => 'select',
'#title' => 'Format',
'#options' => $options,
'#default_value' => $settings['pager_format'],
'#description' => '',
'#prefix' => '<div class="ga-float-left">',
);
$options = drupal_map_assoc(range(1, 20, 1));
$form['pager_quantity'] = array(
'#type' => 'select',
'#title' => 'No. Items',
'#options' => $options,
'#default_value' => $settings['pager_quantity'],
'#description' => '',
);
$form['pager_thm_height'] = array(
'#type' => 'textfield',
'#title' => 'Thumbnail height',
'#default_value' => $settings['pager_thm_height'],
'#size' => 8,
'#maxlength' => 3,
'#description' => '',
);
$form['pager_thm_active_height'] = array(
'#type' => 'textfield',
'#title' => 'Active thumbnail height',
'#default_value' => $settings['pager_thm_active_height'],
'#size' => 8,
'#maxlength' => 3,
'#description' => '',
'#suffix' => '</div>',
);
return $form;
}
/**
* List the aviable Gallery Assist Pager layouts.
*
* @ingroup forms
*/
function gallery_assist_pager_options() {
$pager_path_theme = drupal_get_path('theme', variable_get('theme_default', FALSE)) . '/ga_pager';
#$scan['theme'] = file_scan_directory($pager_path_theme, '.', $nomask = array('.', '..', 'README.txt'), 0, FALSE);
$scan['theme'] = file_scan_directory($pager_path_theme, '/.*/', array(
'recurse' => FALSE,
));
$pager_options = array(
'default' => 'default',
);
foreach ($scan as $dscan) {
foreach ($dscan as $p => $d) {
if (!is_file($d->uri)) {
$pager_options[$d->filename] = $d->filename;
}
}
}
return $pager_options;
}
/**
* Gallery elements subform.
*/
function _gallery_assist_elements_settings_form($settings) {
$form = array();
$options = drupal_map_assoc(range(0, 100, 1));
$options[0] = 'unlimited';
$form['teaser']['teaser_items_per_row'] = array(
'#type' => 'select',
'#title' => 'Items per row (teaser)',
'#options' => $options,
'#default_value' => $settings['teaser_items_per_row'],
'#description' => '',
);
$form['page']['page_items_per_row'] = array(
'#type' => 'select',
'#title' => 'Items per row (page)',
'#options' => $options,
'#default_value' => $settings['page_items_per_row'],
'#description' => '',
);
$form['teaser']['teaser_rows_per_page'] = array(
'#type' => 'select',
'#title' => 'Rows per page (teaser)',
'#options' => $options,
'#default_value' => $settings['teaser_rows_per_page'],
'#description' => '',
);
$form['page']['page_rows_per_page'] = array(
'#type' => 'select',
'#title' => 'Rows per page (page)',
'#options' => $options,
'#default_value' => $settings['page_rows_per_page'],
'#description' => '',
);
$options = drupal_map_assoc(range(1, 20, 1));
$form['thm_margin'] = array(
'#type' => 'select',
'#title' => 'Thumbnails margin',
'#options' => $options,
'#default_value' => $settings['thm_margin'],
);
$form['thm_padding'] = array(
'#type' => 'select',
'#title' => 'Thumbnails padding',
'#options' => $options,
'#default_value' => $settings['thm_padding'],
);
$form['thm_border'] = array(
'#type' => 'select',
'#title' => 'Thumbnails border',
'#options' => $options,
'#default_value' => $settings['thm_border'],
);
$form['thm_border_color'] = array(
'#type' => 'textfield',
'#title' => 'Thumbnails border color',
'#default_value' => check_plain($settings['thm_border_color']),
'#size' => 10,
);
return $form;
}
Functions
Name![]() |
Description |
---|---|
gallery_assist_assignments_form | Form builder; Manage GA content types specific settings. |
gallery_assist_assignments_form_submit | Process GA content types specific settings form submissions. |
gallery_assist_assignments_form_validate | Validate the GA assignments form submition. |
gallery_assist_global_form | Form builder; Manage GA global settings. |
gallery_assist_global_form_submit | Process GA global settings form submissions. |
gallery_assist_info | Provide to administrators resumed information of all concerning to GA. |
gallery_assist_pager_options | List the aviable Gallery Assist Pager layouts. |
_gallery_assist_elements_settings_form | Gallery elements subform. |
_gallery_assist_gallery_style_form | Gallery specific node settings subform. |
_gallery_assist_pager_form | Pager subform. |
_gallery_assist_size_styles_form | Size styles subform. |
_gallery_assist_upload_settings_form | Upload settings subform. |