/var/www/hkosl.com/aga/wp-content/plugins/wordpress-seo/admin/onpage/class-onpage.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
/**
 * WPSEO plugin file.
 *
 * @package WPSEO\Admin
 */

/**
 * Handles the request for getting the Ryte status.
 */
class WPSEO_OnPage implements WPSEO_WordPress_Integration {

    
/**
     * The name of the user meta key for storing the dismissed status.
     *
     * @var string
     */
    
const USER_META_KEY 'wpseo_dismiss_onpage';

    
/**
     * Is the request started by pressing the fetch button.
     *
     * @var boolean
     */
    
private $is_manual_request false;

    
/**
     * Constructs the object.
     */
    
public function __construct() {
        
$this->catch_redo_listener();
    }

    
/**
     * Sets up the hooks.
     *
     * @return void
     */
    
public function register_hooks() {
        
// Adds admin notice if necessary.
        
add_filter'admin_init', array( $this'show_notice' ) );

        if ( ! 
self::is_active() ) {
            return;
        }

        
// Adds weekly schedule to the cron job schedules.
        
add_filter'cron_schedules', array( $this'add_weekly_schedule' ) );

        
// Sets the action for the Ryte fetch.
        
add_action'wpseo_onpage_fetch', array( $this'fetch_from_onpage' ) );
    }

    
/**
     * Shows a notice when the website is not indexable.
     *
     * @return void
     */
    
public function show_notice() {
        
$notification        $this->get_indexability_notification();
        
$notification_center Yoast_Notification_Center::get();

        if ( 
$this->should_show_notice() ) {
            
$notification_center->add_notification$notification );

            return;
        }

        
$notification_center->remove_notification$notification );
    }

    
/**
     * Determines if we can use the functionality.
     *
     * @return bool True if this functionality can be used.
     */
    
public static function is_active() {
        if ( 
wp_doing_ajax() ) {
            return 
false;
        }

        if ( ! 
WPSEO_Options::get'onpage_indexability' ) ) {
            return 
false;
        }

        return 
true;
    }

    
/**
     * Hooks to run on plugin activation.
     */
    
public function activate_hooks() {
        if ( 
$this->get_option()->is_enabled() ) {
            
$this->schedule_cron();

            return;
        }

        
$this->unschedule_cron();
    }

    
/**
     * Adds a weekly cron schedule.
     *
     * @param array $schedules Currently scheduled items.
     *
     * @return array Enriched list of schedules.
     */
    
public function add_weekly_schedule$schedules ) {
        if ( ! 
is_array$schedules ) ) {
            
$schedules = array();
        }

        
$schedules['weekly'] = array(
            
'interval' => WEEK_IN_SECONDS,
            
'display'  => __'Once Weekly''wordpress-seo' ),
        );

        return 
$schedules;
    }

    
/**
     * Fetches the data from Ryte.
     *
     * @return bool True if this has been run.
     */
    
public function fetch_from_onpage() {
        
$onpage_option $this->get_option();
        if ( ! 
$onpage_option->should_be_fetched() ) {
            return 
false;
        }

        
$new_status $this->request_indexability();
        if ( 
false === $new_status ) {
            return 
false;
        }

        
// Updates the timestamp in the option.
        
$onpage_option->set_last_fetchtime() );

        
// The currently indexability status.
        
$old_status $onpage_option->get_status();

        
$onpage_option->set_status$new_status );
        
$onpage_option->save_option();

        
// Check if the status has been changed.
        
if ( $old_status !== $new_status && $new_status !== WPSEO_OnPage_Option::CANNOT_FETCH ) {
            
$this->notify_admins();
        }

        return 
true;
    }

    
/**
     * Retrieves the option to use.
     *
     * @return WPSEO_OnPage_Option The option.
     */
    
protected function get_option() {
        return new 
WPSEO_OnPage_Option();
    }

    
/**
     * Builds the indexability notification.
     *
     * @return Yoast_Notification The notification.
     */
    
private function get_indexability_notification() {
        
$notice sprintf(
            
/* translators: 1: opens a link to a related knowledge base article. 2: closes the link */
            
__'%1$sYour homepage cannot be indexed by search engines%2$s. This is very bad for SEO and should be fixed.''wordpress-seo' ),
            
'<a href="' WPSEO_Shortlinker::get'https://yoa.st/onpageindexerror' ) . '" target="_blank">',
            
'</a>'
        
);

        return new 
Yoast_Notification(
            
$notice,
            array(
                
'type'         => Yoast_Notification::ERROR,
                
'id'           => 'wpseo-dismiss-onpageorg',
                
'capabilities' => 'wpseo_manage_options',
            )
        );
    }

    
/**
     * Sends a request to Ryte to get the indexability.
     *
     * @return int|bool The indexability value.
     */
    
protected function request_indexability() {
        
$parameters = array();
        if ( 
$this->wordfence_protection_enabled() ) {
            
$parameters['wf_strict'] = 1;
        }

        
$request  = new WPSEO_OnPage_Request();
        
$response $request->do_requestget_option'home' ), $parameters );

        if ( isset( 
$response['is_indexable'] ) ) {
            return (int) 
$response['is_indexable'];
        }

        return 
WPSEO_OnPage_Option::CANNOT_FETCH;
    }

    
/**
     * Should the notice being given?
     *
     * @return bool True if a notice should be shown.
     */
    
protected function should_show_notice() {
        if ( ! 
$this->get_option()->is_enabled() ) {
            return 
false;
        }

        
// If development mode is on or the blog is not public, just don't show this notice.
        
if ( WPSEO_Utils::is_development_mode() || ( '0' === get_option'blog_public' ) ) ) {
            return 
false;
        }

        return 
$this->get_option()->get_status() === WPSEO_OnPage_Option::IS_NOT_INDEXABLE;
    }

    
/**
     * Notifies the admins.
     *
     * @return void
     */
    
protected function notify_admins() {
        
/*
         * Let's start showing the notices to all admins by removing the hide-notice meta data for each admin resulting
         * in popping up the notice again.
         */
        
delete_metadata'user'0self::USER_META_KEY''true );
    }

    
/**
     * Schedules the cronjob to get the new indexibility status.
     *
     * @return void
     */
    
private function schedule_cron() {
        if ( 
wp_next_scheduled'wpseo_onpage_fetch' ) ) {
            return;
        }

        
wp_schedule_eventtime(), 'weekly''wpseo_onpage_fetch' );
    }

    
/**
     * Unschedules the cronjob to get the new indexibility status.
     *
     * @return void
     */
    
private function unschedule_cron() {
        if ( ! 
wp_next_scheduled'wpseo_onpage_fetch' ) ) {
            return;
        }

        
wp_clear_scheduled_hook'wpseo_onpage_fetch' );
    }

    
/**
     * Redo the fetch request for Ryte.
     *
     * @return void
     */
    
private function catch_redo_listener() {
        if ( ! 
self::is_active() ) {
            return;
        }

        if ( 
filter_inputINPUT_GET'wpseo-redo-onpage' ) === '1' ) {
            
$this->is_manual_request true;

            
add_action'admin_init', array( $this'fetch_from_onpage' ) );
        }
    }

    
/**
     * Checks if WordFence protects the site against 'fake' Google crawlers.
     *
     * @return boolean True if WordFence protects the site.
     */
    
private function wordfence_protection_enabled() {
        if ( ! 
class_exists'wfConfig' ) ) {
            return 
false;
        }

        if ( ! 
method_exists'wfConfig''get' ) ) {
            return 
false;
        }

        return (bool) 
wfConfig::get'blockFakeBots' );
    }
}