SILENT KILLERPanel

Current Path: > home > codekrsu > > escapematrixonline.com > wp-content > plugins > optinmonster > > OMAPI


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: /home/codekrsu//escapematrixonline.com/wp-content/plugins/optinmonster//OMAPI

NameTypeSizeLast ModifiedActions
EasyDigitalDownloads Directory - -
Elementor Directory - -
Integrations Directory - -
MemberPress Directory - -
Plugins Directory - -
Promos Directory - -
Rules Directory - -
Shortcodes Directory - -
WPForms Directory - -
WooCommerce Directory - -
Actions.php File 7126 bytes February 25 2025 01:06:30.
Ajax.php File 1494 bytes November 17 2021 04:02:26.
Api.php File 14508 bytes February 25 2025 01:06:30.
ApiAuth.php File 2463 bytes October 07 2021 23:34:50.
ApiKey.php File 5205 bytes July 01 2024 22:14:00.
AssetLoader.php File 5721 bytes April 01 2021 19:57:40.
BaseRestApi.php File 6807 bytes October 15 2024 19:52:30.
Blocks.php File 13118 bytes March 26 2025 18:07:30.
ClassicEditor.php File 7085 bytes July 19 2022 01:42:26.
ConstantContact.php File 7602 bytes July 01 2024 22:14:00.
Debug.php File 4453 bytes July 01 2024 22:14:00.
EasyDigitalDownloads.php File 9553 bytes July 01 2024 22:14:00.
Elementor.php File 5493 bytes January 18 2023 22:34:56.
Inserter.php File 11562 bytes September 14 2022 06:35:44.
InstallSkin.php File 1386 bytes January 20 2021 22:11:00.
InstallSkinCompat.php File 1395 bytes January 20 2021 22:11:00.
MailPoet.php File 13680 bytes July 01 2024 22:14:00.
MemberPress.php File 4216 bytes June 23 2023 01:24:22.
Menu.php File 15787 bytes November 27 2024 23:45:46.
Notifications.php File 18910 bytes October 15 2024 19:52:30.
OmuApi.php File 4122 bytes October 27 2021 22:35:34.
Output.php File 24860 bytes September 16 2024 23:28:26.
Pages.php File 17172 bytes March 31 2025 18:30:04.
Partners.php File 4805 bytes July 01 2024 22:14:00.
Plugins.php File 24923 bytes April 23 2024 17:54:30.
Promos.php File 1132 bytes September 14 2022 06:35:44.
Refresh.php File 5891 bytes March 31 2025 18:30:04.
RestApi.php File 39506 bytes October 15 2024 19:52:30.
RevenueAttribution.php File 3037 bytes May 17 2022 18:55:22.
Review.php File 1482 bytes September 08 2021 19:22:54.
Rules.php File 24003 bytes July 01 2024 22:14:00.
Save.php File 11057 bytes October 13 2023 01:19:08.
Shortcode.php File 3668 bytes November 30 2021 23:04:18.
Sites.php File 8554 bytes July 01 2024 22:14:00.
Support.php File 8446 bytes February 25 2025 01:06:30.
Type.php File 2496 bytes February 11 2023 00:30:54.
Urls.php File 8996 bytes November 13 2024 02:13:58.
Utils.php File 7590 bytes March 31 2025 18:30:04.
Validate.php File 9280 bytes February 22 2024 23:03:38.
WPForms.php File 2666 bytes July 27 2023 00:06:52.
Welcome.php File 4930 bytes November 17 2021 04:02:26.
Widget.php File 6652 bytes November 17 2021 04:02:26.
WooCommerce.php File 20046 bytes July 01 2024 22:14:00.
Wordfence.php File 5606 bytes October 09 2024 11:38:44.
WpErrorException.php File 714 bytes November 17 2020 01:51:02.

Reading File: /home/codekrsu//escapematrixonline.com/wp-content/plugins/optinmonster//OMAPI/Save.php

<?php
/**
 * Save class.
 *
 * @since 1.0.0
 *
 * @package OMAPI
 * @author  Thomas Griffin
 */

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

/**
 * Save class.
 *
 * @since 1.0.0
 */
