예제 #1
0
/**
 * Get the current state for this stage in process
 *
 * @since 0.2.0
 *
 * @uses "caldera_forms_render_entry_id"
 *
 * @param int $entry_id ID of entry
 * @param array $form The form configuration
 *
 * @return mixed
 */
function cf_form_connector_get_stage_state($entry_id, $form)
{
    $process_record = cf_form_connector_get_current_position();
    if (!empty($process_record) && !empty($process_record[$form['ID']]) && !empty($form['current_form'])) {
        if (!empty($process_record[$form['ID']][$form['current_form']]) && !empty($process_record[$form['ID']][$form['current_form']]['id'])) {
            if (is_user_logged_in()) {
                return $process_record[$form['ID']][$form['current_form']]['id'];
            } else {
                // no permission, simulate with prepopulate
                $entry = Caldera_Forms::get_entry($process_record[$form['ID']][$form['current_form']]['id'], $form['current_form']);
                if (!empty($entry['data'])) {
                    foreach ($entry['data'] as $field_id => $values) {
                        $process_record[$form['ID']][$form['current_form']]['pre_data'][$field_id] = $values['value'];
                    }
                    cf_form_connector_set_current_position($process_record);
                }
                add_filter('caldera_forms_render_pre_get_entry', 'cf_form_connector_partial_populate_form', 10, 2);
            }
        }
    }
    return $entry_id;
}
예제 #2
0
 static function save_form()
 {
     /// check for form delete
     if (!empty($_GET['delete']) && !empty($_GET['cal_del']) && current_user_can('manage_options')) {
         if (!wp_verify_nonce($_GET['cal_del'], 'cf_del_frm')) {
             // This nonce is not valid.
             wp_die(__('Sorry, please try again', 'caldera-forms'), __('Form Delete Error', 'caldera-forms'));
         } else {
             // ok to delete
             // get form registry
             $forms = Caldera_Forms::get_forms(true);
             if (isset($forms[$_GET['delete']])) {
                 unset($forms[$_GET['delete']]);
                 $form = Caldera_Forms::get_form($_GET['delete']);
                 if (empty($form)) {
                     do_action('caldera_forms_delete_form', $_GET['delete']);
                     update_option('_caldera_forms', $forms);
                 } else {
                     if (delete_option($_GET['delete'])) {
                         do_action('caldera_forms_delete_form', $_GET['delete']);
                         update_option('_caldera_forms', $forms);
                     }
                 }
             }
             wp_redirect('admin.php?page=caldera-forms');
             exit;
         }
     }
     if (isset($_POST['cfimporter']) && current_user_can('manage_options')) {
         if (check_admin_referer('cf-import', 'cfimporter')) {
             if (!empty($_FILES['import_file']['size'])) {
                 $loc = wp_upload_dir();
                 if (move_uploaded_file($_FILES['import_file']['tmp_name'], $loc['path'] . '/cf-form-import.json')) {
                     $data = json_decode(file_get_contents($loc['path'] . '/cf-form-import.json'), true);
                     if (isset($data['ID']) && isset($data['name'])) {
                         // generate a new ID
                         $data['ID'] = uniqid('CF');
                         $data['name'] = $_POST['name'];
                         // rebuild field IDS
                         /*
                         if( !empty( $data['fields'] ) ){
                         	$old_fields = array();
                         	$fields 	= $data['fields'];								
                         	$layout_fields = $data['layout_grid']['fields'];
                         	$data['layout_grid']['fields'] = $data['fields'] = array();
                         	foreach( $fields as $field ){									
                         		$field_id = uniqid('fld_');
                         		$old_fields[$field['ID']] = $field_id;
                         
                         		$data['layout_grid']['fields'][$field_id] = $layout_fields[$field['ID']];
                         		$field['ID'] = $field_id;
                         		$data['fields'][$field_id] = $field;
                         
                         	}
                         
                         
                         	foreach( $data['fields'] as $field ){
                         		// rebind conditions
                         		if( !empty( $field['conditions']['group'] ) ){
                         			foreach( $field['conditions']['group'] as $group_id=>$group ){
                         				foreach( $group as $group_line_id=>$group_line ){
                         					$data['fields'][$field['ID']]['conditions']['group'][$group_id][$group_line_id]['field'] = $old_fields[$group_line['field']];
                         				}
                         			}
                         		}
                         	}
                         
                         }
                         // rebuild processor IDS
                         if( !empty( $data['processors'] ) ){
                         	
                         	$processors 	= $data['processors'];								
                         	$data['processors'] = array();
                         	$old_processors = array();
                         	foreach( $processors as $processor ){
                         		$processor_id = uniqid('fp_');
                         		$old_processors[$processor['ID']] = $processor_id;
                         		$processor['ID'] = $processor_id;									
                         		// fix binding
                         		if( !empty( $processor['config'] ) && !empty( $data['fields'] ) ){
                         			foreach( $processor['config'] as $config_key => &$config_value ){
                         				if( is_string($config_value) ){
                         					foreach( $old_fields as $old_field=>$new_field ){
                         						$config_value = str_replace( $old_field, $new_field, $config_value );
                         					}
                         				}
                         			}
                         		}
                         		$data['processors'][$processor_id] = $processor;
                         	}
                         	// fix processor bindings
                         	foreach( $data['processors'] as &$processor ){
                         		if( !empty( $processor['config'] ) ){
                         			foreach( $processor['config'] as $config_key => &$config_value ){
                         				if( is_string($config_value) ){
                         					foreach( $old_processors as $old_proc=>$new_proc ){
                         						$config_value = str_replace( $old_proc, $new_proc, $config_value );
                         					}
                         				}
                         			}
                         		}
                         	}
                         	// fix field - processor bindings
                         	if( !empty( $data['fields'] ) ){
                         		foreach( $data['fields'] as &$field ){
                         			if( !empty( $field['config'] ) ){
                         				foreach( $field['config'] as $config_key => &$config_value ){
                         					if( is_string($config_value) ){
                         						foreach( $old_processors as $old_proc=>$new_proc ){
                         							$config_value = str_replace( $old_proc, $new_proc, $config_value );
                         						}
                         					}
                         				}
                         			}
                         		}
                         	}
                         }
                         */
                         // get form registry
                         $forms = Caldera_Forms::get_forms(true);
                         if (empty($forms)) {
                             $forms = array();
                         }
                         // add form to registry
                         $forms[$data['ID']] = $data;
                         // remove undeeded settings for registry
                         if (isset($forms[$data['ID']]['layout_grid'])) {
                             unset($forms[$data['ID']]['layout_grid']);
                         }
                         if (isset($forms[$data['ID']]['fields'])) {
                             unset($forms[$data['ID']]['fields']);
                         }
                         if (isset($forms[$data['ID']]['processors'])) {
                             unset($forms[$data['ID']]['processors']);
                         }
                         if (isset($forms[$data['ID']]['settings'])) {
                             unset($forms[$data['ID']]['settings']);
                         }
                         // add from to list
                         update_option($data['ID'], $data);
                         do_action('caldera_forms_import_form', $data);
                         update_option('_caldera_forms', $forms);
                         do_action('caldera_forms_save_form_register', $data);
                         wp_redirect('admin.php?page=caldera-forms&edit=' . $data['ID']);
                         exit;
                     } else {
                         wp_die(__('Sorry, File is not valid.', 'caldera-forms'), __('Form Import Error', 'caldera-forms'));
                     }
                 }
             } else {
                 wp_die(__('Sorry, File not uploaded.', 'caldera-forms'), __('Form Import Error', 'caldera-forms'));
             }
         } else {
             wp_die(__('Sorry, please try again', 'caldera-forms'), __('Form Import Error', 'caldera-forms'));
         }
     }
     if (!empty($_GET['export-form']) && current_user_can('manage_options')) {
         $form = Caldera_Forms::get_form($_GET['export-form']);
         if (empty($form)) {
             wp_die(__('Form does not exist.', 'caldera-forms'));
         }
         header("Pragma: public");
         header("Expires: 0");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Cache-Control: private", false);
         header("Content-Type: application/json");
         header("Content-Disposition: attachment; filename=\"" . sanitize_file_name(strtolower($form['name'])) . "-export.json\";");
         echo json_encode($form);
         exit;
     }
     if (!empty($_GET['export']) && current_user_can('manage_options')) {
         $form = Caldera_Forms::get_form($_GET['export']);
         global $wpdb;
         //build labels
         $labels = array();
         $structure = array();
         $field_types = apply_filters('caldera_forms_get_field_types', array());
         if (!empty($form['fields'])) {
             $headers['date_submitted'] = 'Submitted';
             foreach ($form['fields'] as $field_id => $field) {
                 if (isset($field_types[$field['type']]['capture']) && false === $field_types[$field['type']]['capture']) {
                     continue;
                 }
                 $headers[$field['slug']] = $field['label'];
                 $structure[$field['slug']] = $field_id;
             }
         }
         $filter = null;
         // export set - transient
         if (!empty($_GET['tid'])) {
             $items = get_transient($_GET['tid']);
             if (!empty($items)) {
                 $filter = ' AND `entry`.`id` IN (' . implode(',', $items) . ') ';
             } else {
                 wp_die(__('Export selection has expired', 'caldera-forms'), __('Export Expired', 'caldera-forms'));
             }
         }
         $rawdata = $wpdb->get_results($wpdb->prepare("\n\t\t\tSELECT\n\t\t\t\t`entry`.`id` as `_entryid`,\n\t\t\t\t`entry`.`form_id` AS `_form_id`,\n\t\t\t\t`entry`.`datestamp` AS `_date_submitted`,\n\t\t\t\t`entry`.`user_id` AS `_user_id`\n\n\t\t\tFROM `" . $wpdb->prefix . "cf_form_entries` AS `entry`\n\t\t\t\n\n\t\t\tWHERE `entry`.`form_id` = %s\n\t\t\t" . $filter . "\n\t\t\tAND `entry`.`status` = 'active'\n\t\t\tORDER BY `entry`.`datestamp` DESC;", $_GET['export']));
         $data = array();
         foreach ($rawdata as $entry) {
             $submission = Caldera_Forms::get_entry($entry->_entryid, $form);
             $data[$entry->_entryid]['date_submitted'] = $entry->_date_submitted;
             foreach ($structure as $slug => $field_id) {
                 $data[$entry->_entryid][$slug] = isset($submission['data'][$field_id]['value']) ? $submission['data'][$field_id]['value'] : null;
             }
             //dump($data);
         }
         header("Pragma: public");
         header("Expires: 0");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Cache-Control: private", false);
         header("Content-Type: text/csv charset=utf-8;");
         header("Content-Disposition: attachment; filename=\"" . sanitize_file_name($form['name']) . ".csv\";");
         header("Content-Transfer-Encoding: binary");
         $df = fopen("php://output", 'w');
         fputcsv($df, $headers);
         foreach ($data as $row) {
             $csvrow = array();
             foreach ($headers as $key => $label) {
                 if (!isset($row[$key])) {
                     $row[$key] = null;
                 } else {
                     if (is_array($row[$key]) && isset($row[$key]['label'])) {
                         $row[$key] = $row[$key]['value'];
                     } elseif (is_array($row[$key]) && count($row[$key]) === 1) {
                         $row[$key] = $row[$key][0];
                     } elseif (is_array($row[$key])) {
                         $subs = array();
                         foreach ($row[$key] as $row_part) {
                             if (is_array($row_part) && isset($row_part['label'])) {
                                 $subs[] = $row_part['value'];
                             } else {
                                 $subs[] = $row_part;
                             }
                         }
                         $row[$key] = implode(', ', $subs);
                     }
                 }
                 $csvrow[] = $row[$key];
             }
             fputcsv($df, $row);
         }
         fclose($df);
         exit;
     }
     if (isset($_POST['config']) && isset($_POST['cf_edit_nonce']) && current_user_can('manage_options')) {
         // if this fails, check_admin_referer() will automatically print a "failed" page and die.
         if (check_admin_referer('cf_edit_element', 'cf_edit_nonce')) {
             // strip slashes
             $data = json_decode(stripslashes_deep($_POST['config']), ARRAY_A);
             // get form registry
             $forms = Caldera_Forms::get_forms(true);
             if (empty($forms)) {
                 $forms = array();
             }
             // option value labels
             if (!empty($data['fields'])) {
                 foreach ($data['fields'] as &$field) {
                     if (!empty($field['config']['option']) && is_array($field['config']['option'])) {
                         foreach ($field['config']['option'] as &$option) {
                             if (!isset($option['value'])) {
                                 $option['value'] = $option['label'];
                             }
                         }
                     }
                 }
             }
             // add form to registry
             $forms[$data['ID']] = $data;
             // remove undeeded settings for registry
             if (isset($forms[$data['ID']]['layout_grid'])) {
                 unset($forms[$data['ID']]['layout_grid']);
             }
             if (isset($forms[$data['ID']]['fields'])) {
                 unset($forms[$data['ID']]['fields']);
             }
             if (isset($forms[$data['ID']]['processors'])) {
                 unset($forms[$data['ID']]['processors']);
             }
             if (isset($forms[$data['ID']]['settings'])) {
                 unset($forms[$data['ID']]['settings']);
             }
             foreach ($forms as $form_id => $form_config) {
                 if (empty($form_config)) {
                     unset($forms[$form_id]);
                 }
             }
             // combine structure pages
             $data['layout_grid']['structure'] = implode('#', $data['layout_grid']['structure']);
             // add from to list
             update_option($data['ID'], $data);
             do_action('caldera_forms_save_form', $data);
             update_option('_caldera_forms', $forms);
             do_action('caldera_forms_save_form_register', $data);
             if (!empty($_POST['sender'])) {
                 exit;
             }
             wp_redirect('admin.php?page=caldera-forms');
             die;
         }
         return;
     }
 }
