Media Cleaner - Version 5.5.8

Version Description

  • Add: Support for Image Map Pro.
  • Add: Support for Directories.
  • Update: Code cleaning and a bit of refactoring.
  • Update: Cleaner references table with null values when needed.
  • Fix: Check if the filename exists in the trash for every new upload (and if yes, give it a different filename).
  • Fix: Avoid crash related to unserialization.
  • Fix: Ignore some other plugins' files which are not supposed to be scanned.
  • Info: This plugin is a lot of work. Please help me by giving it a nice review, here.
Download this release

Release Info

Developer TigrouMeow
Plugin Icon 128x128 Media Cleaner
Version 5.5.8
Comparing to
See all releases

Code changes from version 5.5.7 to 5.5.8

Files changed (7) hide show
  1. admin.php +0 -15
  2. core.php +61 -139
  3. media-cleaner.php +2 -2
  4. parsers/common.php +12 -8
  5. readme.txt +11 -2
  6. ui.php +5 -7
  7. views/menu-screen.php +6 -0
admin.php CHANGED
@@ -98,21 +98,6 @@ class Meow_WPMC_Admin extends MeowApps_Admin {
98
  add_settings_field( 'wpmc_live_content', __( 'Live Content<br />(Pro)', 'media-cleaner' ),
99
  array( $this, 'admin_live_content_callback' ),
100
  'wpmc_settings-menu', 'wpmc_settings' );
101
- // add_settings_field( 'wpmc_posts', __( 'Posts', 'media-cleaner' ),
102
- // array( $this, 'admin_posts_callback' ),
103
- // 'wpmc_settings-menu', 'wpmc_settings' );
104
- // add_settings_field( 'wpmc_postmeta', __( 'Post Meta', 'media-cleaner' ),
105
- // array( $this, 'admin_postmeta_callback' ),
106
- // 'wpmc_settings-menu', 'wpmc_settings' );
107
- // add_settings_field( 'wpmc_widgets', __( 'Widgets', 'media-cleaner' ),
108
- // array( $this, 'admin_widgets_callback' ),
109
- // 'wpmc_settings-menu', 'wpmc_settings' );
110
- // add_settings_field( 'wpmc_shortcode', __( 'Shortcodes<br />(Pro)', 'media-cleaner' ),
111
- // array( $this, 'admin_shortcode_callback' ),
112
- // 'wpmc_settings-menu', 'wpmc_settings' );
113
- // add_settings_field( 'wpmc_background', __( 'Background CSS<br />(Pro), 'media-cleaner' ),
114
- // array( $this, 'admin_background_callback' ),
115
- // 'wpmc_settings-menu', 'wpmc_settings' );
116
  add_settings_field( 'wpmc_debuglogs', __( 'Logs', 'media-cleaner' ),
117
  array( $this, 'admin_debuglogs_callback' ),
118
  'wpmc_settings-menu', 'wpmc_settings', array( __( 'Enable', 'media-cleaner' ) ) );
98
  add_settings_field( 'wpmc_live_content', __( 'Live Content<br />(Pro)', 'media-cleaner' ),
99
  array( $this, 'admin_live_content_callback' ),
100
  'wpmc_settings-menu', 'wpmc_settings' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  add_settings_field( 'wpmc_debuglogs', __( 'Logs', 'media-cleaner' ),
102
  array( $this, 'admin_debuglogs_callback' ),
103
  'wpmc_settings-menu', 'wpmc_settings', array( __( 'Enable', 'media-cleaner' ) ) );
core.php CHANGED
@@ -3,19 +3,16 @@
3
  class Meow_WPMC_Core {
4
 
5
  public $admin = null;
6
- public $last_analysis = null; //TODO: Is it actually used?
7
  public $engine = null;
8
  public $catch_timeout = true; // This will halt the plugin before reaching the PHP timeout.
9
  private $regex_file = '/[A-Za-z0-9-_,.\(\)\s]+[.]{1}(MIMETYPES)/';
 
10
  public $current_method = 'media';
11
  private $refcache = array();
12
  public $servername = null;
13
  public $upload_folder = null;
14
  public $contentDir = null; // becomes 'wp-content/uploads'
15
  private $check_content = null;
16
- private $check_postmeta = null;
17
- private $check_posts = null;
18
- private $check_widgets = null;
19
  private $debug_logs = null;
20
  public $site_url = null;
21
 
@@ -23,25 +20,15 @@ class Meow_WPMC_Core {
23
  $this->admin = $admin;
24
  $this->site_url = get_site_url();
25
  $this->current_method = get_option( 'wpmc_method', 'media' );
26
- $types = "jpg|jpeg|jpe|gif|png|tiff|bmp|csv|pdf|xls|xlsx|doc|docx|odt|wpd|rtf|tiff|mp3|mp4|wav|lua";
27
- $this->regex_file = str_replace( "MIMETYPES", $types, $this->regex_file );
28
  $this->servername = str_replace( 'http://', '', str_replace( 'https://', '', $this->site_url ) );
29
  $this->upload_folder = wp_upload_dir();
30
  $this->contentDir = substr( $this->upload_folder['baseurl'], 1 + strlen( $this->site_url ) );
31
-
32
  $this->check_content = get_option( 'wpmc_content', true );
33
- $this->check_postmeta = get_option( 'wpmc_postmeta', false );
34
- $this->check_posts = get_option( 'wpmc_posts', false );
35
- $this->check_widgets = get_option( 'wpmc_widgets', false );
36
-
37
- if ( $this->check_postmeta || $this->check_posts || $this->check_widgets ) {
38
- delete_option( 'wpmc_postmeta' );
39
- delete_option( 'wpmc_posts' );
40
- delete_option( 'wpmc_widgets' );
41
- }
42
-
43
  $this->debug_logs = get_option( 'wpmc_debuglogs', false );
 
44
  add_action( 'wpmc_initialize_parsers', array( $this, 'initialize_parsers' ), 10, 0 );
 
45
 
46
  require __DIR__ . '/engine.php';
47
  require __DIR__ . '/ui.php';
@@ -119,6 +106,23 @@ class Meow_WPMC_Core {
119
  $this->item_scan_avg_time = ceil( ( $this->time_elapsed / $this->items_checked ) * 10 ) / 10;
120
  }
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  function array_to_ids_or_urls( &$meta, &$ids, &$urls ) {
123
  foreach ( $meta as $k => $m ) {
124
  if ( is_numeric( $m ) ) {
@@ -399,14 +403,14 @@ class Meow_WPMC_Core {
399
  function recover_file( $path ) {
400
  $originalPath = trailingslashit( $this->upload_folder['basedir'] ) . $path;
401
  $trashPath = trailingslashit( $this->get_trashdir() ) . $path;
402
- $path_parts = pathinfo( $originalPath );
403
- if ( !file_exists( $path_parts['dirname'] ) && !wp_mkdir_p( $path_parts['dirname'] ) ) {
404
- die( 'Failed to create folder.' );
405
- }
406
  if ( !file_exists( $trashPath ) ) {
407
  $this->log( "The file $originalPath actually does not exist in the trash." );
408
  return true;
409
  }
 
 
 
 
410
  if ( !rename( $trashPath, $originalPath ) ) {
411
  die( 'Failed to move the file.' );
412
  }
@@ -428,12 +432,12 @@ class Meow_WPMC_Core {
428
  // Media
429
  else if ( $issue->type == 1 ) {
430
 
431
- // DEBUG: Seems useless, but there was this condition before
432
- // $fullpath = get_attached_file( $issue->postId );
433
- // if ( empty( $fullpath ) ) {
434
- // error_log( "Media {$issue->postId} does not have attached file anymore." );
435
- // return false;
436
- // }
437
 
438
  $paths = $this->get_paths_from_attachment( $issue->postId );
439
  foreach ( $paths as $path ) {
@@ -451,7 +455,6 @@ class Meow_WPMC_Core {
451
  }
452
 
453
  function trash_file( $fileIssuePath ) {
454
- global $wpdb;
455
  $originalPath = trailingslashit( $this->upload_folder['basedir'] ) . $fileIssuePath;
456
  $trashPath = trailingslashit( $this->get_trashdir() ) . $fileIssuePath;
457
  $path_parts = pathinfo( $trashPath );
@@ -609,37 +612,26 @@ class Meow_WPMC_Core {
609
  private $cached_ids = array();
610
  private $cached_urls = array();
611
 
 
 
612
  private function add_reference( $id, $url, $type, $origin = null, $extra = null ) {
613
- // The references are actually not being added directly in the DB, they are being pushed
614
- // into a cache ($this->refcache).
615
  if ( !empty( $id ) ) {
616
- if ( !in_array( $id, $this->cached_ids ) )
617
  array_push( $this->cached_ids, $id );
618
- else
619
- return;
620
  }
621
  if ( !empty( $url ) ) {
622
  // The URL shouldn't contain http, https, javascript at the beginning (and there are probably many more cases)
623
  // The URL must be cleaned before being passed as a reference.
624
- if ( substr( $url, 0, 5 ) === "http:" )
625
- return;
626
- if ( substr( $url, 0, 6 ) === "https:" )
627
  return;
628
- if ( substr( $url, 0, 11 ) === "javascript:" )
629
- return;
630
- if ( !in_array( $url, $this->cached_urls ) )
631
  array_push( $this->cached_urls, $url );
632
- else
633
- return;
634
  }
635
- //
636
- array_push( $this->refcache, array( 'id' => $id, 'url' => $url, 'type' => $type, 'origin' => $origin ) );
637
-
638
- // Without cache, the code would be this.
639
- // $wpdb->insert( $table_name,
640
- // array(
641
- // 'time' => current_time('mysql'), 'mediaId' => $id, 'mediaUrl' => $url, 'origin' => $origin, 'originType' => $type )
642
- // );
643
  }
644
 
645
  // The cache containing the references is wrote to the DB.
@@ -649,15 +641,21 @@ class Meow_WPMC_Core {
649
  $values = array();
650
  $place_holders = array();
651
  $query = "INSERT INTO $table (mediaId, mediaUrl, originType) VALUES ";
652
- foreach( $this->refcache as $key => $value ) {
653
- array_push( $values, $value['id'], $value['url'], $value['type'] );
654
- if ( $this->debug_logs ) {
655
- if ( !empty( $value['id'] ) )
 
656
  $this->log( "* {$value['type']}: Media #{$value['id']}" );
657
- if ( !empty( $value['url'] ) )
 
 
 
 
 
658
  $this->log( "* {$value['type']}: {$value['url']}" );
 
659
  }
660
- $place_holders[] = "('%d','%s','%s')";
661
  }
662
  if ( !empty( $values ) ) {
663
  $query .= implode( ', ', $place_holders );
@@ -793,17 +791,15 @@ class Meow_WPMC_Core {
793
  if ( !empty( $mediaId ) ) {
794
  $row = $wpdb->get_row( $wpdb->prepare( "SELECT originType FROM $table WHERE mediaId = %d", $mediaId ) );
795
  if ( !empty( $row ) ) {
796
- $this->last_analysis = $row->originType;
797
  $this->log( "OK! Media #{$mediaId} used by {$row->originType}" );
798
- return true;
799
  }
800
  }
801
  if ( !empty( $file ) ) {
802
  $row = $wpdb->get_row( $wpdb->prepare( "SELECT originType FROM $table WHERE mediaUrl = %s", $file ) );
803
  if ( !empty( $row ) ) {
804
- $this->last_analysis = $row->originType;
805
  $this->log( "OK! File {$file} used by {$row->originType}" );
806
- return true;
807
  }
808
  }
809
  return false;
@@ -812,6 +808,10 @@ class Meow_WPMC_Core {
812
  function get_paths_from_attachment( $attachmentId ) {
813
  $paths = array();
814
  $fullpath = get_attached_file( $attachmentId );
 
 
 
 
815
  $mainfile = $this->clean_uploaded_filename( $fullpath );
816
  array_push( $paths, $mainfile );
817
  $baseUp = pathinfo( $mainfile );
@@ -877,83 +877,6 @@ class Meow_WPMC_Core {
877
  return false;
878
  }
879
 
880
- // DEBUG: A new check_media function was written (2020/02), which is faster
881
- // and more optimized - but it's better to keep this one just as a reference in case of issue.
882
- // function check_media( $attachmentId, $checkOnly = false ) {
883
- // $this->last_analysis = "N/A";
884
-
885
- // // Is it an image?
886
- // $meta = wp_get_attachment_metadata( $attachmentId );
887
- // $isImage = isset( $meta, $meta['width'], $meta['height'] );
888
-
889
- // // Get the main file
890
- // global $wpdb;
891
- // $fullpath = get_attached_file( $attachmentId );
892
- // $mainfile = $this->clean_uploaded_filename( $fullpath );
893
- // $baseUp = pathinfo( $mainfile );
894
- // $baseUp = $baseUp['dirname'];
895
-
896
- // $size = 0;
897
- // $countfiles = 0;
898
- // $issue = 'NO_CONTENT';
899
- // if ( file_exists( $fullpath ) ) {
900
-
901
- // // Special scan: Broken only!
902
- // if ( !$this->check_content && !$this->check_postmeta && !$this->check_posts && !$this->check_widgets )
903
- // return true;
904
-
905
- // $size = filesize( $fullpath );
906
-
907
- // // Analysis
908
- // $this->last_analysis = "NONE";
909
- // $this->log( "Checking Media #{$attachmentId}: {$mainfile}" );
910
- // if ( $this->check_is_ignore( $mainfile, $attachmentId ) ) {
911
- // $this->last_analysis = "IGNORED";
912
- // return true;
913
- // }
914
- // if ( $this->reference_exists( $mainfile, $attachmentId ) )
915
- // return true;
916
-
917
- // // If images, check the other files as well
918
- // $countfiles = 0;
919
- // $sizes = $this->get_image_sizes();
920
- // if ( $isImage && isset( $meta['sizes'] ) ) {
921
- // foreach ( $meta['sizes'] as $name => $attr ) {
922
- // if ( isset( $attr['file'] ) ) {
923
- // $filepath = $this->upload_folder['basedir'];
924
- // $filepath = trailingslashit( $filepath ) . trailingslashit( $baseUp ) . $attr['file'];
925
- // if ( file_exists( $filepath ) )
926
- // $size += filesize( $filepath );
927
- // $file = $this->clean_uploaded_filename( $filepath );
928
- // $countfiles++;
929
- // // Analysis
930
- // $this->log( "Checking Media #{$attachmentId}: {$file}" );
931
- // if ( $this->reference_exists( $file, $attachmentId ) )
932
- // return true;
933
- // }
934
- // }
935
- // }
936
- // } else {
937
- // $this->log( "File {$fullpath} does not exist." );
938
- // $issue = 'ORPHAN_MEDIA';
939
- // }
940
-
941
- // if ( !$checkOnly ) {
942
- // $table_name = $wpdb->prefix . "mclean_scan";
943
- // $wpdb->insert( $table_name,
944
- // array(
945
- // 'time' => current_time('mysql'),
946
- // 'type' => 1,
947
- // 'size' => $size,
948
- // 'path' => $mainfile . ( $countfiles > 0 ? ( " (+ " . $countfiles . " files)" ) : "" ),
949
- // 'postId' => $attachmentId,
950
- // 'issue' => $issue
951
- // )
952
- // );
953
- // }
954
- // return false;
955
- // }
956
-
957
  // Delete all issues
958
  function reset_issues( $includingIgnored = false ) {
959
  global $wpdb;
@@ -993,7 +916,6 @@ class Meow_WPMC_Core {
993
  }
994
  }
995
 
996
-
997
  /*
998
  INSTALL / UNINSTALL
999
  */
@@ -1045,8 +967,8 @@ function wpmc_create_database() {
1045
  $sql = "CREATE TABLE $table_name (
1046
  id BIGINT(20) NOT NULL AUTO_INCREMENT,
1047
  mediaId BIGINT(20) NULL,
1048
- mediaUrl VARBINARY(256) NULL,
1049
- originType VARBINARY(32) NOT NULL,
1050
  PRIMARY KEY (id)
1051
  ) " . $charset_collate . ";";
1052
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
3
  class Meow_WPMC_Core {
4
 
5
  public $admin = null;
 
6
  public $engine = null;
7
  public $catch_timeout = true; // This will halt the plugin before reaching the PHP timeout.
8
  private $regex_file = '/[A-Za-z0-9-_,.\(\)\s]+[.]{1}(MIMETYPES)/';
9
+ private $types = "jpg|jpeg|jpe|gif|png|tiff|bmp|csv|pdf|xls|xlsx|doc|docx|odt|wpd|rtf|tiff|mp3|mp4|wav|lua";
10
  public $current_method = 'media';
11
  private $refcache = array();
12
  public $servername = null;
13
  public $upload_folder = null;
14
  public $contentDir = null; // becomes 'wp-content/uploads'
15
  private $check_content = null;
 
 
 
16
  private $debug_logs = null;
17
  public $site_url = null;
18
 
20
  $this->admin = $admin;
21
  $this->site_url = get_site_url();
22
  $this->current_method = get_option( 'wpmc_method', 'media' );
23
+ $this->regex_file = str_replace( "MIMETYPES", $this->types, $this->regex_file );
 
24
  $this->servername = str_replace( 'http://', '', str_replace( 'https://', '', $this->site_url ) );
25
  $this->upload_folder = wp_upload_dir();
26
  $this->contentDir = substr( $this->upload_folder['baseurl'], 1 + strlen( $this->site_url ) );
 
27
  $this->check_content = get_option( 'wpmc_content', true );
 
 
 
 
 
 
 
 
 
 
28
  $this->debug_logs = get_option( 'wpmc_debuglogs', false );
29
+
30
  add_action( 'wpmc_initialize_parsers', array( $this, 'initialize_parsers' ), 10, 0 );
31
+ add_filter( 'wp_unique_filename', array( $this, 'wp_unique_filename' ), 10, 3 );
32
 
33
  require __DIR__ . '/engine.php';
34
  require __DIR__ . '/ui.php';
106
  $this->item_scan_avg_time = ceil( ( $this->time_elapsed / $this->items_checked ) * 10 ) / 10;
107
  }
108
 
109
+ // This checks if a new uploaded filename isn't the same one as a currently
110
+ // filename in the trash (that would cause issues)
111
+ function wp_unique_filename( $filename, $ext, $dir ) {
112
+ $fullpath = trailingslashit( $dir ) . $filename;
113
+ $relativepath = $this->clean_uploaded_filename( $fullpath );
114
+ $trashfilepath = trailingslashit( $this->get_trashdir() ) . $relativepath;
115
+ if ( file_exists( $trashfilepath ) ) {
116
+ $path_parts = pathinfo( $fullpath );
117
+ $filename_noext = $path_parts['filename'];
118
+ $new_filename = $filename_noext . '-' . date('Ymd-His', time()) . '.' . $path_parts['extension'];
119
+ //error_log( 'POTENTIALLY TRASH PATH: ' . $trashfilepath );
120
+ //error_log( 'POTENTIALLY NEW FILE: ' . $new_filename );
121
+ return $new_filename;
122
+ }
123
+ return $filename;
124
+ }
125
+
126
  function array_to_ids_or_urls( &$meta, &$ids, &$urls ) {
127
  foreach ( $meta as $k => $m ) {
128
  if ( is_numeric( $m ) ) {
403
  function recover_file( $path ) {
404
  $originalPath = trailingslashit( $this->upload_folder['basedir'] ) . $path;
405
  $trashPath = trailingslashit( $this->get_trashdir() ) . $path;
 
 
 
 
406
  if ( !file_exists( $trashPath ) ) {
407
  $this->log( "The file $originalPath actually does not exist in the trash." );
408
  return true;
409
  }
410
+ $path_parts = pathinfo( $originalPath );
411
+ if ( !file_exists( $path_parts['dirname'] ) && !wp_mkdir_p( $path_parts['dirname'] ) ) {
412
+ die( 'Failed to create folder.' );
413
+ }
414
  if ( !rename( $trashPath, $originalPath ) ) {
415
  die( 'Failed to move the file.' );
416
  }
432
  // Media
433
  else if ( $issue->type == 1 ) {
434
 
435
+ // If there is no file attached, doesn't handle the files
436
+ $fullpath = get_attached_file( $issue->postId );
437
+ if ( empty( $fullpath ) ) {
438
+ error_log( "Media {$issue->postId} does not have attached file anymore." );
439
+ return false;
440
+ }
441
 
442
  $paths = $this->get_paths_from_attachment( $issue->postId );
443
  foreach ( $paths as $path ) {
455
  }
456
 
457
  function trash_file( $fileIssuePath ) {
 
458
  $originalPath = trailingslashit( $this->upload_folder['basedir'] ) . $fileIssuePath;
459
  $trashPath = trailingslashit( $this->get_trashdir() ) . $fileIssuePath;
460
  $path_parts = pathinfo( $trashPath );
612
  private $cached_ids = array();
613
  private $cached_urls = array();
614
 
615
+ // The references are actually not being added directly in the DB, they are being pushed
616
+ // into a cache ($this->refcache).
617
  private function add_reference( $id, $url, $type, $origin = null, $extra = null ) {
 
 
618
  if ( !empty( $id ) ) {
619
+ if ( !in_array( $id, $this->cached_ids ) ) {
620
  array_push( $this->cached_ids, $id );
621
+ array_push( $this->refcache, array( 'id' => $id, 'url' => null, 'type' => $type, 'origin' => $origin ) );
622
+ }
623
  }
624
  if ( !empty( $url ) ) {
625
  // The URL shouldn't contain http, https, javascript at the beginning (and there are probably many more cases)
626
  // The URL must be cleaned before being passed as a reference.
627
+ if ( substr( $url, 0, 5 ) === "http:" || substr( $url, 0, 6 ) === "https:" || substr( $url, 0, 11 ) === "javascript:" ) {
 
 
628
  return;
629
+ }
630
+ if ( !in_array( $url, $this->cached_urls ) ) {
 
631
  array_push( $this->cached_urls, $url );
632
+ array_push( $this->refcache, array( 'id' => null, 'url' => $url, 'type' => $type, 'origin' => $origin ) );
633
+ }
634
  }
 
 
 
 
 
 
 
 
635
  }
636
 
637
  // The cache containing the references is wrote to the DB.
641
  $values = array();
642
  $place_holders = array();
643
  $query = "INSERT INTO $table (mediaId, mediaUrl, originType) VALUES ";
644
+ foreach ( $this->refcache as $value ) {
645
+ if ( !is_null( $value['id'] ) ) {
646
+ array_push( $values, $value['id'], $value['type'] );
647
+ $place_holders[] = "('%d',NULL,'%s')";
648
+ if ( $this->debug_logs ) {
649
  $this->log( "* {$value['type']}: Media #{$value['id']}" );
650
+ }
651
+ }
652
+ else if ( !is_null( $value['url'] ) ) {
653
+ array_push( $values, $value['url'], $value['type'] );
654
+ $place_holders[] = "(NULL,'%s','%s')";
655
+ if ( $this->debug_logs ) {
656
  $this->log( "* {$value['type']}: {$value['url']}" );
657
+ }
658
  }
 
659
  }
660
  if ( !empty( $values ) ) {
661
  $query .= implode( ', ', $place_holders );
791
  if ( !empty( $mediaId ) ) {
792
  $row = $wpdb->get_row( $wpdb->prepare( "SELECT originType FROM $table WHERE mediaId = %d", $mediaId ) );
793
  if ( !empty( $row ) ) {
 
794
  $this->log( "OK! Media #{$mediaId} used by {$row->originType}" );
795
+ return $row->originType;
796
  }
797
  }
798
  if ( !empty( $file ) ) {
799
  $row = $wpdb->get_row( $wpdb->prepare( "SELECT originType FROM $table WHERE mediaUrl = %s", $file ) );
800
  if ( !empty( $row ) ) {
 
801
  $this->log( "OK! File {$file} used by {$row->originType}" );
802
+ return $row->originType;
803
  }
804
  }
805
  return false;
808
  function get_paths_from_attachment( $attachmentId ) {
809
  $paths = array();
810
  $fullpath = get_attached_file( $attachmentId );
811
+ if ( empty( $fullpath ) ) {
812
+ error_log( 'Media Cleaner: Could not find attached file for Media ID ' . $attachmentId );
813
+ return array();
814
+ }
815
  $mainfile = $this->clean_uploaded_filename( $fullpath );
816
  array_push( $paths, $mainfile );
817
  $baseUp = pathinfo( $mainfile );
877
  return false;
878
  }
879
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
880
  // Delete all issues
881
  function reset_issues( $includingIgnored = false ) {
882
  global $wpdb;
916
  }
917
  }
918
 
 
919
  /*
920
  INSTALL / UNINSTALL
921
  */
967
  $sql = "CREATE TABLE $table_name (
968
  id BIGINT(20) NOT NULL AUTO_INCREMENT,
969
  mediaId BIGINT(20) NULL,
970
+ mediaUrl TINYTEXT NULL,
971
+ originType TINYTEXT NOT NULL,
972
  PRIMARY KEY (id)
973
  ) " . $charset_collate . ";";
974
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
media-cleaner.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Media Cleaner
4
  Plugin URI: https://meowapps.com
5
  Description: Clean your Media Library, many options, trash system.
6
- Version: 5.5.7
7
  Author: Jordy Meow
8
  Author URI: https://meowapps.com
9
  Text Domain: media-cleaner
@@ -25,7 +25,7 @@ if ( is_admin() ) {
25
 
26
  global $wpmc_version;
27
  global $wpmc;
28
- $wpmc_version = '5.5.7';
29
 
30
  require __DIR__ . '/admin.php';
31
  require __DIR__ . '/core.php';
3
  Plugin Name: Media Cleaner
4
  Plugin URI: https://meowapps.com
5
  Description: Clean your Media Library, many options, trash system.
6
+ Version: 5.5.8
7
  Author: Jordy Meow
8
  Author URI: https://meowapps.com
9
  Text Domain: media-cleaner
25
 
26
  global $wpmc_version;
27
  global $wpmc;
28
+ $wpmc_version = '5.5.8';
29
 
30
  require __DIR__ . '/admin.php';
31
  require __DIR__ . '/core.php';
parsers/common.php CHANGED
@@ -149,15 +149,19 @@ SQL;
149
  array_push( $postmeta_images_ids, $meta );
150
  continue;
151
  }
152
- $decoded = @unserialize( $meta );
153
- if ( is_array( $decoded ) ) {
154
- $wpmc->array_to_ids_or_urls( $decoded, $postmeta_images_ids, $postmeta_images_urls );
155
- continue;
 
 
156
  }
157
- $exploded = explode( ',', $meta );
158
- if ( is_array( $exploded ) ) {
159
- $wpmc->array_to_ids_or_urls( $exploded, $postmeta_images_ids, $postmeta_images_urls );
160
- continue;
 
 
161
  }
162
  }
163
  $wpmc->add_reference_id( $postmeta_images_ids, 'META (ID)' );
149
  array_push( $postmeta_images_ids, $meta );
150
  continue;
151
  }
152
+ else if ( is_serialized( $meta ) ) {
153
+ $decoded = @unserialize( $meta );
154
+ if ( is_array( $decoded ) ) {
155
+ $wpmc->array_to_ids_or_urls( $decoded, $postmeta_images_ids, $postmeta_images_urls );
156
+ continue;
157
+ }
158
  }
159
+ else {
160
+ $exploded = explode( ',', $meta );
161
+ if ( is_array( $exploded ) ) {
162
+ $wpmc->array_to_ids_or_urls( $exploded, $postmeta_images_ids, $postmeta_images_urls );
163
+ continue;
164
+ }
165
  }
166
  }
167
  $wpmc->add_reference_id( $postmeta_images_ids, 'META (ID)' );
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: https://commerce.coinbase.com/checkout/d047546a-77a8-41c8-9ea9-4a95
5
  Requires at least: 4.8
6
  Tested up to: 5.3
7
  Requires PHP: 7.0
8
- Stable tag: 5.5.7
9
 
10
  Clean your WordPress from unused or broken media and files. It has its own trash system and recovery features. Please read the description.
11
 
@@ -74,6 +74,16 @@ Better to be safe than sorry. This plugin deletes files! Therefore, backup is no
74
 
75
  == Changelog ==
76
 
 
 
 
 
 
 
 
 
 
 
77
  = 5.5.7 =
78
  * Update: UI improved in many ways, I hope you will love it more!
79
  * Add: Filter by issue, and allow to delete those specific issues.
@@ -84,7 +94,6 @@ Better to be safe than sorry. This plugin deletes files! Therefore, backup is no
84
  * Update: Better support for Revolution Slider.
85
  * Update: Added additional checks for DOM parser and check if the DOM module is loaded.
86
  * Fix: 100% of the code was checked and a few tiny issues were fixed here and there.
87
- * Info: This plugin is a lot of work. Please help me by giving it a nice review, [here](https://wordpress.org/support/plugin/media-cleaner/reviews/?rate=5#new-post). At the same time, I would love to know if you would prefer the results to be refreshed automatically instead of having to click on refresh. Thank you :)
88
 
89
  = 5.5.4 =
90
  * Update: Creates the DB tables automatically.
5
  Requires at least: 4.8
6
  Tested up to: 5.3
7
  Requires PHP: 7.0
8
+ Stable tag: 5.5.8
9
 
10
  Clean your WordPress from unused or broken media and files. It has its own trash system and recovery features. Please read the description.
11
 
74
 
75
  == Changelog ==
76
 
77
+ = 5.5.8 =
78
+ * Add: Support for Image Map Pro.
79
+ * Add: Support for Directories.
80
+ * Update: Code cleaning and a bit of refactoring.
81
+ * Update: Cleaner references table with null values when needed.
82
+ * Fix: Check if the filename exists in the trash for every new upload (and if yes, give it a different filename).
83
+ * Fix: Avoid crash related to unserialization.
84
+ * Fix: Ignore some other plugins' files which are not supposed to be scanned.
85
+ * Info: This plugin is a lot of work. Please help me by giving it a nice review, [here](https://wordpress.org/support/plugin/media-cleaner/reviews/?rate=5#new-post).
86
+
87
  = 5.5.7 =
88
  * Update: UI improved in many ways, I hope you will love it more!
89
  * Add: Filter by issue, and allow to delete those specific issues.
94
  * Update: Better support for Revolution Slider.
95
  * Update: Added additional checks for DOM parser and check if the DOM module is loaded.
96
  * Fix: 100% of the code was checked and a few tiny issues were fixed here and there.
 
97
 
98
  = 5.5.4 =
99
  * Update: Creates the DB tables automatically.
ui.php CHANGED
@@ -122,14 +122,12 @@ class Meow_WPMC_UI {
122
  }
123
 
124
  function display_metabox( $post ) {
125
- $this->core->log( "Media Edit > Checking Media #{$post->ID}" );
126
- $success = $this->core->check_media( $post->ID, true );
127
- $this->core->log( "Success $success\n" );
128
- if ( $success ) {
129
- if ( array_key_exists( $this->core->last_analysis, $this->foundTypes ) )
130
- echo $this->foundTypes[ $this->core->last_analysis ];
131
  else
132
- echo "It seems to be used as: " . $this->core->last_analysis;
133
  }
134
  else {
135
  echo "Doesn't seem to be used.";
122
  }
123
 
124
  function display_metabox( $post ) {
125
+ $originType = $this->core->reference_exists( null, $post->ID );
126
+ if ( $originType ) {
127
+ if ( array_key_exists( $originType, $this->foundTypes ) )
128
+ echo $this->foundTypes[ $originType ];
 
 
129
  else
130
+ echo "It seems to be used as: " . $originType;
131
  }
132
  else {
133
  echo "Doesn't seem to be used.";
views/menu-screen.php CHANGED
@@ -229,6 +229,12 @@
229
  if ( class_exists( 'YIKES_Custom_Product_Tabs' ) )
230
  array_push( $unsupported, 'Yikes Custom Product Tabs' );
231
 
 
 
 
 
 
 
232
  if ( !empty( $unsupported ) ) {
233
  echo "<div class='notice notice-error'><p>";
234
  _e( "<b>Important note about the following plugin(s): </b>", 'media-cleaner' );
229
  if ( class_exists( 'YIKES_Custom_Product_Tabs' ) )
230
  array_push( $unsupported, 'Yikes Custom Product Tabs' );
231
 
232
+ if ( function_exists( 'drts' ) )
233
+ array_push( $unsupported, 'Directories' );
234
+
235
+ if ( class_exists( 'ImageMapPro' ) )
236
+ array_push( $unsupported, 'Image Map Pro' );
237
+
238
  if ( !empty( $unsupported ) ) {
239
  echo "<div class='notice notice-error'><p>";
240
  _e( "<b>Important note about the following plugin(s): </b>", 'media-cleaner' );