6
* Administration page callbacks for the Fancybox module.
11
* Display the Fancybox settings form.
13
function fancybox_admin_settings_form($form_state) {
17
$form['fancybox_path'] = array(
18
'#type' => 'textfield',
19
'#title' => t('Path to Fancybox jQuery plugin'),
20
'#default_value' => variable_get('fancybox_path', FANCYBOX_DEFAULT_PATH),
21
'#description' => t('Enter the location of the <a href="!url" target="_blank">Fancybox jQuery Plugin</a>. It is recommended to use %path.', array('!url' => 'http://fancybox.net/', '%path' => FANCYBOX_DEFAULT_PATH)),
24
$settings = variable_get('fancybox_settings', array());
29
$data['options'] = array(
30
'#type' => 'fieldset',
31
'#title' => t('Options'),
34
$data['options'] += fancybox_options($settings['options']);
37
$data['activation'] = array(
38
'#type' => 'fieldset',
39
'#title' => t('Activation'),
40
'#collapsible' => TRUE,
43
$data['activation']['selector'] = array(
44
'#type' => 'textarea',
45
'#title' => t('jQuery selector'),
46
'#default_value' => isset($settings['activation']['selector']) ? $settings['activation']['selector'] : '',
48
$data['activation']['activation_type'] = array(
50
'#title' => t('Enable Fancybox on specific pages'),
52
'exclude' => t('Enable on every page except the listed pages.'),
53
'include' => t('Enable on only the listed pages.'),
55
'#default_value' => isset($settings['activation']['activation_type']) ? $settings['activation']['activation_type'] : 'exclude',
57
if (user_access('use PHP for block visibility')) {
58
$data['activation']['activation_type']['#options']['php'] = t('Enable if the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
60
$data['activation']['activation_pages'] = array(
61
'#type' => 'textarea',
62
'#title' => t('Pages'),
63
'#default_value' => isset($settings['activation']['activation_pages']) ? $settings['activation']['activation_pages'] : "admin*\nimg_assist*\nnode/add/*\nnode/*/edit",
64
'#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),
68
if (module_exists('image')) {
69
$data['image'] = array(
70
'#type' => 'fieldset',
71
'#title' => t('Image module'),
72
'#collapsible' => TRUE,
75
$data['image']['status'] = array(
76
'#type' => 'checkbox',
77
'#title' => t('Enable Fancybox on Image nodes'),
78
'#default_value' => isset($settings['image']['auto']) ? $settings['image']['auto'] : FALSE,
82
$sizes = image_get_sizes();
83
foreach ($sizes as $label => $size) {
84
$options[$label] = $size['label'];
87
$data['image']['size'] = array(
89
'#title' => t('Display size'),
90
'#options' => $options,
91
'#default_value' => isset($settings['image']['size']) ? $settings['image']['size'] : '_original',
92
'#description' => t('The size to be used when displaying an image in a Fancybox.'),
97
if (module_exists('imagefield')) {
98
$data['imagefield'] = array(
99
'#type' => 'fieldset',
100
'#title' => t('ImageField module'),
101
'#collapsible' => TRUE,
102
'#collapsed' => TRUE,
105
$data['imagefield']['grouping'] = array(
107
'#title' => t('Grouping'),
108
'#options' => array(1 => t('Group per field'), 2 => t('Group all fields on page'), 0 => t('No grouping')),
109
'#default_value' => isset($settings['imagefield']['grouping']) ? $settings['imagefield']['grouping'] : 1,
112
// ImageCache module:
113
if (module_exists('imagecache')) {
114
$options = array(0 => t('Original image (no preset)'));
115
foreach (imagecache_presets() as $preset) {
116
$options[$preset['presetname']] = $preset['presetname'];
118
$data['imagefield']['imagecache_preset'] = array(
120
'#title' => t('ImageCache preset'),
121
'#options' => $options,
122
'#default_value' => isset($settings['imagefield']['imagecache_preset']) ? $settings['imagefield']['imagecache_preset'] : 0,
123
'#description' => t('The ImageCache preset to be use when displaying ImageField images in Fancybox.'),
127
$data['imagefield']['use_node_title'] = array(
128
'#type' => 'checkbox',
129
'#title' => t('Use node title as caption'),
130
'#description' => t('By default, the caption for image fields is the title text for the image. If no title is configured, the alt text will be used. Check this to always display the node title as the image caption.'),
131
'#default_value' => isset($settings['imagefield']['use_node_title']) ? $settings['imagefield']['use_node_title'] : FALSE,
135
$form['data'] = $data;
136
$form['data']['#tree'] = TRUE;
138
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
139
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
145
* Validation handler for the Fancybox settings form.
147
function fancybox_admin_settings_form_validate($form, &$form_state) {
148
// TODO: Check fancybox_path for .js files.
152
* Submit handler for the Fancybox settings form.
154
function fancybox_admin_settings_form_submit($form, &$form_state) {
155
$op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
156
if ($op == t('Reset to defaults')) {
157
variable_del('fancybox_settings');
158
variable_del('fancybox_path');
159
drupal_set_message(t('The configuration options have been reset to their default values.'));
162
$form_state['values']['data']['options'] = fancybox_array_flatten($form_state['values']['data']['options']);
163
variable_set('fancybox_settings', $form_state['values']['data']);
164
variable_set('fancybox_path', rtrim($form_state['values']['fancybox_path'], '/ '));
165
drupal_set_message(t('The configuration options have been saved.'));
170
/*****************************************************************************
172
*****************************************************************************/
175
* Flatten an array, preserving its keys.
177
function fancybox_array_flatten($array) {
179
if (is_array($array)) {
180
foreach ($array as $key => $value) {
181
if (is_array($value)) {
182
$result += fancybox_array_flatten($value);
185
$result[$key] = $value;