|
1
|
|
|
<?php |
|
2
|
|
|
class Jetpack_Tiled_Gallery_Shape { |
|
3
|
|
|
static $shapes_used = array(); |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
public function __construct( $images ) { |
|
6
|
|
|
$this->images = $images; |
|
|
|
|
|
|
7
|
|
|
$this->images_left = count( $images ); |
|
|
|
|
|
|
8
|
|
|
} |
|
9
|
|
|
|
|
10
|
|
|
public function sum_ratios( $number_of_images = 3 ) { |
|
11
|
|
|
return array_sum( array_slice( wp_list_pluck( $this->images, 'ratio' ), 0, $number_of_images ) ); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function next_images_are_symmetric() { |
|
15
|
|
|
return $this->images_left > 2 && $this->images[0]->ratio == $this->images[2]->ratio; |
|
|
|
|
|
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function is_not_as_previous( $n = 1 ) { |
|
19
|
|
|
return ! in_array( get_class( $this ), array_slice( self::$shapes_used, -$n ) ); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function is_wide_theme() { |
|
23
|
|
|
return Jetpack::get_content_width() > 1000; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function image_is_landscape( $image ) { |
|
27
|
|
|
return $image->ratio >= 1 && $image->ratio < 2; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function image_is_portrait( $image ) { |
|
31
|
|
|
return $image->ratio < 1; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function image_is_panoramic( $image ) { |
|
35
|
|
|
return $image->ratio >= 2; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public static function set_last_shape( $last_shape ) { |
|
39
|
|
|
self::$shapes_used[] = $last_shape; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public static function reset_last_shape() { |
|
43
|
|
|
self::$shapes_used = array(); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
class Jetpack_Tiled_Gallery_Three extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
48
|
|
|
public $shape = array( 1, 1, 1 ); |
|
49
|
|
|
|
|
50
|
|
|
public function is_possible() { |
|
51
|
|
|
$ratio = $this->sum_ratios( 3 ); |
|
52
|
|
|
$has_enough_images = $this->images_left >= 3 && ! in_array( $this->images_left, array( 4, 6 ) ); |
|
|
|
|
|
|
53
|
|
|
return $has_enough_images && $this->is_not_as_previous( 3 ) && |
|
54
|
|
|
( ( $ratio < 2.5 ) || ( $ratio < 5 && $this->next_images_are_symmetric() ) || $this->is_wide_theme() ); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
View Code Duplication |
class Jetpack_Tiled_Gallery_Four extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
59
|
|
|
public $shape = array( 1, 1, 1, 1 ); |
|
60
|
|
|
|
|
61
|
|
|
public function is_possible() { |
|
62
|
|
|
return $this->is_not_as_previous() && |
|
63
|
|
|
( |
|
64
|
|
|
( $this->sum_ratios( 4 ) < 3.5 && $this->images_left > 5 ) || |
|
|
|
|
|
|
65
|
|
|
( $this->sum_ratios( 4 ) < 7 && $this->images_left == 4 ) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
View Code Duplication |
class Jetpack_Tiled_Gallery_Five extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
71
|
|
|
public $shape = array( 1, 1, 1, 1, 1 ); |
|
72
|
|
|
|
|
73
|
|
|
public function is_possible() { |
|
74
|
|
|
return $this->is_wide_theme() && $this->is_not_as_previous() && $this->sum_ratios( 5 ) < 5 && |
|
75
|
|
|
( $this->images_left == 5 || ( $this->images_left != 10 && $this->images_left > 6 ) ); |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
View Code Duplication |
class Jetpack_Tiled_Gallery_Two_One extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
80
|
|
|
public $shape = array( 2, 1 ); |
|
81
|
|
|
|
|
82
|
|
|
public function is_possible() { |
|
83
|
|
|
return $this->is_not_as_previous( 3 ) && $this->images_left >= 2 && |
|
|
|
|
|
|
84
|
|
|
$this->images[2]->ratio < 1.6 && $this->images[0]->ratio >= 0.9 && $this->images[0]->ratio < 2.0 && $this->images[1]->ratio >= 0.9 && $this->images[1]->ratio < 2.0; |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
View Code Duplication |
class Jetpack_Tiled_Gallery_One_Two extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
89
|
|
|
public $shape = array( 1, 2 ); |
|
90
|
|
|
|
|
91
|
|
|
public function is_possible() { |
|
92
|
|
|
return $this->is_not_as_previous( 3 ) && $this->images_left >= 2 && |
|
|
|
|
|
|
93
|
|
|
$this->images[0]->ratio < 1.6 && $this->images[1]->ratio >= 0.9 && $this->images[1]->ratio < 2.0 && $this->images[2]->ratio >= 0.9 && $this->images[2]->ratio < 2.0; |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
class Jetpack_Tiled_Gallery_One_Three extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
98
|
|
|
public $shape = array( 1, 3 ); |
|
99
|
|
|
|
|
100
|
|
|
public function is_possible() { |
|
101
|
|
|
return $this->is_not_as_previous( 3 ) && $this->images_left > 3 && |
|
|
|
|
|
|
102
|
|
|
$this->image_is_portrait( $this->images[0] ) && |
|
|
|
|
|
|
103
|
|
|
$this->image_is_landscape( $this->images[1] ) && |
|
|
|
|
|
|
104
|
|
|
$this->image_is_landscape( $this->images[2] ) && |
|
|
|
|
|
|
105
|
|
|
$this->image_is_landscape( $this->images[3] ); |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
class Jetpack_Tiled_Gallery_Three_One extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
110
|
|
|
public $shape = array( 3, 1 ); |
|
111
|
|
|
|
|
112
|
|
|
public function is_possible() { |
|
113
|
|
|
return $this->is_not_as_previous( 3 ) && $this->images_left > 3 && |
|
|
|
|
|
|
114
|
|
|
$this->image_is_portrait( $this->images[3] ) && |
|
|
|
|
|
|
115
|
|
|
$this->image_is_landscape( $this->images[0] ) && |
|
|
|
|
|
|
116
|
|
|
$this->image_is_landscape( $this->images[1] ) && |
|
|
|
|
|
|
117
|
|
|
$this->image_is_landscape( $this->images[2] ); |
|
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
class Jetpack_Tiled_Gallery_Panoramic extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
122
|
|
|
public $shape = array( 1 ); |
|
123
|
|
|
|
|
124
|
|
|
public function is_possible() { |
|
125
|
|
|
return $this->image_is_panoramic( $this->images[0] ); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
View Code Duplication |
class Jetpack_Tiled_Gallery_Symmetric_Row extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
130
|
|
|
public $shape = array( 1, 2, 1 ); |
|
131
|
|
|
|
|
132
|
|
|
public function is_possible() { |
|
133
|
|
|
return $this->is_not_as_previous( 5 ) && |
|
134
|
|
|
$this->images_left > 3 && |
|
|
|
|
|
|
135
|
|
|
$this->images_left != 5 && |
|
136
|
|
|
$this->image_is_portrait( $this->images[0] ) && |
|
|
|
|
|
|
137
|
|
|
$this->image_is_landscape( $this->images[1] ) && |
|
|
|
|
|
|
138
|
|
|
$this->image_is_landscape( $this->images[2] ) && |
|
|
|
|
|
|
139
|
|
|
$this->image_is_portrait( $this->images[3] ); |
|
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
View Code Duplication |
class Jetpack_Tiled_Gallery_Reverse_Symmetric_Row extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
143
|
|
|
public $shape = array( 2, 1, 2 ); |
|
144
|
|
|
|
|
145
|
|
|
public function is_possible() { |
|
146
|
|
|
return $this->is_not_as_previous( 5 ) && $this->images_left > 15 && |
|
|
|
|
|
|
147
|
|
|
$this->image_is_landscape( $this->images[0] ) && |
|
|
|
|
|
|
148
|
|
|
$this->image_is_landscape( $this->images[1] ) && |
|
|
|
|
|
|
149
|
|
|
$this->image_is_portrait( $this->images[2] ) && |
|
|
|
|
|
|
150
|
|
|
$this->image_is_landscape( $this->images[3] ) && |
|
|
|
|
|
|
151
|
|
|
$this->image_is_landscape( $this->images[4] ); |
|
|
|
|
|
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
class Jetpack_Tiled_Gallery_Long_Symmetric_Row extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
156
|
|
|
public $shape = array( 3, 1, 3 ); |
|
157
|
|
|
|
|
158
|
|
|
public function is_possible() { |
|
159
|
|
|
return $this->is_not_as_previous( 5 ) && $this->images_left > 15 && |
|
|
|
|
|
|
160
|
|
|
$this->image_is_landscape( $this->images[0] ) && |
|
|
|
|
|
|
161
|
|
|
$this->image_is_landscape( $this->images[1] ) && |
|
|
|
|
|
|
162
|
|
|
$this->image_is_landscape( $this->images[2] ) && |
|
|
|
|
|
|
163
|
|
|
$this->image_is_portrait( $this->images[3] ) && |
|
|
|
|
|
|
164
|
|
|
$this->image_is_landscape( $this->images[4] ) && |
|
|
|
|
|
|
165
|
|
|
$this->image_is_landscape( $this->images[5] ) && |
|
|
|
|
|
|
166
|
|
|
$this->image_is_landscape( $this->images[6] ); |
|
|
|
|
|
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
class Jetpack_Tiled_Gallery_Three_Columns extends Jetpack_Tiled_Gallery_Shape { |
|
|
|
|
|
|
171
|
|
|
public $shape = array(); |
|
172
|
|
|
|
|
173
|
|
|
public function __construct( $images ) { |
|
174
|
|
|
parent::__construct( $images ); |
|
175
|
|
|
|
|
176
|
|
|
$total_ratio = $this->sum_ratios( $this->images_left ); |
|
|
|
|
|
|
177
|
|
|
$approximate_column_ratio = $total_ratio / 3; |
|
178
|
|
|
$column_one_images = $column_two_images = $column_three_images = $sum = 0; |
|
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
foreach ( $this->images as $image ) { |
|
|
|
|
|
|
181
|
|
|
if ( $sum <= $approximate_column_ratio ) { |
|
182
|
|
|
$column_one_images++; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
if ( $sum > $approximate_column_ratio && $sum <= 2 * $approximate_column_ratio ) { |
|
186
|
|
|
$column_two_images++; |
|
187
|
|
|
} |
|
188
|
|
|
$sum += $image->ratio; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
$column_three_images = $this->images_left - $column_two_images - $column_one_images; |
|
192
|
|
|
|
|
193
|
|
|
if ( $column_one_images ) { |
|
194
|
|
|
$this->shape[] = $column_one_images; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
if ( $column_two_images ) { |
|
198
|
|
|
$this->shape[] = $column_two_images; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
if ( $column_three_images ) { |
|
202
|
|
|
$this->shape[] = $column_three_images; |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
public function is_possible() { |
|
207
|
|
|
return ! empty( $this->shape ); |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.