| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: ChatBot Conversational Forms for Lead Generation |
| 4 |
* Plugin URI: https://www.wpbot.pro/ |
| 5 |
* Description: ChatBot Conversational Forms for Lead Generation |
| 6 |
* Author: ChatBot for WordPress - WPBot |
| 7 |
* @author QuantumCloud |
| 8 |
* Version: 1.5.0 |
| 9 |
* Donate link: https://www.wpbot.pro/ |
| 10 |
* @author QuantumCloud |
| 11 |
* Author URI: https://www.wpbot.pro/ |
| 12 |
* Requires at least: 4.6 |
| 13 |
* Tested up to: 7.1 |
| 14 |
* Text Domain: conversational-form-builder |
| 15 |
*/ |
| 16 |
|
| 17 |
|
| 18 |
// If this file is called directly, abort. |
| 19 |
if ( !defined('WPINC') ) { |
| 20 |
die; |
| 21 |
} |
| 22 |
|
| 23 |
// Abort execution if Pro version is active to prevent conflicts |
| 24 |
if ( ! function_exists( 'is_plugin_active' ) ) { |
| 25 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 26 |
} |
| 27 |
if ( is_plugin_active( 'wpbot-pro-master/qcld-wpwbot.php' ) || is_plugin_active( 'wpbot-pro-professional/qcld-wpwbot.php' ) ) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
// Also abort if we are currently activating the Pro plugin |
| 32 |
if ( isset($_REQUEST['action']) ) { |
| 33 |
if ( $_REQUEST['action'] == 'activate' && isset($_REQUEST['plugin']) && ( ( strpos($_REQUEST['plugin'], 'wpbot-pro-master') !== false ) || ( strpos($_REQUEST['plugin'], 'wpbot-pro-professional') !== false ) ) ) { |
| 34 |
return; |
| 35 |
} |
| 36 |
if ( $_REQUEST['action'] == 'activate-selected' && isset($_POST['checked']) && ( in_array('wpbot-pro-master/qcld-wpwbot.php', $_POST['checked']) || in_array('wpbot-pro-professional/qcld-wpwbot.php', $_POST['checked']) ) ) { |
| 37 |
return; |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
add_action( 'init', function(){ |
| 42 |
//hack to make code splitting work. |
| 43 |
if( false !== strpos( $_SERVER['REQUEST_URI'], 'wp-admin/clients/') ){ |
| 44 |
wfb_redirect(plugin_dir_url(__FILE__).str_replace( '/wp-admin/', '',$_SERVER['REQUEST_URI']));exit; |
| 45 |
} |
| 46 |
|
| 47 |
}); |
| 48 |
|
| 49 |
global $wp_version; |
| 50 |
if ( !version_compare(PHP_VERSION, '5.6.0', '>=') ) { |
| 51 |
function qcformbuilder_forms_php_version_nag() |
| 52 |
{ |
| 53 |
?> |
| 54 |
<div class="notice notice-error"> |
| 55 |
<p> |
| 56 |
<?php esc_html_e('Your version of PHP is incompatible with Qcformbuilder Forms and can not be used.', |
| 57 |
'qcformbuilder-forms'); ?> |
| 58 |
</p> |
| 59 |
</div> |
| 60 |
<?php |
| 61 |
} |
| 62 |
|
| 63 |
add_shortcode('qcformbuilder_form', 'qcformbuilder_forms_fallback_shortcode'); |
| 64 |
add_shortcode('qcformbuilder_form_modal', 'qcformbuilder_forms_fallback_shortcode'); |
| 65 |
add_action('admin_notices', 'qcformbuilder_forms_php_version_nag'); |
| 66 |
} elseif ( !version_compare($wp_version, '4.7.0', '>=') ) { |
| 67 |
function qcformbuilder_forms_wp_version_nag() |
| 68 |
{ |
| 69 |
?> |
| 70 |
<div class="notice notice-error"> |
| 71 |
<p> |
| 72 |
<?php esc_html_e('Your version of WordPress is incompatible with Qcformbuilder Forms and can not be used.', |
| 73 |
'qcformbuilder-forms'); ?> |
| 74 |
</p> |
| 75 |
</div> |
| 76 |
<?php |
| 77 |
} |
| 78 |
|
| 79 |
add_shortcode('qcformbuilder_form', 'qcformbuilder_forms_fallback_shortcode'); |
| 80 |
add_shortcode('qcformbuilder_form_modal', 'qcformbuilder_forms_fallback_shortcode'); |
| 81 |
add_action('admin_notices', 'qcformbuilder_forms_wp_version_nag'); |
| 82 |
} else { |
| 83 |
if ( ! defined('WFBCORE_PATH') ) { |
| 84 |
define('WFBCORE_PATH', plugin_dir_path(__FILE__)); |
| 85 |
} |
| 86 |
if ( ! defined('WFBCORE_URL') ) { |
| 87 |
define('WFBCORE_URL', plugin_dir_url(__FILE__)); |
| 88 |
} |
| 89 |
if ( ! defined('WFBCORE_VER') ) { |
| 90 |
define( 'WFBCORE_VER', '1.5.0' ); |
| 91 |
} |
| 92 |
if ( ! defined('WFBCORE_EXTEND_URL') ) { |
| 93 |
define('WFBCORE_EXTEND_URL', 'https://api.qcformbuilderforms.com/1.0/'); |
| 94 |
} |
| 95 |
if ( ! defined('WFBCORE_BASENAME') ) { |
| 96 |
define('WFBCORE_BASENAME', plugin_basename(__FILE__)); |
| 97 |
} |
| 98 |
/** |
| 99 |
* Qcformbuilder Forms DB version |
| 100 |
* |
| 101 |
* @since 1.3.4 |
| 102 |
* |
| 103 |
* PLEASE keep this an integer |
| 104 |
*/ |
| 105 |
if ( ! defined('WFB_DB') ) { |
| 106 |
define('WFB_DB', 8); |
| 107 |
} |
| 108 |
|
| 109 |
// init internals of CF |
| 110 |
include_once WFBCORE_PATH . 'classes/core.php'; |
| 111 |
|
| 112 |
add_action('init', [ 'Qcformbuilder_Forms', 'init_wfb_internal' ]); |
| 113 |
// table builder |
| 114 |
register_activation_hook(__FILE__, [ 'Qcformbuilder_Forms', 'activate_qcformbuilder_forms' ]); |
| 115 |
|
| 116 |
|
| 117 |
// load system |
| 118 |
add_action('plugins_loaded', 'qcformbuilder_forms_load', 0); |
| 119 |
if( !function_exists('qcformbuilder_forms_load')){ |
| 120 |
function qcformbuilder_forms_load() |
| 121 |
{ |
| 122 |
include_once WFBCORE_PATH . 'classes/autoloader.php'; |
| 123 |
include_once WFBCORE_PATH . 'classes/widget.php'; |
| 124 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_DB', WFBCORE_PATH . 'classes/db'); |
| 125 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Entry', WFBCORE_PATH . 'classes/entry'); |
| 126 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Email', WFBCORE_PATH . 'classes/email'); |
| 127 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Admin', WFBCORE_PATH . 'classes/admin'); |
| 128 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Render', WFBCORE_PATH . 'classes/render'); |
| 129 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Sync', WFBCORE_PATH . 'classes/sync'); |
| 130 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_CSV', WFBCORE_PATH . 'classes/csv'); |
| 131 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Processor_Interface', WFBCORE_PATH . 'processors/classes/interfaces'); |
| 132 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_API', WFBCORE_PATH . 'classes/api'); |
| 133 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Field', WFBCORE_PATH . 'classes/field'); |
| 134 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Magic', WFBCORE_PATH . 'classes/magic'); |
| 135 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Processor', WFBCORE_PATH . 'processors/classes'); |
| 136 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Shortcode', WFBCORE_PATH . 'classes/shortcode'); |
| 137 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_CDN', WFBCORE_PATH . 'classes/cdn'); |
| 138 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Settings', WFBCORE_PATH . 'classes/settings'); |
| 139 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Import', WFBCORE_PATH . 'classes/import'); |
| 140 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms_Query', WFBCORE_PATH . 'classes/query'); |
| 141 |
Qcformbuilder_Forms_Autoloader::add_root('Qcformbuilder_Forms', WFBCORE_PATH . 'classes'); |
| 142 |
Qcformbuilder_Forms_Autoloader::register(); |
| 143 |
|
| 144 |
|
| 145 |
// includes |
| 146 |
include_once WFBCORE_PATH . 'includes/ajax.php'; |
| 147 |
include_once WFBCORE_PATH . 'includes/field_processors.php'; |
| 148 |
include_once WFBCORE_PATH . 'includes/custom_field_class.php'; |
| 149 |
include_once WFBCORE_PATH . 'includes/filter_addon_plugins.php'; |
| 150 |
include_once WFBCORE_PATH . 'includes/compat.php'; |
| 151 |
include_once WFBCORE_PATH . 'processors/functions.php'; |
| 152 |
include_once WFBCORE_PATH . 'includes/functions.php'; |
| 153 |
include_once WFBCORE_PATH . 'ui/blocks/init.php'; |
| 154 |
include_once WFBCORE_PATH . 'vendor/autoload.php'; |
| 155 |
include_once WFBCORE_PATH . 'includes/wfb-pro-client/wfb-pro-init.php'; |
| 156 |
require_once("class-qc-free-plugin-upgrade-notice.php"); |
| 157 |
|
| 158 |
/** |
| 159 |
* Runs after all of the includes and autoload setup is done in Qcformbuilder Forms core |
| 160 |
* |
| 161 |
* @since 1.3.5.3 |
| 162 |
*/ |
| 163 |
do_action('qcformbuilder_forms_includes_complete'); |
| 164 |
|
| 165 |
/** |
| 166 |
* Start cf2 system |
| 167 |
* |
| 168 |
* @since 1.8.0 |
| 169 |
*/ |
| 170 |
add_action('qcformbuilder_forms_v2_init', 'qcformbuilder_forms_v2_container_setup' ); |
| 171 |
qcformbuilder_forms_get_v2_container(); |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
add_action('plugins_loaded', [ 'Qcformbuilder_Forms', 'get_instance' ]); |
| 177 |
|
| 178 |
|
| 179 |
// Admin & Admin Ajax stuff. |
| 180 |
if ( is_admin() || defined('DOING_AJAX') ) { |
| 181 |
add_action('plugins_loaded', [ 'Qcformbuilder_Forms_Admin', 'get_instance' ]); |
| 182 |
add_action('plugins_loaded', [ 'Qcformbuilder_Forms_Support', 'get_instance' ]); |
| 183 |
include_once WFBCORE_PATH . 'includes/plugin-page-banner.php'; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
//@see https://github.com/QcformbuilderWP/Qcformbuilder-Forms/issues/2855 |
| 188 |
add_filter( 'qcformbuilder_forms_pro_log_mode', '__return_false' ); |
| 189 |
add_filter( 'qcformbuilder_forms_pro_mail_debug', '__return_false' ); |
| 190 |
|
| 191 |
|
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Shortcode handler to be used when Qcformbuilder Forms can not be loaded |
| 196 |
* |
| 197 |
* @since 1.7.0 |
| 198 |
* |
| 199 |
* @return string |
| 200 |
*/ |
| 201 |
if( ! function_exists('qcformbuilder_forms_fallback_shortcode') ){ |
| 202 |
function qcformbuilder_forms_fallback_shortcode() |
| 203 |
{ |
| 204 |
if ( current_user_can('edit_posts') ) { |
| 205 |
return esc_html__('Your version of WordPress or PHP is incompatible with Qcformbuilder Forms.', 'qcformbuilder-forms'); |
| 206 |
} |
| 207 |
|
| 208 |
return esc_html__('Form could not be loaded. Contact the site administrator.', 'qcformbuilder-forms'); |
| 209 |
|
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
if(!function_exists('qc_get_first_field')){ |
| 215 |
function qc_get_first_field($array){ |
| 216 |
foreach($array as $k=>$v){ |
| 217 |
return $k; |
| 218 |
} |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
if(!function_exists('qcld_condition_check')){ |
| 223 |
function qcld_condition_check($form, $condition){ |
| 224 |
|
| 225 |
global $wpdb; |
| 226 |
$group = $condition['group']; |
| 227 |
$result = false; |
| 228 |
foreach($group as $key=>$value){ |
| 229 |
foreach($value as $k=>$v){ |
| 230 |
|
| 231 |
$fieldid = $v['field']; |
| 232 |
$compare = $v['compare']; |
| 233 |
$val = $v['value']; |
| 234 |
$fields = $form['fields']; |
| 235 |
$table = $wpdb->prefix.'wfb_form_entry_values'; |
| 236 |
|
| 237 |
$row = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $table WHERE 1 and `field_id` = %d order by id desc limit 1",$fieldid) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- table name from $wpdb->prefix + constant |
| 238 |
|
| 239 |
if(isset($fields[$fieldid]['type']) && $fields[$fieldid]['type']=='dropdown'){ |
| 240 |
|
| 241 |
foreach($fields[$fieldid]['config']['option'] as $ok=>$ov){ |
| 242 |
if($ok==$val && $ov['value']==$row->value){ |
| 243 |
$result = true; |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
}else{ |
| 248 |
|
| 249 |
if($compare=='is'){ |
| 250 |
if($row->value==$val){ |
| 251 |
$result = true; |
| 252 |
} |
| 253 |
} |
| 254 |
if($compare=='contains'){ |
| 255 |
if (strpos($row->value, $val) !== false) { |
| 256 |
$result = true; |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
} |
| 261 |
|
| 262 |
} |
| 263 |
|
| 264 |
} |
| 265 |
return $result; |
| 266 |
} |
| 267 |
} |
| 268 |
if( ( !empty($_GET['page']) && $_GET['page'] == 'qcformbuilder-form-wpbot') ){ |
| 269 |
// add_action( 'admin_notices', 'qcld_condition_promotion_notice'); |
| 270 |
} |
| 271 |
function qcld_condition_promotion_notice(){ |
| 272 |
$promotion_img = WFBCORE_URL . "assets/images/newyear24-wpbot.jpg"; |
| 273 |
?> |
| 274 |
<div data-dismiss-type="qcbot-feedback-notice" class="notice is-dismissible qcbot-feedback" style="background: #e80607"> |
| 275 |
<div class=""> |
| 276 |
<div class="qc-review-text" > |
| 277 |
<a href="https://www.wpbot.pro/pricing/" target="_blank"> |
| 278 |
<img src="<?php echo esc_url($promotion_img); ?>" alt="promotion_img"> |
| 279 |
</a> |
| 280 |
</div> |
| 281 |
</div> |
| 282 |
</div> |
| 283 |
<?php |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
if(!function_exists('qc_get_next_field')){ |
| 288 |
function qc_get_next_field($form, $fieldid){ |
| 289 |
global $wpdb; |
| 290 |
|
| 291 |
$conditions = array(); |
| 292 |
if(isset($form['conditional_groups']['conditions'])){ |
| 293 |
$conditions = $form['conditional_groups']['conditions']; |
| 294 |
} |
| 295 |
$fields = $form['fields']; |
| 296 |
$trigger = 0; |
| 297 |
foreach($form['layout_grid']['fields'] as $k=>$v){ |
| 298 |
if($trigger==1){ |
| 299 |
|
| 300 |
if(trim($fields[$k]['conditions']['type'])!=''){ |
| 301 |
|
| 302 |
$condition = trim($fields[$k]['conditions']['type']); |
| 303 |
if(qcld_condition_check($form, $conditions[$condition])==true){ |
| 304 |
return $k; |
| 305 |
}else{ |
| 306 |
return qc_get_next_field($form, $k); |
| 307 |
} |
| 308 |
|
| 309 |
}else{ |
| 310 |
return $k; |
| 311 |
} |
| 312 |
|
| 313 |
} |
| 314 |
if($k==$fieldid){ |
| 315 |
$trigger = 1; |
| 316 |
} |
| 317 |
|
| 318 |
} |
| 319 |
if($trigger==0){ |
| 320 |
return 'none'; |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
add_action( 'wp_ajax_wpbot_get_form', 'wpbot_get_form' ); |
| 326 |
add_action( 'wp_ajax_nopriv_wpbot_get_form', 'wpbot_get_form' ); |
| 327 |
if(!function_exists('wpbot_get_form')){ |
| 328 |
function wpbot_get_form(){ |
| 329 |
global $wpdb; |
| 330 |
|
| 331 |
$formid = sanitize_text_field($_POST['formid']); |
| 332 |
$table = $wpdb->prefix.'wfb_forms'; |
| 333 |
|
| 334 |
$result = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $table WHERE form_id = %s and type='primary'",$formid) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- table name from $wpdb->prefix + constant |
| 335 |
|
| 336 |
$form = unserialize($result->config); |
| 337 |
$fields = $form['fields']; |
| 338 |
if(isset($form['layout_grid']['fields']) && !empty($form['layout_grid']['fields'])){ |
| 339 |
|
| 340 |
$firstfield = qc_get_first_field($form['layout_grid']['fields']); |
| 341 |
$field = $fields[$firstfield]; |
| 342 |
echo json_encode($field); |
| 343 |
} |
| 344 |
|
| 345 |
die(); |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
add_action( 'wp_ajax_wpbot_capture_form_value', 'wpbot_capture_form_value' ); |
| 350 |
add_action( 'wp_ajax_nopriv_wpbot_capture_form_value', 'wpbot_capture_form_value' ); |
| 351 |
if(!function_exists('wpbot_capture_form_value')){ |
| 352 |
function wpbot_capture_form_value(){ |
| 353 |
global $wpdb; |
| 354 |
|
| 355 |
$formid = sanitize_text_field($_POST['formid']); |
| 356 |
$fieldid = sanitize_text_field($_POST['fieldid']); |
| 357 |
$answer = $_POST['answer']; |
| 358 |
$entry = sanitize_text_field($_POST['entry']); |
| 359 |
$name = sanitize_text_field($_POST['name']); |
| 360 |
|
| 361 |
if($entry==0){ |
| 362 |
|
| 363 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 364 |
$wpdb->insert( |
| 365 |
$wpdb->prefix."wfb_form_entries", |
| 366 |
array( |
| 367 |
'datestamp' => current_time( 'mysql' ), |
| 368 |
'user_id' => 0, |
| 369 |
'form_id' => $formid, |
| 370 |
'status' => 'active' |
| 371 |
) |
| 372 |
); |
| 373 |
|
| 374 |
$entry = $wpdb->insert_id; |
| 375 |
|
| 376 |
} |
| 377 |
if($answer!=''){ |
| 378 |
|
| 379 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 380 |
$wpdb->insert( |
| 381 |
$wpdb->prefix."wfb_form_entry_values", |
| 382 |
array( |
| 383 |
'entry_id' => $entry, |
| 384 |
'field_id' => $fieldid, |
| 385 |
'slug' => '', |
| 386 |
'value' => $answer |
| 387 |
) |
| 388 |
); |
| 389 |
|
| 390 |
} |
| 391 |
$table = $wpdb->prefix.'wfb_forms'; |
| 392 |
|
| 393 |
$result = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table WHERE form_id = %s and type='primary'",$formid)); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- table name from $wpdb->prefix + constant |
| 394 |
|
| 395 |
$form = unserialize($result->config); |
| 396 |
|
| 397 |
$fields = $form['fields']; |
| 398 |
$mailer = $form['mailer']; |
| 399 |
|
| 400 |
$conditions = array(); |
| 401 |
if(isset($form['conditional_groups']['conditions'])){ |
| 402 |
$conditions = $form['conditional_groups']['conditions']; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
//print_r($form['layout_grid']['fields']);exit; |
| 407 |
|
| 408 |
if(isset($form['layout_grid']['fields']) && !empty($form['layout_grid']['fields'])){ |
| 409 |
|
| 410 |
$nextfield = qc_get_next_field($form, $fieldid); |
| 411 |
|
| 412 |
|
| 413 |
if($nextfield!='none' && !empty($fields[$nextfield])){ |
| 414 |
|
| 415 |
$field = $fields[$nextfield]; |
| 416 |
$field['entry'] = $entry; |
| 417 |
|
| 418 |
$field['status'] = 'incomplete'; |
| 419 |
echo json_encode($field); |
| 420 |
|
| 421 |
}else{ |
| 422 |
if(isset($mailer['on_insert']) && $mailer['on_insert']==1){ |
| 423 |
$answers = qc_form_answer($fields, $entry); |
| 424 |
qcld_wb_chatbot_send_form_query($answers, $name, $mailer); |
| 425 |
} |
| 426 |
echo json_encode(array('status'=>'complete')); |
| 427 |
} |
| 428 |
|
| 429 |
}else{ |
| 430 |
if(isset($mailer['on_insert']) && $mailer['on_insert']==1){ |
| 431 |
$answers = qc_form_answer($fields, $entry); |
| 432 |
qcld_wb_chatbot_send_form_query($answers, $name, $mailer); |
| 433 |
} |
| 434 |
echo json_encode(array('status'=>'complete')); |
| 435 |
} |
| 436 |
|
| 437 |
die(); |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
if(!function_exists('qc_form_answer')){ |
| 442 |
function qc_form_answer($fields, $entry){ |
| 443 |
|
| 444 |
global $wpdb; |
| 445 |
$data = array(); |
| 446 |
|
| 447 |
foreach($fields as $key=>$field){ |
| 448 |
|
| 449 |
$fieldid = $field['ID']; |
| 450 |
$question = $field['label']; |
| 451 |
$table = $wpdb->prefix.'wfb_form_entry_values'; |
| 452 |
|
| 453 |
$answer = ''; |
| 454 |
|
| 455 |
if(!empty($fieldid)){ |
| 456 |
$result = $wpdb->get_row($wpdb->prepare("SELECT * FROM $table where entry_id = %s and field_id = %s",$entry,$fieldid)); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter -- table name from $wpdb->prefix + constant |
| 457 |
|
| 458 |
$answer = $result->value; |
| 459 |
} |
| 460 |
if($answer!=''){ |
| 461 |
$data[] = array( |
| 462 |
'question'=>$question, |
| 463 |
'answer' => $answer |
| 464 |
); |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
return $data; |
| 469 |
|
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
if(!function_exists('qcld_wb_chatbot_send_form_query')){ |
| 474 |
function qcld_wb_chatbot_send_form_query($datas, $name, $mailer) { |
| 475 |
|
| 476 |
|
| 477 |
$subject = (isset($mailer['email_subject']) && $mailer['email_subject']!=''?$mailer['email_subject']:'Conversational form data from Chatbot'); |
| 478 |
//Extract Domain |
| 479 |
$url = get_site_url(); |
| 480 |
$url = parse_url($url); |
| 481 |
$domain = $url['host']; |
| 482 |
|
| 483 |
$admin_email = get_option('admin_email'); |
| 484 |
$toEmail = get_option('qlcd_wp_chatbot_admin_email') != '' ? get_option('qlcd_wp_chatbot_admin_email') : $admin_email; |
| 485 |
$fromEmail = "wordpress@" . $domain; |
| 486 |
if(isset($mailer['sender_email']) && $mailer['sender_email']!=''){ |
| 487 |
$fromEmail = $mailer['sender_email']; |
| 488 |
} |
| 489 |
if(isset($mailer['sender_name']) && $mailer['sender_name']!=''){ |
| 490 |
$name = $mailer['sender_name']; |
| 491 |
} |
| 492 |
$conversation_details_text = get_option('qlcd_wp_chatbot_conversation_details') ? get_option('qlcd_wp_chatbot_conversation_details') : esc_html__('Conversation Details', 'wpchatbot'); |
| 493 |
$bodyContent = ""; |
| 494 |
$bodyContent .= '<p><strong>' . $conversation_details_text . ':</strong></p><hr>'; |
| 495 |
|
| 496 |
foreach($datas as $data){ |
| 497 |
|
| 498 |
if(isset($data['question'])){ |
| 499 |
$bodyContent .= '<p>'.esc_html($data['question']).': ' . esc_html($data['answer']) . '</p>'; |
| 500 |
} |
| 501 |
|
| 502 |
} |
| 503 |
|
| 504 |
$bodyContent .= '<p>' . esc_html__('Mail Generated on', 'wpchatbot') . ': ' . the_time('F j, Y g:i a') . '</p>'; |
| 505 |
$body = $bodyContent; |
| 506 |
|
| 507 |
if(isset($mailer['recipients']) && $mailer['recipients']!=''){ |
| 508 |
|
| 509 |
$recipients = explode(',', $mailer['recipients']); |
| 510 |
foreach($recipients as $toEmail){ |
| 511 |
|
| 512 |
//build email body |
| 513 |
|
| 514 |
|
| 515 |
$headers = array(); |
| 516 |
$headers[] = 'Content-Type: text/html; charset=UTF-8'; |
| 517 |
$headers[] = 'From: ' . esc_html($name) . ' <' . esc_html($fromEmail) . '>'; |
| 518 |
@wp_mail(trim($toEmail), $subject, $body, $headers); |
| 519 |
|
| 520 |
} |
| 521 |
|
| 522 |
}else{ |
| 523 |
$headers = array(); |
| 524 |
$headers[] = 'Content-Type: text/html; charset=UTF-8'; |
| 525 |
$headers[] = 'From: ' . esc_html($name) . ' <' . esc_html($fromEmail) . '>'; |
| 526 |
@wp_mail(trim($toEmail), $subject, $body, $headers); |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
} |
| 531 |
} |
| 532 |
if(!function_exists('add_menu_wpbot_adding_page')){ |
| 533 |
add_action( 'admin_menu', 'add_menu_wpbot_adding_page' ); |
| 534 |
function add_menu_wpbot_adding_page(){ |
| 535 |
add_submenu_page( |
| 536 |
'qcformbuilder-forms', |
| 537 |
__( 'ChatBot WPBot', 'qcformbuilder-forms' ), |
| 538 |
__( 'ChatBot WPBot', 'qcformbuilder-forms' ), |
| 539 |
'manage_options', |
| 540 |
'qcformbuilder-form-wpbot', |
| 541 |
'set_wpbot_page' |
| 542 |
|
| 543 |
); |
| 544 |
} |
| 545 |
function set_wpbot_page(){ |
| 546 |
require_once( 'qcld-recommendbot-plugin.php' ); |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
add_action( 'admin_enqueue_scripts', 'wfb_enqueue_wpbot_admin_page_assets' ); |
| 551 |
function wfb_enqueue_wpbot_admin_page_assets( $hook ) { |
| 552 |
$page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 553 |
$is_wpbot_page = ( 'qcformbuilder-form-wpbot' === $page ); |
| 554 |
$is_form_list = ( 'qcformbuilder-forms' === $page && empty( $_GET['edit'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 555 |
$is_form_edit = ( 'qcformbuilder-forms' === $page && ! empty( $_GET['edit'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 556 |
|
| 557 |
if ( ! $is_wpbot_page && ! $is_form_list && ! $is_form_edit ) { |
| 558 |
return; |
| 559 |
} |
| 560 |
|
| 561 |
wp_enqueue_style( |
| 562 |
'wfb-wpbot-admin-page', |
| 563 |
WFBCORE_URL . 'assets/css/wpbot-admin-page.css', |
| 564 |
array(), |
| 565 |
WFBCORE_VER |
| 566 |
); |
| 567 |
|
| 568 |
if ( $is_wpbot_page ) { |
| 569 |
wp_enqueue_script( 'updates' ); |
| 570 |
wp_enqueue_script( 'plugin-install' ); |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
|