| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : 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,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.3/wp-content/plugins/fluentform/app/Services/WPAsync/ |
Upload File : |
<?php
namespace FluentForm\App\Services\WPAsync;
use FluentForm\App\Helpers\Helper;
use FluentForm\App\Modules\Form\FormDataParser;
use FluentForm\App\Modules\Form\FormFieldsParser;
use FluentForm\Framework\Foundation\Application;
class FluentFormAsyncRequest
{
/**
* $prefix The prefix for the identifier
* @var string
*/
protected $table = 'ff_scheduled_actions';
/**
* $action The action for the identifier
* @var string
*/
protected $action = 'fluentform_background_process';
/**
* $actions Actions to be fired when an async request is sent
* @var array
*/
protected $actions = array();
/**
* $app Instance of Application/Framework
* @var \FluentForm\Framework\Foundation\Application
*/
protected $app = null;
static $formCache = [];
static $entryCache = [];
static $submissionCache = [];
/**
* Construct the Object
* @param \FluentForm\Framework\Foundation\Application $app
*/
public function __construct(Application $app)
{
$this->app = $app;
}
public function queue($feed)
{
return wpFluent()->table($this->table)->insertGetId($feed);
}
public function queueFeeds($feeds)
{
return wpFluent()->table($this->table)
->insert($feeds);
}
public function dispatchAjax($data = [])
{
/* This hook is deprecated and will be removed soon */
$sslVerify = apply_filters('fluentform_https_local_ssl_verify', false);
$args = array(
'timeout' => 0.1,
'blocking' => false,
'body' => $data,
'cookies' => wpFluentForm('request')->cookie(),
'sslverify' => apply_filters('fluentform/https_local_ssl_verify', $sslVerify),
);
$queryArgs = array(
'action' => $this->action,
'nonce' => wp_create_nonce($this->action),
);
$url = add_query_arg($queryArgs, Helper::getAjaxUrl());
wp_remote_post(esc_url_raw($url), $args);
}
public function handleBackgroundCall()
{
$nonce = sanitize_text_field(wpFluentForm('request')->get('nonce', ''));
if (!wp_verify_nonce($nonce, $this->action)) {
die('invalid');
}
$originId = wpFluentForm('request')->get('origin_id', false);
$this->processActions($originId);
echo 'success';
die();
}
public function processActions($originId = false)
{
$actionFeedQuery = wpFluent()->table($this->table)
->where('status', 'pending');
if($originId) {
$actionFeedQuery = $actionFeedQuery->where('origin_id', $originId);
}
$actionFeeds = $actionFeedQuery->get();
if(count($actionFeeds) === 0) {
return;
}
$formCache = [];
$submissionCache = [];
$entryCache = [];
foreach ($actionFeeds as $actionFeed) {
$action = $actionFeed->action;
$feed = Helper::safeUnserialize($actionFeed->data);
$feed['scheduled_action_id'] = $actionFeed->id;
if(isset($submissionCache[$actionFeed->origin_id])) {
$submission = $submissionCache[$actionFeed->origin_id];
} else {
$submission = wpFluent()->table('fluentform_submissions')->find($actionFeed->origin_id);
$submissionCache[$submission->id] = $submission;
}
if(isset($formCache[$submission->form_id])) {
$form = $formCache[$submission->form_id];
} else {
$form = wpFluent()->table('fluentform_forms')->find($submission->form_id);
$formCache[$form->id] = $form;
}
if(isset($entryCache[$submission->id])) {
$entry = $entryCache[$submission->id];
} else {
$entry = $this->getEntry($submission, $form);
$entryCache[$submission->id] = $entry;
}
$formData = json_decode($submission->response, true);
wpFluent()->table($this->table)
->where('id', $actionFeed->id)
->update([
'status' => 'processing',
'retry_count' => $actionFeed->retry_count + 1,
'updated_at' => current_time('mysql')
]);
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- Dynamic hook name for async request
do_action($action, $feed, $formData, $entry, $form);
}
if($originId && !empty($form) && !empty($submission)) {
/* This hook is deprecated and will be removed soon */
do_action('fluentform_global_notify_completed', $submission->id, $form);
do_action('fluentform/global_notify_completed', $submission->id, $form);
}
}
private function getEntry($submission, $form)
{
$formInputs = FormFieldsParser::getEntryInputs($form, ['admin_label', 'raw']);
return FormDataParser::parseFormEntry($submission, $form, $formInputs);
}
public function process($queue)
{
if (is_numeric($queue)) {
$queue = wpFluent()->table($this->table)->where('status', 'pending')->find($queue);
}
if (!$queue || empty($queue->action)) {
return;
}
$action = $queue->action;
$feed = Helper::safeUnserialize($queue->data);
$feed['scheduled_action_id'] = $queue->id;
if (isset(static::$submissionCache[$queue->origin_id])) {
$submission = static::$submissionCache[$queue->origin_id];
} else {
$submission = wpFluent()->table('fluentform_submissions')->find($queue->origin_id);
static::$submissionCache[$submission->id] = $submission;
}
if (isset(static::$formCache[$submission->form_id])) {
$form = static::$formCache[$submission->form_id];
} else {
$form = wpFluent()->table('fluentform_forms')->find($submission->form_id);
static::$formCache[$form->id] = $form;
}
if (isset(static::$entryCache[$submission->id])) {
$entry = static::$entryCache[$submission->id];
} else {
$entry = $this->getEntry($submission, $form);
static::$entryCache[$submission->id] = $entry;
}
$formData = json_decode($submission->response, true);
wpFluent()->table($this->table)
->where('id', $queue->id)
->update([
'status' => 'processing',
'retry_count' => $queue->retry_count + 1,
'updated_at' => current_time('mysql')
]);
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- Dynamic hook name for async request
do_action($action, $feed, $formData, $entry, $form);
$this->maybeFinished($submission->id, $form);
}
public function maybeFinished($originId, $form)
{
$pendingFeeds = wpFluent()->table($this->table)->where([
'status' => 'pending',
'origin_id' => $originId
])->get();
if (count($pendingFeeds) === 0) {
do_action('fluentform/global_notify_completed', $originId, $form);
}
}
}