예제 #3
0
 static function save_form()
 {
     if (!isset($_GET['page']) || 'caldera-forms' != $_GET['page']) {
         return;
     }
     add_filter('caldera_forms_manage_cap', array(__CLASS__, 'save_form_cap_filter'), 9, 3);
     /// check for form delete
     if (!empty($_GET['delete']) && !empty($_GET['cal_del']) && current_user_can(Caldera_Forms::get_manage_cap('save'), strip_tags($_GET['delete']))) {
         if (!wp_verify_nonce($_GET['cal_del'], 'cf_del_frm')) {
             // This nonce is not valid.
             wp_die(__('Sorry, please try again', 'caldera-forms'), __('Form Delete Error', 'caldera-forms'));
         } else {
             $deleted = Caldera_Forms_Forms::delete_form(strip_tags($_GET['delete']));
             if ($deleted) {
                 wp_redirect('admin.php?page=caldera-forms');
                 exit;
             } else {
                 wp_die(__('Sorry, please try again', 'caldera-forms'), __('Form could not be deleted.', 'caldera-forms'));
             }
         }
     }
     /** IMPORT */
     if (isset($_POST['cfimporter']) && current_user_can(Caldera_Forms::get_manage_cap('import'))) {
         if (check_admin_referer('cf-import', 'cfimporter')) {
             if (isset($_FILES['import_file']) && !empty($_FILES['import_file']['size'])) {
                 $loc = wp_upload_dir();
                 if (move_uploaded_file($_FILES['import_file']['tmp_name'], $loc['path'] . '/cf-form-import.json')) {
                     $data = json_decode(file_get_contents($loc['path'] . '/cf-form-import.json'), true);
                     if (!is_array($data)) {
                         wp_die(esc_html__('File is not a valid Caldera Form Import', 'caldera-forms'));
                     }
                     if (!isset($_POST['name'])) {
                         wp_die(esc_html__('Form must have a name.', 'caldera-forms'));
                     }
                     $data['name'] = strip_tags($_POST['name']);
                     $new_form_id = Caldera_Forms_Forms::import_form($data);
                     if (is_string($new_form_id)) {
                         cf_redirect('admin.php?page=caldera-forms&edit=' . $new_form_id, 302);
                         exit;
                     } else {
                         wp_die(esc_html__('Form could not be imported.', 'caldera-forms'));
                     }
                 }
             } else {
                 wp_die(esc_html__('Sorry, File not uploaded.', 'caldera-forms'), esc_html__('Form Import Error', 'caldera-forms'));
             }
         } else {
             wp_die(esc_html__('Sorry, please try again', 'caldera-forms'), esc_html__('Form Import Error', 'caldera-forms'));
         }
     }
     if (!empty($_GET['export-form']) && current_user_can(Caldera_Forms::get_manage_cap('export', strip_tags($_GET['export-form'])))) {
         $form = Caldera_Forms_Forms::get_form($_GET['export-form']);
         if (empty($form)) {
             wp_die(__('Form does not exist.', 'caldera-forms'));
         }
         header("Pragma: public");
         header("Expires: 0");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Cache-Control: private", false);
         if (empty($_GET['format']) || $_GET['format'] != 'php') {
             header("Content-Type: application/json");
             header("Content-Disposition: attachment; filename=\"" . sanitize_file_name(strtolower($form['name'])) . "-export.json\";");
             echo json_encode($form);
         } else {
             $form_id = sanitize_key($_GET['form_id']);
             if (!empty($_GET['pin_menu'])) {
                 $form['pinned'] = 1;
             }
             header("Content-Type: application/php");
             header("Content-Disposition: attachment; filename=\"" . sanitize_file_name(strtolower($form_id)) . "-include.php\";");
             echo '<?php' . "\r\n";
             echo "/**\r\n * Caldera Forms - PHP Export \r\n * {$form['name']} \r\n * @version    " . CFCORE_VER . "\r\n * @license   GPL-2.0+\r\n * \r\n */\r\n\r\n\r\n";
             $structure = "/**\r\n * Filter admin forms to include custom form in admin\r\n *\r\n * @since 1.3.1\r\n *\r\n * @param array \$forms All registered forms\r\n */\r\n";
             $structure .= 'add_filter( "caldera_forms_get_forms", function( $forms ){' . "\r\n";
             $structure .= "\t" . '$forms["' . $form_id . '"] = apply_filters( "caldera_forms_get_form-' . $form_id . '", array() );' . "\r\n";
             $structure .= "\t" . 'return $forms;' . "\r\n";
             $structure .= "} );\r\n\r\n";
             $structure .= "/**\r\n * Filter form request to include form structure to be rendered\r\n *\r\n * @since 1.3.1\r\n *\r\n * @param \$form array form structure\r\n */\r\n";
             $structure .= "add_filter( 'caldera_forms_get_form-{$form_id}', function( \$form ){\r\n return " . var_export($form, true) . ";\r\n" . '} );' . "\r\n";
             // cleanups because I'm me
             $structure = str_replace('array (', 'array(', $structure);
             $structure = str_replace($form['ID'], $form_id, $structure);
             // switch field IDs
             if (!empty($_GET['convert_slugs'])) {
                 if (!empty($form['fields'])) {
                     foreach ($form['fields'] as $field_id => $field) {
                         $structure = str_replace($field_id, $field['slug'], $structure);
                     }
                 }
             }
             echo $structure;
         }
         exit;
     }
     if (!empty($_GET['export']) && current_user_can(Caldera_Forms::get_manage_cap('export', strip_tags($_GET['export'])))) {
         $form = Caldera_Forms_Forms::get_form($_GET['export']);
         global $wpdb;
         //build labels
         $labels = array();
         $structure = array();
         $field_types = apply_filters('caldera_forms_get_field_types', array());
         $headers = array();
         if (!empty($form['fields'])) {
             $headers['date_submitted'] = 'Submitted';
             foreach ($form['fields'] as $field_id => $field) {
                 if (isset($field_types[$field['type']]['capture']) && false === $field_types[$field['type']]['capture']) {
                     continue;
                 }
                 $headers[$field['slug']] = $field['label'];
                 $structure[$field['slug']] = $field_id;
             }
         }
         $filter = null;
         // export set - transient
         if (!empty($_GET['tid'])) {
             $items = get_transient($_GET['tid']);
             if (!empty($items)) {
                 $filter = ' AND `entry`.`id` IN (' . implode(',', $items) . ') ';
             } else {
                 wp_die(__('Export selection has expired', 'caldera-forms'), __('Export Expired', 'caldera-forms'));
             }
         }
         $rawdata = $wpdb->get_results($wpdb->prepare("\n\t\t\tSELECT\n\t\t\t\t`entry`.`id` as `_entryid`,\n\t\t\t\t`entry`.`form_id` AS `_form_id`,\n\t\t\t\t`entry`.`datestamp` AS `_date_submitted`,\n\t\t\t\t`entry`.`user_id` AS `_user_id`\n\n\t\t\tFROM `" . $wpdb->prefix . "cf_form_entries` AS `entry`\n\t\t\t\n\n\t\t\tWHERE `entry`.`form_id` = %s\n\t\t\t" . $filter . "\n\t\t\tAND `entry`.`status` = 'active'\n\t\t\tORDER BY `entry`.`datestamp` DESC;", $_GET['export']));
         $data = array();
         foreach ($rawdata as $entry) {
             $submission = Caldera_Forms::get_entry($entry->_entryid, $form);
             $data[$entry->_entryid]['date_submitted'] = $entry->_date_submitted;
             foreach ($structure as $slug => $field_id) {
                 $data[$entry->_entryid][$slug] = isset($submission['data'][$field_id]['value']) ? $submission['data'][$field_id]['value'] : null;
             }
         }
         if (empty($headers)) {
             wp_die(esc_html_e('Could not process export. This is most likely due to a problem with the form configuration.', 'caldera-forms'));
         }
         header("Pragma: public");
         header("Expires: 0");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Cache-Control: private", false);
         header("Content-Type: text/csv charset=utf-8;");
         header("Content-Disposition: attachment; filename=\"" . sanitize_file_name($form['name']) . ".csv\";");
         header("Content-Transfer-Encoding: binary");
         $df = fopen("php://output", 'w');
         fputcsv($df, $headers);
         foreach ($data as $row) {
             $csvrow = array();
             foreach ($headers as $key => $label) {
                 if (!isset($row[$key])) {
                     $row[$key] = null;
                 } else {
                     if (is_array($row[$key]) && isset($row[$key]['label'])) {
                         $row[$key] = $row[$key]['value'];
                     } elseif (is_array($row[$key])) {
                         $subs = array();
                         foreach ($row[$key] as $row_part) {
                             if (is_array($row_part) && isset($row_part['label'])) {
                                 $subs[] = $row_part['value'];
                             } else {
                                 $subs[] = $row_part;
                             }
                         }
                         $row[$key] = implode(', ', $subs);
                     }
                 }
                 $csvrow[] = $row[$key];
             }
             fputcsv($df, $row);
         }
         fclose($df);
         exit;
     }
     if (isset($_POST['config']) && isset($_POST['cf_edit_nonce']) && current_user_can(Caldera_Forms::get_manage_cap('manage'))) {
         // if this fails, check_admin_referer() will automatically print a "failed" page and die.
         if (check_admin_referer('cf_edit_element', 'cf_edit_nonce')) {
             // strip slashes
             $data = json_decode(stripslashes_deep($_POST['config']), ARRAY_A);
             self::save_a_form($data);
             if (!empty($_POST['sender'])) {
                 exit;
             }
             wp_redirect('admin.php?page=caldera-forms');
             die;
         }
         return;
     }
 }
