Файловый менеджер - Редактировать - /home/kunzqhe/photostocker/2/ryte.tar
Ðазад
class-ryte-option.php 0000644 00000006016 15151205061 0010650 0 ustar 00 <?php /** * WPSEO plugin file. * * @package WPSEO\Admin */ /** * This class handles the data for the option where the Ryte data is stored. */ class WPSEO_Ryte_Option { /** * Indicates the data is not fetched. * * @var int */ const NOT_FETCHED = 99; /** * Indicates the option is indexable. * * @var int */ const IS_INDEXABLE = 1; /** * Indicates the option is not indexable. * * @var int */ const IS_NOT_INDEXABLE = 0; /** * Indicates the data could not be fetched. * * @var int */ const CANNOT_FETCH = -1; /** * The name of the option where data will be stored. * * @var string */ const OPTION_NAME = 'wpseo_ryte'; /** * The key of the status in the option. * * @var string */ const STATUS = 'status'; /** * The key of the last fetch date in the option. * * @var string */ const LAST_FETCH = 'last_fetch'; /** * The limit for fetching the status manually. * * @var int */ const FETCH_LIMIT = 15; /** * The Ryte option stored in the database. * * @var array */ private $ryte_option; /** * Setting the object by setting the properties. */ public function __construct() { $this->ryte_option = $this->get_option(); } /** * Getting the status from the option. * * @return string */ public function get_status() { if ( array_key_exists( self::STATUS, $this->ryte_option ) ) { return $this->ryte_option[ self::STATUS ]; } return self::CANNOT_FETCH; } /** * Saving the status to the options. * * @param string $status The status to save. */ public function set_status( $status ) { $this->ryte_option[ self::STATUS ] = $status; } /** * Saving the last fetch timestamp to the options. * * @param int $timestamp Timestamp with the new value. */ public function set_last_fetch( $timestamp ) { $this->ryte_option[ self::LAST_FETCH ] = $timestamp; } /** * Determines whether the indexability status should be fetched. * * If LAST_FETCH isn't set, we assume the indexability status hasn't been fetched * yet and return true. Then, we check whether the last fetch is within the * FETCH_LIMIT time interval (15 seconds) to avoid too many consecutive API calls. * * @return bool Whether the indexability status should be fetched. */ public function should_be_fetched() { if ( ! isset( $this->ryte_option[ self::LAST_FETCH ] ) ) { return true; } return ( ( time() - $this->ryte_option[ self::LAST_FETCH ] ) > self::FETCH_LIMIT ); } /** * Saving the option with the current data. */ public function save_option() { update_option( self::OPTION_NAME, $this->ryte_option ); } /** * Returns the value of the onpage_enabled status. * * @return bool */ public function is_enabled() { return WPSEO_Options::get( 'ryte_indexability' ); } /** * Getting the option with the Ryte data. * * @return array */ private function get_option() { $default = [ self::STATUS => self::NOT_FETCHED, self::LAST_FETCH => 0, ]; return get_option( self::OPTION_NAME, $default ); } } class-ryte-request.php 0000644 00000006567 15151205061 0011043 0 ustar 00 <?php /** * WPSEO plugin file. * * @package WPSEO\Admin */ /** * This class will fetch a new status from Ryte and if it's necessary it will * notify the site admin by email and remove the current meta value to hide the * notice for all admin users. */ class WPSEO_Ryte_Request { /** * The endpoint where the request will be send to. * * @var string */ private $ryte_endpoint = 'https://indexability.yoast.onpage.org/'; /** * Gets the response from the Ryte API and returns the body. * * @param string $target_url The URL to check indexability for. * @param array $parameters Array of extra parameters to send to the Ryte API. * * @return array The successful response or the error details. */ protected function get_remote( $target_url, $parameters = [] ) { $defaults = [ 'url' => $target_url, 'wp_version' => $GLOBALS['wp_version'], 'yseo_version' => WPSEO_VERSION, ]; $parameters = array_merge( $defaults, $parameters ); $url = add_query_arg( $parameters, $this->ryte_endpoint ); // Decrease a chance of "cURL 28 (timeout)" errors by increasing the timeout to 10 seconds. $args = [ 'timeout' => 10 ]; $response = wp_remote_get( $url, $args ); return $this->process_response( $response ); } /** * Sends a request to the Ryte API to check whether a URL is indexable. * * @param string $target_url The URL to check indexability for. * @param array $parameters Array of extra parameters to send to the Ryte API. * * @return array */ public function do_request( $target_url, $parameters = [] ) { $json_body = $this->get_remote( $target_url, $parameters ); // Ryte recognized a redirect, fetch the data of that URL by calling this method with the value from Ryte. if ( ! empty( $json_body['passes_juice_to'] ) ) { return $this->do_request( $json_body['passes_juice_to'], $parameters ); } return $json_body; } /** * Processes the given Ryte response. * * @param array|WP_Error $response The response or WP_Error to process. * * @return array The response body or the error detaiils on failure. */ protected function process_response( $response ) { // Most of the potential errors are WP_Error(s). if ( is_wp_error( $response ) ) { return [ 'is_error' => true, 'raw_error_code' => '', // WP_Error codes aren't that helpful for users, let's display them in a less prominent way. 'wp_error_code' => '(' . $response->get_error_code() . ')', 'message' => $response->get_error_message(), ]; } /* * As of February 2020 the Ryte API returns an error 500 for non-reachable * sites. There's also the need to handle any potential raw HTTP error. */ if ( wp_remote_retrieve_response_code( $response ) !== 200 ) { // Not all HTTP errors may have a response message. Let's provide a default one. $response_message = wp_remote_retrieve_response_message( $response ); $message = ( $response_message ) ? $response_message : __( 'The request to Ryte returned an error.', 'wordpress-seo' ); return [ 'is_error' => true, 'raw_error_code' => wp_remote_retrieve_response_code( $response ), 'wp_error_code' => '', 'message' => $message, ]; } // When the request is successful, the response code will be 200. $response_body = wp_remote_retrieve_body( $response ); return json_decode( $response_body, true ); } } class-ryte.php 0000644 00000011423 15151205061 0007340 0 ustar 00 <?php /** * WPSEO plugin file. * * @package WPSEO\Admin */ /** * Handles the request for getting the Ryte status. */ class WPSEO_Ryte implements WPSEO_WordPress_Integration { /** * Is the request started by pressing the fetch button. * * @var bool */ private $is_manual_request = false; /** * Holds the Ryte API response. * * @var array */ private $ryte_response = null; /** * Constructs the object. */ public function __construct() { $this->maybe_add_weekly_schedule(); } /** * Sets up the hooks. * * @return void */ public function register_hooks() { if ( ! self::is_active() ) { return; } // Sets the action for the Ryte fetch cron job. add_action( 'wpseo_ryte_fetch', [ $this, 'fetch_from_ryte' ] ); } /** * 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( 'ryte_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(); } /** * Determines whether to add a custom cron weekly schedule. * * @return void */ public function maybe_add_weekly_schedule() { // If there's no default cron weekly schedule, add a custom one. add_filter( 'cron_schedules', [ $this, 'add_weekly_schedule' ] ); } /** * Adds a custom weekly cron schedule. * * @param array $schedules The existing custom cron schedules. * * @return array Enriched list of custom cron schedules. */ public function add_weekly_schedule( $schedules ) { if ( ! is_array( $schedules ) ) { $schedules = []; } /* * Starting with version 5.4, WordPress does have a default weekly cron * schedule. See https://core.trac.wordpress.org/changeset/47062. * We need to add a custom one only if the default one doesn't exist. */ if ( isset( $schedules['weekly'] ) ) { return $schedules; } $schedules['weekly'] = [ 'interval' => WEEK_IN_SECONDS, 'display' => __( 'Once Weekly', 'wordpress-seo' ), ]; return $schedules; } /** * Fetches the data from Ryte. * * @return bool|null Whether the request ran. */ public function fetch_from_ryte() { // Don't do anything when the WordPress environment type isn't "production". if ( wp_get_environment_type() !== 'production' ) { return; } $ryte_option = $this->get_option(); if ( ! $ryte_option->should_be_fetched() ) { return false; } $new_status = $this->request_indexability(); // Updates the timestamp in the option. $ryte_option->set_last_fetch( time() ); $ryte_option->set_status( $new_status ); $ryte_option->save_option(); return true; } /** * Retrieves the option to use. * * @return WPSEO_Ryte_Option The option. */ protected function get_option() { return new WPSEO_Ryte_Option(); } /** * Sends a request to Ryte to get the indexability status. * * @return int The indexability status value. */ protected function request_indexability() { $parameters = []; if ( $this->wordfence_protection_enabled() ) { $parameters['wf_strict'] = 1; } $request = new WPSEO_Ryte_Request(); $response = $request->do_request( get_option( 'home' ), $parameters ); // Populate the ryte_response property. $this->ryte_response = $response; // It's a valid Ryte response because the array contains an `is_indexable` element. if ( isset( $response['is_indexable'] ) ) { return (int) $response['is_indexable']; } // It's not a valid Ryte response. return WPSEO_Ryte_Option::CANNOT_FETCH; } /** * Schedules the cronjob to get the new indexability status. * * @return void */ private function schedule_cron() { if ( wp_next_scheduled( 'wpseo_ryte_fetch' ) ) { return; } wp_schedule_event( time(), 'weekly', 'wpseo_ryte_fetch' ); } /** * Unschedules the cronjob to get the new indexability status. * * @return void */ private function unschedule_cron() { if ( ! wp_next_scheduled( 'wpseo_ryte_fetch' ) ) { return; } wp_clear_scheduled_hook( 'wpseo_ryte_fetch' ); } /** * Checks if WordFence protects the site against 'fake' Google crawlers. * * @return bool 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' ); } /** * Retrieves the Ryte API response property. * * @return array|WP_Error The response or WP_Error on failure. */ public function get_response() { return $this->ryte_response; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Ð“ÐµÐ½ÐµÑ€Ð°Ñ†Ð¸Ñ Ñтраницы: 0 |
proxy
|
phpinfo
|
ÐаÑтройка