__( 'Month', 'contact-forms'), 'unique_submissions' => __( 'Unique submissions', 'contact-forms') , 'submissions' => __('Total submissions', 'contact-forms'), ); global $hook_suffix; register_column_headers($hook_suffix, $column_list); //$baseurl = WP_PLUGIN_URL.'/'.substr(plugin_basename(__FILE__),0,-strlen(basename(__FILE__))); //echo ''; //echo ''; //echo ''; } function accua_forms_report_page() { ?>

Forms submissions report

'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); $query = "SELECT YEAR(sub_date) AS `year`, MONTH(sub_date) AS `month`, COUNT(DISTINCT `email`) AS `unique_submissions`, COUNT(*) AS `submissions` FROM `{$wpdb->prefix}cformssubmissions` GROUP BY `year`, `month` ORDER BY `year` DESC, `month` DESC"; $results = $wpdb->get_results($query); if ($results) { ?>
__( 'Unique submissions', 'contact-forms'), 'data' => array()), array( 'label' => __( 'Total submissions', 'contact-forms'), 'data' => array()), ); foreach ($results as $result){ $month = $months[$result->month]; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $time = mktime(0, 0, 0, $result->month, 1, $result->year) * 1000; $data[0]['data'][] = array($time, (int)$result->unique_submissions); $data[1]['data'][] = array($time, (int)$result->submissions); } /* $year = $results[0]->year; $month = $results[0]->month; while ($year <= $result->year || $month <= $result->month) { $month++; if ($month > 12) { $year++; $month = 1; } } */ ?>
$order) { if (strpos($fid, 'cimatti-accua-fields-form-area-') !== 0){ die('-1'); } $fid = substr($fid, 31); if (empty($forms_data[$fid]['fields'])) { die('-1'); } $old_fields = $forms_data[$fid]['fields']; unset($forms_data[$fid]['fields']); $new_fields = array(); $order = explode(',', $order); foreach ($order as $i) { $i = preg_replace('/^(new-)?widget-\\d+_/', '', $i); if (isset($old_fields[$i])) { $new_fields[$i] = $old_fields[$i]; unset($old_fields[$i]); } } if($old_fields){ $new_fields += $old_fields; } $forms_data[$fid]['fields'] = $new_fields; } update_option('accua_forms_saved_forms', $forms_data); die('1'); } add_action( 'wp_ajax_accua-save-form-field', 'accua_forms_save_form_field'); /* azione dove vengono salvati i campi dei un form */ function accua_forms_save_form_field() { if (!current_user_can('manage_options')){ wp_die( -1, 403 ); } check_ajax_referer('edit_form', '_nonce_edit_form'); $post = stripslashes_deep($_POST); //update_option('accua_forms_save_form_field_post', $post); $forms_data = get_option('accua_forms_saved_forms', array()); $fid = $post['form-id']; if (accua_forms_validate_form_id($fid) !== '') { die('-1'); } if (empty($forms_data[$fid]['fields'])) { $forms_data[$fid]['fields'] = array(); } $avail_fields = get_option('accua_forms_avail_fields', array()); @ $wid = (string) $post['widget-id']; if (isset($avail_fields[$wid])) { $check_ref = $wid; } else { if (preg_match('/^(__html|__fieldset-begin|__fieldset-end)-\d+$/', $wid, $matches)) { $check_ref = $matches[1]; } else { die('-1'); } } if (empty($post['delete_widget'])) { //$istance_id = $post['multi_number']; @ $ref = $post['id_base']; if ($ref !== $check_ref) { die('-1'); } $required = !empty($post["form-field-{$wid}-required"]); $widget_number = empty($post['multi_number']) ? (empty($post['widget_number']) ? '' : (int)$post['widget_number']) : (int)$post['multi_number']; if (isset($forms_data[$fid]['fields'][$wid])) { $old_istance_data = $forms_data[$fid]['fields'][$wid]; } else { $old_istance_data = array(); } $forms_data[$fid]['fields'][$wid] = array ( 'version' => 2, 'istance_id' => $wid, 'widget_number' => $widget_number, 'ref' => $ref, 'required' => $required, ); if (!empty($post["form-field-{$wid}-override-label"])) { @ $label = (string) $post["form-field-{$wid}-label"]; if (!current_user_can('unfiltered_html')) { $label = wp_kses($label, 'post'); } $forms_data[$fid]['fields'][$wid]['label'] = $label; } $is_file = false; $is_date = false; if (isset($avail_fields[$wid]['type'])) { if ($avail_fields[$wid]['type'] == 'file') { $is_file = true; } else if ($avail_fields[$wid]['type'] == 'date') { $is_date = true; } } if (!empty($post["form-field-{$wid}-override-default-value"])) { @ $default_value = (string) $post["form-field-{$wid}-default-value"]; if ($is_date) { $default_value = accua_forms_filter_date($default_value); } else if (!current_user_can('unfiltered_html')) { //This is filtered in any case because field type can change $default_value = wp_kses($default_value, 'post'); } $forms_data[$fid]['fields'][$wid]['default_value'] = $default_value; } if (!empty($post["form-field-{$wid}-override-allowed-values"])) { @ $allowed_values = (string) $post["form-field-{$wid}-allowed-values"]; if ($is_file){ $forms_data[$fid]['fields'][$wid]['allowed_extensions'] = accua_forms_filter_extensions($allowed_values); } else { $forms_data[$fid]['fields'][$wid]['allowed_values'] = $allowed_values; } } if (!empty($post["form-field-{$wid}-override-datemin-values"])) { @ $mindate_values = (string) $post["form-field-{$wid}-min-of-date"]; $forms_data[$fid]['fields'][$wid]['min_date'] = accua_forms_filter_date($mindate_values); } if (!empty($post["form-field-{$wid}-override-datemax-values"])) { @ $maxdate_values = (string) $post["form-field-{$wid}-max-of-date"]; $forms_data[$fid]['fields'][$wid]['max_date'] = accua_forms_filter_date($maxdate_values); } } else { unset($forms_data[$fid]['fields'][$wid]); } update_option('accua_forms_saved_forms', $forms_data); die('1'); } function accua_forms_filter_text($text) { if ( is_object( $text ) || is_array( $text ) ) { return ''; } $text = (string) $text; $text = wp_check_invalid_utf8( $text ); $text = preg_replace( '/[ \t\n\r\0\x0B]+/', ' ', $text ); $text = trim( $text ); return $text; } function accua_forms_filter_email($email) { $parts = explode('<', $email); if (isset($parts[1])) { $email = accua_forms_filter_text(trim($parts[1], "<> \t\n\r\0\x0B")); $display_name = accua_forms_filter_text(trim($parts[0])); return "$display_name <$email>"; } else { return accua_forms_filter_text($email); } } function accua_forms_filter_emails($emails) { $split_emails = preg_split("/\s*[,;]\s*/", $emails); $emails = array(); foreach ($split_emails as $email) { $emails[] = accua_forms_filter_email($email); } return implode(', ', $emails); } function accua_forms_filter_extensions($extensions) { $cleaned_extensions = array(); $mimes = get_allowed_mime_types(); $extensions = explode("\n", $extensions); foreach ($extensions as $extension) { $extension = trim($extension); if ($extension !== '') { foreach ( $mimes as $ext_preg => $mime_match ) { $ext_preg = '!^' . $ext_preg . '$!i'; if ( preg_match( $ext_preg, $extension ) ) { $cleaned_extensions[] = $extension; break; } } } } return implode("\n", $cleaned_extensions); } function accua_forms_filter_settings($form_settings) { foreach($form_settings as $k => $v) { switch ($k) { case 'success_message_no_message': case 'error_message_no_message': case 'admin_emails_message_no_message': case 'confirmation_emails_message_no_message': case 'use_ajax': //boolean $form_settings[$k] = (bool) $v; break; case 'layout': $form_settings[$k] = ($v === 'toplabel') ? 'toplabel' : 'sidebyside'; break; case 'emails_from': // single email $form_settings[$k] = accua_forms_filter_email($v); break; case 'admin_emails_to': case 'emails_bcc': //emails list $form_settings[$k] = accua_forms_filter_email($v); break; case 'success_message': case 'error_message': case 'admin_emails_message': case 'confirmation_emails_message': //HTML if (!current_user_can('unfiltered_html')) { $form_settings[$k] = wp_kses($v, 'post'); } break; //case 'title': //case 'emails_from_name': //case 'admin_emails_subject': //case 'confirmation_emails_subject': //case 'style_*': default: // text field $form_settings[$k] = accua_forms_filter_text($v); } } return $form_settings; } add_action( 'wp_ajax_accua-save-form-settings', 'accua_forms_save_form_settings'); function accua_forms_save_form_settings() { if (!current_user_can('manage_options')){ wp_die( -1, 403 ); } check_ajax_referer('edit_form', '_nonce_edit_form'); $post = stripslashes_deep($_POST); $forms_data = get_option('accua_forms_saved_forms', array()); $fid = $post['form-id']; if (accua_forms_validate_form_id($fid) !== '') { die('-1'); } $settings = array( 'title', 'success_message', 'success_message_no_message', 'error_message', 'error_message_no_message', 'emails_from_name', 'emails_from', 'admin_emails_to', 'emails_bcc', 'admin_emails_subject', 'admin_emails_message', 'admin_emails_message_no_message', 'confirmation_emails_subject', 'confirmation_emails_message', 'confirmation_emails_message_no_message', //'use_ajax', 'layout', 'style_margin', 'style_border_color', 'style_border_width', 'style_border_radius', 'style_background_color', 'style_padding', 'style_color', 'style_font_size', 'style_field_spacing', 'style_field_border_color', 'style_field_border_width', 'style_field_border_radius', 'style_field_background_color', 'style_field_padding', 'style_field_color', 'style_submit_border_color', 'style_submit_border_width', 'style_submit_border_radius', 'style_submit_background_color', 'style_submit_padding', 'style_submit_color', 'style_submit_font_size', ); // print_r($post); $new_form_settings = array(); foreach($settings as $i) { if (isset($post[$i])) { $new_form_settings[$i] = $post[$i]; } unset($forms_data[$fid][$i]); } $forms_data[$fid] += accua_forms_filter_settings($new_form_settings); $forms_data[$fid]['use_ajax'] = !empty($post['use_ajax']); update_option('accua_forms_saved_forms', $forms_data); //print_r($forms_data[$fid]); die(''); } function accua_forms_field_settings_form_counter() { static $i = 0; $i++; return $i; } /* impostazioni dei campi */ function accua_forms_field_text_settings_form($fid, $field_data=array(), $istance_data=array()){ static $html_multi_number = 0; $i = accua_forms_field_settings_form_counter(); $hidden = ''; if (!is_array($istance_data)) { if ($istance_data === 'hidden') { $hidden = 'style="display:none"'; } $istance_data = array(); $empty_istance = true; } else { $empty_istance = empty($istance_data); } if (!is_array($field_data)){ $field_data = array(); } $field_data += array( 'version' => '1', 'id' => '__html', 'name' => __( 'Custom HTML content', 'contact-forms'), 'type' => 'html', 'description' => __('Use this special field to inject raw HTML in the form. You can use this multiple times.', 'contact-forms'), 'default_value' => '', 'allowed_values' => '', 'allowed_extensions' => '', ); $override_label = isset($istance_data['label']) ? 'checked="checked"' : ''; $override_default_value = isset($istance_data['default_value']) ? 'checked="checked"' : ''; $override_allowed_values = isset($istance_data['allowed_values']) ? 'checked="checked"' : ''; $override_allowed_extensions = ''; if ($field_data['type'] == 'file') { if (isset($istance_data['version']) && $istance_data['version'] >= 2) { if (isset($istance_data['allowed_extensions'])) { $override_allowed_extensions = 'checked="checked"'; } } else { if (isset($istance_data['allowed_values'])) { $istance_data['allowed_extensions'] = $istance_data['allowed_values']; $override_allowed_extensions = 'checked="checked"'; } } if ($field_data['version'] < 2) { $field_data['allowed_extensions'] = $field_data['allowed_values']; } if ($field_data['allowed_extensions'] === '') { $file_data = get_option('accua_forms_default_file_field_data',array()); if (isset($file_data['valid_extensions'])){ $field_data['allowed_extensions'] = $file_data['valid_extensions']; } } } if ($field_data['type'] == 'date') { $override_mindate_values = isset($istance_data['min_date']) ? 'checked="checked"' : ''; $override_maxdate_values = isset($istance_data['max_date']) ? 'checked="checked"' : ''; //$override_default_value = isset($istance_data['default_date_value']) ? 'checked="checked"' : ''; $istance_data += array( 'min_date' => $field_data['min_date'], 'max_date' => $field_data['max_date'], 'default_value' => $field_data['default_date_value'], ); } $istance_data += array( //'version' => 1, 'istance_id' => $field_data['id'], 'widget_number' => '', 'ref' => $field_data['id'], 'label' => $field_data['name'], 'default_value' => $field_data['default_value'], 'allowed_values' => $field_data['allowed_values'], 'allowed_extensions' => $field_data['allowed_extensions'], 'required' => false, ); foreach ($istance_data as $key => $value) { $istance_data[$key] = htmlspecialchars($istance_data[$key], ENT_QUOTES); } foreach ($field_data as $key => $value) { $field_data[$key] = htmlspecialchars($field_data[$key], ENT_QUOTES); } $multi_number = ''; $add_new = ''; if (in_array($istance_data['ref'], array('__html','__fieldset-begin','__fieldset-end'))) { $forceoverride_field = true; if ($empty_istance) { $add_new = 'multi'; $istance_data['istance_id'] .= '-__i__'; $istance_data['widget_number'] = 1; $multi_number = 1 + $html_multi_number; } else { if ($html_multi_number < $istance_data['widget_number']) { $html_multi_number = $istance_data['widget_number']; } } } else { $forceoverride_field = false; $add_new = $empty_istance ? 'single' : ''; } $fid = htmlspecialchars($fid, ENT_QUOTES); $testi_eot = array ( 'label' => __( 'Label', 'contact-forms'), 'override' => __( 'override', 'contact-forms'), 'default_value' => __( 'Default value', 'contact-forms'), 'default_values' => __( 'Default value(s)', 'contact-forms'), 'desc_def' => __( 'For multiple default values, use | as separator.', 'contact-forms'), 'allowed_values' => __( 'Allowed values', 'contact-forms'), 'desc_all' => __( 'The possible values this field can contain. Enter one value per line, in the format key|label. The key is the value that will be stored in the database. The label is optional, and the key will be used as the label if no label is specified.', 'contact-forms'), 'allowed_extensions' => __( 'Allowed extensions', 'contact-forms'), 'desc_all_ext' => __( 'Accepted file extensions. One per line, without dots.', 'contact-forms'), 'required' => __( 'Required', 'contact-forms'), 'custom_HTML_content' => __( 'Custom HTML content', 'contact-forms'), 'remove' => __( 'Remove', 'contact-forms'), 'close' => __( 'Close', 'contact-forms'), 'save' => __( 'Save', 'contact-forms'), 'min-of-date' => __( 'Min date', 'contact-forms'), 'max-of-date' => __( 'Max date', 'contact-forms') ); if ($forceoverride_field) { $override_begin = ''; $override_type = 'hidden'; $override_end = ''; } else { $override_begin = "({$testi_eot['override']}: "; $override_type = 'checkbox'; $override_end = ')'; } $content = << {$override_begin}{$override_end}

EOT; $default_value = << {$override_begin}{$override_end}

EOT; $default_values = << {$override_begin}{$override_end}

EOT; $allowed_values = << {$override_begin}{$override_end}

{$testi_eot['desc_all']}

EOT; $allowed_ext = << {$override_begin}{$override_end}

{$testi_eot['desc_all_ext']}

EOT; $required_checked = empty($istance_data['required']) ? '' : 'checked="checked"'; $required = <<

EOT; if ($field_data['type'] == 'date'){ $default_date_value = << {$override_begin}{$override_end}

EOT; $min_date = << {$override_begin}{$override_end}

EOT; $max_date = << {$override_begin}{$override_end}

EOT; } switch ($field_data['type']) { case 'textarea': $content .= << {$override_begin}{$override_end}

$required EOT; break; case 'hidden': $content = $default_value; break; case 'checkbox': $content .= $default_value . $required; break; case 'select': case 'radio': case 'post-select': $content .= $default_value . $allowed_values . $required; break; case 'multiselect': case 'multicheckbox': case 'post-multicheckbox': $content .= $default_values . $allowed_values . $required; break; case 'file': $content .= $allowed_ext . $required; case 'submit': case 'fieldset-begin': //just the label break; case 'fieldset-end': //Nothing! $content = ''; break; case 'html': $content = << {$override_begin}{$override_end}

EOT; break; case 'date': $content .= $default_date_value . $min_date . $max_date . $required; break; case 'email': case 'autoreply_email': case 'textfield': case 'colorpicker': case 'datepicker': case 'dateselect': default: $content .= $default_value . $required; break; } $adminurl = admin_url(); return <<

{$field_data['name']}

EOT; } function accua_forms_add_page($message='') { $forms_data = get_option('accua_forms_saved_forms', array()); $trash_data = get_option('accua_forms_trash_forms', array()); if (!empty($_GET['fid'])) { $fid = htmlspecialchars(stripslashes($_GET['fid']), ENT_QUOTES); } else { if ($message === '') { $fid = 1 + ((int) get_option('accua_forms_lastid', 0)); while (isset($forms_data[$fid]) || isset($trash_data[$fid])) { $fid++; } update_option('accua_forms_lastid', $fid); $message = _accua_forms_test_clonefrom($fid); if ($message === '') { return accua_forms_edit_page($fid); } } else { $fid = ''; } } if (!empty($_GET['clonefrom'])) { check_admin_referer('clone_posts'); $clonefrom = stripslashes($_GET['clonefrom']); } else { $clonefrom = ''; } ?>

$message
"; } ?>

Form id:

'; } ?>

".__( 'Form already exists', 'contact-forms')."

"; } else if (empty($forms_data[$clonefrom])) { $error .= "

".__( 'Source form doesn\'t exists.', 'contact-forms')."

"; } else { $forms_data[$fid] = $forms_data[$clonefrom]; if (!isset($forms_data[$fid]['title'])) { $forms_data[$fid]['title'] = $clonefrom ." ".__( 'clone', 'contact-forms'); } else { $forms_data[$fid]['title'] .= " ". __( 'clone', 'contact-forms'); } update_option('accua_forms_saved_forms', $forms_data); } } return $error; } function _accua_forms_form_edit_action() { static $message = null; if ($message === null) { $message = ''; if (isset($_POST['accua-form-edit-action'])){ $post = stripslashes_deep($_POST); switch ($post['accua-form-edit-action']) { case 'delete': $fid = $post['form-id']; check_admin_referer('contact-forms-delete_'.$fid); $forms_data = get_option('accua_forms_saved_forms', array()); unset($forms_data[$fid]); update_option('accua_forms_saved_forms', $forms_data); $fid = htmlspecialchars($fid); $message .= sprintf( __( 'Form "%s" deleted','contact-forms' ), $fid ); break; } } } return $message; } function accua_forms_validate_form_id($fid) { $error = ''; if (!preg_match('/^[a-z0-9_-]+$/i', $fid)) { $error .= "

".__( 'Only letters, numbers, hyphen and underscores allowed in form identificative name', 'contact-forms')."

"; } if (substr($fid,0,2) == '__') { $error .= "

".__( 'The identificative name can\'t start with two underscores (__)', 'contact-forms')."

"; } if (strlen($fid) > 70) { $error .= "

".__( 'You cannot use more than 70 characters for the identificative name', 'contact-forms')."

"; } return $error; } function accua_forms_list_page() { $message = ''; if (isset($_POST['accua-form-edit-action'])){ $message = _accua_forms_form_edit_action(); } else if (isset($_GET['fid'])) { check_admin_referer('edit_posts'); $fid = stripslashes($_GET['fid']); $error = accua_forms_validate_form_id($fid); if ($error === '' && (isset($_GET['clonefrom'])&&$_GET['clonefrom']!=='')) { $error .= _accua_forms_test_clonefrom($fid); } if ($error === '') { return accua_forms_edit_page($fid); } else { return accua_forms_add_page($error); } } ?>
$message
"; } ?>

'C') ); ?>
array ( 'id' => "first_name", 'name' => "First Name", 'type' => "textfield", 'description' => 'This is the first name', ), 'last_name' => array ( 'id' => "last_name", 'name' => "Last Name", 'type' => "textfield", 'description' => 'This is the last name', ), 'email' => array ( 'id' => "email", 'name' => "Email", 'type' => "email", 'description' => 'This is the email', ), ); */ $avail_fields = get_option('accua_forms_avail_fields', array()); $default_form_data = get_option('accua_forms_default_form_data',array()); $form_data = _accua_forms_get_form_data($fid, true, !empty($_GET['restore'])); $form_overrided_data = $form_data['_overrided']; $fid_esc = htmlspecialchars($fid, ENT_QUOTES); $adminurl = admin_url(); global $wp_version; if (version_compare($wp_version, '4') >= 0) { ?>


" /> */ ?>
  • */ ?>

*/ ?>
'__fieldset-begin', 'name' => __('Fieldset begin', 'contact-forms'), 'type' => 'fieldset-begin', 'description' => '', ); } else if ($field['ref'] == '__fieldset-end') { $ref = array( 'id' => '__fieldset-end', 'name' => __('Fieldset end', 'contact-forms'), 'type' => 'fieldset-end', 'description' => '', ); } } } else { $ref = $avail_fields[$field['ref']]; } //print_r($ref); $form_fields_html .= accua_forms_field_text_settings_form($fid, $ref, $field); } foreach ($avail_fields as $avail_field) { $hidden = (empty($form_data['fields'][$avail_field['id']])) ? false : 'hidden'; echo accua_forms_field_text_settings_form($fid, $avail_field, $hidden); } //Custom HTML field echo accua_forms_field_text_settings_form($fid); //Fieldset begin echo accua_forms_field_text_settings_form($fid, array( 'id' => '__fieldset-begin', 'name' => __( 'Fieldset begin', 'contact-forms'), 'type' => 'fieldset-begin', 'description' => __('You can use this field multiple times.', 'contact-forms'), 'default_value' => '', 'allowed_values' => '', )); //Fieldset end echo accua_forms_field_text_settings_form($fid, array( 'id' => '__fieldset-end', 'name' => __( 'Fieldset end', 'contact-forms'), 'type' => 'fieldset-end', 'description' => __('You can use this field multiple times.', 'contact-forms'), 'default_value' => '', 'allowed_values' => '', )); ?>


