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
← All changes | classes/rest.php +26 -15 5.5.2trunk View file →
@@ -142,17 +142,31 @@
142 142 $params = json_decode( $params );
143 143 $params->ids = implode( ',', $params->ids );
144 144 $atts = ( array ) $params;
145 145
146 + $full = !empty( $atts['full'] );
147 + unset( $atts['full'] );
148 +
146 149 $is_collection = isset( $atts['collection'] ) && !empty( $atts['collection'] );
147 150 if ( $is_collection ) {
148 151 $html = do_shortcode( '[meow-collection id="' . $atts['collection'] . '"]' );
152 + $counts = [ 'total' => 0, 'shown' => 0 ];
149 153 } else {
154 + $this->core->last_preview_counts = [ 'total' => 0, 'shown' => 0 ];
155 + if ( $full ) {
156 + $this->core->preview_cutoff = PHP_INT_MAX;
157 + }
150 158 $html = $this->core->gallery( $atts, [ 'isPreview' => true ] );
159 + $counts = $this->core->last_preview_counts;
151 160 }
152 161
153 162
154 - return new WP_REST_Response( [ 'success' => true, 'data' => $html ], 200 );
163 + return new WP_REST_Response( [
164 + 'success' => true,
165 + 'data' => $html,
166 + 'total' => intval( $counts['total'] ),
167 + 'shown' => intval( $counts['shown'] ),
168 + ], 200 );
155 169 }
156 170
157 171 function rest_load_gallery_collection( $request ) {
158 172 try {
@@ -201,9 +215,9 @@
201 215 global $wpdb;
202 216 $params = $request->get_json_params( );
203 217
204 218 $id = $params['id'];
205 - $medias = $params['medias'];
219 + $medias = Meow_MGL_Core::normalize_medias( $params['medias'] ?? null );
206 220 $name = $params['name'];
207 221 $layout = $params['layout'];
208 222 $description = $params['description'];
209 223 $posts = $params['posts'];
@@ -219,9 +233,9 @@
219 233 if ( !$name ) {
220 234 throw new Exception( __( 'Please enter a name for your shortcode.', MGL_DOMAIN ));
221 235 }
222 236
223 - if ( !$is_post_mode && ( !$medias || !count( $medias['thumbnail_ids'] )) ) {
237 + if ( !$is_post_mode && empty( $medias['thumbnail_ids'] ) ) {
224 238 throw new Exception( __( 'Please select at least one image.', MGL_DOMAIN ));
225 239 }
226 240
227 241 if ( $is_post_mode && $dynamic_source === 'posts' && ( !$posts && !$latest_posts )) {
@@ -403,9 +417,9 @@
403 417 $galleries[$gallery['id']] = [
404 418 'name' => $gallery['name'],
405 419 'description' => $gallery['description'],
406 420 'layout' => $gallery['layout'],
407 - 'medias' => unserialize( $gallery['medias'] ),
421 + 'medias' => Meow_MGL_Core::hydrate_medias( maybe_unserialize( $gallery['medias'] ) ),
408 422 'is_post_mode' => ( bool )$gallery['is_post_mode'],
409 423 'hero' => ( bool )$gallery['is_hero_mode'],
410 424 'posts' => $gallery['posts'] ? unserialize( $gallery['posts'] ) : null,
411 425 'latest_posts' => $gallery['latest_posts'],
@@ -515,24 +529,21 @@
515 529 "AND p.ID NOT IN ( " . implode( ', ', array_fill( 0, count( $except ), '%s' )) . " )", $except
516 530 ) : '';
517 531 $join_clause = '';
518 532 if ( $unusedImages ) {
519 - // Retrieve the serialized option from the database
520 - $meow_gallery_shortcodes = get_option( 'mgl_shortcodes' );
533 + // Every image used by a gallery, read from the galleries table (this used to read the
534 + // old 'mgl_shortcodes' option, which isn't written anymore since the migration).
535 + $shortcodes_table = $wpdb->prefix . 'mgl_gallery_shortcodes';
536 + Meow_MGL_Migrations::check_db();
521 537
522 - // Deserialize the option to get the array
523 - $shortcodes_array = maybe_unserialize( $meow_gallery_shortcodes );
524 -
525 - // Extract all thumbnail IDs from the array
526 538 $used_thumbnail_ids = [];
527 - foreach ( $shortcodes_array as $shortcode ) {
528 - if ( isset( $shortcode['medias']['thumbnail_ids'] ) && is_array( $shortcode['medias']['thumbnail_ids'] ) ) {
529 - $used_thumbnail_ids = array_merge( $used_thumbnail_ids, $shortcode['medias']['thumbnail_ids'] );
530 - }
539 + foreach ( $wpdb->get_col( "SELECT medias FROM $shortcodes_table" ) as $medias ) {
540 + $medias = Meow_MGL_Core::normalize_medias( maybe_unserialize( $medias ) );
541 + $used_thumbnail_ids = array_merge( $used_thumbnail_ids, $medias['thumbnail_ids'] );
531 542 }
532 543
533 544 // Make sure the IDs are integers
534 - $used_thumbnail_ids = array_map( 'intval', $used_thumbnail_ids );
545 + $used_thumbnail_ids = array_unique( array_map( 'intval', $used_thumbnail_ids ) );
535 546
536 547 // Include the NOT IN clause to exclude used thumbnail IDs
537 548 if ( !empty( $used_thumbnail_ids ) ) {
538 549 $placeholders = implode( ',', array_fill( 0, count( $used_thumbnail_ids ), '%d' ) );