| 1 |
<?php |
| 2 |
|
| 3 |
use FluentForm\App\Modules\Component\Component; |
| 4 |
|
| 5 |
/** |
| 6 |
* Declare common actions/filters/shortcodes |
| 7 |
*/ |
| 8 |
|
| 9 |
|
| 10 |
/** |
| 11 |
* @var $app \FluentForm\Framework\Foundation\Application |
| 12 |
*/ |
| 13 |
|
| 14 |
add_action('save_post', function ($post_id) { |
| 15 |
if (isset($_POST['post_content'])) { |
| 16 |
$post_content = $_POST['post_content']; |
| 17 |
} else { |
| 18 |
$post = get_post($post_id); |
| 19 |
$post_content = $post->post_content; |
| 20 |
} |
| 21 |
|
| 22 |
$shortcodeIds = \FluentForm\App\Helpers\Helper::getShortCodeIds( |
| 23 |
$post_content, 'fluentform', 'id' |
| 24 |
); |
| 25 |
|
| 26 |
$shortcodeModalIds = \FluentForm\App\Helpers\Helper::getShortCodeIds( |
| 27 |
$post_content, 'fluentform_modal', 'form_id' |
| 28 |
); |
| 29 |
|
| 30 |
if ($shortcodeModalIds) { |
| 31 |
$shortcodeIds = array_merge($shortcodeIds, $shortcodeModalIds); |
| 32 |
} |
| 33 |
|
| 34 |
if ($shortcodeIds) { |
| 35 |
update_post_meta($post_id, '_has_fluentform', $shortcodeIds); |
| 36 |
} elseif (get_post_meta($post_id, '_has_fluentform', true)) { |
| 37 |
update_post_meta($post_id, '_has_fluentform', []); |
| 38 |
} |
| 39 |
}); |
| 40 |
|
| 41 |
$component = new Component($app); |
| 42 |
$component->addRendererActions(); |
| 43 |
$component->addFluentFormShortCode(); |
| 44 |
$component->addFluentFormDefaultValueParser(); |
| 45 |
|
| 46 |
$component = new \FluentForm\App\Modules\Component\Component($app); |
| 47 |
$component->addFluentformSubmissionInsertedFilter(); |
| 48 |
$component->addIsRenderableFilter(); |
| 49 |
|
| 50 |
add_action('wp', function () use ($app) { |
| 51 |
if (isset($_GET['fluentform_pages']) && $_GET['fluentform_pages'] == 1) { |
| 52 |
|
| 53 |
add_action('wp_enqueue_scripts', function () use ($app) { |
| 54 |
wp_enqueue_script('jquery'); |
| 55 |
wp_enqueue_style('fluent-form-styles'); |
| 56 |
$form = wpFluent()->table('fluentform_forms')->find(intval($_REQUEST['preview_id'])); |
| 57 |
if (apply_filters('fluentform_load_default_public', true, $form)) { |
| 58 |
wp_enqueue_style('fluentform-public-default'); |
| 59 |
} |
| 60 |
wp_enqueue_script('fluent-form-submission'); |
| 61 |
wp_enqueue_style('fluent-form-preview', $app->publicUrl('css/preview.css')); |
| 62 |
}); |
| 63 |
|
| 64 |
(new \FluentForm\App\Modules\ProcessExteriorModule())->handleExteriorPages($app); |
| 65 |
} |
| 66 |
}, 1); |
| 67 |
|
| 68 |
$elements = [ |
| 69 |
'select', |
| 70 |
'input_checkbox', |
| 71 |
'input_radio', |
| 72 |
'address', |
| 73 |
'select_country', |
| 74 |
'gdpr_agreement', |
| 75 |
'terms_and_condition', |
| 76 |
]; |
| 77 |
|
| 78 |
foreach ($elements as $element) { |
| 79 |
$event = 'fluentform_response_render_' . $element; |
| 80 |
$app->addFilter($event, function ($response, $field, $form_id, $isLabel = false) { |
| 81 |
$element = $field['element']; |
| 82 |
|
| 83 |
if ($element == 'address' && !empty($response->country)) { |
| 84 |
$countryList = getFluentFormCountryList(); |
| 85 |
if (isset($countryList[$response->country])) { |
| 86 |
$response->country = $countryList[$response->country]; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
if ($element == 'select_country') { |
| 91 |
$countryList = getFluentFormCountryList(); |
| 92 |
if (isset($countryList[$response])) { |
| 93 |
$response = $countryList[$response]; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
if (in_array($field['element'], array('gdpr_agreement', 'terms_and_condition'))) { |
| 98 |
$response = __('Accepted', 'fluentform'); |
| 99 |
} |
| 100 |
|
| 101 |
if($response && $isLabel && in_array($element, ['select', 'input_radio'])) { |
| 102 |
if(isset($field['options'][$response])) { |
| 103 |
return $field['options'][$response]; |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
return \FluentForm\App\Modules\Form\FormDataParser::formatValue($response); |
| 108 |
}, 10, 4); |
| 109 |
} |
| 110 |
|
| 111 |
$app->addFilter('fluentform_response_render_input_file', function ($response, $field, $form_id, $isHtml = false) { |
| 112 |
return \FluentForm\App\Modules\Form\FormDataParser::formatFileValues($response, $isHtml); |
| 113 |
}, 10, 4); |
| 114 |
|
| 115 |
$app->addFilter('fluentform_response_render_input_image', function ($response, $field, $form_id, $isHtml = false) { |
| 116 |
return \FluentForm\App\Modules\Form\FormDataParser::formatImageValues($response, $isHtml); |
| 117 |
}, 10, 4); |
| 118 |
|
| 119 |
$app->addFilter('fluentform_response_render_input_repeat', function ($response, $field, $form_id) { |
| 120 |
return \FluentForm\App\Modules\Form\FormDataParser::formatRepeatFieldValue($response, $field, $form_id); |
| 121 |
}, 10, 3); |
| 122 |
|
| 123 |
$app->addFilter('fluentform_response_render_tabular_grid', function ($response, $field, $form_id, $isHtml = false) { |
| 124 |
return \FluentForm\App\Modules\Form\FormDataParser::formatTabularGridFieldValue($response, $field, $form_id, $isHtml); |
| 125 |
}, 10, 4); |
| 126 |
|
| 127 |
$app->addFilter('fluentform_response_render_input_name', function ($response) { |
| 128 |
return \FluentForm\App\Modules\Form\FormDataParser::formatName($response); |
| 129 |
}, 10, 1); |
| 130 |
|
| 131 |
$app->addFilter('fluentform_filter_insert_data', function ($data) { |
| 132 |
$settings = get_option('_fluentform_global_form_settings', false); |
| 133 |
if (is_array($settings) && isset($settings['misc'])) { |
| 134 |
if (isset($settings['misc']['isIpLogingDisabled'])) { |
| 135 |
if ($settings['misc']['isIpLogingDisabled']) { |
| 136 |
unset($data['ip']); |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
return $data; |
| 141 |
}); |
| 142 |
|
| 143 |
|
| 144 |
// Register api response log hooks |
| 145 |
$app->addAction( |
| 146 |
'fluentform_after_submission_api_response_success', |
| 147 |
'fluentform_after_submission_api_response_success', 10, 6 |
| 148 |
); |
| 149 |
|
| 150 |
$app->addAction( |
| 151 |
'fluentform_after_submission_api_response_failed', |
| 152 |
'fluentform_after_submission_api_response_failed', 10, 6 |
| 153 |
); |
| 154 |
|
| 155 |
function fluentform_after_submission_api_response_success($form, $entryId, $data, $feed, $res, $msg = '') |
| 156 |
{ |
| 157 |
try { |
| 158 |
$isDev = wpFluentForm()->getEnv() != 'production'; |
| 159 |
if (!apply_filters('fluentform_api_success_log', $isDev, $form, $feed)) return; |
| 160 |
|
| 161 |
wpFluent()->table('fluentform_submission_meta')->insert([ |
| 162 |
'response_id' => $entryId, |
| 163 |
'form_id' => $form->id, |
| 164 |
'meta_key' => 'api_log', |
| 165 |
'value' => $msg, |
| 166 |
'name' => $feed->formattedValue['name'], |
| 167 |
'status' => 'success', |
| 168 |
'created_at' => current_time('mysql'), |
| 169 |
'updated_at' => current_time('mysql') |
| 170 |
]); |
| 171 |
} catch (Exception $e) { |
| 172 |
error_log($e->getMessage()); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
function fluentform_after_submission_api_response_failed($form, $entryId, $data, $feed, $res, $msg = '') |
| 177 |
{ |
| 178 |
try { |
| 179 |
|
| 180 |
$isDev = wpFluentForm()->getEnv() != 'production'; |
| 181 |
if (!apply_filters('fluentform_api_failed_log', $isDev, $form, $feed)) return; |
| 182 |
|
| 183 |
wpFluent()->table('fluentform_submission_meta')->insert([ |
| 184 |
'response_id' => $entryId, |
| 185 |
'form_id' => $form->id, |
| 186 |
'meta_key' => 'api_log', |
| 187 |
'value' => json_encode($res), |
| 188 |
'name' => $feed->formattedValue['name'], |
| 189 |
'status' => 'failed', |
| 190 |
'created_at' => current_time('mysql'), |
| 191 |
'updated_at' => current_time('mysql'), |
| 192 |
]); |
| 193 |
} catch (Exception $e) { |
| 194 |
error_log($e->getMessage()); |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
$app->bindInstance( |
| 199 |
'fluentFormAsyncRequest', |
| 200 |
new \FluentForm\App\Services\WPAsync\FluentFormAsyncRequest($app), |
| 201 |
'FluentFormAsyncRequest', |
| 202 |
'FluentForm\App\Services\WPAsync\FluentFormAsyncRequest' |
| 203 |
); |
| 204 |
|
| 205 |
|
| 206 |
$app->addFilter('fluentform-disabled_analytics', function ($status) { |
| 207 |
$settings = get_option('_fluentform_global_form_settings'); |
| 208 |
if (isset($settings['misc']['isAnalyticsDisabled']) && $settings['misc']['isAnalyticsDisabled']) { |
| 209 |
return true; |
| 210 |
} |
| 211 |
return $status; |
| 212 |
}); |
| 213 |
|
| 214 |
$app->addAction('fluentform_before_form_render', function ($form) { |
| 215 |
do_action('fluentform_load_form_assets', $form->id); |
| 216 |
}); |
| 217 |
|
| 218 |
$app->addAction('fluentform_load_form_assets', function ($formId) { |
| 219 |
// check if alreaded loaded |
| 220 |
if (!in_array($formId, \FluentForm\App\Helpers\Helper::$loadedForms)) { |
| 221 |
(new \FluentForm\App\Modules\Form\Settings\FormCssJs())->addCssJs($formId); |
| 222 |
\FluentForm\App\Helpers\Helper::$loadedForms[] = $formId; |
| 223 |
$selectedStyle = \FluentForm\App\Helpers\Helper::getFormMeta($formId, '_ff_selected_style'); |
| 224 |
|
| 225 |
if ($selectedStyle) { |
| 226 |
do_action('fluentform_init_custom_stylesheet', $selectedStyle, $formId); |
| 227 |
} |
| 228 |
} |
| 229 |
}); |
| 230 |
|
| 231 |
$app->addAction('fluentform_submission_inserted', function ($insertId, $formData, $form) use ($app) { |
| 232 |
$notificationManager = new \FluentForm\App\Services\Integrations\GlobalNotificationManager($app); |
| 233 |
$notificationManager->globalNotify($insertId, $formData, $form); |
| 234 |
}, 10, 3); |
| 235 |
|
| 236 |
|
| 237 |
$app->addAction('init', function () use ($app) { |
| 238 |
new \FluentForm\App\Services\Integrations\MailChimp\MailChimpIntegration($app); |
| 239 |
}); |
| 240 |
|
| 241 |
$app->addAction('fluentform_form_element_start', function ($form) use ($app) { |
| 242 |
$honeyPot = new \FluentForm\App\Modules\Form\HoneyPot($app); |
| 243 |
$honeyPot->renderHoneyPot($form); |
| 244 |
}); |
| 245 |
|
| 246 |
$app->addAction('fluentform_before_insert_submission', function ($insertData, $requestData, $form) use ($app) { |
| 247 |
$honeyPot = new \FluentForm\App\Modules\Form\HoneyPot($app); |
| 248 |
$honeyPot->verify($insertData, $requestData, $form->id); |
| 249 |
}, 9, 3); |
| 250 |
|
| 251 |
add_action('ff_log_data', function ($data) use ($app) { |
| 252 |
$dataLogger = new \FluentForm\App\Modules\Logger\DataLogger($app); |
| 253 |
$dataLogger->log($data); |
| 254 |
}); |
| 255 |
|
| 256 |
// permision based filters |
| 257 |
add_filter('fluentform_permission_callback', function ($status, $permission) { |
| 258 |
return (new \FluentForm\App\Modules\Acl\RoleManager())->currentUserFormFormCapability(); |
| 259 |
}, 10, 2); |
| 260 |
|
| 261 |
// widgets |
| 262 |
add_action('widgets_init', function () { |
| 263 |
register_widget('FluentForm\App\Modules\Widgets\SidebarWidgets'); |
| 264 |
}); |
| 265 |
|
| 266 |
add_action('wp', function () { |
| 267 |
global $post; |
| 268 |
|
| 269 |
if (!is_a($post, 'WP_Post')) { |
| 270 |
return; |
| 271 |
} |
| 272 |
|
| 273 |
$fluentFormIds = get_post_meta($post->ID, '_has_fluentform', true); |
| 274 |
|
| 275 |
if ($fluentFormIds && is_array($fluentFormIds)) { |
| 276 |
foreach ($fluentFormIds as $formId) { |
| 277 |
do_action('fluentform_load_form_assets', $formId); |
| 278 |
} |
| 279 |
} |
| 280 |
}); |
| 281 |
|
| 282 |
add_filter('fluentform_validate_input_item_input_email', function ($validation, $field, $formData, $fields, $form) { |
| 283 |
if (\FluentForm\Framework\Helpers\ArrayHelper::get($field, 'raw.settings.is_unique') == 'yes') { |
| 284 |
$fieldName = \FluentForm\Framework\Helpers\ArrayHelper::get($field, 'name'); |
| 285 |
|
| 286 |
if ($inputValue = \FluentForm\Framework\Helpers\ArrayHelper::get($formData, $fieldName)) { |
| 287 |
$exist = wpFluent()->table('fluentform_entry_details') |
| 288 |
->where('form_id', $form->id) |
| 289 |
->where('field_name', $fieldName) |
| 290 |
->where('field_value', $inputValue) |
| 291 |
->first(); |
| 292 |
if ($exist) { |
| 293 |
return [ |
| 294 |
'unique' => \FluentForm\Framework\Helpers\ArrayHelper::get($field, 'raw.settings.unique_validation_message') |
| 295 |
]; |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
return $validation; |
| 301 |
}, 10, 5); |
| 302 |
|
| 303 |
|
| 304 |
add_filter('cron_schedules', function ($schedules) { |
| 305 |
$schedules['ff_every_five_minutes'] = array( |
| 306 |
'interval' => 300, |
| 307 |
'display' => esc_html__('Every 5 minutes (FluentForm)', 'fluentform'), |
| 308 |
); |
| 309 |
return $schedules; |
| 310 |
}, 10, 1); |
| 311 |
|
| 312 |
add_action('fluentform_do_scheduled_tasks', 'fluentFormHandleScheduledTasks'); |
| 313 |
add_action('fluentform_do_email_report_scheduled_tasks', 'fluentFormHandleScheduledEmailReport'); |
| 314 |
|
| 315 |
add_action('ff_integration_action_result', function ($feed, $status, $note = '') { |
| 316 |
if (!isset($feed['scheduled_action_id']) || !$status) { |
| 317 |
return; |
| 318 |
} |
| 319 |
if (!$note) { |
| 320 |
$note = $status; |
| 321 |
} |
| 322 |
$actionId = intval($feed['scheduled_action_id']); |
| 323 |
wpFluent()->table('ff_scheduled_actions') |
| 324 |
->where('id', $actionId) |
| 325 |
->update([ |
| 326 |
'status' => $status, |
| 327 |
'note' => $note |
| 328 |
]); |
| 329 |
}, 10, 3); |
| 330 |
|
| 331 |
add_action('fluentform_global_notify_completed', function ($insertId, $form) use ($app) { |
| 332 |
if(strpos($form->form_fields, '"element":"input_password"') && apply_filters('fluentform_truncate_password_values', true, $form)) { |
| 333 |
// we have password |
| 334 |
(new \FluentForm\App\Services\Integrations\GlobalNotificationManager($app))->cleanUpPassword($insertId, $form); |
| 335 |
} |
| 336 |
}, 10, 2); |
| 337 |
|
| 338 |
/* |
| 339 |
* Elementor Block Init |
| 340 |
*/ |
| 341 |
|
| 342 |
if(defined('ELEMENTOR_VERSION')) { |
| 343 |
new \FluentForm\App\Modules\Widgets\ElementorWidget($app); |
| 344 |
} |