/>

/>
/>
/>
/>
/>
/>
/>
/>

/>
/>
/>
/>
/>
/>
/>

/>
/>
/>
/>
/>
/>
/>

add_pointer('form_edit_preview'); ?>

function resizeIframe(obj) { altezza = obj.contentWindow.document.documentElement.scrollHeight + 200; obj.style.height = altezza + 'px'; } "; ?>
 
    accua_forms_form_fields_order_post: 

    accua_forms_save_form_field_post: 

    accua_forms_saved_form_data: 

    
true, 'editor_class' => 'accua_form_value', 'tinymce' => array( 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,')); ?>

> /> />

> /> />


/>
/>
/>
> /> />

/>
/>
/>
> /> />

*/?>

finished(); } function accua_forms_fields_page_head() { /* $baseurl = WP_PLUGIN_URL.'/'.substr(plugin_basename(__FILE__),0,-strlen(basename(__FILE__))); ?> __( 'Text Field', 'contact-forms'), 'textarea' => __( 'Text Area', 'contact-forms'), 'email' => __( 'Email', 'contact-forms'), 'autoreply_email' => __( 'Autoreply Email', 'contact-forms'), 'checkbox' => __( 'Checkbox','contact-forms'), 'select' => __('Select', 'contact-forms'), 'radio' => __( 'Radio buttons', 'contact-forms'), 'multiselect' => __( 'Multiple selections area', 'contact-forms'), 'multicheckbox' => __( 'Multiple checkboxes', 'contact-forms'), 'post-select' => __( 'Post select', 'contact-forms'), 'post-multicheckbox' => __( 'Multiple post checkboxes', 'contact-forms'), 'colorpicker' => __( 'Color picker', 'contact-forms'), 'hidden' => __('Hidden value', 'contact-forms'), 'file' => __('File upload', 'contact-forms'), 'submit' => __( 'Submit button', 'contact-forms'), 'html' => __( 'Custom HTML', 'contact-forms'), 'captcha' => __( 'Captcha', 'contact-forms'), 'password' => 'Password', 'password-and-confirm' => __( 'Password and password confirmation','contact-forms'), 'date' => __( 'Date','contact-forms'), ); } function accua_forms_filter_date($value){ if (($value !== '') && preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) { try { $date = new DateTime($value); if ($date) { return $value; } } catch (Exception $e) { } } return ''; } function accua_forms_fields_filter_values($post, $old_data = array()) { //TODO: funzione di validazione dei field $data = array( 'version' => 2, 'id' => $post['form-field-id'], 'name' => $post['form-field-name'], 'type' => $post['form-field-type'], 'description' => $post['form-field-description'], 'default_value' => $post['form-field-default-value'], 'default_date_value' => $post['form-field-default-date-value'], 'allowed_values' => $post['form-field-allowed-values'], 'allowed_extensions' => '', 'min_date' => $post['form-field-min-of-date'], 'max_date' => $post['form-field-max-of-date'], ); $valid = true; $message = ''; $types = accua_forms_fields_get_types(); if (!isset($types[$data['type']])) { $message .= "

".__('Invalid type', 'contact-forms')."

"; $valid = false; $data['type'] = 'textfield'; } if (!current_user_can('unfiltered_html')) { $filter_fields = array('name', 'description', 'default_value', 'allowed_values'); foreach ($filter_fields as $k) { $data[$k] = wp_kses($data[$k], 'post'); } } if ($data['type'] == 'file') { $data['allowed_extensions'] = accua_forms_filter_extensions($data['allowed_values']); } $dates = array( 'default_date_value' => __('Invalid default date', 'contact-forms'), 'min_date' => __('Invalid min date', 'contact-forms'), 'max_date' => __('Invalid max date', 'contact-forms'), ); foreach ($dates as $k => $errormsg) { if ($data[$k] !== '') { $data[$k] = accua_forms_filter_date($data[$k]); if ($data[$k] === '') { $message .= "

".$errormsg."

"; $valid = false; } } } return array( 'data' => $data, 'valid' => $valid, 'message' => $message, ); } function accua_forms_fields_page() { /* ?>

Edit Form Fields

array ( 'id' => "first_name", 'name' => "First Name", 'type' => "textfield", 'description' => 'This is the first name', ), 'last_name' => array ( 'id' => "last_name", 'name' => "Last Name", 'type' => "textfield", 'description' => 'This is the last name', ), 'email' => array ( 'id' => "email", 'name' => "Email", 'type' => "email", 'description' => 'This is the email', ), ); */ $avail_fields = get_option('accua_forms_avail_fields', array()); $default_form_values = array( 'version' => 1, 'id' => '', 'name' => '', 'type' => 'textfield', 'description' => '', 'default_value' => '', 'default_date_value' => '', 'allowed_values' => '', 'allowed_extensions' => '', 'min_date' => '', 'max_date' => '', ); $editing = false; $adding = true; if (!empty($_POST['action'])) { check_admin_referer('edit_form_field', '_wpnonce_edit_form_field'); $post = stripslashes_deep($_POST) + $default_form_values; switch($post['action']) { case 'edit-form-field': if (empty($avail_fields[$post['form-field-id']])) { $message .= 'Field "'.htmlspecialchars(sanitize_text_field($post['form-field-id'])).'" doesn\'t exists'; } else { if (empty($post['delete-field'])) { $filtered_data = accua_forms_fields_filter_values($post, $avail_fields[$post['form-field-id']]); $avail_fields[$post['form-field-id']] = $filtered_data['data']; $message .= sprintf( __( 'Field "%s" updated', 'contact-forms'), htmlspecialchars($post['form-field-id']) ); do_action('accua_forms_field_updated', $avail_fields[$post['form-field-id']]); } else { $deleting_field = $avail_fields[$post['form-field-id']]; unset ($avail_fields[$post['form-field-id']]); $message .= sprintf( __( 'Field "%s" deleted', 'contact-forms'), htmlspecialchars($post['form-field-id']) ); do_action('accua_forms_field_deleted', $deleting_field); } update_option('accua_forms_avail_fields', $avail_fields); } break; case 'add-form-field': $fill_form_fields = true; $valid = true; if (empty($post['form-field-id']) || !preg_match('/^[a-z0-9_-]+$/i', $post['form-field-id'])) { $message .= "

".__( 'Only letters, numbers, hyphen and underscores allowed in field identificative slug', 'contact-forms')."

"; $valid = false; } if(substr($post['form-field-id'], 0, 2) == '__') { $message .= "

".__( 'The field identificative slug can\'t start with two underscores (__)', 'contact-forms')."

"; $valid = false; } if (!empty($avail_fields[$post['form-field-id']])) { $message .= sprintf( __( '

A field with identificative slug "%s" already exists

Field "%s" deleted', 'contact-forms'), htmlspecialchars($post['form-field-id']) ); $valid = false; } if (strlen($post['form-field-id']) > 70) { $message .= "

".__( 'The identificative slug cannot be longer than 70 characters', 'contact-forms')."

"; $valid = false; } $filtered_data = accua_forms_fields_filter_values($post); $message .= $filtered_data['message']; $valid = $valid && $filtered_data['valid']; if ($valid) { $fill_form_fields = false; $avail_fields[$post['form-field-id']] = $filtered_data['data']; update_option('accua_forms_avail_fields', $avail_fields); $message .= sprintf( __( 'Field "%s" created', 'contact-forms'), htmlspecialchars($post['form-field-id']) ); do_action('accua_forms_field_added', $avail_fields[$post['form-field-id']]); } if ($fill_form_fields) { $editing = true; $default_form_values = $filtered_data['data']; } break; } } else if (!empty($_GET['edit-fid'])) { $fid = stripslashes($_GET['edit-fid']); if (empty($avail_fields[$fid])) { $message .= sprintf( __( 'Field "%s" doesn\'t exists', 'contact-forms'), htmlspecialchars($fid) ); } else { $adding = false; $editing = true; $default_form_values = $avail_fields[$fid] + $default_form_values; } } if ($default_form_values['version'] >= 2 && $default_form_values['type'] == 'file') { //Show allowed_extensions value in allowed_values field $default_form_values['allowed_values'] = $default_form_values['allowed_extensions']; } ?>

' . __('Search results for “%s”') . '', esc_html( stripslashes($_REQUEST['s']) ) ); ?>

search_box( $tax->labels->search_items, 'tag' ); ?> */ ?>
display(); */ ?> $field) { foreach (array('id', 'name', 'type', 'description') as $i) { $field[$i] = htmlspecialchars($field[$i], ENT_QUOTES); $field[$i] = sanitize_text_field($field[$i]); } echo << END_OF_ROW; } ?>
{$field['name']}
{$field['description']} {$field['id']} {$field['type']}

Note:
Deleting a category does not delete the posts in that category. Instead, posts that were only assigned to the deleted category are set to the category %s.'), apply_filters('the_category', get_cat_name(get_option('default_category')))) ?>

category to tag converter.'), 'import.php') ?>

tag to category converter'), 'import.php') ;?>.

labels->popular_items ) ) { if ( current_user_can( $tax->cap->edit_terms ) ) $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false, 'link' => 'edit' ) ); else $tag_cloud = wp_tag_cloud( array( 'taxonomy' => $taxonomy, 'echo' => false ) ); if ( $tag_cloud ) : ?>

