| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: gallery_block_admin.inc,v 1.1.2.8 2008/08/04 21:13:06 profix898 Exp $ 3 4 require_once(drupal_get_path('module', 'gallery') .'/gallery_settings.inc'); 5 6 /** 7 * gallery.module : gallery_block_admin.inc 8 * Gallery block settings 9 */ 10 11 /** 12 * Function _gallery_block_admin_navigation(). 13 */ 14 function _gallery_block_admin_navigation() { 15 $form['gallery_block_navigation_cache'] = array( 16 '#type' => 'select', 17 '#title' => t('Block cache'), 18 '#default_value' => variable_get('gallery_block_navigation_cache', BLOCK_NO_CACHE), 19 '#options' => array( 20 BLOCK_NO_CACHE => t('Cache disabled'), 21 BLOCK_CACHE_PER_USER | BLOCK_CACHE_PER_PAGE => t('Cache per user and page'), 22 BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE => t('Cache per role and page') 23 ), 24 '#description' => t('Configure cache settings for this block. It\'s usually safe to set this to \'Cache per user and page\'.') 25 ); 26 27 $form['element'] = array('#type' => 'value', '#value' => 'gallery_block_navigation'); 28 return $form; 29 } 30 31 /** 32 * Function _gallery_block_admin_block(). 33 */ 34 function _gallery_block_admin_block($delta) { 35 $block_map = _gallery_block_map(TRUE); 36 $block_type = variable_get('gallery_block_'. $delta .'_type', 'imageblock'); 37 $plugin = $block_map[$block_type]['plugin']; 38 $plugin_block = $block_map[$block_type]['block']; 39 40 // General block settings (common for all G2 block types) 41 $form['gallery_block_'. $delta .'_blockid'] = array( 42 '#type' => 'textfield', 43 '#title' => t('Block Identifier [Block @id]', array('@id' => $delta)), 44 '#default_value' => variable_get('gallery_block_'. $delta .'_blockid', ''), 45 '#size' => 30, 46 '#maxlength' => 255, 47 '#description' => t('A short identifier to distinguish blocks of the same type. (Blocks are numbered by default)') 48 ); 49 $cache_options = array( 50 BLOCK_NO_CACHE => t('Cache disabled'), 51 BLOCK_CACHE_PER_USER | BLOCK_CACHE_PER_PAGE => t('Cache per user and page'), 52 BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE => t('Cache per role and page'), 53 BLOCK_CACHE_PER_USER => t('Cache per user'), 54 BLOCK_CACHE_PER_ROLE => t('Cache per role'), 55 BLOCK_CACHE_GLOBAL => t('Cache globally (use carefully)') 56 ); 57 // Make sure the cache options are compatible with the block parameters 58 if (count($block_map[$block_type]['params'])) { 59 unset($cache_options[BLOCK_CACHE_GLOBAL]); 60 // If the block is item-specific we must (at least) cache per page 61 if (in_array('item', $block_map[$block_type]['params'])) { 62 unset($cache_options[BLOCK_CACHE_PER_ROLE], $cache_options[BLOCK_CACHE_PER_USER]); 63 } 64 } 65 $form['gallery_block_'. $delta .'_cache'] = array( 66 '#type' => 'select', 67 '#title' => t('Block cache'), 68 '#default_value' => variable_get('gallery_block_'. $delta .'_cache', BLOCK_NO_CACHE), 69 '#options' => $cache_options, 70 '#description' => _gallery_block_admin_description($block_type .'_cache'), 71 ); 72 73 // Block type selector 74 $block_list = array(); 75 foreach ($block_map as $type => $details) { 76 $block_list[$type] = $details['block']; 77 } 78 $form['gallery_block_'. $delta .'_type'] = array( 79 '#type' => 'select', 80 '#title' => t('Block type'), 81 '#default_value' => $block_type, 82 '#options' => $block_list, 83 '#description' => t('Select the Gallery2 block to be displayed in this Drupal block. In previous versions only 84 \'ImageBlock\' was available, but now you can embed any Gallery2 block in Drupal.'), 85 ); 86 87 // Block specific settings 88 if ($param_form = _gallery_block_admin_block_params($delta, $plugin, $plugin_block)) { 89 $form[$block_type] = array( 90 '#type' => 'fieldset', 91 '#title' => t('@block settings', array('@block' => $plugin_block)), 92 '#collapsible' => TRUE, 93 '#collapsed' => FALSE 94 ); 95 $form[$block_type][] = $param_form; 96 } 97 98 // Save/Edit button 99 $form['element'] = array('#type' => 'value', '#value' => 'gallery_block_'. $delta); 100 $form['update_btn'] = array( 101 '#type' => 'submit', 102 '#value' => t('Save and Edit'), 103 '#submit' => array('_gallery_block_admin_update') 104 ); 105 106 return $form; 107 } 108 109 /** 110 * Function _gallery_block_admin_description(). 111 */ 112 function _gallery_block_admin_description($element) { 113 switch($element) { 114 case 'imageblock_cache': 115 return t('Configure cache settings for this block. Unless random images are used you can safely keep this to 116 \'Cache per user and page\'. If you dont have per-user permissions configured in your gallery you 117 can improve performance by setting to \'Cache per role and page\'.'); 118 default: 119 return ''; 120 } 121 } 122 123 /** 124 * Function _gallery_block_admin_block_params(). 125 */ 126 function _gallery_block_admin_block_params($delta, $plugin, $plugin_block) { 127 $g2_blocks = gallery_list_blocks(); 128 129 // Image block specific settings 130 if ($plugin_block == 'ImageBlock') { 131 $element = 'gallery_block_'. $delta .'_'. strtolower($plugin_block); 132 return _gallery_block_admin_imageblock($element); 133 } 134 135 // Block specific settings 136 if (isset($g2_blocks[$plugin][$plugin_block]['vars'])) { 137 // Generate a Drupal form element for each G2 block variable 138 foreach ($g2_blocks[$plugin][$plugin_block]['vars'] as $parameter => $options) { 139 $block = strtolower($plugin_block .'_'. $parameter); 140 $element = 'gallery_block_'. $delta .'_'. $block; 141 // Common form element properties 142 $form[$element] = array( 143 '#title' => $options['description'], 144 '#default_value' => variable_get($element, $options['default']), 145 '#description' => _gallery_block_admin_description($block), 146 ); 147 // Form element type specific properties 148 switch ($options['type']) { 149 case 'boolean': 150 $form[$element]['#type'] = 'checkbox'; 151 break; 152 case 'text': 153 $form[$element]['#type'] = 'textfield'; 154 $form[$element]['#size'] = max(10, min(80, strlen($options['default']))); 155 $form[$element]['#maxlength'] = 255; 156 break; 157 case 'choice': 158 $form[$element]['#type'] = 'select'; 159 $form[$element]['#options'] = $options['choices']; 160 break; 161 default: 162 } 163 } 164 return $form; 165 } 166 167 return FALSE; 168 } 169 170 /** 171 * Function _gallery_block_admin_imageblock(). 172 */ 173 function _gallery_block_admin_imageblock($element, $title = 'Gallery Image/Grid Block', $hide_options = NULL) { 174 $plugin_status = gallery_plugin_status(array('imageblock', 'imageframe')); 175 $form['#description'] = t('The @title requires the Gallery2 Image Block plugin (!imageblock_status) and optionally 176 the Gallery2 Image Frame plugin (!imageframe_status).', array( 177 '@title' => $title, 178 '!imageblock_status' => theme('gallery_plugin_status_message', $plugin_status['imageblock']), 179 '!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe'])) 180 ); 181 182 if ($plugin_status['imageblock'] != GALLERY_PLUGIN_ENABLED) { 183 $form['#description'] .= t(' However the Image Block plugin is unavailable.'); 184 return $form; 185 } 186 187 $form['imageblock'] = array('#tree' => TRUE); 188 $form['imageblock']['element'] = array('#type' => 'value', '#value' => $element); 189 190 $num_cols = variable_get($element .'_num_cols', 2); 191 $num_rows = variable_get($element .'_num_rows', 2); 192 $numimages = $num_cols * $num_rows; 193 194 $form['imageblock'][$element .'_num_cols'] = array( 195 '#type' => 'select', 196 '#title' => t('Number of columns'), 197 '#default_value' => variable_get($element .'_num_cols', 2), 198 '#options' => _gallery_range_array(1, 10), 199 '#description' => t('Select the number of columns in the grid.'), 200 ); 201 202 $form['imageblock'][$element .'_num_rows'] = array( 203 '#type' => 'select', 204 '#title' => t('Number of rows'), 205 '#default_value' => variable_get($element .'_num_rows', 2), 206 '#options' => _gallery_range_array(1, 10), 207 '#description' => t('Select the number of rows in the grid.'), 208 ); 209 210 _gallery_block_options($type_map, $param_map); 211 $form['imageblock'][$element .'_block_block'] = array( 212 '#type' => 'fieldset', 213 '#title' => t('Image types'), 214 '#collapsible' => TRUE, 215 '#collapsed' => FALSE, 216 '#tree' => TRUE, 217 '#description' => t('Pick the type of images you would like to see. You can select the same type more than once.'), 218 ); 219 $gallery_block_block = variable_get($element .'_block_block', array('randomImage')); 220 for ($i=0; $i<$numimages; $i++) { 221 $form['imageblock'][$element .'_block_block'][$i] = array( 222 '#type' => 'select', 223 '#title' => '', 224 '#default_value' => isset($gallery_block_block[$i]) ? $gallery_block_block[$i] : NULL, 225 '#options' => array_merge(array(NULL => t('None')), $type_map), 226 ); 227 } 228 229 $form['imageblock'][$element .'_item_id'] = array( 230 '#type' => 'textfield', 231 '#title' => t('Album or Item ID'), 232 '#default_value' => variable_get($element .'_item_id', ''), 233 '#size' => 20, 234 '#maxlength' => 20, 235 '#description' => t('Enter the Gallery image or album ID (or blank). If an album or item ID is specified, random 236 images will only be selected from that album and its sub-albums. If \'user\' (or \'user:123\') 237 is entered, items will be taken from the current (or specified) user\'s useralbum.') 238 ); 239 240 $form['imageblock'][$element .'_block_show'] = array( 241 '#type' => 'checkboxes', 242 '#title' => t('Image data'), 243 '#default_value' => variable_get($element .'_block_show', array('title', 'heading')), 244 '#options' => $param_map, 245 '#description' => t('Choose the item metadata you would like to display.'), 246 ); 247 248 $form['imageblock'][$element .'_size_method'] = array( 249 '#type' => 'select', 250 '#title' => t('Image size method'), 251 '#default_value' => variable_get($element .'_size_method', GALLERY_IMAGEBLOCK_SIZE_METHOD_DEFAULT), 252 '#options' => array( 253 'maxsize' => t('Max Size'), 254 'exactsize' => t('Exact Size'), 255 ), 256 '#description' => t('\'Max Size\' gives faster image downloading, but the image size 257 may be smaller than the size defined below. <br />\'Exact Size\' may be slower 258 (as a larger image is downloaded and then scaled by the browser) but the image 259 will be guaranteed to be the size defined below.'), 260 ); 261 262 $form['imageblock'][$element .'_size'] = array( 263 '#type' => 'textfield', 264 '#title' => t('Image size'), 265 '#default_value' => variable_get($element .'_size', GALLERY_IMAGEBLOCK_SIZE_DEFAULT), 266 '#size' => 10, 267 '#maxlength' => 10, 268 '#description' => t('Sets the size (in pixels) of the longest side of the image according to the method defined above.'), 269 ); 270 271 $imageframe_desc = ($plugin_status['imageframe'] != GALLERY_PLUGIN_ENABLED) ? 272 t('Requires the Gallery2 Image Frame plugin (!imageframe_status).', 273 array('!imageframe_status' => theme('gallery_plugin_status_message', $plugin_status['imageframe']))) : ''; 274 275 $image_frames = gallery_list_image_frames(); 276 277 $form['imageblock'][$element .'_album_frame'] = array( 278 '#type' => 'select', 279 '#title' => t('Album frame'), 280 '#default_value' => variable_get($element .'_album_frame', 'none'), 281 '#options' => $image_frames, 282 '#description' => $imageframe_desc, 283 ); 284 285 $form['imageblock'][$element .'_item_frame'] = array( 286 '#type' => 'select', 287 '#title' => t('Item frame'), 288 '#default_value' => variable_get($element .'_item_frame', 'none'), 289 '#options' => $image_frames, 290 '#description' => $imageframe_desc, 291 ); 292 293 $form['imageblock'][$element .'_link_target'] = array( 294 '#type' => 'textfield', 295 '#title' => t('Link target'), 296 '#default_value' => variable_get($element .'_link_target', ''), 297 '#size' => 20, 298 '#maxlength' => 20, 299 '#description' => t('Enter a link target (e.g. \'_blank\' to open in a new window).'), 300 ); 301 302 $form['imageblock'][$element .'_link'] = array( 303 '#type' => 'textfield', 304 '#title' => t('Image Link'), 305 '#default_value' => variable_get($element .'_link', ''), 306 '#size' => 60, 307 '#maxlength' => 255, 308 '#description' => t('By default the image has a link to the item in the Gallery. This 309 can be overridden here (or leave empty for the default). Use \'none\' for no link, or a URL 310 to link somewhere else instead.'), 311 ); 312 313 // Remove form elements that should not be available 314 if (isset($hide_options) && is_array($hide_options)) { 315 foreach ($hide_options as $option) { 316 unset($form['imageblock'][$element .'_'. $option]); 317 } 318 } 319 320 return $form; 321 } 322 323 /** 324 * Function _gallery_block_admin_imageblock_submit(). 325 */ 326 function _gallery_block_admin_imageblock_submit($form, &$form_state) { 327 _gallery_block_admin_save($form_state['values']); 328 } 329 330 /** 331 * Function _gallery_block_admin_imageblock_save(). 332 */ 333 function _gallery_block_admin_imageblock_save(&$values) { 334 $element = isset($values['element']) ? $values['element'] : FALSE; 335 if ($element) { 336 unset($values['element']); 337 // Validate _size variable 338 if (isset($values[$element .'_imageblock_size'])) { 339 if (!is_numeric($values[$element .'_imageblock_size']) || $values[$element .'_imageblock_size'] < 10) { 340 $values[$element .'_imageblock_size'] = 10; 341 drupal_set_message(t('Image size must be a number greater than ten pixels. 342 (The value has been updated to \'10\' for your convenience.)'), 'error'); 343 } 344 } 345 } 346 // Save imageblock variables 347 foreach ($values['imageblock'] as $key => $value) { 348 if (is_array($value)) { 349 $value = array_values(array_filter($value)); 350 } 351 variable_set($key, $value); 352 } 353 unset($values['imageblock']); 354 } 355 356 /** 357 * Function _gallery_block_admin_update(). 358 */ 359 function _gallery_block_admin_update($form, &$form_state) { 360 _gallery_block_admin_save($form_state['values']); 361 db_query("UPDATE {blocks} SET title = '%s' WHERE module = '%s' AND delta = '%s'", $form_state['values']['title'], $form_state['values']['module'], $form_state['values']['delta']); 362 } 363 364 /** 365 * Function _gallery_block_admin_save(). 366 */ 367 function _gallery_block_admin_save(&$values) { 368 $element = isset($values['element']) ? $values['element'] : FALSE; 369 // Save imageblock values (if present) 370 if (isset($values['imageblock'])) { 371 _gallery_block_admin_imageblock_save($values); 372 } 373 // Save variables 374 if ($element) { 375 unset($values['element']); 376 foreach ($values as $key => $value) { 377 $pos = strpos($key, $element); 378 if ($pos !== FALSE && $pos == 0) { 379 if (is_array($value)) { 380 $value = array_values(array_filter($value)); 381 } 382 variable_set($key, $value); 383 } 384 } 385 } 386 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |