| Drupal | PHP Cross Reference | Content Management Systems |
1 <?php 2 3 /** 4 * @file 5 * Administration pages for image settings. 6 */ 7 8 /** 9 * Menu callback; Listing of all current image styles. 10 */ 11 function image_style_list() { 12 $page = array(); 13 14 $styles = image_styles(); 15 $page['image_style_list'] = array( 16 '#markup' => theme('image_style_list', array('styles' => $styles)), 17 '#attached' => array( 18 'css' => array(drupal_get_path('module', 'image') . '/image.admin.css' => array()), 19 ), 20 ); 21 22 return $page; 23 24 } 25 26 /** 27 * Form builder; Edit an image style name and effects order. 28 * 29 * @param $form_state 30 * An associative array containing the current state of the form. 31 * @param $style 32 * An image style array. 33 * @ingroup forms 34 * @see image_style_form_submit() 35 * @see image_style_name_validate() 36 */ 37 function image_style_form($form, &$form_state, $style) { 38 $title = t('Edit %name style', array('%name' => $style['name'])); 39 drupal_set_title($title, PASS_THROUGH); 40 41 // Adjust this form for styles that must be overridden to edit. 42 $editable = (bool) ($style['storage'] & IMAGE_STORAGE_EDITABLE); 43 44 if (!$editable && empty($form_state['input'])) { 45 drupal_set_message(t('This image style is currently being provided by a module. Click the "Override defaults" button to change its settings.'), 'warning'); 46 } 47 48 $form_state['image_style'] = $style; 49 $form['#tree'] = TRUE; 50 $form['#attached']['css'][drupal_get_path('module', 'image') . '/image.admin.css'] = array(); 51 52 // Show the thumbnail preview. 53 $form['preview'] = array( 54 '#type' => 'item', 55 '#title' => t('Preview'), 56 '#markup' => theme('image_style_preview', array('style' => $style)), 57 ); 58 59 // Allow the name of the style to be changed, unless this style is 60 // provided by a module's hook_default_image_styles(). 61 if ($style['storage'] & IMAGE_STORAGE_MODULE) { 62 $form['name'] = array( 63 '#type' => 'item', 64 '#title' => t('Image style name'), 65 '#markup' => $style['name'], 66 '#description' => t('This image style is being provided by %module module and may not be renamed.', array('%module' => $style['module'])), 67 ); 68 } 69 else { 70 $form['name'] = array( 71 '#type' => 'textfield', 72 '#size' => '64', 73 '#title' => t('Image style name'), 74 '#default_value' => $style['name'], 75 '#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'), 76 '#element_validate' => array('image_style_name_validate'), 77 '#required' => TRUE, 78 ); 79 } 80 81 // Build the list of existing image effects for this image style. 82 $form['effects'] = array( 83 '#theme' => 'image_style_effects', 84 ); 85 foreach ($style['effects'] as $key => $effect) { 86 $form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL; 87 $form['effects'][$key]['label'] = array( 88 '#markup' => $effect['label'], 89 ); 90 $form['effects'][$key]['summary'] = array( 91 '#markup' => isset($effect['summary theme']) ? theme($effect['summary theme'], array('data' => $effect['data'])) : '', 92 ); 93 $form['effects'][$key]['weight'] = array( 94 '#type' => 'weight', 95 '#title' => t('Weight for @title', array('@title' => $effect['label'])), 96 '#title_display' => 'invisible', 97 '#default_value' => $effect['weight'], 98 '#access' => $editable, 99 ); 100 101 // Only attempt to display these fields for editable styles as the 'ieid' 102 // key is not set for styles defined in code. 103 if ($editable) { 104 $form['effects'][$key]['configure'] = array( 105 '#type' => 'link', 106 '#title' => t('edit'), 107 '#href' => 'admin/config/media/image-styles/edit/' . $style['name'] . '/effects/' . $effect['ieid'], 108 '#access' => $editable && isset($effect['form callback']), 109 ); 110 $form['effects'][$key]['remove'] = array( 111 '#type' => 'link', 112 '#title' => t('delete'), 113 '#href' => 'admin/config/media/image-styles/edit/' . $style['name'] . '/effects/' . $effect['ieid'] . '/delete', 114 '#access' => $editable, 115 ); 116 } 117 } 118 119 // Build the new image effect addition form and add it to the effect list. 120 $new_effect_options = array(); 121 foreach (image_effect_definitions() as $effect => $definition) { 122 $new_effect_options[$effect] = check_plain($definition['label']); 123 } 124 $form['effects']['new'] = array( 125 '#tree' => FALSE, 126 '#weight' => isset($form_state['input']['weight']) ? $form_state['input']['weight'] : NULL, 127 '#access' => $editable, 128 ); 129 $form['effects']['new']['new'] = array( 130 '#type' => 'select', 131 '#title' => t('Effect'), 132 '#title_display' => 'invisible', 133 '#options' => $new_effect_options, 134 '#empty_option' => t('Select a new effect'), 135 ); 136 $form['effects']['new']['weight'] = array( 137 '#type' => 'weight', 138 '#title' => t('Weight for new effect'), 139 '#title_display' => 'invisible', 140 '#default_value' => count($form['effects']) - 1, 141 ); 142 $form['effects']['new']['add'] = array( 143 '#type' => 'submit', 144 '#value' => t('Add'), 145 '#validate' => array('image_style_form_add_validate'), 146 '#submit' => array('image_style_form_submit', 'image_style_form_add_submit'), 147 ); 148 149 // Show the Override or Submit button for this style. 150 $form['actions'] = array('#type' => 'actions'); 151 $form['actions']['override'] = array( 152 '#type' => 'submit', 153 '#value' => t('Override defaults'), 154 '#validate' => array(), 155 '#submit' => array('image_style_form_override_submit'), 156 '#access' => !$editable, 157 ); 158 $form['actions']['submit'] = array( 159 '#type' => 'submit', 160 '#value' => t('Update style'), 161 '#access' => $editable, 162 ); 163 164 return $form; 165 } 166 167 /** 168 * Validate handler for adding a new image effect to an image style. 169 */ 170 function image_style_form_add_validate($form, &$form_state) { 171 if (!$form_state['values']['new']) { 172 form_error($form['effects']['new']['new'], t('Select an effect to add.')); 173 } 174 } 175 176 /** 177 * Submit handler for adding a new image effect to an image style. 178 */ 179 function image_style_form_add_submit($form, &$form_state) { 180 $style = $form_state['image_style']; 181 // Check if this field has any configuration options. 182 $effect = image_effect_definition_load($form_state['values']['new']); 183 184 // Load the configuration form for this option. 185 if (isset($effect['form callback'])) { 186 $path = 'admin/config/media/image-styles/edit/' . $form_state['image_style']['name'] . '/add/' . $form_state['values']['new']; 187 $form_state['redirect'] = array($path, array('query' => array('weight' => $form_state['values']['weight']))); 188 } 189 // If there's no form, immediately add the image effect. 190 else { 191 $effect['isid'] = $style['isid']; 192 $effect['weight'] = $form_state['values']['weight']; 193 image_effect_save($effect); 194 drupal_set_message(t('The image effect was successfully applied.')); 195 } 196 } 197 198 /** 199 * Submit handler for overriding a module-defined style. 200 */ 201 function image_style_form_override_submit($form, &$form_state) { 202 drupal_set_message(t('The %style style has been overridden, allowing you to change its settings.', array('%style' => $form_state['image_style']['name']))); 203 image_default_style_save($form_state['image_style']); 204 } 205 206 /** 207 * Submit handler for saving an image style. 208 */ 209 function image_style_form_submit($form, &$form_state) { 210 // Update the image style name if it has changed. 211 $style = $form_state['image_style']; 212 if (isset($form_state['values']['name']) && $style['name'] != $form_state['values']['name']) { 213 $style['name'] = $form_state['values']['name']; 214 } 215 216 // Update image effect weights. 217 if (!empty($form_state['values']['effects'])) { 218 foreach ($form_state['values']['effects'] as $ieid => $effect_data) { 219 if (isset($style['effects'][$ieid])) { 220 $effect = $style['effects'][$ieid]; 221 $effect['weight'] = $effect_data['weight']; 222 image_effect_save($effect); 223 } 224 } 225 } 226 227 image_style_save($style); 228 if ($form_state['values']['op'] == t('Update style')) { 229 drupal_set_message(t('Changes to the style have been saved.')); 230 } 231 $form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name']; 232 } 233 234 /** 235 * Form builder; Form for adding a new image style. 236 * 237 * @ingroup forms 238 * @see image_style_add_form_submit() 239 * @see image_style_name_validate() 240 */ 241 function image_style_add_form($form, &$form_state) { 242 $form['name'] = array( 243 '#type' => 'textfield', 244 '#size' => '64', 245 '#title' => t('Style name'), 246 '#default_value' => '', 247 '#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'), 248 '#element_validate' => array('image_style_name_validate'), 249 '#required' => TRUE, 250 ); 251 252 $form['submit'] = array( 253 '#type' => 'submit', 254 '#value' => t('Create new style'), 255 ); 256 257 return $form; 258 } 259 260 /** 261 * Submit handler for adding a new image style. 262 */ 263 function image_style_add_form_submit($form, &$form_state) { 264 $style = array('name' => $form_state['values']['name']); 265 $style = image_style_save($style); 266 drupal_set_message(t('Style %name was created.', array('%name' => $style['name']))); 267 $form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name']; 268 } 269 270 /** 271 * Element validate function to ensure unique, URL safe style names. 272 */ 273 function image_style_name_validate($element, $form_state) { 274 // Check for duplicates. 275 $styles = image_styles(); 276 if (isset($styles[$element['#value']]) && (!isset($form_state['image_style']['isid']) || $styles[$element['#value']]['isid'] != $form_state['image_style']['isid'])) { 277 form_set_error($element['#name'], t('The image style name %name is already in use.', array('%name' => $element['#value']))); 278 } 279 280 // Check for illegal characters in image style names. 281 if (preg_match('/[^0-9a-z_\-]/', $element['#value'])) { 282 form_set_error($element['#name'], t('Please only use lowercase alphanumeric characters, underscores (_), and hyphens (-) for style names.')); 283 } 284 } 285 286 /** 287 * Form builder; Form for deleting an image style. 288 * 289 * @param $style 290 * An image style array. 291 * 292 * @ingroup forms 293 * @see image_style_delete_form_submit() 294 */ 295 function image_style_delete_form($form, &$form_state, $style) { 296 $form_state['image_style'] = $style; 297 298 $replacement_styles = array_diff_key(image_style_options(), array($style['name'] => '')); 299 $form['replacement'] = array( 300 '#title' => t('Replacement style'), 301 '#type' => 'select', 302 '#options' => $replacement_styles, 303 '#empty_option' => t('No replacement, just delete'), 304 ); 305 306 return confirm_form( 307 $form, 308 t('Optionally select a style before deleting %style', array('%style' => $style['name'])), 309 'admin/config/media/image-styles', 310 t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted.'), 311 t('Delete'), t('Cancel') 312 ); 313 } 314 315 /** 316 * Submit handler to delete an image style. 317 */ 318 function image_style_delete_form_submit($form, &$form_state) { 319 $style = $form_state['image_style']; 320 321 image_style_delete($style, $form_state['values']['replacement']); 322 drupal_set_message(t('Style %name was deleted.', array('%name' => $style['name']))); 323 $form_state['redirect'] = 'admin/config/media/image-styles'; 324 } 325 326 /** 327 * Confirmation form to revert a database style to its default. 328 */ 329 function image_style_revert_form($form, $form_state, $style) { 330 $form_state['image_style'] = $style; 331 332 return confirm_form( 333 $form, 334 t('Revert the %style style?', array('%style' => $style['name'])), 335 'admin/config/media/image-styles', 336 t('Reverting this style will delete the customized settings and restore the defaults provided by the @module module.', array('@module' => $style['module'])), 337 t('Revert'), t('Cancel') 338 ); 339 } 340 341 /** 342 * Submit handler to convert an overridden style to its default. 343 */ 344 function image_style_revert_form_submit($form, &$form_state) { 345 drupal_set_message(t('The %style style has been reverted to its defaults.', array('%style' => $form_state['image_style']['name']))); 346 image_default_style_revert($form_state['image_style']); 347 $form_state['redirect'] = 'admin/config/media/image-styles'; 348 } 349 350 /** 351 * Form builder; Form for adding and editing image effects. 352 * 353 * This form is used universally for editing all image effects. Each effect adds 354 * its own custom section to the form by calling the form function specified in 355 * hook_image_effects(). 356 * 357 * @param $form_state 358 * An associative array containing the current state of the form. 359 * @param $style 360 * An image style array. 361 * @param $effect 362 * An image effect array. 363 * 364 * @ingroup forms 365 * @see hook_image_effects() 366 * @see image_effects() 367 * @see image_resize_form() 368 * @see image_scale_form() 369 * @see image_rotate_form() 370 * @see image_crop_form() 371 * @see image_effect_form_submit() 372 */ 373 function image_effect_form($form, &$form_state, $style, $effect) { 374 if (!empty($effect['data'])) { 375 $title = t('Edit %label effect', array('%label' => $effect['label'])); 376 } 377 else{ 378 $title = t('Add %label effect', array('%label' => $effect['label'])); 379 } 380 drupal_set_title($title, PASS_THROUGH); 381 382 $form_state['image_style'] = $style; 383 $form_state['image_effect'] = $effect; 384 385 // If no configuration for this image effect, return to the image style page. 386 if (!isset($effect['form callback'])) { 387 drupal_goto('admin/config/media/image-styles/edit/' . $style['name']); 388 } 389 390 $form['#tree'] = TRUE; 391 $form['#attached']['css'][drupal_get_path('module', 'image') . '/image.admin.css'] = array(); 392 if (function_exists($effect['form callback'])) { 393 $form['data'] = call_user_func($effect['form callback'], $effect['data']); 394 } 395 396 // Check the URL for a weight, then the image effect, otherwise use default. 397 $form['weight'] = array( 398 '#type' => 'hidden', 399 '#value' => isset($_GET['weight']) ? intval($_GET['weight']) : (isset($effect['weight']) ? $effect['weight'] : count($style['effects'])), 400 ); 401 402 $form['actions'] = array('#tree' => FALSE, '#type' => 'actions'); 403 $form['actions']['submit'] = array( 404 '#type' => 'submit', 405 '#value' => isset($effect['ieid']) ? t('Update effect') : t('Add effect'), 406 ); 407 $form['actions']['cancel'] = array( 408 '#type' => 'link', 409 '#title' => t('Cancel'), 410 '#href' => 'admin/config/media/image-styles/edit/' . $style['name'], 411 ); 412 413 return $form; 414 } 415 416 /** 417 * Submit handler for updating an image effect. 418 */ 419 function image_effect_form_submit($form, &$form_state) { 420 $style = $form_state['image_style']; 421 $effect = array_merge($form_state['image_effect'], $form_state['values']); 422 $effect['isid'] = $style['isid']; 423 image_effect_save($effect); 424 drupal_set_message(t('The image effect was successfully applied.')); 425 $form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name']; 426 } 427 428 /** 429 * Form builder; Form for deleting an image effect. 430 * 431 * @param $style 432 * Name of the image style from which the image effect will be removed. 433 * @param $effect 434 * Name of the image effect to remove. 435 * @ingroup forms 436 * @see image_effect_delete_form_submit() 437 */ 438 function image_effect_delete_form($form, &$form_state, $style, $effect) { 439 $form_state['image_style'] = $style; 440 $form_state['image_effect'] = $effect; 441 442 $question = t('Are you sure you want to delete the @effect effect from the %style style?', array('%style' => $style['name'], '@effect' => $effect['label'])); 443 return confirm_form($form, $question, 'admin/config/media/image-styles/edit/' . $style['name'], '', t('Delete')); 444 } 445 446 /** 447 * Submit handler to delete an image effect. 448 */ 449 function image_effect_delete_form_submit($form, &$form_state) { 450 $style = $form_state['image_style']; 451 $effect = $form_state['image_effect']; 452 453 image_effect_delete($effect); 454 drupal_set_message(t('The image effect %name has been deleted.', array('%name' => $effect['label']))); 455 $form_state['redirect'] = 'admin/config/media/image-styles/edit/' . $style['name']; 456 } 457 458 /** 459 * Element validate handler to ensure an integer pixel value. 460 * 461 * The property #allow_negative = TRUE may be set to allow negative integers. 462 */ 463 function image_effect_integer_validate($element, &$form_state) { 464 $value = empty($element['#allow_negative']) ? $element['#value'] : preg_replace('/^-/', '', $element['#value']); 465 if ($element['#value'] != '' && (!is_numeric($value) || intval($value) <= 0)) { 466 if (empty($element['#allow_negative'])) { 467 form_error($element, t('!name must be an integer.', array('!name' => $element['#title']))); 468 } 469 else { 470 form_error($element, t('!name must be a positive integer.', array('!name' => $element['#title']))); 471 } 472 } 473 } 474 475 /** 476 * Element validate handler to ensure a hexadecimal color value. 477 */ 478 function image_effect_color_validate($element, &$form_state) { 479 if ($element['#value'] != '') { 480 $hex_value = preg_replace('/^#/', '', $element['#value']); 481 if (!preg_match('/^#[0-9A-F]{3}([0-9A-F]{3})?$/', $element['#value'])) { 482 form_error($element, t('!name must be a hexadecimal color value.', array('!name' => $element['#title']))); 483 } 484 } 485 } 486 487 /** 488 * Element validate handler to ensure that either a height or a width is 489 * specified. 490 */ 491 function image_effect_scale_validate($element, &$form_state) { 492 if (empty($element['width']['#value']) && empty($element['height']['#value'])) { 493 form_error($element, t('Width and height can not both be blank.')); 494 } 495 } 496 497 /** 498 * Form structure for the image resize form. 499 * 500 * Note that this is not a complete form, it only contains the portion of the 501 * form for configuring the resize options. Therefore it does not not need to 502 * include metadata about the effect, nor a submit button. 503 * 504 * @param $data 505 * The current configuration for this resize effect. 506 */ 507 function image_resize_form($data) { 508 $form['width'] = array( 509 '#type' => 'textfield', 510 '#title' => t('Width'), 511 '#default_value' => isset($data['width']) ? $data['width'] : '', 512 '#field_suffix' => ' ' . t('pixels'), 513 '#required' => TRUE, 514 '#size' => 10, 515 '#element_validate' => array('image_effect_integer_validate'), 516 '#allow_negative' => FALSE, 517 ); 518 $form['height'] = array( 519 '#type' => 'textfield', 520 '#title' => t('Height'), 521 '#default_value' => isset($data['height']) ? $data['height'] : '', 522 '#field_suffix' => ' ' . t('pixels'), 523 '#required' => TRUE, 524 '#size' => 10, 525 '#element_validate' => array('image_effect_integer_validate'), 526 '#allow_negative' => FALSE, 527 ); 528 return $form; 529 } 530 531 /** 532 * Form structure for the image scale form. 533 * 534 * Note that this is not a complete form, it only contains the portion of the 535 * form for configuring the scale options. Therefore it does not not need to 536 * include metadata about the effect, nor a submit button. 537 * 538 * @param $data 539 * The current configuration for this scale effect. 540 */ 541 function image_scale_form($data) { 542 $form = image_resize_form($data); 543 $form['#element_validate'] = array('image_effect_scale_validate'); 544 $form['width']['#required'] = FALSE; 545 $form['height']['#required'] = FALSE; 546 $form['upscale'] = array( 547 '#type' => 'checkbox', 548 '#default_value' => (isset($data['upscale'])) ? $data['upscale'] : 0, 549 '#title' => t('Allow Upscaling'), 550 '#description' => t('Let scale make images larger than their original size'), 551 ); 552 return $form; 553 } 554 555 /** 556 * Form structure for the image crop form. 557 * 558 * Note that this is not a complete form, it only contains the portion of the 559 * form for configuring the crop options. Therefore it does not not need to 560 * include metadata about the effect, nor a submit button. 561 * 562 * @param $data 563 * The current configuration for this crop effect. 564 */ 565 function image_crop_form($data) { 566 $data += array( 567 'width' => '', 568 'height' => '', 569 'anchor' => 'center-center', 570 ); 571 572 $form = image_resize_form($data); 573 $form['anchor'] = array( 574 '#type' => 'radios', 575 '#title' => t('Anchor'), 576 '#options' => array( 577 'left-top' => t('Top') . ' ' . t('Left'), 578 'center-top' => t('Top') . ' ' . t('Center'), 579 'right-top' => t('Top') . ' ' . t('Right'), 580 'left-center' => t('Center') . ' ' . t('Left'), 581 'center-center' => t('Center'), 582 'right-center' => t('Center') . ' ' . t('Right'), 583 'left-bottom' => t('Bottom') . ' ' . t('Left'), 584 'center-bottom' => t('Bottom') . ' ' . t('Center'), 585 'right-bottom' => t('Bottom') . ' ' . t('Right'), 586 ), 587 '#theme' => 'image_anchor', 588 '#default_value' => $data['anchor'], 589 '#description' => t('The part of the image that will be retained during the crop.'), 590 ); 591 592 return $form; 593 } 594 595 /** 596 * Form structure for the image rotate form. 597 * 598 * Note that this is not a complete form, it only contains the portion of the 599 * form for configuring the rotate options. Therefore it does not not need to 600 * include metadata about the effect, nor a submit button. 601 * 602 * @param $data 603 * The current configuration for this rotate effect. 604 */ 605 function image_rotate_form($data) { 606 $form['degrees'] = array( 607 '#type' => 'textfield', 608 '#default_value' => (isset($data['degrees'])) ? $data['degrees'] : 0, 609 '#title' => t('Rotation angle'), 610 '#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'), 611 '#field_suffix' => '°', 612 '#required' => TRUE, 613 '#size' => 6, 614 '#maxlength' => 4, 615 '#element_validate' => array('image_effect_integer_validate'), 616 '#allow_negative' => TRUE, 617 ); 618 $form['bgcolor'] = array( 619 '#type' => 'textfield', 620 '#default_value' => (isset($data['bgcolor'])) ? $data['bgcolor'] : '#FFFFFF', 621 '#title' => t('Background color'), 622 '#description' => t('The background color to use for exposed areas of the image. Use web-style hex colors (#FFFFFF for white, #000000 for black). Leave blank for transparency on image types that support it.'), 623 '#size' => 7, 624 '#maxlength' => 7, 625 '#element_validate' => array('image_effect_color_validate'), 626 ); 627 $form['random'] = array( 628 '#type' => 'checkbox', 629 '#default_value' => (isset($data['random'])) ? $data['random'] : 0, 630 '#title' => t('Randomize'), 631 '#description' => t('Randomize the rotation angle for each image. The angle specified above is used as a maximum.'), 632 ); 633 return $form; 634 } 635 636 /** 637 * Returns HTML for the page containing the list of image styles. 638 * 639 * @param $variables 640 * An associative array containing: 641 * - styles: An array of all the image styles returned by image_get_styles(). 642 * 643 * @see image_get_styles() 644 * @ingroup themeable 645 */ 646 function theme_image_style_list($variables) { 647 $styles = $variables['styles']; 648 649 $header = array(t('Style name'), t('Settings'), array('data' => t('Operations'), 'colspan' => 3)); 650 $rows = array(); 651 foreach ($styles as $style) { 652 $row = array(); 653 $row[] = l($style['name'], 'admin/config/media/image-styles/edit/' . $style['name']); 654 $link_attributes = array( 655 'attributes' => array( 656 'class' => array('image-style-link'), 657 ), 658 ); 659 if ($style['storage'] == IMAGE_STORAGE_NORMAL) { 660 $row[] = t('Custom'); 661 $row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes); 662 $row[] = l(t('delete'), 'admin/config/media/image-styles/delete/' . $style['name'], $link_attributes); 663 } 664 elseif ($style['storage'] == IMAGE_STORAGE_OVERRIDE) { 665 $row[] = t('Overridden'); 666 $row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes); 667 $row[] = l(t('revert'), 'admin/config/media/image-styles/revert/' . $style['name'], $link_attributes); 668 } 669 else { 670 $row[] = t('Default'); 671 $row[] = l(t('edit'), 'admin/config/media/image-styles/edit/' . $style['name'], $link_attributes); 672 $row[] = ''; 673 } 674 $rows[] = $row; 675 } 676 677 if (empty($rows)) { 678 $rows[] = array(array( 679 'colspan' => 4, 680 'data' => t('There are currently no styles. <a href="!url">Add a new one</a>.', array('!url' => url('admin/config/media/image-styles/add'))), 681 )); 682 } 683 684 return theme('table', array('header' => $header, 'rows' => $rows)); 685 } 686 687 /** 688 * Returns HTML for a listing of the effects within a specific image style. 689 * 690 * @param $variables 691 * An associative array containing: 692 * - form: A render element representing the form. 693 * 694 * @ingroup themeable 695 */ 696 function theme_image_style_effects($variables) { 697 $form = $variables['form']; 698 699 $rows = array(); 700 701 foreach (element_children($form) as $key) { 702 $row = array(); 703 $form[$key]['weight']['#attributes']['class'] = array('image-effect-order-weight'); 704 if (is_numeric($key)) { 705 $summary = drupal_render($form[$key]['summary']); 706 $row[] = drupal_render($form[$key]['label']) . (empty($summary) ? '' : ' ' . $summary); 707 $row[] = drupal_render($form[$key]['weight']); 708 $row[] = drupal_render($form[$key]['configure']); 709 $row[] = drupal_render($form[$key]['remove']); 710 } 711 else { 712 // Add the row for adding a new image effect. 713 $row[] = '<div class="image-style-new">' . drupal_render($form['new']['new']) . drupal_render($form['new']['add']) . '</div>'; 714 $row[] = drupal_render($form['new']['weight']); 715 $row[] = array('data' => '', 'colspan' => 2); 716 } 717 718 if (!isset($form[$key]['#access']) || $form[$key]['#access']) { 719 $rows[] = array( 720 'data' => $row, 721 'class' => !empty($form[$key]['weight']['#access']) || $key == 'new' ? array('draggable') : array(), 722 ); 723 } 724 } 725 726 $header = array( 727 t('Effect'), 728 t('Weight'), 729 array('data' => t('Operations'), 'colspan' => 2), 730 ); 731 732 if (count($rows) == 1 && $form['new']['#access']) { 733 array_unshift($rows, array(array( 734 'data' => t('There are currently no effects in this style. Add one by selecting an option below.'), 735 'colspan' => 4, 736 ))); 737 } 738 739 $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'image-style-effects'))); 740 drupal_add_tabledrag('image-style-effects', 'order', 'sibling', 'image-effect-order-weight'); 741 return $output; 742 } 743 744 /** 745 * Returns HTML for a preview of an image style. 746 * 747 * @param $variables 748 * An associative array containing: 749 * - style: The image style array being previewed. 750 * 751 * @ingroup themeable 752 */ 753 function theme_image_style_preview($variables) { 754 $style = $variables['style']; 755 756 $sample_image = variable_get('image_style_preview_image', drupal_get_path('module', 'image') . '/sample.png'); 757 $sample_width = 160; 758 $sample_height = 160; 759 760 // Set up original file information. 761 $original_path = $sample_image; 762 $original_image = image_get_info($original_path); 763 if ($original_image['width'] > $original_image['height']) { 764 $original_width = min($original_image['width'], $sample_width); 765 $original_height = round($original_width / $original_image['width'] * $original_image['height']); 766 } 767 else { 768 $original_height = min($original_image['height'], $sample_height); 769 $original_width = round($original_height / $original_image['height'] * $original_image['width']); 770 } 771 $original_attributes = array_intersect_key($original_image, array('width' => '', 'height' => '')); 772 $original_attributes['style'] = 'width: ' . $original_width . 'px; height: ' . $original_height . 'px;'; 773 774 // Set up preview file information. 775 $preview_file = image_style_path($style['name'], $original_path); 776 if (!file_exists($preview_file)) { 777 image_style_create_derivative($style, $original_path, $preview_file); 778 } 779 $preview_image = image_get_info($preview_file); 780 if ($preview_image['width'] > $preview_image['height']) { 781 $preview_width = min($preview_image['width'], $sample_width); 782 $preview_height = round($preview_width / $preview_image['width'] * $preview_image['height']); 783 } 784 else { 785 $preview_height = min($preview_image['height'], $sample_height); 786 $preview_width = round($preview_height / $preview_image['height'] * $preview_image['width']); 787 } 788 $preview_attributes = array_intersect_key($preview_image, array('width' => '', 'height' => '')); 789 $preview_attributes['style'] = 'width: ' . $preview_width . 'px; height: ' . $preview_height . 'px;'; 790 791 // In the previews, timestamps are added to prevent caching of images. 792 $output = '<div class="image-style-preview preview clearfix">'; 793 794 // Build the preview of the original image. 795 $original_url = file_create_url($original_path); 796 $output .= '<div class="preview-image-wrapper">'; 797 $output .= t('original') . ' (' . l(t('view actual size'), $original_url) . ')'; 798 $output .= '<div class="preview-image original-image" style="' . $original_attributes['style'] . '">'; 799 $output .= '<a href="' . $original_url . '">' . theme('image', array('path' => $original_path, 'alt' => t('Sample original image'), 'title' => '', 'attributes' => $original_attributes)) . '</a>'; 800 $output .= '<div class="height" style="height: ' . $original_height . 'px"><span>' . $original_image['height'] . 'px</span></div>'; 801 $output .= '<div class="width" style="width: ' . $original_width . 'px"><span>' . $original_image['width'] . 'px</span></div>'; 802 $output .= '</div>'; // End preview-image. 803 $output .= '</div>'; // End preview-image-wrapper. 804 805 // Build the preview of the image style. 806 $preview_url = file_create_url($preview_file) . '?cache_bypass=' . REQUEST_TIME; 807 $output .= '<div class="preview-image-wrapper">'; 808 $output .= check_plain($style['name']) . ' (' . l(t('view actual size'), file_create_url($preview_file) . '?' . time()) . ')'; 809 $output .= '<div class="preview-image modified-image" style="' . $preview_attributes['style'] . '">'; 810 $output .= '<a href="' . file_create_url($preview_file) . '?' . time() . '">' . theme('image', array('path' => $preview_url, 'alt' => t('Sample modified image'), 'title' => '', 'attributes' => $preview_attributes)) . '</a>'; 811 $output .= '<div class="height" style="height: ' . $preview_height . 'px"><span>' . $preview_image['height'] . 'px</span></div>'; 812 $output .= '<div class="width" style="width: ' . $preview_width . 'px"><span>' . $preview_image['width'] . 'px</span></div>'; 813 $output .= '</div>'; // End preview-image. 814 $output .= '</div>'; // End preview-image-wrapper. 815 816 $output .= '</div>'; // End image-style-preview. 817 818 return $output; 819 } 820 821 /** 822 * Returns HTML for a 3x3 grid of checkboxes for image anchors. 823 * 824 * @param $variables 825 * An associative array containing: 826 * - element: A render element containing radio buttons. 827 * 828 * @ingroup themeable 829 */ 830 function theme_image_anchor($variables) { 831 $element = $variables['element']; 832 833 $rows = array(); 834 $row = array(); 835 foreach (element_children($element) as $n => $key) { 836 $element[$key]['#attributes']['title'] = $element[$key]['#title']; 837 unset($element[$key]['#title']); 838 $row[] = drupal_render($element[$key]); 839 if ($n % 3 == 3 - 1) { 840 $rows[] = $row; 841 $row = array(); 842 } 843 } 844 845 return theme('table', array('header' => array(), 'rows' => $rows, 'attributes' => array('class' => array('image-anchor')))); 846 } 847 848 /** 849 * Returns HTML for a summary of an image resize effect. 850 * 851 * @param $variables 852 * An associative array containing: 853 * - data: The current configuration for this resize effect. 854 * 855 * @ingroup themeable 856 */ 857 function theme_image_resize_summary($variables) { 858 $data = $variables['data']; 859 860 if ($data['width'] && $data['height']) { 861 return check_plain($data['width']) . 'x' . check_plain($data['height']); 862 } 863 else { 864 return ($data['width']) ? t('width @width', array('@width' => $data['width'])) : t('height @height', array('@height' => $data['height'])); 865 } 866 } 867 868 /** 869 * Returns HTML for a summary of an image scale effect. 870 * 871 * @param $variables 872 * An associative array containing: 873 * - data: The current configuration for this scale effect. 874 * 875 * @ingroup themeable 876 */ 877 function theme_image_scale_summary($variables) { 878 $data = $variables['data']; 879 return theme('image_resize_summary', array('data' => $data)) . ' ' . ($data['upscale'] ? '(' . t('upscaling allowed') . ')' : ''); 880 } 881 882 /** 883 * Returns HTML for a summary of an image crop effect. 884 * 885 * @param $variables 886 * An associative array containing: 887 * - data: The current configuration for this crop effect. 888 * 889 * @ingroup themeable 890 */ 891 function theme_image_crop_summary($variables) { 892 return theme('image_resize_summary', $variables); 893 } 894 895 /** 896 * Returns HTML for a summary of an image rotate effect. 897 * 898 * @param $variables 899 * An associative array containing: 900 * - data: The current configuration for this rotate effect. 901 * 902 * @ingroup themeable 903 */ 904 function theme_image_rotate_summary($variables) { 905 $data = $variables['data']; 906 return ($data['random']) ? t('random between -@degrees° and @degrees°', array('@degrees' => str_replace('-', '', $data['degrees']))) : t('@degrees°', array('@degrees' => $data['degrees'])); 907 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title