PluginProbe
Media Cloud Sync / trunk
Media Cloud Sync vtrunk
1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 All 34 releases
← All changes | includes/filters/content.php +31 -16 1.2.12trunk View file →
@@ -305,21 +305,20 @@
305 305 $reverse_compatibility = apply_filters('wpmcs_enable_backward_url_replacement', false);
306 306
307 307 if( $reverse_compatibility ) {
308 308 if ( str_replace( Filter::get_bare_upload_base_urls(), '', $url ) !== $url ) {
309 + // Local URL, no replacement needed.
309 310 return false;
310 311 }
311 312
312 313 if ( str_replace( Filter::get_remote_domains(), '', $url ) === $url ) {
314 + // Not a known remote URL, no replacement needed.
313 315 return false;
314 316 }
315 317 } else {
316 318 if ( str_replace( Filter::get_bare_upload_base_urls(), '', $url ) === $url ) {
317 319 // Remote URL, no replacement needed
318 - if ( str_replace( Filter::get_bare_upload_base_urls(), '', $url ) === $url ) {
319 - // Remote URL, no replacement needed
320 - return false;
321 - }
320 + return false;
322 321 }
323 322 }
324 323
325 324 // Server URL, perform replacement
@@ -358,16 +357,17 @@
358 357 ? Utils::reduce_url($wpmcsItem->get_url( $item_source['id'], 'full', $item_source['source_type'] ))
359 358 : Utils::reduce_url(trailingslashit($upload_dir['baseurl']).$item['source_path']);
360 359
361 360
362 - $extras = $wpmcsItem->get_extras( $item_source['id'], false, $item_source['source_type'] );
363 361
364 - if(isset($extras['original']) && !Utils::is_empty($extras['original'])) {
362 + if(isset($item['original_source_path']) && !Utils::is_empty($item['original_source_path'])){
365 363 $bare_url[] = $backward_replacement
366 364 ? Utils::reduce_url($wpmcsItem->get_url( $item_source['id'], 'original', $item_source['source_type'] ))
367 - : Utils::reduce_url(trailingslashit($upload_dir['baseurl']).$extras['original']['source_path']);
365 + : Utils::reduce_url(trailingslashit($upload_dir['baseurl']).$item['original_source_path']);
368 366 }
369 367
368 + $extras = $wpmcsItem->get_extras( $item_source['id'], false, $item_source['source_type'] );
369 +
370 370 if(isset($extras['sizes']) && !Utils::is_empty($extras['sizes'])) {
371 371 foreach($extras['sizes'] as $size => $sub_image) {
372 372 if(!Utils::is_empty($sub_image)){
373 373 $bare_url[] = $backward_replacement
@@ -416,12 +416,14 @@
416 416 if($backward_replacement) {
417 417 $url_pairs[$source_cloud_file] = $source_server_file; // Backward compatibility
418 418 }
419 419
420 - $extras = $wpmcsItem->get_extras($item_source['id'], false, $item_source['source_type']);
421 420
422 - if(isset($extras['original']) && !Utils::is_empty($extras['original'])) {
423 - $original_server_file = Utils::remove_scheme($base.$extras['original']['source_path']);
421 + if(
422 + isset($item['original_source_path']) &&
423 + !Utils::is_empty($item['original_source_path'])
424 + ) {
425 + $original_server_file = Utils::remove_scheme($base.$item['original_source_path']);
424 426 $original_cloud_file = Utils::remove_scheme($wpmcsItem->get_url($item_source['id'], 'original', $item_source['source_type']));
425 427 $url_pairs[$original_server_file] = $original_cloud_file;
426 428 if($backward_replacement) {
427 429 $url_pairs[$original_cloud_file] = $original_server_file; // Backward compatibility
@@ -426,10 +428,15 @@
426 428 if($backward_replacement) {
427 429 $url_pairs[$original_cloud_file] = $original_server_file; // Backward compatibility
428 430 }
429 431 }
432 +
433 + $extras = $wpmcsItem->get_extras($item_source['id'], false, $item_source['source_type']);
434 +
430 435 if(isset($extras['sizes'])){
431 436 foreach ($extras['sizes'] as $size => $sub_image) {
437 + if(Utils::is_empty($sub_image['source_path'])) continue;
438 +
432 439 $sub_server_file = Utils::remove_scheme($base.$sub_image['source_path']);
433 440 $sub_cloud_file = Utils::remove_scheme($wpmcsItem->get_url( $item_source['id'], $size, $item_source['source_type'] ));
434 441 $url_pairs[$sub_server_file] = $sub_cloud_file;
435 442 if($backward_replacement) {
@@ -566,9 +573,11 @@
566 573
567 574 if ( empty( $urls ) ) {
568 575 return $results;
569 576 }
570 -
577 + // Check if backward compatibility is enabled
578 + $reverse_compatibility = apply_filters('wpmcs_enable_backward_url_replacement', false);
579 +
571 580 if ( ! is_array( $urls ) ) {
572 581 $urls = array( $urls );
573 582 }
574 583
@@ -601,9 +610,9 @@
601 610 continue;
602 611 }
603 612
604 613
605 - $path = Utils::get_attachment_source_path( $full_url );
614 + $path = Utils::get_attachment_source_path( $full_url, $reverse_compatibility ? 'key' : 'source' );
606 615
607 616 $paths[ $path ] = $full_url;
608 617 $full_urls[ $full_url ][] = $url;
609 618 }
@@ -608,9 +617,14 @@
608 617 $full_urls[ $full_url ][] = $url;
609 618 }
610 619
611 620 if ( ! empty( $paths ) ) {
612 - $wpmcsItems = $wpmcsItem->get_items_by_source_paths( array_keys( $paths ) );
621 + if($reverse_compatibility) {
622 + // For backward compatibility, search inside 'key' and 'original_key' columns.
623 + $wpmcsItems = $wpmcsItem->get_items_by_paths( array_keys( $paths ), true, false, 'key' );
624 + } else {
625 + $wpmcsItems = $wpmcsItem->get_items_by_paths( array_keys( $paths ) );
626 + }
613 627
614 628 if ( ! empty( $wpmcsItems ) ) {
615 629 foreach ( $wpmcsItems as $item ) {
616 630 // Each returned item may have matched on either the source_path or original_source_path.
@@ -618,11 +632,12 @@
618 632 // it's possible that both source paths are used by separate URLs.
619 633 $source_id = (int)$item['source_id'];
620 634 $source_type = $item['source_type'];
621 635 $source_paths = [ $item['source_path'] ];
622 - $original = $wpmcsItem->get_extras($source_id, 'original', $source_type);
623 - if(isset($original['source_path'])) {
624 - $source_paths[] = $original['source_path'];
636 +
637 + // If original_source_path is set, add it to source_paths.
638 + if(isset($item['original_source_path']) && !Utils::is_empty($item['original_source_path'])) {
639 + $source_paths[] = $item['original_source_path'];
625 640 }
626 641
627 642 foreach ( $source_paths as $source_path ) {
628 643 if ( ! empty( $paths[ $source_path ] ) ) {