/**
  * @covers FrmAppHelper::get_settings
  */
 function test_get_settings()
 {
     $settings = FrmAppHelper::get_settings();
     $this->assertNotEmpty($settings);
     $this->assertTrue(is_object($settings));
     $this->assertNotEmpty($settings->success_msg);
 }
 public static function process_form($stop_load = false)
 {
     global $frm_vars;
     $frm_settings = FrmAppHelper::get_settings();
     $process_form = FrmAppHelper::get_post_param('process_form', '', 'sanitize_text_field');
     if (!wp_verify_nonce($process_form, 'process_form_nonce')) {
         wp_die($frm_settings->admin_permission);
     }
     $errors = array();
     $message = '';
     if (!isset($frm_vars['settings_routed']) || !$frm_vars['settings_routed']) {
         //$errors = $frm_settings->validate($_POST,array());
         $frm_settings->update(stripslashes_deep($_POST));
         if (empty($errors)) {
             $frm_settings->store();
             $message = __('Settings Saved', 'formidable');
         }
     } else {
         $message = __('Settings Saved', 'formidable');
     }
     if ($stop_load == 'stop_load') {
         $frm_vars['settings_routed'] = true;
         return;
     }
     self::display_form($errors, $message);
 }
 public function test_add_js()
 {
     $frm_settings = FrmAppHelper::get_settings();
     global $frm_vars;
     if ($frm_settings->jquery_css) {
         $this->assertNotEmpty($frm_vars['datepicker_loaded']);
     }
     if ($frm_settings->accordion_js) {
         $this->assertTrue(wp_script_is('jquery-ui-widget', 'enqueued'));
         $this->assertTrue(wp_script_is('jquery-ui-accordion', 'enqueued'));
     }
 }
Exemple #4
0
 public static function validate($params, $fields, $form, $title, $description)
 {
     global $frm_vars;
     $frm_settings = FrmAppHelper::get_settings();
     if (($_POST && isset($_POST['frm_page_order_' . $form->id]) || FrmProFormsHelper::going_to_prev($form->id)) && !FrmProFormsHelper::saving_draft()) {
         $errors = '';
         $fields = FrmFieldsHelper::get_form_fields($form->id);
         $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
         $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
         require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
         add_filter('frm_continue_to_create', '__return_false');
     } else {
         if ($form->editable && isset($form->options['single_entry']) && $form->options['single_entry'] && $form->options['single_entry_type'] == 'user') {
             $user_ID = get_current_user_id();
             if ($user_ID) {
                 $entry = FrmEntry::getAll(array('it.user_id' => $user_ID, 'it.form_id' => $form->id), '', 1, true);
                 if ($entry) {
                     $entry = reset($entry);
                 }
             } else {
                 $entry = false;
             }
             if ($entry && !empty($entry) && (!isset($frm_vars['created_entries'][$form->id]) || !isset($frm_vars['created_entries'][$form->id]['entry_id']) || $entry->id != $frm_vars['created_entries'][$form->id]['entry_id'])) {
                 FrmProEntriesController::show_responses($entry, $fields, $form, $title, $description);
             } else {
                 $record = $frm_vars['created_entries'][$form->id]['entry_id'];
                 $saved_message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
                 if (FrmProFormsHelper::saving_draft()) {
                     $saved_message = isset($form->options['draft_msg']) ? $form->options['draft_msg'] : __('Your draft has been saved.', 'formidable');
                 }
                 $saved_message = apply_filters('frm_content', $saved_message, $form, $record ? $record : false);
                 $message = wpautop(do_shortcode($record ? $saved_message : $frm_settings->failed_msg));
                 $message = '<div class="frm_message" id="message">' . $message . '</div>';
                 FrmProEntriesController::show_responses($record, $fields, $form, $title, $description, $message);
             }
             add_filter('frm_continue_to_create', '__return_false');
         } else {
             if (FrmProFormsHelper::saving_draft()) {
                 $record = isset($frm_vars['created_entries']) && isset($frm_vars['created_entries'][$form->id]) ? $frm_vars['created_entries'][$form->id]['entry_id'] : 0;
                 if (!$record) {
                     return;
                 }
                 $saved_message = '';
                 FrmProFormsHelper::save_draft_msg($saved_message, $form, $record);
                 $message = FrmFormsHelper::get_success_message(array('message' => $saved_message, 'form' => $form, 'entry_id' => $record, 'class' => 'frm_message'));
                 FrmProEntriesController::show_responses($record, $fields, $form, $title, $description, $message);
                 add_filter('frm_continue_to_create', '__return_false');
             }
         }
     }
 }
 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);
 }
 /**
  * Make sure the stylesheet is loaded at the right times
  */
 public function test_front_head()
 {
     $this->set_front_end();
     if (defined('DOING_AJAX') && DOING_AJAX) {
         $this->markTestSkipped('Run with --group styles');
     }
     ob_start();
     do_action('wp_head');
     $styles = ob_get_contents();
     ob_end_clean();
     $this->assertNotEmpty($styles);
     $frm_settings = FrmAppHelper::get_settings();
     $stylesheet_urls = $this->get_custom_stylesheet();
     $style_included = strpos($styles, $stylesheet_urls['formidable']);
     if ($frm_settings->load_style == 'all') {
         $this->assertTrue($style_included !== false, 'The formidablepro stylesheet is missing');
     } else {
         $this->assertFalse($style_included, 'The formidablepro stylesheet is included when it should not be');
     }
 }