class OMAPI_Save {

	/**
	 * Holds the class object.
	 *
	 * @since 1.0.0
	 *
	 * @var object
	 */
	public static $instance;

	/**
	 * Path to the file.
	 *
	 * @since 1.0.0
	 *
	 * @var string
	 */
	public $file = __FILE__;

	/**
	 * Holds save error.
	 *
	 * @since 1.0.0
	 *
	 * @var mixed
	 */
	public $error = null;

	/**
	 * Holds the base class object.
	 *
	 * @since 1.0.0
	 *
	 * @var object
	 */
	public $base;

	/**
	 * Primary class constructor.
	 *
	 * @since 1.0.0
	 */
	public function __construct() {

		// Set our object.
		$this->set();
	}

	/**
	 * Sets our object instance and base class instance.
	 *
	 * @since 1.0.0
	 */
	public function set() {
		self::$instance = $this;
		$this->base     = OMAPI::get_instance();
	}

	/**
	 * Store the optin data locally on the site.
	 *
	 * @since 1.0.0
	 *
	 * @param array $optins  Array of optin objects to store.
	 * @param bool  $enabled Whether newly-added campaigns are auto-enabled. Default is true.
	 */
	public function store_optins( $optins, $enabled = true ) {
		/**
		 * Allows the filtering of what campaigns are stored locally.
		 *
		 * @since 1.6.3
		 *
		 * @param array  $optins An array of `WP_Post` objects.
		 * @param object $this   The OMAPI object.
		 *
		 * @return array The filtered `WP_Post` objects array.
		 */
		$optins = apply_filters( 'optin_monster_pre_store_options', $optins, $this );

		// Do nothing if this is just a success message.
		if ( isset( $optins->success ) ) {
			return;
		}

		// Loop through all of the local optins so we can try to match and update.
		$local_optins = $this->base->get_optins( array( 'post_status' => 'any' ) );
		if ( ! empty( $local_optins ) ) {
			$this->sync_optins( $local_optins, $optins, $enabled );
		} else {
			$this->add_optins( $optins, $enabled );
		}

	}

	/**
	 * Add the retrieved optins as new optin post objects in the DB.
	 *
	 * @since 1.3.5
	 *
	 * @param array $optins  Array of optin objects to store.
	 * @param bool  $enabled Whether newly-added campaigns are auto-enabled. Default is true.
	 */
	public function add_optins( $optins, $enabled = true ) {
		foreach ( (array) $optins as $slug => $optin ) {
			// Maybe update an optin rather than add a new one.
			$local = $this->base->get_optin_by_slug( $slug );
			if ( $local ) {
				$this->update_optin( $local, $optin );
			} else {
				$this->new_optin( $slug, $optin, $enabled );
			}
		}
	}

	/**
	 * Sync the retrieved optins with our stored optins.
	 *
	 * @since 1.3.5
	 *
	 * @param array $local_optins  Array of local optin objects to sync.
	 * @param array $remote_optins Array of optin objects to store.
	 * @param bool  $enabled       Whether newly-added campaigns are auto-enabled. Default is true.
	 */
	public function sync_optins( $local_optins, $remote_optins, $enabled = true ) {
		foreach ( $local_optins as $local ) {

			if ( isset( $remote_optins[ $local->post_name ] ) ) {

				$this->update_optin( $local, $remote_optins[ $local->post_name ] );

				unset( $remote_optins[ $local->post_name ] );
			} else {

				// Delete the local optin. It does not exist remotely.
				$this->delete_optin( $local );
				unset( $remote_optins[ $local->post_name ] );
			}
		}

		// If we still have optins, they are new and we need to add them.
		if ( ! empty( $remote_optins ) ) {
			foreach ( (array) $remote_optins as $slug => $optin ) {
				$local = $this->base->get_optin_by_slug( $slug );
				if ( $local ) {
					$this->update_optin( $local, $optin );
				} else {
					$this->new_optin( $slug, $optin, $enabled );
				}
			}
		}
	}

