function prepare_items() { global $wpdb, $per_page, $frm_settings; $paged = $this->get_pagenum(); $default_orderby = 'name'; $default_order = 'ASC'; $orderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : $default_orderby; $order = isset($_REQUEST['order']) ? $_REQUEST['order'] : $default_order; $page = $this->get_pagenum(); $default_count = empty($this->page_name) ? 20 : 10; $per_page = $this->get_items_per_page('formidable_page_formidable' . str_replace('-', '_', $this->page_name) . '_per_page', $default_count); $start = isset($_REQUEST['start']) ? $_REQUEST['start'] : ($page - 1) * $per_page; $s = isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : ''; $fid = isset($_REQUEST['fid']) ? $_REQUEST['fid'] : ''; if ($s != '') { preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches); $search_terms = array_map('trim', $matches[0]); } $s_query = " (status is NULL OR status = '' OR status = 'published') AND default_template=0 AND is_template = " . (int) $this->params['template']; if ($s != '') { foreach ((array) $search_terms as $term) { if (!empty($s_query)) { $s_query .= " AND"; } $term = FrmAppHelper::esc_like($term); $s_query .= $wpdb->prepare(" (name like %s OR description like %s OR created_at like %s)", '%' . $term . '%', '%' . $term . '%', '%' . $term . '%'); unset($term); } } $frm_form = new FrmForm(); $this->items = $frm_form->getAll($s_query, " ORDER BY {$orderby} {$order}", " LIMIT {$start}, {$per_page}", true, false); $total_items = FrmAppHelper::getRecordCount($s_query, $this->table_name); $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page)); }
public static function form($errors = array(), $message = '') { $where = array('parent_form_id' => array(null, 0), 'status' => array(null, '', 'published')); $forms = FrmForm::getAll($where, 'name'); $export_types = apply_filters('frm_xml_export_types', array('forms' => __('Forms', 'formidable'), 'items' => __('Entries', 'formidable'))); $export_format = apply_filters('frm_export_formats', array('xml' => array('name' => 'XML', 'support' => 'forms', 'count' => 'multiple'), 'csv' => array('name' => 'CSV', 'support' => 'items', 'count' => 'single'))); include FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php'; }
public static function form($errors = array(), $message = '') { $forms = FrmForm::getAll(array('status' => array(null, '', 'published')), 'name'); $export_types = apply_filters('frm_xml_export_types', array('forms' => __('Forms', 'formidable'))); $export_format = apply_filters('frm_export_formats', array('xml' => array('name' => 'XML', 'support' => 'forms', 'count' => 'multiple'))); if (FrmAppHelper::pro_is_installed()) { $frmpro_settings = new FrmProSettings(); $csv_format = $frmpro_settings->csv_format; } else { $csv_format = 'UTF-8'; } include FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php'; }
public static function form($errors = array(), $message = '') { //wp_enqueue_script('jquery-chosen'); //wp_enqueue_style('formidable'); $frm_form = new FrmForm(); $forms = $frm_form->getAll("status is NULL OR status = '' OR status = 'published'", ' ORDER BY name'); unset($frm_form); $export_types = apply_filters('frm_xml_export_types', array('forms' => __('Forms', 'formidable'))); $export_format = apply_filters('frm_export_formats', array('xml' => array('name' => 'XML', 'support' => 'forms', 'count' => 'multiple'))); global $frmpro_settings; $csv_format = $frmpro_settings ? $frmpro_settings->csv_format : 'UTF-8'; include FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php'; }
/** * @covers FrmForm::destroy */ function test_destroy() { $forms = FrmForm::getAll(); $this->assertNotEmpty(count($forms)); foreach ($forms as $form) { if ($form->is_template) { continue; } $id = FrmForm::destroy($form->id); $form_exists = FrmForm::getOne($form->id); $this->assertEmpty($form_exists, 'Failed to delete form ' . $form->form_key); $subforms_exist = FrmForm::getAll(array('parent_form_id' => $form->id)); $this->assertEmpty($subforms_exist, 'Failed to delete child forms for parent form ' . $form->form_key); } }
public function prepare_items() { global $wpdb, $per_page, $mode; $mode = empty($_REQUEST['mode']) ? 'list' : $_REQUEST['mode']; $default_orderby = 'name'; $default_order = 'ASC'; $orderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : $default_orderby; $order = isset($_REQUEST['order']) ? $_REQUEST['order'] : $default_order; $page = $this->get_pagenum(); $per_page = $this->get_items_per_page('formidable_page_formidable_per_page'); $start = isset($_REQUEST['start']) ? $_REQUEST['start'] : ($page - 1) * $per_page; $s_query = array(); $s_query[] = array('or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 1); switch ($this->status) { case 'template': $s_query['is_template'] = 1; $s_query['status !'] = 'trash'; break; case 'draft': $s_query['is_template'] = 0; $s_query['status'] = 'draft'; break; case 'trash': $s_query['status'] = 'trash'; break; default: $s_query['is_template'] = 0; $s_query['status !'] = 'trash'; break; } $s = isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : ''; if ($s != '') { preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches); $search_terms = array_map('trim', $matches[0]); foreach ((array) $search_terms as $term) { $s_query[] = array('or' => true, 'name LIKE' => $term, 'description LIKE' => $term, 'created_at LIKE' => $term); unset($term); } } $this->items = FrmForm::getAll($s_query, $orderby . ' ' . $order, $start . ',' . $per_page); $total_items = FrmDb::get_count('frm_forms', $s_query); $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page)); }
private static function popup_opts_frm_graph(array &$opts, $shortcode) { $form_list = FrmForm::getAll(array('status' => 'published', 'is_template' => 0), 'name'); ?> <h4 class="frm_left_label"><?php _e('Select a field:', 'formidable'); ?> </h4> <select class="frm_get_field_selection" id="frm_form_frmsc_<?php echo esc_attr($shortcode); ?> _id"> <option value="">— <?php _e('Select Form', 'formidable'); ?> —</option> <?php foreach ($form_list as $form_opts) { ?> <option value="<?php echo esc_attr($form_opts->id); ?> "><?php echo '' == $form_opts->name ? __('(no title)', 'formidable') : esc_html(FrmAppHelper::truncate($form_opts->name, 30)); ?> </option> <?php } ?> </select> <span id="frm_form_frmsc_<?php echo esc_attr($shortcode); ?> _id_fields"> </span> <div class="frm_box_line"></div> <?php $opts = array('type' => array('val' => 'default', 'label' => __('Graph Type', 'formidable'), 'type' => 'select', 'opts' => array('default' => __('Default', 'formidable'), 'bar' => __('Bar', 'formidable'), 'column' => __('Column', 'formidable'), 'pie' => __('Pie', 'formidable'), 'line' => __('Line', 'formidable'), 'area' => __('Area', 'formidable'), 'SteppedArea' => __('Stepped Area', 'formidable'), 'geo' => __('Geolocation Map', 'formidable'))), 'data_type' => array('val' => 'count', 'label' => __('Data Type', 'formidable'), 'type' => 'select', 'opts' => array('count' => __('The number of entries', 'formidable'), 'total' => __('Add the field values together', 'formidable'), 'average' => __('Average the totaled field values', 'formidable'))), 'height' => array('val' => '', 'label' => __('Height', 'formidable'), 'type' => 'text'), 'width' => array('val' => '', 'label' => __('Width', 'formidable'), 'type' => 'text'), 'bg_color' => array('val' => '', 'label' => __('Background color', 'formidable'), 'type' => 'text'), 'truncate_label' => array('val' => '', 'label' => __('Truncate graph labels', 'formidable'), 'type' => 'text'), 'truncate' => array('val' => '', 'label' => __('Truncate title', 'formidable'), 'type' => 'text'), 'title' => array('val' => '', 'label' => __('Graph title', 'formidable'), 'type' => 'text'), 'title_size' => array('val' => '', 'label' => __('Title font size', 'formidable'), 'type' => 'text'), 'title_font' => array('val' => '', 'label' => __('Title font name', 'formidable'), 'type' => 'text'), 'is3d' => array('val' => 1, 'label' => __('Turn your pie graph three-dimensional', 'formidable'), 'show' => array('type' => 'pie')), 'include_zero' => array('val' => 1, 'label' => __('When using dates for the x_axis parameter, you can also fill in dates with a zero value. This will also apply to dropdown, radio, and checkbox fields with no x_axis defined.', 'formidable')), 'show_key' => array('val' => 1, 'label' => __('Include the key with the graph', 'formidable'))); /* 'ids' => false, 'colors' => '', 'grid_color' => '#CCC', 'response_count' => 10, 'user_id' => false, 'entry_id' => false, 'x_axis' => false, 'limit' => '', 'x_start' => '', 'x_end' => '', 'min' => '', 'max' => '', 'y_title' => '', 'x_title' => '', 'field' => false, 'tooltip_label' => '', 'start_date' => '', 'end_date' => '', 'group_by' => '', 'x_order' => '1', any field id in this form => value */ }
function form() { $forms = FrmForm::getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name'); include_once FRMPRO_VIEWS_PATH . '/shared/import_form.php'; }
public static function import_xml_forms($forms, $imported) { // Keep track of repeating sections and child forms that are imported $repeat_fields = $child_forms_missing_parent = array(); foreach ($forms as $item) { $form = array('id' => (int) $item->id, 'form_key' => (string) $item->form_key, 'name' => (string) $item->name, 'description' => (string) $item->description, 'options' => (string) $item->options, 'logged_in' => (int) $item->logged_in, 'is_template' => (int) $item->is_template, 'default_template' => (int) $item->default_template, 'editable' => (int) $item->editable, 'status' => (string) $item->status, 'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0, 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at))); $form['options'] = FrmAppHelper::maybe_json_decode($form['options']); // if template, allow to edit if form keys match, otherwise, creation date must also match $edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']); if (!$form['is_template']) { $edit_query['created_at'] = $form['created_at']; } $old_parent_form_id = self::maybe_replace_parent_form_id($imported['forms'], $form['parent_form_id']); $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form); $this_form = FrmForm::getAll($edit_query, '', 1); unset($edit_query); if (!empty($this_form)) { $old_id = $form_id = $this_form->id; FrmForm::update($form_id, $form); $imported['updated']['forms']++; // Keep track of whether this specific form was updated or not $imported['form_status'][$form_id] = 'updated'; $form_fields = FrmField::get_all_for_form($form_id); $old_fields = array(); foreach ($form_fields as $f) { $old_fields[$f->id] = $f; $old_fields[$f->field_key] = $f->id; unset($f); } $form_fields = $old_fields; unset($old_fields); } else { $old_id = false; //form does not exist, so create it $form_id = FrmForm::create($form); if ($form_id) { $imported['imported']['forms']++; // Keep track of whether this specific form was updated or not $imported['form_status'][$form_id] = 'imported'; self::track_child_forms_missing_parent((int) $form_id, $old_parent_form_id, $child_forms_missing_parent); } } self::import_xml_fields($item->field, $form_id, $this_form, $form_fields, $imported, $repeat_fields); // Delete any fields attached to this form that were not included in the template if (isset($form_fields) && !empty($form_fields)) { foreach ($form_fields as $field) { if (is_object($field)) { FrmField::destroy($field->id); } unset($field); } unset($form_fields); } // Update field ids/keys to new ones do_action('frm_after_duplicate_form', $form_id, $form, array('old_id' => $old_id)); $imported['forms'][(int) $item->id] = $form_id; // Send pre 2.0 form options through function that creates actions self::migrate_form_settings_to_actions($form['options'], $form_id, $imported, $switch = true); unset($form, $item); } self::update_repeat_field_options($repeat_fields, $imported['forms']); self::update_child_form_parents($child_forms_missing_parent, $imported['forms']); return $imported; }
public static function get_params($form = null) { global $frm_vars; $frm_form = new FrmForm(); if (!$form) { $form = $frm_form->getAll(array(), 'name', 1); } else { if (!is_object($form)) { $form = $frm_form->getOne($form); } } if (isset($frm_vars['form_params']) && is_array($frm_vars['form_params']) && isset($frm_vars['form_params'][$form->id])) { return $frm_vars['form_params'][$form->id]; } $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action'; $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form); $default_values = array('id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id, 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action); $values['posted_form_id'] = FrmAppHelper::get_param('form_id'); if (!is_numeric($values['posted_form_id'])) { $values['posted_form_id'] = FrmAppHelper::get_param('form'); } if ($form->id == $values['posted_form_id']) { //if there are two forms on the same page, make sure not to submit both foreach ($default_values as $var => $default) { if ($var == 'action') { $values[$var] = FrmAppHelper::get_param($action_var, $default); } else { $values[$var] = FrmAppHelper::get_param($var, $default); } unset($var); unset($default); } } else { foreach ($default_values as $var => $default) { $values[$var] = $default; unset($var); unset($default); } } if (in_array($values['action'], array('create', 'update')) and (!isset($_POST) or !isset($_POST['action']) and !isset($_POST['frm_action']))) { $values['action'] = 'new'; } return $values; }
function upgrade() { global $wpdb, $frmdb; $db_version = FrmAppHelper::$pro_db_version; // this is the version of the database we're moving to $old_db_version = get_option('frmpro_db_version'); if ($db_version == $old_db_version) { return; } // update rewrite rules for views flush_rewrite_rules(); if ($old_db_version) { if ($db_version >= 3 && $old_db_version < 3) { //migrate hidden field data into the parent field global $frm_field; $wpdb->update($frmdb->fields, array('type' => 'scale'), array('type' => '10radio')); $fields = $frm_field->getAll(); foreach ($fields as $field) { $field->field_options = maybe_unserialize($field->field_options); if (isset($field->field_options['hide_field']) and is_numeric($field->field_options['hide_field']) and (isset($field->field_options['hide_opt']) and !empty($field->field_options['hide_opt']) or isset($field->field_options['form_select']) and !empty($field->field_options['form_select']))) { global $frm_field; //save hidden fields to parent field $parent_field = $frm_field->getOne($field->field_options['hide_field']); if ($parent_field) { $parent_options = maybe_unserialize($parent_field->field_options); if (!isset($parent_options['dependent_fields'])) { $parent_options['dependent_fields'] = array(); } else { foreach ($parent_options['dependent_fields'] as $child_id => $child_opt) { if (empty($child_opt) or $child_opt == '') { unset($parent_options['dependent_fields'][$child_id]); } else { if ($child_id != $field->id) { //check to make sure this field is still dependent $check_field = $frm_field->getOne($child_id); $check_options = maybe_unserialize($check_field->field_options); if (!is_numeric($check_options['hide_field']) or $check_options['hide_field'] != $parent_field->id or empty($check_options['hide_opt']) and empty($check_options['form_select'])) { unset($parent_options['dependent_fields'][$child_id]); } } } } } $dep_fields = array(); if ($field->type == 'data' and isset($field->field_options['form_select']) and is_numeric($field_options['form_select'])) { $dep_fields[] = $field->field_options['form_select']; $dep_fields[] = $field->field_options['data_type']; } else { if (isset($field->field_options['hide_opt']) and !empty($field->field_options['hide_opt'])) { $dep_fields[] = $field->field_options['hide_opt']; } } if (!empty($dep_fields)) { $parent_options['dependent_fields'][$field->id] = $dep_fields; } $frm_field->update($parent_field->id, array('field_options' => $parent_options)); } } } } if ($db_version >= 16 and $old_db_version < 16) { //migrate table into wp_posts $display_posts = array(); if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}frm_display'")) { //only migrate if table exists $dis = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}frm_display"); } else { $dis = array(); } foreach ($dis as $d) { $post = array('post_title' => $d->name, 'post_content' => $d->content, 'post_date' => $d->created_at, 'post_excerpt' => $d->description, 'post_name' => $d->display_key, 'post_status' => 'publish', 'post_type' => 'frm_display'); $post_ID = wp_insert_post($post); unset($post); update_post_meta($post_ID, 'frm_old_id', $d->id); if (!isset($d->show_count) or empty($d->show_count)) { $d->show_count = 'none'; } foreach (array('dyncontent', 'param', 'form_id', 'post_id', 'entry_id', 'param', 'type', 'show_count', 'insert_loc') as $f) { update_post_meta($post_ID, 'frm_' . $f, $d->{$f}); unset($f); } $d->options = maybe_unserialize($d->options); update_post_meta($post_ID, 'frm_options', $d->options); if (isset($d->options['insert_loc']) and $d->options['insert_loc'] != 'none' and is_numeric($d->options['post_id']) and !isset($display_posts[$d->options['post_id']])) { $display_posts[$d->options['post_id']] = $post_ID; } unset($d); unset($post_ID); } unset($dis); global $frmdb, $frmpro_display; //get all post_ids from frm_entries $entry_posts = $wpdb->get_results("SELECT id, post_id, form_id FROM {$frmdb->entries} WHERE post_id > 0"); $form_display = array(); foreach ($entry_posts as $ep) { if (isset($form_display[$ep->form_id])) { $display_posts[$ep->post_id] = $form_display[$ep->form_id]; } else { $d = $frmpro_display->get_auto_custom_display(array('post_id' => $ep->post_id, 'form_id' => $ep->form_id, 'entry_id' => $ep->id)); $display_posts[$ep->post_id] = $form_display[$ep->form_id] = $d ? $d->ID : 0; unset($d); } unset($ep); } unset($form_display); foreach ($display_posts as $post_ID => $d) { if ($d) { update_post_meta($post_ID, 'frm_display_id', $d); } unset($d); unset($post_ID); } unset($display_posts); } if ($db_version >= 17 && $old_db_version < 17) { $frm_form = new FrmForm(); //migrate "allow one per field" into "unique" $form = $frm_form->getAll(); $field_ids = array(); foreach ($form as $f) { if (isset($f->options['single_entry']) and $f->options['single_entry'] and is_numeric($f->options['single_entry_type'])) { $f->options['single_entry'] = 0; $wpdb->update($wpdb->prefix . 'frm_forms', array('options' => serialize($f->options)), array('id' => $f->id)); $field_ids[] = $f->options['single_entry_type']; } unset($f); } if (!empty($field_ids)) { $fields = $wpdb->get_results("SELECT id, field_options FROM {$frmdb->fields} WHERE id in (" . implode(',', $field_ids) . ")"); foreach ($fields as $f) { $opts = maybe_unserialize($f->field_options); $opts['unique'] = 1; $wpdb->update($frmdb->fields, array('field_options' => serialize($opts)), array('id' => $f->id)); unset($f); } } } if ($db_version >= 25 && $old_db_version < 25) { // let's remove the old displays now $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}frm_display"); } } /**** ADD DEFAULT TEMPLATES ****/ if (class_exists('FrmXMLController')) { FrmXMLController::add_default_templates(); } update_option('frmpro_db_version', $db_version); global $frmpro_settings; $frmpro_settings->store(); //update the styling settings }
public static function add_default_templates($path, $default = true, $template = true) { _deprecated_function(__FUNCTION__, '1.07.05', 'FrmXMLController::add_default_templates()'); global $frm_field; $path = untrailingslashit(trim($path)); $templates = glob($path . "/*.php"); $frm_form = new FrmForm(); for ($i = count($templates) - 1; $i >= 0; $i--) { $filename = str_replace('.php', '', str_replace($path . '/', '', $templates[$i])); $template_query = array('form_key' => $filename); if ($template) { $template_query['is_template'] = 1; } if ($default) { $template_query['default_template'] = 1; } $form = $frm_form->getAll($template_query, '', 1); $values = FrmFormsHelper::setup_new_vars(); $values['form_key'] = $filename; $values['is_template'] = $template; $values['status'] = 'published'; if ($default) { $values['default_template'] = 1; } include $templates[$i]; //get updated form if (isset($form) && $form) { $form = $frm_form->getOne($form->id); } else { $form = $frm_form->getAll($template_query, '', 1); } if ($form) { do_action('frm_after_duplicate_form', $form->id, (array) $form); } } }
public static function form_switcher() { $where = apply_filters('frm_forms_dropdown', "is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ''); $frm_form = new FrmForm(); $forms = $frm_form->getAll($where, ' ORDER BY name'); unset($frm_form); $args = array('id' => 0, 'form' => 0); if (isset($_GET['id']) and !isset($_GET['form'])) { unset($args['form']); } else { if (isset($_GET['form']) and !isset($_GET['id'])) { unset($args['id']); } } if (isset($_GET['page']) and $_GET['page'] == 'formidable-entries' and isset($_GET['frm_action']) and in_array($_GET['frm_action'], array('edit', 'show', 'destroy_all'))) { $args['frm_action'] = 'list'; $args['form'] = 0; } else { if (isset($_GET['page']) and $_GET['page'] == 'formidable' and isset($_GET['frm_action']) and $_GET['frm_action'] == 'new') { $args['frm_action'] = 'edit'; } else { if (isset($_GET['post'])) { $args['form'] = 0; $base = admin_url('edit.php?post_type=frm_display'); } } } ?> <li class="dropdown last" id="frm_bs_dropdown"> <a href="#" id="frm-navbarDrop" class="frm-dropdown-toggle" data-toggle="dropdown"><?php _e('Switch Form', 'formidable'); ?> <b class="caret"></b></a> <ul class="frm-dropdown-menu" role="menu" aria-labelledby="frm-navbarDrop"> <?php foreach ($forms as $form) { if (isset($args['id'])) { $args['id'] = $form->id; } if (isset($args['form'])) { $args['form'] = $form->id; } ?> <li><a href="<?php echo isset($base) ? add_query_arg($args, $base) : add_query_arg($args); ?> " tabindex="-1"><?php echo empty($form->name) ? __('(no title)') : FrmAppHelper::truncate($form->name, 33); ?> </a></li> <?php unset($form); } ?> </ul> </li> <?php }
echo $field['id']; ?> ]" id="dyn_default_value_<?php echo $field['id']; ?> " value="<?php echo esc_attr($field['dyn_default_value']); ?> " class="dyn_default_value frm_long_input" /></td> </tr> <?php } if ($field['type'] == 'data') { global $frm_field; $frm_form = new FrmForm(); $form_list = $frm_form->getAll(array('status' => 'published', 'is_template' => 0), 'name'); $selected_field = ''; $current_field_id = $field['id']; if (isset($field['form_select']) && is_numeric($field['form_select'])) { $selected_field = $frm_field->getOne($field['form_select']); if ($selected_field) { $fields = $frm_field->getAll(array('fi.form_id' => $selected_field->form_id)); } else { $selected_field = ''; } } else { if (isset($field['form_select'])) { $selected_field = $field['form_select']; } } require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/dynamic-options.php';
function test_imported_forms() { $imported_forms = FrmForm::getAll(); self::_check_parent_form_id($imported_forms); }
public static function import_xml_forms($forms, $imported) { $frm_form = new FrmForm(); $frm_field = new FrmField(); foreach ($forms as $item) { $form = array('id' => (int) $item->id, 'form_key' => (string) $item->form_key, 'name' => (string) $item->name, 'description' => (string) $item->description, 'options' => (string) $item->options, 'logged_in' => (int) $item->logged_in, 'is_template' => (int) $item->is_template, 'default_template' => (int) $item->default_template, 'editable' => (int) $item->editable, 'status' => (string) $item->status, 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at))); $form['options'] = FrmAppHelper::maybe_json_decode($form['options']); // if template, allow to edit if form keys match, otherwise, creation date must also match $edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']); if (!$form['is_template']) { $edit_query['created_at'] = $form['created_at']; } $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form); $this_form = $frm_form->getAll($edit_query, '', 1); unset($edit_query); if (!empty($this_form)) { $form_id = $this_form->id; $frm_form->update($form_id, $form); $imported['updated']['forms']++; $form_fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order'); $old_fields = array(); foreach ($form_fields as $f) { $old_fields[$f->id] = $f; $old_fields[$f->field_key] = $f->id; unset($f); } $form_fields = $old_fields; unset($old_fields); } else { //form does not exist, so create it if ($form_id = $frm_form->create($form)) { $imported['imported']['forms']++; } } foreach ($item->field as $field) { $f = array('id' => (int) $field->id, 'field_key' => (string) $field->field_key, 'name' => (string) $field->name, 'description' => (string) $field->description, 'type' => (string) $field->type, 'default_value' => FrmAppHelper::maybe_json_decode((string) $field->default_value), 'field_order' => (int) $field->field_order, 'form_id' => (int) $form_id, 'required' => (int) $field->required, 'options' => FrmAppHelper::maybe_json_decode((string) $field->options), 'field_options' => FrmAppHelper::maybe_json_decode((string) $field->field_options)); if (is_array($f['default_value']) && in_array($f['type'], array('text', 'email', 'url', 'textarea', 'number', 'phone', 'date', 'time', 'image', 'hidden', 'password', 'tag'))) { if (count($f['default_value']) === 1) { $f['default_value'] = '[' . reset($f['default_value']) . ']'; } else { $f['default_value'] = reset($f['default_value']); } } $f = apply_filters('frm_duplicated_field', $f); if ($this_form) { // check for field to edit by field id if (isset($form_fields[$f['id']])) { $frm_field->update($f['id'], $f); $imported['updated']['fields']++; unset($form_fields[$f['id']]); //unset old field key if (isset($form_fields[$f['field_key']])) { unset($form_fields[$f['field_key']]); } } else { if (isset($form_fields[$f['field_key']])) { // check for field to edit by field key unset($f['id']); $frm_field->update($form_fields[$f['field_key']], $f); $imported['updated']['fields']++; unset($form_fields[$form_fields[$f['field_key']]]); //unset old field id unset($form_fields[$f['field_key']]); //unset old field key } else { if ($frm_field->create($f)) { // if no matching field id or key in this form, create the field $imported['imported']['fields']++; } } } } else { if ($frm_field->create($f)) { $imported['imported']['fields']++; } } unset($field); } // Delete any fields attached to this form that were not included in the template if (isset($form_fields) && !empty($form_fields)) { foreach ($form_fields as $field) { if (is_object($field)) { $frm_field->destroy($field->id); } unset($field); } unset($form_fields); } // Update field ids/keys to new ones do_action('frm_after_duplicate_form', $form_id, $form); $imported['forms'][(int) $item->id] = $form_id; unset($form); unset($item); } unset($frm_form); unset($frm_field); return $imported; }
/** * Migrate "allow one per field" into "unique" */ private static function migrate_to_17() { global $wpdb; $form = FrmForm::getAll(); $field_ids = array(); foreach ($form as $f) { if (isset($f->options['single_entry']) && $f->options['single_entry'] && is_numeric($f->options['single_entry_type'])) { $f->options['single_entry'] = 0; $wpdb->update($wpdb->prefix . 'frm_forms', array('options' => serialize($f->options)), array('id' => $f->id)); $field_ids[] = $f->options['single_entry_type']; } unset($f); } if (!empty($field_ids)) { $fields = FrmDb::get_results('frm_fields', array('id' => $field_ids), 'id, field_options'); foreach ($fields as $f) { $opts = maybe_unserialize($f->field_options); $opts['unique'] = 1; $wpdb->update($wpdb->prefix . 'frm_fields', array('field_options' => serialize($opts)), array('id' => $f->id)); unset($f); } } }
public static function get_current_form_id() { global $frm_vars; $form_id = 0; if (isset($frm_vars['current_form']) and $frm_vars['current_form']) { $form_id = $frm_vars['current_form']->id; } if (!$form_id) { $form_id = FrmAppHelper::get_param('form', false); } if (!$form_id) { $frm_form = new FrmForm(); $frm_vars['current_form'] = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name', ' LIMIT 1'); $form_id = (isset($frm_vars['current_form']) and $frm_vars['current_form']) ? $frm_vars['current_form']->id : 0; } return $form_id; }
public static function get_params($form = null) { if (!$form) { $frm_form = new FrmForm(); $form = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name', ' LIMIT 1'); } $values = array(); foreach (array('id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form ? $form->id : 0, 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'fid' => '', 'keep_post' => '') as $var => $default) { $values[$var] = FrmAppHelper::get_param($var, $default); } return $values; }
public static function import_xml_forms($forms, $imported) { // Keep track of repeating sections that are created $repeat_fields = array(); foreach ($forms as $item) { $form = array('id' => (int) $item->id, 'form_key' => (string) $item->form_key, 'name' => (string) $item->name, 'description' => (string) $item->description, 'options' => (string) $item->options, 'logged_in' => (int) $item->logged_in, 'is_template' => (int) $item->is_template, 'default_template' => (int) $item->default_template, 'editable' => (int) $item->editable, 'status' => (string) $item->status, 'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0, 'created_at' => date('Y-m-d H:i:s', strtotime((string) $item->created_at))); $form['options'] = FrmAppHelper::maybe_json_decode($form['options']); // if template, allow to edit if form keys match, otherwise, creation date must also match $edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']); if (!$form['is_template']) { $edit_query['created_at'] = $form['created_at']; } if (!empty($form['parent_form_id']) && isset($imported['forms'][$form['parent_form_id']])) { // replace the old parent id with the new one $form['parent_form_id'] = $imported['forms'][$form['parent_form_id']]; } $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form); $this_form = FrmForm::getAll($edit_query, '', 1); unset($edit_query); if (!empty($this_form)) { $old_id = $form_id = $this_form->id; FrmForm::update($form_id, $form); $imported['updated']['forms']++; // Keep track of whether this specific form was updated or not $imported['form_status'][$form_id] = 'updated'; $form_fields = FrmField::get_all_for_form($form_id); $old_fields = array(); foreach ($form_fields as $f) { $old_fields[$f->id] = $f; $old_fields[$f->field_key] = $f->id; unset($f); } $form_fields = $old_fields; unset($old_fields); } else { $old_id = false; //form does not exist, so create it $form_id = FrmForm::create($form); if ($form_id) { $imported['imported']['forms']++; // Keep track of whether this specific form was updated or not $imported['form_status'][$form_id] = 'imported'; } } foreach ($item->field as $field) { $f = array('id' => (int) $field->id, 'field_key' => (string) $field->field_key, 'name' => (string) $field->name, 'description' => (string) $field->description, 'type' => (string) $field->type, 'default_value' => FrmAppHelper::maybe_json_decode((string) $field->default_value), 'field_order' => (int) $field->field_order, 'form_id' => (int) $form_id, 'required' => (int) $field->required, 'options' => FrmAppHelper::maybe_json_decode((string) $field->options), 'field_options' => FrmAppHelper::maybe_json_decode((string) $field->field_options)); if (is_array($f['default_value']) && in_array($f['type'], array('text', 'email', 'url', 'textarea', 'number', 'phone', 'date', 'time', 'hidden', 'password', 'tag', 'image'))) { if (count($f['default_value']) === 1) { $f['default_value'] = '[' . reset($f['default_value']) . ']'; } else { $f['default_value'] = reset($f['default_value']); } } $f = apply_filters('frm_duplicated_field', $f); if (!empty($this_form)) { // check for field to edit by field id if (isset($form_fields[$f['id']])) { FrmField::update($f['id'], $f); $imported['updated']['fields']++; unset($form_fields[$f['id']]); //unset old field key if (isset($form_fields[$f['field_key']])) { unset($form_fields[$f['field_key']]); } } else { if (isset($form_fields[$f['field_key']])) { // check for field to edit by field key unset($f['id']); FrmField::update($form_fields[$f['field_key']], $f); $imported['updated']['fields']++; unset($form_fields[$form_fields[$f['field_key']]]); //unset old field id unset($form_fields[$f['field_key']]); //unset old field key } else { $new_id = FrmField::create($f); if ($new_id == false) { continue; } self::track_repeating_fields($f, $new_id, $repeat_fields); // if no matching field id or key in this form, create the field $imported['imported']['fields']++; } } } else { $new_id = FrmField::create($f); if ($new_id == false) { continue; } self::track_repeating_fields($f, $new_id, $repeat_fields); $imported['imported']['fields']++; } unset($field, $new_id); } // Delete any fields attached to this form that were not included in the template if (isset($form_fields) && !empty($form_fields)) { foreach ($form_fields as $field) { if (is_object($field)) { FrmField::destroy($field->id); } unset($field); } unset($form_fields); } // Update field ids/keys to new ones do_action('frm_after_duplicate_form', $form_id, $form, array('old_id' => $old_id)); $imported['forms'][(int) $item->id] = $form_id; // Send pre 2.0 form options through function that creates actions self::migrate_form_settings_to_actions($form['options'], $form_id, $imported, $switch = true); unset($form, $item); } self::update_repeat_field_options($repeat_fields, $imported['forms']); return $imported; }
private static function maybe_get_form($form) { // if template, allow to edit if form keys match, otherwise, creation date must also match $edit_query = array('form_key' => $form['form_key'], 'is_template' => $form['is_template']); if (!$form['is_template']) { $edit_query['created_at'] = $form['created_at']; } $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form); return FrmForm::getAll($edit_query, '', 1); }
/** * Get all forms running on the site * * @since 1.0.0 * * @param $form_list * * @return mixed */ public function get_forms($form_list) { if (class_exists('Caldera_Forms')) { $forms = \Caldera_Forms::get_forms(); $form_list['caldera'] = array('name' => __('Caldera Forms', 'caldera-forms'), 'forms' => array()); foreach ($forms as $form) { $form_list['caldera']['forms'][$form['ID']] = $form['name']; } } if (class_exists('RGFormsModel')) { $forms = \RGFormsModel::get_forms(null, 'title'); $form_list['gform'] = array('name' => __('Gravity Forms', 'gravityforms'), 'forms' => array()); foreach ($forms as $form) { $form_list['gform']['forms'][$form->id] = $form->title; } } if (class_exists('NF_Forms')) { $nforms = new \NF_Forms(); $nforms = $nforms->get_all(); $form_list['ninja'] = array('name' => __('Ninja Forms', 'ninja-forms'), 'forms' => array()); foreach ($nforms as $form) { $form_list['ninja']['forms'][$form] = Ninja_Forms()->form($form)->get_setting('form_title'); } } if (class_exists('WPCF7_ContactForm')) { $cforms = \WPCF7_ContactForm::find(array('posts_per_page' => -1)); $form_list['cf7'] = array('name' => __('Contact Form 7', 'contact-form-7'), 'forms' => array()); foreach ($cforms as $form) { $form_list['cf7']['forms'][$form->id()] = $form->title(); } } if (class_exists('FrmForm')) { $fforms = \FrmForm::getAll(); $form_list['frmid'] = array('name' => __('Formidable', 'formidable'), 'forms' => array()); foreach ($fforms as $form) { if (!empty($form->is_template)) { continue; } $form_list['frmid']['forms'][$form->id] = $form->name; } } // jetpack if (function_exists('grunion_display_form_view')) { global $wpdb; $shortcodes = $wpdb->get_results("SELECT `post_id` FROM `" . $wpdb->postmeta . "` WHERE `meta_key` = '_g_feedback_shortcode';", ARRAY_A); if (!empty($shortcodes)) { $form_list['jp'] = array('name' => __('Jetpack Contact Form', 'jetpack'), 'forms' => array()); foreach ($shortcodes as $post_id) { $form = get_post($post_id['post_id']); $form_list['jp']['forms'][$post_id['post_id']] = $form->post_title; } } } return $form_list; }
function search_box($text, $input_id) { if (!$this->has_items() and !isset($_REQUEST['s'])) { return; } if ($this->plural == 'entries') { global $frm_field; $frm_form = new FrmForm(); if (isset($this->params['form'])) { $form = $frm_form->getOne($this->params['form']); } else { $form = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name', ' LIMIT 1'); } if ($form) { $field_list = $frm_field->getAll("fi.type not in ('divider','captcha','break','html') and fi.form_id=" . $form->id, 'field_order'); $fid = isset($_REQUEST['fid']) ? esc_attr(stripslashes($_REQUEST['fid'])) : ''; } } $input_id = $input_id . '-search-input'; $search_str = isset($_REQUEST['s']) ? esc_attr(stripslashes($_REQUEST['s'])) : ''; if (!empty($_REQUEST['orderby'])) { echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />'; } if (!empty($_REQUEST['order'])) { echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />'; } ?> <p class="search-box"> <label class="screen-reader-text" for="<?php echo $input_id; ?> "><?php echo $text; ?> :</label> <?php if (isset($field_list) and !empty($field_list)) { ?> <select name="fid"> <option value="">— <?php _e('All Fields', 'formidable'); ?> —</option> <option value="created_at" <?php selected($fid, 'created_at'); ?> ><?php _e('Entry creation date', 'formidable'); ?> </option> <option value="id" <?php selected($fid, 'id'); ?> ><?php _e('Entry ID', 'formidable'); ?> </option> <?php foreach ($field_list as $f) { ?> <option value="<?php echo $f->type == 'user_id' ? 'user_id' : $f->id; ?> " <?php selected($fid, $f->id); ?> ><?php echo FrmAppHelper::truncate($f->name, 30); ?> </option> <?php } ?> </select> <?php } ?> <input type="text" id="<?php echo $input_id; ?> " name="s" value="<?php echo $search_str; ?> " /> <?php submit_button($text, 'button', false, false, array('id' => 'search-submit')); ?> <?php if (!empty($search_str)) { ?> or <a href="<?php echo admin_url('admin.php?page=formidable-entries&frm_action=list&form=' . $form->id); ?> "><?php _e('Reset', 'formidable'); ?> </a> <?php } ?> </p> <?php }
<?php } ?> </select></td> </tr> <tr> <td><input type='checkbox' name='use_formidable_forms'/></td> <td><?php _e('Use Formidable Forms', 'dvinwcql'); ?> - <select name='formidable_form_select' id='formidable_form_select'> <option value=''>Select Form</option> <?php if (class_exists('FrmForm')) { $frm_form = new FrmForm(); $forms = $frm_form->getAll("is_template=0 AND status = 'published'", ' ORDER BY name'); } else { $forms = array(); } foreach ($forms as $form) { ?> <option value='<?php echo $form->id; ?> '><?php echo $form->name; ?> </option> <?php } ?>
public static function get_translatable_items($items, $type, $filter) { // Only return items if string translation is available, and if type is for formidable. if ($type != 'formidable') { return $items; } global $sitepress, $wpdb; $default_lang = $sitepress->get_default_language(); $languages = $sitepress->get_active_languages(); $frm_form = new FrmForm(); if (isset($_GET) && isset($_GET['frm_action']) && $_GET['frm_action'] == 'translate' && isset($_GET['id']) && is_numeric($_GET['id'])) { $forms = $frm_form->getOne($_GET['id']); $forms = array($forms->id => $forms); } else { $forms = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name'); } unset($frm_form); foreach ($forms as $k => $v) { $new_item = new stdClass(); $new_item->external_type = true; $new_item->type = 'formidable'; $new_item->id = $v->id; $new_item->post_type = 'formidable'; $new_item->post_id = 'external_' . $new_item->post_type . '_' . $v->id; $new_item->post_date = $v->created_at; $new_item->post_status = $v->status == 'draft' ? __('Inactive', 'formidable_wpml') : __('Active', 'formidable_wpml'); $new_item->post_title = $v->name; $new_item->is_translation = false; $new_item->string_data = self::_get_form_strings($v->id); // add to the translation table if required $post_trid = $sitepress->get_element_trid($new_item->id, 'post_' . $new_item->post_type); if (!$post_trid) { $sitepress->set_element_language_details($new_item->id, 'post_' . $new_item->post_type, false, $default_lang, null, false); } // register the strings with WPML foreach ($new_item->string_data as $key => $value) { $key = function_exists('mb_substr') ? mb_substr($new_item->id . '_' . $key, 0, 160) : substr($new_item->id . '_' . $key, 0, 160); if (!icl_st_is_registered_string('formidable', $key)) { icl_register_string('formidable', $key, $value); } unset($key); unset($value); } $post_trid = $sitepress->get_element_trid($new_item->id, 'post_' . $new_item->post_type); $post_translations = $sitepress->get_element_translations($post_trid, 'post_' . $new_item->post_type); global $iclTranslationManagement; $md5 = $iclTranslationManagement->post_md5($new_item); foreach ($post_translations as $lang => $translation) { $res = $wpdb->get_row("SELECT status, needs_update, md5 FROM {$wpdb->prefix}icl_translation_status WHERE translation_id={$translation->translation_id}"); if ($res) { if (!$res->needs_update) { // see if the md5 has changed. if ($md5 != $res->md5) { $res->needs_update = 1; $wpdb->update($wpdb->prefix . 'icl_translation_status', array('needs_update' => 1), array('translation_id' => $translation->translation_id)); } } $_suffix = str_replace('-', '_', $lang); $index = 'status_' . $_suffix; $new_item->{$index} = $res->status; $index = 'needs_update_' . $_suffix; $new_item->{$index} = $res->needs_update; } } $items[] = $new_item; } return $items; }