Exemple #7
0
 public static function uninstall()
 {
     if (!current_user_can('administrator')) {
         $frm_settings = FrmAppHelper::get_settings();
         wp_die($frm_settings->admin_permission);
     }
     global $wpdb;
     $wpdb->query('DROP TABLE IF EXISTS ' . $wpdb->prefix . 'frm_display');
     delete_option('frmpro_options');
     delete_option('frmpro_db_version');
     //locations
     delete_option('frm_usloc_options');
     delete_option('frmpro_copies_db_version');
     delete_option('frmpro_copies_checked');
     // updating
     delete_site_option('frmpro-authorized');
     delete_site_option('frmpro-credentials');
     delete_site_option('frm_autoupdate');
     delete_site_option('frmpro-wpmu-sitewide');
 }
    public function pro_cred_form()
    {
        global $frm_vars;
        if ($_POST && isset($_POST['process_cred_form']) && $_POST['process_cred_form'] == 'Y') {
            if (!isset($_POST['frm_cred']) || !wp_verify_nonce($_POST['frm_cred'], 'frm_cred_nonce')) {
                $frm_settings = FrmAppHelper::get_settings();
                $response = array('response' => $frm_settings->admin_permission, 'auth' => false);
            } else {
                $response = $this->activate();
            }
            if ($response['auth']) {
                $frm_vars['pro_is_authorized'] = true;
                ?>
<div id="message" class="updated"><strong><?php 
                _e('Your Pro installation is now active. Enjoy!', 'formidable');
                ?>
</strong></div>
<?php 
            } else {
                ?>
<div class="error">
    <strong><?php 
                _e('ERROR', 'formidable');
                ?>
</strong>: <?php 
                echo $response['response'];
                ?>
</div>
<?php 
            }
        }
        ?>
<div id="frm_license_top">
    <?php 
        $this->display_form();
        if (!$frm_vars['pro_is_authorized']) {
            ?>
    <p>Already signed up? <a href="https://formidablepro.com/account/?action=licenses" target="_blank"><?php 
            _e('Click here', 'formidable');
            ?>
</a> to get your license number.</p>
    <?php 
        }
        ?>
</div>

<?php 
        if ($frm_vars['pro_is_authorized']) {
            ?>
<div class="frm_pro_installed">
<div><strong class="alignleft" style="margin-right:10px;"><?php 
            _e('Formidable Pro is Installed', 'formidable');
            ?>
</strong>
    <a href="javascript:void(0)" class="frm_show_auth_form button-secondary alignleft"><?php 
            _e('Enter new license', 'formidable');
            ?>
</a>
    <a href="#" id="frm_deauthorize_link" class="button-secondary alignright"><?php 
            _e('Deauthorize this site', 'formidable');
            ?>
</a>
    <div class="spinner"></div>
</div>
<div class="clear"></div>
</div>
<p class="frm_aff_link"><a href="https://formidablepro.com/account/?action=licenses" target="_blank"><?php 
            _e('Account', 'formidable');
            ?>
</a></p>
<?php 
        }
        ?>

<div class="clear"></div>

<?php 
    }
 public static function validate_recaptcha(&$errors, $field, $args)
 {
     if ($field->type != 'captcha' || FrmAppHelper::is_admin() || apply_filters('frm_is_field_hidden', false, $field, stripslashes_deep($_POST))) {
         return;
     }
     $frm_settings = FrmAppHelper::get_settings();
     if (empty($frm_settings->pubkey)) {
         // don't require the captcha if it shouldn't be shown
         return;
     }
     if (!isset($_POST['g-recaptcha-response'])) {
         // If captcha is missing, check if it was already verified
         if (!isset($_POST['recaptcha_checked']) || !wp_verify_nonce($_POST['recaptcha_checked'], 'frm_ajax')) {
             // There was no captcha submitted
             $errors['field' . $args['id']] = __('The captcha is missing from this form', 'formidable');
         }
         return;
     }
     $arg_array = array('body' => array('secret' => $frm_settings->privkey, 'response' => $_POST['g-recaptcha-response'], 'remoteip' => FrmAppHelper::get_ip_address()));
     $resp = wp_remote_post('https://www.google.com/recaptcha/api/siteverify', $arg_array);
     $response = json_decode(wp_remote_retrieve_body($resp), true);
     if (isset($response['success']) && !$response['success']) {
         // What happens when the CAPTCHA was entered incorrectly
         $errors['field' . $args['id']] = !isset($field->field_options['invalid']) || $field->field_options['invalid'] == '' ? $frm_settings->re_msg : $field->field_options['invalid'];
     } else {
         if (is_wp_error($resp)) {
             $error_string = $resp->get_error_message();
             $errors['field' . $args['id']] = __('There was a problem verifying your recaptcha', 'formidable');
             $errors['field' . $args['id']] .= ' ' . $error_string;
         }
     }
 }
 public static function destroy_all()
 {
     if (!current_user_can('frm_delete_entries')) {
         $frm_settings = FrmAppHelper::get_settings();
         wp_die($frm_settings->admin_permission);
     }
     global $wpdb;
     $params = FrmForm::get_admin_params();
     $message = '';
     $errors = array();
     $form_id = (int) $params['form'];
     if ($form_id) {
         $entry_ids = FrmDb::get_col('frm_items', array('form_id' => $form_id));
         $action = FrmFormAction::get_action_for_form($form_id, 'wppost', 1);
         if ($action) {
             // this action takes a while, so only trigger it if there are posts to delete
             foreach ($entry_ids as $entry_id) {
                 do_action('frm_before_destroy_entry', $entry_id);
                 unset($entry_id);
             }
         }
         $wpdb->query($wpdb->prepare("DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id));
         $results = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id));
         if ($results) {
             $message = __('Entries were Successfully Destroyed', 'formidable');
         }
     } else {
         $errors = __('No entries were specified', 'formidable');
     }
     self::display_list($message, $errors);
 }
 public static function get_form_contents($form, $title, $description, $atts)
 {
     global $frm_vars;
     $frm_settings = FrmAppHelper::get_settings();
     $submit = isset($form->options['submit_value']) ? $form->options['submit_value'] : $frm_settings->submit_value;
     $user_ID = get_current_user_id();
     $params = FrmForm::get_params($form);
     $message = $errors = '';
     if ($params['posted_form_id'] == $form->id && $_POST) {
         $errors = isset($frm_vars['created_entries'][$form->id]) ? $frm_vars['created_entries'][$form->id]['errors'] : array();
     }
     $include_form_tag = apply_filters('frm_include_form_tag', true, $form);
     $fields = FrmFieldsHelper::get_form_fields($form->id, isset($errors) && !empty($errors));
     if ($params['action'] != 'create' || $params['posted_form_id'] != $form->id || !$_POST) {
         do_action('frm_display_form_action', $params, $fields, $form, $title, $description);
         if (apply_filters('frm_continue_to_new', true, $form->id, $params['action'])) {
             $values = FrmEntriesHelper::setup_new_vars($fields, $form);
             include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
         }
         return;
     }
     if (!empty($errors)) {
         $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
         include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
         return;
     }
     do_action('frm_validate_form_creation', $params, $fields, $form, $title, $description);
     if (!apply_filters('frm_continue_to_create', true, $form->id)) {
         return;
     }
     $values = FrmEntriesHelper::setup_new_vars($fields, $form, true);
     $created = isset($frm_vars['created_entries']) && isset($frm_vars['created_entries'][$form->id]) ? $frm_vars['created_entries'][$form->id]['entry_id'] : 0;
     $conf_method = apply_filters('frm_success_filter', 'message', $form, $form->options, 'create');
     if ($created && is_numeric($created) && $conf_method != 'message') {
         do_action('frm_success_action', $conf_method, $form, $form->options, $created);
         do_action('frm_after_entry_processed', array('entry_id' => $created, 'form' => $form));
         return;
     }
     if ($created && is_numeric($created)) {
         $message = isset($form->options['success_msg']) ? $form->options['success_msg'] : $frm_settings->success_msg;
         $class = 'frm_message';
     } else {
         $message = $frm_settings->failed_msg;
         $class = 'frm_error_style';
     }
     $message = FrmFormsHelper::get_success_message(array('message' => $message, 'form' => $form, 'entry_id' => $created, 'class' => $class));
     $message = apply_filters('frm_main_feedback', $message, $form, $created);
     if (!isset($form->options['show_form']) || $form->options['show_form']) {
         require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/new.php';
     } else {
         global $frm_vars;
         self::maybe_load_css($form, $values['custom_style'], $frm_vars['load_css']);
         $include_extra_container = 'frm_forms' . FrmFormsHelper::get_form_style_class($values);
         include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/errors.php';
     }
     do_action('frm_after_entry_processed', array('entry_id' => $created, 'form' => $form));
 }
    public static function display_recaptcha($field)
    {
        $frm_settings = FrmAppHelper::get_settings();
        $lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field);
        $api_js_url = 'https://www.google.com/recaptcha/api.js';
        if ($lang != 'en') {
            $api_js_url .= '?hl=' . $lang;
        }
        $api_js_url = apply_filters('frm_recpatcha_js_url', $api_js_url);
        wp_register_script('recaptcha-api', $api_js_url, '', true);
        wp_enqueue_script('recaptcha-api');
        ?>
