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.9.7 6.9.8 6.9.9 7.0.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.0.6 7.0.7
media-cleaner / engine.php
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
engine.php
148 lines
1 <?php
2
3 class Meow_WPMC_Engine {
4
5 function __construct( $core, $admin ) {
6 $this->core = $core;
7 $this->admin = $admin;
8 }
9
10 /*
11 STEP 1: Parse the content, and look for references
12 */
13
14 // Parse the posts for references (based on $limit and $limitsize for paging the scan)
15 function parse( $limit, $limitsize, &$message = '' ) {
16 if ( empty( $limit ) )
17 $this->core->reset_issues();
18
19 $method = get_option( 'wpmc_method', 'media' );
20 $check_library = get_option(' wpmc_media_library', true );
21 $check_postmeta = get_option( 'wpmc_postmeta', false );
22 $check_posts = get_option( 'wpmc_posts', false );
23 $check_widgets = get_option( 'wpmc_widgets', false );
24
25 if ( $method == 'media' && !$check_posts && !$check_postmeta && !$check_widgets ) {
26 $message = __( "Posts, Meta and Widgets analysis are all off. Done.", 'media-cleaner' );
27 return true;
28 }
29 if ( $method == 'files' && $check_library && !$check_posts && !$check_postmeta && !$check_widgets ) {
30 $message = __( "Posts, Meta and Widgets analysis are all off. Done.", 'media-cleaner' );
31 return true;
32 }
33
34 // Initialize the parsers
35 do_action( 'wpmc_initialize_parsers' );
36
37 global $wpdb;
38 // Maybe we could avoid to check more post_types.
39 // SELECT post_type, COUNT(*) FROM `wp_posts` GROUP BY post_type
40 $posts = $wpdb->get_col( $wpdb->prepare( "SELECT p.ID FROM $wpdb->posts p
41 WHERE p.post_status != 'inherit'
42 AND p.post_status != 'trash'
43 AND p.post_status != 'auto-draft'
44 AND p.post_type != 'attachment'
45 AND p.post_type != 'shop_order'
46 AND p.post_type != 'shop_order_refund'
47 AND p.post_type != 'nav_menu_item'
48 AND p.post_type != 'revision'
49 AND p.post_type != 'auto-draft'
50 AND p.post_type != 'wphb_minify_group'
51 AND p.post_type != 'customize_changeset'
52 AND p.post_type != 'oembed_cache'
53 AND p.post_type NOT LIKE 'ml-slide%'
54 AND p.post_type NOT LIKE '%acf-%'
55 AND p.post_type NOT LIKE '%edd_%'
56 LIMIT %d, %d", $limit, $limitsize
57 )
58 );
59
60 // Only at the beginning
61 if ( empty( $limit ) ) {
62 $this->core->log( "Parsed references:" );
63 if ( get_option( 'wpmc_widgets', false ) ) {
64
65 global $wp_registered_widgets;
66 $syswidgets = $wp_registered_widgets;
67 $active_widgets = get_option( 'sidebars_widgets' );
68 foreach ( $active_widgets as $sidebar_name => $widgets ) {
69 if ( $sidebar_name != 'wp_inactive_widgets' && !empty( $widgets ) && is_array( $widgets ) ) {
70 foreach ( $widgets as $key => $widget ) {
71 do_action( 'wpmc_scan_widget', $syswidgets[$widget] );
72 }
73 }
74 }
75
76 do_action( 'wpmc_scan_widgets' );
77 }
78 do_action( 'wpmc_scan_once' );
79 }
80
81 $this->core->timeout_check_start( count( $posts ) );
82
83 foreach ( $posts as $post ) {
84 $this->core->timeout_check();
85
86 // Check Meta
87 if ( $check_postmeta )
88 do_action( 'wpmc_scan_postmeta', $post );
89
90 // Check Posts
91 if ( $check_posts ) {
92 // Get HTML for this post
93 $html = get_post_field( 'post_content', $post );
94 do_action( 'wpmc_scan_post', $html, $post );
95 }
96
97 // Extra scanning methods
98 do_action( 'wpmc_scan_extra', $post );
99
100 $this->core->timeout_check_additem();
101 }
102
103 // Write the references found (and cached) by the parsers
104 $this->core->write_references();
105
106 $finished = count( $posts ) < $limitsize;
107 if ( $finished )
108 $this->core->log();
109 $message = __( "Posts checked.", 'media-cleaner' );
110 return $finished;
111 }
112
113 /*
114 STEP 2: List the media entries (or files)
115 */
116
117 // Get files in /uploads (if path is null, the root of /uploads is returned)
118 function get_files( $path = null ) {
119 $files = apply_filters( 'wpmc_list_uploaded_files', null, $path );
120 return $files;
121 }
122
123 function get_media_entries( $limit, $limitsize ) {
124 global $wpdb;
125 $results = $wpdb->get_col( $wpdb->prepare( "SELECT p.ID FROM $wpdb->posts p
126 WHERE p.post_status = 'inherit'
127 AND p.post_type = 'attachment'
128 LIMIT %d, %d", $limit, $limitsize
129 )
130 );
131 return $results;
132 }
133
134 /*
135 STEP 3: Check the media entries (or files) against the references
136 */
137
138 function check_media( $media ) {
139 return $this->core->check_media( $media );
140 }
141
142 function check_file( $file ) {
143 return apply_filters( 'wpmc_check_file', true, $file );
144 }
145
146 }
147
148 ?>