/** * Get Caldera Forms * * Includes backwards compat for pre-Caldera Forms 1.3.4 * * @since 2.0.5 * * @param string $id_name ID or name of form * * @return array|void */ function cf_custom_fields_get_form($id_name) { if (class_exists('Caldera_Forms_Forms')) { $form = Caldera_Forms_Forms::get_form($id_name); } else { $form = Caldera_Forms::get_form($id_name); } if (isset($form['ID']) && !isset($form['id'])) { $form['id'] = $form['ID']; } return $form; }
function cf_conn_form_get_all_fields($connected_form) { $fields = array(); if (isset($connected_form['node'])) { foreach ($connected_form['node'] as $connected_form) { $_form = Caldera_Forms_Forms::get_form($connected_form['form']); $fields = array_merge(Caldera_Forms_Forms::get_fields($_form), $fields); } } return $fields; }
/** * Handler for shortcode * * @since 1.3.1 * * @param array $atts * @param string $content * @param string $shortcode * * @return string|void */ public static function shortcode_handler($atts, $content, $shortcode) { if (!isset($atts['id'])) { return; } if ($shortcode === 'caldera_form_modal') { $atts['modal'] = true; } if (isset($atts['modal']) && $atts['modal']) { $form = Caldera_Forms_Forms::get_form($atts['id']); if (!is_array($form)) { return; } if (empty($content)) { $content = $form['name']; } $tag_atts = sprintf('data-form="%1s"', $form['ID']); if (empty($atts['preview'])) { $tag_atts .= sprintf('data-remodal-target="modal-%1s"', $form['ID']); } if (!empty($atts['width'])) { $tag_atts .= sprintf(' data-width="%1s"', $atts['width']); } if (!empty($atts['height'])) { $tag_atts .= sprintf(' data-height="%1s"', $atts['height']); } $title = __(sprintf('Click to open the form %1s in a modal', $form['name']), 'caldera-forms'); if (!empty($atts['type']) && $atts['type'] == 'button') { $form = sprintf('<button class="caldera-forms-modal" %1s title="%2s">%3s</button>', $tag_atts, $title, $content); } else { $form = sprintf('<a href="#" class="caldera-forms-modal" %1s title="%2s">%3s</a>', $tag_atts, $title, $content); } wp_enqueue_script('cf-dynamic'); } else { $form = self::render_form($atts); } return $form; }
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; } }
<?php global $field_type_list, $field_type_templates; if (!isset($_GET['edit']) || !is_string($_GET['edit'])) { wp_die(esc_html__('Invalid form ID', 'caldera-forms')); } // Load element $element = Caldera_Forms_Forms::get_form($_GET['edit']); if (empty($element) || !is_array($element)) { wp_die(esc_html__('Invalid form', 'caldera-forms')); } /** * Filter which Magic Tags are available in the form editor * * * @since 1.3.2 * * @param array $tags Array of magic registered tags * @param array $form_id for which this applies. */ $magic_tags = apply_filters('caldera_forms_get_magic_tags', array(), $element['ID']); //dump($element); if (empty($element['success'])) { $element['success'] = __('Form has successfully been submitted. Thank you.', 'caldera-forms'); } if (!isset($element['db_support'])) { $element['db_support'] = 1; } /** * Convert existing field conditions if old method used *