labels->popular_items; ?>

cap->edit_terms) ) { // Back compat hooks. Deprecated in preference to {$taxonomy}_pre_add_form if ( 'category' == $taxonomy ) do_action('add_category_form_pre', (object)array('parent' => 0) ); elseif ( 'link_category' == $taxonomy ) do_action('add_link_category_form_pre', (object)array('parent' => 0) ); else do_action('add_tag_form_pre', $taxonomy); do_action($taxonomy . '_pre_add_form', $taxonomy); */ $types = accua_forms_fields_get_types(); ?>

id); ?>" /> */ ?>

size="40" /> '; } ?>

0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>

0) ); elseif ( 'link_category' == $taxonomy ) do_action('edit_link_category_form', (object)array('parent' => 0) ); else do_action('add_tag_form', $taxonomy); do_action($taxonomy . '_add_form', $taxonomy); */ ?>
accua_forms_avail_fields:', htmlspecialchars(print_r($avail_fields, true)), ''; */ } function accua_forms_settings_page() { ?>

'', 'error_message' => '', 'emails_from_name' => '', 'emails_from' => '', 'admin_emails_to' => '', 'emails_bcc' => '', 'admin_emails_subject' => '', 'admin_emails_message' => '', 'confirmation_emails_subject' => '', 'confirmation_emails_message' => '', 'layout' => 'sidebyside', 'style_margin' => '', 'style_border_color' => '', 'style_border_width' => '', 'style_border_radius' => '', 'style_background_color' => '', 'style_padding' => '', 'style_color' => '', 'style_font_size' => '', 'style_field_spacing' => '', 'style_field_border_color' => '', 'style_field_border_width' => '', 'style_field_border_radius' => '', 'style_field_background_color' => '', 'style_field_padding' => '', 'style_field_color' => '', 'style_submit_border_color' => '', 'style_submit_border_width' => '', 'style_submit_border_radius' => '', 'style_submit_background_color' => '', 'style_submit_padding' => '', 'style_submit_color' => '', 'style_submit_font_size' => '', ); $empty_file_data = array( 'valid_extensions' => '', 'max_size' => '', 'dest_path' => '', ); $empty_captcha_data = array( 'recaptcha_force_v1' => '', 'recaptcha_public_key' => '', 'recaptcha_private_key' => '', ); $empty_analytics_data = array( 'analytics_track_submit' => false, 'analytics_track_fields' => false, ); $empty_anonymize_ip_data = array( 'anonymize_ip_bytes' => 0, ); if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['accua_form_save_form_settings'])) { check_admin_referer('accua_form_save_settings', '_nonce_accua_form_save_settings'); $post = stripslashes_deep($_POST); $post += $empty_form_data; $post += $empty_file_data; $post += $empty_captcha_data; $post += $empty_analytics_data; $post += $empty_anonymize_ip_data; $form_data = array(); $file_data = array(); $captcha_data = array(); $analytics_data = array(); $anonymize_ip_data = array(); foreach($empty_form_data as $key=>$val){ $form_data[$key] = $post[$key]; } $form_data = accua_forms_filter_settings($form_data); $file_data['valid_extensions'] = accua_forms_filter_extensions($post['valid_extensions']); $file_data['max_size'] = $post['max_size']; if (current_user_can('edit_files') || current_user_can('install_plugins')) { $file_data['dest_path'] = $post['dest_path']; } else { $old_file_data = get_option('accua_forms_default_file_field_data',array()); $file_data['dest_path'] = isset($old_file_data['dest_path']) ? $old_file_data['dest_path'] : ''; } $captcha_data['recaptcha_force_v1'] = (bool) $post['recaptcha_force_v1']; $captcha_data['recaptcha_public_key'] = sanitize_text_field($post['recaptcha_public_key']); $captcha_data['recaptcha_private_key'] = sanitize_text_field($post['recaptcha_private_key']); foreach($empty_analytics_data as $key=>$val){ $analytics_data[$key] = (bool) $post[$key]; } /* foreach($empty_anonymize_ip_data as $key=>$val){ $anonymize_ip_data[$key] = $post[$key]; } */ $anonymize_ip_bytes = (int) $post['anonymize_ip_bytes']; if ($anonymize_ip_bytes < 0) { $anonymize_ip_bytes = 0; } else if ($anonymize_ip_bytes > 4) { $anonymize_ip_bytes = 4; } $anonymize_ip_data['anonymize_ip_bytes'] = $anonymize_ip_bytes; update_option('accua_forms_default_form_data', $form_data); update_option('accua_forms_default_file_field_data', $file_data); update_option('accua_forms_default_captcha_field_data', $captcha_data); update_option('accua_forms_default_analytics_data', $analytics_data); update_option('accua_forms_anonymize_ip_data', $anonymize_ip_data); if (!empty($post['delete_previous_ip_values'])) { global $wpdb; $wpdb->query("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_ip = ''"); } } else { $form_data = get_option('accua_forms_default_form_data',array()) + $empty_form_data; $file_data = get_option('accua_forms_default_file_field_data',array()) + $empty_file_data; $captcha_data = get_option('accua_forms_default_captcha_field_data',array()) + $empty_captcha_data; $analytics_data = get_option('accua_forms_default_analytics_data',array()) + $empty_analytics_data; $anonymize_ip_data = get_option('accua_forms_anonymize_ip_data',array()) + $empty_anonymize_ip_data; } if ($captcha_data['recaptcha_force_v1']) { $captcha_data = $empty_captcha_data; } ?>
:

