/var/www/hkosl.com/aga/wp-content/plugins/wordpress-seo/admin/links/class-link-query.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
 * WPSEO plugin file.
 *
 * @package WPSEO\Admin\Links
 */

/**
 * Database helper class.
 */
class WPSEO_Link_Query {

    
/**
     * Determine if there are any unprocessed public posts.
     *
     * @param array $post_types List of post types to check with.
     *
     * @return bool True if unprocessed posts are found, false if none are found.
     */
    
public static function has_unprocessed_posts( array $post_types ) {
        global 
$wpdb;

        if ( empty( 
$post_types ) ) {
            return 
false;
        }

        
$post_types  self::format_post_types$post_types );
        
$count_table self::get_count_table_name();

        
// Get any object which has not got the processed meta key.
        
$query '
            SELECT ID
              FROM ' 
$wpdb->posts ' AS posts
         LEFT JOIN ' 
$count_table ' AS yoast_meta
                ON yoast_meta.object_id = posts.ID
             WHERE posts.post_status = "publish"
               AND posts.post_type IN ( ' 
$post_types ' )
               AND yoast_meta.internal_link_count IS NULL
             LIMIT 1'
;

        
// If anything is found, we have unprocessed posts.
        
$results $wpdb->get_var$query );

        return ! empty( 
$results );
    }

    
/**
     * Filter out posts that have not been processed yet.
     *
     * @param array $post_ids Post IDs to filter.
     *
     * @return array
     */
    
public static function filter_unprocessed_posts( array $post_ids ) {
        global 
$wpdb;

        
$post_ids array_filter$post_ids );
        if ( empty( 
$post_ids ) || array() === $post_ids ) {
            return 
$post_ids;
        }

        
$count_table self::get_count_table_name();

        
$query '
            SELECT object_id
              FROM ' 
$count_table '
             WHERE object_id IN ( ' 
implode','$post_ids ) . ' )
            '
;

        
$results $wpdb->get_results$queryARRAY_A );

        return 
array_map'intval'wp_list_pluck$results'object_id' ) );
    }

    
/**
     * Returns a limited set of unindexed posts.
     *
     * @param array $post_types The post type.
     * @param int   $limit      The limit for the resultset.
     *
     * @return array|null|object The set of unindexed posts.
     */
    
public static function get_unprocessed_posts( array $post_types$limit ) {
        global 
$wpdb;

        
$count_table self::get_count_table_name();
        
$post_types  self::format_post_types$post_types );

        
// @codingStandardsIgnoreStart
        
$query 'SELECT posts.ID, posts.post_content
                  FROM ' 
$wpdb->posts ' AS posts
             LEFT JOIN ' 
$count_table ' AS yoast_meta
                     ON yoast_meta.object_id = posts.ID
                 WHERE posts.post_status = "publish"
                   AND posts.post_type IN ( ' 
$post_types ' )
                   AND yoast_meta.internal_link_count IS NULL
                 LIMIT %d
        '
;
        
// @codingStandardsIgnoreEnd

        
return $wpdb->get_results(
            
$wpdb->prepare$query$limit )
        );
    }

    
/**
     * Returns the total amount of unindexed posts for given post type.
     *
     * @param array $post_types The post types.
     *
     * @return int The total of unindexed posts.
     */
    
public static function get_unprocessed_count( array $post_types ) {
        global 
$wpdb;

        if ( empty( 
$post_types ) ) {
            return 
0;
        }

        
$count_table self::get_count_table_name();
        
$post_types  self::format_post_types$post_types );

        
// @codingStandardsIgnoreStart
        
$query '
            SELECT COUNT( posts.ID )
              FROM ' 
$wpdb->posts ' AS posts
         LEFT JOIN ' 
$count_table ' AS yoast_meta
                ON yoast_meta.object_id = posts.ID
             WHERE posts.post_status = "publish"
               AND posts.post_type IN ( ' 
$post_types ' )
               AND yoast_meta.internal_link_count IS NULL'
;
        
// @codingStandardsIgnoreEnd

        
return (int) $wpdb->get_var$query );
    }

    
/**
     * Returns the table name where the counts are stored.
     *
     * @return string
     */
    
protected static function get_count_table_name() {
        
$storage = new WPSEO_Meta_Storage();
        return 
$storage->get_table_name();
    }

    
/**
     * Formats an array with post types as an SQL string.
     *
     * @param array $post_types The post types to format.
     *
     * @return string Post types formatted for use in SQL statement.
     */
    
protected static function format_post_types( array $post_types ) {
        
$sanitized_post_types array_map'esc_sql'$post_types );
        
$post_types           sprintf'"%s"'implode'", "'$sanitized_post_types ) );

        return 
$post_types;
    }
}