<div id="field_<?php 
        echo esc_attr($field['field_key']);
        ?>
" class="g-recaptcha" data-sitekey="<?php 
        echo esc_attr($frm_settings->pubkey);
        ?>
"></div>
<?php 
    }
    public static function display_recaptcha($field)
    {
        $frm_settings = FrmAppHelper::get_settings();
        $lang = apply_filters('frm_recaptcha_lang', $frm_settings->re_lang, $field);
        $class_prefix = '';
        $api_js_url = 'https://www.google.com/recaptcha/api.js?';
        $allow_mutiple = $frm_settings->re_multi;
        if ($allow_mutiple) {
            $api_js_url .= '&onload=frmRecaptcha&render=explicit';
            $class_prefix = 'frm-';
        }
        if ($lang != 'en') {
            $api_js_url .= '&hl=' . $lang;
        }
        $api_js_url = apply_filters('frm_recaptcha_js_url', $api_js_url);
        wp_register_script('recaptcha-api', $api_js_url, '', true);
        wp_enqueue_script('recaptcha-api');
        ?>
<div id="field_<?php 
        echo esc_attr($field['field_key']);
        ?>
" class="<?php 
        echo esc_attr($class_prefix);
        ?>
g-recaptcha" data-sitekey="<?php 
        echo esc_attr($frm_settings->pubkey);
        ?>
" data-size="<?php 
        echo esc_attr($field['captcha_size']);
        ?>
" data-theme="<?php 
        echo esc_attr($field['captcha_theme']);
        ?>
"></div>
<?php 
    }
 /**
  * Display the validation error messages when an entry is submitted
  *
  * @param array $args - includes img, errors
  * @since 2.0.6
  */
 public static function show_errors($args)
 {
     $frm_settings = FrmAppHelper::get_settings();
     if (empty($frm_settings->invalid_msg)) {
         $show_img = false;
     } else {
         echo wp_kses_post($frm_settings->invalid_msg);
         $show_img = true;
     }
     self::show_error(array('img' => $args['img'], 'errors' => $args['errors'], 'show_img' => $show_img));
 }
 public static function get_new_vars($errors = array(), $form = false, $message = '')
 {
     global $frm_vars;
     $description = true;
     $title = false;
     $form = apply_filters('frm_pre_display_form', $form);
     if (!$form) {
         wp_die(__('You are trying to access an entry that does not exist.', 'formidable'));
         return;
     }
     $fields = FrmFieldsHelper::get_form_fields($form->id, !empty($errors));
     $values = $fields ? FrmEntriesHelper::setup_new_vars($fields, $form) : array();
     $frm_settings = FrmAppHelper::get_settings();
     $submit = isset($frm_vars['next_page'][$form->id]) ? $frm_vars['next_page'][$form->id] : (isset($values['submit_value']) ? $values['submit_value'] : $frm_settings->submit_value);
     if (is_object($submit)) {
         $submit = $submit->name;
     }
     require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-entries/new.php';
 }
 public static function replace_html_shortcodes($html, $field, $atts)
 {
     if ('divider' == $field['type']) {
         global $frm_vars;
         $html = str_replace(array('frm_none_container', 'frm_hidden_container', 'frm_top_container', 'frm_left_container', 'frm_right_container'), '', $html);
         if (isset($frm_vars['collapse_div']) && $frm_vars['collapse_div']) {
             $html = "</div>\n" . $html;
             $frm_vars['collapse_div'] = false;
         }
         if (isset($frm_vars['div']) && $frm_vars['div'] && $frm_vars['div'] != $field['id']) {
             // close the div if it's from a different section
             $html = "</div>\n" . $html;
             $frm_vars['div'] = false;
         }
         if (FrmField::is_option_true($field, 'slide')) {
             $trigger = ' frm_trigger';
             $collapse_div = '<div class="frm_toggle_container" style="display:none;">';
         } else {
             $trigger = $collapse_div = '';
         }
         if (FrmField::is_option_true($field, 'repeat')) {
             $errors = isset($atts['errors']) ? $atts['errors'] : array();
             $field_name = 'item_meta[' . $field['id'] . ']';
             $html_id = FrmFieldsHelper::get_html_id($field);
             $frm_settings = FrmAppHelper::get_settings();
             ob_start();
             include FrmAppHelper::plugin_path() . '/classes/views/frm-fields/input.php';
             $input = ob_get_contents();
             ob_end_clean();
             if (FrmField::is_option_true($field, 'slide')) {
                 $input = $collapse_div . $input . '</div>';
             }
             $html = str_replace('[collapse_this]', $input, $html);
         } else {
             self::remove_close_div($field, $html);
             if (strpos($html, '[collapse_this]') !== false) {
                 $html = str_replace('[collapse_this]', $collapse_div, $html);
                 // indicate that a second div is open
                 if (!empty($collapse_div)) {
                     $frm_vars['collapse_div'] = $field['id'];
                 }
             }
         }
         self::maybe_add_collapse_icon($trigger, $field, $html);
         $html = str_replace('[collapse_class]', $trigger, $html);
     } else {
         if ($field['type'] == 'html') {
             if (apply_filters('frm_use_wpautop', true)) {
                 $html = wpautop($html);
             }
             $html = apply_filters('frm_get_default_value', $html, (object) $field, false);
             $html = do_shortcode($html);
         } else {
             if (FrmField::is_option_true($field, 'conf_field')) {
                 //Add confirmation field
                 //Get confirmation field ready for replace_shortcodes function
                 $conf_html = $field['custom_html'];
                 $conf_field = $field;
                 $conf_field['id'] = 'conf_' . $field['id'];
                 $conf_field['name'] = __('Confirm', 'formidable') . ' ' . $field['name'];
                 $conf_field['description'] = $field['conf_desc'];
                 $conf_field['field_key'] = 'conf_' . $field['field_key'];
                 if ($conf_field['classes']) {
                     $conf_field['classes'] = str_replace('first_', '', $conf_field['classes']);
                 } else {
                     if ($conf_field['conf_field'] == 'inline') {
                         $conf_field['classes'] = ' frm_half';
                     }
                 }
                 //Prevent loop
                 $conf_field['conf_field'] = 'stop';
                 //If inside of repeating section
                 $args = array();
                 if (isset($atts['section_id'])) {
                     $args['field_name'] = preg_replace('/\\[' . $field['id'] . '\\]$/', '', $atts['field_name']);
                     $args['field_name'] = $args['field_name'] . '[conf_' . $field['id'] . ']';
                     $args['field_id'] = 'conf_' . $atts['field_id'];
                     $args['field_plus_id'] = $atts['field_plus_id'];
                     $args['section_id'] = $atts['section_id'];
                 }
                 // Filter default value/placeholder text
                 $field['conf_input'] = apply_filters('frm_get_default_value', $field['conf_input'], (object) $field, false);
                 //If clear on focus, set default value. Otherwise, set value.
                 if ($conf_field['clear_on_focus'] == 1) {
                     $conf_field['default_value'] = $field['conf_input'];
                     $conf_field['value'] = '';
                 } else {
                     $conf_field['value'] = $field['conf_input'];
                 }
                 //If going back and forth between pages, keep value in confirmation field
                 if (isset($_POST['item_meta'])) {
                     $temp_args = array();
                     if (isset($atts['section_id'])) {
                         $temp_args = array('parent_field_id' => $atts['section_id'], 'key_pointer' => str_replace('-', '', $atts['field_plus_id']));
                     }
                     FrmEntriesHelper::get_posted_value($conf_field['id'], $conf_field['value'], $temp_args);
                 }
                 //Replace shortcodes
                 $conf_html = FrmFieldsHelper::replace_shortcodes($conf_html, $conf_field, '', '', $args);
                 //Add a couple of classes
                 $conf_html = str_replace('frm_primary_label', 'frm_primary_label frm_conf_label', $conf_html);
                 $conf_html = str_replace('frm_form_field', 'frm_form_field frm_conf_field', $conf_html);
                 //Remove label if stacked. Hide if inline.
                 if ($field['conf_field'] == 'inline') {
                     $conf_html = str_replace('frm_form_field', 'frm_form_field frm_hidden_container', $conf_html);
                 } else {
                     $conf_html = str_replace('frm_form_field', 'frm_form_field frm_none_container', $conf_html);
                 }
                 $html .= $conf_html;
             }
         }
     }
     if (strpos($html, '[collapse_this]')) {
         $html = str_replace('[collapse_this]', '', $html);
     }
     return $html;
 }
 private static function add_html_placeholder($field, array &$add_html, array &$class)
 {
     if (empty($field['default_value']) || FrmAppHelper::is_admin_page('formidable')) {
         return;
     }
     if (!FrmField::is_option_true($field, 'clear_on_focus')) {
         if (is_array($field['default_value'])) {
             $field['default_value'] = json_encode($field['default_value']);
         }
         $add_html['data-frmval'] = 'data-frmval="' . esc_attr($field['default_value']) . '"';
         return;
     }
     $frm_settings = FrmAppHelper::get_settings();
     if ($frm_settings->use_html && !in_array($field['type'], array('select', 'radio', 'checkbox', 'hidden'))) {
         // use HMTL5 placeholder with js fallback
         $add_html['placeholder'] = 'placeholder="' . esc_attr($field['default_value']) . '"';
         wp_enqueue_script('jquery-placeholder');
     } else {
         if (!$frm_settings->use_html) {
             $val = str_replace(array("\r\n", "\n"), '\\r', addslashes(str_replace('&#039;', "'", esc_attr($field['default_value']))));
             $add_html['data-frmval'] = 'data-frmval="' . esc_attr($val) . '"';
             $class[] = 'frm_toggle_default';
             if ($field['value'] == $field['default_value']) {
                 $class[] = 'frm_default';
             }
         }
     }
 }
 public static function setup_new_vars($fields, $form = '', $reset = false)
 {
     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) {
         $default = $field->default_value;
         $posted_val = false;
         $new_value = $default;
         if (!$reset && $_POST && isset($_POST['item_meta'][$field->id]) && $_POST['item_meta'][$field->id] != '') {
             $new_value = stripslashes_deep($_POST['item_meta'][$field->id]);
             $posted_val = true;
         } else {
             if (FrmField::is_option_true($field, 'clear_on_focus')) {
                 $new_value = '';
             }
         }
         $is_default = $new_value == $default ? true : false;
         //If checkbox, multi-select dropdown, or checkbox data from entries field, set return array to true
         $return_array = FrmField::is_field_with_multiple_values($field);
         $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true, $return_array);
         if (!is_array($new_value)) {
             if ($is_default) {
                 $new_value = $field->default_value;
             } else {
                 if (!$posted_val) {
                     $new_value = apply_filters('frm_filter_default_value', $new_value, $field);
                 }
             }
             $new_value = str_replace('"', '&quot;', $new_value);
         }
         unset($is_default, $posted_val);
         $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);
         $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);
 }
 /**
  * @since 2.2.10
  * @param array $post_values
  * @return boolean|int
  */
 public static function custom_style_value($post_values)
 {
     if ($post_values && isset($post_values['options']['custom_style'])) {
         $custom_style = absint($post_values['options']['custom_style']);
     } else {
         $frm_settings = FrmAppHelper::get_settings();
         $custom_style = $frm_settings->load_style != 'none';
     }
     return $custom_style;
 }
 public static function get_menu_name()
 {
     $frm_settings = FrmAppHelper::get_settings();
     return $frm_settings->menu;
 }
 public static function validate_number_field(&$errors, $field, $value)
 {
     //validate the number format
     if ($field->type != 'number') {
         return;
     }
     if (!is_numeric($value)) {
         $errors['field' . $field->temp_id] = FrmFieldsHelper::get_error_msg($field, 'invalid');
     }
     // validate number settings
     if ($value != '') {
         $frm_settings = FrmAppHelper::get_settings();
         // only check if options are available in settings
         if ($frm_settings->use_html && isset($field->field_options['minnum']) && isset($field->field_options['maxnum'])) {
             //minnum maxnum
             if ((double) $value < $field->field_options['minnum']) {
                 $errors['field' . $field->temp_id] = __('Please select a higher number', 'formidable');
             } else {
                 if ((double) $value > $field->field_options['maxnum']) {
                     $errors['field' . $field->temp_id] = __('Please select a lower number', 'formidable');
                 }
             }
         }
     }
 }
