Media File Renamer - Version 4.2.4

Version Description

  • Update: UTF-8 is handled by default, no need to have an option for it.
  • Add: Option for transliteration (cyrillic, accents, umlauts).
  • Note: If you like it, please review the plugin here: https://wordpress.org/support/plugin/media-file-renamer/reviews/?rate=5#new-post. It's important for us :) Thank you!
Download this release

Release Info

Developer TigrouMeow
Plugin Icon 128x128 Media File Renamer
Version 4.2.4
Comparing to
See all releases

Code changes from version 4.2.2 to 4.2.4

Files changed (10) hide show
  1. api.php +78 -0
  2. common/admin.css +61 -1
  3. common/admin.php +1 -3
  4. core.php +103 -34
  5. media-file-renamer.php +4 -3
  6. mfrh_admin.php +14 -14
  7. readme.txt +7 -4
  8. ui.php +4 -4
  9. views/column.php +2 -2
  10. views/menu-screen.php +2 -2
api.php CHANGED
@@ -18,6 +18,84 @@ function mfrh_move( $mediaId, $newPath ) {
18
  return $mfrh_core->move( $mediaId, $newPath );
19
  }
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  /**
22
  *
23
  * TESTS
18
  return $mfrh_core->move( $mediaId, $newPath );
19
  }
20
 
21
+ /**
22
+ * Calls the specified mb_*** function if it is available.
23
+ * If it isn't, calls the regular function instead
24
+ * @param string $fn The function name to call
25
+ * @return mixed
26
+ */
27
+ function mfrh_mb($fn) {
28
+ static $available = null;
29
+ if ( is_null($available) ) $available = extension_loaded( 'mbstring' );
30
+
31
+ if ( func_num_args() > 1 ) {
32
+ $args = func_get_args();
33
+ array_shift( $args ); // Remove 1st arg
34
+ return $available ?
35
+ call_user_func_array( "mb_{$fn}", $args ) :
36
+ call_user_func_array( $fn, $args );
37
+ }
38
+ return $available ?
39
+ call_user_func( "mb_{$fn}" ) :
40
+ call_user_func( $fn );
41
+ }
42
+
43
+ /**
44
+ * A multibyte compatible implementation of pathinfo()
45
+ * @param string $path
46
+ * @param int $options
47
+ * @return string|array
48
+ */
49
+ function mfrh_pathinfo( $path, $options = null ) {
50
+ if ( is_null( $options ) ) {
51
+ $r = array ();
52
+ if ( $x = mfrh_pathinfo( $path, PATHINFO_DIRNAME ) ) $r['dirname'] = $x;
53
+ $r['basename'] = mfrh_pathinfo( $path, PATHINFO_BASENAME );
54
+ if ( $x = mfrh_pathinfo( $path, PATHINFO_EXTENSION ) ) $r['extension'] = $x;
55
+ $r['filename'] = mfrh_pathinfo( $path, PATHINFO_FILENAME );
56
+ return $r;
57
+ }
58
+ if ( !$path ) return '';
59
+ $path = rtrim( $path, DIRECTORY_SEPARATOR );
60
+ switch ( $options ) {
61
+ case PATHINFO_DIRNAME:
62
+ $x = mfrh_mb( 'strrpos', $path, DIRECTORY_SEPARATOR ); // The last occurrence of slash
63
+ return is_int($x) ? mfrh_mb( 'substr', $path, 0, $x ) : '.';
64
+
65
+ case PATHINFO_BASENAME:
66
+ $x = mfrh_mb( 'strrpos', $path, DIRECTORY_SEPARATOR ); // The last occurrence of slash
67
+ return is_int($x) ? mfrh_mb( 'substr', $path, $x + 1 ) : $path;
68
+
69
+ case PATHINFO_EXTENSION:
70
+ $x = mfrh_mb( 'strrpos', $path, '.' ); // The last occurrence of dot
71
+ return is_int($x) ? mfrh_mb( 'substr', $path, $x + 1 ) : '';
72
+
73
+ case PATHINFO_FILENAME:
74
+ $basename = mfrh_pathinfo( $path, PATHINFO_BASENAME );
75
+ $x = mfrh_mb( 'strrpos', $basename, '.' ); // The last occurrence of dot
76
+ return is_int($x) ? mfrh_mb( 'substr', $basename, 0, $x ) : $basename;
77
+ }
78
+ return pathinfo( $path, $options );
79
+ }
80
+
81
+ /**
82
+ * A multibyte compatible implementation of dirname()
83
+ * @param string $path
84
+ * @return string
85
+ */
86
+ function mfrh_dirname( $path ) {
87
+ return mfrh_pathinfo( $path, PATHINFO_DIRNAME );
88
+ }
89
+
90
+ /**
91
+ * A multibyte compatible implementation of basename()
92
+ * @param string $path
93
+ * @return string
94
+ */
95
+ function mfrh_basename( $path ) {
96
+ return mfrh_pathinfo( $path, PATHINFO_BASENAME );
97
+ }
98
+
99
  /**
100
  *
101
  * TESTS
common/admin.css CHANGED
@@ -1,4 +1,64 @@
1
- /* MEOW BOX (SETTINGS BOX) */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  .meow-box {
4
  box-sizing: border-box;
1
+ /* MEOW-TABS */
2
+
3
+ .meow-tabs {
4
+ display: flex;
5
+ flex-wrap: wrap;
6
+ box-sizing: border-box;
7
+ }
8
+
9
+ .meow-tabs * {
10
+ box-sizing: border-box;
11
+ }
12
+
13
+ .meow-tabs .meow-tabs-input {
14
+ position: absolute;
15
+ opacity: 0;
16
+ }
17
+
18
+ .meow-tabs .meow-tabs-label {
19
+ width: auto;
20
+ padding: 4px 12px;
21
+ background: #3c3c3c;
22
+ cursor: pointer;
23
+ font-weight: bold;
24
+ font-size: 13px;
25
+ text-transform: uppercase;
26
+ color: white;
27
+ transition: background 0.1s, color 0.1s;
28
+ }
29
+
30
+ .meow-tabs .inside {
31
+ display: none;
32
+ width: 100%;
33
+ }
34
+
35
+ .meow-tabs .meow-tabs-label:hover {
36
+ background: #36495f;
37
+ }
38
+
39
+ .meow-tabs .meow-tabs-label:active {
40
+ background: #3C82C7;
41
+ }
42
+
43
+ .meow-tabs .meow-tabs-input:focus + .meow-tabs-label {
44
+ box-shadow: inset 0px 0px 0px 3px #2aa1c0;
45
+ z-index: 1;
46
+ }
47
+
48
+ .meow-tabs .meow-tabs-input:checked + .meow-tabs-label {
49
+ background: #3C82C7 !important;
50
+ }
51
+
52
+ .meow-tabs-input:checked + .meow-tabs-label + .inside {
53
+ display: block;
54
+ order: 99;
55
+ }
56
+
57
+ .meow-tabs .inside {
58
+ background: #fff;
59
+ }
60
+
61
+ /* MEOW-BOX */
62
 
63
  .meow-box {
64
  box-sizing: border-box;
common/admin.php CHANGED
@@ -5,7 +5,7 @@ if ( !class_exists( 'MeowApps_Admin' ) ) {
5
  class MeowApps_Admin {
6
 
7
  public static $loaded = false;
8
- public static $admin_version = "1.4";
9
 
10
  public $prefix; // prefix used for actions, filters (mfrh)
11
  public $mainfile; // plugin main file (media-file-renamer.php)
@@ -154,8 +154,6 @@ if ( !class_exists( 'MeowApps_Admin' ) ) {
154
  if ( !empty( $this->prefix ) )
155
  $title = apply_filters( $this->prefix . '_plugin_title', $title );
156
  if ( $this->display_ads() ) {
157
- echo '<a class="meow-header-ad" target="_blank" href="http://www.shareasale.com/r.cfm?b=906810&u=767054&m=41388&urllink=&afftrack="">
158
- <img src="' . $this->common_url( 'img/wpengine.png' ) . '" height="60" border="0" /></a>';
159
  }
160
  ?>
161
  <h1 style="line-height: 16px;">
5
  class MeowApps_Admin {
6
 
7
  public static $loaded = false;
8
+ public static $admin_version = "1.6";
9
 
10
  public $prefix; // prefix used for actions, filters (mfrh)
11
  public $mainfile; // plugin main file (media-file-renamer.php)
154
  if ( !empty( $this->prefix ) )
155
  $title = apply_filters( $this->prefix . '_plugin_title', $title );
156
  if ( $this->display_ads() ) {
 
 
157
  }
158
  ?>
159
  <h1 style="line-height: 16px;">
core.php CHANGED
@@ -36,7 +36,7 @@ class Meow_MFRH_Core {
36
  // https://stackoverflow.com/questions/3964793/php-case-insensitive-version-of-file-exists
37
  static function sensitive_file_exists( $filename, $fullpath = true, $caseInsensitive = true ) {
38
  $output = false;
39
- $directoryName = dirname( $filename );
40
  $fileArray = glob( $directoryName . '/*', GLOB_NOSORT );
41
  $i = ( $caseInsensitive ) ? "i" : "";
42
 
@@ -152,7 +152,7 @@ SQL;
152
  function wp_handle_upload_prefilter( $file ) {
153
 
154
  $this->log( "** On Upload: " . $file['name'] );
155
- $pp = pathinfo( $file['name'] );
156
 
157
  // If everything's fine, renames in based on the Title in the EXIF
158
  $method = apply_filters( 'mfrh_method', 'media_title' );
@@ -182,7 +182,7 @@ SQL;
182
  add_filter( 'wp_read_image_metadata', array( $this, 'wp_read_image_metadata' ), 10, 2 );
183
 
184
  // Modify the filename
185
- $pp = pathinfo( $file['name'] );
186
  $file['name'] = $this->new_filename( null, $pp['basename'] );
187
  return $file;
188
  }
@@ -201,7 +201,7 @@ SQL;
201
  $id = $post['ID'];
202
  $old_filepath = get_attached_file( $id );
203
  $old_filepath = Meow_MFRH_Core::sensitive_file_exists( $old_filepath );
204
- $path_parts = pathinfo( $old_filepath );
205
  //print_r( $path_parts );
206
  $directory = $path_parts['dirname'];
207
  $old_filename = $path_parts['basename'];
@@ -391,16 +391,84 @@ SQL;
391
  *
392
  */
393
 
394
- static function replace_special_chars( $str ) {
395
- $special_chars = array(
396
- "å" => "a", "Å" => "a",
397
- "ä" => "ae", "Ä" => "ae",
398
- "ö" => "oe", "Ö" => "oe",
399
- "ü" => "ue", "Ü" => "ue",
400
- "ß" => "ss", "ẞ" => "ss"
401
- );
402
- foreach ( $special_chars as $key => $value )
403
- $str = str_replace( $key, $value, $str );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  return $str;
405
  }
406
 
@@ -423,14 +491,14 @@ SQL;
423
  if ( !empty( $media ) ) {
424
  // Media already exists (not a fresh upload). Gets filename and ext.
425
  $old_filepath = get_attached_file( $media['ID'] );
426
- $pp = pathinfo( $old_filepath );
427
  $new_ext = empty( $pp['extension'] ) ? "" : $pp['extension'];
428
  $old_filename = $pp['basename'];
429
  $old_filename_no_ext = $pp['filename'];
430
  }
431
  else {
432
  // It's an upload, let's check if the extension is provided in the text
433
- $pp = pathinfo( $text );
434
  $new_ext = empty( $pp['extension'] ) ? "" : $pp['extension'];
435
  $text = $pp['filename'];
436
  }
@@ -438,7 +506,7 @@ SQL;
438
  // Generate the new filename.
439
  if ( !empty( $manual_filename ) ) {
440
  // Filename is forced. Strip the extension. Keeps this extension in $new_ext.
441
- $pp = pathinfo( $manual_filename );
442
  $manual_filename = $pp['filename'];
443
  $new_ext = empty( $pp['extension'] ) ? $new_ext : $pp['extension'];
444
  $new_filename = $manual_filename;
@@ -448,17 +516,18 @@ SQL;
448
  $text = str_replace( ".jpg", "", $text );
449
  $text = str_replace( ".png", "", $text );
450
  $text = str_replace( "'", "-", $text );
451
- $text = strtolower( Meow_MFRH_Core::replace_chars( $text ) );
452
- $utf8_filename = apply_filters( 'mfrh_utf8', false );
453
- if ( $utf8_filename )
454
- $new_filename = sanitize_file_name( $text );
455
- else {
456
- // Remove non-ASCII characters
457
- $text = Meow_MFRH_Core::replace_special_chars( $text );
458
- $text = preg_replace( '/[[:^print:]]/', '', $text );
459
- $new_filename = str_replace( "%", "-", sanitize_title( $text ) );
460
- }
461
  }
 
 
 
 
 
 
 
 
 
462
  if ( empty( $new_filename ) )
463
  $new_filename = "empty";
464
 
@@ -533,7 +602,7 @@ SQL;
533
 
534
  // Prepare the variables
535
  $old_filepath = get_attached_file( $id );
536
- $path_parts = pathinfo( $old_filepath );
537
  $old_ext = $path_parts['extension'];
538
  $upload_dir = wp_upload_dir();
539
  $old_directory = trim( str_replace( $upload_dir['basedir'], '', $path_parts['dirname'] ), '/' ); // '2011/01'
@@ -542,11 +611,11 @@ SQL;
542
  $new_filepath = trailingslashit( trailingslashit( $upload_dir['basedir'] ) . $new_directory ) . $filename;
543
 
544
  $this->log( "** Move Media: " . $filename );
545
- $this->log( "The new directory will be: " . dirname( $new_filepath ) );
546
 
547
  // Create the directory if it does not exist
548
- if ( !file_exists( dirname( $new_filepath ) ) ) {
549
- mkdir( dirname( $new_filepath ), 0777, true );
550
  }
551
 
552
  // There is no support for UNDO (as the current process of Media File Renamer doesn't keep the path for the undo, only the filename... so the move breaks this - let's deal with this later).
@@ -688,7 +757,7 @@ SQL;
688
  $new_filepath = $output['desired_filepath'];
689
  $new_filename = $output['desired_filename'];
690
  $manual = $output['manual'] || !empty( $manual_filename );
691
- $path_parts = pathinfo( $old_filepath );
692
  $directory = $path_parts['dirname']; // '2011/01'
693
  $old_filename = $path_parts['basename']; // 'whatever.jpeg'
694
 
@@ -722,7 +791,7 @@ SQL;
722
  $old_ext = $path_parts['extension'];
723
  $new_ext = $old_ext;
724
  if ( $manual_filename ) {
725
- $pp = pathinfo( $manual_filename );
726
  $new_ext = $pp['extension'];
727
  }
728
 
@@ -840,7 +909,7 @@ SQL;
840
  // Rename slug/permalink
841
  if ( get_option( "mfrh_rename_slug" ) ) {
842
  $oldslug = $post['post_name'];
843
- $info = pathinfo( $new_filepath );
844
  $newslug = preg_replace( '/\\.[^.\\s]{3,4}$/', '', $info['basename'] );
845
  $post['post_name'] = $newslug;
846
  if ( wp_update_post( $post ) )
36
  // https://stackoverflow.com/questions/3964793/php-case-insensitive-version-of-file-exists
37
  static function sensitive_file_exists( $filename, $fullpath = true, $caseInsensitive = true ) {
38
  $output = false;
39
+ $directoryName = mfrh_dirname( $filename );
40
  $fileArray = glob( $directoryName . '/*', GLOB_NOSORT );
41
  $i = ( $caseInsensitive ) ? "i" : "";
42
 
152
  function wp_handle_upload_prefilter( $file ) {
153
 
154
  $this->log( "** On Upload: " . $file['name'] );
155
+ $pp = mfrh_pathinfo( $file['name'] );
156
 
157
  // If everything's fine, renames in based on the Title in the EXIF
158
  $method = apply_filters( 'mfrh_method', 'media_title' );
182
  add_filter( 'wp_read_image_metadata', array( $this, 'wp_read_image_metadata' ), 10, 2 );
183
 
184
  // Modify the filename
185
+ $pp = mfrh_pathinfo( $file['name'] );
186
  $file['name'] = $this->new_filename( null, $pp['basename'] );
187
  return $file;
188
  }
201
  $id = $post['ID'];
202
  $old_filepath = get_attached_file( $id );
203
  $old_filepath = Meow_MFRH_Core::sensitive_file_exists( $old_filepath );
204
+ $path_parts = mfrh_pathinfo( $old_filepath );
205
  //print_r( $path_parts );
206
  $directory = $path_parts['dirname'];
207
  $old_filename = $path_parts['basename'];
391
  *
392
  */
393
 
394
+ /**
395
+ * Performs transliteration
396
+ * @param string $str The string to transliterate
397
+ * @return string
398
+ */
399
+ function transliterate( $str ) {
400
+ // Conversion table
401
+ static $chars = null;
402
+
403
+ if ( is_null($chars) ) {
404
+ $chars = array (
405
+ /** Cyrillics **/
406
+ 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G',
407
+ 'Д' => 'D', 'Е' => 'E', 'Ё' => 'E', 'Ж' => 'Zh',
408
+ 'З' => 'Z', 'И' => 'I', 'Й' => 'I', 'К' => 'K',
409
+ 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O',
410
+ 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T',
411
+ 'У' => 'U', 'Ф' => 'F', 'Х' => 'Kh', 'Ц' => 'Ts',
412
+ 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Shch', 'Ъ' => 'Ie',
413
+ 'Ы' => 'Y', 'Ь' => '', 'Э' => 'E', 'Ю' => 'Iu',
414
+ 'Я' => 'Ia',
415
+ 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g',
416
+ 'д' => 'd', 'е' => 'e', 'ё' => 'e', 'ж' => 'zh',
417
+ 'з' => 'z', 'и' => 'i', 'й' => 'i', 'к' => 'k',
418
+ 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o',
419
+ 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't',
420
+ 'у' => 'u', 'ф' => 'f', 'х' => 'kh', 'ц' => 'ts',
421
+ 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'shch', 'ъ' => 'ie',
422
+ 'ы' => 'y', 'ь' => '', 'э' => 'e', 'ю' => 'iu',
423
+ 'я' => 'ia'
424
+ );
425
+ }
426
+ // Preform conversion
427
+ foreach ( $chars as $from => $to )
428
+ $str = str_replace( $from, $to, $str );
429
+
430
+ return $str;
431
+ }
432
+
433
+ /**
434
+ * Removes some unicode puncuation characters from a string.
435
+ * The conversion table derived from `sanitize_title_with_dashes()`
436
+ * @param string $str The string to remove from
437
+ * @return string
438
+ * @see sanitize_title_with_dashes()
439
+ */
440
+ function remove_special_chars( $str ) {
441
+ // Conversion table
442
+ static $chars = null;
443
+
444
+ if ( is_null($chars) ) {
445
+ $chars = array (
446
+ // iexcl and iquest
447
+ '%c2%a1', '%c2%bf',
448
+ // angle quotes
449
+ '%c2%ab', '%c2%bb', '%e2%80%b9', '%e2%80%ba',
450
+ // curly quotes
451
+ '%e2%80%98', '%e2%80%99', '%e2%80%9c', '%e2%80%9d',
452
+ '%e2%80%9a', '%e2%80%9b', '%e2%80%9e', '%e2%80%9f',
453
+ // copy, reg, deg, hellip and trade
454
+ '%c2%a9', '%c2%ae', '%c2%b0', '%e2%80%a6', '%e2%84%a2',
455
+ // acute accents
456
+ '%c2%b4', '%cb%8a', '%cc%81', '%cd%81',
457
+ // grave accent, macron, caron
458
+ '%cc%80', '%cc%84', '%cc%8c',
459
+
460
+ /** Extras **/
461
+ // circumflex
462
+ '%5e', '%cc%82', '%cb%86', '%ef%bc%be',
463
+ // low circumflex
464
+ '%cc%ad', '%ea%9e%88'
465
+ );
466
+ $chars = array_map( 'urldecode', $chars );
467
+ }
468
+ // Preform conversion
469
+ foreach ( $chars as $char )
470
+ $str = str_replace( $char, '', $str );
471
+
472
  return $str;
473
  }
474
 
491
  if ( !empty( $media ) ) {
492
  // Media already exists (not a fresh upload). Gets filename and ext.
493
  $old_filepath = get_attached_file( $media['ID'] );
494
+ $pp = mfrh_pathinfo( $old_filepath );
495
  $new_ext = empty( $pp['extension'] ) ? "" : $pp['extension'];
496
  $old_filename = $pp['basename'];
497
  $old_filename_no_ext = $pp['filename'];
498
  }
499
  else {
500
  // It's an upload, let's check if the extension is provided in the text
501
+ $pp = mfrh_pathinfo( $text );
502
  $new_ext = empty( $pp['extension'] ) ? "" : $pp['extension'];
503
  $text = $pp['filename'];
504
  }
506
  // Generate the new filename.
507
  if ( !empty( $manual_filename ) ) {
508
  // Filename is forced. Strip the extension. Keeps this extension in $new_ext.
509
+ $pp = mfrh_pathinfo( $manual_filename );
510
  $manual_filename = $pp['filename'];
511
  $new_ext = empty( $pp['extension'] ) ? $new_ext : $pp['extension'];
512
  $new_filename = $manual_filename;
516
  $text = str_replace( ".jpg", "", $text );
517
  $text = str_replace( ".png", "", $text );
518
  $text = str_replace( "'", "-", $text );
519
+ $text = strtolower( $this->replace_chars( $text ) );
520
+ $new_filename = sanitize_file_name( $text );
 
 
 
 
 
 
 
 
521
  }
522
+
523
+ // Convert all accent characters to ASCII characters
524
+ if ( apply_filters( 'mfrh_converts', false ) ) {
525
+ $new_filename = remove_accents( $new_filename );
526
+ $new_filename = $this->remove_special_chars( $new_filename );
527
+ $new_filename = $this->transliterate( $new_filename );
528
+ $new_filename = strtolower( $new_filename );
529
+ }
530
+
531
  if ( empty( $new_filename ) )
532
  $new_filename = "empty";
533
 
602
 
603
  // Prepare the variables
604
  $old_filepath = get_attached_file( $id );
605
+ $path_parts = mfrh_pathinfo( $old_filepath );
606
  $old_ext = $path_parts['extension'];
607
  $upload_dir = wp_upload_dir();
608
  $old_directory = trim( str_replace( $upload_dir['basedir'], '', $path_parts['dirname'] ), '/' ); // '2011/01'
611
  $new_filepath = trailingslashit( trailingslashit( $upload_dir['basedir'] ) . $new_directory ) . $filename;
612
 
613
  $this->log( "** Move Media: " . $filename );
614
+ $this->log( "The new directory will be: " . mfrh_dirname( $new_filepath ) );
615
 
616
  // Create the directory if it does not exist
617
+ if ( !file_exists( mfrh_dirname( $new_filepath ) ) ) {
618
+ mkdir( mfrh_dirname( $new_filepath ), 0777, true );
619
  }
620
 
621
  // There is no support for UNDO (as the current process of Media File Renamer doesn't keep the path for the undo, only the filename... so the move breaks this - let's deal with this later).
757
  $new_filepath = $output['desired_filepath'];
758
  $new_filename = $output['desired_filename'];
759
  $manual = $output['manual'] || !empty( $manual_filename );
760
+ $path_parts = mfrh_pathinfo( $old_filepath );
761
  $directory = $path_parts['dirname']; // '2011/01'
762
  $old_filename = $path_parts['basename']; // 'whatever.jpeg'
763
 
791
  $old_ext = $path_parts['extension'];
792
  $new_ext = $old_ext;
793
  if ( $manual_filename ) {
794
+ $pp = mfrh_pathinfo( $manual_filename );
795
  $new_ext = $pp['extension'];
796
  }
797
 
909
  // Rename slug/permalink
910
  if ( get_option( "mfrh_rename_slug" ) ) {
911
  $oldslug = $post['post_name'];
912
+ $info = mfrh_pathinfo( $new_filepath );
913
  $newslug = preg_replace( '/\\.[^.\\s]{3,4}$/', '', $info['basename'] );
914
  $post['post_name'] = $newslug;
915
  if ( wp_update_post( $post ) )
media-file-renamer.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Media File Renamer
4
  Plugin URI: http://meowapps.com
5
  Description: Auto-rename the files when titles are modified and update and the references (links). Manual Rename is a Pro option. Please read the description.
6
- Version: 4.2.2
7
  Author: Jordy Meow
8
  Author URI: http://meowapps.com
9
  Text Domain: media-file-renamer
@@ -26,10 +26,11 @@ if ( class_exists( 'Meow_MFRH_Core' ) ) {
26
  return;
27
  }
28
 
29
- if ( is_admin() ) {
 
30
 
31
  global $mfrh_version, $mfrh_core;
32
- $mfrh_version = '4.2.2';
33
 
34
  // Admin
35
  require( 'mfrh_admin.php');
3
  Plugin Name: Media File Renamer
4
  Plugin URI: http://meowapps.com
5
  Description: Auto-rename the files when titles are modified and update and the references (links). Manual Rename is a Pro option. Please read the description.
6
+ Version: 4.2.4
7
  Author: Jordy Meow
8
  Author URI: http://meowapps.com
9
  Text Domain: media-file-renamer
26
  return;
27
  }
28
 
29
+ // In admin or Rest API request (REQUEST URI begins with '/wp-json/')
30
+ if ( is_admin() || strpos( trailingslashit( $_SERVER['REQUEST_URI'] ), '/' . trailingslashit( rest_get_url_prefix() ) ) === 0 ) {
31
 
32
  global $mfrh_version, $mfrh_core;
33
+ $mfrh_version = '4.2.4';
34
 
35
  // Admin
36
  require( 'mfrh_admin.php');
mfrh_admin.php CHANGED
@@ -81,9 +81,14 @@ class Meow_MFRH_Admin extends MeowApps_Admin {
81
  array( $this, 'admin_rename_slug_callback' ),
82
  'mfrh_settings-menu', 'mfrh_settings' );
83
 
 
 
 
 
84
  register_setting( 'mfrh_settings', 'mfrh_auto_rename' );
85
  register_setting( 'mfrh_settings', 'mfrh_on_upload' );
86
  register_setting( 'mfrh_settings', 'mfrh_rename_slug' );
 
87
 
88
  // SUBMENU > Settings > Side Settings
89
  add_settings_section( 'mfrh_side_settings', null, null, 'mfrh_side_settings-menu' );
@@ -128,9 +133,6 @@ class Meow_MFRH_Admin extends MeowApps_Admin {
128
 
129
  // SUBMENU > Settings > Developer Settings
130
  add_settings_section( 'mfrh_developer_settings', null, null, 'mfrh_developer_settings-menu' );
131
- add_settings_field( 'mfrh_utf8_filename', __( 'UTF-8 Filename<br />(Pro)', 'media-file-renamer' ),
132
- array( $this, 'admin_utf8_filename_callback' ),
133
- 'mfrh_developer_settings-menu', 'mfrh_developer_settings' );
134
  add_settings_field( 'mfrh_force_rename', __( 'Force Rename<br />(Pro)', 'media-file-renamer' ),
135
  array( $this, 'admin_force_rename_callback' ),
136
  'mfrh_developer_settings-menu', 'mfrh_developer_settings' );
@@ -148,7 +150,6 @@ class Meow_MFRH_Admin extends MeowApps_Admin {
148
  'mfrh_developer_settings-menu', 'mfrh_developer_settings' );
149
 
150
  register_setting( 'mfrh_developer_settings', 'mfrh_rename_guid' );
151
- register_setting( 'mfrh_developer_settings', 'mfrh_utf8_filename' );
152
  register_setting( 'mfrh_developer_settings', 'mfrh_force_rename' );
153
  register_setting( 'mfrh_developer_settings', 'mfrh_log' );
154
  register_setting( 'mfrh_developer_settings', 'mfrh_logsql' );
@@ -250,6 +251,13 @@ class Meow_MFRH_Admin extends MeowApps_Admin {
250
  echo $html;
251
  }
252
 
 
 
 
 
 
 
 
253
  function admin_manual_rename_callback( $args ) {
254
  $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="mfrh_manual_rename" name="mfrh_manual_rename" value="1" ' .
255
  checked( 1, apply_filters( 'mfrh_manual', false ), false ) . '/>';
@@ -346,15 +354,7 @@ class Meow_MFRH_Admin extends MeowApps_Admin {
346
  $value = get_option( 'mfrh_rename_on_save', null );
347
  $html = '<input type="checkbox" id="mfrh_rename_on_save" name="mfrh_rename_on_save" value="1" ' .
348
  checked( 1, get_option( 'mfrh_rename_on_save' ), false ) . '/>';
349
- $html .= __( '<label>Enabled</label><br/><small>You can modify the titles of your media while editing a post but, of course, the plugin can\'t update the HTML at this stage. With this option, the plugin will update the filenames and HTML after that you saved the post. This option is <b>NOT RECOMMENDED.</b></small>', 'media-file-renamer' );
350
- echo $html;
351
- }
352
-
353
- function admin_utf8_filename_callback( $args ) {
354
- $html = '<input ' . disabled( $this->is_registered(), false, false ) . '
355
- type="checkbox" id="mfrh_utf8_filename" name="mfrh_utf8_filename" value="1" ' .
356
- checked( 1, apply_filters( 'mfrh_utf8', false ), false ) . '/>';
357
- $html .= __( '<label>Allow non-ASCII filenames</label><br /><small>This usually doesn\'t work well on Windows installs.</small>', 'media-file-renamer' );
358
  echo $html;
359
  }
360
 
@@ -370,7 +370,7 @@ class Meow_MFRH_Admin extends MeowApps_Admin {
370
  $value = get_option( 'mfrh_log', null );
371
  $html = '<input type="checkbox" id="mfrh_log" name="mfrh_log" value="1" ' .
372
  checked( 1, get_option( 'mfrh_log' ), false ) . '/>';
373
- $html .= __( '<label>Enabled</label><br/><small>Simple logging that explains which actions has been run. The file is <a target="_blank" href="' . plugin_dir_url( __FILE__ ) . 'media-file-renamer.log">media-file-renamer.log</a>.</small>', 'media-file-renamer' );
374
  echo $html;
375
  }
376
 
81
  array( $this, 'admin_rename_slug_callback' ),
82
  'mfrh_settings-menu', 'mfrh_settings' );
83
 
84
+ add_settings_field( 'mfrh_convert_to_ascii', "Transliteration<br /><i>To ASCII</i> (Pro)",
85
+ array( $this, 'admin_convert_to_ascii_callback' ),
86
+ 'mfrh_settings-menu', 'mfrh_settings' );
87
+
88
  register_setting( 'mfrh_settings', 'mfrh_auto_rename' );
89
  register_setting( 'mfrh_settings', 'mfrh_on_upload' );
90
  register_setting( 'mfrh_settings', 'mfrh_rename_slug' );
91
+ register_setting( 'mfrh_settings', 'mfrh_convert_to_ascii' );
92
 
93
  // SUBMENU > Settings > Side Settings
94
  add_settings_section( 'mfrh_side_settings', null, null, 'mfrh_side_settings-menu' );
133
 
134
  // SUBMENU > Settings > Developer Settings
135
  add_settings_section( 'mfrh_developer_settings', null, null, 'mfrh_developer_settings-menu' );
 
 
 
136
  add_settings_field( 'mfrh_force_rename', __( 'Force Rename<br />(Pro)', 'media-file-renamer' ),
137
  array( $this, 'admin_force_rename_callback' ),
138
  'mfrh_developer_settings-menu', 'mfrh_developer_settings' );
150
  'mfrh_developer_settings-menu', 'mfrh_developer_settings' );
151
 
152
  register_setting( 'mfrh_developer_settings', 'mfrh_rename_guid' );
 
153
  register_setting( 'mfrh_developer_settings', 'mfrh_force_rename' );
154
  register_setting( 'mfrh_developer_settings', 'mfrh_log' );
155
  register_setting( 'mfrh_developer_settings', 'mfrh_logsql' );
251
  echo $html;
252
  }
253
 
254
+ function admin_convert_to_ascii_callback( $args ) {
255
+ $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="mfrh_convert_to_ascii" name="mfrh_convert_to_ascii" value="1" ' .
256
+ checked( 1, apply_filters( 'mfrh_converts', false ), false ) . '/>';
257
+ $html .= __( '<label>Enable</label><br /><small>Replace accents, umlauts, cyrillic, diacritics, by their ASCII equivalent.<br /><i>Examples: tête -> tete, schön -> schon, Добро -> dobro, etc.</i></small>', 'media-file-renamer' );
258
+ echo $html;
259
+ }
260
+
261
  function admin_manual_rename_callback( $args ) {
262
  $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="mfrh_manual_rename" name="mfrh_manual_rename" value="1" ' .
263
  checked( 1, apply_filters( 'mfrh_manual', false ), false ) . '/>';
354
  $value = get_option( 'mfrh_rename_on_save', null );
355
  $html = '<input type="checkbox" id="mfrh_rename_on_save" name="mfrh_rename_on_save" value="1" ' .
356
  checked( 1, get_option( 'mfrh_rename_on_save' ), false ) . '/>';
357
+ $html .= __( '<label>Enabled (NOT RECOMMENDED)</label><br/><small>You can modify the titles of your media while editing a post but, of course, the plugin can\'t update the HTML at this stage. With this option, the plugin will update the filenames and HTML after that you saved the post.', 'media-file-renamer' );
 
 
 
 
 
 
 
 
358
  echo $html;
359
  }
360
 
370
  $value = get_option( 'mfrh_log', null );
371
  $html = '<input type="checkbox" id="mfrh_log" name="mfrh_log" value="1" ' .
372
  checked( 1, get_option( 'mfrh_log' ), false ) . '/>';
373
+ $html .= __( '<label>Enabled</label><br/><small>Simple logging that explains which actions has been run.<br />The file is <a target="_blank" href="' . plugin_dir_url( __FILE__ ) . 'media-file-renamer.log">media-file-renamer.log</a>.</small>', 'media-file-renamer' );
374
  echo $html;
375
  }
376
 
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Media File Renamer ===
2
- Contributors: TigrouMeow
3
  Tags: rename, file, files, media, manager, image, renamer, wpml, optimization, seo, retina, gutenberg
4
  Requires at least: 4.6
5
  Tested up to: 4.9.7
6
- Stable tag: 4.2.2
7
 
8
  Automatically rename files depending on Media titles dynamically + update links. Pro version has many more options. Check the description :)
9
 
@@ -47,15 +47,18 @@ Check the FAQ on the official website, [here](https://meowapps.com/media-file-re
47
 
48
  == Changelog ==
49
 
 
 
 
 
 
50
  = 4.2.2 =
51
  * Add: Polylang compatibility.
52
  * Update: UI enhancements and attempt to make the renaming faster.
53
- * Note: If you like it, please review the plugin here: https://wordpress.org/support/plugin/media-file-renamer/reviews/?rate=5#new-post. It's important for us :) Thank you!
54
 
55
  = 4.2.1 =
56
  * Add: All the actions in the Media Library are now asynchronous. No more page reload!
57
  * Update: Many changes and little enhancements in the code, for speed, security and code-tidyness.
58
- * Note: If you like it, please review the plugin here: https://wordpress.org/support/plugin/media-file-renamer/reviews/?rate=5#new-post. It's important for us :) Thank you!
59
 
60
  = 4.0.4 =
61
  * Fix: Renaming using filters (work in progress).
1
  === Media File Renamer ===
2
+ Contributors: TigrouMeow, amekusa
3
  Tags: rename, file, files, media, manager, image, renamer, wpml, optimization, seo, retina, gutenberg
4
  Requires at least: 4.6
5
  Tested up to: 4.9.7
6
+ Stable tag: 4.2.4
7
 
8
  Automatically rename files depending on Media titles dynamically + update links. Pro version has many more options. Check the description :)
9
 
47
 
48
  == Changelog ==
49
 
50
+ = 4.2.4 =
51
+ * Update: UTF-8 is handled by default, no need to have an option for it.
52
+ * Add: Option for transliteration (cyrillic, accents, umlauts).
53
+ * Note: If you like it, please review the plugin here: https://wordpress.org/support/plugin/media-file-renamer/reviews/?rate=5#new-post. It's important for us :) Thank you!
54
+
55
  = 4.2.2 =
56
  * Add: Polylang compatibility.
57
  * Update: UI enhancements and attempt to make the renaming faster.
 
58
 
59
  = 4.2.1 =
60
  * Add: All the actions in the Media Library are now asynchronous. No more page reload!
61
  * Update: Many changes and little enhancements in the code, for speed, security and code-tidyness.
 
62
 
63
  = 4.0.4 =
64
  * Fix: Renaming using filters (work in progress).
ui.php CHANGED
@@ -97,7 +97,7 @@ class Meow_MFRH_UI {
97
  $this->core->rename( $mfrh_undo, $original_filename );
98
 
99
  $fp = get_attached_file( $mfrh_undo );
100
- $path_parts = pathinfo( $fp );
101
  $basename = $path_parts['basename'];
102
  if ( $basename == $original_filename )
103
  delete_post_meta( $mfrh_undo, '_original_filename' );
@@ -159,7 +159,7 @@ class Meow_MFRH_UI {
159
  }
160
 
161
  function attachment_fields( $post ) {
162
- $info = pathinfo( get_attached_file( $post->ID ) );
163
  $basename = $info['basename'];
164
  $is_manual = apply_filters( 'mfrh_manual', false );
165
  $html = '<input type="text" readonly class="widefat" name="mfrh_new_filename" value="' . $basename. '" />';
@@ -318,7 +318,7 @@ class Meow_MFRH_UI {
318
  $this->core->rename( $id, $newName );
319
  $file = get_attached_file( $id );
320
  wp_send_json_success( array (
321
- 'filename' => basename( $file ),
322
  'ids' => $this->core->get_posts_by_attached_file( $file )
323
  ) );
324
  }
@@ -346,7 +346,7 @@ class Meow_MFRH_UI {
346
  delete_post_meta( $id, '_original_filename' );
347
  $file = get_attached_file( $id );
348
  wp_send_json_success( array (
349
- 'filename' => basename( $file ),
350
  'ids' => $this->core->get_posts_by_attached_file( $file )
351
  ) );
352
  }
97
  $this->core->rename( $mfrh_undo, $original_filename );
98
 
99
  $fp = get_attached_file( $mfrh_undo );
100
+ $path_parts = mfrh_pathinfo( $fp );
101
  $basename = $path_parts['basename'];
102
  if ( $basename == $original_filename )
103
  delete_post_meta( $mfrh_undo, '_original_filename' );
159
  }
160
 
161
  function attachment_fields( $post ) {
162
+ $info = mfrh_pathinfo( get_attached_file( $post->ID ) );
163
  $basename = $info['basename'];
164
  $is_manual = apply_filters( 'mfrh_manual', false );
165
  $html = '<input type="text" readonly class="widefat" name="mfrh_new_filename" value="' . $basename. '" />';
318
  $this->core->rename( $id, $newName );
319
  $file = get_attached_file( $id );
320
  wp_send_json_success( array (
321
+ 'filename' => mfrh_basename( $file ),
322
  'ids' => $this->core->get_posts_by_attached_file( $file )
323
  ) );
324
  }
346
  delete_post_meta( $id, '_original_filename' );
347
  $file = get_attached_file( $id );
348
  wp_send_json_success( array (
349
+ 'filename' => mfrh_basename( $file ),
350
  'ids' => $this->core->get_posts_by_attached_file( $file )
351
  ) );
352
  }
views/column.php CHANGED
@@ -15,8 +15,8 @@ $needsRename = $core->check_attachment( get_post( $id, ARRAY_A ), $file );
15
  <input type="hidden" name="id" value="<?php echo $id; ?>">
16
 
17
  <?php // Quick Renamer ?>
18
- <?php $filename = basename( get_attached_file( $id ) ); ?>
19
- <?php $disabled = !( $admin->is_registered() && get_option( 'mfrh_manual_rename' ) ); ?>
20
  <input type="text" name="filename" value="<?php esc_attr_e( $filename ); ?>" autocomplete="off" data-origin="<?php esc_attr_e( $filename ); ?>"<?php if ($disabled) echo ' readonly'; ?>>
21
  <?php if ( isset( $file['desired_filename'] ) ): // i ?>
22
  <input type="text" name="recommended-filename" value="<?php esc_attr_e( $file['desired_filename'] ); ?>" readonly>
15
  <input type="hidden" name="id" value="<?php echo $id; ?>">
16
 
17
  <?php // Quick Renamer ?>
18
+ <?php $filename = mfrh_basename( get_attached_file( $id ) ); ?>
19
+ <?php $disabled = !( $admin->is_registered() && apply_filters( 'mfrh_manual', false ) ); ?>
20
  <input type="text" name="filename" value="<?php esc_attr_e( $filename ); ?>" autocomplete="off" data-origin="<?php esc_attr_e( $filename ); ?>"<?php if ($disabled) echo ' readonly'; ?>>
21
  <?php if ( isset( $file['desired_filename'] ) ): // i ?>
22
  <input type="text" name="recommended-filename" value="<?php esc_attr_e( $file['desired_filename'] ); ?>" readonly>
views/menu-screen.php CHANGED
@@ -10,7 +10,7 @@
10
  <?php if ( !$admin->is_registered() ): ?>
11
  <div class="updated">
12
  <p>
13
- <?php _e( '<b>The Pro version</b> of the plugin allows you to <b>rename based on the title of the post</b> (product or whatever else) you media is attached to, <b>rename manually</b>, use <b>numbered files</b> (by adding a counter if the filenames are similar), <b>sync the title with your ALT text</b>, UTF8 support (if you need it), a force rename (to repair a broken install), and, more importantly, <b>supports the developer</b> :) Thank you!<br /><br /><a class="button-primary" href="https://store.meowapps.com/" target="_blank">Get the Pro</a>', 'media-file-renamer' ); ?>
14
  </p>
15
  </div>
16
  <?php endif; ?>
@@ -131,7 +131,7 @@
131
  WHERE m.meta_key = '_original_filename'" );
132
  foreach ( $results as $row ) {
133
  $fullsize_path = wp_get_attachment_url( $row->ID );
134
- $parts = pathinfo( $fullsize_path );
135
  $shorten_url = trailingslashit( $parts['dirname'] ) . $row->original_filename;
136
  if ( isset( $_GET['mfrh_beforeafter_filenames'] ) )
137
  echo "<tr><td>{$shorten_url}</td><td>$fullsize_path</td></tr>";
10
  <?php if ( !$admin->is_registered() ): ?>
11
  <div class="updated">
12
  <p>
13
+ <?php _e( '<b>The Pro version</b> of the plugin allows you to <b>rename based on the title of the post</b> (product or whatever else) you media is attached to, <b>rename manually</b>, use <b>numbered files</b> (by adding a counter if the filenames are similar), <b>sync the title with your ALT text</b>, a force rename (to repair a broken install), and, more importantly, <b>supports the developer</b> :) Thank you!<br /><br /><a class="button-primary" href="https://store.meowapps.com/" target="_blank">Get the Pro</a>', 'media-file-renamer' ); ?>
14
  </p>
15
  </div>
16
  <?php endif; ?>
131
  WHERE m.meta_key = '_original_filename'" );
132
  foreach ( $results as $row ) {
133
  $fullsize_path = wp_get_attachment_url( $row->ID );
134
+ $parts = mfrh_pathinfo( $fullsize_path );
135
  $shorten_url = trailingslashit( $parts['dirname'] ) . $row->original_filename;
136
  if ( isset( $_GET['mfrh_beforeafter_filenames'] ) )
137
  echo "<tr><td>{$shorten_url}</td><td>$fullsize_path</td></tr>";