	/**
	 * Update an existing optin post object in the DB with the one fetched from the API.
	 *
	 * @since  1.3.5
	 *
	 * @param  object $local The local optin post object.
	 * @param  object $optin The optin object.
	 *
	 * @return void
	 */
	public function update_optin( $local, $optin ) {
		$status = 'publish';
		if ( ! empty( $optin->status ) && 'active' !== $optin->status ) {
			$status = 'draft';
		}

		if (
			$optin->title !== $local->post_title
			|| $optin->output !== $local->post_content
			|| $status !== $local->post_status
		) {
			$this->optin_to_db(
				array(
					'ID'           => $local->ID, // Existing ID.
					'post_title'   => $optin->title,
					'post_content' => $optin->output,
					'post_status'  => $status,
				)
			);
		}

		$this->update_optin_meta( $local->ID, $optin );
	}

	/**
	 * Generate a new optin post object in the DB.
	 *
	 * @since  1.3.5
	 *
	 * @param  string $slug    The campaign slug.
	 * @param  object $optin   The optin object.
	 * @param  bool   $enabled Whether the new campaigns are auto-enabled. Default is true.
	 *
	 * @return void
	 */
	public function new_optin( $slug, $optin, $enabled = true ) {
		$status = 'publish';
		if ( ! empty( $optin->status ) && 'active' !== $optin->status ) {
			$status = 'draft';
		}

		$post_id = $this->optin_to_db(
			array(
				'post_name'    => $slug,
				'post_title'   => $optin->title,
				'post_excerpt' => $optin->id,
				'post_content' => $optin->output,
				'post_status'  => $status,
				'post_type'    => OMAPI_Type::SLUG,
			)
		);

		if ( 'post' === $optin->type ) {
			update_post_meta( $post_id, '_omapi_automatic', 1 );
		}

		$enabled = apply_filters( 'optin_monster_auto_enable_campaign', $enabled );
		if ( $enabled ) {
			update_post_meta( $post_id, '_omapi_enabled', true );
		}

		$this->update_optin_meta( $post_id, $optin );
	}

	/**
	 * Adds/updates the optin post-object in the DB.
	 *
	 * @since  1.9.10
	 *
	 * @param  array $args Array of args for post object.
	 *
	 * @return mixed Result
	 */
	protected function optin_to_db( $args ) {
		$priority = has_filter( 'content_save_pre', 'wp_filter_post_kses' );
		if ( false !== $priority ) {
			remove_filter( 'content_save_pre', 'wp_filter_post_kses', $priority );
		}

		if ( ! empty( $args['ID'] ) ) {
			$result = wp_update_post( $args );
		} else {
			$result = wp_insert_post( $args );
		}

		if ( false !== $priority ) {
			add_filter( 'content_save_pre', 'wp_filter_post_kses', $priority );
		}

		return $result;
	}

	/**
	 * Deletes the optin post-type object from the DB.
	 *
	 * @since  1.9.10
	 *
	 * @param  mixed   $id      WP_Post object, or post ID, or campaign slug (post_name).
	 * @param  boolean $by_slug Whether id passed in was the campaign slug.
	 *
	 * @return mixed            Result of wp_delete_post.
	 */
	public function delete_optin( $id, $by_slug = false ) {
		if ( $by_slug ) {
			$id = $this->base->get_optin_by_slug( $id );
		}

		return wp_delete_post( absint( ! empty( $id->ID ) ? $id->ID : $id ), true );
	}

	/**
	 * Update the optin post object's post-meta with an API object's values.
	 *
	 * @since  1.3.5
	 *
	 * @param  int    $post_id The post (optin) ID.
	 * @param  object $optin   The optin object.
	 *
	 * @return void
	 */
	public function update_optin_meta( $post_id, $optin ) {
		update_post_meta( $post_id, '_omapi_type', $optin->type );
		update_post_meta( $post_id, '_omapi_ids', $optin->ids );

		$shortcodes = ! empty( $optin->shortcodes ) ? $optin->shortcodes : null;

		$this->update_shortcodes_meta( $post_id, $shortcodes );
	}