Exemple #22
0
 public function uninstall()
 {
     if (!current_user_can('administrator')) {
         $frm_settings = FrmAppHelper::get_settings();
         wp_die($frm_settings->admin_permission);
     }
     global $wpdb, $wp_roles;
     $wpdb->query('DROP TABLE IF EXISTS ' . $this->fields);
     $wpdb->query('DROP TABLE IF EXISTS ' . $this->forms);
     $wpdb->query('DROP TABLE IF EXISTS ' . $this->entries);
     $wpdb->query('DROP TABLE IF EXISTS ' . $this->entry_metas);
     delete_option('frm_options');
     delete_option('frm_db_version');
     //delete roles
     $frm_roles = FrmAppHelper::frm_capabilities();
     $roles = get_editable_roles();
     foreach ($frm_roles as $frm_role => $frm_role_description) {
         foreach ($roles as $role => $details) {
             $wp_roles->remove_cap($role, $frm_role);
             unset($role, $details);
         }
         unset($frm_role, $frm_role_description);
     }
     unset($roles, $frm_roles);
     // delete actions, views, and styles
     // prevent the post deletion from triggering entries to be deleted
     remove_action('before_delete_post', 'FrmProDisplaysController::before_delete_post');
     remove_action('deleted_post', 'FrmProEntriesController::delete_entry');
     $post_ids = $wpdb->get_col($wpdb->prepare('SELECT ID FROM ' . $wpdb->posts . ' WHERE post_type in (%s, %s, %s)', FrmFormActionsController::$action_post_type, FrmStylesController::$post_type, 'frm_display'));
     foreach ($post_ids as $post_id) {
         // Delete's each post.
         wp_delete_post($post_id, true);
     }
     unset($post_ids);
     // delete transients
     delete_transient('frmpro_css');
     delete_transient('frm_options');
     delete_transient('frmpro_options');
     $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE %s OR option_name LIKE %s', '_transient_timeout_frm_form_fields_%', '_transient_frm_form_fields_%'));
     do_action('frm_after_uninstall');
     return true;
 }
                                ?>
 <?php 
                                do_action('frm_field_input_html', $field);
                                ?>
 /><?php 
                                if (!isset($atts) || !isset($atts['label']) || $atts['label']) {
                                    echo ' ' . $opt . '</label>';
                                }
                                FrmFieldsHelper::include_other_input(array('other_opt' => $other_opt, 'read_only' => $read_only, 'checked' => $checked, 'name' => $other_args['name'], 'value' => $other_args['value'], 'field' => $field, 'html_id' => $html_id, 'opt_key' => $opt_key));
                                unset($other_opt, $other_args, $checked);
                                ?>
