Uname: Linux p3plzcpnl499967.prod.phx3.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
Software: Apache
PHP version: 8.2.30 [ PHP INFO ] PHP os: Linux
Server Ip: 208.109.40.231
Your Ip: 216.73.216.26
User: nayff91c5tsx (10005085) | Group: nayff91c5tsx (10005085)
Safe Mode: OFF
Disable Function:
NONE

name : Client.php
<?php

namespace FluentFormPro\Integrations\Zapier;

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

use Exception;
use FluentForm\Framework\Foundation\Application;

class Client
{
	use NotifyTrait;

	protected $app = null;
	protected $table = 'fluentform_form_meta';
	protected $metaKey = 'fluentform_zapier_feed';
	protected $baseUrl = 'https://hooks.zapier.com/hooks/catch/';

	public function __construct(Application $app)
	{
		$this->app = $app;
	}

	/**
	 * Get Zapier Feeds
	 * @return JSON Response
	 */
	public function getNotifications()
	{
		$hooks = wpFluent()
		->table($this->table)
		->where('form_id', intval($this->app->request->get('form_id')))
		->where('meta_key', $this->metaKey)
		->get();

		if ($hooks) {
			$hooks = array_map(function($hook) {
				$hook->value = json_decode($hook->value);
				return $hook;
			}, $hooks);
		}

		wp_send_json_success($hooks);
	}

	/**
	 * Save Zapier Feed
	 * @return JSON Response
	 */
	public function saveNotification()
	{
		$request = $this->validate($this->app->request->all());

		if (empty($request['id'])) {
			$id = $this->insertNotification($request);
		} else {
			$id = $this->updateNotification($request);
		}

		wp_send_json_success(['id' => $id]);
	}

	protected function insertNotification($request)
	{
		return wpFluent()
		->table($this->table)
		->insertGetId([
			'meta_key' => $this->metaKey,
			'form_id' => $request['form_id'],
			'value' => $request['value']
		]);
	}

	protected function updateNotification($request)
	{
		wpFluent()
		->table($this->table)
		->where('id', $id = $request['id'])
		->update(['value' => $request['value']]);

		return $id;
	}

	/**
	 * Delete Zapier Feed
	 * @return JSON Response
	 */
	public function deleteNotification()
    {
    	try {
    		wpFluent()
			->table($this->table)
			->where('id', $this->app->request->get('id'))
			->delete();

	        wp_send_json_success();
    	} catch(Exception $e) {
    		wp_send_json_error();
    	}
    }

    protected function validate($request)
	{
		$validator = fluentValidator($request['value'], [
			'name' => 'required',
			'url' => 'required|url'
		]);

		if ($validator->validate()->fails()) {
			wp_send_json_error($validator->errors(), 422);
		}

		$request['value']['url'] = esc_url_raw($request['value']['url']);
		$request['value']['name'] = sanitize_text_field($request['value']['name']);
		
		$request['value'] = json_encode($request['value']);

		return $request;
	}
}
© 2026 GrazzMean