	/**
	 * Store the raw shortcodes to the optin's meta for later retrieval/parsing.
	 *
	 * @since  1.3.5
	 *
	 * @param  int               $post_id    The post (optin) ID.
	 * @param  string|array|null $shortcodes The shortcodes to store to meta, or delete from meta if null.
	 *
	 * @return void
	 */
	protected function update_shortcodes_meta( $post_id, $shortcodes = null ) {
		if ( ! empty( $shortcodes ) ) {
			update_post_meta( $post_id, '_omapi_shortcode_output', self::get_shortcodes_string( $shortcodes ) );
			update_post_meta( $post_id, '_omapi_shortcode', true );
		} else {
			delete_post_meta( $post_id, '_omapi_shortcode_output' );
			delete_post_meta( $post_id, '_omapi_shortcode' );
		}
	}

	/**
	 * Updated the `optin_monster_api` option in the database.
	 *
	 * @since 1.9.8
	 *
	 * @param array $option The full `optin_monster_api` option array.
	 * @param array $data   Optional. The parameters passed in via POST request.
	 *
	 * @return mixed The results of update_option.
	 */
	public function update_option( $option, $data = array() ) {

		// Allow storing the timestamp of when the API is connected for "first time".
		// We are not changing it if the user disconnects and reconnects.
		$connected = $this->base->get_option( 'connected' );
		if ( ! empty( $connected ) ) {
			unset( $option['connected'] );
		}

		/**
		 * Filters the `optin_monster_api` option before being saved to the database.
		 *
		 * @since 1.0.0
		 *
		 * @param array  $option The full `optin_monster_api` option array.
		 * @param array  $data   The parameters passed in via POST request.
		 */
		$option = apply_filters( 'optin_monster_api_save', $option, $data );

		// Save the option.
		return update_option( 'optin_monster_api', $option );
	}

	/**
	 * Handles auto-generating WooCommerce API keys for use with OM.
	 *
	 * @since 1.7.0
	 * @since 2.8.0 All the logic was moved to OMAPI_WooCommerce_Save class.
	 *
	 * @deprecated 2.8.0 Use `OMAPI_WooCommerce_Save->autogenerate()` instead.
	 *
	 * @return array
	 */
	public function woocommerce_autogenerate() {
		_deprecated_function( __FUNCTION__, '2.8.0', 'OMAPI_WooCommerce_Save->autogenerate()' );

		return $this->base->woocommerce->save->autogenerate();
	}

	/**
	 * Handles connecting WooCommerce when the connect button is clicked.
	 *
	 * @since 1.7.0
	 * @since 2.8.0 All the logic was moved to OMAPI_WooCommerce_Save class.
	 *
	 * @deprecated 2.8.0 Use `OMAPI_WooCommerce_Save->connect()` instead.
	 *
	 * @param array $data The data passed in via POST request.
	 *
	 * @return void
	 */
	public function woocommerce_connect( $data ) {
		_deprecated_function( __FUNCTION__, '2.8.0', 'OMAPI_WooCommerce_Save->connect()' );

		return $this->base->woocommerce->save->connect( $data );
	}

	/**
	 * Handles disconnecting WooCommerce when the disconnect button is clicked.
	 *
	 * @since 1.7.0
	 * @since 2.8.0 All the logic was moved to OMAPI_WooCommerce_Save class.
	 *
	 * @deprecated 2.8.0 Use `OMAPI_WooCommerce_Save->disconnect()` instead.
	 *
	 * @param array $data The data passed in via POST request.
	 *
	 * @return void
	 */
	public function woocommerce_disconnect( $data ) {
		_deprecated_function( __FUNCTION__, '2.8.0', 'OMAPI_WooCommerce_Save->disconnect()' );

		return $this->base->woocommerce->save->disconnect( $data );
	}

	/**
	 * Parse shortcodes into a string.
	 *
	 * @since 2.2.0
	 *
	 * @param  mixed $shortcodes Convert shortcodes array to a concatenated string.
	 *
	 * @return string
	 */
	public static function get_shortcodes_string( $shortcodes ) {
		return is_array( $shortcodes )
			? '|||' . implode( '|||', array_map( 'htmlentities', $shortcodes ) )
			: '|||' . htmlentities( $shortcodes, ENT_COMPAT, 'UTF-8' );
	}

}

SILENT KILLER Tool