PluginProbe
Meow Gallery / trunk
Meow Gallery vtrunk
5.5.4 5.5.3 5.5.2 5.5.1 5.5.0 5.4.9 5.4.8 5.4.7 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 All 156 releases
meow-gallery / classes / skeleton.php

skeleton.php in Meow Gallery trunk, at classes/skeleton.php

212 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Meow_MGL_Skeleton {
4
5 public function __construct() {
6 // Constructor logic if needed
7 }
8
9 public function get_skeleton_html($layout, $gallery_options, $image_count = null) {
10 $skeleton_html = '<div class="mgl-gallery-skeleton" style="opacity: 1;">';
11
12 switch ($layout) {
13 case 'tiles':
14 $skeleton_html .= $this->get_responsive_tiles_skeleton($gallery_options, $image_count);
15 break;
16 case 'masonry':
17 $skeleton_html .= $this->get_responsive_masonry_skeleton($gallery_options, $image_count);
18 break;
19 case 'square':
20 $skeleton_html .= $this->get_responsive_square_skeleton($gallery_options, $image_count);
21 break;
22 case 'justified':
23 $skeleton_html .= $this->get_responsive_justified_skeleton($gallery_options, $image_count);
24 break;
25 case 'cascade':
26 $skeleton_html .= $this->get_responsive_cascade_skeleton($gallery_options, $image_count);
27 break;
28 case 'horizontal':
29 case 'carousel':
30 $skeleton_html .= $this->get_responsive_horizontal_skeleton($gallery_options, $image_count);
31 break;
32 case 'map':
33 $skeleton_html .= $this->get_map_skeleton($gallery_options, $image_count);
34 break;
35 default:
36 $skeleton_html .= $this->get_responsive_tiles_skeleton($gallery_options, $image_count);
37 }
38
39 $skeleton_html .= '</div>';
40
41 return $skeleton_html;
42 }
43
44 private function get_responsive_tiles_skeleton($gallery_options, $image_count = null) {
45 $gutter = $gallery_options['tiles_gutter'] ?? 10;
46 $columns = $gallery_options['tiles_columns'] ?? 2;
47 $count = $image_count ?? 4; // Default to 4 if no count provided
48
49 // Limit the skeleton to a reasonable number to prevent performance issues
50 $count = min($count, 12);
51
52 $html = '<div class="mgl-skeleton-tiles" style="width: 100%; opacity: 1;">';
53
54 // Calculate rows needed
55 $rows = ceil($count / $columns);
56 $rows = min($rows, 3); // Limit to 3 rows maximum
57
58 for ($row = 0; $row < $rows; $row++) {
59 $html .= '<div style="display: flex; margin-bottom: ' . $gutter . 'px; height: 200px;">';
60
61 // Items in this row
62 $items_in_row = min($columns, $count - ($row * $columns));
63
64 for ($col = 0; $col < $items_in_row; $col++) {
65 $html .= '<div style="flex: 1; padding: 0 ' . ($gutter/2) . 'px;">';
66 $html .= '<div class="mgl-skeleton-item" style="width: 100%; height: 100%; background-color: #e2e2e2; border-radius: 4px; overflow: hidden; position: relative;">';
67 $html .= '<div class="mgl-skeleton-shimmer"></div>';
68 $html .= '</div></div>';
69 }
70
71 $html .= '</div>';
72 }
73
74 $html .= '</div>';
75
76 return $html;
77 }
78
79 private function get_responsive_masonry_skeleton($gallery_options, $image_count = null) {
80 $columns = $gallery_options['masonry_columns'] ?? 3;
81 $gutter = $gallery_options['masonry_gutter'] ?? 5;
82 $count = $image_count ?? 6; // Default to 6 if no count provided
83
84 // Limit the skeleton to a reasonable number
85 $count = min($count, $columns * 3); // Max 3 rows worth
86
87 $html = '<div class="mgl-skeleton-masonry" style="display: grid; grid-template-columns: repeat(' . $columns . ', 1fr); gap: ' . $gutter . 'px; height: 300px; overflow: hidden;">';
88
89 for ($i = 0; $i < $count; $i++) {
90 $height = 120 + ($i % 3) * 40; // Vary heights slightly
91 $html .= '<div class="mgl-skeleton-item" style="height: ' . $height . 'px; background-color: #e2e2e2; border-radius: 4px; overflow: hidden; position: relative;">';
92 $html .= '<div class="mgl-skeleton-shimmer"></div>';
93 $html .= '</div>';
94 }
95
96 $html .= '</div>';
97
98 return $html;
99 }
100
101 private function get_responsive_square_skeleton($gallery_options, $image_count = null) {
102 $columns = $gallery_options['square_columns_desktop'] ?? 5;
103 $gutter = $gallery_options['square_gutter'] ?? 5;
104 $count = $image_count ?? $columns; // Default to one row if no count provided
105
106 // Limit the skeleton to a reasonable number
107 $count = min($count, $columns * 2); // Max 2 rows worth
108
109 $html = '<div class="mgl-skeleton-square" style="display: grid; grid-template-columns: repeat(' . $columns . ', 1fr); gap: ' . $gutter . 'px; overflow: hidden;">';
110
111 for ($i = 0; $i < $count; $i++) {
112 $html .= '<div class="mgl-skeleton-item" style="aspect-ratio: 1; background-color: #e2e2e2; border-radius: 4px; overflow: hidden; position: relative;">';
113 $html .= '<div class="mgl-skeleton-shimmer"></div>';
114 $html .= '</div>';
115 }
116
117 $html .= '</div>';
118
119 return $html;
120 }
121
122 private function get_responsive_justified_skeleton($gallery_options, $image_count = null) {
123 $gutter = $gallery_options['justified_gutter'] ?? 5;
124 $row_height = min($gallery_options['justified_row_height'] ?? 200, 180); // Cap at 180px
125 $count = $image_count ?? 6; // Default to 6 if no count provided
126
127 // Limit the skeleton to a reasonable number
128 $count = min($count, 9); // Max 9 items
129 $items_per_row = 3;
130 $rows = min(ceil($count / $items_per_row), 3); // Max 3 rows
131
132 $html = '<div class="mgl-skeleton-justified">';
133
134 for ($row = 0; $row < $rows; $row++) {
135 $items_in_row = min($items_per_row, $count - ($row * $items_per_row));
136 $html .= '<div style="display: flex; height: ' . $row_height . 'px; margin-bottom: ' . $gutter . 'px;">';
137
138 for ($i = 0; $i < $items_in_row; $i++) {
139 $html .= '<div class="mgl-skeleton-item" style="flex: 1; margin: 0 ' . ($gutter / 2) . 'px; height: 100%; background-color: #e2e2e2; border-radius: 4px; overflow: hidden; position: relative;">';
140 $html .= '<div class="mgl-skeleton-shimmer"></div>';
141 $html .= '</div>';
142 }
143
144 $html .= '</div>';
145 }
146
147 $html .= '</div>';
148
149 return $html;
150 }
151
152 private function get_responsive_cascade_skeleton($gallery_options, $image_count = null) {
153 $gutter = $gallery_options['cascade_gutter'] ?? 10;
154 $count = $image_count ?? 4; // Default to 4 if no count provided
155
156 // Limit the skeleton to a reasonable number
157 $count = min($count, 6); // Max 6 items for cascade
158
159 $html = '<div class="mgl-skeleton-cascade" style="overflow: hidden;">';
160
161 for ($i = 0; $i < $count; $i++) {
162 $width = ($i % 2 === 0) ? '60%' : '40%';
163 $height = 100 + ($i * 20);
164 $margin_left = ($i % 2 === 0) ? '0' : 'auto';
165
166 $html .= '<div style="padding: ' . ($gutter / 2) . 'px;">';
167 $html .= '<div class="mgl-skeleton-item" style="height: ' . $height . 'px; width: ' . $width . '; margin-left: ' . $margin_left . '; background-color: #e2e2e2; border-radius: 4px; overflow: hidden; position: relative;">';
168 $html .= '<div class="mgl-skeleton-shimmer"></div>';
169 $html .= '</div></div>';
170 }
171
172 $html .= '</div>';
173
174 return $html;
175 }
176
177 private function get_responsive_horizontal_skeleton($gallery_options, $image_count = null) {
178 $image_height = min($gallery_options['horizontal_image_height'] ?? $gallery_options['carousel_image_height'] ?? 300, 250); // Cap at 250px
179 $gutter = $gallery_options['horizontal_gutter'] ?? $gallery_options['carousel_gutter'] ?? 5;
180 $count = $image_count ?? 5; // Default to 5 if no count provided
181
182 // Limit the skeleton to a reasonable number
183 $count = min($count, 8); // Max 8 items for horizontal
184
185 $html = '<div class="mgl-skeleton-horizontal" style="height: ' . $image_height . 'px;">';
186 $html .= '<div style="display: flex; height: 100%; overflow: hidden;">';
187
188 for ($i = 0; $i < $count; $i++) {
189 $width = $image_height * 0.8; // Fixed ratio
190 $html .= '<div class="mgl-skeleton-item" style="height: 100%; width: ' . $width . 'px; flex-shrink: 0; margin-right: ' . $gutter . 'px; background-color: #e2e2e2; border-radius: 4px; overflow: hidden; position: relative;">';
191 $html .= '<div class="mgl-skeleton-shimmer"></div>';
192 $html .= '</div>';
193 }
194
195 $html .= '</div></div>';
196
197 return $html;
198 }
199
200 private function get_map_skeleton($gallery_options, $image_count = null) {
201 $height = $gallery_options['map_height'] ?? 400;
202
203 $html = '<div class="mgl-skeleton-map" style="height: ' . $height . 'px; background-color: #f0f0f0; display: flex; align-items: center; justify-content: center; position: relative; border-radius: 4px; overflow: hidden;">';
204 $html .= '<div class="mgl-skeleton-shimmer"></div>';
205 $html .= '</div>';
206
207 return $html;
208 }
209
210 }
211
212 ?>