예제 #4
0
 public function api_handler()
 {
     global $wp_query;
     // check for API
     // if this is not a request for json or a singular object then bail
     if (!isset($wp_query->query_vars['cf_api'])) {
         return;
     }
     // check if form exists
     $form = self::get_form($wp_query->query_vars['cf_api']);
     if (!empty($form['ID'])) {
         if ($form['ID'] === $wp_query->query_vars['cf_api']) {
             // got it!
             // need entry?
             if (!empty($wp_query->query_vars['cf_entry'])) {
                 $entry = Caldera_Forms::get_entry($wp_query->query_vars['cf_entry'], $form);
                 wp_send_json($entry);
             }
             // is a post?
             if ($_SERVER['REQUEST_METHOD'] === 'POST') {
                 $_POST['_wp_http_referer_true'] = 'api';
                 $_POST['_cf_frm_id'] = $_POST['cfajax'] = $wp_query->query_vars['cf_api'];
                 $submission = Caldera_Forms::process_submission();
                 wp_send_json($submission);
             }
         }
     }
     $atts = array('id' => $wp_query->query_vars['cf_api'], 'ajax' => true);
     echo self::render_form($atts);
     exit;
 }
예제 #5
0
 public static function cf_init_system()
 {
     global $post, $front_templates, $wp_query, $process_id, $form;
     // check for API
     if (!empty($wp_query->query_vars['cf_api'])) {
         // check if form exists
         $form = self::get_form($wp_query->query_vars['cf_api']);
         if (!empty($form['ID'])) {
             if ($form['ID'] === $wp_query->query_vars['cf_api']) {
                 // got it!
                 // need entry?
                 if (!empty($wp_query->query_vars['cf_entry'])) {
                     $entry = Caldera_Forms::get_entry($wp_query->query_vars['cf_entry'], $form);
                     wp_send_json($entry);
                 }
                 // is a post?
                 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
                     $_POST['_wp_http_referer_true'] = 'api';
                     $_POST['_cf_frm_id'] = $_POST['cfajax'] = $wp_query->query_vars['cf_api'];
                     $submission = Caldera_Forms::process_submission();
                 }
                 wp_send_json($wp_query);
                 die;
             }
         }
     }
     if (!empty($_GET['cf_preview'])) {
         $form = self::get_form($_GET['cf_preview']);
         $userid = get_current_user_id();
         if (!empty($userid)) {
             if (empty($form['ID']) || $form['ID'] !== $_GET['cf_preview']) {
                 return;
             }
             if (empty($post) || $post->post_title !== 'Caldera Forms Preview') {
                 $temp_page = get_page_by_title('Caldera Forms Preview');
                 if (empty($temp_page)) {
                     // create page
                     $post = array('post_content' => '', 'post_name' => 'caldera_forms_preview', 'post_title' => 'Caldera Forms Preview', 'post_status' => 'draft', 'post_type' => 'page', 'ping_status' => 'closed', 'comment_status' => 'closed');
                     $page_id = wp_insert_post($post);
                     wp_redirect(trailingslashit(get_home_url()) . '?page_id=' . $page_id . '&preview=true&cf_preview=' . $_GET['cf_preview']);
                     exit;
                 }
                 if ($temp_page->post_status !== 'draft') {
                     wp_update_post(array('ID' => $temp_page->ID, 'post_status' => 'draft'));
                 }
                 wp_redirect(trailingslashit(get_home_url()) . '?page_id=' . $temp_page->ID . '&preview=true&cf_preview=' . $_GET['cf_preview']);
                 exit;
             }
             $post->post_title = $form['name'];
             $post->post_content = '[caldera_form id="' . $_GET['cf_preview'] . '"]';
         }
     }
     // catch a transient process
     if (!empty($_GET['cf_tp'])) {
         // process a transient stored entry
         $data = get_transient($_GET['cf_tp']);
         if (!empty($data) && $data['transient'] === $_GET['cf_tp'] && isset($data['data'])) {
             // create post values
             $_POST = array_merge($_POST, $data['data']);
             // set transient id
             $_POST['_cf_frm_tr'] = $data['transient'];
         }
     }
     // hook into submision
     if (isset($_POST['_cf_verify']) && isset($_POST['_cf_frm_id'])) {
         if (wp_verify_nonce($_POST['_cf_verify'], 'caldera_forms_front')) {
             self::process_submission();
             exit;
         }
         exit;
         /// end form and redirect to submit page or result page.
     }
     /* just pull them in!
     		if(empty($post)){
     			if(isset($wp_query->queried_object)){
     				$post = $wp_query->queried_object;
     			}
     		}
     		if(empty($post)){
     			//cant find form;
     			return;
     		}*/
     // get fields
     $field_types = self::get_field_types();
     foreach ($field_types as $field_type) {
         //enqueue styles
         if (!empty($field_type['styles'])) {
             foreach ($field_type['styles'] as $style) {
                 if (false !== strpos($style, '//')) {
                     wp_enqueue_style('cf-' . sanitize_key(basename($style)), $style, array(), self::VERSION);
                 } else {
                     wp_enqueue_style($style);
                 }
             }
         }
         //enqueue scripts
         if (!empty($field_type['scripts'])) {
             // check for jquery deps
             $depts[] = 'jquery';
             foreach ($field_type['scripts'] as $script) {
                 if (false !== strpos($script, '//')) {
                     wp_enqueue_script('cf-' . sanitize_key(basename($script)), $script, $depts, self::VERSION);
                 } else {
                     wp_enqueue_script($script);
                 }
             }
         }
     }
     // field styles
     wp_enqueue_style('cf-frontend-field-styles', CFCORE_URL . 'assets/css/fields.min.css', array(), self::VERSION);
     $style_includes = get_option('_caldera_forms_styleincludes');
     $style_includes = apply_filters('caldera_forms_get_style_includes', $style_includes);
     if (!empty($style_includes['grid'])) {
         wp_enqueue_style('cf-grid-styles', CFCORE_URL . 'assets/css/caldera-grid.css', array(), self::VERSION);
     }
     if (!empty($style_includes['form'])) {
         wp_enqueue_style('cf-form-styles', CFCORE_URL . 'assets/css/caldera-form.css', array(), self::VERSION);
     }
     if (!empty($style_includes['alert'])) {
         wp_enqueue_style('cf-alert-styles', CFCORE_URL . 'assets/css/caldera-alert.css', array(), self::VERSION);
     }
     //	}
     //}
     // not a post-
     if (!isset($post->post_content)) {
         return;
     }
     $codes = get_shortcode_regex();
     preg_match_all('/' . $codes . '/s', $post->post_content, $found);
     if (!empty($found[0][0])) {
         foreach ($found[2] as $index => $code) {
             if ('caldera_form' === $code) {
                 if (!empty($found[3][$index])) {
                     $atts = shortcode_parse_atts($found[3][$index]);
                     if (isset($atts['id'])) {
                         // has form get  stuff for it
                         $form = self::get_form($atts['id']);
                         if (!empty($form)) {
                             // get list of used fields
                             if (empty($form['fields'])) {
                                 /// no filds - next form
                             }
                             // has a form - get field type
                             if (!isset($field_types)) {
                                 $field_types = self::get_field_types();
                             }
                             if (!empty($form['fields'])) {
                                 foreach ($form['fields'] as $field) {
                                     //enqueue styles
                                     if (!empty($field_types[$field['type']]['styles'])) {
                                         foreach ($field_types[$field['type']]['styles'] as $style) {
                                             if (filter_var($style, FILTER_VALIDATE_URL)) {
                                                 wp_enqueue_style('cf-' . sanitize_key(basename($style)), $style, array(), self::VERSION);
                                             } else {
                                                 wp_enqueue_style($style);
                                             }
                                         }
                                     }
                                     //enqueue scripts
                                     if (!empty($field_types[$field['type']]['scripts'])) {
                                         // check for jquery deps
                                         $depts[] = 'jquery';
                                         foreach ($field_types[$field['type']]['scripts'] as $script) {
                                             if (filter_var($script, FILTER_VALIDATE_URL)) {
                                                 wp_enqueue_script('cf-' . sanitize_key(basename($script)), $script, $depts, self::VERSION);
                                             } else {
                                                 wp_enqueue_script($script);
                                             }
                                         }
                                     }
                                 }
                             }
                             // if depts been set- scripts are used -
                             //wp_enqueue_script( 'cf-frontend-script-init', CFCORE_URL . 'assets/js/frontend-script-init.min.js', array('jquery'), self::VERSION, true);
                             if (isset($form['settings']['styles']['use_grid'])) {
                                 if ($form['settings']['styles']['use_grid'] === 'yes') {
                                     wp_enqueue_style('cf-grid-styles', CFCORE_URL . 'assets/css/caldera-grid.css', array(), self::VERSION);
                                 }
                             }
                             if (isset($form['settings']['styles']['use_form'])) {
                                 if ($form['settings']['styles']['use_form'] === 'yes') {
                                     wp_enqueue_style('cf-form-styles', CFCORE_URL . 'assets/css/caldera-form.css', array(), self::VERSION);
                                 }
                             }
                             if (isset($form['settings']['styles']['use_alerts'])) {
                                 if ($form['settings']['styles']['use_alerts'] === 'yes') {
                                     wp_enqueue_style('cf-alert-styles', CFCORE_URL . 'assets/css/caldera-alert.css', array(), self::VERSION);
                                 }
                             }
                         }
                     }
                 }
             }
             if ($code == 'caldera_form_modal') {
                 //dump($code);
                 wp_enqueue_style('cf-modal-styles', CFCORE_URL . 'assets/css/modals.css', array(), self::VERSION);
                 //caldera_form_modal
             }
         }
     }
 }
