summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/tiled-gallery/tiled-gallery/tiled-gallery-rectangular.php')
-rw-r--r--plugins/jetpack/modules/tiled-gallery/tiled-gallery/tiled-gallery-rectangular.php55
1 files changed, 29 insertions, 26 deletions
diff --git a/plugins/jetpack/modules/tiled-gallery/tiled-gallery/tiled-gallery-rectangular.php b/plugins/jetpack/modules/tiled-gallery/tiled-gallery/tiled-gallery-rectangular.php
index 40eaaf07..9ea272fc 100644
--- a/plugins/jetpack/modules/tiled-gallery/tiled-gallery/tiled-gallery-rectangular.php
+++ b/plugins/jetpack/modules/tiled-gallery/tiled-gallery/tiled-gallery-rectangular.php
@@ -10,7 +10,7 @@ class Jetpack_Tiled_Gallery_Layout_Rectangular extends Jetpack_Tiled_Gallery_Lay
$grouper = new Jetpack_Tiled_Gallery_Grouper( $this->attachments );
Jetpack_Tiled_Gallery_Shape::reset_last_shape();
- return parent::HTML( array( 'rows' => $grouper->grouped_images ) );
+ return parent::HTML( array( 'rows' => $grouper->grouped_images ) );
}
}
@@ -20,7 +20,7 @@ class Jetpack_Tiled_Gallery_Layout_Columns extends Jetpack_Tiled_Gallery_Layout
public function HTML( $context = array() ) {
$grouper = new Jetpack_Tiled_Gallery_Grouper( $this->attachments, array( 'Three_Columns', 'Two' ) );
- return parent::HTML( array( 'rows' => $grouper->grouped_images ) );
+ return parent::HTML( array( 'rows' => $grouper->grouped_images ) );
}
}
@@ -43,15 +43,15 @@ class Jetpack_Tiled_Gallery_Grouper {
'Four',
'Three',
'Two_One',
- 'Panoramic'
+ 'Panoramic',
);
public function __construct( $attachments, $shapes = array() ) {
$content_width = Jetpack_Tiled_Gallery::get_content_width();
$this->overwrite_shapes( $shapes );
- $this->last_shape = '';
- $this->images = $this->get_images_with_sizes( $attachments );
+ $this->last_shape = '';
+ $this->images = $this->get_images_with_sizes( $attachments );
$this->grouped_images = $this->get_grouped_images();
$this->apply_content_width( $content_width );
}
@@ -64,12 +64,13 @@ class Jetpack_Tiled_Gallery_Grouper {
public function get_current_row_size() {
$images_left = count( $this->images );
- if ( $images_left < 3 )
+ if ( $images_left < 3 ) {
return array_fill( 0, $images_left, 1 );
+ }
foreach ( $this->shapes as $shape_name ) {
$class_name = "Jetpack_Tiled_Gallery_$shape_name";
- $shape = new $class_name( $this->images );
+ $shape = new $class_name( $this->images );
if ( $shape->is_possible() ) {
Jetpack_Tiled_Gallery_Shape::set_last_shape( $class_name );
return $shape->shape;
@@ -84,11 +85,11 @@ class Jetpack_Tiled_Gallery_Grouper {
$images_with_sizes = array();
foreach ( $attachments as $image ) {
- $meta = wp_get_attachment_metadata( $image->ID );
- $image->width_orig = ( isset( $meta['width'] ) && $meta['width'] > 0 )? $meta['width'] : 1;
- $image->height_orig = ( isset( $meta['height'] ) && $meta['height'] > 0 )? $meta['height'] : 1;
- $image->ratio = $image->width_orig / $image->height_orig;
- $image->ratio = $image->ratio? $image->ratio : 1;
+ $meta = wp_get_attachment_metadata( $image->ID );
+ $image->width_orig = ( isset( $meta['width'] ) && $meta['width'] > 0 ) ? $meta['width'] : 1;
+ $image->height_orig = ( isset( $meta['height'] ) && $meta['height'] > 0 ) ? $meta['height'] : 1;
+ $image->ratio = $image->width_orig / $image->height_orig;
+ $image->ratio = $image->ratio ? $image->ratio : 1;
$images_with_sizes[] = $image;
}
@@ -109,7 +110,7 @@ class Jetpack_Tiled_Gallery_Grouper {
public function get_grouped_images() {
$grouped_images = array();
- while( !empty( $this->images ) ) {
+ while ( ! empty( $this->images ) ) {
$grouped_images[] = new Jetpack_Tiled_Gallery_Row( $this->read_row() );
}
@@ -120,9 +121,9 @@ class Jetpack_Tiled_Gallery_Grouper {
// todo: do not stretch images
public function apply_content_width( $width ) {
foreach ( $this->grouped_images as $row ) {
- $row->width = $width;
+ $row->width = $width;
$row->raw_height = 1 / $row->ratio * ( $width - $this->margin * ( count( $row->groups ) - $row->weighted_ratio ) );
- $row->height = round( $row->raw_height );
+ $row->height = round( $row->raw_height );
$this->calculate_group_sizes( $row );
}
@@ -135,7 +136,7 @@ class Jetpack_Tiled_Gallery_Grouper {
foreach ( $row->groups as $group ) {
$group->height = $row->height;
// Storing the raw calculations in a separate property to prevent rounding errors from cascading down and for diagnostics
- $group->raw_width = ( $row->raw_height - $this->margin * count( $group->images ) ) * $group->ratio + $this->margin;
+ $group->raw_width = ( $row->raw_height - $this->margin * count( $group->images ) ) * $group->ratio + $this->margin;
$group_widths_array[] = $group->raw_width;
}
$rounded_group_widths_array = Jetpack_Constrained_Array_Rounding::get_rounded_constrained_array( $group_widths_array, $row->width );
@@ -153,11 +154,11 @@ class Jetpack_Tiled_Gallery_Grouper {
foreach ( $group->images as $image ) {
$image->width = $group->width - $this->margin;
// Storing the raw calculations in a separate property for diagnostics
- $image->raw_height = ( $group->raw_width - $this->margin ) / $image->ratio;
+ $image->raw_height = ( $group->raw_width - $this->margin ) / $image->ratio;
$image_heights_array[] = $image->raw_height;
}
- $image_height_sum = $group->height - count( $image_heights_array ) * $this->margin;
+ $image_height_sum = $group->height - count( $image_heights_array ) * $this->margin;
$rounded_image_heights_array = Jetpack_Constrained_Array_Rounding::get_rounded_constrained_array( $image_heights_array, $image_height_sum );
foreach ( $group->images as $image ) {
@@ -168,8 +169,8 @@ class Jetpack_Tiled_Gallery_Grouper {
class Jetpack_Tiled_Gallery_Row {
public function __construct( $groups ) {
- $this->groups = $groups;
- $this->ratio = $this->get_ratio();
+ $this->groups = $groups;
+ $this->ratio = $this->get_ratio();
$this->weighted_ratio = $this->get_weighted_ratio();
}
@@ -178,7 +179,7 @@ class Jetpack_Tiled_Gallery_Row {
foreach ( $this->groups as $group ) {
$ratio += $group->ratio;
}
- return $ratio > 0? $ratio : 1;
+ return $ratio > 0 ? $ratio : 1;
}
public function get_weighted_ratio() {
@@ -193,19 +194,21 @@ class Jetpack_Tiled_Gallery_Row {
class Jetpack_Tiled_Gallery_Group {
public function __construct( $images ) {
$this->images = $images;
- $this->ratio = $this->get_ratio();
+ $this->ratio = $this->get_ratio();
}
public function get_ratio() {
$ratio = 0;
foreach ( $this->images as $image ) {
- if ( $image->ratio )
- $ratio += 1/$image->ratio;
+ if ( $image->ratio ) {
+ $ratio += 1 / $image->ratio;
+ }
}
- if ( !$ratio )
+ if ( ! $ratio ) {
return 1;
+ }
- return 1/$ratio;
+ return 1 / $ratio;
}
public function items( $needs_attachment_link, $grayscale ) {