</div>
<?php 
                            }
                        }
                    }
                } else {
                    if ($field['type'] == 'captcha' && !FrmAppHelper::is_admin()) {
                        $frm_settings = FrmAppHelper::get_settings();
                        if (!empty($frm_settings->pubkey)) {
                            FrmFieldsHelper::display_recaptcha($field);
                        }
                    } else {
                        do_action('frm_form_fields', $field, $field_name, compact('errors', 'html_id'));
                        do_action('frm_form_field_' . $field['type'], $field, $field_name, compact('errors', 'html_id'));
                    }
                }
            }
        }
    }
}
 /**
  * Check if the Formidable styling should be loaded,
  * then enqueue it for the footer
  * @since 2.0
  */
 public static function enqueue_style()
 {
     global $frm_vars;
     if (isset($frm_vars['css_loaded']) && $frm_vars['css_loaded']) {
         // the CSS has already been loaded
         return;
     }
     $frm_settings = FrmAppHelper::get_settings();
     if ($frm_settings->load_style != 'none') {
         wp_enqueue_style('formidable');
         $frm_vars['css_loaded'] = true;
     }
 }
 public static function options_form($field, $display, $values)
 {
     remove_action('frm_field_options_form', 'FrmFieldsController::add_conditional_update_msg', 50);
     global $frm_vars;
     $frm_settings = FrmAppHelper::get_settings();
     $form_fields = false;
     if ($display['logic'] && !empty($field['hide_field']) && is_array($field['hide_field'])) {
         $form_fields = FrmField::get_all_for_form($values['id']);
     }
     if ('data' == $field['type']) {
         $frm_field_selection = FrmField::pro_field_selection();
     }
     if ($field['type'] == 'date') {
         $locales = FrmAppHelper::locales('date');
     } else {
         if ($field['type'] == 'file') {
             $mimes = get_allowed_mime_types();
         }
     }
     require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/options-form.php';
 }
 public static function page_route($content)
 {
     global $post;
     $frm_settings = FrmAppHelper::get_settings();
     if ($post && $post->ID == $frm_settings->preview_page_id && isset($_GET['form'])) {
         $content = FrmFormsController::page_preview();
     }
     return $content;
 }
 public static function submit_button_label($submit)
 {
     if (!$submit || empty($submit)) {
         $frm_settings = FrmAppHelper::get_settings();
         $submit = $frm_settings->submit_value;
     }
     return $submit;
 }