media-cleaner
Last commit date
common
7 years ago
parsers
7 years ago
scripts
7 years ago
views
7 years ago
admin.php
7 years ago
api.php
7 years ago
core.php
7 years ago
engine.php
7 years ago
media-cleaner.php
7 years ago
parsers.php
7 years ago
readme.txt
7 years ago
ui.php
7 years ago
admin.php
503 lines
| 1 | <?php |
| 2 | |
| 3 | include "common/admin.php"; |
| 4 | |
| 5 | class Meow_WPMC_Admin extends MeowApps_Admin { |
| 6 | |
| 7 | public function __construct( $prefix, $mainfile, $domain ) { |
| 8 | parent::__construct( $prefix, $mainfile, $domain ); |
| 9 | add_action( 'admin_menu', array( $this, 'app_menu' ) ); |
| 10 | add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 11 | add_filter( 'pre_update_option', array( $this, 'pre_update_option' ), 10, 3 ); |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Filters and performs validation for certain options |
| 16 | * @param mixed $value Option value |
| 17 | * @param string $option Option name |
| 18 | * @param mixed $old_value The current value of the option |
| 19 | * @return mixed The actual value to be stored |
| 20 | */ |
| 21 | function pre_update_option( $value, $option, $old_value ) { |
| 22 | if ( strpos( $option, 'wpmc_' ) !== 0 ) return $value; // Never touch extraneous options |
| 23 | $validated = $this->validate_option( $option, $value ); |
| 24 | if ( $validated instanceof WP_Error ) { |
| 25 | // TODO: Show warning for invalid option value |
| 26 | return $old_value; |
| 27 | } |
| 28 | return $validated; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Validates certain option values |
| 33 | * @param string $option Option name |
| 34 | * @param mixed $value Option value |
| 35 | * @return mixed|WP_Error Validated value if no problem |
| 36 | */ |
| 37 | function validate_option( $option, $value ) { |
| 38 | switch ( $option ) { |
| 39 | case 'wpmc_dirs_filter': |
| 40 | case 'wpmc_files_filter': |
| 41 | if ( $value && @preg_match( $value, '' ) === false ) return new WP_Error( 'invalid_option', __( "Invalid Regular-Expression", 'media-cleaner' ) ); |
| 42 | break; |
| 43 | } |
| 44 | return $value; |
| 45 | } |
| 46 | |
| 47 | function admin_notices() { |
| 48 | |
| 49 | $mediasBuffer = get_option( 'wpmc_medias_buffer', null ); |
| 50 | $postsBuffer = get_option( 'wpmc_posts_buffer', null ); |
| 51 | $analysisBuffer = get_option( 'wpmc_analysis_buffer', null ); |
| 52 | $delay = get_option( 'wpmc_delay', null ); |
| 53 | |
| 54 | if ( !is_numeric( $mediasBuffer ) || $mediasBuffer < 1 ) |
| 55 | update_option( 'wpmc_medias_buffer', 100 ); |
| 56 | if ( !is_numeric( $postsBuffer ) || $postsBuffer < 1 ) |
| 57 | update_option( 'wpmc_posts_buffer', 5 ); |
| 58 | if ( !is_numeric( $analysisBuffer ) || $analysisBuffer < 1 ) |
| 59 | update_option( 'wpmc_analysis_buffer', 100 ); |
| 60 | if ( !is_numeric( $delay ) ) |
| 61 | update_option( 'wpmc_delay', 100 ); |
| 62 | |
| 63 | if ( !$this->is_registered() && get_option( 'wpmc_method', 'media' ) == 'files' ) { |
| 64 | _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' ); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | function common_url( $file ) { |
| 69 | return trailingslashit( plugin_dir_url( __FILE__ ) ) . 'common/' . $file; |
| 70 | } |
| 71 | |
| 72 | function app_menu() { |
| 73 | |
| 74 | // SUBMENU > Settings |
| 75 | add_submenu_page( 'meowapps-main-menu', 'Media Cleaner', 'Media Cleaner', 'manage_options', |
| 76 | 'wpmc_settings-menu', array( $this, 'admin_settings' ) ); |
| 77 | |
| 78 | // SUBMENU > Settings > Settings (Scanning) |
| 79 | add_settings_section( 'wpmc_settings', null, null, 'wpmc_settings-menu' ); |
| 80 | add_settings_field( 'wpmc_method', "Method", |
| 81 | array( $this, 'admin_method_callback' ), |
| 82 | 'wpmc_settings-menu', 'wpmc_settings' ); |
| 83 | add_settings_field( 'wpmc_content', "Content", |
| 84 | array( $this, 'admin_content_callback' ), |
| 85 | 'wpmc_settings-menu', 'wpmc_settings' ); |
| 86 | add_settings_field( 'wpmc_media_library', "Media Library", |
| 87 | array( $this, 'admin_media_library_callback' ), |
| 88 | 'wpmc_settings-menu', 'wpmc_settings' ); |
| 89 | add_settings_field( 'wpmc_live_content', "Live Content<br />(Pro)", |
| 90 | array( $this, 'admin_live_content_callback' ), |
| 91 | 'wpmc_settings-menu', 'wpmc_settings' ); |
| 92 | // add_settings_field( 'wpmc_posts', "Posts", |
| 93 | // array( $this, 'admin_posts_callback' ), |
| 94 | // 'wpmc_settings-menu', 'wpmc_settings' ); |
| 95 | // add_settings_field( 'wpmc_postmeta', "Post Meta", |
| 96 | // array( $this, 'admin_postmeta_callback' ), |
| 97 | // 'wpmc_settings-menu', 'wpmc_settings' ); |
| 98 | // add_settings_field( 'wpmc_widgets', "Widgets", |
| 99 | // array( $this, 'admin_widgets_callback' ), |
| 100 | // 'wpmc_settings-menu', 'wpmc_settings' ); |
| 101 | // add_settings_field( 'wpmc_shortcode', "Shortcodes<br />(Pro)", |
| 102 | // array( $this, 'admin_shortcode_callback' ), |
| 103 | // 'wpmc_settings-menu', 'wpmc_settings' ); |
| 104 | // add_settings_field( 'wpmc_background', "Background CSS<br />(Pro)", |
| 105 | // array( $this, 'admin_background_callback' ), |
| 106 | // 'wpmc_settings-menu', 'wpmc_settings' ); |
| 107 | add_settings_field( 'wpmc_debuglogs', "Logs", |
| 108 | array( $this, 'admin_debuglogs_callback' ), |
| 109 | 'wpmc_settings-menu', 'wpmc_settings', array( "Enable" ) ); |
| 110 | |
| 111 | // SUBMENU > Settings > Filters |
| 112 | add_settings_section( 'wpmc_filters_settings', null, null, 'wpmc_filters_settings-menu' ); |
| 113 | add_settings_field( 'wpmc_thumbnails_only', "Thumbnails Only", |
| 114 | array( $this, 'admin_thumbnails_only_callback' ), |
| 115 | 'wpmc_filters_settings-menu', 'wpmc_filters_settings' ); |
| 116 | |
| 117 | add_settings_field( |
| 118 | 'wpmc_dirs_filter', |
| 119 | 'Directories Filter', |
| 120 | array( $this, 'admin_dirs_filter_callback' ), |
| 121 | 'wpmc_filters_settings-menu', |
| 122 | 'wpmc_filters_settings' |
| 123 | ); |
| 124 | |
| 125 | add_settings_field( |
| 126 | 'wpmc_files_filter', |
| 127 | 'Files Filter', |
| 128 | array( $this, 'admin_files_filter_callback' ), |
| 129 | 'wpmc_filters_settings-menu', |
| 130 | 'wpmc_filters_settings' |
| 131 | ); |
| 132 | |
| 133 | // SUBMENU > Settings > UI |
| 134 | add_settings_section( 'wpmc_ui_settings', null, null, 'wpmc_ui_settings-menu' ); |
| 135 | add_settings_field( 'wpmc_hide_thumbnails', "Thumbnails", |
| 136 | array( $this, 'admin_hide_thumbnails_callback' ), |
| 137 | 'wpmc_ui_settings-menu', 'wpmc_ui_settings' ); |
| 138 | add_settings_field( 'wpmc_hide_warning', "Warning Message", |
| 139 | array( $this, 'admin_hide_warning_callback' ), |
| 140 | 'wpmc_ui_settings-menu', 'wpmc_ui_settings' ); |
| 141 | add_settings_field( 'wpmc_results_per_page', "Results Per Page", |
| 142 | array( $this, 'admin_results_per_page' ), |
| 143 | 'wpmc_ui_settings-menu', 'wpmc_ui_settings' ); |
| 144 | |
| 145 | // SUBMENU > Settings > Advanced |
| 146 | add_settings_section( 'wpmc_advanced_settings', null, null, 'wpmc_advanced_settings-menu' ); |
| 147 | add_settings_field( 'wpmc_medias_buffer', "Medias Buffer", |
| 148 | array( $this, 'admin_medias_buffer_callback' ), |
| 149 | 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' ); |
| 150 | add_settings_field( 'wpmc_posts_buffer', "Posts Buffer", |
| 151 | array( $this, 'admin_posts_buffer_callback' ), |
| 152 | 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' ); |
| 153 | add_settings_field( 'wpmc_analysis_buffer', "Analysis Buffer", |
| 154 | array( $this, 'admin_analysis_buffer_callback' ), |
| 155 | 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' ); |
| 156 | add_settings_field( 'wpmc_delay', "Delay (in ms)", |
| 157 | array( $this, 'admin_delay_callback' ), |
| 158 | 'wpmc_advanced_settings-menu', 'wpmc_advanced_settings' ); |
| 159 | |
| 160 | // SETTINGS |
| 161 | register_setting( 'wpmc_settings', 'wpmc_method' ); |
| 162 | register_setting( 'wpmc_settings', 'wpmc_content' ); |
| 163 | register_setting( 'wpmc_settings', 'wpmc_live_content' ); |
| 164 | // register_setting( 'wpmc_settings', 'wpmc_posts' ); |
| 165 | // register_setting( 'wpmc_settings', 'wpmc_shortcode' ); |
| 166 | // register_setting( 'wpmc_settings', 'wpmc_background' ); |
| 167 | // register_setting( 'wpmc_settings', 'wpmc_widgets' ); |
| 168 | register_setting( 'wpmc_settings', 'wpmc_media_library' ); |
| 169 | // register_setting( 'wpmc_settings', 'wpmc_postmeta' ); |
| 170 | register_setting( 'wpmc_settings', 'wpmc_debuglogs' ); |
| 171 | |
| 172 | register_setting( 'wpmc_filters_settings', 'wpmc_thumbnails_only' ); |
| 173 | register_setting( 'wpmc_filters_settings', 'wpmc_dirs_filter' ); |
| 174 | register_setting( 'wpmc_filters_settings', 'wpmc_files_filter' ); |
| 175 | |
| 176 | register_setting( 'wpmc_ui_settings', 'wpmc_hide_thumbnails' ); |
| 177 | register_setting( 'wpmc_ui_settings', 'wpmc_hide_warning' ); |
| 178 | register_setting( 'wpmc_ui_settings', 'wpmc_results_per_page' ); |
| 179 | |
| 180 | register_setting( 'wpmc_advanced_settings', 'wpmc_medias_buffer' ); |
| 181 | register_setting( 'wpmc_advanced_settings', 'wpmc_posts_buffer' ); |
| 182 | register_setting( 'wpmc_advanced_settings', 'wpmc_analysis_buffer' ); |
| 183 | register_setting( 'wpmc_advanced_settings', 'wpmc_delay' ); |
| 184 | } |
| 185 | |
| 186 | function admin_medias_buffer_callback( $args ) { |
| 187 | $value = get_option( 'wpmc_medias_buffer', 100 ); |
| 188 | $html = '<input type="number" style="width: 100%;" id="wpmc_medias_buffer" name="wpmc_medias_buffer" value="' . $value . '" />'; |
| 189 | $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>'; |
| 190 | echo $html; |
| 191 | } |
| 192 | |
| 193 | function admin_posts_buffer_callback( $args ) { |
| 194 | $value = get_option( 'wpmc_posts_buffer', 5 ); |
| 195 | $html = '<input type="number" style="width: 100%;" id="wpmc_posts_buffer" name="wpmc_posts_buffer" value="' . $value . '" />'; |
| 196 | $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>'; |
| 197 | echo $html; |
| 198 | } |
| 199 | |
| 200 | function admin_analysis_buffer_callback( $args ) { |
| 201 | $value = get_option( 'wpmc_analysis_buffer', 100 ); |
| 202 | $html = '<input type="number" style="width: 100%;" id="wpmc_analysis_buffer" name="wpmc_analysis_buffer" value="' . $value . '" />'; |
| 203 | $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>'; |
| 204 | echo $html; |
| 205 | } |
| 206 | |
| 207 | function admin_delay_callback( $args ) { |
| 208 | $value = get_option( 'wpmc_delay', 100 ); |
| 209 | $html = '<input type="number" style="width: 100%;" id="wpmc_delay" name="wpmc_delay" value="' . $value . '" />'; |
| 210 | $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>'; |
| 211 | echo $html; |
| 212 | } |
| 213 | |
| 214 | function admin_settings() { |
| 215 | ?> |
| 216 | <div class="wrap"> |
| 217 | <?php |
| 218 | echo $this->display_title( "Media Cleaner" ); |
| 219 | ?> |
| 220 | <div class="meow-section meow-group"> |
| 221 | <div class="meow-box meow-col meow-span_2_of_2"> |
| 222 | <h3>How to use</h3> |
| 223 | <div class="inside"> |
| 224 | <?php echo _e( "You can choose two kind of methods. Usually, users like to analyze their Media Library for images which are not in used (Media Library Method + Content Check), and then, their Filesystem for images which aren't registered in the Media Library (Filesystem Method + Media Library Check). Check the <a target=\"_blank\" href=\"https://meowapps.com/media-cleaner-tutorial/\">tutorial</a> for more information.", 'media-cleaner' ); ?> |
| 225 | <p class="submit"> |
| 226 | <a class="button button-primary" href="upload.php?page=media-cleaner"><?php echo _e( "Access Media Cleaner Dashboard", 'media-cleaner' ); ?></a> |
| 227 | </p> |
| 228 | </div> |
| 229 | </div> |
| 230 | </div> |
| 231 | |
| 232 | <div class="meow-section meow-group"> |
| 233 | |
| 234 | <div class="meow-col meow-span_1_of_2"> |
| 235 | |
| 236 | <div class="meow-box"> |
| 237 | <h3>Scanning</h3> |
| 238 | <div class="inside"> |
| 239 | <form method="post" action="options.php"> |
| 240 | <?php settings_fields( 'wpmc_settings' ); ?> |
| 241 | <?php do_settings_sections( 'wpmc_settings-menu' ); ?> |
| 242 | <?php submit_button(); ?> |
| 243 | </form> |
| 244 | </div> |
| 245 | </div> |
| 246 | |
| 247 | <div class="meow-box"> |
| 248 | <h3>Filters</h3> |
| 249 | <div class="inside"> |
| 250 | <form method="post" action="options.php"> |
| 251 | <?php settings_fields( 'wpmc_filters_settings' ); ?> |
| 252 | <?php do_settings_sections( 'wpmc_filters_settings-menu' ); ?> |
| 253 | <?php submit_button(); ?> |
| 254 | </form> |
| 255 | </div> |
| 256 | |
| 257 | </div> |
| 258 | |
| 259 | </div> |
| 260 | |
| 261 | <div class="meow-col meow-span_1_of_2"> |
| 262 | <?php $this->display_serialkey_box( "https://meowapps.com/media-cleaner/" ); ?> |
| 263 | |
| 264 | <div class="meow-box"> |
| 265 | <h3>UI</h3> |
| 266 | <div class="inside"> |
| 267 | <form method="post" action="options.php"> |
| 268 | <?php settings_fields( 'wpmc_ui_settings' ); ?> |
| 269 | <?php do_settings_sections( 'wpmc_ui_settings-menu' ); ?> |
| 270 | <?php submit_button(); ?> |
| 271 | </form> |
| 272 | </div> |
| 273 | </div> |
| 274 | |
| 275 | <div class="meow-box"> |
| 276 | <h3>Advanced</h3> |
| 277 | <div class="inside"> |
| 278 | <form method="post" action="options.php"> |
| 279 | <?php settings_fields( 'wpmc_advanced_settings' ); ?> |
| 280 | <?php do_settings_sections( 'wpmc_advanced_settings-menu' ); ?> |
| 281 | <?php submit_button(); ?> |
| 282 | </form> |
| 283 | </div> |
| 284 | </div> |
| 285 | |
| 286 | <!-- |
| 287 | <?php if ( get_option( 'wpmc_shortcode', false ) ): ?> |
| 288 | <div class="meow-box"> |
| 289 | <h3>Shortcodes</h3> |
| 290 | <div class="inside"><small> |
| 291 | <p>Here are the shortcodes registered in your WordPress by your theme and other plugins.</p> |
| 292 | <?php |
| 293 | global $shortcode_tags; |
| 294 | try { |
| 295 | if ( is_array( $shortcode_tags ) ) { |
| 296 | $my_shortcodes = array(); |
| 297 | foreach ( $shortcode_tags as $sc ) |
| 298 | if ( $sc != '__return_false' ) { |
| 299 | if ( is_string( $sc ) ) |
| 300 | array_push( $my_shortcodes, str_replace( '_shortcode', '', (string)$sc ) ); |
| 301 | } |
| 302 | $my_shortcodes = implode( ', ', $my_shortcodes ); |
| 303 | } |
| 304 | } |
| 305 | catch (Exception $e) { |
| 306 | $my_shortcodes = ""; |
| 307 | } |
| 308 | echo $my_shortcodes; |
| 309 | ?> |
| 310 | </small></div> |
| 311 | </div> |
| 312 | <?php endif; ?> |
| 313 | --> |
| 314 | |
| 315 | </div> |
| 316 | |
| 317 | </div> |
| 318 | </div> |
| 319 | <?php |
| 320 | } |
| 321 | |
| 322 | |
| 323 | |
| 324 | /* |
| 325 | OPTIONS CALLBACKS |
| 326 | */ |
| 327 | |
| 328 | function admin_method_callback( $args ) { |
| 329 | $value = get_option( 'wpmc_method', 'media' ); |
| 330 | $html = '<select id="wpmc_method" name="wpmc_method"> |
| 331 | <option ' . selected( 'media', $value, false ) . 'value="media">Media Library</option> |
| 332 | <option ' . disabled( $this->is_registered(), false, false ) . ' ' . selected( 'files', $value, false ) . 'value="files">Filesystem (Pro)</option> |
| 333 | </select><small><br />' . __( 'Check the <a target="_blank" href="https://meowapps.com/media-cleaner-tutorial/">tutorial</a> for more information.', 'media-cleaner' ) . '</small>'; |
| 334 | |
| 335 | // TODO: This is temporary |
| 336 | // $html .= '<br /><br /><small><b style="color: red;">Notice: </b><b> Those settings will be simplified soon. Have a look <a href="https://trello.com/c/qrCuITg8/55-cleaner-simplification-of-the-settings" target="_blank">here</a> and let me know in the comments if you like the idea or not.</b></small>'; |
| 337 | |
| 338 | echo $html; |
| 339 | } |
| 340 | |
| 341 | |
| 342 | // function admin_shortcode_callback( $args ) { |
| 343 | // $value = get_option( 'wpmc_shortcode', null ); |
| 344 | // $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_shortcode" name="wpmc_shortcode" value="1" ' . |
| 345 | // checked( 1, get_option( 'wpmc_shortcode' ), false ) . '/>'; |
| 346 | // $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>'; |
| 347 | // echo $html; |
| 348 | // } |
| 349 | |
| 350 | // function admin_background_callback( $args ) { |
| 351 | // $value = get_option( 'wpmc_background', null ); |
| 352 | // $html = '<input ' . disabled( $this->is_registered(), false, false ) . ' type="checkbox" id="wpmc_background" name="wpmc_background" value="1" ' . |
| 353 | // checked( 1, get_option( 'wpmc_background' ), false ) . '/>'; |
| 354 | // $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>'; |
| 355 | // echo $html; |
| 356 | // } |
| 357 | |
| 358 | function admin_debuglogs_callback( $args ) { |
| 359 | global $wpmc; |
| 360 | $debuglogs = get_option( 'wpmc_debuglogs' ); |
| 361 | $clearlogs = isset ( $_GET[ 'clearlogs' ] ) ? $_GET[ 'clearlogs' ] : 0; |
| 362 | if ( $clearlogs && file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) { |
| 363 | unlink( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ); |
| 364 | } |
| 365 | $html = '<input type="checkbox" id="wpmc_debuglogs" name="wpmc_debuglogs" value="1" ' . |
| 366 | checked( 1, $debuglogs, false ) . '/>'; |
| 367 | $html .= '<label for="wpmc_debuglogs"> ' . $args[0] . '</label><br>'; |
| 368 | $html .= '<small>' . __( 'Creates an internal log file, for debugging purposes.', 'media-cleaner' ); |
| 369 | if ( $debuglogs && !file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) { |
| 370 | if ( !$wpmc->log( "Testing the logging feature. It works!" ) ) { |
| 371 | $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__ ) ); |
| 372 | } |
| 373 | } |
| 374 | if ( file_exists( plugin_dir_path( __FILE__ ) . '/media-cleaner.log' ) ) { |
| 375 | $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__ ) ); |
| 376 | } |
| 377 | $html .= '</small>'; |
| 378 | echo $html; |
| 379 | } |
| 380 | |
| 381 | function admin_media_library_callback( $args ) { |
| 382 | $value = get_option( 'wpmc_media_library', true ); |
| 383 | $html = '<input type="checkbox" id="wpmc_media_library" name="wpmc_media_library" value="1" ' . |
| 384 | disabled( get_option( 'wpmc_method', 'media' ) == 'files', false, false ) . ' ' . |
| 385 | checked( 1, $value, false ) . '/>'; |
| 386 | $html .= '<label>Check</label><br /><small>Checks if the file is linked to a media. <i>Only matters to the Filesystem Method.</i></small>'; |
| 387 | echo $html; |
| 388 | } |
| 389 | |
| 390 | function admin_content_callback( $args ) { |
| 391 | $value = get_option( 'wpmc_content', true ); |
| 392 | $html = '<input type="checkbox" id="wpmc_content" name="wpmc_content" value="1" ' . |
| 393 | checked( 1, $value, false ) . '/>'; |
| 394 | $html .= '<label>Check</label><br /><small>Check if the media/file is used in the content, such as Posts, Pages (and other Post Types), Metadata, Widgets, etc.</small>'; |
| 395 | echo $html; |
| 396 | } |
| 397 | |
| 398 | function admin_live_content_callback( $args ) { |
| 399 | $value = get_option( 'wpmc_live_content', false ); |
| 400 | $html = '<input ' . disabled( $this->is_registered(), false, false ) . |
| 401 | ' type="checkbox" id="wpmc_content" name="wpmc_live_content" value="1" ' . |
| 402 | checked( 1, $value, false ) . '/>'; |
| 403 | $html .= '<label>Check</label><br /><small>The live version of the website will be also analyzed (as if a visitor was loading it). <i>This will increase the accuracy of the results.</i></small>'; |
| 404 | echo $html; |
| 405 | } |
| 406 | |
| 407 | // function admin_posts_callback( $args ) { |
| 408 | // $value = get_option( 'wpmc_posts', true ); |
| 409 | // $html = '<input type="checkbox" id="wpmc_posts" name="wpmc_posts" value="1" ' . |
| 410 | // checked( 1, get_option( 'wpmc_posts' ), false ) . '/>'; |
| 411 | // $html .= '<label>Analyze</label><br /><small>Check if the media/file is used by any post types.</small>'; |
| 412 | // echo $html; |
| 413 | // } |
| 414 | |
| 415 | // function admin_postmeta_callback( $args ) { |
| 416 | // $value = get_option( 'wpmc_postmeta', true ); |
| 417 | // $html = '<input type="checkbox" id="wpmc_postmeta" name="wpmc_postmeta" value="1" ' . |
| 418 | // checked( 1, get_option( 'wpmc_postmeta' ), false ) . '/>'; |
| 419 | // $html .= '<label>Analyze</label><br /><small>Checks if the media/file is used in the meta.</small>'; |
| 420 | // echo $html; |
| 421 | // } |
| 422 | |
| 423 | // function admin_widgets_callback( $args ) { |
| 424 | // $value = get_option( 'wpmc_widgets', false ); |
| 425 | // $html = '<input type="checkbox" id="wpmc_widgets" name="wpmc_widgets" value="1" ' . |
| 426 | // checked( 1, get_option( 'wpmc_widgets' ), false ) . '/>'; |
| 427 | // $html .= '<label>Analyze</label><br /><small>Checks if the media/file is used by any widget.</small>'; |
| 428 | // echo $html; |
| 429 | // } |
| 430 | |
| 431 | function admin_hide_thumbnails_callback( $args ) { |
| 432 | $value = get_option( 'wpmc_hide_thumbnails', null ); |
| 433 | $html = '<input type="checkbox" id="wpmc_hide_thumbnails" name="wpmc_hide_thumbnails" value="1" ' . |
| 434 | checked( 1, get_option( 'wpmc_hide_thumbnails' ), false ) . '/>'; |
| 435 | $html .= '<label>Hide</label><br /><small>If you prefer not to see the thumbnails.</small>'; |
| 436 | echo $html; |
| 437 | } |
| 438 | |
| 439 | function admin_hide_warning_callback( $args ) { |
| 440 | $value = get_option( 'wpmc_hide_warning', null ); |
| 441 | $html = '<input type="checkbox" id="wpmc_hide_warning" name="wpmc_hide_warning" value="1" ' . |
| 442 | checked( 1, get_option( 'wpmc_hide_warning' ), false ) . '/>'; |
| 443 | $html .= '<label>Hide</label><br /><small>Have you read it twice? If yes, hide it :)</small>'; |
| 444 | echo $html; |
| 445 | } |
| 446 | |
| 447 | function admin_results_per_page( $args ) { |
| 448 | $value = get_option( 'wpmc_results_per_page', 20 ); |
| 449 | $html = <<< HTML |
| 450 | <input step="1" min="1" max="999" name="wpmc_results_per_page" id="wpmc_results_per_page" maxlength="3" value="{$value}" type="number"> |
| 451 | HTML; |
| 452 | echo $html; |
| 453 | } |
| 454 | |
| 455 | function admin_thumbnails_only_callback( $args ) { |
| 456 | $value = get_option( 'wpmc_thumbnails_only', false ); |
| 457 | $html = '<input type="checkbox" id="wpmc_thumbnails_only" name="wpmc_thumbnails_only" value="1" ' . |
| 458 | disabled( get_option( 'wpmc_method', 'media' ) == 'files', false, false ) . ' ' . |
| 459 | checked( 1, get_option( 'wpmc_thumbnails_only' ), false ) . '/>'; |
| 460 | $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>'; |
| 461 | echo $html; |
| 462 | } |
| 463 | |
| 464 | function admin_dirs_filter_callback( $args ) { |
| 465 | $value = get_option( 'wpmc_dirs_filter', '' ); |
| 466 | $invalid = @preg_match( $value, '' ) === false; |
| 467 | ?> |
| 468 | <input type="text" id="wpmc_dirs_filter" name="wpmc_dirs_filter" value="<?php echo $value; ?>" placeholder="/regex/" autocomplete="off" data-needs-validation style="font-family: monospace;"> |
| 469 | <?php |
| 470 | } |
| 471 | |
| 472 | function admin_files_filter_callback( $args ) { |
| 473 | $value = get_option( 'wpmc_files_filter', '' ); |
| 474 | $invalid = @preg_match( $value, '' ) === false; |
| 475 | ?> |
| 476 | <input type="text" id="wpmc_files_filter" name="wpmc_files_filter" value="<?php echo $value; ?>" placeholder="/regex/" autocomplete="off" data-needs-validation style="font-family: monospace;"> |
| 477 | <?php |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * |
| 482 | * GET / SET OPTIONS (TO REMOVE) |
| 483 | * |
| 484 | */ |
| 485 | |
| 486 | function old_getoption( $option, $section, $default = '' ) { |
| 487 | $options = get_option( $section ); |
| 488 | if ( isset( $options[$option] ) ) { |
| 489 | if ( $options[$option] == "off" ) { |
| 490 | return false; |
| 491 | } |
| 492 | if ( $options[$option] == "on" ) { |
| 493 | return true; |
| 494 | } |
| 495 | return $options[$option]; |
| 496 | } |
| 497 | return $default; |
| 498 | } |
| 499 | |
| 500 | } |
| 501 | |
| 502 | ?> |
| 503 |