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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 views 7 years ago admin.php 7 years ago checkers.php 8 years ago core.php 7 years ago custom_checkers.php 8 years ago media-cleaner.css 7 years ago media-cleaner.js 7 years ago media-cleaner.php 7 years ago readme.txt 7 years ago scan.php 7 years ago ui.php 7 years ago
admin.php
408 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 add_settings_field( 'wpmc_results_per_page', "Results Per Page",
88 array( $this, 'admin_results_per_page' ),
89 'wpmc_ui_settings-menu', 'wpmc_ui_settings' );
90
91 // SUBMENU > Settings > Advanced
92 add_settings_section( 'wpmc_advanced_settings', null, null, 'wpmc_advanced_settings-menu' );
93 add_settings_field( 'wpmc_medias_buffer', "Medias Buffer",
94 array( $this, 'admin_medias_buffer_callback' ),
95 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' );
96 add_settings_field( 'wpmc_posts_buffer', "Posts Buffer",
97 array( $this, 'admin_posts_buffer_callback' ),
98 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' );
99 add_settings_field( 'wpmc_analysis_buffer', "Analysis Buffer",
100 array( $this, 'admin_analysis_buffer_callback' ),
101 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' );
102 add_settings_field( 'wpmc_delay', "Delay (in ms)",
103 array( $this, 'admin_delay_callback' ),
104 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' );
105
106 // SETTINGS
107 register_setting( 'wpmc_settings', 'wpmc_method' );
108 register_setting( 'wpmc_settings', 'wpmc_posts' );
109 // register_setting( 'wpmc_settings', 'wpmc_shortcode' );
110 // register_setting( 'wpmc_settings', 'wpmc_background' );
111 register_setting( 'wpmc_settings', 'wpmc_widgets' );
112 register_setting( 'wpmc_settings', 'wpmc_media_library' );
113 register_setting( 'wpmc_settings', 'wpmc_postmeta' );
114 register_setting( 'wpmc_settings', 'wpmc_debuglogs' );
115
116
117 register_setting( 'wpmc_filters_settings', 'wpmc_thumbnails_only' );
118
119 register_setting( 'wpmc_ui_settings', 'wpmc_hide_thumbnails' );
120 register_setting( 'wpmc_ui_settings', 'wpmc_hide_warning' );
121 register_setting( 'wpmc_ui_settings', 'wpmc_results_per_page' );
122
123 register_setting( 'wpmc_advanced_settings', 'wpmc_medias_buffer' );
124 register_setting( 'wpmc_advanced_settings', 'wpmc_posts_buffer' );
125 register_setting( 'wpmc_advanced_settings', 'wpmc_analysis_buffer' );
126 register_setting( 'wpmc_advanced_settings', 'wpmc_delay' );
127 }
128
129 function admin_medias_buffer_callback( $args ) {
130 $value = get_option( 'wpmc_medias_buffer', 100 );
131 $html = '<input type="number" style="width: 100%;" id="wpmc_medias_buffer" name="wpmc_medias_buffer" value="' . $value . '" />';
132 $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>';
133 echo $html;
134 }
135
136 function admin_posts_buffer_callback( $args ) {
137 $value = get_option( 'wpmc_posts_buffer', 5 );
138 $html = '<input type="number" style="width: 100%;" id="wpmc_posts_buffer" name="wpmc_posts_buffer" value="' . $value . '" />';
139 $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>';
140 echo $html;
141 }
142
143 function admin_analysis_buffer_callback( $args ) {
144 $value = get_option( 'wpmc_analysis_buffer', 100 );
145 $html = '<input type="number" style="width: 100%;" id="wpmc_analysis_buffer" name="wpmc_analysis_buffer" value="' . $value . '" />';
146 $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>';
147 echo $html;
148 }
149
150 function admin_delay_callback( $args ) {
151 $value = get_option( 'wpmc_delay', 100 );
152 $html = '<input type="number" style="width: 100%;" id="wpmc_delay" name="wpmc_delay" value="' . $value . '" />';
153 $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>';
154 echo $html;
155 }
156
157 function admin_settings() {
158 ?>
159 <div class="wrap">
160 <?php
161 echo $this->display_title( "Media Cleaner" );
162 ?>
163 <div class="meow-section meow-group">
164 <div class="meow-box meow-col meow-span_2_of_2">
165 <h3>How to use</h3>
166 <div class="inside">
167 <?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' ); ?>
168 <p class="submit">
169 <a class="button button-primary" href="upload.php?page=media-cleaner"><?php echo _e( "Access Media Cleaner Dashboard", 'media-cleaner' ); ?></a>
170 </p>
171 </div>
172 </div>
173 </div>
174
175 <div class="meow-section meow-group">
176
177 <div class="meow-col meow-span_1_of_2">
178
179 <div class="meow-box">
180 <h3>Scanning</h3>
181 <div class="inside">
182 <form method="post" action="options.php">
183 <?php settings_fields( 'wpmc_settings' ); ?>
184 <?php do_settings_sections( 'wpmc_settings-menu' ); ?>
185 <?php submit_button(); ?>
186 </form>
187 </div>
188 </div>
189
190 <div class="meow-box">
191 <h3>Filters</h3>
192 <div class="inside">
193 <form method="post" action="options.php">
194 <?php settings_fields( 'wpmc_filters_settings' ); ?>
195 <?php do_settings_sections( 'wpmc_filters_settings-menu' ); ?>
196 <?php submit_button(); ?>
197 </form>
198 </div>
199
200 </div>
201
202 </div>
203
204 <div class="meow-col meow-span_1_of_2">
205 <?php $this->display_serialkey_box( "https://meowapps.com/media-cleaner/" ); ?>
206
207 <div class="meow-box">
208 <h3>UI</h3>
209 <div class="inside">
210 <form method="post" action="options.php">
211 <?php settings_fields( 'wpmc_ui_settings' ); ?>
212 <?php do_settings_sections( 'wpmc_ui_settings-menu' ); ?>
213 <?php submit_button(); ?>
214 </form>
215 </div>
216 </div>
217
218 <div class="meow-box">
219 <h3>Advanced</h3>
220 <div class="inside">
221 <form method="post" action="options.php">
222 <?php settings_fields( 'wpmc_advanced_settings' ); ?>
223 <?php do_settings_sections( 'wpmc_advanced_settings-menu' ); ?>
224 <?php submit_button(); ?>
225 </form>
226 </div>
227 </div>
228
229 <!--
230 <?php if ( get_option( 'wpmc_shortcode', false ) ): ?>
231 <div class="meow-box">
232 <h3>Shortcodes</h3>
233 <div class="inside"><small>
234 <p>Here are the shortcodes registered in your WordPress by your theme and other plugins.</p>
235 <?php
236 global $shortcode_tags;
237 try {
238 if ( is_array( $shortcode_tags ) ) {
239 $my_shortcodes = array();
240 foreach ( $shortcode_tags as $sc )
241 if ( $sc != '__return_false' ) {
242 if ( is_string( $sc ) )
243 array_push( $my_shortcodes, str_replace( '_shortcode', '', (string)$sc ) );
244 }
245 $my_shortcodes = implode( ', ', $my_shortcodes );
246 }
247 }
248 catch (Exception $e) {
249 $my_shortcodes = "";
250 }
251 echo $my_shortcodes;
252 ?>
253 </small></div>
254 </div>
255 <?php endif; ?>
256 -->
257
258 </div>
259
260 </div>
261 </div>
262 <?php
263 }
264
265
266
267 /*
268 OPTIONS CALLBACKS
269 */
270
271 function admin_method_callback( $args ) {
272 $value = get_option( 'wpmc_method', 'media' );
273 $html = '<select id="wpmc_method" name="wpmc_method">
274 <option ' . selected( 'media', $value, false ) . 'value="media">Media Library</option>
275 <option ' . disabled( $this->is_registered(), false, false ) . ' ' . selected( 'files', $value, false ) . 'value="files">Filesystem (Pro)</option>
276 </select><small><br />' . __( 'Check the <a target="_blank" href="//meowapps.com/media-cleaner/tutorial/">tutorial</a> for more information.', 'media-cleaner' ) . '</small>';
277 echo $html;
278 }
279
280
281 // function admin_shortcode_callback( $args ) {
282 // $value = get_option( 'wpmc_shortcode', null );
283 // $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_shortcode" name="wpmc_shortcode" value="1" ' .
284 // checked( 1, get_option( 'wpmc_shortcode' ), false ) . '/>';
285 // $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>';
286 // echo $html;
287 // }
288
289 // function admin_background_callback( $args ) {
290 // $value = get_option( 'wpmc_background', null );
291 // $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_background" name="wpmc_background" value="1" ' .
292 // checked( 1, get_option( 'wpmc_background' ), false ) . '/>';
293 // $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>';
294 // echo $html;
295 // }
296
297 function admin_debuglogs_callback( $args ) {
298 $debuglogs = get_option( 'wpmc_debuglogs' );
299 $clearlogs = isset ( $_GET[ 'clearlogs' ] ) ? $_GET[ 'clearlogs' ] : 0;
300 if ( $clearlogs && file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
301 unlink( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' );
302 }
303 $html = '<input type="checkbox" id="wpmc_debuglogs" name="wpmc_debuglogs" value="1" ' .
304 checked( 1, $debuglogs, false ) . '/>';
305 $html .= '<label for="wpmc_debuglogs"> ' . $args[0] . '</label><br>';
306 $html .= '<small>' . __( 'Creates an internal log file, for debugging purposes.', 'media-cleaner' );
307 if ( $debuglogs && !file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
308 if ( !$this->core->log( "Testing the logging feature. It works!" ) ) {
309 $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__ ) );
310 }
311 }
312 if ( file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) {
313 $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__ ) );
314 }
315 $html .= '</small>';
316 echo $html;
317 }
318
319 function admin_media_library_callback( $args ) {
320 $value = get_option( 'wpmc_media_library', true );
321 $html = '<input type="checkbox" id="wpmc_media_library" name="wpmc_media_library" value="1" ' .
322 disabled( get_option( 'wpmc_method', 'media' ) == 'files', false, false ) . ' ' .
323 checked( 1, get_option( 'wpmc_media_library' ), false ) . '/>';
324 $html .= '<label>Check</label><br /><small>Checks if the file is linked to a media. Only makes sense with the Filesystem scan.</small>';
325 echo $html;
326 }
327
328 function admin_posts_callback( $args ) {
329 $value = get_option( 'wpmc_posts', true );
330 $html = '<input type="checkbox" id="wpmc_posts" name="wpmc_posts" value="1" ' .
331 checked( 1, get_option( 'wpmc_posts' ), false ) . '/>';
332 $html .= '<label>Analyze</label><br /><small>Check if the media/file is used by any post types.</small>';
333 echo $html;
334 }
335
336 function admin_postmeta_callback( $args ) {
337 $value = get_option( 'wpmc_postmeta', true );
338 $html = '<input type="checkbox" id="wpmc_postmeta" name="wpmc_postmeta" value="1" ' .
339 checked( 1, get_option( 'wpmc_postmeta' ), false ) . '/>';
340 $html .= '<label>Analyze</label><br /><small>Checks if the media/file is used in the meta.</small>';
341 echo $html;
342 }
343
344 function admin_widgets_callback( $args ) {
345 $value = get_option( 'wpmc_widgets', false );
346 $html = '<input type="checkbox" id="wpmc_widgets" name="wpmc_widgets" value="1" ' .
347 checked( 1, get_option( 'wpmc_widgets' ), false ) . '/>';
348 $html .= '<label>Analyze</label><br /><small>Checks if the media/file is used by any widget.</small>';
349 echo $html;
350 }
351
352 function admin_hide_thumbnails_callback( $args ) {
353 $value = get_option( 'wpmc_hide_thumbnails', null );
354 $html = '<input type="checkbox" id="wpmc_hide_thumbnails" name="wpmc_hide_thumbnails" value="1" ' .
355 checked( 1, get_option( 'wpmc_hide_thumbnails' ), false ) . '/>';
356 $html .= '<label>Hide</label><br /><small>If you prefer not to see the thumbnails.</small>';
357 echo $html;
358 }
359
360 function admin_hide_warning_callback( $args ) {
361 $value = get_option( 'wpmc_hide_warning', null );
362 $html = '<input type="checkbox" id="wpmc_hide_warning" name="wpmc_hide_warning" value="1" ' .
363 checked( 1, get_option( 'wpmc_hide_warning' ), false ) . '/>';
364 $html .= '<label>Hide</label><br /><small>Have you read it twice? If yes, hide it :)</small>';
365 echo $html;
366 }
367
368 function admin_results_per_page( $args ) {
369 $value = get_option( 'wpmc_results_per_page', 20 );
370 $html = <<< HTML
371 <input step="1" min="1" max="999" name="wpmc_results_per_page" id="wpmc_results_per_page" maxlength="3" value="{$value}" type="number">
372 HTML;
373 echo $html;
374 }
375
376 function admin_thumbnails_only_callback( $args ) {
377 $value = get_option( 'wpmc_thumbnails_only', false );
378 $html = '<input type="checkbox" id="wpmc_thumbnails_only" name="wpmc_thumbnails_only" value="1" ' .
379 disabled( get_option( 'wpmc_method', 'media' ) == 'files', false, false ) . ' ' .
380 checked( 1, get_option( 'wpmc_thumbnails_only' ), false ) . '/>';
381 $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>';
382 echo $html;
383 }
384
385 /**
386 *
387 * GET / SET OPTIONS (TO REMOVE)
388 *
389 */
390
391 function old_getoption( $option, $section, $default = '' ) {
392 $options = get_option( $section );
393 if ( isset( $options[$option] ) ) {
394 if ( $options[$option] == "off" ) {
395 return false;
396 }
397 if ( $options[$option] == "on" ) {
398 return true;
399 }
400 return $options[$option];
401 }
402 return $default;
403 }
404
405 }
406
407 ?>
408