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