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.0.4 7.0.5 7.0.6 7.0.7
media-cleaner / admin.php
media-cleaner Last commit date
common 8 years ago admin.php 8 years ago checkers.php 8 years ago core.php 8 years ago custom_checkers.php 8 years ago media-cleaner.css 9 years ago media-cleaner.js 8 years ago media-cleaner.php 8 years ago readme.txt 8 years ago scan.php 8 years ago wpmc_admin.php 8 years ago wpmc_checkers.php 8 years ago wpmc_custom_checkers.php 9 years ago wpmc_scan.php 8 years ago
admin.php
396 lines
1 <?php
2
3 include "common/admin.php";
4
5 class Meow_WPMC_Admin extends MeowApps_Admin {
6
7 public $core;
8
9 public function __construct( $prefix, $mainfile, $domain ) {
10 parent::__construct( $prefix, $mainfile, $domain );
11 add_action( 'admin_menu', array( $this, 'app_menu' ) );
12 add_action( 'admin_notices', array( $this, 'admin_notices' ) );
13 }
14
15 function admin_notices() {
16
17 $mediasBuffer = get_option( 'wpmc_medias_buffer', null );
18 $postsBuffer = get_option( 'wpmc_posts_buffer', null );
19 $analysisBuffer = get_option( 'wpmc_analysis_buffer', null );
20 $delay = get_option( 'wpmc_delay', null );
21
22 if ( !is_numeric( $mediasBuffer ) || $mediasBuffer < 1 )
23 update_option( 'wpmc_medias_buffer', 100 );
24 if ( !is_numeric( $postsBuffer ) || $postsBuffer < 1 )
25 update_option( 'wpmc_posts_buffer', 5 );
26 if ( !is_numeric( $analysisBuffer ) || $analysisBuffer < 1 )
27 update_option( 'wpmc_analysis_buffer', 100 );
28 if ( !is_numeric( $delay ) )
29 update_option( 'wpmc_delay', 100 );
30
31 if ( !$this->is_registered() && get_option( 'wpmc_method', 'media' ) == 'files' ) {
32 _e( "<div class='error'><p>The Pro version is required to scan files. You can <a target='_blank' href='http://meowapps.com/media-cleaner'>get a serial for the Pro version here</a>.</p></div>", 'media-cleaner' );
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 // SUBMENU > Settings
43 add_submenu_page( 'meowapps-main-menu', 'Media Cleaner', 'Media Cleaner', 'manage_options',
44 'wpmc_settings-menu', array( $this, 'admin_settings' ) );
45
46 // SUBMENU > Settings > Settings (Scanning)
47 add_settings_section( 'wpmc_settings', null, null, 'wpmc_settings-menu' );
48 add_settings_field( 'wpmc_method', "Method",
49 array( $this, 'admin_method_callback' ),
50 'wpmc_settings-menu', 'wpmc_settings' );
51 add_settings_field( 'wpmc_media_library', "Media Library",
52 array( $this, 'admin_media_library_callback' ),
53 'wpmc_settings-menu', 'wpmc_settings' );
54 add_settings_field( 'wpmc_posts', "Posts",
55 array( $this, 'admin_posts_callback' ),
56 'wpmc_settings-menu', 'wpmc_settings' );
57 add_settings_field( 'wpmc_postmeta', "Post Meta",
58 array( $this, 'admin_postmeta_callback' ),
59 'wpmc_settings-menu', 'wpmc_settings' );
60 add_settings_field( 'wpmc_widgets', "Widgets",
61 array( $this, 'admin_widgets_callback' ),
62 'wpmc_settings-menu', 'wpmc_settings' );
63 // add_settings_field( 'wpmc_shortcode', "Shortcodes<br />(Pro)",
64 // array( $this, 'admin_shortcode_callback' ),
65 // 'wpmc_settings-menu', 'wpmc_settings' );
66 // add_settings_field( 'wpmc_background', "Background CSS<br />(Pro)",
67 // array( $this, 'admin_background_callback' ),
68 // 'wpmc_settings-menu', 'wpmc_settings' );
69 add_settings_field( 'wpmc_debuglogs', "Logs",
70 array( $this, 'admin_debuglogs_callback' ),
71 'wpmc_settings-menu', 'wpmc_settings', array( "Enable" ) );
72
73 // SUBMENU > Settings > Filters
74 add_settings_section( 'wpmc_filters_settings', null, null, 'wpmc_filters_settings-menu' );
75 add_settings_field( 'wpmc_thumbnails_only', "Thumbnails Only",
76 array( $this, 'admin_thumbnails_only_callback' ),
77 'wpmc_filters_settings-menu', 'wpmc_filters_settings' );
78
79 // SUBMENU > Settings > UI
80 add_settings_section( 'wpmc_ui_settings', null, null, 'wpmc_ui_settings-menu' );
81 add_settings_field( 'wpmc_hide_thumbnails', "Thumbnails",
82 array( $this, 'admin_hide_thumbnails_callback' ),
83 'wpmc_ui_settings-menu', 'wpmc_ui_settings' );
84 add_settings_field( 'wpmc_hide_warning', "Warning Message",
85 array( $this, 'admin_hide_warning_callback' ),
86 'wpmc_ui_settings-menu', 'wpmc_ui_settings' );
87
88 // SUBMENU > Settings > Advanced
89 add_settings_section( 'wpmc_advanced_settings', null, null, 'wpmc_advanced_settings-menu' );
90 add_settings_field( 'wpmc_medias_buffer', "Medias Buffer",
91 array( $this, 'admin_medias_buffer_callback' ),
92 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' );
93 add_settings_field( 'wpmc_posts_buffer', "Posts Buffer",
94 array( $this, 'admin_posts_buffer_callback' ),
95 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' );
96 add_settings_field( 'wpmc_analysis_buffer', "Analysis Buffer",
97 array( $this, 'admin_analysis_buffer_callback' ),
98 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' );
99 add_settings_field( 'wpmc_delay', "Delay (in ms)",
100 array( $this, 'admin_delay_callback' ),
101 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' );
102
103 // SETTINGS
104 register_setting( 'wpmc_settings', 'wpmc_method' );
105 register_setting( 'wpmc_settings', 'wpmc_posts' );
106 // register_setting( 'wpmc_settings', 'wpmc_shortcode' );
107 // register_setting( 'wpmc_settings', 'wpmc_background' );
108 register_setting( 'wpmc_settings', 'wpmc_widgets' );
109 register_setting( 'wpmc_settings', 'wpmc_media_library' );
110 register_setting( 'wpmc_settings', 'wpmc_postmeta' );
111 register_setting( 'wpmc_settings', 'wpmc_debuglogs' );
112
113
114 register_setting( 'wpmc_filters_settings', 'wpmc_thumbnails_only' );
115
116 register_setting( 'wpmc_ui_settings', 'wpmc_hide_thumbnails' );
117 register_setting( 'wpmc_ui_settings', 'wpmc_hide_warning' );
118
119 register_setting( 'wpmc_advanced_settings', 'wpmc_medias_buffer' );
120 register_setting( 'wpmc_advanced_settings', 'wpmc_posts_buffer' );
121 register_setting( 'wpmc_advanced_settings', 'wpmc_analysis_buffer' );
122 register_setting( 'wpmc_advanced_settings', 'wpmc_delay' );
123 }
124
125 function admin_medias_buffer_callback( $args ) {
126 $value = get_option( 'wpmc_medias_buffer', 100 );
127 $html = '<input type="number" style="width: 100%;" id="wpmc_medias_buffer" name="wpmc_medias_buffer" value="' . $value . '" />';
128 $html .= '<br /><span class="description">The number of media entries to read at a time. This is fast, so the value should be between 50 and 1000.</label>';
129 echo $html;
130 }
131
132 function admin_posts_buffer_callback( $args ) {
133 $value = get_option( 'wpmc_posts_buffer', 5 );
134 $html = '<input type="number" style="width: 100%;" id="wpmc_posts_buffer" name="wpmc_posts_buffer" value="' . $value . '" />';
135 $html .= '<br /><span class="description">The number of posts (and any other post types) to analyze at a time. This is the most intense part of the process. Recommended value is between 1 (slow server) and 20 (excellent server).</label>';
136 echo $html;
137 }
138
139 function admin_analysis_buffer_callback( $args ) {
140 $value = get_option( 'wpmc_analysis_buffer', 100 );
141 $html = '<input type="number" style="width: 100%;" id="wpmc_analysis_buffer" name="wpmc_analysis_buffer" value="' . $value . '" />';
142 $html .= '<br /><span class="description">The number of media entries or files to analyze at a time. This is the main part of the process, but is is much faster than analyzing each post. Recommended value is between 20 (slow server) and 1000 (excellent server).</label>';
143 echo $html;
144 }
145
146 function admin_delay_callback( $args ) {
147 $value = get_option( 'wpmc_delay', 100 );
148 $html = '<input type="number" style="width: 100%;" id="wpmc_delay" name="wpmc_delay" value="' . $value . '" />';
149 $html .= '<br /><span class="description">Time to wait between each request (in milliseconds). The overall process is intensive so this gives the chance to your server to chill out a bit. A very good server doesn\'t need it, but a slow/shared hosting might even reject requests if they are too fast and frequent. Recommended value is actually 0, 100 for safety, 2000 or 5000 if your hosting is kind of cheap.</label>';
150 echo $html;
151 }
152
153 function admin_settings() {
154 ?>
155 <div class="wrap">
156 <?php
157 echo $this->display_title( "Media Cleaner" );
158 ?>
159 <div class="meow-section meow-group">
160 <div class="meow-box meow-col meow-span_2_of_2">
161 <h3>How to use</h3>
162 <div class="inside">
163 <?php echo _e( "You can choose two kind of methods, analyzing your Media Library for images which are not in used, or in your Filesystem for images which aren't registered in the Media Library or not in used. <b>Those checks can be very expensive in term of resources and might fail so you might want to play with those options depending on your install and what you need.</b> Check the <a target=\"_blank\" href=\"//meowapps.com/media-cleaner/tutorial/\">tutorial</a> for more information.", 'media-cleaner' ); ?>
164 <p class="submit">
165 <a class="button button-primary" href="upload.php?page=media-cleaner"><?php echo _e( "Access Media Cleaner Dashboard", 'media-cleaner' ); ?></a>
166 </p>
167 </div>
168 </div>
169 </div>
170
171 <div class="meow-section meow-group">
172
173 <div class="meow-col meow-span_1_of_2">
174
175 <div class="meow-box">
176 <h3>Scanning</h3>
177 <div class="inside">
178 <form method="post" action="options.php">
179 <?php settings_fields( 'wpmc_settings' ); ?>
180 <?php do_settings_sections( 'wpmc_settings-menu' ); ?>
181 <?php submit_button(); ?>
182 </form>
183 </div>
184 </div>
185
186 <div class="meow-box">
187 <h3>Filters</h3>
188 <div class="inside">
189 <form method="post" action="options.php">
190 <?php settings_fields( 'wpmc_filters_settings' ); ?>
191 <?php do_settings_sections( 'wpmc_filters_settings-menu' ); ?>
192 <?php submit_button(); ?>
193 </form>
194 </div>
195
196 </div>
197
198 </div>
199
200 <div class="meow-col meow-span_1_of_2">
201 <?php $this->display_serialkey_box( "https://meowapps.com/media-cleaner/" ); ?>
202
203 <div class="meow-box">
204 <h3>UI</h3>
205 <div class="inside">
206 <form method="post" action="options.php">
207 <?php settings_fields( 'wpmc_ui_settings' ); ?>
208 <?php do_settings_sections( 'wpmc_ui_settings-menu' ); ?>
209 <?php submit_button(); ?>
210 </form>
211 </div>
212 </div>
213
214 <div class="meow-box">
215 <h3>Advanced</h3>
216 <div class="inside">
217 <form method="post" action="options.php">
218 <?php settings_fields( 'wpmc_advanced_settings' ); ?>
219 <?php do_settings_sections( 'wpmc_advanced_settings-menu' ); ?>
220 <?php submit_button(); ?>
221 </form>
222 </div>
223 </div>
224
225 <!--
226 <?php if ( get_option( 'wpmc_shortcode', false ) ): ?>
227 <div class="meow-box">
228 <h3>Shortcodes</h3>
229 <div class="inside"><small>
230 <p>Here are the shortcodes registered in your WordPress by your theme and other plugins.</p>
231 <?php
232 global $shortcode_tags;
233 try {
234 if ( is_array( $shortcode_tags ) ) {
235 $my_shortcodes = array();
236 foreach ( $shortcode_tags as $sc )
237 if ( $sc != '__return_false' ) {
238 if ( is_string( $sc ) )
239 array_push( $my_shortcodes, str_replace( '_shortcode', '', (string)$sc ) );
240 }
241 $my_shortcodes = implode( ', ', $my_shortcodes );
242 }
243 }
244 catch (Exception $e) {
245 $my_shortcodes = "";
246 }
247 echo $my_shortcodes;
248 ?>
249 </small></div>
250 </div>
251 <?php endif; ?>
252 -->
253
254 </div>
255
256 </div>
257 </div>
258 <?php
259 }
260
261
262
263 /*
264 OPTIONS CALLBACKS
265 */
266
267 function admin_method_callback( $args ) {
268 $value = get_option( 'wpmc_method', 'media' );
269 $html = '<select id="wpmc_method" name="wpmc_method">
270 <option ' . selected( 'media', $value, false ) . 'value="media">Media Library</option>
271 <option ' . disabled( $this->is_registered(), false, false ) . ' ' . selected( 'files', $value, false ) . 'value="files">Filesystem (Pro)</option>
272 </select><small><br />' . __( 'Check the <a target="_blank" href="//meowapps.com/media-cleaner/tutorial/">tutorial</a> for more information.', 'media-cleaner' ) . '</small>';
273 echo $html;
274 }
275
276
277 // function admin_shortcode_callback( $args ) {
278 // $value = get_option( 'wpmc_shortcode', null );
279 // $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_shortcode" name="wpmc_shortcode" value="1" ' .
280 // checked( 1, get_option( 'wpmc_shortcode' ), false ) . '/>';
281 // $html .= '<label>Resolve</label><br /><small>The shortcodes you are using in your <b>posts</b> and/or <b>widgets</b> (depending on your options) will be resolved and analyzed. You don\'t need to have this option enabled for the WP Gallery (as it is covered by the Galleries option).</small>';
282 // echo $html;
283 // }
284
285 // function admin_background_callback( $args ) {
286 // $value = get_option( 'wpmc_background', null );
287 // $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_background" name="wpmc_background" value="1" ' .
288 // checked( 1, get_option( 'wpmc_background' ), false ) . '/>';
289 // $html .= '<label>Analyze</label><br /><small>When parsing HTML, the CSS inline background will also be analyzed. A few page builders are using this.</small>';
290 // echo $html;
291 // }
292
293 function admin_debuglogs_callback( $args ) {
294 $debuglogs = get_option( 'wpmc_debuglogs' );
295 $clearlogs = isset ( $_GET[ 'clearlogs' ] ) ? $_GET[ 'clearlogs' ] : 0;
296 if ( $clearlogs && file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
297 unlink( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' );
298 }
299 $html = '<input type="checkbox" id="wpmc_debuglogs" name="wpmc_debuglogs" value="1" ' .
300 checked( 1, $debuglogs, false ) . '/>';
301 $html .= '<label for="wpmc_debuglogs"> ' . $args[0] . '</label><br>';
302 $html .= '<small>' . __( 'Creates an internal log file, for debugging purposes.', 'media-cleaner' );
303 if ( $debuglogs && !file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
304 if ( !$this->core->log( "Testing the logging feature. It works!" ) ) {
305 $html .= sprintf( __( '<br /><b>Cannot create the logging file. Logging will not work. The plugin as a whole might not be able to work neither.</b>', 'media-cleaner' ), plugin_dir_url( __FILE__ ) );
306 }
307 }
308 if ( file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
309 $html .= sprintf( __( '<br />The <a target="_blank" href="%smedia-cleaner.log">log file</a> is available. You can also <a href="?page=wpmc_settings-menu&clearlogs=true">clear</a> it.', 'media-cleaner' ), plugin_dir_url( __FILE__ ) );
310 }
311 $html .= '</small>';
312 echo $html;
313 }
314
315 function admin_media_library_callback( $args ) {
316 $value = get_option( 'wpmc_media_library', true );
317 $html = '<input type="checkbox" id="wpmc_media_library" name="wpmc_media_library" value="1" ' .
318 disabled( get_option( 'wpmc_method', 'media' ) == 'files', false, false ) . ' ' .
319 checked( 1, get_option( 'wpmc_media_library' ), false ) . '/>';
320 $html .= '<label>Check</label><br /><small>Checks if the file is linked to a media. Only makes sense with the Filesystem scan.</small>';
321 echo $html;
322 }
323
324 function admin_posts_callback( $args ) {
325 $value = get_option( 'wpmc_posts', true );
326 $html = '<input type="checkbox" id="wpmc_posts" name="wpmc_posts" value="1" ' .
327 checked( 1, get_option( 'wpmc_posts' ), false ) . '/>';
328 $html .= '<label>Analyze</label><br /><small>Check if the media/file is used by any post types.</small>';
329 echo $html;
330 }
331
332 function admin_postmeta_callback( $args ) {
333 $value = get_option( 'wpmc_postmeta', true );
334 $html = '<input type="checkbox" id="wpmc_postmeta" name="wpmc_postmeta" value="1" ' .
335 checked( 1, get_option( 'wpmc_postmeta' ), false ) . '/>';
336 $html .= '<label>Analyze</label><br /><small>Checks if the media/file is used in the meta.</small>';
337 echo $html;
338 }
339
340 function admin_widgets_callback( $args ) {
341 $value = get_option( 'wpmc_widgets', false );
342 $html = '<input type="checkbox" id="wpmc_widgets" name="wpmc_widgets" value="1" ' .
343 checked( 1, get_option( 'wpmc_widgets' ), false ) . '/>';
344 $html .= '<label>Analyze</label><br /><small>Checks if the media/file is used by any widget.</small>';
345 echo $html;
346 }
347
348 function admin_hide_thumbnails_callback( $args ) {
349 $value = get_option( 'wpmc_hide_thumbnails', null );
350 $html = '<input type="checkbox" id="wpmc_hide_thumbnails" name="wpmc_hide_thumbnails" value="1" ' .
351 checked( 1, get_option( 'wpmc_hide_thumbnails' ), false ) . '/>';
352 $html .= '<label>Hide</label><br /><small>If you prefer not to see the thumbnails.</small>';
353 echo $html;
354 }
355
356 function admin_hide_warning_callback( $args ) {
357 $value = get_option( 'wpmc_hide_warning', null );
358 $html = '<input type="checkbox" id="wpmc_hide_warning" name="wpmc_hide_warning" value="1" ' .
359 checked( 1, get_option( 'wpmc_hide_warning' ), false ) . '/>';
360 $html .= '<label>Hide</label><br /><small>Have you read it twice? If yes, hide it :)</small>';
361 echo $html;
362 }
363
364 function admin_thumbnails_only_callback( $args ) {
365 $value = get_option( 'wpmc_thumbnails_only', false );
366 $html = '<input type="checkbox" id="wpmc_thumbnails_only" name="wpmc_thumbnails_only" value="1" ' .
367 disabled( get_option( 'wpmc_method', 'media' ) == 'files', false, false ) . ' ' .
368 checked( 1, get_option( 'wpmc_thumbnails_only' ), false ) . '/>';
369 $html .= '<label>Enable</label><br /><small>Restrict the filesystem scan to thumbnails (files containing the resolution). If none of the checks above are selected, you will get the list of all the thumbnails and be able to remove them.</small>';
370 echo $html;
371 }
372
373 /**
374 *
375 * GET / SET OPTIONS (TO REMOVE)
376 *
377 */
378
379 function old_getoption( $option, $section, $default = '' ) {
380 $options = get_option( $section );
381 if ( isset( $options[$option] ) ) {
382 if ( $options[$option] == "off" ) {
383 return false;
384 }
385 if ( $options[$option] == "on" ) {
386 return true;
387 }
388 return $options[$option];
389 }
390 return $default;
391 }
392
393 }
394
395 ?>
396