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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 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
149 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', false );
25
26 if ( $method == 'media' && $check_posts && !$check_content && !$check_postmeta && !$check_widgets ) {
27 $message = __( "Posts, Meta and Widgets analysis are all off. Done.", 'media-cleaner' );
28 return true;
29 }
30 if ( $method == 'files' && $check_library && !$check_content && !$check_posts && !$check_postmeta && !$check_widgets ) {
31 $message = __( "Posts, Meta and Widgets analysis are all 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 Meta
88 if ( $check_content || $check_postmeta )
89 do_action( 'wpmc_scan_postmeta', $post );
90
91 // Check Posts
92 if ( $check_content || $check_posts ) {
93 // Get HTML for this post
94 $html = get_post_field( 'post_content', $post );
95 do_action( 'wpmc_scan_post', $html, $post );
96 }
97
98 // Extra scanning methods
99 do_action( 'wpmc_scan_extra', $post );
100
101 $this->core->timeout_check_additem();
102 }
103
104 // Write the references found (and cached) by the parsers
105 $this->core->write_references();
106
107 $finished = count( $posts ) < $limitsize;
108 if ( $finished )
109 $this->core->log();
110 $message = __( "Posts checked.", 'media-cleaner' );
111 return $finished;
112 }
113
114 /*
115 STEP 2: List the media entries (or files)
116 */
117
118 // Get files in /uploads (if path is null, the root of /uploads is returned)
119 function get_files( $path = null ) {
120 $files = apply_filters( 'wpmc_list_uploaded_files', null, $path );
121 return $files;
122 }
123
124 function get_media_entries( $limit, $limitsize ) {
125 global $wpdb;
126 $results = $wpdb->get_col( $wpdb->prepare( "SELECT p.ID FROM $wpdb->posts p
127 WHERE p.post_status = 'inherit'
128 AND p.post_type = 'attachment'
129 LIMIT %d, %d", $limit, $limitsize
130 )
131 );
132 return $results;
133 }
134
135 /*
136 STEP 3: Check the media entries (or files) against the references
137 */
138
139 function check_media( $media ) {
140 return $this->core->check_media( $media );
141 }
142
143 function check_file( $file ) {
144 return apply_filters( 'wpmc_check_file', true, $file );
145 }
146
147 }
148
149 ?>