:

:

:

:

:

:

:

:

:

*/ ?>
true, 'editor_class' => 'accua_form_value', 'tinymce' => array( 'theme_advanced_buttons1' => 'bold,italic,underline,|,bullist,numlist,')); ?>










0) { _e( 'This value is limited by server upload limits of ', 'contact-forms'); echo AccuaForm_Element_File::format_size($server_max_size).". "; _e( 'If you need a greater limit you should ask to the server administrator.', 'contact-forms'); } ?>
: .

/>

/>

/>

/>

/>



/>

/>





0) { _e( 'This value is limited by server upload limits of ', 'contact-forms'); echo AccuaForm_Element_File::format_size($server_max_size).". "; _e( 'If you need a greater limit you should ask to the server administrator.', 'contact-forms'); } ?>

: .

*/ ?>

array(), 'title' => '', 'success_message' => '', 'error_message' => '', 'emails_from_name' => '', 'emails_from' => '', 'admin_emails_to' => '', 'emails_bcc' => '', 'admin_emails_subject' => '', 'admin_emails_message' => '', 'confirmation_emails_subject' => '', 'confirmation_emails_message' => '', 'use_ajax' => true, 'layout' => 'sidebyside', 'style_margin' => '', 'style_border_color' => '', 'style_border_width' => '', 'style_border_radius' => '', 'style_background_color' => '', 'style_padding' => '', 'style_color' => '', 'style_font_size' => '', 'style_field_spacing' => '', 'style_field_border_color' => '', 'style_field_border_width' => '', 'style_field_border_radius' => '', 'style_field_background_color' => '', 'style_field_padding' => '', 'style_field_color' => '', 'style_submit_border_color' => '', 'style_submit_border_width' => '', 'style_submit_border_radius' => '', 'style_submit_background_color' => '', 'style_submit_padding' => '', 'style_submit_color' => '', 'style_submit_font_size' => '', ); if ($fid === false) { return $empty_form_data; } $default_form_data = get_option('accua_forms_default_form_data',array()); if ($fid === null) { return $default_form_data + $empty_form_data; } $forms_data = get_option('accua_forms_saved_forms', array()); if ($restore_trash) { $trash_data = get_option('accua_forms_trash_forms', array()); if (isset($trash_data[$fid])) { $forms_data[$fid] = $trash_data[$fid]; update_option('accua_forms_saved_forms', $forms_data); unset($trash_data[$fid]); update_option('accua_forms_trash_forms', $trash_data); } } if (isset($forms_data[$fid])) { $form_data = array( '_overrided' => $forms_data[$fid] ) + $forms_data[$fid] + $default_form_data + $empty_form_data; /* if ($form_data['fields']) { foreach ($form_data['fields'] as $i => $istance_data) { // TODO: popuplate default fields data? } } */ return $form_data; } else if ($return_empty) { return array( '_overrided' => array() ) + $default_form_data + $empty_form_data; } else { return null; } } function _accua_forms_style_parameters($params) { $ret = ''; foreach ($params as $key => $value) { $value = trim($value); if ($value !== '') { if (is_numeric($value)) { $ret .= "{$key}:{$value}px;"; } else { $ret .= "{$key}:{$value};"; } if ($key == 'border-width') { $ret .= "border-style:solid;"; } } } return $ret; } /* * generazione del form (e della preview) * */ add_action('accua_form_alter', 'accua_forms_form_generate', -999, 2); function accua_forms_form_generate($baseid, $form) { if (substr($baseid, 0, 14) == '__accua-form__') { $fid = substr($baseid,14); $form_data = _accua_forms_get_form_data($fid, false); /* echo '"; */ if ($form_data) { $form_style = _accua_forms_style_parameters(array( 'margin' => $form_data['style_margin'], 'border-color' => $form_data['style_border_color'], 'border-width' => $form_data['style_border_width'], 'border-radius' => $form_data['style_border_radius'], 'background' => $form_data['style_background_color'], 'padding' => $form_data['style_padding'], 'color' => $form_data['style_color'], 'font-size' => $form_data['style_font_size'], )); $field_style = _accua_forms_style_parameters(array( 'margin-bottom' => $form_data['style_field_spacing'], 'border-color' => $form_data['style_field_border_color'], 'border-width' => $form_data['style_field_border_width'], 'border-radius' => $form_data['style_field_border_radius'], 'background' => (trim($form_data['style_field_background_color']) === '')?'transparent':$form_data['style_field_background_color'], 'padding' => $form_data['style_field_padding'], 'color' => (trim($form_data['style_field_color']) === '')?$form_data['style_color']:$form_data['style_field_color'], 'font-size' => $form_data['style_font_size'], )); $field_properties = array(); if ($field_style !== '') { $field_properties['style'] = $field_style; } $submit_style = _accua_forms_style_parameters(array( 'border-color' => $form_data['style_submit_border_color'], 'border-width' => $form_data['style_submit_border_width'], 'border-radius' => $form_data['style_submit_border_radius'], 'background' => $form_data['style_submit_background_color'], 'padding' => $form_data['style_submit_padding'], 'color' => $form_data['style_submit_color'], 'font-size' => $form_data['style_submit_font_size'], )); $submit_properties = array(); if ($submit_style !== '') { $submit_properties['style'] = $submit_style; } if ($form_style !== '') { $form->configure(array('style' => $form_style)); } if (!empty($form_data['use_ajax'])){ $form->configure(array( "accua_ajax" => 1, )); } $add_submit = true; $fieldset_open = false; $avail_fields = get_option('accua_forms_avail_fields', array()); foreach ($form_data['fields'] as $istance_data) { if (empty($avail_fields[$istance_data['ref']])) { $field_data = array(); if (!empty($istance_data['ref'])) { if ($istance_data['ref'] == '__fieldset-begin') { $field_data = array( 'id' => '__fieldset-begin', 'name' => __('Fieldset begin', 'contact-forms'), 'type' => 'fieldset-begin', 'description' => '', ); } else if ($istance_data['ref'] == '__fieldset-end') { $field_data = array( 'id' => '__fieldset-end', 'name' => __('Fieldset end', 'contact-forms'), 'type' => 'fieldset-end', 'description' => '', ); } } } else { $field_data = $avail_fields[$istance_data['ref']]; } $field_data += array( 'version' => 1, 'id' => '__html', 'name' => __( 'Custom HTML content', 'contact-forms'), 'type' => 'html', 'description' => __('Use this special field to inject raw HTML in the form. You can use this multiple times.', 'contact-forms'), 'default_value' => '', 'allowed_values' => '', 'allowed_extensions' => '', ); $istance_data += array( 'version' => 1, ); if ($field_data['type'] == 'file') { if ($field_data['version'] < 2) { $field_data['allowed_extensions'] = $field_data['allowed_values']; } if ($istance_data['version'] < 2 && isset($istance_data['allowed_values'])) { $istance_data['allowed_extensions'] = $istance_data['allowed_values']; } } /* prendo i dati relativi ai campi di tipo date lo faccio prima, così default value in questo modo viene sovrascritto se un campo è di un tipo diverso NB: se i campi sono già sovrascritti, si trovano già in istance_data */ if ($field_data['type'] == 'date'){ $istance_data += array( 'default_value' => $field_data['default_date_value'], 'min_date' => $field_data['min_date'], 'max_date' => $field_data['max_date'], ); } $istance_data += array( 'istance_id' => $field_data['id'], 'widget_number' => '', 'ref' => $field_data['id'], 'label' => $field_data['name'], 'default_value' => $field_data['default_value'], /* viene impostato il valore di defualt se non è un campo data */ 'allowed_values' => $field_data['allowed_values'], 'allowed_extensions' => $field_data['allowed_extensions'], ); $element = NULL; $element_conf = NULL; $allowed_val = trim($istance_data['allowed_values']); if ($field_data['type'] == 'post-multicheckbox' || $field_data['type'] == 'post-select') { $posts = accua_get_pages($allowed_val); $allowed_values = array(); foreach ($posts as $p) { //$allowed_values[$p->ID] = apply_filters( 'the_title', $p->post_title, $p->ID ); $allowed_values[$p->ID] = $p->post_title; } } else { if ($field_data['type'] == 'file') { $filedata = get_option('accua_forms_default_file_field_data',array()); $filedata += array( 'valid_extensions' => '', 'max_filesize' => '', 'dest_path' => '', ); $allowed_val = accua_forms_filter_extensions($istance_data['allowed_extensions']); if ($allowed_val == '') { $allowed_val = accua_forms_filter_extensions($filedata['valid_extensions']); } } $allowed_val = explode("\n",$allowed_val); $allowed_values = array(); foreach ($allowed_val as $val) { $val = explode('|',$val,2); $val[0] = trim($val[0]); /* if (empty($val[0])) { continue; } */ if ((!isset($val[1])) || (trim($val[1])==='')) { if ($val[0] === '') { continue; } else { $val[1] = $val[0]; } } $allowed_values[$val[0]] = $val[1]; } } switch ($field_data['type']) { case 'textarea': $element = new Element_Textarea($istance_data['label'], $istance_data['istance_id'], $field_properties+array('cols' => '50', 'value'=>$istance_data['default_value'])); break; case 'hidden': $element = new Element_Hidden($istance_data['istance_id'], $istance_data['default_value']); break; case 'checkbox': $lab = $istance_data['label']; if (!empty($istance_data['required'])) { $lab .= ' *'; } if ($allowed_values) { reset($allowed_values); $val = (string) key($allowed_values); $defval = trim($istance_data['default_value']); } else if ($istance_data['default_value'] == '1') { $defval = $val = '1'; } else { $val = empty($istance_data['default_value'])?'1':$istance_data['default_value']; $defval = ''; } $element = new AccuaForm_Element_Checkbox('', $istance_data['istance_id'], array($val => $lab), array('value' => $defval)); break; case 'select': case 'post-select': if (!isset($allowed_values[''])) { $allowed_values = array('' => '') + $allowed_values; } $defval = trim($istance_data['default_value']); $element = new AccuaForm_Element_Select($istance_data['label'], $istance_data['istance_id'], $allowed_values, $field_properties+array('value'=>$defval)); break; case 'radio': $defval = trim($istance_data['default_value']); $element = new AccuaForm_Element_Radio($istance_data['label'], $istance_data['istance_id'], $allowed_values, array('value'=>$defval)); break; case 'multiselect': $defval = explode('|', $istance_data['default_value']); foreach ($defval as $k => $v) { $defval[$k] = trim($v); } $element = new AccuaForm_Element_Select($istance_data['label'], $istance_data['istance_id'], $allowed_values, $field_properties+array('multiple' => true, 'value'=>$defval)); break; case 'multicheckbox': case 'post-multicheckbox': $defval = explode('|', $istance_data['default_value']); foreach ($defval as $k => $v) { $defval[$k] = trim($v); } $element = new AccuaForm_Element_Checkbox($istance_data['label'], $istance_data['istance_id'], $allowed_values, array('value'=>$defval)); break; case 'file': $fdata = array(); if ($allowed_values) { $fdata['validExtensions'] = array_keys($allowed_values); } if (!empty($filedata['max_size'])){ $fdata['maxSize'] = $filedata['max_size']; } $fdata['destPath'] = _accua_forms_get_abs_dest_path($filedata['dest_path']); $element = new AccuaForm_Element_File($istance_data['label'], $istance_data['istance_id'], $field_properties+$fdata); break; case 'html': $element = new Element_HTML($istance_data['default_value']); break; case 'email': case 'autoreply_email': $element = new AccuaForm_Element_Email($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value'])); $element->setValidation(new Validation_Email( str_replace('%element%', $istance_data['label'], __("Attention: '%element%' must contain an email address.", 'contact-forms')) )); //"Errore: '{$istance_data['label']}' deve contenere un indirizzo email valido." break; case 'colorpicker': $element = new AccuaForm_Element_ColorPicker($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value'])); break; case 'fieldset-begin': if ($fieldset_open) { $form->addElement(new AccuaForm_Element_FieldsetEnd()); } else { $fieldset_open = true; } $element = new AccuaForm_Element_FieldsetBegin($istance_data['label'], $istance_data['istance_id']); break; case 'fieldset-end': if ($fieldset_open) { $element = new AccuaForm_Element_FieldsetEnd(); $fieldset_open = false; } break; case 'submit': $add_submit = false; $element = new Element_Button($istance_data['label'], 'submit', $submit_properties+array('name' => $istance_data['istance_id'], 'value' => $istance_data['default_value'])); break; case 'captcha': $empty_captcha_data = array( 'recaptcha_force_v1' => '', 'recaptcha_public_key' => '', 'recaptcha_private_key' => '', ); $captcha_data = get_option('accua_forms_default_captcha_field_data',array()) + $empty_captcha_data; $captcha_properties = array("description" => ""); $captcha_use_v1 = true; if (($captcha_data['recaptcha_public_key'] !== '') && ($captcha_data['recaptcha_private_key'] !== '')) { $captcha_properties['privateKey'] = $captcha_data['recaptcha_private_key']; $captcha_properties['publicKey'] = $captcha_data['recaptcha_public_key']; $captcha_use_v1 = $captcha_data['recaptcha_force_v1']; } if ($captcha_use_v1) { $element = new Element_HTML("\n\n\n\n"); } else { $element = new AccuaForm_Element_Captcha2 ($istance_data['label'], '', $captcha_properties); } break; case 'password': $element = new Element_Password($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value'])); break; case 'password-and-confirm': $id_2 = "___{$istance_data['istance_id']}___confirmpass"; $element = new Element_Password(__("Password", 'contact-forms'), $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value'])); $element_conf = new Element_Password(__("Confirm password", 'contact-forms'), $id_2, $field_properties+array('value'=>$istance_data['default_value'])); $element_conf_validator = new AccuaForm_Validation_Password(); $element_conf_validator->configure(array('otherPasswordFieldName'=>$istance_data['istance_id'])); $element_conf->setValidation($element_conf_validator); break; case 'date': $element = new AccuaForm_Element_Date($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value'], 'minDate'=>$istance_data['min_date'], 'maxDate'=>$istance_data['max_date'])); break; //case 'textfield': default: $element = new Element_Textbox($istance_data['label'], $istance_data['istance_id'], $field_properties+array('value'=>$istance_data['default_value'])); break; } if ($element) { if (!empty($istance_data['required'])) { $element->setClass('accuaforms-field-required'); if($field_data['type'] == 'captcha' && empty($captcha_use_v1)) { //nothing } else if($field_data['type'] == 'password-and-confirm') { $element->setValidation(new Validation_Required( str_replace('%element%', $istance_data['label'], __("Attention: Passwords are required fields.", 'contact-forms')) )); } else { $element->setValidation(new Validation_Required( str_replace('%element%', $istance_data['label'], __("Attention: '%element%' is a required field.", 'contact-forms')) )); } } if ($elementName = $element->getName()) { $element->setClass('accuaform-fieldname-'.$elementName); } if ($field_data['type']) { $element->setClass('accuaform-fieldtype-'.$field_data['type']); } $form->addElement($element); if($element_conf!=NULL) { $form->addElement($element_conf); $element_conf=NULL; } } } if ($fieldset_open) { $form->addElement(new AccuaForm_Element_FieldsetEnd()); $fieldset_open = false; } if ($add_submit) { $form->addElement(new Element_Button(__('Submit', 'contact-forms'), 'submit', $submit_properties)); } } } } function accua_forms_aggregate_submitted_data(&$replace_map, $params = array()) { if (empty($params['txt']) && empty($params['html']) && empty($params['json']) && empty($params['email'])) { $params += array( 'txt' => true, 'html' => true, 'json' => true, 'email' => true, ); } if (!empty($params['txt'])) { $replace_map['__submitted_txt'] = implode("\n",$replace_map['__submitted_txt_raw']); } if (!empty($params['html'])) { $replace_map['__submitted_html'] = implode('',$replace_map['__submitted_html_raw']); } if (!empty($params['json'])) { $replace_map['__submitted_json'] = _accua_forms_json_encode($replace_map['__submitted_json_raw']); } if (!empty($params['email'])) { $replace_map['__autoreply_email'] = implode('; ', $replace_map['__autoreply_email_raw']); } } add_filter('accua_form_validate', 'accua_forms_validation_handler', 10, 4); function accua_forms_validation_handler($valid, $submittedID, $submittedData, $form){ if (substr($submittedID, 0, 14) == '__accua-form__') { $fid = substr($submittedID,14); $form_data = _accua_forms_get_form_data($fid, false); if ($form_data) { return apply_filters('accua_forms_validation', $valid, $fid, $submittedData, $form); } } return $valid; } function accua_forms_anonymize_ip($ip) { $ip = (string) $ip; $anonymize_ip_data = get_option('accua_forms_anonymize_ip_data',array()); if (empty($anonymize_ip_data['anonymize_ip_bytes'])) { return $ip; } switch ($anonymize_ip_data['anonymize_ip_bytes']) { case 1: $ip = preg_replace('/\.[^.]+$/', '.xxx', $ip); break; case 2: $ip = preg_replace('/\.[^.]+\.[^.]+$/', '.xxx.xxx', $ip); break; case 3: $ip = preg_replace('/\.[^.]+\.[^.]+\.[^.]+$/', '.xxx.xxx.xxx', $ip); break; case 4: $ip = ''; } return $ip; } add_action('accua_form_submit', 'accua_forms_form_submission_handler', -10, 3); function accua_forms_form_submission_handler($submittedID, $submittedData, $form) { if (empty($GLOBALS['wp_rewrite'])) { $GLOBALS['wp_rewrite'] = new WP_Rewrite(); } if (!class_exists('AccuaConditionalReplacer')){ require_once('AccuaConditionalReplacer.php'); } if (substr($submittedID, 0, 14) == '__accua-form__') { $fid = substr($submittedID,14); $form_data = _accua_forms_get_form_data($fid, false); if ($form_data) { global $wpdb; $time = time(); $afs_stats = _accua_forms_json_encode(array( 'user_agent' => $form->stats['user_agent'], 'platform' => $form->stats['platform'], 'tentatives' => $form->stats['tentatives'], 'submit_method' => $form->stats['submit_method'], )); $anonymized_ip = accua_forms_anonymize_ip($form->stats['ip']); $insert_ret = $wpdb->insert( $wpdb->prefix . 'accua_forms_submissions', array ( 'afs_form_id' => (string) $fid, 'afs_post_id' => (string) $form->stats['pid'], 'afs_ip' => $anonymized_ip, 'afs_uri' => (string) $form->stats['uri'], 'afs_referrer' => (string) $form->stats['referrer'], 'afs_lang' => (string) $form->stats['lang'], 'afs_created' => (string) gmdate('Y-m-d H:i:s', $form->stats['created']), 'afs_submitted' => (string) gmdate('Y-m-d H:i:s', $time), 'afs_stats' => (string) $afs_stats, ) ); if ($insert_ret) { $submission_id = $form->stats['submission_id'] = $wpdb->insert_id; } else { $submission_id = $form->stats['submission_id'] = 0; error_log("[WordPress Contact Forms] unable to save submitted form data"); } $review_submission_url = admin_url('admin.php').'?page=accua_forms_submissions_list&sid='.$submission_id; $replace_map = array( '__fid' => $fid, '__subid' => $submission_id, '__pid' => $form->stats['pid'], '__ip' => $form->stats['ip'], '__anonymized_ip' => $anonymized_ip, '__uri' => $form->stats['uri'], '__url' => $form->stats['url'], '__referrer' => $form->stats['referrer'], '__lang' => $form->stats['lang'], '__locale' => $form->stats['locale'], '__created' => $form->stats['created'], '__created_day' => date('l j F Y', $form->stats['created']), '__created_day_month_year' => date('j F Y', $form->stats['created']), '__created_hour' => date('G:i', $form->stats['created']), '__submitted' => $time, '__submitted_day' => date('l j F Y', $time), '__submitted_day_month_year' => date('j F Y', $time), '__submitted_hour' => date('G:i', $time), '__confirmation_emails_message' => $form_data['confirmation_emails_message'], '__user_agent' => $form->stats['user_agent'], '__platform' => $form->stats['platform'], '__tentatives' => $form->stats['tentatives'], '__submit_method' => $form->stats['submit_method'], '__review_submission_url' => $review_submission_url, ); $avail_fields = get_option('accua_forms_avail_fields', array()); $replace_map['__autoreply_email_raw'] = array(); $replace_map['__submitted_txt_raw'] = array(); $replace_map['__submitted_html_raw'] = array(); $replace_map['__submitted_json_raw'] = array(); $_field_data = array(); $_istance_data = array(); $field_data = array(); foreach ($submittedData as $istance_id => $value) { if (empty($form_data['fields'][$istance_id])) { continue; } $istance_data = $form_data['fields'][$istance_id]; if (empty($avail_fields[$istance_data['ref']])) { $fieldset_data = array(); if (!empty($istance_data['ref'])) { if ($istance_data['ref'] == '__fieldset-begin') { $field_data = array( 'id' => '__fieldset-begin', 'name' => __('Fieldset begin', 'contact-forms'), 'type' => 'fieldset-begin', 'description' => '', ); } else if ($istance_data['ref'] == '__fieldset-end') { $field_data = array( 'id' => '__fieldset-end', 'name' => __('Fieldset end', 'contact-forms'), 'type' => 'fieldset-end', 'description' => '', ); } } } else { $field_data = $avail_fields[$istance_data['ref']]; } $field_data += array( 'id' => '__html', 'name' => __( 'Custom HTML content', 'contact-forms'), 'type' => 'html', 'description' => __( 'Use this special field to inject raw HTML in the form. You can use this multiple times.', 'contact-forms'), 'default_value' => '', 'allowed_values' => '', ); /* echo "\n"; */ $istance_data += array( 'istance_id' => $field_data['id'], 'widget_number' => '', 'ref' => $field_data['id'], 'label' => $field_data['name'], 'default_value' => $field_data['default_value'], 'allowed_values' => $field_data['allowed_values'], ); $type = $field_data['type']; $file_download_url = ''; switch ($field_data['type']) { case 'checkbox': case 'submit': if (empty($value)) { $replace_map[$istance_data['istance_id']] = $value = ''; } else { if (empty($istance_data['default_value'])) { $replace_map[$istance_data['istance_id']] = 'Checked'; $value = '1'; } else { $replace_map[$istance_data['istance_id']] = $value = $istance_data['default_value']; } } break; case 'multiselect': case 'multicheckbox': case 'select': case 'radio': $el = $form->getElementByName($istance_id); $opts = $el->getOptions(); if (!is_array($value)) { $value = array($value); } $label = array(); foreach ($value as $val) { if (isset($opts[$val])) { $label[] = $opts[$val]; } } $replace_map['__label_'.$istance_data['istance_id']] = implode(", ", $label); $replace_map[$istance_data['istance_id']] = implode(', ',$value); $value = implode('|',$value); break; case 'post-multicheckbox': if (is_array($value) && $value) { $el = $form->getElementByName($istance_id); $opts = $el->getOptions(); $value2 = array(); $titles = array(); $ids = array(); $urls = array(); foreach ($value as $val) { if (isset($opts[$val])) { $titles[] = $opts[$val]; $ids[] = $value; $urls[] = get_permalink($value); $value2[] = $val . ': ' . trim(preg_replace('/[\s\n\r]+/', ' ', $opts[$val])); } } $replace_map['__label_'.$istance_data['istance_id']] = $replace_map['__post_title_'.$istance_data['istance_id']] = implode("\n", $titles); $replace_map['__post_id_'.$istance_data['istance_id']] = implode("\n", $ids); $replace_map['__post_url_'.$istance_data['istance_id']] = implode("\n", $urls); $replace_map[$istance_data['istance_id']] = $value = implode("\n", $value2); } else { $replace_map['__label_'.$istance_data['istance_id']] = $replace_map['__post_title_'.$istance_data['istance_id']] = ''; $replace_map['__post_id_'.$istance_data['istance_id']] = ''; $replace_map['__post_url_'.$istance_data['istance_id']] = ''; $replace_map[$istance_data['istance_id']] = $value = ''; } break; case 'post-select': if ($value !== '') { $el = $form->getElementByName($istance_id); $opts = $el->getOptions(); if (isset($opts[$value])) { $replace_map['__label_'.$istance_data['istance_id']] = $replace_map['__post_title_'.$istance_data['istance_id']] = $opts[$value]; $replace_map['__post_id_'.$istance_data['istance_id']] = $value; $replace_map['__post_url_'.$istance_data['istance_id']] = get_permalink($value); $value = $value . ': ' . trim(preg_replace('/[\s\n\r]+/', ' ', $opts[$value])); } else { $replace_map['__label_'.$istance_data['istance_id']] = $replace_map['__post_title_'.$istance_data['istance_id']] = ''; $replace_map['__post_id_'.$istance_data['istance_id']] = ''; $replace_map['__post_url_'.$istance_data['istance_id']] = ''; $value = ''; } } $replace_map[$istance_data['istance_id']] = $value; break; case 'autoreply_email': if ($value !== '') { $replace_map['__autoreply_email_raw'][] = $value; } $replace_map[$istance_data['istance_id']] = $value; break; case 'file': //TODO: move temp file to "{$submission_id}_{$field_data['id']}_{$file['name']}"; value is $file['name'] $buildid = $submittedData['_AccuaForm_buildID']; $file = $form->getFile($istance_id); if ($value !== null && $value !== '' && $file) { if ($form->renameFile($istance_id, "{$submission_id}_{$field_data['id']}_{$file['name']}")) { $urlfield = rawurlencode($istance_data['istance_id']); $urlfile = rawurlencode($value); $file_download_url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$submission_id}&field={$urlfield}&file={$urlfile}"; } } $replace_map[$istance_data['istance_id']] = $value; $replace_map['__download_'.$istance_data['istance_id']] = $file_download_url; break; case 'password': case 'password-and-confirm': $value = trim($value); $replace_map[$istance_data['istance_id']] = $value; $type = 'hashed-password'; if ($value !== '') { $value = wp_hash_password($value); } $replace_map['__hashed_'.$istance_data['istance_id']] = $value; break; default: $replace_map[$istance_data['istance_id']] = $value; } switch ($field_data['type']) { case 'file': $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value\t$file_download_url"; $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = "$value\t$file_download_url"; $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}".htmlspecialchars($value).""; break; case 'email': case 'autoreply_email': $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value"; $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value; $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}".htmlspecialchars($value).""; break; case 'submit': break; case 'colorpicker': $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value"; $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value; if ($value === '') { $value_html = ''; } else { $value_esc = htmlspecialchars($value, ENT_QUOTES); $value_html = " $value_esc"; } $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}$value_html"; break; case 'password': case 'password-and-confirm': break; default: $replace_map['__submitted_txt_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}\t$value"; $replace_map['__submitted_json_raw'][$istance_data['istance_id']] = $value; $replace_map['__submitted_html_raw'][$istance_data['istance_id']] = "{$istance_data['istance_id']}".htmlspecialchars($value); } if ($submission_id) { $wpdb->insert( $wpdb->prefix . 'accua_forms_submissions_values', array ( 'afsv_sub_id' => $submission_id, 'afsv_field_id' => $istance_data['istance_id'], 'afsv_type' => $type, 'afsv_value' => $value, ), array('%d','%s','%s','%s') ); } $_field_data[$istance_data['istance_id']] = $field_data; $_istance_data[$istance_data['istance_id']] = $istance_data; } $replace_map['__autoreply'] = (bool) ($replace_map['__autoreply_email_raw'] && $form_data['confirmation_emails_subject'] && $form_data['confirmation_emails_message']); accua_forms_aggregate_submitted_data($replace_map); //Older undocumented filter, maintained for backward compatibility. In fact filter accua_forms_form_submission_handler is called before accua_forms_submission, but for the rest they are the same $replace_map = apply_filters('accua_forms_form_submission_handler', $replace_map, $fid, $submittedData, $form, $_field_data, $_istance_data); //Newer filter, with an easier name $replace_map = apply_filters('accua_forms_submission', $replace_map, $fid, $submittedData, $form, $_field_data, $_istance_data); $submitted_html = '
' . $replace_map['__submitted_html'] . '
'; $confirmation_emails_message = $replace_map['__confirmation_emails_message']; unset($replace_map['__submitted_html'], $replace_map['__confirmation_emails_message'], $replace_map['__submitted_txt_raw'], $replace_map['__submitted_html_raw'], $replace_map['__submitted_json_raw'], $replace_map['__autoreply_email_raw']); $replace_map_html = array(); foreach($replace_map as $key => $value) { $replace_map_html["!$key"] = wp_kses($value, 'post'); $replace_map_html[$key] = htmlspecialchars($value, ENT_QUOTES); } $replace_map['__submitted_html'] = $replace_map_html['__submitted_html'] = $replace_map_html['!__submitted_html'] = $submitted_html; $replacer_html = new AccuaConditionalReplacer($replace_map_html); $confirmation_emails_message = $replace_map['__confirmation_emails_message'] = $replacer_html->doReplace($confirmation_emails_message); $replacer_html->appendPattern(array('__confirmation_emails_message' => $confirmation_emails_message, '!__confirmation_emails_message' => $confirmation_emails_message)); $replacer = new AccuaConditionalReplacer($replace_map); $form_data_replaced = array(); $settings = array( 'emails_from_name', 'emails_from', 'admin_emails_to', 'emails_bcc', 'admin_emails_subject', 'confirmation_emails_subject', ); foreach($settings as $i) { $form_data_replaced[$i] = $replacer->doReplace($form_data[$i]); } $settings_html = array( 'success_message', 'admin_emails_message', ); foreach($settings_html as $i) { $form_data_replaced[$i] = $replacer_html->doReplace($form_data[$i]); } AccuaForm::appendSubmittedMessages(wpautop($form_data_replaced['success_message'])); $header = array("Content-Type: text/html; charset=".get_option('blog_charset')); $emails_from = trim($form_data_replaced['emails_from']); if (strpos($emails_from, '@') !== false) { if ((strpos($emails_from, '<') === false) && is_email($emails_from)) { $emails_from_name = trim($form_data_replaced['emails_from_name']); if ($emails_from_name !== '') { $emails_from = "=?" . get_bloginfo('charset') . "?B?" . base64_encode($emails_from_name) . "?= <$emails_from>"; } } $header[] = 'From: '.$emails_from; } if ($form_data_replaced['emails_bcc']) { $header[] = 'Bcc: '.$form_data_replaced['emails_bcc']; } if ($form_data_replaced['admin_emails_to'] && $form_data_replaced['admin_emails_subject']) { /* $admin_tos = explode(',', strtr($form_data_replaced['admin_emails_to'], "\n\t\r;", ',,,,')); foreach ($admin_tos as $admin_to) { $mail1 = wp_mail(trim($admin_to), $form_data_replaced['admin_emails_subject'], $form_data_replaced['admin_emails_message'], $header); } */ $mail1 = wp_mail($form_data_replaced['admin_emails_to'], $form_data_replaced['admin_emails_subject'],''.wpautop($form_data_replaced['admin_emails_message']).'', $header); } if ($replace_map['__autoreply'] && $replace_map['__autoreply_email'] && $form_data_replaced['confirmation_emails_subject'] && $confirmation_emails_message) { $mail2 = wp_mail($replace_map['__autoreply_email'], $form_data_replaced['confirmation_emails_subject'], ''.wpautop($confirmation_emails_message).'', $header); } /* echo ""; */ } } } function accua_forms_get_submission_data($subid, $options = array()){ //TODO: Completa e usa per sostituire i campi global $wpdb; $subid = (int) $subid; $options += array( 'extra' => true, 'file_format' => 'name', ); $ret = array(); if ($options['extra']) { $query1 = "SELECT * FROM `{$wpdb->prefix}accua_forms_submissions` WHERE afs_id = $subid"; $data = $wpdb->get_row($query1); if (!empty($data)) { $created = $data->afs_created; $created[10] = 'T'; $created.='.00+00:00'; $created = strtotime($created); $submitted = $data->afs_submitted; $submitted[10] = 'T'; $submitted.='.00+00:00'; $submitted = strtotime($submitted); if ($data->afs_stats) { $stats = json_decode($data->afs_stats, true); if (!$stats) { $stats = array(); } } else { $stats = array(); } $stats += array( 'user_agent' => '', 'platform' => '', 'tentatives' => '', 'submit_method' => '', ); $ret += array( '__fid' => $data->afs_form_id, '__subid' => $subid, '__pid' => $data->afs_post_id, '__ip' => $data->afs_ip, '__anonymized_ip' => accua_forms_anonymize_ip($data->afs_ip), '__uri' => $data->afs_uri, '__referrer' => $data->afs_referrer, '__lang' => $data->afs_lang, '__created' => $created, '__created_day' => date('l j F Y', $created), '__created_hour' => date('G:i', $created), '__submitted' => $submitted, '__submitted_day' => date('l j F Y', $submitted), '__submitted_hour' => date('G:i', $submitted), '__user_agent' => $stats['user_agent'], '__platform' => $stats['platform'], '__tentatives' => $stats['tentatives'], '__submit_method' => $stats['submit_method'], ); } } $query2 = "SELECT * FROM `{$wpdb->prefix}accua_forms_submissions_values` WHERE afsv_sub_id = $subid"; $data2 = $wpdb->get_results($query2, OBJECT); foreach ($data2 as $row) { switch ($row->afsv_type) { case 'file' : if ($options['file_format'] == 'url' || $options['file_format'] == 'link') { $fieldid = rawurlencode($row->afsv_field_id); $filename = rawurlencode($row->afsv_value); $url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$row->afsv_sub_id}&field={$fieldid}&file={$filename}"; if ($options['file_format'] == 'link'){ $url = htmlspecialchars($url,ENT_QUOTES); $filename = htmlspecialchars($row->afsv_value,ENT_QUOTES); $fielddata = "{$filename}"; } else { $fielddata = $url; } } else { // $options['file_format'] == 'name' $fielddata = $row->afsv_value; } break; default: $fielddata = $row->afsv_value; } $ret[$row->afsv_field_id] = $fielddata; } return $ret; } add_shortcode( 'accua-form', 'accua_forms_shortcode_handler' ); function accua_forms_shortcode_handler($atts, $content = '', $code = '') { if (empty($atts['fid'])) { return ''; } $fid = $atts['fid']; $form_data = _accua_forms_get_form_data($fid, false); if (! $form_data) { return ''; } $fid = '__accua-form__'.$fid; $out = ''; if (AccuaForm::getSubmittedID() == $fid) { /* return "
Form submitted.\n\nData: " . print_r(AccuaForm::getSubmittedData(), true) . '
'; */ $messages = AccuaForm::getSubmittedMessages(); if ($messages) { $out .= '
'.$messages.'
'; } if (AccuaForm::isValid()) { return $out; } $form = AccuaForm::getSubmittedForm(); } else { $analytics_data = get_option('accua_forms_default_analytics_data',array()); $params = array( 'layout' => $form_data['layout'], 'title' => $form_data['title'], 'track_submit' => !empty($analytics_data['analytics_track_submit']), 'track_fields' => !empty($analytics_data['analytics_track_fields']), ); $form = AccuaForm::create($fid, $params); } $out .= $form->render(true); $doing_ajax = function_exists('wp_doing_ajax') ? wp_doing_ajax() : (defined( 'DOING_AJAX' ) && DOING_AJAX); if ($doing_ajax && ($_REQUEST['action'] === 'wpseo_filter_shortcodes')) { $strip_regexp = '/(]*>(.*?)<\/iframe>|]*>(.*?)<\/script>|]*)type="hidden"[^>]*>)/is'; $out = preg_replace($strip_regexp, '', $out); } return $out; } function accua_forms_include($fid, $atts=array(), $content = '', $code = '') { $atts['fid'] = $fid; echo accua_forms_shortcode_handler($atts, $content, $code); } function __accua_forms_submissions_list_page(){ if(isset($_GET['sid'])) { accua_forms_single_submission(); } else { accua_forms_submissions_list_page(); } } function accua_forms_submissions_list_page_head(){ if(isset($_GET['sid'])) { require_once('accua-forms-single-submission.php'); accua_forms_single_submission(true); } else { require_once('accua-forms-submissions-page.php'); accua_forms_submissions_list_page(true); } } add_action('wp_ajax_accua_forms_download_submitted_file', 'accua_forms_download_submitted_file'); add_action('wp_ajax_nopriv_accua_forms_download_submitted_file', 'accua_forms_download_submitted_file'); function accua_forms_download_submitted_file(){ $get = stripslashes_deep($_GET); if (isset($get['subid'],$get['field'],$get['file'])) { if (!empty($get['html'])) { header("Content-type: text/html"); $subid = rawurlencode($get['subid']); $fieldid = rawurlencode($get['field']); $filename = rawurlencode($get['file']); $url = admin_url('admin-ajax.php') . "?action=accua_forms_download_submitted_file&subid={$subid}&field={$fieldid}&file={$filename}"; $url = htmlspecialchars($url,ENT_QUOTES); $filename = htmlspecialchars($get['file'],ENT_QUOTES); die("{$filename}{$filename}"); } global $wpdb; $subid = (int) $get['subid']; $field = $get['field']; $file = $get['file']; $query = "SELECT * FROM `{$wpdb->prefix}accua_forms_submissions_values` WHERE afsv_sub_id = %d AND afsv_field_id = %s AND afsv_value = %s "; $query = $wpdb->prepare($query, $subid, $field, $file); $subval = $wpdb->get_results($query, OBJECT); if ($subval) { $file_data = get_option('accua_forms_default_file_field_data',array()) + array('dest_path' => ''); $dest_path = _accua_forms_get_abs_dest_path($file_data['dest_path']); $filename = "{$dest_path}/{$subid}_{$field}_{$file}"; if (is_file($filename) && is_readable($filename)){ if (function_exists('finfo_open')){ @ $finfo = finfo_open(FILEINFO_MIME); if ($finfo) { @ $filetype = finfo_file($finfo, $filename); @ finfo_close($finfo); } } if (empty($filetype) && function_exists('mime_content_type')){ @ $filetype = mime_content_type($filename); } if (empty($filetype)) { $filetype = "application/octet-stream"; } header("Content-type: $filetype"); header("Content-length: ".filesize($filename)); if (empty($_GET['view'])) { header("Content-disposition: attachment; filename=\"$file\""); } readfile($filename); die(''); } } } header("HTTP/1.0 404 Not Found"); //header("Status: 404 Not Found"); die('File not found'); } function accua_forms_buildConditionalReplacer($map = array()) { if (!class_exists('AccuaConditionalReplacer')){ require_once('AccuaConditionalReplacer.php'); } return new AccuaConditionalReplacer($map); } add_action('wp_ajax_accua_forms_preview', 'accua_forms_preview'); function accua_forms_preview() { if (!current_user_can('manage_options')){ die (''); } echo ' '; wp_print_styles(); wp_print_head_scripts(); echo ''; echo accua_forms_shortcode_handler(array('fid'=>$_REQUEST['fid'])); wp_print_footer_scripts(); echo ''; die(''); } //salvataggio file excel add_action('wp_ajax_accua_forms_submission_page_save_excel', 'accua_forms_submission_page_save_excel'); //add_action('wp_ajax_nopriv_accua_forms_submission_page_save_excel', 'accua_forms_submission_page_save_excel'); function accua_forms_submission_page_save_excel() { if (!current_user_can('manage_options')){ header("HTTP/1.0 401 Access Denied"); //header("Status: 401 Access Denied"); die('You are not authorized to access this page.'); } require_once('accua-forms-submissions-page.php'); $listTable = new Accua_Forms_Submissions_List_Table(); $listTable->export_xls = true; $listTable->prepare_items(true); $show_col = explode( ',', $_GET['accua_show_field']); $show_col = array_diff($show_col, array('singlesub')); header("Content-disposition: attachment; filename=downloads-report.xls"); header("Content-type: application/vnd.ms-excel"); accua_forms_submission_page_save_excel_general($listTable,$show_col); die(''); } function accua_forms_submission_page_save_excel_general(Accua_Forms_Submissions_List_Table $listTable,array $show_col,array $options=array()) { global $wpdb; $content_type = 'text/html; charset=' . get_option('blog_charset'); //creo il file excel ?> get_columns(); foreach($cols as $col_key=>$col_value) { if(in_array($col_key, $show_col)) { ?> items as $id_submission=>$single_submission) { @ set_time_limit(10); echo ""; foreach($cols as $col_key=>$col_value) { if(in_array($col_key, $show_col)) { echo ""; } } echo ""; } ?>
"; if ($col_key == 'lead_status') { if (isset($lead_statuses[$single_submission['lead_status']])) { echo htmlspecialchars($lead_statuses[$single_submission['lead_status']]); } } else if(isset($single_submission[$col_key])) { if ( method_exists( $listTable, 'column_' . $col_key ) ) { echo call_user_func( array( &$listTable, 'column_' . $col_key ), $single_submission ); } else { echo $listTable->column_default( $single_submission, $col_key ); } } echo "
$value) { $tokens .= $value['name'] . ": {" . $key . "}\n"; switch ($value['type']) { case 'file': $tokens .= $value['name'] . " (download link): {__download_" . $key . "}\n"; break; case 'multiselect': case 'multicheckbox': $tokens .= $value['name'] . " (labels): {__label_" . $key . "}\n"; break; case 'select': case 'radio': $tokens .= $value['name'] . " (label): {__label_" . $key . "}\n"; break; case 'post-multicheckbox': $tokens .= $value['name'] . " (posts titles): {__label_" . $key . "}\n"; $tokens .= $value['name'] . " (posts ids): {__post_id_" . $key . "}\n"; $tokens .= $value['name'] . " (posts urls): {__post_url_" . $key . "}\n"; break; case 'post-select': $tokens .= $value['name'] . " (post title): {__label_" . $key . "}\n"; $tokens .= $value['name'] . " (post id): {__post_id_" . $key . "}\n"; $tokens .= $value['name'] . " (post url): {__post_url_" . $key . "}\n"; break; } } echo <<

Tokens

In HTML text, use {!token_name} to insert unfiltered token value

Fields

These tokens are available only if the field is added to the form
$tokens

Generic tokens

{__fid}
{__subid}
{__pid}
{__ip}
{__anonymized_ip}
{__uri}
{__url}
{__referrer}
{__lang}
{__locale}
{__created}
{__created_day}
{__created_day_month_year}
{__created_hour}
{__submitted}
{__submitted_day}
{__submitted_day_month_year}
{__submitted_hour}
{__user_agent}
{__platform}
{__tentatives}
{__submit_method}
{__submitted_txt}
{__submitted_html}
{__submitted_json}
{__autoreply}
{__autoreply_email}
{__confirmation_emails_message}
{__review_submission_url}
EOT; do_action('accua_forms_print_tokens'); } function accua_get_pages($args = '') { global $wpdb; $defaults = array( 'child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => array(), 'include' => array(), 'meta_key' => '', 'meta_value' => '', 'meta_value_lt' => '', 'meta_value_gt' => '', 'meta_value_le' => '', 'meta_value_ge' => '', 'meta_value_like' => '', 'meta_value_format' => 'string', 'authors' => '', 'parent' => -1, 'exclude_tree' => '', 'number' => '', 'offset' => 0, 'post_type' => 'page', 'post_status' => 'publish', ); $r = wp_parse_args( $args, $defaults ); $child_of = (int) $r['child_of']; $sort_order = $r['sort_order']; $sort_column = $r['sort_column']; $hierarchical = $r['hierarchical']; $exclude = $r['exclude']; $include = $r['include']; $meta_key = $r['meta_key']; $meta_value = $r['meta_value']; $meta_value_lt = $r['meta_value_lt']; $meta_value_gt = $r['meta_value_gt']; $meta_value_le = $r['meta_value_le']; $meta_value_ge = $r['meta_value_ge']; $meta_value_like = $r['meta_value_like']; $meta_value_format = $r['meta_value_format']; $authors = $r['authors']; $parent = $r['parent']; $exclude_tree = $r['exclude_tree']; $number = (int) $r['number']; $offset = (int) $r['offset']; $post_type = $r['post_type']; $post_status = $r['post_status']; /* // Make sure the post type is hierarchical $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); if ( !in_array( $post_type, $hierarchical_post_types ) ) return false; */ // Make sure we have a valid post type if ( !is_array( $post_type ) ) $post_type = explode( ',', $post_type ); if ( array_diff( $post_type, get_post_types() ) ) return false; // Make sure we have a valid post status if ( !is_array( $post_status ) ) $post_status = explode( ',', $post_status ); if ( array_diff( $post_status, get_post_stati() ) ) return false; /* $cache = array(); $key = md5( serialize( compact(array_keys($defaults)) ) ); if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) { if ( is_array($cache) && isset( $cache[ $key ] ) ) { $pages = apply_filters('get_pages', $cache[ $key ], $r ); return $pages; } } if ( !is_array($cache) ) $cache = array(); */ $inclusions = ''; if ( !empty($include) ) { $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include $parent = -1; $exclude = ''; $meta_key = ''; $meta_value = ''; $meta_value_lt = ''; $meta_value_gt = ''; $meta_value_le = ''; $meta_value_ge = ''; $meta_value_like = ''; $hierarchical = false; $incpages = wp_parse_id_list( $include ); if ( ! empty( $incpages ) ) { foreach ( $incpages as $incpage ) { if (empty($inclusions)) $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage); else $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage); } } } if (!empty($inclusions)) $inclusions .= ')'; $exclusions = ''; if ( !empty($exclude) ) { $expages = wp_parse_id_list( $exclude ); if ( ! empty( $expages ) ) { foreach ( $expages as $expage ) { if (empty($exclusions)) $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage); else $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage); } } } if (!empty($exclusions)) $exclusions .= ')'; $author_query = ''; if (!empty($authors)) { $post_authors = preg_split('/[\s,]+/',$authors); if ( ! empty( $post_authors ) ) { foreach ( $post_authors as $post_author ) { //Do we have an author id or an author login? if ( 0 == intval($post_author) ) { $post_author = get_user_by('login', $post_author); if ( empty($post_author) ) continue; if ( empty($post_author->ID) ) continue; $post_author = $post_author->ID; } if ( '' == $author_query ) $author_query = $wpdb->prepare(' post_author = %d ', $post_author); else $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); } if ( '' != $author_query ) $author_query = " AND ($author_query)"; } } $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified', 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent', 'ID', 'rand', 'comment_count'); $join = ''; $where = "$exclusions $inclusions "; if ( ! ( empty( $meta_key ) && empty( $meta_value ) && empty( $meta_value_lt ) && empty( $meta_value_gt ) && empty( $meta_value_le ) && empty( $meta_value_ge ) && empty( $meta_value_like ) ) ) { $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )"; $allowed_keys[] = 'meta_key'; $allowed_keys[] = 'meta_value'; // meta_key and meta_value might be slashed $meta_key = stripslashes($meta_key); $meta_value = stripslashes($meta_value); $meta_value_lt = stripslashes($meta_value_lt); $meta_value_gt = stripslashes($meta_value_gt); $meta_value_le = stripslashes($meta_value_le); $meta_value_ge = stripslashes($meta_value_ge); $meta_value_like = stripslashes($meta_value_like); if ( ! empty( $meta_key ) ) { $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key); } $meta_value_field = "$wpdb->postmeta.meta_value"; $meta_value_timestamp = false; switch($meta_value_format) { case 'timestamp': $meta_value_field = "TIMESTAMP( $meta_value_field )"; $meta_value_param = "FROM_UNIXTIME( %s )"; $meta_value_timestamp = true; break; case 'int': $meta_value_param = "%d"; break; case 'float': $meta_value_param = "%f"; break; //case 'string': default: $meta_value_param = "%s"; } if ( ! empty( $meta_value ) ) { if ($meta_value_timestamp) { $meta_value = strtotime($meta_value); } $where .= $wpdb->prepare(" AND $meta_value_field = $meta_value_param", $meta_value); } if ( ! empty( $meta_value_lt ) ) { if ($meta_value_timestamp) { $meta_value_lt = strtotime($meta_value_lt); } $where .= $wpdb->prepare(" AND $meta_value_field < $meta_value_param", $meta_value_lt); } if ( ! empty( $meta_value_gt ) ) { if ($meta_value_timestamp) { $meta_value_gt = strtotime($meta_value_gt); } $where .= $wpdb->prepare(" AND $meta_value_field > $meta_value_param", $meta_value_gt); } if ( ! empty( $meta_value_le ) ) { if ($meta_value_timestamp) { $meta_value_le = strtotime($meta_value_le); } $where .= $wpdb->prepare(" AND $meta_value_field <= $meta_value_param", $meta_value_le); } if ( ! empty( $meta_value_ge ) ) { if ($meta_value_timestamp) { $meta_value_ge = strtotime($meta_value_ge); } $where .= $wpdb->prepare(" AND $meta_value_field >= $meta_value_param", $meta_value_ge); } if ( ! empty( $meta_value_like ) ) { if ($meta_value_timestamp) { $meta_value_like = strtotime($meta_value_like); } $where .= $wpdb->prepare(" AND $meta_value_field like $meta_value_param", $meta_value_like); } } if ( $parent >= 0 ) $where .= $wpdb->prepare(' AND post_parent = %d ', $parent); if ( 1 == count ( $post_type ) ) { $where_post_type = $wpdb->prepare( "post_type = %s", array_shift( $post_type ) ); } else { $post_type = implode( "', '", $post_type ); $where_post_type = "post_type IN ('$post_type')"; } if ( 1 == count( $post_status ) ) { $where_post_type .= $wpdb->prepare( " AND post_status = %s", array_shift( $post_status ) ); } else { $post_status = implode( "', '", $post_status ); $where_post_type .= " AND post_status IN ('$post_status')"; } $orderby_array = array(); foreach ( explode( ',', $sort_column ) as $orderby ) { $orderby = trim( $orderby ); if ( !in_array( $orderby, $allowed_keys ) ) continue; switch ( $orderby ) { case 'menu_order': break; case 'ID': $orderby = "$wpdb->posts.ID"; break; case 'rand': $orderby = 'RAND()'; break; case 'comment_count': $orderby = "$wpdb->posts.comment_count"; break; case 'meta_key': case 'meta_value': $orderby = "$wpdb->postmeta.$orderby"; break; default: if ( 0 === strpos( $orderby, 'post_' ) ) $orderby = "$wpdb->posts." . $orderby; else $orderby = "$wpdb->posts.post_" . $orderby; } $orderby_array[] = $orderby; } $sort_column = ! empty( $orderby_array ) ? implode( ',', $orderby_array ) : "$wpdb->posts.post_title"; $sort_order = strtoupper( $sort_order ); if ( '' !== $sort_order && !in_array( $sort_order, array( 'ASC', 'DESC' ) ) ) $sort_order = 'ASC'; $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where "; $query .= $author_query; $query .= " ORDER BY " . $sort_column . " " . $sort_order ; if ( !empty($number) && !empty($offset) ) { $query .= $wpdb->prepare(' LIMIT %d, %d', $offset, $number); } //echo ""; $pages = $wpdb->get_results($query); if ( empty($pages) ) { $pages = apply_filters('get_pages', array(), $r); return $pages; } // Sanitize before caching so it'll only get done once $num_pages = count($pages); for ($i = 0; $i < $num_pages; $i++) { $pages[$i] = sanitize_post($pages[$i], 'raw'); } /* // Update cache. update_post_cache( $pages ); */ if ( $child_of || $hierarchical ) $pages = get_page_children($child_of, $pages); if ( !empty($exclude_tree) ) { $exclude = (int) $exclude_tree; $children = get_page_children($exclude, $pages); $excludes = array(); foreach ( $children as $child ) $excludes[] = $child->ID; $excludes[] = $exclude; $num_pages = count($pages); for ( $i = 0; $i < $num_pages; $i++ ) { if ( in_array($pages[$i]->ID, $excludes) ) unset($pages[$i]); } } $pages = apply_filters('get_pages', $pages, $r); return $pages; } function accua_forms_trash_submission($id_sub){ global $wpdb; return $wpdb->query($wpdb->prepare("UPDATE `{$wpdb->prefix}accua_forms_submissions` SET afs_status = -1 WHERE afs_id = %d", $id_sub)) !== FALSE; } function accua_forms_get_lead_statuses() { static $statuses = NULL; if ($statuses === NULL) { $statuses = array( 0 => __('Undefined', 'contact-forms'), -1 => __('Spam', 'contact-forms'), 1 => __('Job Candidate', 'contact-forms'), 2 => __('Lead', 'contact-forms'), 3 => __('Prospect', 'contact-forms'), 4 => __('Opportunity', 'contact-forms'), 5 => __('Customer', 'contact-forms'), 6 => __('Supplier', 'contact-forms'), 7 => __('Other', 'contact-forms'), ); } return $statuses; } function accua_forms_select_lead_status($subid, $original_lead_status) { static $accuaHelp = NULL; if ($accuaHelp === NULL) { if (!class_exists('AccuaFormsHelp')) { require_once('accua-forms-help.php'); } $accuaHelp = AccuaFormsHelp::getInstance(); } $nonce = htmlspecialchars(_accua_forms_json_encode(wp_create_nonce( "set_lead_status_$subid" )),ENT_QUOTES); $ret = "" . $accuaHelp->add_pointer('contact_forms_lead_statuses') . ""; return $ret; } add_action( 'wp_ajax_accua-forms-set-lead-status' , 'accua_forms_set_lead_status'); function accua_forms_set_lead_status() { if (!current_user_can('manage_options')){ wp_die(0, 403); } $post = $_POST + array( 'subid' => 0, 'lead_status' => 0, ); $subid = (int) $post['subid']; if ($subid) { check_ajax_referer("set_lead_status_$subid", '_nonce_set_lead_status'); $lead_status = (int) $post['lead_status']; $statuses = accua_forms_get_lead_statuses(); if (isset($statuses[$lead_status])) { global $wpdb; $ret = $wpdb->update("{$wpdb->prefix}accua_forms_submissions", array('afs_lead_status' => $lead_status), array('afs_id' => $subid), '%d', '%d' ); if ($ret !== FALSE) { wp_die(1, 200); } } } wp_die(0, 500); }