Media File Renamer - Version 3.4.6

Version Description

  • Fix: Update system fixed and code cleaning.
Download this release

Release Info

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

Version 3.4.6

common/admin.css ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* MEOW BOX (SETTINGS BOX) */
2
+
3
+ .meow-box {
4
+ box-sizing: border-box;
5
+ border: 1px solid #e5e5e5;
6
+ box-shadow: 2px 2px 1px rgba(0,0,0,.02);
7
+ background: #fff;
8
+ color: #444;
9
+ margin-bottom: 15px;
10
+ font-size: 13px !important;
11
+ border-top-right-radius: 8px;
12
+ }
13
+
14
+ .meow-box input, .meow-box th, .meow-box label, .meow-box select {
15
+ font-size: 13px !important;
16
+ }
17
+
18
+ .meow-box small {
19
+ font-size: 11px !important;
20
+ }
21
+
22
+ .meow-box h3 {
23
+ font-size: 13px;
24
+ padding: 4px 12px;
25
+ margin: 0;
26
+ background: #3c3c3c;
27
+ color: #ffffff;
28
+ text-transform: uppercase;
29
+ border-top-right-radius: 8px;
30
+ /*border-bottom: 1px solid #eee;*/
31
+ }
32
+
33
+ .meow-box h3 .dashicons {
34
+ position: relative;
35
+ top: 0px;
36
+ margin-right: 5px;
37
+ }
38
+
39
+ .meow-box .pro_info {
40
+ padding: 5px;
41
+ margin: 10px -10px 5px -10px;
42
+ font-size: 11px;
43
+ line-height: 13px;
44
+ }
45
+
46
+ .meow-box .pro_info.enabled {
47
+ background: #4482d2;
48
+ border-left: 5px solid #4482d2;
49
+ color: white;
50
+ }
51
+
52
+ .meow-box .pro_info.disabled {
53
+ background: #96555b;
54
+ border-left: 5px solid #632329;
55
+ color: white;
56
+ }
57
+
58
+ .meow-box .pro_info.disabled a {
59
+ background: #96555b;
60
+ color: red;
61
+ text-decoration: none;
62
+ }
63
+
64
+ .meow-box .inside {
65
+ margin: 10px;
66
+ }
67
+
68
+ .meow-box th {
69
+ padding: 10px 10px 10px 0px;
70
+ width: 22%;
71
+ }
72
+
73
+ .meow-box td {
74
+ padding: 10px 10px;
75
+ }
76
+
77
+ .meow-box p.submit {
78
+ text-align: right;
79
+ margin: 10px -10px -10px -10px;
80
+ padding: 7px 10px 10px 0px !important;
81
+ border-top: 1px solid #eee !important;
82
+ max-width: inherit;
83
+ background: rgba(125, 125, 125, 0.04);
84
+ border-radius: 0px;
85
+ }
86
+
87
+ .meow-box [type="text"], .meow-box select {
88
+ width: 100%;
89
+ }
90
+
91
+ /* CONTROLS INSIDE A COLUMN (LABEL ON THE LEFT, VALUE ON THE RIGHT) */
92
+ .meow-box td [type="text"], .meow-box td [type="checkbox"], .meow-box td select {
93
+ margin-top: -3px;
94
+ }
95
+
96
+ .meow-header-ad {
97
+ float: right;
98
+ }
99
+
100
+ /* BUTTONS */
101
+
102
+ .meow-button-xs {
103
+ font-size: 10px !important;
104
+ height: 20px !important;
105
+ line-height: 18px !important;
106
+ position: relative !important;
107
+ top: 1px !important;
108
+ text-align: center !important
109
+ }
110
+
111
+ /* MODAL */
112
+
113
+ #meow-modal-info-backdrop {
114
+ background: rgba(0, 0, 0, 0.75);
115
+ position: fixed;
116
+ top: 0px;
117
+ bottom: 0px;
118
+ right: 0px;
119
+ left: 0px;
120
+ z-index: 10000;
121
+ }
122
+
123
+ #meow-modal-info {
124
+ background: white;
125
+ box-shadow: 0px 0px 5px black;
126
+ padding: 15px;
127
+ overflow-y: scroll;
128
+ position: fixed;
129
+ z-index: 10000;
130
+ left: 100px;
131
+ right: 100px;
132
+ top: 50px;
133
+ bottom: 50px;
134
+ }
135
+
136
+ #meow-modal-info h3 {
137
+ height: 25px;
138
+ border-bottom: 2px solid #808080;
139
+ }
140
+
141
+ #meow-modal-info td {
142
+ text-align: center;
143
+ font-size: 11px;
144
+ border: 1px solid #D3DCFF;
145
+ padding: 10px 15px;
146
+ background: #EFF8FF;
147
+ }
148
+
149
+ #meow-modal-info .close {
150
+ float: right;
151
+ font-size: 18px;
152
+ font-weight: bold;
153
+ font-family: Verdana;
154
+ cursor: pointer;
155
+ }
156
+
157
+ #meow-modal-info .loading {
158
+ background-color: #F2F2F2;
159
+ text-align: center;
160
+ padding-top: 10px;
161
+ background-size: 32px 32px;
162
+ }
163
+
164
+ #meow-modal-info .meow-sized-image {
165
+ width: 19px;
166
+ height: 19px;
167
+ margin-right: 10px;
168
+ }
169
+
170
+ /* IMAGE SIZES RELATED INFO */
171
+
172
+ .meow-sized-images {
173
+ margin-top: 0px;
174
+ cursor: pointer;
175
+ }
176
+
177
+ .meow-sized-images li, #meow-modal-info .meow-sized-image {
178
+ display: block;
179
+ color: white;
180
+ padding: 5px 0px;
181
+ font-size: 10px;
182
+ text-align: center;
183
+ width: 18px;
184
+ height: 18px;
185
+ line-height: 8px;
186
+ background: black;
187
+ float: left;
188
+ margin-right: 1px;
189
+ box-sizing: border-box;
190
+ margin-bottom: 2px;
191
+ }
192
+
193
+ .meow-sized-images:after {
194
+ clear: both;
195
+ content:""; display:table;
196
+ }
197
+
198
+ .meow-sized-images + span {
199
+ position: relative;
200
+ top: -12px;
201
+ }
202
+
203
+ /* MEOW COLORS */
204
+
205
+ .meow-bk-blue {
206
+ background: #3C82C7 !important;
207
+ color: white;
208
+ }
209
+
210
+ .meow-bk-orange {
211
+ background: #f1900e !important;
212
+ color: white;
213
+ }
214
+
215
+ .meow-bk-red {
216
+ background: #c53a47 !important;
217
+ color: white;
218
+ }
219
+
220
+ .meow-bk-gray {
221
+ background: gray !important;
222
+ color: white;
223
+ }
224
+
225
+ .meow-bk-green {
226
+ background: #2b9463 !important;
227
+ color: white;
228
+ }
229
+
230
+ .meow-bk-black {
231
+ background: #3c3c3c !important;
232
+ color: white;
233
+ }
234
+
235
+ .meow-bk-purple {
236
+ background: #984c96 !important;
237
+ color: white;
238
+ }
239
+
240
+ /* DASHBOARD */
241
+
242
+ .meow-dashboard .meow-box li {
243
+ border-bottom: 1px solid #eee;
244
+ padding: 0px 10px 10px 10px;
245
+ }
246
+
247
+ .meow-dashboard .meow-box li:last-child {
248
+ border: none;
249
+ padding-bottom: 0px;
250
+ }
251
+
252
+ .meow-button-xs .dashicons {
253
+ font-size: 18px !important;
254
+ }
255
+
256
+ .meow-button-xs.updating-message:before {
257
+ margin-top: 0px !important;
258
+ }
259
+
260
+ .meow-button-xs.updating-message * {
261
+ display: none;
262
+ }
263
+
264
+ #phpinfo {
265
+ font-size: 11px;
266
+ }
267
+
268
+ #phpinfo .e {
269
+ padding: 5px;
270
+ background: lightgray;
271
+ }
272
+
273
+ #phpinfo .h th {
274
+ padding: 5px;
275
+ color: white;
276
+ background: gray;
277
+ text-align: left;
278
+ font-size: 14px !important;
279
+ }
280
+
281
+ #phpinfo h1 {
282
+ padding: 10px 0px;
283
+ font-weight: bold;
284
+ }
285
+
286
+ #phpinfo h2 {
287
+ padding: 10px 0px;
288
+ font-weight: bold;
289
+ font-size: 20px;
290
+ }
291
+
292
+ #error_log {
293
+ font-size: 12px;
294
+ }
295
+
296
+ /* ROWS AND COLUMNS */
297
+ .meow-col { display: block; float:left; margin: 1% 0 1% 1.6%; }
298
+ .meow-col:first-child { margin-left: 0; }
299
+
300
+ /* GROUPING */
301
+ .meow-row { clear: both; padding: 0px; margin: 0px; }
302
+ .meow-row:before,
303
+ .meow-row:after { content:""; display:table; }
304
+ .meow-row:after { clear:both; }
305
+ .meow-row { zoom:1; /* For IE 6/7 */ }
306
+
307
+ /* GRID OF THREE */
308
+ .meow-span_3_of_3 { width: 100%; }
309
+ .meow-span_2_of_3 { width: 66.1%; }
310
+ .meow-span_1_of_3 { width: 32.2%; }
311
+
312
+ /* GRID OF TWO */
313
+ .meow-span_2_of_2 { width: 100%; }
314
+ .meow-span_1_of_2 { width: 49.2%; }
315
+
316
+ @media only screen and (max-width: 480px) {
317
+ .meow-col { margin: 0 0 0px 0;}
318
+ .meow-span_3_of_3, .meow-span_2_of_3, .meow-span_1_of_3 { width: 100%; }
319
+ .meow-span_2_of_2, .meow-span_1_of_2 { width: 100%; }
320
+ .meow-header-ad { display: none !important; }
321
+ .meow-box [type="text"] { width: 100% !important; }
322
+ }
common/admin.php ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( !class_exists( 'MeowApps_Admin' ) ) {
4
+
5
+ class MeowApps_Admin {
6
+
7
+ public static $loaded = false;
8
+ public static $admin_version = "1.2";
9
+
10
+ public $prefix; // prefix used for actions, filters (mfrh)
11
+ public $mainfile; // plugin main file (media-file-renamer.php)
12
+ public $domain; // domain used for translation (media-file-renamer)
13
+
14
+ public function __construct( $prefix, $mainfile, $domain ) {
15
+
16
+ // Core Admin (used by all Meow Apps plugins)
17
+ if ( !MeowApps_Admin::$loaded ) {
18
+ if ( is_admin() ) {
19
+ add_action( 'admin_menu', array( $this, 'admin_menu_start' ) );
20
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
21
+ add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
22
+ }
23
+ MeowApps_Admin::$loaded = true;
24
+ }
25
+
26
+ // Variables for this plugin
27
+ $this->prefix = $prefix;
28
+ $this->mainfile = $mainfile;
29
+ $this->domain = $domain;
30
+
31
+ // Check if the free version is installed but there is license
32
+ // TODO: In the future, this should be removed ideally
33
+ if ( is_admin() ) {
34
+ $license = get_option( $this->prefix . '_license', "" );
35
+ if ( ( !empty( $license ) ) && !file_exists( plugin_dir_path( __FILE__ ) . '/meowapps/admin.php' ) ) {
36
+ add_action( 'admin_notices', array( $this, 'admin_notices_licensed_free' ) );
37
+ }
38
+ }
39
+ }
40
+
41
+ function admin_notices_licensed_free() {
42
+ if ( isset( $_POST[$this->prefix . '_reset_sub'] ) ) {
43
+ delete_option( $this->prefix . '_pro_serial' );
44
+ delete_option( $this->prefix . '_license' );
45
+ return;
46
+ }
47
+ echo '<div class="error">';
48
+ echo '<p>It looks like you are using the free version of the plugin (<b>' . $this->mainfile . '</b>) but a license for the Pro version was also found. The Pro version might have been replaced by the Free version during an update (might be caused by a temporarily issue). If it is the case, <b>please download it again</b> from the <a target="_blank" href="https://store.meowapps.com">Meow Store</a>. If you wish to continue using the free version and clear this message, click on this button.';
49
+ echo '<p>
50
+ <form method="post" action="">
51
+ <input type="hidden" name="' . $this->prefix . '_reset_sub" value="true">
52
+ <input type="submit" name="submit" id="submit" class="button" value="Remove the license">
53
+ </form>
54
+ </p>
55
+ ';
56
+ echo '</div>';
57
+ }
58
+
59
+ function display_ads() {
60
+ return !get_option( 'meowapps_hide_ads', false );
61
+ }
62
+
63
+ function display_title( $title = "Meow Apps",
64
+ $author = "By <a style='text-decoration: none;' href='http://meowapps.com' target='_blank'>Jordy Meow</a>" ) {
65
+ if ( !empty( $this->prefix ) )
66
+ $title = apply_filters( $this->prefix . '_plugin_title', $title );
67
+ if ( $this->display_ads() ) {
68
+ echo '<a class="meow-header-ad" target="_blank" href="http://www.shareasale.com/r.cfm?b=906810&u=767054&m=41388&urllink=&afftrack="">
69
+ <img src="' . $this->common_url( 'img/wpengine.png' ) . '" height="60" border="0" /></a>';
70
+ }
71
+ ?>
72
+ <h1 style="line-height: 16px;">
73
+ <img width="36" style="margin-right: 10px; float: left; position: relative; top: -5px;"
74
+ src="<?php echo $this->meowapps_logo_url(); ?>"><?php echo $title; ?><br />
75
+ <span style="font-size: 12px"><?php echo $author; ?></span>
76
+ </h1>
77
+ <div style="clear: both;"></div>
78
+ <?php
79
+ }
80
+
81
+ function admin_enqueue_scripts() {
82
+ wp_register_style( 'meowapps-core-css', $this->common_url( 'admin.css' ) );
83
+ wp_enqueue_style( 'meowapps-core-css' );
84
+ }
85
+
86
+ function admin_menu_start() {
87
+ if ( get_option( 'meowapps_hide_meowapps', false ) ) {
88
+ register_setting( 'general', 'meowapps_hide_meowapps' );
89
+ add_settings_field( 'meowapps_hide_ads', 'Meow Apps Menu', array( $this, 'meowapps_hide_dashboard_callback' ), 'general' );
90
+ return;
91
+ }
92
+
93
+ // Creates standard menu if it does NOT exist
94
+ global $submenu;
95
+ if ( !isset( $submenu[ 'meowapps-main-menu' ] ) ) {
96
+ add_menu_page( 'Meow Apps', 'Meow Apps', 'manage_options', 'meowapps-main-menu',
97
+ array( $this, 'admin_meow_apps' ), 'dashicons-camera', 82 );
98
+ add_submenu_page( 'meowapps-main-menu', __( 'Dashboard', 'meowapps' ),
99
+ __( 'Dashboard', 'meowapps' ), 'manage_options',
100
+ 'meowapps-main-menu', array( $this, 'admin_meow_apps' ) );
101
+ }
102
+
103
+ add_settings_section( 'meowapps_common_settings', null, null, 'meowapps_common_settings-menu' );
104
+ add_settings_field( 'meowapps_hide_meowapps', "Main Menu",
105
+ array( $this, 'meowapps_hide_dashboard_callback' ),
106
+ 'meowapps_common_settings-menu', 'meowapps_common_settings' );
107
+ add_settings_field( 'meowapps_hide_ads', "Ads",
108
+ array( $this, 'meowapps_hide_ads_callback' ),
109
+ 'meowapps_common_settings-menu', 'meowapps_common_settings' );
110
+ register_setting( 'meowapps_common_settings', 'meowapps_hide_meowapps' );
111
+ register_setting( 'meowapps_common_settings', 'meowapps_hide_ads' );
112
+ }
113
+
114
+ function meowapps_hide_ads_callback() {
115
+ $value = get_option( 'meowapps_hide_ads', null );
116
+ $html = '<input type="checkbox" id="meowapps_hide_ads" name="meowapps_hide_ads" value="1" ' .
117
+ checked( 1, get_option( 'meowapps_hide_ads' ), false ) . '/>';
118
+ $html .= __( '<label>Hide</label><br /><small>Doesn\'t display the ads.</small>', 'wp-retina-2x' );
119
+ echo $html;
120
+ }
121
+
122
+ function meowapps_hide_dashboard_callback() {
123
+ $value = get_option( 'meowapps_hide_meowapps', null );
124
+ $html = '<input type="checkbox" id="meowapps_hide_meowapps" name="meowapps_hide_meowapps" value="1" ' .
125
+ checked( 1, get_option( 'meowapps_hide_meowapps' ), false ) . '/>';
126
+ $html .= __( '<label>Hide <b>Meow Apps</b> Menu</label><br /><small>Hide Meow Apps menu and all its components, for a nicer an faster WordPress admin UI. An option will be added in Settings > General to display it again.</small>', 'wp-retina-2x' );
127
+ echo $html;
128
+ }
129
+
130
+ function display_serialkey_box( $url = "https://meowapps.com/" ) {
131
+ $html = '<div class="meow-box">';
132
+ $html .= '<h3 class="' . ( $this->is_registered( $this->prefix ) ? 'meow-bk-blue' : 'meow-bk-red' ) . '">Pro Version ' .
133
+ ( $this->is_registered( $this->prefix ) ? '(enabled)' : '(disabled)' ) . '</h3>';
134
+ $html .= '<div class="inside">';
135
+ echo $html;
136
+ $html = apply_filters( $this->prefix . '_meowapps_license_input', ( 'More information about the Pro version here:
137
+ <a target="_blank" href="' . $url . '">' . $url . '</a>.' ), $url );
138
+ $html .= '</div>';
139
+ $html .= '</div>';
140
+ echo $html;
141
+ }
142
+
143
+ function is_registered() {
144
+ return apply_filters( $this->prefix . '_meowapps_is_registered', false, $this->prefix );
145
+ }
146
+
147
+ function check_install( $plugin ) {
148
+ $pluginpath = get_home_path() . 'wp-content/plugins/' . $plugin;
149
+ if ( !file_exists( $pluginpath ) ) {
150
+ $url = wp_nonce_url( "update.php?action=install-plugin&plugin=$plugin", "install-plugin_$plugin" );
151
+ return "<a href='$url'><small><span class='' style='float: right;'>install</span></small></a>";
152
+ }
153
+ $plugin_file = $plugin . '/' . $plugin . '.php';
154
+ if ( is_plugin_active( $plugin_file ) )
155
+ return "<small><span style='float: right; color: green;'><span class='dashicons dashicons-yes'></span></span></small>";
156
+ else {
157
+ $url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $plugin_file ),
158
+ 'activate-plugin_' . $plugin_file );
159
+ return '<small><span style="color: orange; float: right;">off
160
+ (<a style="color: rgba(30,140,190,.8); text-decoration: none;" href="' .
161
+ $url . '">enable</a>)</span></small>';
162
+ }
163
+ }
164
+
165
+ function common_url( $file ) {
166
+ die( "Meow Apps: The function common_url( \$file ) needs to be overriden." );
167
+ // Normally, this should be used:
168
+ // return plugin_dir_url( __FILE__ ) . ( '\/common\/' . $file );
169
+ }
170
+
171
+ function meowapps_logo_url() {
172
+ return $this->common_url( 'img/meowapps.png' );
173
+ }
174
+
175
+ function plugins_loaded() {
176
+ if ( isset( $_GET[ 'tool' ] ) && $_GET[ 'tool' ] == 'error_log' ) {
177
+ $sec = "5";
178
+ header("Refresh: $sec;");
179
+ }
180
+ }
181
+
182
+ function admin_meow_apps() {
183
+
184
+ echo '<div class="wrap meow-dashboard">';
185
+ if ( isset( $_GET['tool'] ) && $_GET['tool'] == 'phpinfo' ) {
186
+ echo "<a href=\"javascript:history.go(-1)\">< Go back</a><br /><br />";
187
+ echo '<div id="phpinfo">';
188
+ ob_start();
189
+ phpinfo();
190
+ $pinfo = ob_get_contents();
191
+ ob_end_clean();
192
+ $pinfo = preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1', $pinfo );
193
+ echo $pinfo;
194
+ echo "</div>";
195
+ }
196
+ else if ( isset( $_GET['tool'] ) && $_GET['tool'] == 'error_log' ) {
197
+ $errorpath = ini_get( 'error_log' );
198
+ echo "<a href=\"javascript:history.go(-1)\">< Go back</a><br /><br />";
199
+ echo '<div id="error_log">';
200
+ if ( file_exists( $errorpath ) ) {
201
+ echo "Now (auto-reload every 5 seconds):<br />[" . date( "d-M-Y H:i:s", time() ) . " UTC]<br /<br /><br />Errors (order by latest):";
202
+ $errors = file_get_contents( $errorpath );
203
+ $errors = explode( "\n", $errors );
204
+ $errors = array_reverse( $errors );
205
+ $errors = implode( "<br />", $errors );
206
+ echo $errors;
207
+ }
208
+ else {
209
+ echo "The PHP Error Logs cannot be found. Please ask your hosting service for it.";
210
+ }
211
+ echo "</div>";
212
+
213
+ }
214
+ else {
215
+
216
+ ?>
217
+ <?php $this->display_title(); ?>
218
+ <p>
219
+ <?php _e( 'Meow Apps is run by <a href="http://jordymeow.com">Jordy Meow</a>, a photographer and software developer based in Japan. When he realized that WordPress was an environment not so friendly to photographers, Meow Apps was born. It is a suite of plugins dedicate to make the blogging life of image lovers easy and pretty. Meow Apps also teams up with the best players in the community (other themes or plugins developers). For more information, please check <a href="http://meowapps.com" target="_blank">Meow Apps</a>.', 'meowapps' )
220
+ ?>
221
+ </p>
222
+ <div class="meow-row">
223
+ <div class="meow-box meow-col meow-span_1_of_2 ">
224
+ <h3 class=""><span class="dashicons dashicons-camera"></span> UI Plugins </h3>
225
+ <ul class="">
226
+ <li><b>WP/LR Sync</b> <?php echo $this->check_install( 'wplr-sync' ) ?><br />
227
+ Bring synchronization from Lightroom to WordPress.</li>
228
+ <li><b>Meow Lightbox</b> <?php echo $this->check_install( 'meow-lightbox' ) ?><br />
229
+ Lightbox with EXIF information nicely displayed.</li>
230
+ <li><b>Meow Gallery</b> <?php echo $this->check_install( 'meow-gallery' ) ?><br />
231
+ Simple gallery to make your photos look better (Masonry and others).</li>
232
+ <li><b>Audio Story for Images</b> <?php echo $this->check_install( 'audio-story-images' ) ?><br />
233
+ Add audio to your images.</li>
234
+ </ul>
235
+ </div>
236
+ <div class="meow-box meow-col meow-span_1_of_2">
237
+ <h3 class=""><span class="dashicons dashicons-admin-tools"></span> System Plugins</h3>
238
+ <ul class="">
239
+ <li><b>Media File Renamer</b> <?php echo $this->check_install( 'media-file-renamer' ) ?><br />
240
+ Nicer filenames and better SEO, automatically.</li>
241
+ <li><b>Media Cleaner</b> <?php echo $this->check_install( 'media-cleaner' ) ?><br />
242
+ Detect the files you are not using to clean your system.</li>
243
+ <li><b>WP Retina 2x</b> <?php echo $this->check_install( 'wp-retina-2x' ) ?><br />
244
+ Make your website perfect for retina devices.</li>
245
+ <li><b>WP Category Permalink</b> <?php echo $this->check_install( 'wp-category-permalink' ) ?><br />
246
+ Allows you to select a main category (or taxonomy) for nicer permalinks.</li>
247
+ </ul>
248
+ </div>
249
+ </div>
250
+
251
+ <div class="meow-row">
252
+ <div class="meow-box meow-col meow-span_2_of_3">
253
+ <h3><span class="dashicons dashicons-admin-tools"></span> Common</h3>
254
+ <div class="inside">
255
+ <form method="post" action="options.php">
256
+ <?php settings_fields( 'meowapps_common_settings' ); ?>
257
+ <?php do_settings_sections( 'meowapps_common_settings-menu' ); ?>
258
+ <?php submit_button(); ?>
259
+ </form>
260
+ </div>
261
+ </div>
262
+
263
+ <div class="meow-box meow-col meow-span_1_of_3">
264
+ <h3><span class="dashicons dashicons-admin-tools"></span> Debug</h3>
265
+ <div class="inside">
266
+ <ul>
267
+ <li><a href="?page=meowapps-main-menu&amp;tool=error_log">Display Error Log</a></li>
268
+ <li><a href="?page=meowapps-main-menu&amp;tool=phpinfo">Display PHP Info</a></li>
269
+ </ul>
270
+ </div>
271
+ </div>
272
+ </div>
273
+
274
+ <?php
275
+
276
+ }
277
+
278
+ echo "<br /><small style='color: lightgray;'>Meow Admin " . MeowApps_Admin::$admin_version . "</small></div>";
279
+ }
280
+
281
+ // HELPERS
282
+
283
+ static function size_shortname( $name ) {
284
+ $name = preg_split( '[_-]', $name );
285
+ $short = strtoupper( substr( $name[0], 0, 1 ) );
286
+ if ( count( $name ) > 1 )
287
+ $short .= strtoupper( substr( $name[1], 0, 1 ) );
288
+ return $short;
289
+ }
290
+
291
+ }
292
+
293
+ }
294
+
295
+ if ( file_exists( plugin_dir_path( __FILE__ ) . '/meowapps/admin.php' ) ) {
296
+ require( 'meowapps/admin.php' );
297
+ }
298
+
299
+ ?>
common/img/meowapps.png ADDED
Binary file
common/img/wpengine.png ADDED
Binary file
core.php ADDED
@@ -0,0 +1,1091 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Meow_MFRH_Core {
4
+
5
+ private $mfrh_admin = null;
6
+
7
+ public function __construct( $mfrh_admin ) {
8
+ $this->mfrh_admin = $mfrh_admin;
9
+ add_action( 'plugins_loaded', array( $this, 'init' ) );
10
+ add_action( 'plugins_loaded', array( $this, 'init_actions' ) );
11
+ }
12
+
13
+ function init() {
14
+
15
+ include( 'mfrh_custom.php' );
16
+
17
+ global $mfrh_version;
18
+ //load_plugin_textdomain( 'media-file-renamer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
19
+
20
+ add_action( 'admin_head', array( $this, 'admin_head' ) );
21
+ add_action( 'admin_menu', array( $this, 'admin_menu' ) );
22
+ add_action( 'wp_ajax_mfrh_rename_media', array( $this, 'wp_ajax_mfrh_rename_media' ) );
23
+ add_filter( 'media_send_to_editor', array( $this, 'media_send_to_editor' ), 20, 3 );
24
+ add_action( 'admin_notices', array( $this, 'admin_notices' ) );
25
+ add_action( 'edit_attachment', array( $this, 'edit_attachment' ) );
26
+ add_action( 'add_attachment', array( $this, 'edit_attachment' ) );
27
+ add_action( 'add_meta_boxes', array( $this, 'add_rename_metabox' ) );
28
+ add_filter( 'attachment_fields_to_save', array( $this, 'attachment_save' ), 20, 2 );
29
+ add_action( 'save_post', array( $this, 'save_post' ) );
30
+
31
+ if ( get_option( 'mfrh_on_upload', false ) )
32
+ add_filter( 'wp_handle_upload_prefilter', array( $this, 'wp_handle_upload_prefilter' ), 10, 2 );
33
+
34
+ // Column for Media Library
35
+ $method = apply_filters( 'mfrh_method', 'media_title' );
36
+ if ( $method != 'none' ) {
37
+ add_filter( 'manage_media_columns', array( $this, 'add_media_columns' ) );
38
+ add_action( 'manage_media_custom_column', array( $this, 'manage_media_custom_column' ), 10, 2 );
39
+ }
40
+
41
+ // Support for additional plugins
42
+ add_action( 'wpml_loaded', array( $this, 'wpml_load' ) );
43
+ }
44
+
45
+ /**
46
+ *
47
+ * ADDITIONAL PLUGINS
48
+ *
49
+ */
50
+
51
+ function wpml_load() {
52
+ require( 'plugins/wpml.php' );
53
+ }
54
+
55
+ /**
56
+ *
57
+ * ERROR/INFO MESSAGE HANDLING
58
+ *
59
+ */
60
+
61
+ function admin_notices() {
62
+ $screen = get_current_screen();
63
+ if ( ( $screen->base == 'post' && $screen->post_type == 'attachment' ) ||
64
+ ( $screen->base == 'media' && isset( $_GET['attachment_id'] ) ) ) {
65
+ $attachmentId = isset( $_GET['post'] ) ? $_GET['post'] : $_GET['attachment_id'];
66
+ if ( $this->check_attachment( $attachmentId, $output ) ) {
67
+ if ( $output['desired_filename_exists'] ) {
68
+ echo '<div class="error"><p>
69
+ The file ' . $output['desired_filename'] . ' already exists. Please give a new title for this media.
70
+ </p></div>';
71
+ }
72
+ }
73
+ if ( $this->wpml_media_is_installed() && !$this->is_real_media( $attachmentId ) ) {
74
+ echo '<div class="error"><p>
75
+ This attachment seems to be a virtual copy (or translation). Media File Renamer will not make any modification from here.
76
+ </p></div>';
77
+ }
78
+ }
79
+ }
80
+
81
+ /**
82
+ *
83
+ * 'RENAME' LINK
84
+ *
85
+ */
86
+
87
+ function add_media_columns($columns) {
88
+ $columns['mfrh_column'] = __( 'Rename', 'media-file-renamer' );
89
+ return $columns;
90
+ }
91
+
92
+ function manage_media_custom_column( $column_name, $id ) {
93
+ $paged = isset( $_GET['paged'] ) ? ( '&paged=' . $_GET['paged'] ) : "";
94
+ if ( $column_name == 'mfrh_column' ) {
95
+ $check = $this->check_attachment( $id, $output );
96
+
97
+ $original_filename = get_post_meta( $id, '_original_filename', true );
98
+
99
+ if ( $check ) {
100
+ $this->generate_explanation( $output );
101
+ }
102
+ else if ( isset( $output['manual'] ) && $output['manual'] ) {
103
+ echo "<span title='" . __( 'Manually renamed.', 'media-file-renamer' ) . "' style='font-size: 24px; color: #36B15C;' class='dashicons dashicons-yes'></span>";
104
+ $page = isset( $_GET['page'] ) ? ( '&page=' . $_GET['page'] ) : "";
105
+ echo "<a title='" . __( 'Locked to manual only. Click to unlock it.', 'media-file-renamer' ) . "' href='?" . $page . "&mfrh_unlock=" . $id . $paged . "'><span style='font-size: 20px; position: relative; top: 0px; color: #36B15C;' class='dashicons dashicons-lock'></span></a>";
106
+ }
107
+ else {
108
+ echo "<span title='" . __( 'Automatically renamed.', 'media-file-renamer' ) . "'style='font-size: 24px; color: #36B15C;' class='dashicons dashicons-yes'></span>";
109
+ $page = isset( $_GET['page'] ) ? ( '&page=' . $_GET['page'] ) : "";
110
+ if ( get_option( 'mfrh_undo', false ) && !empty( $original_filename ) ) {
111
+ echo "<a title='" . __( 'Rename to original filename: ', 'media-file-renamer' ) . $original_filename . "' href='?" . $page . "&mfrh_undo=" . $id . $paged . "' style='position: relative; top: 4px; font-size: 15px; color: #de4817;' class='dashicons dashicons-undo'></a>";
112
+ }
113
+ echo "<a title='" . __( 'Click to lock it to manual only.', 'media-file-renamer' ) . "' href='?" . $page . "&mfrh_lock=" . $id . $paged . "'><span style='font-size: 20px;' class='dashicons dashicons-unlock'></span></a>";
114
+ }
115
+ }
116
+ }
117
+
118
+ function admin_head() {
119
+ if ( !empty( $_GET['mfrh_rename'] ) ) {
120
+ $mfrh_rename = $_GET['mfrh_rename'];
121
+ $this->rename_media( get_post( $mfrh_rename, ARRAY_A ), null );
122
+ $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'mfrh_rename' ), $_SERVER['REQUEST_URI'] );
123
+ }
124
+ if ( !empty( $_GET['mfrh_unlock'] ) ) {
125
+ $mfrh_unlock = $_GET['mfrh_unlock'];
126
+ delete_post_meta( $mfrh_unlock, '_manual_file_renaming' );
127
+ $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'mfrh_unlock' ), $_SERVER['REQUEST_URI'] );
128
+ }
129
+ if ( !empty( $_GET['mfrh_undo'] ) ) {
130
+ $mfrh_undo = $_GET['mfrh_undo'];
131
+ $original_filename = get_post_meta( $mfrh_undo, '_original_filename', true );
132
+ $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'mfrh_undo' ), $_SERVER['REQUEST_URI'] );
133
+ $this->rename_media( get_post( $mfrh_undo, ARRAY_A ), null, false, $original_filename );
134
+
135
+ $fp = get_attached_file( $mfrh_undo );
136
+ $path_parts = pathinfo( $fp );
137
+ $basename = $path_parts['basename'];
138
+ if ( $basename == $original_filename )
139
+ delete_post_meta( $mfrh_undo, '_original_filename' );
140
+ }
141
+ if ( !empty( $_GET['mfrh_lock'] ) ) {
142
+ $mfrh_lock = $_GET['mfrh_lock'];
143
+ add_post_meta( $mfrh_lock, '_manual_file_renaming', true, true );
144
+ $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'mfrh_lock' ), $_SERVER['REQUEST_URI'] );
145
+ }
146
+
147
+ ?>
148
+ <script type="text/javascript" >
149
+
150
+ var current;
151
+ var ids = [];
152
+
153
+ function mfrh_process_next() {
154
+ var data = { action: 'mfrh_rename_media', subaction: 'renameMediaId', id: ids[current - 1] };
155
+ jQuery('#mfrh_progression').text(current + "/" + ids.length);
156
+ jQuery.post(ajaxurl, data, function (response) {
157
+ if (++current <= ids.length) {
158
+ mfrh_process_next();
159
+ }
160
+ else {
161
+ jQuery('#mfrh_progression').html("<?php echo __( "Done. Please <a href='javascript:history.go(0)'>refresh</a> this page.", 'media-file-renamer' ); ?>");
162
+ }
163
+ });
164
+ }
165
+
166
+ function mfrh_rename_media(all) {
167
+ current = 1;
168
+ ids = [];
169
+ var data = { action: 'mfrh_rename_media', subaction: 'getMediaIds', all: all ? '1' : '0' };
170
+ jQuery('#mfrh_progression').text("<?php echo __( "Please wait...", 'media-file-renamer' ); ?>");
171
+ jQuery.post(ajaxurl, data, function (response) {
172
+ reply = jQuery.parseJSON(response);
173
+ ids = reply.ids;
174
+ jQuery('#mfrh_progression').html(current + "/" + ids.length);
175
+ mfrh_process_next();
176
+ });
177
+ }
178
+ </script>
179
+ <?php
180
+ }
181
+
182
+ /**
183
+ *
184
+ * BULK MEDIA RENAME PAGE
185
+ *
186
+ */
187
+
188
+ function wp_ajax_mfrh_rename_media() {
189
+ $subaction = $_POST['subaction'];
190
+ if ( $subaction == 'getMediaIds' ) {
191
+ $all = intval( $_POST['all'] );
192
+ global $wpdb;
193
+ $ids = $wpdb->get_col( "SELECT p.ID FROM $wpdb->posts p WHERE post_status = 'inherit' AND post_type = 'attachment'" );
194
+ if ( !$all ) {
195
+ $idsToRemove = $wpdb->get_col( "SELECT m.post_id FROM wp_postmeta m WHERE m.meta_key = '_manual_file_renaming' and m.meta_value = 1" );
196
+ $ids = array_values( array_diff( $ids, $idsToRemove ) );
197
+ }
198
+ $reply = array();
199
+ $reply['ids'] = $ids;
200
+ $reply['total'] = count( $ids );
201
+ echo json_encode( $reply );
202
+ die;
203
+ }
204
+ else if ( $subaction == 'renameMediaId' ) {
205
+ $id = intval( $_POST['id'] );
206
+ $this->rename_media( get_post( $id, ARRAY_A ), null );
207
+ echo 1;
208
+ die();
209
+ }
210
+ echo 0;
211
+ die();
212
+ }
213
+
214
+ function admin_menu() {
215
+ $method = apply_filters( 'mfrh_method', 'media_title' );
216
+ if ( $method != 'none' ) {
217
+ add_media_page( 'Media File Renamer', __( 'Renamer', 'media-file-renamer' ), 'manage_options', 'rename_media_files', array( $this, 'rename_media_files' ) );
218
+ }
219
+ }
220
+
221
+ function wpml_media_is_installed() {
222
+ return defined( 'WPML_MEDIA_VERSION' );
223
+ }
224
+
225
+ // To avoid issue with WPML Media for instance
226
+ function is_real_media( $id ) {
227
+ if ( $this->wpml_media_is_installed() ) {
228
+ global $sitepress;
229
+ $language = $sitepress->get_default_language( $id );
230
+ return icl_object_id( $id, 'attachment', true, $language ) == $id;
231
+ }
232
+ return true;
233
+ }
234
+
235
+ function is_header_image( $id ) {
236
+ static $headers = false;
237
+ if ( $headers == false ) {
238
+ global $wpdb;
239
+ $headers = $wpdb->get_col( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_is_custom_header'" );
240
+ }
241
+ return in_array( $id, $headers );
242
+ }
243
+
244
+ function generate_unique_filename( $actual, $dirname, $filename, $counter = null ) {
245
+ $new_filename = $filename;
246
+ if ( !is_null( $counter ) ) {
247
+ $whereisdot = strrpos( $new_filename, '.' );
248
+ $new_filename = substr( $new_filename, 0, $whereisdot ) . '-' . $counter
249
+ . '.' . substr( $new_filename, $whereisdot + 1 );
250
+ }
251
+ if ( $actual == $new_filename )
252
+ return false;
253
+ if ( file_exists( $dirname . "/" . $new_filename ) )
254
+ return $this->generate_unique_filename( $actual, $dirname, $filename,
255
+ is_null( $counter ) ? 2 : $counter + 1 );
256
+ return $new_filename;
257
+ }
258
+
259
+ function get_post_from_media( $id ) {
260
+ global $wpdb;
261
+ $postid = $wpdb->get_var( $wpdb->prepare( "
262
+ SELECT post_parent p
263
+ FROM $wpdb->posts p
264
+ WHERE ID = %d", $id ),
265
+ 0, 0 );
266
+ if ( empty( $postid ) )
267
+ return null;
268
+ return get_post( $postid, OBJECT );
269
+ }
270
+
271
+ function wp_handle_upload_prefilter( $file ) {
272
+ $method = apply_filters( 'mfrh_method', 'media_title' );
273
+ if ( $method == 'media_title' ) {
274
+ $exif = wp_read_image_metadata( $file['tmp_name'] );
275
+ if ( !empty( $exif ) && isset( $exif[ 'title' ] ) && !empty( $exif[ 'title' ] ) ) {
276
+ $parts = pathinfo( $file['name'] );
277
+ $file['name'] = $this->new_filename( null, $exif[ 'title' ] ) . '.' . $parts['extension'];
278
+ return $file;
279
+ }
280
+ }
281
+ return $file;
282
+ }
283
+
284
+ // Return false if everything is fine, otherwise return true with an output.
285
+ function check_attachment( $id, &$output = array() ) {
286
+ $method = apply_filters( 'mfrh_method', 'media_title' );
287
+ if ( $method === 'none') {
288
+ delete_post_meta( $id, '_require_file_renaming' );
289
+ return false;
290
+ }
291
+ if ( get_post_meta( $id, '_manual_file_renaming', true ) ) {
292
+ $output['manual'] = true;
293
+ return false;
294
+ }
295
+
296
+ // Skip header images
297
+ if ( $this->is_header_image( $id ) ) {
298
+ delete_post_meta( $id, '_require_file_renaming' );
299
+ return false;
300
+ }
301
+
302
+ // Get information
303
+ $post = get_post( $id, ARRAY_A );
304
+ $base_title = $post['post_title'];
305
+ if ( $method == 'post_title' ) {
306
+ $attachedpost = $this->get_post_from_media( $post['ID'] );
307
+ if ( is_null( $attachedpost ) )
308
+ return false;
309
+ $base_title = $attachedpost->post_title;
310
+ }
311
+ else if ( $method == 'alt_text' ) {
312
+ $image_alt = get_post_meta( $post['ID'], '_wp_attachment_image_alt', true );
313
+ if ( is_null( $image_alt ) )
314
+ return false;
315
+ $base_title = $image_alt;
316
+ }
317
+ $desired_filename = $this->new_filename( $post, $base_title );
318
+ $old_filepath = get_attached_file( $post['ID'] );
319
+ $path_parts = pathinfo( $old_filepath );
320
+
321
+ // Dead file, let's forget it!
322
+ if ( !file_exists( $old_filepath ) ) {
323
+ delete_post_meta( $id, '_require_file_renaming' );
324
+ return false;
325
+ }
326
+
327
+ // Filename is equal to sanitized title
328
+ if ( $desired_filename == $path_parts['basename'] ) {
329
+ delete_post_meta( $id, '_require_file_renaming' );
330
+ return false;
331
+ }
332
+
333
+ // Send info to the requester function
334
+ $output['post_id'] = $post['ID'];
335
+ $output['post_name'] = $post['post_name'];
336
+ $output['post_title'] = $post['post_title'];
337
+ $output['current_filename'] = $path_parts['basename'];
338
+ $output['desired_filename'] = $desired_filename;
339
+ $output['desired_filename_exists'] = false;
340
+ if ( file_exists( $path_parts['dirname'] . "/" . $desired_filename ) ) {
341
+ $is_numbered = apply_filters( 'mfrh_numbered', false );
342
+ if ( $is_numbered ) {
343
+ $output['desired_filename'] = $this->generate_unique_filename( $path_parts['basename'],
344
+ $path_parts['dirname'], $desired_filename );
345
+ if ( $output['desired_filename'] == false ) {
346
+ delete_post_meta( $id, '_require_file_renaming' );
347
+ return false;
348
+ }
349
+ add_post_meta( $post['ID'], '_numbered_filename', $output['desired_filename'], true );
350
+ }
351
+ else {
352
+ $output['desired_filename_exists'] = true;
353
+ if ( strtolower( $output['current_filename'] ) == strtolower( $output['desired_filename'] ) ) {
354
+ // If Windows, let's be careful about the fact that case doesn't affect files
355
+ delete_post_meta( $post['ID'], '_require_file_renaming' );
356
+ return false;
357
+ }
358
+ }
359
+ }
360
+
361
+ // It seems it could be renamed :)
362
+ if ( !get_post_meta( $post['ID'], '_require_file_renaming' ) ) {
363
+ add_post_meta( $post['ID'], '_require_file_renaming', true, true );
364
+ }
365
+ return true;
366
+ }
367
+
368
+ function check_text() {
369
+ $issues = array();
370
+ global $wpdb;
371
+ $ids = $wpdb->get_col( "
372
+ SELECT p.ID
373
+ FROM $wpdb->posts p
374
+ WHERE post_status = 'inherit'
375
+ AND post_type = 'attachment'
376
+ " );
377
+ foreach ( $ids as $id )
378
+ if ( $this->check_attachment( $id, $output ) )
379
+ array_push( $issues, $output );
380
+ return $issues;
381
+ }
382
+
383
+ function generate_explanation( $file ) {
384
+ if ( $file['post_title'] == "" ) {
385
+ echo " <a class='button-primary' href='post.php?post=" . $file['post_id'] . "&action=edit'>" . __( 'Edit Media', 'media-file-renamer' ) . "</a><br /><small>" . __( 'This title cannot be used for a filename.', 'media-file-renamer' ) . "</small>";
386
+ }
387
+ else if ( $file['desired_filename_exists'] ) {
388
+ echo "<a class='button-primary' href='post.php?post=" . $file['post_id'] . "&action=edit'>" . __( 'Edit Media', 'media-file-renamer' ) . "</a><br /><small>" . __( 'The ideal filename already exists. If you would like to use a count and rename it, enable the <b>Numbered Files</b> option in the plugin settings.', 'media-file-renamer' ) . "</small>";
389
+ }
390
+ else {
391
+ $page = isset( $_GET['page'] ) ? ( '&page=' . $_GET['page'] ) : "";
392
+ $mfrh_scancheck = ( isset( $_GET ) && isset( $_GET['mfrh_scancheck'] ) ) ? '&mfrh_scancheck' : '';
393
+ $mfrh_to_rename = ( !empty( $_GET['to_rename'] ) && $_GET['to_rename'] == 1 ) ? '&to_rename=1' : '';
394
+ $modify_url = "post.php?post=" . $file['post_id'] . "&action=edit";
395
+ $page = isset( $_GET['page'] ) ? ( '&page=' . $_GET['page'] ) : "";
396
+
397
+ echo "<a class='button-primary' href='?" . $page . $mfrh_scancheck . $mfrh_to_rename . "&mfrh_rename=" . $file['post_id'] . "'>" . __( 'Auto-Rename', 'media-file-renamer' ) . "</a>";
398
+ echo "<a title='" . __( 'Click to lock it to manual only.', 'media-file-renamer' ) . "' href='?" . $page . "&mfrh_lock=" . $file['post_id'] . "'><span style='font-size: 16px; margin-top: 5px;' class='dashicons dashicons-unlock'></span></a>";
399
+
400
+ echo"<br /><small style='line-height: 8px;'>" .
401
+ sprintf( __( 'Rename to %s. You can also <a href="%s">edit this media</a>.', 'media-file-renamer' ), $file['desired_filename'], $modify_url ) . "</small>";
402
+ }
403
+ }
404
+
405
+ function rename_media_files() {
406
+ $hide_ads = get_option( 'meowapps_hide_ads' );
407
+ echo '<div class="wrap">';
408
+ echo $this->mfrh_admin->display_title( "Media File Renamer" );
409
+ echo '<p></p>';
410
+ global $wpdb;
411
+
412
+ $checkFiles = null;
413
+ if ( isset( $_GET ) && isset( $_GET['mfrh_scancheck'] ) )
414
+ $checkFiles = $this->check_text();
415
+ // FLAGGING
416
+ // if ( get_option( 'mfrh_flagging' ) ) {
417
+ // $this->file_counter( $flagged, $total, true );
418
+ // }
419
+ $all_media = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts p WHERE post_status = 'inherit' AND post_type = 'attachment'" );
420
+ $manual_media = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta WHERE meta_key = '_manual_file_renaming' AND meta_value = 1" );
421
+ ?>
422
+
423
+ <?php
424
+ if ( !$this->mfrh_admin->is_registered() ) {
425
+ echo '<div class="updated"><p>';
426
+ echo __( '<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> :) The serial key for the Pro has to be inserted in your Meow Apps > File Renamer > Pro. Thank you :)<br /><br /><a class="button-primary" href="http://meowapps.com/media-file-renamer/" target="_blank">Get the serial key for the Pro</a>', 'media-file-renamer' );
427
+ echo '</p></div>';
428
+ }
429
+ ?>
430
+
431
+ <h2>Rename in Bulk</h2>
432
+
433
+ <?php if ( get_option( 'mfrh_flagging' ) ): ?>
434
+ <p>
435
+ <b>There are <span class='mfrh-flagged' style='color: red;'><?php _e( $flagged ); ?></span> media files flagged for auto-renaming out of <?php _e( $total ); ?> in total.</b> Those are the files that couldn't be renamed on the fly when their names were updated. You can now rename those flagged media, or rename all of them (which will unlock them all and force their renaming). <span style='color: red; font-weight: bold;'>Please backup your uploads folder + DB before using this.</span>
436
+ </p>
437
+ <?php else: ?>
438
+ <p>
439
+ You might have noticed that some of your media are locked by the file renamer, others are unlocked. Automatically, the plugin locks the media you renamed manually. By default, they are unlocked. Here, you have the choice of rename all the media in your DB or only the ones which are unlocked (to keep the files you renamed manually). <span style='color: red; font-weight: bold;'>Please backup your uploads folder + DB before using this.</span>
440
+ </p>
441
+ <?php endif; ?>
442
+
443
+ <div style='margin-top: 12px; background: #FFF; padding: 5px; border-radius: 4px; height: 28px; box-shadow: 0px 0px 6px #C2C2C2;'>
444
+
445
+ <a onclick='mfrh_rename_media(false)' id='mfrh_rename_all_images' class='button-primary'
446
+ style='margin-right: 0px;'><span class="dashicons dashicons-controls-play" style="position: relative; top: 3px; left: -2px;"></span>
447
+ <?php echo sprintf( __( "Rename ALL [%d]", 'media-file-renamer' ), $all_media - $manual_media ); ?>
448
+ </a>
449
+ <a onclick='mfrh_rename_media(true)' id='mfrh_unlock_rename_all_images' class='button-primary'
450
+ style='margin-right: 10px;'><span class="dashicons dashicons-controls-play" style="position: relative; top: 3px; left: -2px;"></span>
451
+ <?php echo sprintf( __( "Unlock ALL & Rename [%d]", 'media-file-renamer' ), $all_media ); ?>
452
+ </a>
453
+ <span id='mfrh_progression'></span>
454
+
455
+ <?php if ( get_option( 'mfrh_flagging' ) ): ?>
456
+ <?php if ($flagged > 0): ?>
457
+ <a onclick='mfrh_rename_media(false)' id='mfrh_rename_dued_images' class='button-primary'>
458
+ <?php echo sprintf( __( "Rename <span class='mfrh-flagged'>%d</span> flagged media", 'media-file-renamer' ), $flagged ); ?>
459
+ </a>
460
+ <?php else: ?>
461
+ <a id='mfrh_rename_dued_images' class='button-primary'>
462
+ <?php echo sprintf( __( "Rename <span class='mfrh-flagged'>%d</span> flagged media", 'media-file-renamer' ), $flagged ); ?>
463
+ </a>
464
+ <?php endif; ?>
465
+ <?php endif; ?>
466
+
467
+ </div>
468
+
469
+ <h2>Rename 1 by 1</h2>
470
+ <p>If you want to rename the media this way, I recommend you to do it from the Media Library directly. If you think this "Scan All" is really handy, please tell me that you are using it on the forums. I am currently planning to remove it and moving the "Rename in Bulk" with the settings of File Renamer (to clean the WordPress UI).</p>
471
+ <table class='wp-list-table widefat fixed media' style='margin-top: 15px;'>
472
+ <thead>
473
+ <tr><th><?php _e( 'Title', 'media-file-renamer' ); ?></th><th><?php _e( 'Current Filename', 'media-file-renamer' ); ?></th><th><?php _e( 'Desired Filename', 'media-file-renamer' ); ?></th><th><?php _e( 'Action', 'media-file-renamer' ); ?></th></tr>
474
+ </thead>
475
+ <tfoot>
476
+ <tr><th><?php _e( 'Title', 'media-file-renamer' ); ?></th><th><?php _e( 'Current Filename', 'media-file-renamer' ); ?></th><th><?php _e( 'Desired Filename', 'media-file-renamer' ); ?></th><th><?php _e( 'Action', 'media-file-renamer' ); ?></th></tr>
477
+ </tfoot>
478
+ <tbody>
479
+ <?php
480
+ if ( $checkFiles != null ) {
481
+ foreach ( $checkFiles as $file ) {
482
+ echo "<tr><td><a href='post.php?post=" . $file['post_id'] . "&action=edit'>" . ( $file['post_title'] == "" ? "(no title)" : $file['post_title'] ) . "</a></td>"
483
+ . "<td>" . $file['current_filename'] . "</td>"
484
+ . "<td>" . $file['desired_filename'] . "</td>";
485
+ echo "<td>";
486
+ $this->generate_explanation( $file );
487
+ echo "</td></tr>";
488
+ }
489
+ }
490
+ else if ( isset( $_GET['mfrh_scancheck'] ) && ( $checkFiles == null || count( $checkFiles ) < 1 ) ) {
491
+ ?><tr><td colspan='4'><div style='width: 100%; margin-top: 15px; margin-bottom: 15px; text-align: center;'>
492
+ <div style='margin-top: 15px;'><?php _e( 'There are no issues. Cool!<br />Let\'s go visit <a target="_blank" href=\'http://jordymeow.com\'>The Offbeat Guide of Japan</a> :)', 'media-file-renamer' ); ?></div>
493
+ </div></td><?php
494
+ }
495
+ else if ( $checkFiles == null ) {
496
+ ?><tr><td colspan='4'><div style='width: 100%; text-align: center;'>
497
+ <a class='button-primary' href="?page=rename_media_files&mfrh_scancheck" style='margin-top: 15px; margin-bottom: 15px;'><span class="dashicons dashicons-admin-generic" style="position: relative; top: 3px; left: -2px;"></span>
498
+ <?php echo sprintf( __( "Scan All & Show Issues", 'media-file-renamer' ) ); ?>
499
+ </a>
500
+ </div></td><?php
501
+ }
502
+ ?>
503
+ </tbody>
504
+ </table>
505
+ </div>
506
+ <?php
507
+
508
+ // FUTURE AND TODO
509
+ // This shows the previous/new slug and previous/new filename for export to CSV
510
+ // SELECT p.ID,
511
+ // MAX(CASE WHEN m.meta_key = '_wp_old_slug' THEN m.meta_value ELSE NULL END) original_slug,
512
+ // post_name current_slug,
513
+ // MAX(CASE WHEN m.meta_key = '_original_filename' THEN m.meta_value ELSE NULL END) original_filemame,
514
+ // MAX(CASE WHEN m.meta_key = '_wp_attached_file' THEN m.meta_value ELSE NULL END) current_filename
515
+ // FROM wp_posts p
516
+ // LEFT JOIN wp_postmeta m ON p.ID = m.post_id
517
+ // WHERE post_status = 'inherit' AND post_type = 'attachment'
518
+
519
+ }
520
+
521
+ /**
522
+ *
523
+ * RENAME ON SAVE / PUBLISH
524
+ * Originally proposed by Ben Heller
525
+ * Added and modified by Jordy Meow
526
+ */
527
+
528
+ function rename_media_on_publish ( $post_id ) {
529
+ $onsave = get_option( "mfrh_rename_on_save" );
530
+ $args = array( 'post_type' => 'attachment',
531
+ 'numberposts' => -1, 'post_status' =>'any', 'post_parent' => $post_id );
532
+ $attachments = get_posts( $args );
533
+ if ( $attachments ) {
534
+ foreach ( $attachments as $attachment ) {
535
+ $attachment = get_post( $attachment, ARRAY_A );
536
+ $this->check_attachment( $attachment['ID'] );
537
+ if ( $onsave ) {
538
+ $this->rename_media( $attachment, $attachment, true );
539
+ }
540
+ }
541
+ }
542
+ }
543
+
544
+ function save_post( $post_id ) {
545
+ $status = get_post_status( $post_id );
546
+ if ( !in_array( $status, array( 'publish', 'future' ) ) )
547
+ return;
548
+ $this->rename_media_on_publish( $post_id );
549
+ }
550
+
551
+ /**
552
+ *
553
+ * EDITOR
554
+ *
555
+ */
556
+
557
+ function edit_attachment( $post_ID ) {
558
+ $this->log( '[edit_attachment]' );
559
+ $this->check_attachment( $post_ID, $output );
560
+ // $output['post_name']
561
+ }
562
+
563
+ function media_send_to_editor( $html, $attachment_id, $attachment ) {
564
+ $this->check_attachment( $attachment_id, $output );
565
+ return $html;
566
+ }
567
+
568
+ function add_rename_metabox() {
569
+ add_meta_box( 'mfrh_media', 'Filename', array( $this, 'attachment_fields' ), 'attachment', 'side', 'high' );
570
+ }
571
+
572
+ function attachment_fields( $post ) {
573
+ $info = pathinfo( get_attached_file( $post->ID ) );
574
+ $basename = $info['basename'];
575
+ $is_manual = apply_filters( 'mfrh_manual', false );
576
+ $html = '<input type="text" readonly class="widefat" name="mfrh_new_filename" value="' . $basename. '" />';
577
+ $html .= '<p class="description">This feature is for <a target="_blank" href="http://meowapps.com/media-file-renamer/">Pro users</a> only.</p>';
578
+ echo apply_filters( "mfrh_admin_attachment_fields", $html, $post );
579
+ return $post;
580
+ }
581
+
582
+ function attachment_save( $post, $attachment ) {
583
+ $this->log( '[attachment_save]' );
584
+ $method = apply_filters( 'mfrh_method', 'media_title' );
585
+ $info = pathinfo( get_attached_file( $post['ID'] ) );
586
+ $basename = $info['basename'];
587
+ $new = $post['mfrh_new_filename'];
588
+
589
+ // The filename is being changed manually, let's force it through $new.
590
+ if ( !empty( $new ) && $basename !== $new )
591
+ return $this->rename_media( $post, $attachment, false, $new );
592
+
593
+ $method = apply_filters( 'mfrh_method', 'media_title' );
594
+ if ( $method == 'media_title' ) {
595
+ // If the title was not changed, don't do anything.
596
+ if ( get_the_title( $post['ID'] ) == $post['post_title'] )
597
+ return $post;
598
+ return $this->rename_media( $post, $attachment, false, null );
599
+ }
600
+ return $post;
601
+ }
602
+
603
+ function log_sql( $data, $antidata ) {
604
+ if ( !get_option( 'mfrh_logsql' ) || !$this->mfrh_admin->is_registered() )
605
+ return;
606
+ $fh = fopen( trailingslashit( WP_PLUGIN_DIR ) . 'media-file-renamer/mfrh_sql.log', 'a' );
607
+ $fh_anti = fopen( trailingslashit( WP_PLUGIN_DIR ) . 'media-file-renamer/mfrh_sql_revert.log', 'a' );
608
+ $date = date( "Y-m-d H:i:s" );
609
+ fwrite( $fh, "{$data}\n" );
610
+ fwrite( $fh_anti, "{$antidata}\n" );
611
+ fclose( $fh );
612
+ fclose( $fh_anti );
613
+ }
614
+
615
+ function log( $data, $inErrorLog = false ) {
616
+ if ( $inErrorLog )
617
+ error_log( $data );
618
+ if ( !get_option( 'mfrh_log' ) )
619
+ return;
620
+ $fh = fopen( trailingslashit( WP_PLUGIN_DIR ) . 'media-file-renamer/media-file-renamer.log', 'a' );
621
+ $date = date( "Y-m-d H:i:s" );
622
+ fwrite( $fh, "$date: {$data}\n" );
623
+ fclose( $fh );
624
+ }
625
+
626
+ /**
627
+ *
628
+ * GENERATE A NEW FILENAME
629
+ *
630
+ */
631
+
632
+ function replace_special_chars( $str ) {
633
+ $special_chars = array(
634
+ "å" => "a", "Å" => "a",
635
+ "ä" => "ae", "Ä" => "ae",
636
+ "ö" => "oe", "Ö" => "oe",
637
+ "ü" => "ue", "Ü" => "ue",
638
+ "ß" => "ss", "ẞ" => "ss"
639
+ );
640
+ foreach ( $special_chars as $key => $value )
641
+ $str = str_replace( $key, $value, $str );
642
+ return $str;
643
+ }
644
+
645
+ // NEW MEDIA FILE INFO (depending on the title of the media)
646
+ function new_filename( $media, $title, $forceFilename = null ) {
647
+
648
+ // Clean the title
649
+ $title = str_replace( ".jpg", "", $title );
650
+ $title = str_replace( ".png", "", $title );
651
+ $title = str_replace( "'", "-", $title );
652
+
653
+ // Filename is forced (in case of manual, for example)
654
+ if ( $forceFilename )
655
+ $forceFilename = preg_replace( '/\\.[^.\\s]{3,4}$/', '', trim( $forceFilename ) );
656
+ if ( !empty( $forceFilename ) )
657
+ $new_filename = $forceFilename;
658
+ else {
659
+ $utf8_filename = apply_filters( 'mfrh_utf8', false );
660
+ if ( $utf8_filename )
661
+ $new_filename = sanitize_file_name( $title );
662
+ else
663
+ $new_filename = str_replace( "%", "-", sanitize_title( $this->replace_special_chars( $title ) ) );
664
+ }
665
+
666
+ if ( !empty( $media ) ) {
667
+ $old_filepath = get_attached_file( $media['ID'] );
668
+ $path_parts = pathinfo( $old_filepath );
669
+ $old_filename = $path_parts['basename'];
670
+ // This line is problematic during the further rename that exclude the extensions. Better to implement
671
+ // this properly with thorough testing later.
672
+ //$ext = str_replace( 'jpeg', 'jpg', $path_parts['extension'] ); // In case of a jpeg extension, rename it to jpg
673
+ $ext = $path_parts['extension'];
674
+ }
675
+ else {
676
+ // New upload, a filename without extension will be returned
677
+ $old_filename = null;
678
+ $ext = null;
679
+ }
680
+
681
+ if ( empty( $new_filename ) )
682
+ $new_filename = "empty";
683
+ $new_filename = !empty( $ext ) ? ( $new_filename . '.' . $ext ) : $new_filename;
684
+ if ( !$forceFilename )
685
+ $new_filename = apply_filters( 'mfrh_new_filename', $new_filename, $old_filename, $media );
686
+ return $new_filename;
687
+ }
688
+
689
+ // Only replace the first occurence
690
+ function str_replace( $needle, $replace, $haystack ) {
691
+ $pos = strpos( $haystack, $needle );
692
+ if ( $pos !== false ) {
693
+ $haystack = substr_replace( $haystack, $replace, $pos, strlen( $needle ) );
694
+ }
695
+ return $haystack;
696
+ }
697
+
698
+ /**
699
+ *
700
+ * RENAME FILES + COFFEE TIME
701
+ */
702
+
703
+ function call_hooks_rename_url( $post, $orig_image_url, $new_image_url ) {
704
+ // With the full URLs
705
+ do_action( 'mfrh_url_renamed', $post, $orig_image_url, $new_image_url );
706
+
707
+ // With DB URLs
708
+ $upload_dir = wp_upload_dir();
709
+ do_action( 'mfrh_url_renamed', $post, str_replace( $upload_dir, "", $orig_image_url ),
710
+ str_replace( $upload_dir, "", $new_image_url ) );
711
+ }
712
+
713
+ function rename_media( $post, $attachment, $disableMediaLibraryMode = false, $forceFilename = null ) {
714
+ $force = !empty( $forceFilename );
715
+ $manual = get_post_meta( $post['ID'], '_manual_file_renaming', true );
716
+
717
+ if ( $manual && !$forceFilename )
718
+ return $post;
719
+
720
+ $require = get_post_meta( $post['ID'], '_require_file_renaming', false );
721
+ $method = apply_filters( 'mfrh_method', 'media_title' );
722
+ $numbered_filename = get_post_meta( $post['ID'], '_numbered_filename', true );
723
+ if ( !empty( $numbered_filename ) ) {
724
+ $this->log( "Numbered filename ($numbered_filename) is being injected." );
725
+ $forceFilename = $numbered_filename;
726
+ delete_post_meta( $post['ID'], '_numbered_filename' );
727
+ }
728
+
729
+ // MEDIA TITLE & FILE PARTS
730
+ $meta = wp_get_attachment_metadata( $post['ID'] );
731
+ $old_filepath = get_attached_file( $post['ID'] ); // '2011/01/whatever.jpeg'
732
+ $path_parts = pathinfo( $old_filepath );
733
+ $directory = $path_parts['dirname']; // '2011/01'
734
+ $old_filename = $path_parts['basename']; // 'whatever.jpeg'
735
+ $old_ext = $path_parts['extension'];
736
+
737
+ // This line is problematic during the further rename that exclude the extensions. Better to implement
738
+ // this properly with thorough testing later.
739
+ //$ext = str_replace( 'jpeg', 'jpg', $path_parts['extension'] ); // In case of a jpeg extension, rename it to jpg
740
+ $ext = $path_parts['extension'];
741
+
742
+ $this->log( "** Rename Media: " . $old_filename );
743
+
744
+ // Was renamed manually? Avoid renaming when title has been changed.
745
+ if ( !$this->is_real_media( $post['ID'] ) ) {
746
+ $this->log( "Attachment {$post['ID']} looks like a translation, better not to continue." );
747
+ delete_post_meta( $post['ID'], '_require_file_renaming' );
748
+ return $post;
749
+ }
750
+
751
+ // If this is being renamed based on the post the media is attached to.
752
+ $base_new_title = $post['post_title'];
753
+ if ( !$force && $method == 'post_title' ) {
754
+ $linkedpost = $this->get_post_from_media( $post['ID'] );
755
+ if ( empty( $linkedpost ) ) {
756
+ $this->log( "Attachment {$post['ID']} is not linked to a post yet it seems." );
757
+ delete_post_meta( $post['ID'], '_require_file_renaming' );
758
+ return $post;
759
+ }
760
+ $base_new_title = $linkedpost->post_title;
761
+ }
762
+ else if ( !$force && $method == 'alt_text' ) {
763
+ $image_alt = get_post_meta( $post['ID'], '_wp_attachment_image_alt', true );
764
+ if ( empty( $image_alt ) ) {
765
+ $this->log( "Attachment {$post['ID']} has no alternative text it seems." );
766
+ delete_post_meta( $post['ID'], '_require_file_renaming' );
767
+ return $post;
768
+ }
769
+ $base_new_title = $image_alt;
770
+ }
771
+
772
+ // Empty post title when renaming using title? Let's not go further.
773
+ if ( !$force && empty( $base_new_title ) ) {
774
+ $this->log( "Title is empty, doesn't rename." );
775
+ delete_post_meta( $post['ID'], '_require_file_renaming' );
776
+ return $post;
777
+ }
778
+
779
+ // Is it a header image? Skip.
780
+ if ( $this->is_header_image( $post['ID'] ) ) {
781
+ $this->log( "Doesn't rename header image." );
782
+ delete_post_meta( $post['ID'], '_require_file_renaming' );
783
+ return $post;
784
+ }
785
+ if ( $manual && !$this->mfrh_admin->is_registered() ) {
786
+ return $post;
787
+ }
788
+
789
+ delete_post_meta( $post['ID'], '_manual_file_renaming' );
790
+ $sanitized_media_title = $this->new_filename( $post, $base_new_title, $forceFilename );
791
+ $this->log( "New file should be: " . $sanitized_media_title );
792
+
793
+ // Don't do anything if the media title didn't change or if it would turn to an empty string
794
+ if ( $path_parts['basename'] == $sanitized_media_title ) {
795
+ $this->log( "File seems renamed already." );
796
+ delete_post_meta( $post['ID'], '_require_file_renaming' );
797
+ return $post;
798
+ }
799
+
800
+ // MEDIA LIBRARY USAGE DETECTION
801
+ // Detects if the user is using the Media Library or 'Add an Image' (while a post edit)
802
+ // If it is not the Media Library, we don't rename, to avoid issues
803
+ $media_library_mode = !isset( $attachment['image-size'] ) || $disableMediaLibraryMode;
804
+ if ( !$media_library_mode ) {
805
+ // This media requires renaming
806
+ if ( !get_post_meta( $post['ID'], '_require_file_renaming' ) )
807
+ add_post_meta( $post['ID'], '_require_file_renaming', true, true );
808
+ $this->log( "Seems like the user is editing a post. Marked the file as to be renamed." );
809
+ return $post;
810
+ }
811
+
812
+ // NEW DESTINATION FILES ALREADY EXISTS - WE DON'T DO NOTHING
813
+ $force_rename = apply_filters( 'mfrh_force_rename', false );
814
+ $new_filepath = trailingslashit( $directory ) . $sanitized_media_title;
815
+ if ( !$force_rename && file_exists( $directory . "/" . $sanitized_media_title ) ) {
816
+ $desired = false;
817
+ $is_numbered = apply_filters( 'mfrh_numbered', false );
818
+ if ( $is_numbered ) {
819
+ $desired = $this->generate_unique_filename( $old_filename,
820
+ $path_parts['dirname'], $sanitized_media_title );
821
+ }
822
+ if ( $desired != false ) {
823
+ $this->log( "Seems like $sanitized_media_title could be numbered as $desired." );
824
+ $new_filepath = trailingslashit( $directory ) . $desired;
825
+ $sanitized_media_title = $desired;
826
+ }
827
+ else {
828
+ if ( !get_post_meta( $post['ID'], '_require_file_renaming' ) )
829
+ add_post_meta( $post['ID'], '_require_file_renaming', true, true );
830
+ $this->log( "The new file already exists ($new_filepath), it is safer to avoid doing anything." );
831
+ return $post;
832
+ }
833
+ }
834
+
835
+ // Exact same code as rename-media, it's a good idea to keep track of the original filename.
836
+ $original_filename = get_post_meta( $post['ID'], '_original_filename', true );
837
+ if ( empty( $original_filename ) )
838
+ add_post_meta( $post['ID'], '_original_filename', $old_filename, true );
839
+
840
+ // Rename the main media file.
841
+ try {
842
+ if ( ( !file_exists( $old_filepath ) || !rename( $old_filepath, $new_filepath ) ) && !$force_rename ) {
843
+ $this->log( "The file couldn't be renamed from $old_filepath to $new_filepath." );
844
+ return $post;
845
+ }
846
+ $this->log( "File $old_filepath renamed to $new_filepath." );
847
+ do_action( 'mfrh_path_renamed', $post, $old_filepath, $new_filepath );
848
+ }
849
+ catch (Exception $e) {
850
+ return $post;
851
+ }
852
+
853
+ // Filenames without extensions
854
+ $noext_old_filename = $this->str_replace( '.' . $old_ext, '', $old_filename );
855
+ $noext_new_filename = $this->str_replace( '.' . $ext, '', $sanitized_media_title );
856
+ $this->log( "Files with no extensions: $noext_old_filename and $noext_new_filename." );
857
+
858
+ // Update the attachment meta
859
+ if ( $meta ) {
860
+ $meta['file'] = $this->str_replace( $noext_old_filename, $noext_new_filename, $meta['file'] );
861
+ if ( isset( $meta["url"] ) && $meta["url"] != "" && count( $meta["url"] ) > 4 )
862
+ $meta["url"] = $this->str_replace( $noext_old_filename, $noext_new_filename, $meta["url"] );
863
+ else
864
+ $meta["url"] = $noext_new_filename . "." . $ext;
865
+ }
866
+
867
+ // Images
868
+ if ( wp_attachment_is_image( $post['ID'] ) ) {
869
+ // Loop through the different sizes in the case of an image, and rename them.
870
+ $orig_image_urls = array();
871
+ $orig_image_data = wp_get_attachment_image_src( $post['ID'], 'full' );
872
+ $orig_image_urls['full'] = $orig_image_data[0];
873
+ if ( empty( $meta['sizes'] ) ) {
874
+ $this->log( "The WP metadata for attachment " . $post['ID'] . " does not exist.", true );
875
+ }
876
+ else {
877
+ foreach ( $meta['sizes'] as $size => $meta_size ) {
878
+ if ( !isset($meta['sizes'][$size]['file'] ) )
879
+ continue;
880
+ $meta_old_filename = $meta['sizes'][$size]['file'];
881
+ $meta_old_filepath = trailingslashit( $directory ) . $meta_old_filename;
882
+ $meta_new_filename = $this->str_replace( $noext_old_filename, $noext_new_filename, $meta_old_filename );
883
+ $meta_new_filepath = trailingslashit( $directory ) . $meta_new_filename;
884
+ $orig_image_data = wp_get_attachment_image_src( $post['ID'], $size );
885
+ $orig_image_urls[$size] = $orig_image_data[0];
886
+ // ak: Double check files exist before trying to rename.
887
+ if ( $force_rename || ( file_exists( $meta_old_filepath ) && ( ( !file_exists( $meta_new_filepath ) )
888
+ || is_writable( $meta_new_filepath ) ) ) ) {
889
+ // WP Retina 2x is detected, let's rename those files as well
890
+ if ( function_exists( 'wr2x_generate_images' ) ) {
891
+ $wr2x_old_filepath = $this->str_replace( '.' . $ext, '@2x.' . $ext, $meta_old_filepath );
892
+ $wr2x_new_filepath = $this->str_replace( '.' . $ext, '@2x.' . $ext, $meta_new_filepath );
893
+ if ( file_exists( $wr2x_old_filepath ) && ( (!file_exists( $wr2x_new_filepath ) ) || is_writable( $wr2x_new_filepath ) ) ) {
894
+ @rename( $wr2x_old_filepath, $wr2x_new_filepath );
895
+ $this->log( "Retina file $wr2x_old_filepath renamed to $wr2x_new_filepath." );
896
+ do_action( 'mfrh_path_renamed', $post, $wr2x_old_filepath, $wr2x_new_filepath );
897
+ }
898
+ }
899
+ @rename( $meta_old_filepath, $meta_new_filepath );
900
+ $meta['sizes'][$size]['file'] = $meta_new_filename;
901
+ $this->log( "File $meta_old_filepath renamed to $meta_new_filepath." );
902
+ do_action( 'mfrh_path_renamed', $post, $meta_old_filepath, $meta_new_filepath );
903
+ }
904
+ }
905
+ }
906
+ }
907
+ else {
908
+ $orig_attachment_url = wp_get_attachment_url( $post['ID'] );
909
+ }
910
+
911
+ // This media doesn't require renaming anymore
912
+ delete_post_meta( $post['ID'], '_require_file_renaming' );
913
+ if ( $force ) {
914
+ add_post_meta( $post['ID'], '_manual_file_renaming', true, true );
915
+ }
916
+
917
+ // Update metadata
918
+ if ( $meta )
919
+ wp_update_attachment_metadata( $post['ID'], $meta );
920
+ update_attached_file( $post['ID'], $new_filepath );
921
+ clean_post_cache( $post['ID'] );
922
+
923
+ // Call the actions so that the plugin's plugins can update everything else (than the files)
924
+ if ( wp_attachment_is_image( $post['ID'] ) ) {
925
+ $orig_image_url = $orig_image_urls['full'];
926
+ $new_image_data = wp_get_attachment_image_src( $post['ID'], 'full' );
927
+ $new_image_url = $new_image_data[0];
928
+ $this->call_hooks_rename_url( $post, $orig_image_url, $new_image_url );
929
+
930
+ if ( !empty( $meta['sizes'] ) ) {
931
+ foreach ( $meta['sizes'] as $size => $meta_size ) {
932
+ $orig_image_url = $orig_image_urls[$size];
933
+ $new_image_data = wp_get_attachment_image_src( $post['ID'], $size );
934
+ $new_image_url = $new_image_data[0];
935
+ $this->call_hooks_rename_url( $post, $orig_image_url, $new_image_url );
936
+ }
937
+ }
938
+ }
939
+ else {
940
+ $new_attachment_url = wp_get_attachment_url( $post['ID'] );
941
+ $this->call_hooks_rename_url( $post, $orig_attachment_url, $new_attachment_url );
942
+ }
943
+
944
+ // SLUG
945
+ if ( get_option( "mfrh_rename_slug" ) ) {
946
+ $oldslug = $post['post_name'];
947
+ $info = pathinfo( $new_filepath );
948
+ $newslug = preg_replace( '/\\.[^.\\s]{3,4}$/', '', $info['basename'] );
949
+ $post['post_name'] = $newslug;
950
+ $this->log( "Slug $oldslug set to $newslug." );
951
+ wp_update_post( $post );
952
+ }
953
+
954
+ // HTTP REFERER set to the new media link
955
+ if ( isset( $_REQUEST['_wp_original_http_referer'] ) && strpos( $_REQUEST['_wp_original_http_referer'], '/wp-admin/' ) === false ) {
956
+ $_REQUEST['_wp_original_http_referer'] = get_permalink( $post['ID'] );
957
+ }
958
+
959
+ do_action( 'mfrh_media_renamed', $post, $old_filepath, $new_filepath );
960
+ return $post;
961
+ }
962
+
963
+ /**
964
+ *
965
+ * INTERNAL ACTIONS (HOOKS)
966
+ * Mostly from the Side-Updates
967
+ *
968
+ * Available actions are:
969
+ * mfrh_path_renamed
970
+ * mfrh_url_renamed
971
+ * mfrh_media_renamed
972
+ *
973
+ */
974
+
975
+ // Register internal actions
976
+ function init_actions() {
977
+ if ( get_option( "mfrh_update_posts", true ) )
978
+ add_action( 'mfrh_url_renamed', array( $this, 'action_update_posts' ), 10, 3 );
979
+ if ( get_option( "mfrh_update_postmeta", true ) )
980
+ add_action( 'mfrh_url_renamed', array( $this, 'action_update_postmeta' ), 10, 3 );
981
+
982
+ if ( get_option( "mfrh_rename_guid" ) ) {
983
+ add_action( 'mfrh_media_renamed', array( $this, 'action_rename_guid' ), 10, 3 );
984
+ }
985
+ }
986
+
987
+ // The GUID should never be updated but... this will if the option is checked.
988
+ // [TigrouMeow] It the recent version of WordPress, the GUID is not part of the $post (even though it is in database)
989
+ // Explanation: http://pods.io/2013/07/17/dont-use-the-guid-field-ever-ever-ever/
990
+ function action_rename_guid( $post, $old_filepath, $new_filepath ) {
991
+ $meta = wp_get_attachment_metadata( $post['ID'] );
992
+ $old_guid = get_the_guid( $post['ID'] );
993
+ if ( $meta )
994
+ $new_filepath = wp_get_attachment_url( $post['ID'] );
995
+ global $wpdb;
996
+ $query = $wpdb->prepare( "UPDATE $wpdb->posts SET guid = '%s' WHERE ID = '%d'", $new_filepath, $post['ID'] );
997
+ $query_revert = $wpdb->prepare( "UPDATE $wpdb->posts SET guid = '%s' WHERE ID = '%d'", $old_guid, $post['ID'] );
998
+ $this->log_sql( $query, $query_revert );
999
+ $wpdb->query( $query );
1000
+ clean_post_cache( $post['ID'] );
1001
+ $this->log( "Guid $old_guid changed to $new_filepath." );
1002
+ }
1003
+
1004
+ // Mass update of all the meta with the new filenames
1005
+ function action_update_postmeta( $post, $orig_image_url, $new_image_url ) {
1006
+ global $wpdb;
1007
+ $query = $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_value = '%s'
1008
+ WHERE meta_key <> '_original_filename'
1009
+ AND (TRIM(meta_value) = '%s'
1010
+ OR TRIM(meta_value) = '%s'
1011
+ );", $new_image_url, $orig_image_url, str_replace( ' ', '%20', $orig_image_url ) );
1012
+ $query_revert = $wpdb->prepare( "UPDATE $wpdb->postmeta SET meta_value = '%s'
1013
+ WHERE meta_key <> '_original_filename'
1014
+ AND meta_value = '%s';
1015
+ ", $orig_image_url, $new_image_url );
1016
+ $wpdb->query( $query );
1017
+ $this->log_sql( $query, $query_revert );
1018
+
1019
+ //_wp_attached_file
1020
+
1021
+ $this->log( "Metadata exactly like $orig_image_url were replaced by $new_image_url." );
1022
+ }
1023
+
1024
+ // Mass update of all the articles with the new filenames
1025
+ function action_update_posts( $post, $orig_image_url, $new_image_url ) {
1026
+ global $wpdb;
1027
+
1028
+ // Content
1029
+ $query = $wpdb->prepare( "UPDATE $wpdb->posts SET post_content = REPLACE(post_content, '%s', '%s');", $orig_image_url, $new_image_url );
1030
+ $query_revert = $wpdb->prepare( "UPDATE $wpdb->posts SET post_content = REPLACE(post_content, '%s', '%s');", $new_image_url, $orig_image_url );
1031
+ $wpdb->query( $query );
1032
+ $this->log_sql( $query, $query_revert );
1033
+ $this->log( "Post content like $orig_image_url were replaced by $new_image_url." );
1034
+
1035
+ // Excerpt
1036
+ $query = $wpdb->prepare( "UPDATE $wpdb->posts SET post_excerpt = REPLACE(post_excerpt, '%s', '%s');", $orig_image_url, $new_image_url );
1037
+ $query_revert = $wpdb->prepare( "UPDATE $wpdb->posts SET post_excerpt = REPLACE(post_excerpt, '%s', '%s');", $new_image_url, $orig_image_url );
1038
+ $wpdb->query( $query );
1039
+ $this->log_sql( $query, $query_revert );
1040
+ $this->log( "Post content like $orig_image_url were replaced by $new_image_url." );
1041
+ }
1042
+ }
1043
+
1044
+ /*******************************************************************************
1045
+ * OLD PRO / TODO: THIS FUNCTION SHOULD BE REMOVED IN THE FUTURE
1046
+ ******************************************************************************/
1047
+
1048
+ add_action( 'admin_notices', 'mfrh_admin_notices' );
1049
+
1050
+ function mfrh_admin_notices() {
1051
+ if ( isset( $_POST['mfrh_reset_sub'] ) ) {
1052
+ delete_transient( 'mfrh_validated' );
1053
+ delete_option( 'mfrh_pro_serial' );
1054
+ delete_option( 'mfrh_pro_status' );
1055
+ }
1056
+ $validated = get_transient( 'mfrh_validated' );
1057
+ $subscr_id = get_option( 'mfrh_pro_serial', "" );
1058
+ if ( empty( $subscr_id ) || empty( $validated ) )
1059
+ return;
1060
+ $forever = strpos( $subscr_id, 'F-' ) !== false;
1061
+ $yearly = strpos( $subscr_id, 'I-' ) !== false;
1062
+ ?>
1063
+ <div class="error">
1064
+ <p>
1065
+ <b>IMPORTANT MESSAGE ABOUT MEDIA FILE RENAMER.</b>
1066
+ In order to comply with WordPress.org rules, big changes in the code and how the plugin was sold had to be made. The plugin now requires to be bought through <a target='_blank' href="https://store.meowapps.com">https://store.meowapps.com</a>. You will be able to download the Pro version there, manage your keys and websites. It is a much more robust system. Since only the free version can be hosted by WordPress.org, this is the one which is active now. I am trying to ease this upgrade, depending on your current license.<br /><br />
1067
+ Your license is <b><?php echo $subscr_id ?></b>.
1068
+ <?php
1069
+ if ( $forever ) {
1070
+ echo "You have a Forever license. If you got this license less than 160 days ago, reply to the welcome e-mail (after buying a new license) with your previous license key ($subscr_id) and the e-mail you are using in Paypal. I will refund the previous payment. If it is more than 160 days, we are out of luck. So here is a discount of <b>90% off</b>, for any license you like: <b>UPGRADE90FILERENAMER</b>. If you use the discount, the refund will be of course not possible.";
1071
+ }
1072
+ else if ( $yearly ) {
1073
+ echo "You have a Yearly license. If you got this license less than 160 days ago, reply to the welcome e-mail (after buying a new license) with your previous license key ($subscr_id) and the e-mail you are using in Paypal. I will refund the previous payment. If it is more than 160 days ago, we are out of luck. So here is a discount of <b>50% off</b>, for any license you like: <b>UPGRADEFILERENAMER50</b>. Also, don't forget to cancel your current subscription in Paypal (<a target='_blank' href='https://www.paypal.com/us/selfhelp/article/How-do-I-cancel-an-automatic-payment-I-have-with-a-merchant-FAQ2058'>click here</a> if you don't know how to do this).";
1074
+ }
1075
+ else {
1076
+ echo "Your license is special, so please contact me.";
1077
+ }
1078
+ ?>
1079
+ If you absolutely need to use the plugin as it was before, with your current license key, please download it again here: <a target='_blank' href="https://meowapps.com/previous-versions/">Previous Versions</a>. I will keep the old system up for a while, but no updates will be possible.
1080
+ <br /><br />Also note that I also have now an <a target='_blank' href='https://store.meowapps.com/affiliate-area/'>Affiliate Program</a> in that store, don't hesitate to register for it. Thanks a lot for your comprehension and sorry for the troubles. Not easy for anyone but it had to be done and I think you will really enjoy the new store more than the previous clunky system. I wrote a little post about this change here, so don't hesitate to add a comment if you have a question: <a href="https://meowapps.com/migration-store/">Migration to the Meow Apps Store</a>.
1081
+ </p>
1082
+ <p>
1083
+ <form method="post" action="">
1084
+ <input type="hidden" name="mfrh_reset_sub" value="true">
1085
+ <input type="submit" name="submit" id="submit" class="button" value="Got it. Understood!">
1086
+ <br /><small>Make sure you got a new license and all before clicking this button. <b>It will also clean your install from the old serial key.</b></small>
1087
+ </form>
1088
+ </p>
1089
+ </div>
1090
+ <?php
1091
+ }
media-file-renamer.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
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: 3.4.6
7
+ Author: Jordy Meow
8
+ Author URI: http://meowapps.com
9
+ Text Domain: media-file-renamer
10
+ Domain Path: /languages
11
+
12
+ Dual licensed under the MIT and GPL licenses:
13
+ http://www.opensource.org/licenses/mit-license.php
14
+ http://www.gnu.org/licenses/gpl.html
15
+
16
+ Originally developed for two of my websites:
17
+ - Jordy Meow (http://jordymeow.com)
18
+ - Haikyo (http://haikyo.org)
19
+ */
20
+
21
+ if ( is_admin() ) {
22
+
23
+ global $mfrh_version;
24
+ $mfrh_version = '3.4.6';
25
+
26
+ // Admin
27
+ require( 'mfrh_admin.php');
28
+ $mfrh_admin = new Meow_MFRH_Admin( 'mfrh', __FILE__, 'media-file-renamer' );
29
+
30
+ // Core
31
+ require( 'core.php' );
32
+ $mfrh_core = new Meow_MFRH_Core( $mfrh_admin );
33
+ }
mfrh_admin.php ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ include "common/admin.php";
4
+
5
+ class Meow_MFRH_Admin extends MeowApps_Admin {
6
+
7
+ public function __construct( $prefix, $mainfile, $domain ) {
8
+ parent::__construct( $prefix, $mainfile, $domain );
9
+ if ( is_admin() ) {
10
+ add_action( 'admin_menu', array( $this, 'app_menu' ) );
11
+ add_action( 'admin_notices', array( $this, 'admin_notices' ) );
12
+ }
13
+ }
14
+
15
+ function admin_notices() {
16
+ if ( isset( $_GET['reset'] ) ) {
17
+ if ( file_exists( plugin_dir_path( __FILE__ ) . '/media-file-renamer.log' ) )
18
+ unlink( plugin_dir_path( __FILE__ ) . '/media-file-renamer.log' );
19
+ if ( file_exists( plugin_dir_path( __FILE__ ) . '/mfrh_sql.log' ) )
20
+ unlink( plugin_dir_path( __FILE__ ) . '/mfrh_sql.log' );
21
+ if ( file_exists( plugin_dir_path( __FILE__ ) . '/mfrh_sql_revert.log' ) )
22
+ unlink( plugin_dir_path( __FILE__ ) . '/mfrh_sql_revert.log' );
23
+ }
24
+ $method = apply_filters( 'mfrh_method', 'media_title' );
25
+ $sync_alt = get_option( 'mfrh_sync_alt' );
26
+ if ( $sync_alt && $method == 'alt_text' ) {
27
+ update_option( 'mfrh_sync_alt', false, false );
28
+ ?>
29
+ <div class="notice notice-warning is-dismissible">
30
+ <p><?php _e( 'The option Sync ALT was turned off since it does not make sense to have it with this Auto-Rename mode.', 'media-file-renamer' ); ?></p>
31
+ </div>
32
+ <?php
33
+ }
34
+ }
35
+
36
+ function common_url( $file ) {
37
+ return trailingslashit( plugin_dir_url( __FILE__ ) ) . 'common/' . $file;
38
+ }
39
+
40
+ function app_menu() {
41
+
42
+ $method = apply_filters( 'mfrh_method', 'media_title' );
43
+
44
+ // SUBMENU > Settings
45
+ add_submenu_page( 'meowapps-main-menu', 'Media File Renamer', 'Media Renamer', 'manage_options',
46
+ 'mfrh_settings-menu', array( $this, 'admin_settings' ) );
47
+
48
+ // SUBMENU > Settings > Basic Settings
49
+ add_settings_section( 'mfrh_settings', null, null, 'mfrh_settings-menu' );
50
+ add_settings_field( 'mfrh_auto_rename', "Auto Rename",
51
+ array( $this, 'admin_auto_rename_callback' ),
52
+ 'mfrh_settings-menu', 'mfrh_settings' );
53
+ add_settings_field( 'mfrh_on_upload', "On Upload",
54
+ array( $this, 'admin_on_upload_callback' ),
55
+ 'mfrh_settings-menu', 'mfrh_settings' );
56
+
57
+ add_settings_field( 'mfrh_rename_slug', "Sync Slug<br /><i>Permalink</i>",
58
+ array( $this, 'admin_rename_slug_callback' ),
59
+ 'mfrh_settings-menu', 'mfrh_settings' );
60
+
61
+ register_setting( 'mfrh_settings', 'mfrh_auto_rename' );
62
+ register_setting( 'mfrh_settings', 'mfrh_on_upload' );
63
+ register_setting( 'mfrh_settings', 'mfrh_rename_slug' );
64
+
65
+ // SUBMENU > Settings > Side Settings
66
+ add_settings_section( 'mfrh_side_settings', null, null, 'mfrh_side_settings-menu' );
67
+ add_settings_field( 'mfrh_update_posts', __( 'Posts', 'media-file-renamer' ),
68
+ array( $this, 'admin_update_posts_callback' ),
69
+ 'mfrh_side_settings-menu', 'mfrh_side_settings' );
70
+ add_settings_field( 'mfrh_update_postmeta', __( 'Post Meta', 'media-file-renamer' ),
71
+ array( $this, 'admin_update_postmeta_callback' ),
72
+ 'mfrh_side_settings-menu', 'mfrh_side_settings' );
73
+
74
+ register_setting( 'mfrh_side_settings', 'mfrh_update_posts' );
75
+ register_setting( 'mfrh_side_settings', 'mfrh_update_postmeta' );
76
+
77
+ // SUBMENU > Settings > Advanced Settings
78
+ add_settings_section( 'mfrh_advanced_settings', null, null, 'mfrh_advanced_settings-menu' );
79
+ add_settings_field( 'mfrh_undo', "Undo",
80
+ array( $this, 'admin_undo_callback' ),
81
+ 'mfrh_advanced_settings-menu', 'mfrh_advanced_settings' );
82
+ add_settings_field( 'mfrh_manual_rename', "Manual Rename<br />(Pro)",
83
+ array( $this, 'admin_manual_rename_callback' ),
84
+ 'mfrh_advanced_settings-menu', 'mfrh_advanced_settings' );
85
+ add_settings_field( 'mfrh_numbered_files', "Numbered Files<br />(Pro)",
86
+ array( $this, 'admin_numbered_files_callback' ),
87
+ 'mfrh_advanced_settings-menu', 'mfrh_advanced_settings' );
88
+
89
+ if ( $method == 'media_title' || $method == 'post_title' ) {
90
+ add_settings_field( 'mfrh_sync_alt', "Sync ALT<br />(Pro)",
91
+ array( $this, 'admin_sync_alt_callback' ),
92
+ 'mfrh_advanced_settings-menu', 'mfrh_advanced_settings' );
93
+ }
94
+
95
+ register_setting( 'mfrh_advanced_settings', 'mfrh_undo' );
96
+ register_setting( 'mfrh_advanced_settings', 'mfrh_manual_rename' );
97
+ register_setting( 'mfrh_advanced_settings', 'mfrh_numbered_files' );
98
+ register_setting( 'mfrh_advanced_settings', 'mfrh_sync_alt' );
99
+
100
+ // SUBMENU > Settings > Developer Settings
101
+ add_settings_section( 'mfrh_developer_settings', null, null, 'mfrh_developer_settings-menu' );
102
+ add_settings_field( 'mfrh_utf8_filename', __( 'UTF-8 Filename<br />(Pro)', 'media-file-renamer' ),
103
+ array( $this, 'admin_utf8_filename_callback' ),
104
+ 'mfrh_developer_settings-menu', 'mfrh_developer_settings' );
105
+ add_settings_field( 'mfrh_force_rename', __( 'Force Rename<br />(Pro)', 'media-file-renamer' ),
106
+ array( $this, 'admin_force_rename_callback' ),
107
+ 'mfrh_developer_settings-menu', 'mfrh_developer_settings' );
108
+ add_settings_field( 'mfrh_log', __( 'Logs', 'media-file-renamer' ),
109
+ array( $this, 'admin_log_callback' ),
110
+ 'mfrh_developer_settings-menu', 'mfrh_developer_settings' );
111
+ add_settings_field( 'mfrh_logsql', __( 'SQL Logs<br />(Pro)', 'media-file-renamer' ),
112
+ array( $this, 'admin_logsql_callback' ),
113
+ 'mfrh_developer_settings-menu', 'mfrh_developer_settings' );
114
+ add_settings_field( 'mfrh_rename_guid', "Sync GUID",
115
+ array( $this, 'admin_rename_guid_callback' ),
116
+ 'mfrh_developer_settings-menu', 'mfrh_developer_settings' );
117
+ add_settings_field( 'mfrh_rename_on_save', "Rename on Post Save",
118
+ array( $this, 'admin_rename_on_save_callback' ),
119
+ 'mfrh_developer_settings-menu', 'mfrh_developer_settings' );
120
+
121
+ register_setting( 'mfrh_developer_settings', 'mfrh_rename_guid' );
122
+ register_setting( 'mfrh_developer_settings', 'mfrh_utf8_filename' );
123
+ register_setting( 'mfrh_developer_settings', 'mfrh_force_rename' );
124
+ register_setting( 'mfrh_developer_settings', 'mfrh_log' );
125
+ register_setting( 'mfrh_developer_settings', 'mfrh_logsql' );
126
+ register_setting( 'mfrh_developer_settings', 'mfrh_rename_on_save' );
127
+ }
128
+
129
+ function admin_settings() {
130
+ ?>
131
+ <div class="wrap">
132
+ <?php echo $this->display_title( "Media File Renamer" ); ?>
133
+
134
+ <div class="meow-row">
135
+ <div class="meow-box meow-col meow-span_2_of_2">
136
+ <h3>How to use</h3>
137
+ <div class="inside">
138
+ <?php echo _e( 'This plugin works out of the box, the default settings are the best for most installs. However, you should have a look at the <a target="_blank" href="https://meowapps.com/media-file-renamer/">tutorial</a>.', 'media-file-renamer' ) ?>
139
+ </div>
140
+ </div>
141
+ </div>
142
+
143
+ <div class="meow-row">
144
+
145
+ <div class="meow-col meow-span_1_of_2">
146
+
147
+ <div class="meow-box">
148
+ <h3>Settings</h3>
149
+ <div class="inside">
150
+ <form method="post" action="options.php">
151
+ <?php settings_fields( 'mfrh_settings' ); ?>
152
+ <?php do_settings_sections( 'mfrh_settings-menu' ); ?>
153
+ <?php submit_button(); ?>
154
+ </form>
155
+ </div>
156
+ </div>
157
+
158
+ <div class="meow-box">
159
+ <h3>Side Updates</h3>
160
+ <div class="inside">
161
+ <p><?php _e( 'When the files are renamed, many links to them on your WordPress might be broken. Those options are updating the references to those files. <b>Give it a try, every install is different and it might not work for certain kind of references.</b>', 'media-file-renamer' );
162
+ ?></p>
163
+ <form method="post" action="options.php">
164
+ <?php settings_fields( 'mfrh_side_settings' ); ?>
165
+ <?php do_settings_sections( 'mfrh_side_settings-menu' ); ?>
166
+ <?php submit_button(); ?>
167
+ </form>
168
+ </div>
169
+ </div>
170
+
171
+ </div>
172
+
173
+ <div class="meow-col meow-span_1_of_2">
174
+ <?php $this->display_serialkey_box( "https://meowapps.com/media-file-renamer/" ); ?>
175
+
176
+ <div class="meow-box">
177
+ <h3>Advanced Settings</h3>
178
+ <div class="inside">
179
+ <form method="post" action="options.php">
180
+ <?php settings_fields( 'mfrh_advanced_settings' ); ?>
181
+ <?php do_settings_sections( 'mfrh_advanced_settings-menu' ); ?>
182
+ <?php submit_button(); ?>
183
+ </form>
184
+ </div>
185
+ </div>
186
+
187
+ <div class="meow-box">
188
+ <h3>Developer Settings</h3>
189
+ <div class="inside">
190
+ <form method="post" action="options.php">
191
+ <?php settings_fields( 'mfrh_developer_settings' ); ?>
192
+ <?php do_settings_sections( 'mfrh_developer_settings-menu' ); ?>
193
+ <?php _e( 'Do you want to clear/reset the logs? Click <a href="?page=mfrh_settings-menu&reset=true">here</a>.</b>', 'media-file-renamer' ); ?>
194
+ <?php submit_button(); ?>
195
+ </form>
196
+ </div>
197
+ </div>
198
+
199
+ </div>
200
+
201
+ </div>
202
+
203
+ </div>
204
+ <?php
205
+ }
206
+
207
+ /*
208
+ OPTIONS CALLBACKS
209
+ */
210
+
211
+ function admin_rename_slug_callback( $args ) {
212
+ $value = get_option( 'mfrh_rename_slug', null );
213
+ $html = '<input type="checkbox" id="mfrh_rename_slug" name="mfrh_rename_slug" value="1" ' .
214
+ checked( 1, get_option( 'mfrh_rename_slug' ), false ) . '/>';
215
+ $html .= __( '<label>Slug = Filename</label><br /><small>Better to keep this un-checked as the link might have been referenced somewhere else.</small>', 'media-file-renamer' );
216
+ echo $html;
217
+ }
218
+
219
+ function admin_manual_rename_callback( $args ) {
220
+ $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="mfrh_manual_rename" name="mfrh_manual_rename" value="1" ' .
221
+ checked( 1, apply_filters( 'mfrh_manual', false ), false ) . '/>';
222
+ $html .= '<label>Enable</label><br /><small>Manual field will be enabled in the Media Edit screen.</small>';
223
+ echo $html;
224
+ }
225
+
226
+ function admin_numbered_files_callback( $args ) {
227
+ $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="mfrh_numbered_files" name="mfrh_numbered_files" value="1" ' .
228
+ checked( 1, apply_filters( 'mfrh_numbered', false ), false ) . '/>';
229
+ $html .= __( '<label>Enable Numbering</label><br /><small>Identical filenames will be allowed by the plugin and a number will be appended automatically (myfile.jpg, myfile-2.jpg, myfile-3.jpg, etc).</small>', 'media-file-renamer' );
230
+ echo $html;
231
+ }
232
+
233
+ function admin_rename_guid_callback( $args ) {
234
+ $html = '<input type="checkbox" id="mfrh_rename_guid" name="mfrh_rename_guid" value="1" ' .
235
+ checked( 1, get_option( 'mfrh_rename_guid' ), false ) . '/>';
236
+ $html .= __( '<label>GUID = Filename</label><br/><small>The GUID will be renamed like the new filename.<br /><small>Better to keep this un-checked.</small>', 'media-file-renamer' );
237
+ echo $html;
238
+ }
239
+
240
+ function admin_sync_alt_callback( $args ) {
241
+ $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="mfrh_sync_alt" name="mfrh_sync_alt" value="1" ' .
242
+ checked( 1, get_option( 'mfrh_sync_alt' ), false ) . '/>';
243
+ $method = apply_filters( 'mfrh_method', 'media_title' );
244
+ $what = __( "Error!", 'media-file-renamer' );
245
+ if ( $method == "media_title" )
246
+ $what = __( "Title of Media", 'media-file-renamer' );
247
+ else if ( $method == "post_title" )
248
+ $what = __( "Attached Post Title", 'media-file-renamer' );
249
+ $html .= __( "<label>ALT = <b>$what</b></label><br /><small>Keep in mind that the HTML in your posts and pages will be however not modified, that is too dangerous!</small>", 'media-file-renamer' );
250
+ echo $html;
251
+ }
252
+
253
+ function admin_undo_callback( $args ) {
254
+ $html = '<input type="checkbox" id="mfrh_undo" name="mfrh_undo" value="1" ' .
255
+ checked( 1, get_option( 'mfrh_undo', false ), false ) . '/>';
256
+ $html .= __( '<label>Enable</label><br /><small>A little undo icon will be added in the Rename column (Media Library). When clicked, the filename will be renamed back to the original.</small>', 'media-file-renamer' );
257
+ echo $html;
258
+ }
259
+
260
+ function admin_auto_rename_callback( $args ) {
261
+ $value = apply_filters( 'mfrh_method', 'media_title' );
262
+ $html = '<label><select id="mfrh_auto_rename" name="mfrh_auto_rename">
263
+ <option ' . selected( 'media_title', $value, false ) . 'value="media_title">Title of Media</option>
264
+ <option ' .
265
+ disabled( $this->is_registered(), false, false ) . ' ' .
266
+ selected( 'post_title', $value, false ) . 'value="post_title">Attached Post Title (Pro)</option>
267
+ <option ' .
268
+ disabled( $this->is_registered(), false, false ) . ' ' .
269
+ selected( 'alt_text', $value, false ) . 'value="alt_text">Alternative Text (Pro)</option>
270
+ <option ' . selected( 'none', $value, false ) . 'value="none">None</option>
271
+ </select></label><small><br />' . __( 'If the plugin considers that it is too dangerous to rename the file directly at some point, it will be flagged internally <b>as to be renamed</b>. The list of those flagged files can be found in Media > File Renamer and they can be renamed from there.', 'media-file-renamer' ) . '</small>';
272
+ echo $html;
273
+ }
274
+
275
+ function admin_on_upload_callback( $args ) {
276
+ $html = '<input type="checkbox" id="mfrh_on_upload" name="mfrh_on_upload" value="1" ' .
277
+ checked( 1, get_option( 'mfrh_on_upload', false ), false ) . '/>';
278
+ $html .= __( '<label>Enable</label><br /><small>During upload, the filename will be renamed based on the title of the media.</small>', 'media-file-renamer' );
279
+ echo $html;
280
+ }
281
+
282
+ function admin_update_postmeta_callback( $args ) {
283
+ $value = get_option( 'mfrh_update_postmeta', true );
284
+ $html = '<input type="checkbox" id="mfrh_update_postmeta" name="mfrh_update_postmeta" value="1" ' .
285
+ checked( 1, get_option( 'mfrh_update_postmeta', true ), false ) . '/>';
286
+ $html .= __( '<label>Enabled</label><br /><small>Update the references in the <b>custom fields</b> of the posts (including pages and custom types metadata).</small>', 'media-file-renamer' );
287
+ echo $html;
288
+ }
289
+
290
+ function admin_update_posts_callback( $args ) {
291
+ $value = get_option( 'mfrh_update_posts', true );
292
+ $html = '<input type="checkbox" id="mfrh_update_posts" name="mfrh_update_posts" value="1" ' .
293
+ checked( 1, get_option( 'mfrh_update_posts', true ), false ) . '/>';
294
+ $html .= __( '<label>Enabled</label><br /><small>Update the references to the renamed files in the <b>content</b> and <b>excerpt</b> of the posts (pages and custom types included).</small>', 'media-file-renamer' );
295
+ echo $html;
296
+ }
297
+
298
+ function admin_rename_on_save_callback( $args ) {
299
+ $value = get_option( 'mfrh_rename_on_save', null );
300
+ $html = '<input type="checkbox" id="mfrh_rename_on_save" name="mfrh_rename_on_save" value="1" ' .
301
+ checked( 1, get_option( 'mfrh_rename_on_save' ), false ) . '/>';
302
+ $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' );
303
+ echo $html;
304
+ }
305
+
306
+ function admin_utf8_filename_callback( $args ) {
307
+ $html = '<input ' . disabled( $this->is_registered(), false, false ) . '
308
+ type="checkbox" id="mfrh_utf8_filename" name="mfrh_utf8_filename" value="1" ' .
309
+ checked( 1, apply_filters( 'mfrh_utf8', false ), false ) . '/>';
310
+ $html .= __( '<label>Allow non-ASCII filenames</label><br /><small>This usually doesn\'t work well on Windows installs.</small>', 'media-file-renamer' );
311
+ echo $html;
312
+ }
313
+
314
+ function admin_force_rename_callback( $args ) {
315
+ $value = get_option( 'mfrh_force_rename', null );
316
+ $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="mfrh_force_rename" name="mfrh_force_rename" value="1" ' .
317
+ checked( 1, get_option( 'mfrh_force_rename' ), false ) . '/>';
318
+ $html .= __( '<label>Enabled</label><br/><small>Update the references to the file even if the file renaming itself was not successful. You might want to use that option if your install is broken and you are trying to link your Media to files for which the filenames has been altered (after a migration for exemple)</small>', 'media-file-renamer' );
319
+ echo $html;
320
+ }
321
+
322
+ function admin_log_callback( $args ) {
323
+ $value = get_option( 'mfrh_log', null );
324
+ $html = '<input type="checkbox" id="mfrh_log" name="mfrh_log" value="1" ' .
325
+ checked( 1, get_option( 'mfrh_log' ), false ) . '/>';
326
+ $html .= __( '<label>Enabled</label><br/><small>Simple logging that explains which actions has been run. The file is <a target="_blank" href="' . plugins_url("media-file-renamer") . '/media-file-renamer.log">media-file-renamer.log</a>.</small>', 'media-file-renamer' );
327
+ echo $html;
328
+ }
329
+
330
+ function admin_logsql_callback( $args ) {
331
+ $value = get_option( 'mfrh_logsql', null );
332
+ $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="mfrh_logsql" name="mfrh_logsql" value="1" ' .
333
+ checked( 1, get_option( 'mfrh_logsql' ), false ) . '/>';
334
+ $html .= __( '<label>Enabled</label><br/><small>The files <a target="_blank" href="' . plugins_url( "media-file-renamer" ) . '/mfrh_sql.log">mfrh_sql.log</a> and <a target="_blank" href="' . plugins_url( "media-file-renamer" ) . '/mfrh_sql_revert.log">mfrh_sql_revert.log</a> will be created and they will include the raw SQL queries which were run by the plugin. If there is an issue, the revert file can help you reverting the changes more easily.</small>', 'media-file-renamer' );
335
+ echo $html;
336
+ }
337
+
338
+ /**
339
+ *
340
+ * GET / SET OPTIONS (TO REMOVE)
341
+ *
342
+ */
343
+
344
+ function old_getoption( $option, $section, $default = '' ) {
345
+ $options = get_option( $section );
346
+ if ( isset( $options[$option] ) ) {
347
+ if ( $options[$option] == "off" ) {
348
+ return false;
349
+ }
350
+ if ( $options[$option] == "on" ) {
351
+ return true;
352
+ }
353
+ return $options[$option];
354
+ }
355
+ return $default;
356
+ }
357
+
358
+ }
359
+
360
+ ?>
mfrh_custom.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // For help about this file, check:
4
+ // http://apps.meow.fr/media-file-renamer/faq/
5
+
6
+ // add_filter( 'mfrh_new_filename', 'add_hello_in_front_of_filenames', 10, 3 );
7
+ //
8
+ // function add_hello_in_front_of_filenames( $new, $old, $post ) {
9
+ // return "hello-" . $new;
10
+ // }
11
+
12
+ // add_action( 'mfrh_url_renamed', 'url_of_media_was_modified', 10, 3 );
13
+ //
14
+ // function url_of_media_was_modified( $post, $orig_image_url, $new_image_url ) {
15
+ //
16
+ // }
17
+
18
+ // add_action( 'mfrh_media_renamed', 'filepath_of_media_was_modified', 10, 3 );
19
+ //
20
+ // function filepath_of_media_was_modified( $post, $orig_image_url, $new_image_url ) {
21
+ //
22
+ // }
23
+
24
+ ?>
plugins/wpml.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Thanks to David García from WPML
4
+
5
+ add_action( 'mfrh_path_renamed', 'mfrh_wpml_update_translations', 10, 3 );
6
+
7
+ function mfrh_wpml_update_translations( $post, $old_filepath, $new_filepath ) {
8
+ $args = array('element_id' => $post['ID'], 'element_type' => 'attachment' );
9
+ $info = apply_filters( 'wpml_element_language_details', null, $args );
10
+ if ( ! empty( $info->trid ) ) {
11
+ $translations = apply_filters( 'wpml_get_element_translations', NULL, $info->trid, 'post_attachment' );
12
+ foreach ( $translations as $translation ) {
13
+ if ( $post['ID'] != $translation->element_id ) {
14
+ update_post_meta( $translation->element_id, '_wp_attached_file', $new_filepath );
15
+ }
16
+ }
17
+ }
18
+ }
19
+
20
+ ?>
readme.txt ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Media File Renamer ===
2
+ Contributors: TigrouMeow
3
+ Tags: rename, file, media, management, image, renamer, wpml, wp-retina-2x
4
+ Requires at least: 4.2
5
+ Tested up to: 4.7
6
+ Stable tag: 3.4.6
7
+
8
+ Automatically rename files depending on Media titles dynamically + update links. Pro version has many more options. Check the description :)
9
+
10
+ == Description ==
11
+
12
+ The Media File Renamer is a WordPress plugin that physically renames media files nicely for a cleaner system and for a better SEO. Please read this description.
13
+
14
+ **IMPORTANT**. This is originally an *automatic* renamer based on the Media title. This plugin features were all meant to be automatic depending on the title of the Media. Manual Rename (and a few more features) were added two years later, in a Pro version. I add complex features based on requests usually in the Pro to be able to maintain the quality of the plugin and its support.
15
+
16
+ **HOW IT WORKS**. The plugin automatically renames your media filenames depending on their titles. When files are renamed, the references to it are also updated (posts, pages, custom types and their metadata). A new column in the Media Manager will display to you the new ideal filename and a button will allow you to rename it straight away. You can lock and unlock the renaming automatic process through little icons. There is also a little dashboard called File Renamer in Media that will help you rename all your files at once. Advanced users can change the way the files are renamed by using the plugin's filters (check the FAQ). There is also a LOCK option on every image to avoid the filename to be modified any further.
17
+
18
+ **PRO VERSION**. The [Pro Version](http://meowapps.com/media-file-renamer/) gives a few more features like manual renaming, renaming depending on the post the media is attached to or the content of the alternative text (ALT), logging of SQL queries and a few more options. A good process is to actually let the plugin do the renaming automatically (like in the free version) and to do manual renaming for the files that require fine tuning.
19
+
20
+ **BE CAREFUL**. File renaming is a dangerous process. Before renaming everything automatically, try to rename a few files first and check if all the references to those files have been properly updated on your website. WordPress has so many themes and plugins that this renaming process can't unfortunately cover all the cases, especially if other plugins are using unconventional ways. If references aren't updated properly, please write a nice post (not an angry one) in the support threads :) I will try my best to cover more and more special cases. In any case, always make a **backup** of your database and files before using a plugin that alter your install. Also, it your website seems broken after a few renames, try to **clear your cache**. The cached HTML will indeed not be linked to the new filenames.
21
+
22
+ **FOR DEVELOPER**. The plugin can be tweaked and reference updates enhanced for your themes/plugins. Have a look [here](https://wordpress.org/plugins/media-file-renamer/faq/).
23
+
24
+ **JUST TO MAKE SURE**. This plugin will not allow you to change the filename manually in its standard version. The [Pro Version](http://meowapps.com/media-file-renamer/) is required. If you are about to *write an angry review* because this feature is not available, please *mention that you read the whole description*.
25
+
26
+ This plugin works perfectly with WP Retina 2x, WPML and many more. Is has been tested in Windows, Linux, BSD and OSX systems.
27
+
28
+ Languages: English, French.
29
+
30
+ == Installation ==
31
+
32
+ 1. Upload `media-file-renamer.php` to the `/wp-content/plugins/` directory
33
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
34
+ 3. Try it with one file first! :)
35
+
36
+ == Upgrade Notice ==
37
+
38
+ Simply replace `media-file-renamer.php` by the new one.
39
+
40
+ == Frequently Asked Questions ==
41
+
42
+ Check the FAQ on the official website, here: http://meowapps.com/media-file-renamer/faq/. The following is to enhance the plugin for your own install and is aim to advanced users and developers. If you want to quickly try to use the following filters and actions, please have a look a the file called mfrh_custom.php in the plugin, uncomment some code and hack it :)
43
+
44
+ **Change the way the files are renamed**
45
+
46
+ If you are willing to customize the way the file are renamed, please use the mfrh_new_filename filter. The $new is the new filename proposed by the plugin, $old is the previous one and $post contains the information about the current attachment.
47
+
48
+ `
49
+ add_filter( 'mfrh_new_filename', 'my_filter_filename', 10, 3 );
50
+
51
+ function my_filter_filename( $new, $old, $post ) {
52
+ return "renamed-" . $new;
53
+ }
54
+ `
55
+
56
+ **Update References**
57
+
58
+ You can also update the references to the files or URLs which are renamed/modified by using the following filters. If you themes or another plugins are storing those references by yourself, then this is a chance to achieve this :)
59
+
60
+ The $post is an array containing information about the media (as it is like a post), and you can use the $original_image_url and $new_image_url to do the required renaming:
61
+
62
+ `
63
+ add_action( 'mfrh_url_renamed', 'my_url_renamed', 10, 3 );
64
+
65
+ function my_url_renamed( $post, $orig_image_url, $new_image_url ) {
66
+ return "renamed-" . $new;
67
+ }
68
+ `
69
+
70
+ This is the same as above but it is about the physical filepath on your filesystem:
71
+
72
+ `
73
+ add_action( 'mfrh_media_renamed', 'my_media_renamed', 10, 3 );
74
+
75
+ function my_media_renamed( $post, $old_filepath, $new_filepath ) {
76
+ return "renamed-" . $new;
77
+ }
78
+ `
79
+
80
+ You are welcome to create plugins using Media File Renamer using special rules for renaming. Please tell me you so if you make one and I will list those plugins here.
81
+
82
+ == Screenshots ==
83
+
84
+ 1. Type in the name of your media, that is all.
85
+ 2. Special screen for bulk actions.
86
+ 3. This needs to be renamed.
87
+ 4. The little lock and unlock icons.
88
+ 5. Options for the automatic renaming (there are more options than just this).
89
+
90
+ == Changelog ==
91
+
92
+ = 3.4.6 =
93
+ * Fix: Update system fixed and code cleaning.
94
+
95
+ = 3.4.5 =
96
+ * Fix: Better handling of umlauts.
97
+ * Info: There will be an important warning showing up during this update. It is an important annoucement.
98
+
99
+ = 3.2.7 =
100
+ * Fix: Slug was not getting renamed after recent WP update.
101
+ * Fix: Tiny fixed to avoid notices.
102
+ * Add: Support for WPML Media (thanks to David García froml WPML Team).
103
+
104
+ = 3.2.4 =
105
+ * Fix: Should work with more plugins/themes, WooCommerce for example. The updates aren't done only on the full URLs of the images in the DB now but also on the relative uploads path as well.
106
+ * Info: If you have some time, please review me nicely at https://wordpress.org/support/view/plugin-reviews/media-file-renamer?rate=5#postform. Thanks to you, I get a lot of motivation to make this plugin better :)
107
+
108
+ = 3.2.3 =
109
+ * Add: Option to rename depending on the ALT. Useful if you get interesting information in your ALT.
110
+ * Update: Sync ALT also works with Attached Post Title.
111
+ * Fix: Better handling of norwegian letters (will improve this kind of things over time).
112
+
113
+ = 3.2.2 =
114
+ * Add: Rename the file during upload, based on the media title. Not by default, check the options :)
115
+
116
+ = 3.2.0 =
117
+ * Fix: Logging could not be enabled.
118
+ * Update: Code cleaning.
119
+
120
+ = 3.1.0 =
121
+ * Update: The UI was a bit modified and enhanced. I also think it is simpler and cleaner.
122
+ * Update: Removed the auto-flagging process which was causing issues on sizeable installs.
123
+
124
+ = 3.0.0 =
125
+ * Fix: The references in the excerpts are now also updated (they are used by WooCommerce).
126
+ * Add: Undo button. When the media is unlocked and has been renamed, you have a Undo button. You need to active this in the option.
127
+ * Update: Everything has been moved into the Meow Apps menu for a cleaner admin.
128
+
129
+ = 2.7.8 =
130
+ * Fix: Removed Flattr.
131
+ * Add: Additional cleaning to avoid extensions sometimes written in the title by WP.
132
+ * Add: Clean out the english apostrophe 's during the creation of the new filename.
133
+
134
+ = 2.7.6 =
135
+ * Add: New option to remove the ad, the Flattr button and the information message about the Pro.
136
+ * Fix: Renaming slug was not working well after latest WordPress updates
137
+ * Fix: Use direct links for all my images and links to follow WordPress rules.
138
+
139
+ = 2.7.1 =
140
+ * Info: A file mfrh_custom.php has been added. If you are an advanced users or a developer, please have a look at the FAQ here: https://wordpress.org/plugins/media-file-renamer/faq/. Since I am only one developer, I can't cover all the renaming cases we have (since sometimes plugins keep their own links to the filenames; such as WooCommerce). That will make it easy to advanced users to push Media File Renamer to cover more and more special cases.
141
+
142
+ = 2.6.9 =
143
+ * Change: Modified description and information about the mfrh_url_renamed and mfrh_media_renamed filters.
144
+ * Add: New option to force renaming file (even though the file failed to be renamed). That will help PRO users to fix their broken install, often after a migration for example (often related to change of hosting service using different encoding).
145
+ * Fix: Click on lock/unlock doesn't take you back to the first page anymore.
146
+ * Fix: Little naming issue when numbering + custom filter is used.
147
+
148
+ = 2.6.0 =
149
+ * Add: Lock/Unlock icons in the Media Manager.
150
+ * Add: Rename depending on the title of the post the media is attached to.
151
+
152
+ = 2.5.0 =
153
+ * Update: WordPress 4.4.
154
+ * Add: Add -2, -3, etc... when filenames are similar. Pro only.
155
+ * Fix: There was a glitch when .jpeg extension were used. Now keep them as .jpeg.
156
+
157
+ = 2.4.0 =
158
+ * Fix: There was a possibility that the image sizes filenames could be overwritten wrongly.
159
+ * Update: Rename the GUID (File Name) is now the default. Too many people think it is a bug while it is not.
160
+ * Add: UTF-8 support for renaming files. Before playing with this, give it a try. Windows-based hosting service will probably not work well with this.
161
+ * Fix: Auto-Rename was renaming files even though it was disabled.
162
+ * Update: If Auto-Rename is disabled, the Media Library column is not shown anymore, neither is the dashboard (they are useless in that case).
163
+ * Add: Metadata containing '%20' instead of spaces are now considered too during the renaming.
164
+
165
+ = 2.3.0 =
166
+ * Add: Update the metadata (true by default).
167
+ * Fix: Guid was renamed wrongly in one rare case.
168
+ * Fix: Double extension issue with manual renaming.
169
+
170
+ = 2.2.4 =
171
+ * Fix: Couldn't rename automatically the files without changing the titles, now the feature is back.
172
+ * Fix: Better 'explanations' before renaming.
173
+ * Fix: Should work with WPML Media now.
174
+ * Fix: Manage empty filenames by naming them 'empty'.
175
+
176
+ = 2.2.2 =
177
+ * Add: Option to automatically sync the alternative text with the title.
178
+ * Add: Filters and Actions to allow plugins (or custom code) to customize the renaming.
179
+ * Fix: Avoid to rename file if title is not changed (annoying if you previously manually updated it).
180
+ * Change: Plugin functions are only loaded if the user is using the admin.
181
+
182
+ = 2.2.0 =
183
+ * Add: Many new options.
184
+ * Add: Pro version.
185
+ * Add: Manual file rename (Pro).
186
+ * Update: Use actions for renaming (to facilitate support for more renaming features).
187
+
188
+ = 2.0.0 =
189
+ * Fix: Texts.
190
+ * Fix: Versioning.
191
+
192
+ = 1.9.4 =
193
+ * Add: New option to avoid to modify database (no updates, only renaming).
194
+ * Add: New option to force update the GUID (aka "File name"...). Not recommended _at all_.
195
+ * Fix: Options were without effect.
196
+ * Fix: GUID issue.
197
+
198
+ = 1.3.4 =
199
+ * Fix: issue with attachments without metadata.
200
+ * Fix: UTF-8 title name (i.e. Japanese or Chinese characters).
201
+
202
+ = 1.3.0 =
203
+ * Add: option to rename the files automatically when a post is published.
204
+
205
+ = 1.2.2 =
206
+ * Fix: the 'to be renamed' flag was not removed in a few cases.
207
+
208
+ = 1.2.0 =
209
+ * Fix: issue with strong-caching with WP header images.
210
+ * Fix: now ignore missing files.
211
+ * Change: renaming is now part of the Media Library with nice buttons.
212
+ * Change: the dashboard has been moved to Tools (users should use the Media Library mostly).
213
+ * Change: no bubble counter on the dashboard menu; to avoid plugin to consume any resources.
214
+
215
+ = 1.0.4 =
216
+ * Fix: '<?' to '<?php'.
217
+ * Add: French translation.
218
+ * Change: Donation button (can be removed, check the FAQ).
219
+
220
+ = 1.0.2 =
221
+ * Fix: Ignore 'Header Image' to avoid related issues.
222
+ * Change: Updated screenshots.
223
+ * Change: 'To be renamed' filter removed (useless feature).
224
+
225
+ = 1.0.0 =
226
+ * Change: Rename Dashboard enhanced.
227
+ * Change: Scanning function now displays the results nicely.
228
+ * Change: Handle the media with 'physical' issues.
229
+
230
+ = 0.9.4 =
231
+ * Fix: Works better on Windows (file case).
232
+ * Fix: doesn't add numbering when the file exists already - was way too dangerous.
233
+ * Change: warns you if the Media title exists.
234
+ * Fix: Removed a 'warning'.
235
+
236
+ = 0.9 =
237
+ * Fix: Media were not flagged "as to be renamed" when the title was changed during editing a post.
238
+ * Change: Internal optimization.
239
+ * Add: Settings page.
240
+ * Add: Option to rename the slug or not (default: yes).
241
+
242
+ = 0.8 =
243
+ * Fix: Works with WP 3.5.
244
+ * Change: Update the links in DB directly.
245
+ * Fix: number of flagged media not updated straight after the mass rename.
246
+ * Fix: the "file name" in the media info was empty.
247
+ * Fix: SQL optimization & memory usage huge improvement.
248
+
249
+ = 0.5 =
250
+ * Add: New view "To be renamed" in the Media Library.
251
+ * Add: a nice counter to show the number of files that need to be renamed.
252
+ * Fix: the previous update (0.4) was actually not containing all the changes.
253
+
254
+ = 0.4 =
255
+ * Support for WPML
256
+ * Support for Retina plugins such as WP Retina 2x
257
+ * Adds a '-' between the filename and counter in case of similar files
258
+ * Mark the media as to be renamed when its name is changed outside the Media Library (avoid all the issues we had before)
259
+ * The GUID is now updated using the URL of the images and not the post ID + title (http://wordpress.org/support/topic/plugin-media-file-renamer-incorrect-guid-fix-serious-bug?replies=2#post-2239192).
260
+ * Double-check before physically renaming the files.
261
+
262
+ = 0.3 =
263
+ * Corrections + improvements.
264
+ * Handles well the 'special cases' now.
265
+ * Tiny corrections.
266
+
267
+ = 0.1 =
268
+ * First release.
269
+
270
+ == Wishlist ==
271
+
272
+ Do you have suggestions? Feel free to contact me at <a href='http://www.totorotimes.com'>Totoro Times</a>.
screenshot-1.png ADDED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
screenshot-4.png ADDED
Binary file
screenshot-5.png ADDED
Binary file