HEX
Server: nginx/1.18.0
System: Linux iZj6c1ieg2jrpk1z5tzi19Z 6.3.9-1.el7.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 21 22:18:40 EDT 2023 x86_64
User: www (1001)
PHP: 8.2.4
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.cytocare.cn/wp-content/plugins/wordpress-seo-premium/src/actions/zapier-action.php
<?php

namespace Yoast\WP\SEO\Premium\Actions;

use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Premium\Helpers\Zapier_Helper;
use Yoast\WP\SEO\Repositories\Indexable_Repository;

/**
 * Handles the actual requests to the Zapier endpoints.
 */
class Zapier_Action {

	/**
	 * Instance of the Options_Helper.
	 *
	 * @var Options_Helper
	 */
	protected $options_helper;

	/**
	 * The Zapier helper.
	 *
	 * @var Zapier_Helper
	 */
	protected $zapier_helper;

	/**
	 * The Indexable repository.
	 *
	 * @var Indexable_Repository
	 */
	protected $indexable_repository;

	/**
	 * Zapier_Action constructor.
	 *
	 * @param Options_Helper       $options_helper       The Options Helper.
	 * @param Zapier_Helper        $zapier_helper        The Zapier helper.
	 * @param Indexable_Repository $indexable_repository The Indexable repository.
	 */
	public function __construct(
		Options_Helper $options_helper,
		Zapier_Helper $zapier_helper,
		Indexable_Repository $indexable_repository
	) {
		$this->options_helper       = $options_helper;
		$this->zapier_helper        = $zapier_helper;
		$this->indexable_repository = $indexable_repository;
	}

	/**
	 * Subscribes Zapier and stores the passed URL for later usage.
	 *
	 * @param string $url     The URL to subscribe.
	 * @param string $api_key The API key from Zapier to check against the one stored in the options.
	 *
	 * @return object The response object.
	 */
	public function subscribe( $url, $api_key ) {
		if ( ! $this->zapier_helper->is_valid_api_key( $api_key ) ) {
			return (object) [
				'data'    => [],
				'message' => 'The API key does not match.',
				'status'  => 500,
			];
		}

		if ( $this->zapier_helper->is_connected() ) {
			return (object) [
				'data'    => [],
				'message' => 'Subscribing failed. A subscription already exists.',
				'status'  => 500,
			];
		}

		$subscription_data = $this->zapier_helper->subscribe_url( $url );

		if ( ! $subscription_data ) {
			return (object) [
				'data'    => [],
				'message' => 'Subscribing failed.',
				'status'  => 500,
			];
		}

		return (object) [
			'data'   => $subscription_data,
			'status' => 200,
		];
	}

	/**
	 * Unsubscribes Zapier based on the passed ID.
	 *
	 * @param string $id The ID to unsubscribe.
	 *
	 * @return object The response object.
	 */
	public function unsubscribe( $id ) {
		if ( ! $this->zapier_helper->is_subscribed_id( $id ) ) {
			return (object) [
				'message' => \sprintf( 'Unsubscribing failed. Subscription with ID `%s` does not exist.', $id ),
				'status'  => 404,
			];
		}

		if ( ! $this->zapier_helper->unsubscribe_id( $id ) ) {
			return (object) [
				'message' => 'Unsubscribing failed. Unable to delete subscription.',
				'status'  => 500,
			];
		}

		return (object) [
			'message' => \sprintf( 'Successfully unsubscribed subscription with ID `%s`.', $id ),
			'status'  => 200,
		];
	}

	/**
	 * Checks the API key submitted by Zapier.
	 *
	 * @param string $api_key The API key from Zapier to check against the one
	 *     stored in the options.
	 *
	 * @return object The response object.
	 */
	public function check_api_key( $api_key ) {
		if ( ! $this->zapier_helper->is_valid_api_key( $api_key ) ) {
			return (object) [
				'data'    => [],
				'message' => 'The API key does not match.',
				'status'  => 500,
			];
		}

		return (object) [
			'data'    => [],
			'message' => 'The API key is valid.',
			'status'  => 200,
		];
	}

	/**
	 * Sends an array of the last published post URLs.
	 *
	 * @param string $api_key The API key from Zapier to check against the one
	 *     stored in the options.
	 *
	 * @return object The response object.
	 */
	public function perform_list( $api_key ) {
		if ( ! $this->zapier_helper->is_valid_api_key( $api_key ) ) {
			return (object) [
				'data'    => [],
				'message' => 'The API key does not match.',
				'status'  => 500,
			];
		}

		$latest_post = \get_posts(
			[
				'numberposts' => 1,
			]
		);
		$zapier_data = [];
		foreach ( $latest_post as $item ) {
			$indexable     = $this->indexable_repository->find_by_id_and_type( $item->ID, 'post' );
			$zapier_data[] = (object) $this->zapier_helper->get_data_for_zapier( $indexable );
		}

		return (object) [
			'data'   => $zapier_data,
			'status' => 200,
		];
	}
}