/[drupal]/contributions/modules/node_gallery/node_gallery.admin.inc
ViewVC logotype

Contents of /contributions/modules/node_gallery/node_gallery.admin.inc

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


Revision 1.10 - (show annotations) (download) (as text)
Wed May 6 01:57:01 2009 UTC (6 months, 2 weeks ago) by kmonty
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1, DRUPAL-6--2
Changes since 1.9: +14 -6 lines
File MIME type: text/x-php
* Fixed a bug that caused many saved settings not to be loaded while editing an established Node Gallery Relationship
* Added the ability to have a cover view as the Gallery landing page
* Added the ability to select a preset for the Gallery landing page.
1 <?php
2 // $Id: node_gallery.admin.inc,v 1.8 2009/04/27 19:22:29 kmonty Exp $
3
4 /**
5 * @file
6 * Node gallery admin file.
7 *
8 */
9
10 function node_gallery_config_list() {
11 $items = gallery_config_gateway::get_types('gallery');
12 $node_types = node_get_types();
13
14 if (!empty($items)) {
15 $headers = array(t('Gallery Name'), t('Gallery type'), t('Image type'), t('Operations'));
16 foreach ($items as $item) {
17 $rows[] = array($item->name, $node_types[$item->gallery_type]->name,
18 $node_types[$item->image_type]->name, theme('links', node_gallery_config_operations($item)));
19 }
20 return theme('table', $headers, $rows, array('class' => 'node-gallery-config-list'));
21 }
22 else {
23 return t("There's no gallery type now.");
24 }
25 }
26
27 function node_gallery_config_operations($config) {
28 $items[] = array('title' => t('Edit'), 'href' => 'admin/build/node_gallery/edit/'. $config->gallery_type);
29 $items[] = array('title' => t('Delete'), 'href' => 'admin/build/node_gallery/delete/'. $config->gallery_type);
30
31 return $items;
32 }
33
34 function node_gallery_config_form($form_state, $gallery_config = NULL) {
35 $form = array();
36 static $node_types, $image_types, $imagecaches;
37
38 if (empty($imagecaches)) {
39 foreach (imagecache_presets() as $id => $imagecache) {
40 $imagecaches[$imagecache['presetname']] = $imagecache['presetname'];
41 }
42 }
43 if (empty($imagecaches)) {
44 form_set_error('Node gallery config', t('No imagecache preset now. You must set at least one.'));
45 }
46
47 if (empty($gallery_config)) {
48 drupal_set_title(t('Add Gallery Config'));
49 }
50 else {
51 drupal_set_title(t('Edit %name', array('%name' => $gallery_config->name)));
52 }
53 $gallery_config = empty($gallery_config) ? array() : (array) $gallery_config;
54 $gallery_config = empty($form_state['storage']) ? $gallery_config : array_merge($gallery_config, $form_state['storage']);
55 $gallery_config = empty($form_state['values']) ? $gallery_config : array_merge($gallery_config, $form_state['values']);
56
57 $form['name'] = array(
58 '#type' => 'textfield',
59 '#title' => t('Gallery Type Name'),
60 '#description' => t('The human-readable name of this content type. This text will be displayed as part of the list on the create content page. It is recommended that this name begin with a capital letter and contain only letters, numbers, and <strong>spaces</strong>.'),
61 '#maxlength' => 32,
62 '#required' => TRUE,
63 '#default_value' => $gallery_config['name']
64 );
65
66 $step = empty($form_state['values']['step']) ? 1 : $form_state['values']['step'] + 1;
67
68 $form['step'] = array(
69 '#type' => 'hidden',
70 '#value' => $step,
71 );
72
73 if ($step == 1) {
74 if (empty($node_types)) {
75 foreach (node_get_types() as $node_type) {
76 $node_types[$node_type->type] = $node_type->name;
77 }
78 }
79
80 $form['gallery_type'] = array(
81 '#type' => 'radios',
82 '#title' => t('Gallery Type'),
83 '#options' => $node_types,
84 '#description' => t('Select which content type should be used as gallery type.'),
85 '#default_value' => $gallery_config['gallery_type'],
86 '#required' => TRUE,
87 );
88 $form['image_type'] = array(
89 '#type' => 'radios',
90 '#title' => t('Image Type'),
91 '#options' => $node_types,
92 '#description' => t('Select which content type should be used as image type.'),
93 '#default_value' => $gallery_config['image_type'],
94 '#required' => TRUE,
95 );
96
97 $form['next'] = array(
98 '#type' => 'submit',
99 '#value' => t('Next'),
100 '#submit' => array('node_gallery_config_form_next_submit'),
101 );
102 }
103 else {
104 /*cck support*/
105 if (module_exists('content')) {
106 content_clear_type_cache();
107 $image_type = content_types($form_state['storage']['image_type']);
108 //non-cck fields
109 foreach ($image_type['extra'] as $name => $field) {
110 if ($name != 'menu' && $name != 'attachments') {
111 $image_type_fields[$name] = $field['label'];
112 }
113 }
114 //cck fields
115 foreach ($image_type['fields'] as $name => $field) {
116 $image_type_fields[$name] = $field['widget']['label'];
117 }
118 }
119 else {
120 $node_fields = node_gallery_get_type_fields($form_state['storage']['image_type']);
121 foreach ($node_fields as $name => $field) {
122 $image_type_fields[$name] = $field['label'];
123 }
124 }
125
126 //print_r($gallery_config);die;
127
128 $lightbox2 = module_exists('lightbox2');
129 drupal_add_js(drupal_get_path('module', 'node_gallery') .'/node_gallery.admin.js', 'module');
130
131 $form['data'] = array(
132 '#tree' => TRUE,
133 );
134
135 $form['data']['display_fields'] = array(
136 '#type' => 'checkboxes',
137 '#title' => t('Fields'),
138 '#options' => $image_type_fields,
139 '#description' => t('Specify which fields should be displayed.'),
140 '#required' => TRUE,
141 '#default_value' => empty($gallery_config['display_fields']) ? array() : $gallery_config['display_fields'],
142 );
143
144 $form['data']['gallery_directory'] = array(
145 '#type' => 'textfield',
146 '#title' => t('Gallery Directory'),
147 '#description' => t('Specify a subdirectory of the file system to save the images of your gallery . The document root is \'files\'.
148 Use %uid for user_id, %username for username, %gid for gallery_id, %gallery_name for gallery_name.'),
149 '#default_value' => $gallery_config['gallery_directory']
150 );
151
152 $form['data']['default_cover'] = array(
153 '#type' => 'textfield',
154 '#title' => t('Default Cover Image'),
155 '#description' => t('Specify a default cover image to show when there is not an image in gallery. The path begins with your drupal root. <strong>Do not include the leading slash /.</strong>'),
156 '#default_value' => $gallery_config['default_cover'],
157 );
158
159 $form['data']['image_size'] = array(
160 '#type' => 'fieldset',
161 '#title' => t('Image Sizes'),
162 '#description' => t('Specify which imagecache preset you wish to use to display the image.'),
163 '#tree' => TRUE,
164 );
165 $form['data']['image_size']['cover'] = array(
166 '#type' => 'select',
167 '#title' => t('Cover'),
168 '#options' => $imagecaches,
169 '#default_value' => $gallery_config['image_size']['cover'],
170 );
171 $form['data']['image_size']['thumbnail'] = array(
172 '#type' => 'select',
173 '#title' => t('Thumbnail'),
174 '#options' => $imagecaches,
175 '#default_value' => $gallery_config['image_size']['thumbnail'],
176 );
177 $form['data']['image_size']['preview'] = array(
178 '#type' => 'select',
179 '#title' => t('Preview (This will be your Display--A Preview of the Full-Size Image)'),
180 '#options' => $imagecaches,
181 '#default_value' => $gallery_config['image_size']['preview'],
182 );
183
184 $form['data']['teaser'] = array(
185 '#type' => 'fieldset',
186 '#title' => t('Teaser Setting'),
187 '#description' => t('Specify how to display the gallery and image when viewing the node as a teaser.'),
188 );
189
190 $display_extra_options = array();
191 if ($lightbox2) {
192 $display_extra_options['lightbox2_gallery'] = t('Thumbnails that open a Lightbox2 Gallery');
193 }
194
195 $form['data']['teaser']['gallery_display_type'] = array(
196 '#type' => 'radios',
197 '#title' => t('Display Type'),
198 '#attributes' => array('class' => 'teaser-display-type-radios'),
199 '#options' => array_merge(array('cover' => t('Cover'), 'thumbnails' => t('Thumbnails')), $display_extra_options),
200 '#default_value' => empty($gallery_config['teaser']['gallery_display_type']) ? 'cover' : $gallery_config['teaser']['gallery_display_type'],
201 );
202 $form['data']['teaser']['thumbnails_num'] = array(
203 '#type' => 'textfield',
204 '#title' => t('Number of Thumbnails to Display'),
205 '#description' => t('If you select the gallery display type as thumbnails above, enter the number of thumbnails you want to display when viewing the teaser.'),
206 '#default_value' => $gallery_config['teaser']['thumbnails_num'],
207 );
208 if ($lightbox2) {
209 $form['data']['teaser']['lightbox2_gallery'] = array(
210 '#type' => 'select',
211 '#title' => t('Image Size for Lightbox2 Gallery'),
212 '#options' => $imagecaches,
213 '#description' => t('Select an Imagecache preset that will be used with the Lightbox2 popup.'),
214 '#default_value' => $gallery_config['teaser']['lightbox2_gallery'],
215 '#prefix' => '<div class="lightbox2-gallery-preset">',
216 '#suffix' => '</div>'
217 );
218 }
219 $form['data']['teaser']['image'] = array(
220 '#type' => 'select',
221 '#title' => t('Image Size for Teaser Display Type'),
222 '#options' => $imagecaches,
223 '#default_value' => $gallery_config['teaser']['image'],
224 );
225
226 /**
227 * Gallery Landing page
228 */
229 $form['data']['gallery'] = array(
230 '#type' => 'fieldset',
231 '#title' => t('Gallery Landing Page Setting'),
232 '#description' => t('Specify how to display the gallery landing page and image when viewing the node as a teaser.'),
233 );
234
235 $gallery_display_extra_options = array();
236 $gallery_display_default_value = ($gallery_config['gallery']['gallery_display'] == '') ? 'thumbnails' : $gallery_config['gallery']['gallery_display'];
237 if ($lightbox2) {
238 $gallery_display_extra_options['lightbox2_gallery'] = t('Thumbnails that open a Lightbox2 Gallery');
239 }
240 else {
241 if ($gallery_display_default_value == 'lightbox2_gallery') {
242 // We don't want the default to be a radio that doesn't exist
243 $gallery_display_default_value = 'thumbnails';
244 }
245 }
246
247 $form['data']['gallery']['gallery_display'] = array(
248 '#type' => 'radios',
249 '#title' => t('Gallery Display Type'),
250 '#attributes' => array('class' => 'gallery-display-type-radios'),
251 '#options' => array_merge(array('cover' => t('Cover'), 'thumbnails' => t('Thumbnails')), $gallery_display_extra_options),
252 '#default_value' => $gallery_display_default_value,
253 );
254 if ($lightbox2) {
255 $form['data']['gallery']['lightbox2_gallery_preset'] = array(
256 '#type' => 'select',
257 '#title' => t('Image Size for Lightbox2 Gallery'),
258 '#options' => $imagecaches,
259 '#description' => t('Select an Imagecache preset that will be used with the Lightbox2 popup.'),
260 '#default_value' => $gallery_config['gallery']['lightbox2_gallery_preset'],
261 '#prefix' => '<div class="gallery-lightbox2-gallery-preset">',
262 '#suffix' => '</div>'
263 );
264 }
265 $form['data']['gallery']['image'] = array(
266 '#type' => 'select',
267 '#title' => t('Image Size for Gallery Display Type'),
268 '#options' => $imagecaches,
269 '#default_value' => $gallery_config['gallery']['image'],
270 );
271
272 $extra_options = array();
273 $extra_description = '';
274 if ($lightbox2) {
275 $extra_options['lightbox2'] = t('Enable as Lightbox2 Popup');
276 }
277 else {
278 $extra_description = '<br />'. t('If you install and enable the <a href="http://drupal.org/project/lightbox2">Lightbox2</a> module, you can use Lightbox to display a larger version of the photo.');
279 }
280
281 $form['data']['view_original'] = array(
282 '#type' => 'radios',
283 '#title' => t('View Larger Image'),
284 '#attributes' => array('class' => 'view-original-radios'),
285 '#options' => array_merge(array('0' => t('Disable'), 'default' => t('Enable as a Link on the Displayed Image'), 'text' => t('Enable as Text Link Below the Displayed Image')), $extra_options),
286 '#description' => t('Specify whether allow or not viewing the original image.') . $extra_description,
287 '#default_value' => empty($gallery_config['view_original']) ? 0 : $gallery_config['view_original'],
288 );
289
290 $form['data']['view_original_text'] = array(
291 '#type' => 'textfield',
292 '#title' => t('View Original Text Link'),
293 '#description' => t('If you have selected the "Enable Text Link Below Displayed Image" option, you should provide some text for the link.'),
294 '#default_value' => empty($gallery_config['view_original_text']) ? t('Download the Original Image') : $gallery_config['view_original_text'],
295 '#prefix' => '<div class="view-original-text-value">',
296 '#suffix' => '</div>'
297 );
298
299 // Force the user to select a imagecache preset for lightbox
300 if ($lightbox2) {
301 $form['data']['lightbox2'] = array(
302 '#type' => 'select',
303 '#title' => t('Imagecache Preset for Lightbox2'),
304 '#options' => $imagecaches,
305 '#description' => t('Select an Imagecache preset that will be used with the Lightbox2 popup. Please note that this preset should be larger than your Display preset.'),
306 '#default_value' => $gallery_config['lightbox2'],
307 '#prefix' => '<div class="lightbox2-preset">',
308 '#suffix' => '</div>'
309 );
310 }
311
312 $form['data']['content_display'] = array(
313 '#type' => 'radios',
314 '#title' => t('Choose the content you want to display'),
315 '#options' => array('gallery' => t('Gallery'), 'image' => t('Images')),
316 '#description' => t("If you select 'Gallery', the body text of the Gallery node will be used. If you select 'Images', the
317 body text of the Image node will be used. This allows you choose if you want the content display with each image to be different or not."),
318 '#default_value' => empty($gallery_config['content_display']) ? 'image' : $gallery_config['content_display'],
319 );
320
321 $form['data']['image_comment'] = array(
322 '#type' => 'radios',
323 '#title' => t('Comment to image'),
324 '#options' => array(t('Disabled'), t('Read only'), t('Read/Write')),
325 '#description' => t('Choose whether or not to allow comment to images.'),
326 '#default_value' => ($gallery_config['image_comment'] == '') ? 2 : $gallery_config['image_comment'],
327 );
328
329 $form['data']['upload_settings'] = array(
330 '#type' => 'fieldset',
331 '#title' => t('Image Upload Settings'),
332 '#description' => t('This allows you to configure the bulk upload page.'),
333 );
334
335 $form['data']['upload_settings']['number_uploads'] = array(
336 '#type' => 'select',
337 '#title' => t('Number of Uploads'),
338 '#options' => array(
339 '1' => '1',
340 '2' => '2',
341 '3' => '3',
342 '4' => '4',
343 '5' => '5',
344 '6' => '6',
345 '7' => '7',
346 '8' => '8',
347 '9' => '9',
348 '10' => '10',
349 '11' => '11',
350 '12' => '12',
351 '13' => '13',
352 '14' => '14',
353 '15' => '15',
354 '16' => '16',
355 '17' => '17',
356 '18' => '18',
357 '19' => '19',
358 '20' => '20',
359 ),
360 '#multiple' => FALSE,
361 '#description' => t('This allows you to specify how many file upload fields appear on the image upload form. By default, only 5 fields are provided. We recommend you do not have more than 5 fields if you are on a shared host or have limited resourced. If you incress this to more than 5, we highly recommend you test this by uploading lots of large files before putting your site into production.'),
362 '#default_value' => empty($gallery_config['upload_settings']['number_uploads']) ? '5' : $gallery_config['upload_settings']['number_uploads'],
363 );
364
365 $form['previous'] = array(
366 '#type' => 'submit',
367 '#value' => t('Previous'),
368 '#submit' => array('node_gallery_config_form_pre_submit'),
369 );
370 $form['submit'] = array(
371 '#type' => 'submit',
372 '#value' => t('Submit'),
373 );
374 }
375
376 return $form;
377 }
378
379 function node_gallery_config_form_validate($form, &$form_state) {
380 if ($form_state['values']['next'] == t('Next')) {
381 if ($form_state['values']['gallery_type'] == $form_state['values']['image_type']) {
382 unset($form_state['values']['step']);
383 form_set_error('Type', t('The gallery type and image type can\'t be the same.'));
384 }
385 }
386 }
387
388 function node_gallery_config_form_next_submit($form, &$form_state) {
389 $form_state['storage'] = empty($form_state['storage']) ? $form_state['values'] : array_merge($form_state['storage'], $form_state['values']);
390 }
391
392 function node_gallery_config_form_pre_submit($form, &$form_state) {
393 $form_state['storage'] = empty($form_state['storage']) ? $form_state['values'] : array_merge($form_state['storage'], $form_state['values']);
394 unset($form_state['values']['step']);
395 }
396
397 function node_gallery_config_form_submit($form, &$form_state) {
398 $submit_values = array_merge($form_state['storage'], $form_state['values']);
399
400 $gallery_config = new gallery_config($submit_values);
401 $gallery_config->save();
402
403 unset($form_state['storage']);
404 $form_state['rebuild'] = FALSE;
405 $form_state['redirect'] = 'admin/build/node_gallery';
406 }
407
408 function node_gallery_config_delete_form($form_state, $gallery_config) {
409 $form['gallery_type'] = array(
410 '#type' => 'value',
411 '#value' => $gallery_config->gallery_type,
412 );
413
414 return confirm_form($form, t('Are you sure you want to delete gallery type config %name?', array('%name' => $gallery_config->gallery_type)),
415 'admin/build/node_gallery', NULL, t('Delete'), t('Back'));
416 }
417
418 function node_gallery_config_delete_form_submit($form, &$form_state) {
419 $gallery_config = new gallery_config($form_state['values']);
420
421 if ($gallery_config->delete()) {
422 drupal_set_message(t('Gallery type config %name has been deleted.', array('%name' => $gallery_config->gallery_type)));
423 watchdog(
424 'node_gallery',
425 t('Image gallery delete form: %name deleted.', array('%name' => $gallery_config->gallery_type)),
426 WATCHDOG_NOTICE
427 );
428
429 $form_state['redirect'] = 'admin/build/node_gallery';
430 }
431 }
432
433 /**
434 * copy from cck module.
435 *
436 * @param unknown_type $type_name
437 * @return unknown
438 */
439 function node_gallery_get_type_fields($type_name) {
440 $type = node_get_types('type', $type_name);
441 $extra = array();
442
443 if ($type->has_title) {
444 $extra['title'] = array(
445 'label' => $type->title_label,
446 'description' => t('Node module form.'),
447 'weight' => -5
448 );
449 }
450 if ($type->has_body) {
451 $extra['body_field'] = array(
452 'label' => $type->body_label,
453 'description' => t('Node module form.'),
454 'weight' => 0,
455 'view' => 'body'
456 );
457 }
458 if (module_exists('locale') && variable_get("language_content_type_$type_name", 0)) {
459 $extra['language'] = array(
460 'label' => t('Language'),
461 'description' => t('Locale module form.'),
462 'weight' => 0
463 );
464 }
465 if (module_exists('taxonomy') && taxonomy_get_vocabularies($type_name)) {
466 $extra['taxonomy'] = array(
467 'label' => t('Taxonomy'),
468 'description' => t('Taxonomy module form.'),
469 'weight' => -3
470 );
471 }
472
473 return $extra;
474 }

  ViewVC Help
Powered by ViewVC 1.1.2