2009-07-21 07:09:47 +00:00
< ? php
/**
* @ file
* Administration pages for image settings .
*/
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for a listing of the effects within a specific image style .
2009-07-21 07:09:47 +00:00
*
2009-10-09 01:00:08 +00:00
* @ param $variables
* An associative array containing :
2010-04-13 15:23:03 +00:00
* - form : A render element representing the form .
2009-10-09 01:00:08 +00:00
*
2009-07-21 07:09:47 +00:00
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_image_style_effects ( $variables ) {
$form = $variables [ 'form' ];
2009-07-21 07:09:47 +00:00
$rows = array ();
foreach ( element_children ( $form ) as $key ) {
2010-11-21 07:24:53 +00:00
$row = array ();
$form [ $key ][ 'weight' ][ '#attributes' ][ 'class' ] = array ( 'image-effect-order-weight' );
2011-12-03 15:06:48 +00:00
if ( $key != 'new' ) {
2009-07-21 07:09:47 +00:00
$summary = drupal_render ( $form [ $key ][ 'summary' ]);
$row [] = drupal_render ( $form [ $key ][ 'label' ]) . ( empty ( $summary ) ? '' : ' ' . $summary );
$row [] = drupal_render ( $form [ $key ][ 'weight' ]);
2012-10-09 19:49:07 +00:00
$row [] = array ( 'data' => $form [ $key ][ 'operations' ]);
2009-07-21 07:09:47 +00:00
}
else {
// Add the row for adding a new image effect.
$row [] = '<div class="image-style-new">' . drupal_render ( $form [ 'new' ][ 'new' ]) . drupal_render ( $form [ 'new' ][ 'add' ]) . '</div>' ;
$row [] = drupal_render ( $form [ 'new' ][ 'weight' ]);
2012-10-09 19:49:07 +00:00
$row [] = '' ;
2009-07-21 07:09:47 +00:00
}
2012-08-30 17:47:56 +00:00
$rows [] = array (
'data' => $row ,
'class' => array ( 'draggable' ),
);
2009-07-21 07:09:47 +00:00
}
$header = array (
t ( 'Effect' ),
t ( 'Weight' ),
2012-10-09 19:49:07 +00:00
t ( 'Operations' ),
2009-07-21 07:09:47 +00:00
);
2012-01-02 12:48:19 +00:00
if ( count ( $rows ) == 1 && ( ! isset ( $form [ 'new' ][ '#access' ]) || $form [ 'new' ][ '#access' ])) {
2009-07-21 07:09:47 +00:00
array_unshift ( $rows , array ( array (
'data' => t ( 'There are currently no effects in this style. Add one by selecting an option below.' ),
'colspan' => 4 ,
)));
}
2009-10-09 01:00:08 +00:00
$output = theme ( 'table' , array ( 'header' => $header , 'rows' => $rows , 'attributes' => array ( 'id' => 'image-style-effects' )));
2009-07-21 07:09:47 +00:00
drupal_add_tabledrag ( 'image-style-effects' , 'order' , 'sibling' , 'image-effect-order-weight' );
return $output ;
}
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for a preview of an image style .
2009-07-21 07:09:47 +00:00
*
2009-10-09 01:00:08 +00:00
* @ param $variables
* An associative array containing :
2013-07-08 22:37:04 +00:00
* - style : \Drupal\image\ImageStyleInterface image style being previewed .
2009-10-09 01:00:08 +00:00
*
2009-07-21 07:09:47 +00:00
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_image_style_preview ( $variables ) {
$style = $variables [ 'style' ];
2012-11-03 01:18:07 +00:00
$sample_image = config ( 'image.settings' ) -> get ( 'preview_image' );
2009-07-21 07:09:47 +00:00
$sample_width = 160 ;
$sample_height = 160 ;
// Set up original file information.
$original_path = $sample_image ;
$original_image = image_get_info ( $original_path );
if ( $original_image [ 'width' ] > $original_image [ 'height' ]) {
$original_width = min ( $original_image [ 'width' ], $sample_width );
$original_height = round ( $original_width / $original_image [ 'width' ] * $original_image [ 'height' ]);
}
else {
$original_height = min ( $original_image [ 'height' ], $sample_height );
$original_width = round ( $original_height / $original_image [ 'height' ] * $original_image [ 'width' ]);
}
$original_attributes = array_intersect_key ( $original_image , array ( 'width' => '' , 'height' => '' ));
$original_attributes [ 'style' ] = 'width: ' . $original_width . 'px; height: ' . $original_height . 'px;' ;
// Set up preview file information.
2013-07-08 22:37:04 +00:00
$preview_file = $style -> buildUri ( $original_path );
2009-08-17 19:14:42 +00:00
if ( ! file_exists ( $preview_file )) {
2013-07-08 22:37:04 +00:00
$style -> createDerivative ( $original_path , $preview_file );
2009-07-21 07:09:47 +00:00
}
2009-08-17 19:14:42 +00:00
$preview_image = image_get_info ( $preview_file );
2009-07-21 07:09:47 +00:00
if ( $preview_image [ 'width' ] > $preview_image [ 'height' ]) {
$preview_width = min ( $preview_image [ 'width' ], $sample_width );
$preview_height = round ( $preview_width / $preview_image [ 'width' ] * $preview_image [ 'height' ]);
}
else {
$preview_height = min ( $preview_image [ 'height' ], $sample_height );
$preview_width = round ( $preview_height / $preview_image [ 'height' ] * $preview_image [ 'width' ]);
}
$preview_attributes = array_intersect_key ( $preview_image , array ( 'width' => '' , 'height' => '' ));
$preview_attributes [ 'style' ] = 'width: ' . $preview_width . 'px; height: ' . $preview_height . 'px;' ;
// In the previews, timestamps are added to prevent caching of images.
2010-10-21 20:50:43 +00:00
$output = '<div class="image-style-preview preview clearfix">' ;
2009-07-21 07:09:47 +00:00
// Build the preview of the original image.
2010-10-21 20:50:43 +00:00
$original_url = file_create_url ( $original_path );
2009-07-21 07:09:47 +00:00
$output .= '<div class="preview-image-wrapper">' ;
2010-10-21 20:50:43 +00:00
$output .= t ( 'original' ) . ' (' . l ( t ( 'view actual size' ), $original_url ) . ')' ;
2009-07-21 07:09:47 +00:00
$output .= '<div class="preview-image original-image" style="' . $original_attributes [ 'style' ] . '">' ;
2011-11-25 03:09:40 +00:00
$output .= '<a href="' . $original_url . '">' . theme ( 'image' , array ( 'uri' => $original_path , 'alt' => t ( 'Sample original image' ), 'title' => '' , 'attributes' => $original_attributes )) . '</a>' ;
2009-07-21 07:09:47 +00:00
$output .= '<div class="height" style="height: ' . $original_height . 'px"><span>' . $original_image [ 'height' ] . 'px</span></div>' ;
$output .= '<div class="width" style="width: ' . $original_width . 'px"><span>' . $original_image [ 'width' ] . 'px</span></div>' ;
$output .= '</div>' ; // End preview-image.
$output .= '</div>' ; // End preview-image-wrapper.
// Build the preview of the image style.
2010-10-21 20:50:43 +00:00
$preview_url = file_create_url ( $preview_file ) . '?cache_bypass=' . REQUEST_TIME ;
2009-07-21 07:09:47 +00:00
$output .= '<div class="preview-image-wrapper">' ;
2012-10-23 13:46:22 +00:00
$output .= check_plain ( $style -> label ()) . ' (' . l ( t ( 'view actual size' ), file_create_url ( $preview_file ) . '?' . time ()) . ')' ;
2009-07-21 07:09:47 +00:00
$output .= '<div class="preview-image modified-image" style="' . $preview_attributes [ 'style' ] . '">' ;
2011-11-25 03:09:40 +00:00
$output .= '<a href="' . file_create_url ( $preview_file ) . '?' . time () . '">' . theme ( 'image' , array ( 'uri' => $preview_url , 'alt' => t ( 'Sample modified image' ), 'title' => '' , 'attributes' => $preview_attributes )) . '</a>' ;
2009-07-21 07:09:47 +00:00
$output .= '<div class="height" style="height: ' . $preview_height . 'px"><span>' . $preview_image [ 'height' ] . 'px</span></div>' ;
$output .= '<div class="width" style="width: ' . $preview_width . 'px"><span>' . $preview_image [ 'width' ] . 'px</span></div>' ;
$output .= '</div>' ; // End preview-image.
$output .= '</div>' ; // End preview-image-wrapper.
$output .= '</div>' ; // End image-style-preview.
return $output ;
}
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for a 3 x3 grid of checkboxes for image anchors .
2009-07-21 07:09:47 +00:00
*
2009-10-09 01:00:08 +00:00
* @ param $variables
* An associative array containing :
2010-04-13 15:23:03 +00:00
* - element : A render element containing radio buttons .
2009-10-09 01:00:08 +00:00
*
2009-07-21 07:09:47 +00:00
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_image_anchor ( $variables ) {
$element = $variables [ 'element' ];
2009-07-21 07:09:47 +00:00
$rows = array ();
$row = array ();
foreach ( element_children ( $element ) as $n => $key ) {
$element [ $key ][ '#attributes' ][ 'title' ] = $element [ $key ][ '#title' ];
unset ( $element [ $key ][ '#title' ]);
$row [] = drupal_render ( $element [ $key ]);
if ( $n % 3 == 3 - 1 ) {
$rows [] = $row ;
$row = array ();
}
}
2009-10-09 01:00:08 +00:00
return theme ( 'table' , array ( 'header' => array (), 'rows' => $rows , 'attributes' => array ( 'class' => array ( 'image-anchor' ))));
2009-07-21 07:09:47 +00:00
}
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for a summary of an image resize effect .
2009-07-21 07:09:47 +00:00
*
2009-10-09 01:00:08 +00:00
* @ param $variables
* An associative array containing :
* - data : The current configuration for this resize effect .
*
2009-07-21 07:09:47 +00:00
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_image_resize_summary ( $variables ) {
$data = $variables [ 'data' ];
2009-07-21 07:09:47 +00:00
if ( $data [ 'width' ] && $data [ 'height' ]) {
return check_plain ( $data [ 'width' ]) . 'x' . check_plain ( $data [ 'height' ]);
}
else {
return ( $data [ 'width' ]) ? t ( 'width @width' , array ( '@width' => $data [ 'width' ])) : t ( 'height @height' , array ( '@height' => $data [ 'height' ]));
}
}
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for a summary of an image scale effect .
2009-07-21 07:09:47 +00:00
*
2009-10-09 01:00:08 +00:00
* @ param $variables
* An associative array containing :
* - data : The current configuration for this scale effect .
*
2009-07-21 07:09:47 +00:00
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_image_scale_summary ( $variables ) {
$data = $variables [ 'data' ];
return theme ( 'image_resize_summary' , array ( 'data' => $data )) . ' ' . ( $data [ 'upscale' ] ? '(' . t ( 'upscaling allowed' ) . ')' : '' );
2009-07-21 07:09:47 +00:00
}
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for a summary of an image crop effect .
2009-07-21 07:09:47 +00:00
*
2009-10-09 01:00:08 +00:00
* @ param $variables
* An associative array containing :
* - data : The current configuration for this crop effect .
*
2009-07-21 07:09:47 +00:00
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_image_crop_summary ( $variables ) {
2013-06-29 10:00:09 +00:00
$image_resize_summary = array (
'#theme' => 'image_resize_summary' ,
'#data' => $variables [ 'data' ],
);
return drupal_render ( $image_resize_summary );
2009-07-21 07:09:47 +00:00
}
/**
2010-04-13 15:23:03 +00:00
* Returns HTML for a summary of an image rotate effect .
2009-07-21 07:09:47 +00:00
*
2009-10-09 01:00:08 +00:00
* @ param $variables
* An associative array containing :
* - data : The current configuration for this rotate effect .
*
2009-07-21 07:09:47 +00:00
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_image_rotate_summary ( $variables ) {
$data = $variables [ 'data' ];
2009-07-21 07:09:47 +00:00
return ( $data [ 'random' ]) ? t ( 'random between -@degrees° and @degrees°' , array ( '@degrees' => str_replace ( '-' , '' , $data [ 'degrees' ]))) : t ( '@degrees°' , array ( '@degrees' => $data [ 'degrees' ]));
}