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