HEX
Server: Apache
System: Linux web15f74.uni5.net 5.4.282-1.el8.elrepo.x86_64 #1 SMP Mon Aug 19 18:33:22 EDT 2024 x86_64
User: lucendi (859622)
PHP: 7.4.33
Disabled: apache_child_terminate,c99_buff_prepare,c99_sess_put,dl,exec,leak,link,myshellexec,openlog,passthru,pclose,pcntl_exec,php_check_syntax,php_strip_whitespace,popen,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,symlink,system,socket_listen,socket_create_listen,putenv
Upload Files
File: /home/lucendi/www/wp-content/themes/divi/core/components/api/email/HubSpot.php
<?php

/**
 * Wrapper for HubSpot's API.
 *
 * @since   3.0.72
 *
 * @package ET\Core\API\Email
 */
class ET_Core_API_Email_HubSpot extends ET_Core_API_Email_Provider {

	/**
	 * @inheritDoc
	 */
	public $BASE_URL = 'https://api.hubapi.com/contacts/v1';

	/**
	 * @inheritDoc
	 */
	public $LISTS_URL = 'https://api.hubapi.com/contacts/v1/lists/static';

	/**
	 * @inheritDoc
	 */
	public $SUBSCRIBE_URL = 'https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/@email@';

	/**
	 * @inheritDoc
	 */
	public $name = 'HubSpot';

	/**
	 * @inheritDoc
	 */
	public $slug = 'hubspot';

	protected function _get_list_add_contact_url( $list_id ) {
		$url = "{$this->BASE_URL}/lists/{$list_id}/add";

		return add_query_arg( 'hapikey', $this->data['api_key'], $url );
	}

	protected function _maybe_set_urls( $email = '' ) {
		if ( empty( $this->data['api_key'] ) ) {
			return;
		}

		$this->LISTS_URL     = add_query_arg( 'hapikey', $this->data['api_key'], $this->LISTS_URL );
		$this->SUBSCRIBE_URL = add_query_arg( 'hapikey', $this->data['api_key'], $this->SUBSCRIBE_URL );

		if ( $email ) {
			$this->SUBSCRIBE_URL = str_replace( '@email@', rawurlencode( $email ), $this->SUBSCRIBE_URL );
		}
	}

	/**
	 * @inheritDoc
	 */
	public function get_account_fields() {
		return array(
			'api_key' => array(
				'label' => esc_html__( 'API Key', 'et_core' ),
			),
		);
	}

	/**
	 * @inheritDoc
	 */
	public function get_data_keymap( $keymap = array(), $custom_fields_key = '' ) {
		$keymap = array(
			'list'       => array(
				'list_id'           => 'listId',
				'name'              => 'name',
				'subscribers_count' => 'metaData.size',
			),
			'subscriber' => array(),
			'error'      => array(
				'error_message' => 'message',
			),
		);

		return parent::get_data_keymap( $keymap, $custom_fields_key );
	}

	/**
	 * @inheritDoc
	 */
	public function fetch_subscriber_lists() {
		if ( empty( $this->data['api_key'] ) ) {
			return $this->API_KEY_REQUIRED;
		}

		$this->_maybe_set_urls();

		/**
		 * The maximum number of subscriber lists to request from Hubspot's API at a time.
		 *
		 * @since 3.0.75
		 *
		 * @param int $max_lists Value must be <= 250.
		 */
		$max_lists = (int) apply_filters( 'et_core_api_email_hubspot_max_lists', 250 );

		$this->LISTS_URL = add_query_arg( 'count', $max_lists, $this->LISTS_URL );

		$this->response_data_key = 'lists';

		return parent::fetch_subscriber_lists();
	}

	/**
	 * @inheritDoc
	 */
	public function subscribe( $args, $url = '' ) {
		if ( empty( $this->data['api_key'] ) ) {
			return $this->API_KEY_REQUIRED;
		}

		$this->_maybe_set_urls( $args['email'] );

		$data = array(
			'properties' => array(
				array(
					'property' => 'email',
					'value'    => et_sanitized_previously( $args['email'] ),
				),
				array(
					'property' => 'firstname',
					'value'    => et_sanitized_previously( $args['name'] ),
				),
				array(
					'property' => 'lastname',
					'value'    => et_sanitized_previously( $args['last_name'] ),
				),
			),
		);

		$this->prepare_request( $this->SUBSCRIBE_URL, 'POST', false, $data, true );
		$this->make_remote_request();

		if ( $this->response->ERROR ) {
			return $this->get_error_message();
		}

		$url  = $this->_get_list_add_contact_url( $args['list_id'] );
		$data = array(
			'emails' => array( $args['email'] ),
		);

		$this->prepare_request( $url, 'POST', false, $data, true );
		$this->make_remote_request();

		if ( $this->response->ERROR ) {
			return $this->get_error_message();
		}

		return 'success';
	}
}