function _setup_test_update_values($entry) { $form = FrmForm::getOne($entry->form_id); $this->set_current_user_to_1(); $values = array('form_id' => $entry->form_id, 'frm_hide_fields_' . $entry->form_id => '', 'frm_helers_' . $entry->form_id => '', 'form_key' => $form->form_key, 'item_meta' => $entry->metas, 'frm_submit_entry_' . $entry->form_id => wp_create_nonce('frm_submit_entry_' . $entry->form_id), '_wp_http_referer' => '/features/create-a-post-no-categories/?frm_action=edit&entry=' . $entry->id, 'id' => $entry->id, 'item_key' => $entry->item_key, 'item_name' => $entry->name, 'frm_user_id' => $entry->user_id, 'frm_skip_cookie' => 1); return $values; }
function user_can_edit_check($entry, $form) { global $user_ID; if (!$user_ID) { return false; } if (is_numeric($form)) { $form = FrmForm::getOne($form); } $form->options = maybe_unserialize($form->options); //if editable and user can edit someone elses entry if ($form->editable and isset($form->options['open_editable']) and $form->options['open_editable'] and isset($form->options['open_editable_role']) and FrmAppHelper::user_has_permission($form->options['open_editable_role'])) { return true; } if (is_object($entry)) { if ($entry->user_id == $user_ID) { return true; } else { return false; } } $where = "user_id='{$user_ID}' and fr.id='{$form->id}'"; if ($entry and !empty($entry)) { if (is_numeric($entry)) { $where .= ' and it.id=' . $entry; } else { $where .= " and item_key='" . $entry . "'"; } } return FrmEntry::getAll($where, '', ' LIMIT 1', true); }
public static function show() { FrmAppHelper::permission_check('frm_view_reports'); remove_action('frm_form_action_reports', 'FrmStatisticsController::list_reports'); add_filter('frm_form_stop_action_reports', '__return_true'); global $wpdb; $form = false; if (isset($_REQUEST['form'])) { $form = FrmForm::getOne($_REQUEST['form']); } if (!$form) { require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-statistics/select.php'; return; } $exclude_types = FrmField::no_save_fields(); $exclude_types = array_merge($exclude_types, array('rte', 'textarea', 'file', 'grid', 'signature', 'form', 'table')); $fields = FrmField::getAll(array('fi.form_id' => (int) $form->id, 'fi.type not' => $exclude_types), 'field_order'); $js = ''; $data = array(); $colors = '#21759B,#EF8C08,#C6C6C6'; $data['time'] = self::get_daily_entries($form, array('is3d' => true, 'colors' => $colors, 'bg_color' => 'transparent')); $data['month'] = self::get_daily_entries($form, array('is3d' => true, 'colors' => $colors, 'bg_color' => 'transparent', 'width' => '100%'), 'MONTH'); foreach ($fields as $field) { $this_data = self::graph_shortcode(array('id' => $field->id, 'field' => $field, 'is3d' => true, 'min' => 0, 'colors' => $colors, 'width' => 650, 'bg_color' => 'transparent')); if (strpos($this_data, 'frm_no_data_graph') === false) { $data[$field->id] = $this_data; } unset($field, $this_data); } $entries = FrmDb::get_col($wpdb->prefix . 'frm_items', array('form_id' => $form->id), 'created_at'); // trigger the scripts to load global $frm_vars; $frm_vars['forms_loaded'][] = true; include FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-statistics/show.php'; }
function create($values) { global $wpdb, $blog_id, $frmpro_display; $exists = $wpdb->query("DESCRIBE {$this->table_name}"); if (!$exists) { $this->install(true); } unset($exists); $new_values = array(); $new_values['blog_id'] = $blog_id; $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; $new_values['type'] = isset($values['type']) ? $values['type'] : 'form'; //options here are: form, display if ($new_values['type'] == 'form') { $frm_form = new FrmForm(); $form_copied = $frm_form->getOne($new_values['form_id']); $new_values['copy_key'] = $form_copied->form_key; } else { $form_copied = $frmpro_display->getOne($new_values['form_id']); $new_values['copy_key'] = $form_copied->post_name; } $new_values['created_at'] = current_time('mysql', 1); $exists = $this->getAll(array('blog_id' => $blog_id, 'form_id' => $new_values['form_id'], 'type' => $new_values['type']), '', ' LIMIT 1'); if ($exists) { return false; } $query_results = $wpdb->insert($this->table_name, $new_values); if ($query_results) { return $wpdb->insert_id; } else { return false; } }
public static function add_form_nav($views) { if (!FrmProDisplaysHelper::is_edit_view_page()) { return $views; } $form = isset($_REQUEST['form']) && is_numeric($_REQUEST['form']) ? $_REQUEST['form'] : false; if (!$form) { return $views; } $form = FrmForm::getOne($form); if (!$form) { return $views; } echo '<div id="poststuff">'; echo '<div id="post-body" class="metabox-holder columns-2">'; echo '<div id="post-body-content">'; FrmAppController::get_form_nav($form, true, 'hide'); echo '</div>'; echo '<div class="clear"></div>'; echo '</div>'; echo '<div id="titlediv"><input id="title" type="text" value="' . esc_attr($form->name == '' ? __('(no title)') : $form->name) . '" readonly="readonly" disabled="disabled" /></div>'; echo '</div>'; echo '<style type="text/css">p.search-box{margin-top:-91px;}</style>'; return $views; }
public static function create($values) { global $wpdb, $blog_id; $exists = $wpdb->query('DESCRIBE ' . self::table_name()); if (!$exists) { self::install(true); } unset($exists); $new_values = array(); $new_values['blog_id'] = $blog_id; $new_values['form_id'] = isset($values['form_id']) ? (int) $values['form_id'] : null; $new_values['type'] = isset($values['type']) ? $values['type'] : 'form'; //options here are: form, display if ($new_values['type'] == 'form') { $form_copied = FrmForm::getOne($new_values['form_id']); $new_values['copy_key'] = $form_copied->form_key; } else { $form_copied = FrmProDisplay::getOne($new_values['form_id']); $new_values['copy_key'] = $form_copied->post_name; } $new_values['created_at'] = current_time('mysql', 1); $exists = self::getAll(array('blog_id' => $blog_id, 'form_id' => $new_values['form_id'], 'type' => $new_values['type']), '', ' LIMIT 1'); if ($exists) { return false; } $query_results = $wpdb->insert(self::table_name(), $new_values); if ($query_results) { return $wpdb->insert_id; } else { return false; } }
function duplicate($id, $template = false, $copy_keys = false, $blog_id = false) { global $wpdb; $frm_form = new FrmForm(); $values = $frm_form->getOne($id, $blog_id); if (!$values) { return false; } $new_key = $copy_keys ? $values->form_key : ''; $new_values = array('form_key' => FrmAppHelper::get_unique_key($new_key, $wpdb->prefix . 'frm_forms', 'form_key'), 'name' => $values->name, 'description' => $values->description, 'status' => $template ? '' : 'draft', 'logged_in' => $values->logged_in ? $values->logged_in : 0, 'editable' => $values->editable ? $values->editable : 0, 'created_at' => current_time('mysql', 1), 'is_template' => $template ? 1 : 0); if ($blog_id) { $new_values['status'] = 'published'; $new_options = maybe_unserialize($values->options); $new_options['email_to'] = get_option('admin_email'); $new_options['copy'] = false; $new_values['options'] = $new_options; } else { $new_values['options'] = $values->options; } if (is_array($new_values['options'])) { $new_values['options'] = serialize($new_values['options']); } $query_results = $wpdb->insert($wpdb->prefix . 'frm_forms', $new_values); if ($query_results) { global $frm_field; $form_id = $wpdb->insert_id; $frm_field->duplicate($id, $form_id, $copy_keys, $blog_id); // update form settings after fields are created do_action('frm_after_duplicate_form', $form_id, $new_values); return $form_id; } else { return false; } }
function import_xml() { // install test data in older format add_filter('frm_default_templates_files', 'FrmUnitTest::install_data'); FrmXMLController::add_default_templates(); $form = FrmForm::getOne('contact-db12'); $this->assertEquals($form->form_key, 'contact-db12'); }
/** * @covers FrmXMLHelper::track_repeating_fields * @covers FrmXMLHelper::update_repeat_field_options */ public function _check_form_select($f, $expected_form_key) { $this->assertNotEmpty($f->field_options['form_select'], 'Imported repeating section has a blank form_select.'); // Check if the form_select setting matches the correct form $nested_form = FrmForm::getOne($f->field_options['form_select']); $this->assertNotEmpty($nested_form, 'The form_select in an imported repeating section is not updating correctly.'); $this->assertEquals($expected_form_key, $nested_form->form_key, 'The form_select is not updating properly when a repeating section is imported.'); }
function entry_created($entry_id, $form_id) { if (apply_filters('frm_stop_standard_email', false, $entry_id)) { return; } global $frm_entry, $frm_entry_meta; $entry = $frm_entry->getOne($entry_id, true); $frm_form = new FrmForm(); $form = $frm_form->getOne($form_id); $values = $frm_entry_meta->getAll("it.item_id = {$entry_id}", " ORDER BY fi.field_order"); if (isset($form->options['notification'])) { $notification = reset($form->options['notification']); } else { $notification = $form->options; } // Set the from and to email names and addresses $to_email = $notification['email_to']; if (empty($to_email)) { $to_email = '[admin_email]'; } $to_emails = explode(',', $to_email); $reply_to = $reply_to_name = ''; foreach ($values as $value) { $val = apply_filters('frm_email_value', maybe_unserialize($value->meta_value), $value, $entry); if (is_array($val)) { $val = implode(', ', $val); } if (isset($notification['reply_to']) and (int) $notification['reply_to'] == $value->field_id and is_email($val)) { $reply_to = $val; } if (isset($notification['reply_to_name']) and (int) $notification['reply_to_name'] == $value->field_id) { $reply_to_name = $val; } } if (empty($reply_to) && $notification['reply_to'] == 'custom') { $reply_to = $notification['cust_reply_to']; } if (empty($reply_to_name) && $notification['reply_to_name'] == 'custom') { $reply_to_name = $notification['cust_reply_to_name']; } // Set the email message $plain_text = isset($notification['plain_text']) && $notification['plain_text'] ? true : false; $mail_body = isset($notification['email_message']) ? $notification['email_message'] : ''; $mail_body = FrmEntriesHelper::replace_default_message($mail_body, array('id' => $entry->id, 'entry' => $entry, 'plain_text' => $plain_text, 'user_info' => isset($notification['inc_user_info']) ? $notification['inc_user_info'] : false)); // Set the subject $subject = isset($notification['email_subject']) ? $notification['email_subject'] : ''; if (empty($subject)) { $frm_blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $subject = sprintf(__('%1$s Form submitted on %2$s', 'formidable'), $form->name, $frm_blogname); } // Send the emails now foreach ((array) $to_emails as $to_email) { $this->send_notification_email(trim($to_email), $subject, $mail_body, $reply_to, $reply_to_name, $plain_text); } }
public static function _logic_row() { check_ajax_referer('frm_ajax', 'nonce'); $meta_name = FrmAppHelper::get_param('meta_name', '', 'get', 'sanitize_title'); $form_id = FrmAppHelper::get_param('form_id', '', 'get', 'absint'); $key = FrmAppHelper::get_param('email_id', '', 'get', 'sanitize_title'); $type = FrmAppHelper::get_param('type', '', 'get', 'sanitize_title'); $form = FrmForm::getOne($form_id); FrmProFormsController::include_logic_row(array('form_id' => $form->id, 'form' => $form, 'meta_name' => $meta_name, 'condition' => array('hide_field_cond' => '==', 'hide_field' => ''), 'key' => $key, 'name' => 'frm_' . $type . '_action[' . $key . '][post_content][conditions][' . $meta_name . ']')); wp_die(); }
function duplicate($id, $copy_keys = false, $blog_id = false) { global $wpdb; $values = $this->getOne($id, $blog_id, true); if (!$values or !is_numeric($values->frm_form_id)) { return false; } $new_values = array(); foreach (array('post_name', 'post_title', 'post_excerpt', 'post_content', 'post_status', 'post_type') as $k) { $new_values[$k] = $values->{$k}; unset($k); } $meta = array(); foreach (array('form_id', 'entry_id', 'post_id', 'dyncontent', 'param', 'type', 'show_count', 'insert_loc') as $k) { $meta[$k] = $values->{'frm_' . $k}; unset($k); } $default = FrmProDisplaysHelper::get_default_opts(); $meta['options'] = array(); foreach ($default as $k => $v) { if (isset($meta[$k])) { continue; } $meta['options'][$k] = $values->{'frm_' . $k}; unset($k); unset($v); } $meta['options']['copy'] = false; if ($blog_id) { $frm_form = new FrmForm(); $old_form = $frm_form->getOne($values->frm_form_id, $blog_id); $new_form = $frm_form->getOne($old_form->form_key); $meta['form_id'] = $new_form->id; } else { $meta['form_id'] = $values->form_id; } $post_ID = wp_insert_post($new_values); $new_values = array_merge((array) $new_values, $meta); $this->update($post_ID, $new_values); return $post_ID; }
public static function save_wppost_actions($settings, $action) { $form_id = $action['menu_order']; if (isset($settings['post_custom_fields'])) { foreach ($settings['post_custom_fields'] as $cf_key => $n) { if (!isset($n['custom_meta_name'])) { continue; } if ($n['meta_name'] == '' && $n['custom_meta_name'] != '') { $settings['post_custom_fields'][$cf_key]['meta_name'] = $n['custom_meta_name']; } unset($settings['post_custom_fields'][$cf_key]['custom_meta_name']); unset($cf_key, $n); } } self::create_post_category_field($settings, $form_id); self::create_post_status_field($settings, $form_id); //update/create View if (!empty($settings['display_id'])) { if (is_numeric($settings['display_id'])) { //updating View $type = get_post_meta($settings['display_id'], 'frm_show_count', true); if ('one' == $type) { $display = get_post($settings['display_id'], ARRAY_A); $display['post_content'] = $_POST['dyncontent']; wp_insert_post($display); } else { update_post_meta($settings['display_id'], 'frm_dyncontent', $_POST['dyncontent']); } } else { if ('new' == $settings['display_id']) { // Get form name for View title $form = FrmForm::getOne($form_id); if (!empty($form->name)) { $post_title = $form->name; } else { $post_title = __('Single Post', 'formidable'); } //create new $cd_values = array('post_status' => 'publish', 'post_type' => 'frm_display', 'post_title' => $post_title, 'post_excerpt' => __('Used for the single post page', 'formidable'), 'post_content' => $_POST['dyncontent']); $display_id = wp_insert_post($cd_values); $settings['display_id'] = $display_id; unset($cd_values); update_post_meta($display_id, 'frm_param', 'entry'); update_post_meta($display_id, 'frm_type', 'display_key'); update_post_meta($display_id, 'frm_show_count', 'one'); update_post_meta($display_id, 'frm_form_id', $form_id); } } } return $settings; }
function _setup_post_values($form_id) { $fields = FrmField::get_all_for_form($form_id); $form = FrmForm::getOne($form_id); $_POST = array('page' => 'formidable', 'frm_action' => 'update', 'id' => $form_id, 'action' => 'update', 'frm_save_form' => wp_create_nonce('frm_save_form_nonce'), 'status' => 'published', 'new_status' => '', 'name' => $form->name, 'frm_fields_submitted' => array(), 'item_meta' => array(), 'field_options' => array()); foreach ($fields as $field) { $_POST['frm_fields_submitted'][] = $field->id; $_POST['item_meta'][$field->id] = 'default'; $field_options = array('description_' . $field->id => '', 'type_' . $field->id => '', 'required_indicator_' . $field->id => '*', 'field_key_' . $field->id => $field->field_key, 'classes_' . $field->id => '', 'label_' . $field->id => '', 'size_' . $field->id => '', 'max_' . $field->id => '', 'admin_only_' . $field->id => '', 'use_calc_' . $field->id => 1, 'calc_' . $field->id => '', 'calc_dec_' . $field->id => '', 'show_hide_' . $field->id => 'show', 'any_all_' . $field->id => 'any', 'blank_' . $field->id => 'This field cannot be blank.', 'unique_msg_' . $field->id => ''); $_POST['field_options'] = array_merge($_POST['field_options'], $field_options); $_REQUEST = $_POST; } }
public function no_items() { $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : ''; if (!empty($s)) { _e('No Entries Found', 'formidable'); return; } $form_id = $form = $this->params['form']; if ($form_id) { $form = FrmForm::getOne($form_id); } $colspan = $this->get_column_count(); include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/no_entries.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 static function get_form_nav($id, $show_nav = false) { global $pagenow, $frm_vars; $show_nav = FrmAppHelper::get_param('show_nav', $show_nav); if (!$show_nav) { return; } $current_page = isset($_GET['page']) ? $_GET['page'] : (isset($_GET['post_type']) ? $_GET['post_type'] : 'None'); if ($id and is_numeric($id)) { $frm_form = new FrmForm(); $form = $frm_form->getOne($id); unset($frm_form); } else { $form = false; } include FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php'; }
public static function setup_new_vars($fields, $form = '', $reset = false, $args = array()) { global $frm_vars; $values = array(); foreach (array('name' => '', 'description' => '', 'item_key' => '') as $var => $default) { $values[$var] = FrmAppHelper::get_post_param($var, $default); } $values['fields'] = array(); if (empty($fields)) { return apply_filters('frm_setup_new_entry', $values); } foreach ((array) $fields as $field) { $new_value = self::get_field_value_for_new_entry($field, $reset); $field_array = array('id' => $field->id, 'value' => $new_value, 'default_value' => $field->default_value, 'name' => $field->name, 'description' => $field->description, 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), 'options' => $field->options, 'required' => $field->required, 'field_key' => $field->field_key, 'field_order' => $field->field_order, 'form_id' => $field->form_id, 'parent_form_id' => isset($args['parent_form_id']) ? $args['parent_form_id'] : $field->form_id); $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); $opt_defaults['required_indicator'] = ''; $opt_defaults['original_type'] = $field->type; foreach ($opt_defaults as $opt => $default_opt) { $field_array[$opt] = isset($field->field_options[$opt]) && $field->field_options[$opt] != '' ? $field->field_options[$opt] : $default_opt; unset($opt, $default_opt); } unset($opt_defaults); if ($field_array['custom_html'] == '') { $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); } $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field); $field_array = array_merge($field->field_options, $field_array); $values['fields'][] = $field_array; if (!$form || !isset($form->id)) { $form = FrmForm::getOne($field->form_id); } } $form->options = maybe_unserialize($form->options); if (is_array($form->options)) { foreach ($form->options as $opt => $value) { $values[$opt] = FrmAppHelper::get_post_param($opt, $value); unset($opt, $value); } } $form_defaults = FrmFormsHelper::get_default_opts(); $frm_settings = FrmAppHelper::get_settings(); $form_defaults['custom_style'] = $frm_settings->load_style != 'none'; $values = array_merge($form_defaults, $values); return apply_filters('frm_setup_new_entry', $values); }
public static function show() { global $frmdb, $frm_field, $frm_entry_meta, $frm_entry, $wpdb; if (!isset($_GET['form'])) { require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-statistics/show.php'; return; } $frm_form = new FrmForm(); $form = $frm_form->getOne($_GET['form']); $form_options = maybe_unserialize($form->options); $fields = $frm_field->getAll("fi.type not in ('divider','captcha','break','rte','textarea','file','grid','html','signature','table') and fi.form_id=" . (int) $form->id, 'field_order ASC'); $js = ''; $data = array(); $colors = '#21759B,#EF8C08,#C6C6C6'; $data['time'] = self::get_daily_entries($form, array('is3d' => true, 'colors' => $colors)); $data['month'] = self::get_daily_entries($form, array('is3d' => true, 'colors' => $colors), 'MONTH'); foreach ($fields as $field) { $data[$field->id] = self::graph_shortcode(array('id' => $field->id, 'field' => $field, 'is3d' => true, 'min' => 0, 'colors' => $colors, 'width' => 650)); unset($field); } include FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-statistics/show.php'; }
/** * @covers FrmDb::migrate_to_17 */ function test_migrate_from_12_to_17() { $this->frm_install(); update_option('frm_db_version', 12); $form = FrmForm::getOne('contact-db12'); $this->assertNotEmpty($form); $this->assertTrue(is_numeric($form->id)); $notification = array(0 => array('email_to' => '*****@*****.**', 'also_email_to' => array(1, 2), 'reply_to' => '*****@*****.**', 'reply_to_name' => 'Reply to me', 'cust_reply_to' => '', 'cust_reply_to_name' => '', 'plain_text' => 1, 'email_message' => 'This is my email message. [default-message]', 'email_subject' => 'The subject', 'update_email' => 2, 'inc_user_info' => 1)); $form->options['notification'] = $notification; global $wpdb; $updated = $wpdb->update($wpdb->prefix . 'frm_forms', array('options' => maybe_serialize($form->options)), array('id' => $form->id)); FrmForm::clear_form_cache(); $this->assertEquals($updated, 1); $form = FrmForm::getOne('contact-db12'); $this->assertNotEmpty($form->options, 'The form settings are empty'); $this->assertTrue(isset($form->options['notification']), 'The old notification settings are missing'); $this->assertEquals($form->options['notification'][0]['email_to'], '*****@*****.**'); // migrate data FrmAppController::install(); $form_actions = FrmFormAction::get_action_for_form($form->id, 'email'); foreach ($form_actions as $action) { $this->assertTrue(strpos($action->post_content['email_to'], '*****@*****.**') !== false); } }
function get_object_by_id($form_id) { return FrmForm::getOne($form_id); }
public static function generate_xml($type, $args = array()) { global $wpdb; $type = (array) $type; if (in_array('items', $type) && !in_array('forms', $type)) { // make sure the form is included if there are entries $type[] = 'forms'; } if (in_array('forms', $type)) { // include actions with forms $type[] = 'actions'; } $tables = array('items' => $wpdb->prefix . 'frm_items', 'forms' => $wpdb->prefix . 'frm_forms', 'posts' => $wpdb->posts, 'styles' => $wpdb->posts, 'actions' => $wpdb->posts); $defaults = array('ids' => false); $args = wp_parse_args($args, $defaults); $sitename = sanitize_key(get_bloginfo('name')); if (!empty($sitename)) { $sitename .= '.'; } $filename = $sitename . 'formidable.' . date('Y-m-d') . '.xml'; header('Content-Description: File Transfer'); header('Content-Disposition: attachment; filename=' . $filename); header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); //make sure ids are numeric if (is_array($args['ids']) && !empty($args['ids'])) { $args['ids'] = array_filter($args['ids'], 'is_numeric'); } $records = array(); foreach ($type as $tb_type) { $where = array(); $join = ''; $table = $tables[$tb_type]; $select = $table . '.id'; $query_vars = array(); switch ($tb_type) { case 'forms': //add forms if ($args['ids']) { $where[] = array('or' => 1, $table . '.id' => $args['ids'], $table . '.parent_form_id' => $args['ids']); } else { $where[$table . '.status !'] = 'draft'; } break; case 'actions': $select = $table . '.ID'; $where['post_type'] = FrmFormActionsController::$action_post_type; if (!empty($args['ids'])) { $where['menu_order'] = $args['ids']; } break; case 'items': //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)"; if ($args['ids']) { $where[$table . '.form_id'] = $args['ids']; } break; case 'styles': // Loop through all exported forms and get their selected style IDs $form_ids = $args['ids']; $style_ids = array(); foreach ($form_ids as $form_id) { $form_data = FrmForm::getOne($form_id); // For forms that have not been updated while running 2.0, check if custom_style is set if (isset($form_data->options['custom_style'])) { $style_ids[] = $form_data->options['custom_style']; } unset($form_id, $form_data); } $select = $table . '.ID'; $where['post_type'] = 'frm_styles'; // Only export selected styles if (!empty($style_ids)) { $where['ID'] = $style_ids; } break; default: $select = $table . '.ID'; $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)'; $where['pm.meta_key'] = 'frm_form_id'; if (empty($args['ids'])) { $where['pm.meta_value >'] = 1; } else { $where['pm.meta_value'] = $args['ids']; } break; } $records[$tb_type] = FrmDb::get_col($table . $join, $where, $select); unset($tb_type); } echo '<?xml version="1.0" encoding="' . esc_attr(get_bloginfo('charset')) . "\" ?>\n"; include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php'; }
public function search_box($text, $input_id) { if (!$this->has_items() && !isset($_REQUEST['s'])) { return; } if (isset($this->params['form'])) { $form = FrmForm::getOne($this->params['form']); } else { $form = FrmForm::get_published_forms(array(), 1); } if ($form) { $field_list = FrmField::getAll(array('fi.form_id' => $form->id, 'fi.type not' => FrmField::no_save_fields()), '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'])) : ''; foreach (array('orderby', 'order') as $get_var) { if (!empty($_REQUEST[$get_var])) { echo '<input type="hidden" name="' . esc_attr($get_var) . '" value="' . esc_attr($_REQUEST[$get_var]) . '" />'; } } ?> <div class="search-box frm_sidebar"> <label class="screen-reader-text" for="<?php echo esc_attr($input_id); ?> "><?php echo esc_attr($text); ?> :</label> <input type="text" id="<?php echo esc_attr($input_id); ?> " name="s" value="<?php echo esc_attr($search_str); ?> " /> <?php if (isset($field_list) && !empty($field_list)) { ?> <select name="fid" class="hide-if-js"> <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> <div class="button dropdown hide-if-no-js"> <a href="#" id="frm-fid-search" class="frm-dropdown-toggle" data-toggle="dropdown"><?php _e('Search', 'formidable'); ?> <b class="caret"></b></a> <ul class="frm-dropdown-menu pull-right" id="frm-fid-search-menu" role="menu" aria-labelledby="frm-fid-search"> <li><a href="#" id="fid-">— <?php _e('All Fields', 'formidable'); ?> —</a></li> <li><a href="#" id="fid-created_at"><?php _e('Entry creation date', 'formidable'); ?> </a></li> <li><a href="#" id="fid-id"><?php _e('Entry ID', 'formidable'); ?> </a></li> <?php foreach ($field_list as $f) { ?> <li><a href="#" id="fid-<?php echo $f->type == 'user_id' ? 'user_id' : $f->id; ?> "><?php echo FrmAppHelper::truncate($f->name, 30); ?> </a></li> <?php unset($f); } ?> </ul> </div> <?php submit_button($text, 'button hide-if-js', false, false, array('id' => 'search-submit')); } else { submit_button($text, 'button', false, false, array('id' => 'search-submit')); if (!empty($search_str)) { ?> <a href="<?php echo esc_url(admin_url('admin.php?page=formidable-entries&frm_action=list&form=' . $form->id)); ?> "><?php _e('Reset', 'formidable'); ?> </a> <?php } } ?> </div> <?php }
/** * @covers FrmProFieldsController::toggle_repeat */ function _check_if_new_form_created($old_count, $args) { global $wpdb; $all_forms = $wpdb->get_col("SELECT id FROM " . $wpdb->prefix . "frm_forms"); $new_count = count($all_forms); $this->assertEquals($old_count + 1, $new_count, 'A new form is not created when switching divider to repeatable.'); // Get ID of new form $new_form_id = max($all_forms); // Check parent_form_id $new_form = FrmForm::getOne($new_form_id); $this->assertEquals($args['parent_form_id'], $new_form->parent_form_id, 'parent_form_id is not set correctly when a new form is created when switching to a repeating section.'); return $new_form_id; }
/** * If a form is a child form, get the parent form. Then if the entry is a child entry, get the parent entry. * * @since 2.0.13 * @param int|object $form - pass by reference * @param int|object $entry - pass by reference */ private static function maybe_get_parent_form_and_entry(&$form, &$entry) { // If form is a child form, refer to parent form's settings if ($form->parent_form_id) { $form = FrmForm::getOne($form->parent_form_id); // Make sure we're also checking the parent entry's permissions FrmEntry::maybe_get_entry($entry); if ($entry->parent_item_id) { $entry = FrmEntry::getOne($entry->parent_item_id); } } }
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; }
public static function delete_form_transient($form_id) { $form_id = absint($form_id); delete_transient('frm_form_fields_' . $form_id . 'exclude'); delete_transient('frm_form_fields_' . $form_id . 'include'); global $wpdb; $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_' . $form_id . 'ex%', '_transient_frm_form_fields_' . $form_id . 'ex%', '_transient_timeout_frm_form_fields_' . $form_id . 'in%', '_transient_frm_form_fields_' . $form_id . 'in%')); $cache_key = serialize(array('fi.form_id' => $form_id)) . 'field_orderlb'; wp_cache_delete($cache_key, 'frm_field'); // this cache key is autogenerated in FrmDb::get_var wp_cache_delete('(__fi.form_id=%d_OR_fr.parent_form_id=%d_)__' . $form_id . '_' . $form_id . '_ORDER_BY_field_orderfi.*__fr.name_as_form_name_results', 'frm_field'); $form = FrmForm::getOne($form_id); if ($form && $form->parent_form_id) { self::delete_form_transient($form->parent_form_id); } }
/** * Initialize the plugin by setting localization, filters, and administration functions. * * @since 1.0.0 * * @access private */ private function __construct() { global $formworks_tracker; //auto load modules $dir = FRMWKS_PATH . 'includes/modules'; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($folder = readdir($dh)) !== false) { if ($folder === '..' || $folder === '.') { continue; } if (file_exists($dir . '/' . $folder . '/handler.php')) { include_once $dir . '/' . $folder . '/handler.php'; } } closedir($dh); } } // Load plugin text domain add_action('init', array($this, 'load_plugin_textdomain')); //initialize visitor tracker if (!is_admin()) { add_action('wp', array($this, 'register_visitor_session')); } // Activate plugin when new blog is added add_action('wpmu_new_blog', array($this, 'activate_new_site')); // Load admin style sheet and JavaScript. add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_stylescripts')); // Load front style sheet and JavaScript. add_action('wp_enqueue_scripts', array($this, 'enqueue_front_stylescripts')); // output tracking code add_action('wp_print_footer_scripts', array($this, 'print_front_scripts')); // Add partial completions add_action('wp_ajax_frmwks_push', array($this, 'tracker_push')); add_action('wp_ajax_nopriv_frmwks_push', array($this, 'tracker_push')); // open actions add_action('formworks_track', array($this, 'handle_track'), 10, 4); /** * Tracking */ /** Caldera Forms */ add_action('caldera_forms_submit_complete', function ($form) { do_action('formworks_track', 'caldera', $form['ID'], 'submission'); }); add_filter('caldera_forms_render_form', function ($html, $form) { $selector = array("name" => $form['name'], "selector" => "." . $form['ID'], "prefix" => 'caldera', "id" => $form['ID']); do_action('formworks_track', 'caldera', $form['ID'], 'loaded', $selector); return $html; }, 10, 2); /** JETPACK */ add_filter('grunion_contact_form_success_message', function ($html) { if (isset($_GET['contact-form-id'])) { $form_id = $_GET['contact-form-id']; do_action('formworks_track', 'jp', $form_id, 'submission'); } return $html; }); add_filter('grunion_contact_form_form_action', function ($url, $post, $form) { $selector = array("name" => $post->post_title, "selector" => "#contact-form-" . $form); do_action('formworks_track', 'jp', $form, 'loaded', $selector); return $url; }, 15, 3); /** Formidable */ add_action('frm_process_entry', function ($params) { do_action('formworks_track', 'frmid', $params['form_id'], 'submission'); }, 15); add_filter('formidable_shortcode_atts', function ($shortcode_atts, $atts) { if (class_exists('\\FrmForm')) { $form = \FrmForm::getOne($atts['id']); } $selector = array("name" => $form->name, "selector" => "#form_" . $form->form_key); do_action('formworks_track', 'frmid', $form->id, 'loaded', $selector); }, 10, 2); /** Contact Form 7 */ add_filter('wpcf7_form_elements', function ($html) { if (class_exists('\\WPCF7_ContactForm')) { $form = \WPCF7_ContactForm::get_current(); do_action('formworks_track', 'cf7', $form->id(), 'loaded'); } return $html; }, 10, 2); add_action('wpcf7_submit', function ($instance, $result) { if (isset($result['status']) && 'mail_sent' === $result['status']) { do_action('formworks_track', 'cf7', $instance->id(), 'submission'); } }, 20, 2); /** Gravity Forms */ add_filter('gform_get_form_filter', function ($html, $form) { $selector = array("name" => $form['title'], "selector" => "#gform_" . $form['id']); do_action('formworks_track', 'gform', $form['id'], 'loaded', $selector); return $html; }, 10, 2); add_action('gform_after_submission', function ($form) { // do a submission complete do_action('formworks_track', 'gform', $form['form_id'], 'submission'); return; }); /** Ninja Forms */ add_action('ninja_forms_post_process', function () { global $ninja_forms_processing; if (is_object($ninja_forms_processing)) { do_action('formworks_track', 'ninja', $ninja_forms_processing->get_form_ID(), 'submission'); } }); //load settings class && licensing in admin if (is_admin()) { new settings(); add_action('admin_init', function () { $plugin = frmwks_licensing_args(); new \calderawp\licensing_helper\licensing($plugin); }, 0); } }
private static function fields_to_values($form_id, array &$values) { $form = FrmForm::getOne($form_id); $values = array('fields' => array(), 'id' => $form->id); $fields = FrmField::get_all_for_form($form->id); foreach ($fields as $k => $f) { $f = (array) $f; $opts = (array) $f['field_options']; $f = array_merge($opts, $f); if (!isset($f['post_field'])) { $f['post_field'] = ''; } $values['fields'][] = $f; unset($k, $f); } return $form; }
function validate($values, $exclude = false) { global $wpdb, $frm_field, $frm_entry_meta, $frm_settings; $errors = array(); if (!isset($values['form_id']) || !isset($values['item_meta'])) { $errors['form'] = __('There was a problem with your submission. Please try again.', 'formidable'); return $errors; } if (is_admin() && is_user_logged_in() && (!isset($values['frm_submit_entry_' . $values['form_id']]) || !wp_verify_nonce($values['frm_submit_entry_' . $values['form_id']], 'frm_submit_entry_nonce'))) { $errors['form'] = __('You do not have permission to do that', 'formidable'); } if (!isset($values['item_key']) or $values['item_key'] == '') { $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_items', 'item_key'); } $where = apply_filters('frm_posted_field_ids', 'fi.form_id=' . (int) $values['form_id']); if ($exclude) { $where .= " and fi.type not in ('" . implode("','", array_filter($exclude, 'esc_sql')) . "')"; } $posted_fields = $frm_field->getAll($where, 'field_order'); foreach ($posted_fields as $posted_field) { $posted_field->field_options = maybe_unserialize($posted_field->field_options); $value = ''; if (isset($values['item_meta'][$posted_field->id])) { $value = $values['item_meta'][$posted_field->id]; } if (isset($posted_field->field_options['default_blank']) and $posted_field->field_options['default_blank'] and $value == $posted_field->default_value) { $value = ''; } if (is_array($value) and count($value) === 1) { $value = reset($value); } if ($posted_field->type == 'rte' and !is_array($value) and trim($value) == '<br>') { $value = ''; } if ($posted_field->required == '1' and !is_array($value) and trim($value) == '') { $errors['field' . $posted_field->id] = (!isset($posted_field->field_options['blank']) or $posted_field->field_options['blank'] == '' or $posted_field->field_options['blank'] == 'Untitled cannot be blank') ? $frm_settings->blank_msg : $posted_field->field_options['blank']; } else { if ($posted_field->type == 'text' and !isset($_POST['name'])) { $_POST['name'] = $value; } } $_POST['item_meta'][$posted_field->id] = $value; if ($posted_field->type == 'captcha' and isset($_POST['recaptcha_challenge_field'])) { global $frm_settings; if (!function_exists('recaptcha_check_answer')) { require FrmAppHelper::plugin_path() . '/classes/recaptchalib.php'; } $response = recaptcha_check_answer($frm_settings->privkey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']); if (!$response->is_valid) { // What happens when the CAPTCHA was entered incorrectly $errors['captcha-' . $response->error] = $errors['field' . $posted_field->id] = (!isset($posted_field->field_options['invalid']) or $posted_field->field_options['invalid'] == '') ? $frm_settings->re_msg : $posted_field->field_options['invalid']; } } $errors = apply_filters('frm_validate_field_entry', $errors, $posted_field, $value); } // check for spam if (empty($exclude) && isset($values['item_meta']) && !empty($values['item_meta']) && empty($errors)) { global $wpcom_api_key; if ((function_exists('akismet_http_post') || is_callable('Akismet::http_post')) && (get_option('wordpress_api_key') || $wpcom_api_key) && $this->akismet($values)) { $frm_form = new FrmForm(); $form = $frm_form->getOne($values['form_id']); if (isset($form->options['akismet']) && !empty($form->options['akismet']) && ($form->options['akismet'] != 'logged' || !is_user_logged_in())) { $errors['spam'] = __('Your entry appears to be spam!', 'formidable'); } } // check for blacklist keys if ($this->blacklist_check($values)) { $errors['spam'] = __('Your entry appears to be spam!', 'formidable'); } } $errors = apply_filters('frm_validate_entry', $errors, $values); return $errors; }