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

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

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


Revision 1.15 - (show annotations) (download) (as text)
Thu Nov 5 04:53:17 2009 UTC (3 weeks ago) by rapsli
Branch: MAIN
Changes since 1.14: +12 -72 lines
File MIME type: text/x-php
* support for multiple galleries
* implemented hook_fast_gallery_info to easly plug into the storage engine
1 <?php
2 // $Id:
3
4 function _fast_gallery_gallery_form($key, $chid = NULL, $value = '', $title = '', $size = 10, $alias = '') {
5 $form = array(
6 '#tree' => TRUE,
7 );
8
9 // We'll manually set the #parents property of these fields so that
10 // their values appear in the $form_state['values']['choice'] array.
11 $form['chid'] = array(
12 '#type' => 'value',
13 '#value' => $chid,
14 '#parents' => array('a_gallery', $key, 'chid'),
15 );
16
17 $form['fg_path'] = array(
18 '#type' => 'textfield',
19 '#default_value' => $value,
20 '#size' => 30,
21 '#parents' => array('a_gallery', $key, 'fg_path'),
22 );
23
24 $form['fg_alias'] = array(
25 '#type' => 'textfield',
26 '#default_value' => $alias,
27 '#size' => 30,
28 '#parents' => array('a_gallery', $key, 'fg_alias'),
29 );
30
31 $form['fg_title'] = array(
32 '#type' => 'textfield',
33 '#default_value' => $title,
34 '#size' => 30,
35 '#parents' => array('a_gallery', $key, 'fg_title'),
36 );
37
38 /*$form['weight'] = array(
39 '#type' => 'weight',
40 '#default_value' => $weight,
41 '#delta' => $size,
42 '#parents' => array('a_gallery', $key, 'weight'),
43 );*/
44
45 return $form;
46 }
47
48 /**
49 * Callback function for admin settings
50 */
51 function fast_gallery_general_settings_form($form, &$form_state) {
52 $gallery_default = variable_get('fg_galleries', array());
53
54 // Add a wrapper for the choices and more button.
55 $form['gallery_wrapper'] = array(
56 '#tree' => FALSE,
57 '#weight' => -4,
58 '#prefix' => '<div class="clearfix" id="fg-galleries-wrapper">',
59 '#suffix' => '</div>',
60 );
61
62 // Container for just the poll choices.
63 $form['gallery_wrapper']['a_gallery'] = array(
64 '#prefix' => '<div id="fg-gallery">',
65 '#suffix' => '</div>',
66 '#theme' => 'fg_multiple_galleries',
67 );
68
69 // Add the current choices to the form.
70 $delta = 0;
71 $weight = 0;
72 if (!isset($form_state['values']['a_gallery'])) {
73 $gallery_count = 1;
74 }
75 else {
76 $gallery_count = sizeof($form_state['values']['a_gallery']);
77 $ar_galleries = $form_state['values']['a_gallery'];
78 }
79
80 if (isset($gallery_default)) {
81 $delta = count($gallery_default);
82 $weight = -$delta;
83 foreach ($gallery_default as $gid => $gal) {
84 $key = 'chid:' . $gid;
85 $form['gallery_wrapper']['a_gallery'][$key] = _fast_gallery_gallery_form($key, $gid, $gal['fg_path'], $gal['fg_title'], $gallery_count, $gal['fg_alias']);
86 //$weight = ($gal['weight'] > $weight) ? $gal['weight'] : $weight;
87 }
88 }
89
90 $key = 'new:' . ($delta);
91 $form['gallery_wrapper']['a_gallery'][$key] = _fast_gallery_gallery_form($key, NULL, '', '', $gallery_count, '');
92
93 // We name our button 'poll_more' to avoid conflicts with other modules using
94 // AJAX-enabled buttons with the id 'more'.
95 $form['gallery_wrapper']['fg_more'] = array(
96 '#type' => 'submit',
97 '#value' => t('Add gallery'),
98 '#description' => t("If the amount of boxes above isn't enough, click here to add more choices."),
99 '#weight' => 1,
100 '#submit' => array(''), // If no javascript action.
101 '#ajax' => array(
102 'callback' => 'fast_gallery_ajax_handler',
103 'wrapper' => 'fg-gallery',
104 'method' => 'replace',
105 'effect' => 'fade',
106 ),
107 );
108
109 $form['fg_setup'] = array(
110 '#type' => 'fieldset',
111 '#title' => t('Setup'),
112 '#collapsible' => TRUE,
113 '#collapsed' => FALSE,
114 );
115
116 $engines = module_invoke_all('fast_gallery_info');
117
118 $ar_engines = array();
119 foreach ($engines['storageengine'] as $key => $engine) {
120 $ar_engines[$key] = $engine['name'];
121 }
122
123 $form['fg_setup']['fg_storage_engine'] = array(
124 '#type' => 'select',
125 '#title' => t('Storage engine'),
126 '#default_value' => variable_get('fg_storage_engine', FG_DEFAULT_STORAGE_ENGINE),
127 '#options' => $ar_engines,
128 );
129
130 $js_framework_options = array();
131 $js_framework_options[0] = t('<none>');
132 $js_framework_default = 0;
133 if (module_exists('thickbox'))
134 $js_framework_options[1] = t('Thickbox');
135 if (module_exists('lightbox2')) {
136 $js_framework_default = 2;
137 $js_framework_options[2] = t('Lightbox2 (no slideshow)');
138 $js_framework_options[3] = t('Lightbox2 (with slideshow)');
139 }
140
141 $form['fg_setup']['fast_gallery_js_framework'] = array(
142 '#type' => 'select',
143 '#title' => t('Choose your Javascript framework'),
144 '#options' => $js_framework_options,
145 '#default_value' => variable_get('fast_gallery_js_framework', $js_framework_default),
146 '#description' => t('Thickbox and Lightbox are the two options for displaying images.'),
147 );
148
149 $ic_link = l('Imagecache', 'admin/build/imagecache');
150 $form['fast_gallery_operations'] = array(
151 '#type' => 'fieldset',
152 '#title' => t('Operations'),
153 '#collapsible' => TRUE,
154 '#collapsed' => FALSE,
155 '#tree' => FALSE,
156 '#description' => t('Remember to first click Save Settings (if you made any changes) before performing the below operations. Clear the database whenever you change the gallery path. Rescan the database whenever you add images, delete images, move images, or restructure the hierarchy. Flush Internal Cache to delete and force recaching of Internal Cache thumbnails. If you are using Imagecache, you need to flush thumbnails on the Imagecache settings page: ') . $ic_link,
157 );
158
159 $form['fast_gallery_operations']['fast_gallery_clear'] = array(
160 '#type' => 'button',
161 '#value' => t('Clear DB'),
162 '#ajax' => array(
163 'callback' => 'fast_gallery_ajax_handler',
164 'method' => 'replace',
165 'effect' => 'fade',
166 'progress' => array(
167 'type' => 'bar',
168 'message' => t('Clearing DB')
169 ),
170 'wrapper' => 'attach-wrapper',
171 )
172 );
173
174 $form['fast_gallery_operations']['fast_gallery_rescan'] = array(
175 '#type' => 'button',
176 '#value' => t('Rescan'),
177 '#ajax' => array(
178 'callback' => 'fast_gallery_ajax_handler',
179 'method' => 'replace',
180 'effect' => 'fade',
181 'progress' => array(
182 'type' => 'bar',
183 'message' => t('Scan for new pictures...')
184 ),
185 'wrapper' => 'attach-wrapper',
186 )
187 );
188
189 $form['fast_gallery_operations']['fast_gallery_flush_thumbs'] = array(
190 '#type' => 'button',
191 '#value' => t('Flush Internal Cache'),
192 '#ajax' => array(
193 'callback' => 'fast_gallery_ajax_handler',
194 'method' => 'replace',
195 'effect' => 'fade',
196 'progress' => array(
197 'type' => 'bar',
198 'message' => t('Flushing thumbnails')
199 ),
200 'wrapper' => 'attach-wrapper',
201 )
202 );
203
204 $form['submit'] = array(
205 '#type' => 'submit',
206 '#value' => t('Submit'),
207 );
208 return $form;
209 }
210
211 /**
212 * validation function for the settinsg form
213 * @param $form
214 * @param $form_state
215 */
216 function fast_gallery_general_settings_form_validate($form, &$form_state) {
217 foreach ($form_state['values']['a_gallery'] as $key => $gallery) {
218 $path = $gallery['fg_path'];
219
220 //incase we have a path -> check if it's valid
221 if (!is_dir($path) && $path != '') {
222 form_error($form['gallery_wrapper']['a_gallery'][$key]['fg_path'], t('This path does not exist.'));
223 }
224
225 //incase there's a path make sure the path ends with a slash
226 if ($path != '') {
227 $last_token = substr($path, -1);
228 if ($last_token != '/') {
229 $path .= '/';
230 $form_state['values']['a_gallery'][$key]['fg_path'] = $path;
231 }
232 }
233
234 //incase there's a path -> check if there's an alias
235 if ($form_state['values']['a_gallery'][$key]['fg_alias'] == '' && $form_state['values']['a_gallery'][$key]['fg_path'] != '') {
236 form_error($form['gallery_wrapper']['a_gallery'][$key]['fg_alias'], t('Please enter an alias'));
237 }
238 }
239 }
240
241 /**
242 * submitting the form making sure we save all the relevant information
243 * @param $form
244 * @param $form_state
245 * @return unknown_type
246 */
247 function fast_gallery_general_settings_form_submit($form, &$form_state) {
248
249 $ar_galleries = array();
250 foreach ($form_state['values']['a_gallery'] as $gallery) {
251 if ($gallery['fg_path'] != '') {
252 $ar_galleries[$gallery['fg_path']] = $gallery;
253 }
254 }
255 variable_set('fg_galleries', $ar_galleries);
256
257 menu_rebuild();
258 }
259 function fast_gallery_ajax_handler($form, $form_state) {
260 $fg = fast_gallery_get_FastGallery();
261
262 switch ($form_state['clicked_button']['#id']) {
263 case 'edit-fast-gallery-flush-thumbs': //clear cache
264 $cache = fast_gallery_get_cache();
265 $cache->flushThumbs();
266 break;
267 case 'edit-fast-gallery-rescan': //reindex images
268 $fg->rescanGallery();
269 break;
270 case 'edit-fast-gallery-clear': //clear db
271 $fg->clearDb();
272 break;
273 case 'edit-fg-more':
274 $choice_form = $form['gallery_wrapper']['a_gallery'];
275 return $choice_form;
276 break;
277 }
278 }
279
280 /**
281 * theming the form for adding new galleries
282 * @param $key
283 * @param $chid
284 * @param $value
285 * @param $votes
286 * @param $weight
287 * @param $size
288 * @return unknown_type
289 */
290 function theme_fg_multiple_galleries($variables) {
291 $form = $variables['form'];
292
293 //drupal_add_tabledrag('fg-galleries-table', 'order', 'sibling', 'poll-weight');
294
295 $delta = 0;
296 $rows = array();
297 $headers = array(
298 // '',
299 t('Path to Gallery'),
300 t('Path Alias'),
301 t('Title of Gallery'),
302 //t('Weight'),
303 );
304
305 foreach (element_children($form) as $key) {
306 $delta++;
307 // Set special classes for drag and drop updating.
308 //$form[$key]['weight']['#attributes']['class'] = array('poll-weight');
309
310 // Build the table row.
311 $row = array(
312 'data' => array(
313 //array('class' => array('choice-flag')),
314 drupal_render($form[$key]['fg_path']),
315 drupal_render($form[$key]['fg_alias']),
316 drupal_render($form[$key]['fg_title']),
317 //drupal_render($form[$key]['weight']),
318 ),
319 //'class' => array('draggable'),
320 );
321
322 // Add any additional classes set on the row.
323 if (!empty($form[$key]['#attributes']['class'])) {
324 $row['class'] = array_merge($row['class'], $form[$key]['#attributes']['class']);
325 }
326
327 $rows[] = $row;
328 }
329
330 $output = theme('table', array('header' => $headers, 'rows' => $rows, 'attributes' => array('id' => 'fg-galleries-table')));
331 $output .= drupal_render_children($form);
332 return $output;
333 }

  ViewVC Help
Powered by ViewVC 1.1.2