예제 #6
0
파일: core.php 프로젝트: Acens/jao2015
 /**
  * Makes Caldera Forms go in front-end!
  */
 public static function cf_init_system()
 {
     global $post, $front_templates, $wp_query, $process_id, $form;
     // check for API
     if (!empty($wp_query->query_vars['cf_api'])) {
         // check if form exists
         $form = self::get_form($wp_query->query_vars['cf_api']);
         if (!empty($form['ID'])) {
             if ($form['ID'] === $wp_query->query_vars['cf_api']) {
                 // got it!
                 // need entry?
                 if (!empty($wp_query->query_vars['cf_entry'])) {
                     $entry = Caldera_Forms::get_entry($wp_query->query_vars['cf_entry'], $form);
                     wp_send_json($entry);
                 }
                 // is a post?
                 if ($_SERVER['REQUEST_METHOD'] === 'POST') {
                     $_POST['_wp_http_referer_true'] = 'api';
                     $_POST['_cf_frm_id'] = $_POST['cfajax'] = $wp_query->query_vars['cf_api'];
                     $submission = Caldera_Forms::process_submission();
                 }
                 wp_send_json($wp_query);
                 die;
             }
         }
     }
     // catch a transient process
     if (!empty($_GET['cf_tp'])) {
         // process a transient stored entry
         $data = get_transient($_GET['cf_tp']);
         if (!empty($data) && $data['transient'] === $_GET['cf_tp'] && isset($data['data'])) {
             // create post values
             $_POST = array_merge($_POST, $data['data']);
             // set transient id
             $_POST['_cf_frm_tr'] = $data['transient'];
         }
     }
     // hook into submission
     if (isset($_POST['_cf_verify']) && isset($_POST['_cf_frm_id'])) {
         if (wp_verify_nonce($_POST['_cf_verify'], 'caldera_forms_front')) {
             self::process_submission();
             exit;
         }
         exit;
         /// end form and redirect to submit page or result page.
     }
     /* just pull them in!
     		if(empty($post)){
     			if(isset($wp_query->queried_object)){
     				$post = $wp_query->queried_object;
     			}
     		}
     		if(empty($post)){
     			//cant find form;
     			return;
     		}*/
 }