Esempio n. 1
0
 public static function install($force = false)
 {
     $db_version = 1.2;
     // this is the version of the database we're moving to
     $old_db_version = get_site_option('frmpro_copies_db_version');
     global $wpdb;
     if ($db_version != $old_db_version || $force) {
         $force = true;
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         $frmdb = new FrmDb();
         $charset_collate = $frmdb->collation();
         /* Create/Upgrade Display Table */
         $sql = 'CREATE TABLE ' . self::table_name() . ' (
                 id int(11) NOT NULL auto_increment,
                 type varchar(255) default NULL,
                 copy_key varchar(255) default NULL,
                 form_id int(11) default NULL,
                 blog_id int(11) default NULL,
                 created_at datetime NOT NULL,
                 PRIMARY KEY id (id),
                 KEY form_id (form_id),
                 KEY blog_id (blog_id)
         ) ' . $charset_collate . ';';
         dbDelta($sql);
         update_site_option('frmpro_copies_db_version', $db_version);
     }
     self::copy_forms($force);
 }
 /**
  * @covers FrmDb::uninstall
  */
 public function test_uninstall()
 {
     $this->set_as_user_role('administrator');
     $frmdb = new FrmDb();
     $uninstalled = $frmdb->uninstall();
     $this->assertTrue($uninstalled);
     $this->markTestIncomplete('Make sure uninstall is complete');
     $this->do_tables_exist(false);
     $this->assertEmpty(get_option('frm_db_version', true));
     $this->assertEmpty(get_option('frm_options', true));
     // TODO: Check if roles exist FrmAppHelper::frm_capabilities()
     // TODO: Check if any posts exist for extra types
     // TODO: Check if transients exist: frmpro_css, frm_options, frmpro_options, %frm_form_fields%
 }
Esempio n. 3
0
 function form($form_action, $args = array())
 {
     global $wpdb;
     extract($args);
     $post_types = FrmProAppHelper::get_custom_post_types();
     if (!$post_types) {
         return;
     }
     $post_type = FrmProFormsHelper::post_type($args['values']['id']);
     $taxonomies = get_object_taxonomies($post_type);
     $action_control = $this;
     $echo = true;
     $form_id = $form->id;
     $display = false;
     $displays = array();
     $display_ids = FrmDb::get_col($wpdb->postmeta, array('meta_key' => 'frm_form_id', 'meta_value' => $form_id), 'post_ID');
     if ($display_ids) {
         $query_args = array('pm.meta_key' => 'frm_show_count', 'post_type' => 'frm_display', 'pm.meta_value' => array('dynamic', 'calendar', 'one'), 'p.post_status' => array('publish', 'private'), 'p.ID' => $display_ids);
         $displays = FrmDb::get_results($wpdb->posts . ' p LEFT JOIN ' . $wpdb->postmeta . ' pm ON (p.ID = pm.post_ID)', $query_args, 'p.ID, p.post_title', array('order_by' => 'p.post_title ASC'));
         if (isset($form_action->post_content['display_id'])) {
             // get view from settings
             if (is_numeric($form_action->post_content['display_id'])) {
                 $display = FrmProDisplay::getOne($form_action->post_content['display_id'], false, true);
             }
         } else {
             if (!is_numeric($form_action->post_content['post_content']) && !empty($display_ids)) {
                 // get auto view
                 $display = FrmProDisplay::get_form_custom_display($form_id);
                 if ($display) {
                     $display = FrmProDisplaysHelper::setup_edit_vars($display, true);
                 }
             }
         }
     }
     // Get array of all custom fields
     $custom_fields = array();
     if (isset($form_action->post_content['post_custom_fields'])) {
         foreach ($form_action->post_content['post_custom_fields'] as $custom_field_opts) {
             if (isset($custom_field_opts['meta_name'])) {
                 $custom_fields[] = $custom_field_opts['meta_name'];
             }
             unset($custom_field_opts);
         }
     }
     unset($display_ids);
     include dirname(__FILE__) . '/post_options.php';
 }
Esempio n. 4
0
 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));
 }
 public static function generate_csv($atts)
 {
     global $frm_vars;
     $frm_vars['prevent_caching'] = true;
     self::$fields = $atts['form_cols'];
     self::$form_id = $atts['form']->id;
     self::set_class_paramters();
     $filename = apply_filters('frm_csv_filename', date('ymdHis', time()) . '_' . sanitize_title_with_dashes($atts['form']->name) . '_formidable_entries.csv', $atts['form']);
     unset($atts['form'], $atts['form_cols']);
     self::print_file_headers($filename);
     unset($filename);
     $comment_count = FrmDb::get_count('frm_item_metas', array('item_id' => $atts['entry_ids'], 'field_id' => 0, 'meta_value like' => '{'), array('group_by' => 'item_id', 'order_by' => 'count(*) DESC', 'limit' => 1));
     self::$comment_count = $comment_count;
     self::prepare_csv_headings();
     // fetch 20 posts at a time rather than loading the entire table into memory
     while ($next_set = array_splice($atts['entry_ids'], 0, 20)) {
         self::prepare_next_csv_rows($next_set);
     }
 }
 public static function formidable_shortcode_atts($atts, $all_atts)
 {
     global $frm_vars, $wpdb;
     // reset globals
     $frm_vars['readonly'] = $atts['readonly'];
     $frm_vars['editing_entry'] = false;
     $frm_vars['show_fields'] = array();
     $frm_vars['editing_entry'] = false;
     if (!is_array($atts['fields'])) {
         $frm_vars['show_fields'] = explode(',', $atts['fields']);
     }
     if (!empty($atts['exclude_fields'])) {
         if (!is_array($atts['exclude_fields'])) {
             $atts['exclude_fields'] = explode(',', $atts['exclude_fields']);
         }
         $query = array('form_id' => (int) $atts['id'], 'id NOT' => $atts['exclude_fields'], 'field_key NOT' => $atts['exclude_fields']);
         $frm_vars['show_fields'] = FrmDb::get_col($wpdb->prefix . 'frm_fields', $query);
     }
     if ($atts['entry_id'] && $atts['entry_id'] == 'last') {
         $user_ID = get_current_user_id();
         if ($user_ID) {
             $frm_vars['editing_entry'] = FrmDb::get_var($wpdb->prefix . 'frm_items', array('form_id' => $atts['id'], 'user_id' => $user_ID), 'id', array('order_by' => 'created_at DESC'));
         }
     } else {
         if ($atts['entry_id']) {
             $frm_vars['editing_entry'] = $atts['entry_id'];
         }
     }
     foreach ($atts as $unset => $val) {
         if (is_array($all_atts) && isset($all_atts[$unset])) {
             unset($all_atts[$unset]);
         }
         unset($unset, $val);
     }
     if (is_array($all_atts)) {
         foreach ($all_atts as $att => $val) {
             $_GET[$att] = urlencode($val);
             unset($att, $val);
         }
     }
 }
Esempio n. 7
0
 /**
  * @param string $table_name
  */
 public static function &getRecordCount($where = '', $table_name)
 {
     _deprecated_function(__FUNCTION__, '2.0', 'FrmDb::get_count');
     $count = FrmDb::get_count($table_name, $where);
     return $count;
 }
 public static function duplicate()
 {
     check_ajax_referer('frm_ajax', 'nonce');
     global $wpdb;
     $field_id = FrmAppHelper::get_post_param('field_id', 0, 'absint');
     $form_id = FrmAppHelper::get_post_param('form_id', 0, 'absint');
     $copy_field = FrmField::getOne($field_id);
     if (!$copy_field) {
         wp_die();
     }
     do_action('frm_duplicate_field', $copy_field, $form_id);
     do_action('frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id);
     $values = array('id' => $form_id);
     FrmFieldsHelper::fill_field($values, $copy_field, $form_id);
     $field_count = FrmDb::get_count($wpdb->prefix . 'frm_fields fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id)', array('or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id));
     $values['field_order'] = $field_count + 1;
     if (!($field_id = FrmField::create($values))) {
         wp_die();
     }
     self::include_single_field($field_id, $values);
     wp_die();
 }
Esempio n. 9
0
 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';
 }
Esempio n. 10
0
 function get_records($table, $args = array(), $order_by = '', $limit = '', $fields = '*')
 {
     global $wpdb;
     extract(FrmDb::get_where_clause_and_values($args));
     if (!empty($order_by)) {
         $order_by = " ORDER BY {$order_by}";
     }
     if (!empty($limit)) {
         $limit = " LIMIT {$limit}";
     }
     $query = "SELECT {$fields} FROM {$table}{$where}{$order_by}{$limit}";
     $query = $wpdb->prepare($query, $values);
     return $wpdb->get_results($query);
 }
Esempio n. 11
0
 public static function get_search_ids($s, $form_id, $args = array())
 {
     global $wpdb;
     if (empty($s)) {
         return false;
     }
     preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
     $search_terms = array_map('trim', $matches[0]);
     $spaces = '';
     $e_ids = $p_search = array();
     $search = array('or' => 1);
     $data_field = FrmProFormsHelper::has_field('data', $form_id, false);
     foreach ((array) $search_terms as $term) {
         $p_search[] = array($spaces . $wpdb->posts . '.post_title like' => $term, $spaces . $wpdb->posts . '.post_content like' => $term, 'or' => 1);
         $search[$spaces . 'meta_value like'] = $term;
         $spaces .= ' ';
         // add a space to keep the array keys unique
         if (is_numeric($term)) {
             $e_ids[] = (int) $term;
         }
         if ($data_field) {
             $df_form_ids = array();
             //search the joined entry too
             foreach ((array) $data_field as $df) {
                 FrmProFieldsHelper::get_subform_ids($df_form_ids, $df);
                 unset($df);
             }
             $data_form_ids = FrmDb::get_col($wpdb->prefix . 'frm_fields', array('id' => $df_form_ids), 'form_id');
             unset($df_form_ids);
             if ($data_form_ids) {
                 $data_entry_ids = FrmEntryMeta::getEntryIds(array('fi.form_id' => $data_form_ids, 'meta_value like' => $term));
                 if ($data_entry_ids) {
                     if (!isset($search['meta_value'])) {
                         $search['meta_value'] = array();
                     }
                     $search['meta_value'] = array_merge($search['meta_value'], $data_entry_ids);
                 }
             }
             unset($data_form_ids);
         }
     }
     $matching_posts = FrmDb::get_col($wpdb->posts, $p_search, 'ID');
     $p_ids = array($search, 'or' => 1);
     if ($matching_posts) {
         $post_ids = FrmDb::get_col($wpdb->prefix . 'frm_items', array('post_id' => $matching_posts, 'form_id' => (int) $form_id));
         if ($post_ids) {
             $p_ids['item_id'] = $post_ids;
         }
     }
     if (!empty($e_ids)) {
         $p_ids['item_id'] = $e_ids;
     }
     $query = array('fi.form_id' => $form_id);
     $query[] = $p_ids;
     return FrmEntryMeta::getEntryIds($query, '', '', true, $args);
 }
Esempio n. 12
0
 /**
  * @param string $key
  * @return int entry_id
  */
 public static function get_id_by_key($key)
 {
     $entry_id = FrmDb::get_var('frm_items', array('item_key' => sanitize_title($key)));
     return $entry_id;
 }
 /**
  * Export to CSV
  * @since 2.0.19
  */
 public static function csv($form_id = false, $search = '', $fid = '')
 {
     FrmAppHelper::permission_check('frm_view_entries');
     if (!$form_id) {
         $form_id = FrmAppHelper::get_param('form', '', 'get', 'sanitize_text_field');
         $search = FrmAppHelper::get_param(isset($_REQUEST['s']) ? 's' : 'search', '', 'get', 'sanitize_text_field');
         $fid = FrmAppHelper::get_param('fid', '', 'get', 'sanitize_text_field');
     }
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
         //Remove time limit to execute this function
         $mem_limit = str_replace('M', '', ini_get('memory_limit'));
         if ((int) $mem_limit < 256) {
             ini_set('memory_limit', '256M');
         }
     }
     global $wpdb;
     $form = FrmForm::getOne($form_id);
     $form_id = $form->id;
     $form_cols = self::get_fields_for_csv_export($form_id, $form);
     $item_id = FrmAppHelper::get_param('item_id', 0, 'get', 'sanitize_text_field');
     if (!empty($item_id)) {
         $item_id = explode(',', $item_id);
     }
     $query = array('form_id' => $form_id);
     if ($item_id) {
         $query['id'] = $item_id;
     }
     /**
      * Allows the query to be changed for fetching the entry ids to include in the export
      *
      * $query is the array of options to be filtered. It includes form_id, and maybe id (array of entry ids),
      * and the search query. This should return an array, but it can be handled as a string as well.
      */
     $query = apply_filters('frm_csv_where', $query, compact('form_id', 'search', 'fid', 'item_id'));
     $entry_ids = FrmDb::get_col($wpdb->prefix . 'frm_items it', $query);
     unset($query);
     if (empty($entry_ids)) {
         esc_html_e('There are no entries for that form.', 'formidable');
     } else {
         FrmCSVExportHelper::generate_csv(compact('form', 'entry_ids', 'form_cols'));
     }
     wp_die();
 }
Esempio n. 14
0
 /**
  * if there are posts linked to entries for this form
  */
 private static function prepare_post_filter($args, $where_field, &$new_ids)
 {
     if (empty($args['form_posts'])) {
         // there are not posts related to this view
         return;
     }
     if (!isset($where_field->field_options['post_field']) || !in_array($where_field->field_options['post_field'], array('post_category', 'post_custom', 'post_status', 'post_content', 'post_excerpt', 'post_title', 'post_name', 'post_date'))) {
         // this is not a post field
         return;
     }
     $post_ids = array();
     foreach ($args['form_posts'] as $form_post) {
         $post_ids[$form_post->post_id] = $form_post->id;
         if (!in_array($form_post->id, $new_ids)) {
             $new_ids[] = $form_post->id;
         }
     }
     if (empty($post_ids)) {
         return;
     }
     global $wpdb;
     $filter_args = array();
     if ($where_field->field_options['post_field'] == 'post_category') {
         //check categories
         $args['temp_where_is'] = FrmDb::append_where_is(str_replace(array('!', 'not '), '', $args['where_is']));
         $t_where = array('or' => 1, 't.term_id ' . $args['temp_where_is'] => $args['where_val'], 't.slug ' . $args['temp_where_is'] => $args['where_val'], 't.name ' . $args['temp_where_is'] => $args['where_val']);
         unset($args['temp_where_is']);
         $query = array('tt.taxonomy' => $where_field->field_options['taxonomy']);
         $query[] = $t_where;
         self::add_group_by($filter_args, $args, 'tr.object_id');
         $add_posts = FrmDb::get_col($wpdb->terms . ' AS t INNER JOIN ' . $wpdb->term_taxonomy . ' AS tt ON tt.term_id = t.term_id INNER JOIN ' . $wpdb->term_relationships . ' AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id', $query, 'tr.object_id', $filter_args);
         $add_posts = array_intersect($add_posts, array_keys($post_ids));
         if (in_array($args['where_is'], array('!=', 'not LIKE'))) {
             $remove_posts = $add_posts;
             $add_posts = false;
         } else {
             if (empty($add_posts)) {
                 $new_ids = array();
                 return;
             }
         }
     } else {
         $query = array();
         if ($where_field->field_options['post_field'] == 'post_custom' && $where_field->field_options['custom_field'] != '') {
             //check custom fields
             $get_field = 'post_id';
             $get_table = $wpdb->postmeta;
             $query['meta_key'] = $where_field->field_options['custom_field'];
             $query_key = 'meta_value';
         } else {
             //if field is post field
             $get_field = 'ID';
             $get_table = $wpdb->posts;
             $query_key = sanitize_title($where_field->field_options['post_field']);
         }
         self::add_group_by($filter_args, $args, $query_key);
         $query_key .= (in_array($where_field->type, array('number', 'scale')) ? ' +0 ' : ' ') . FrmDb::append_where_is($args['where_is']);
         $query[$query_key] = $args['where_val'];
         $add_posts = FrmDb::get_col($get_table, $query, $get_field, $filter_args);
         $add_posts = array_intersect($add_posts, array_keys($post_ids));
     }
     if ($add_posts && !empty($add_posts)) {
         $new_ids = array();
         foreach ($add_posts as $add_post) {
             if (!in_array($post_ids[$add_post], $new_ids)) {
                 $new_ids[] = $post_ids[$add_post];
             }
         }
     }
     if (isset($remove_posts)) {
         if (!empty($remove_posts)) {
             foreach ($remove_posts as $remove_post) {
                 $key = array_search($post_ids[$remove_post], $new_ids);
                 if ($key && $new_ids[$key] == $post_ids[$remove_post]) {
                     unset($new_ids[$key]);
                 }
                 unset($key);
             }
         }
     } else {
         if (!$add_posts) {
             $new_ids = array();
         }
     }
 }
Esempio n. 15
0
    public static function get_shortcode_select($form_id, $target_id = 'content', $type = 'all')
    {
        $field_list = array();
        $exclude = FrmField::no_save_fields();
        if (is_numeric($form_id)) {
            if ($type == 'field_opt') {
                $exclude[] = 'data';
                $exclude[] = 'checkbox';
            }
            $field_list = FrmField::get_all_for_form($form_id, '', 'include');
        }
        $linked_forms = array();
        ?>
        <select class="frm_shortcode_select frm_insert_val" data-target="<?php 
        echo esc_attr($target_id);
        ?>
">
            <option value="">&mdash; <?php 
        _e('Select a value to insert into the box below', 'formidable');
        ?>
 &mdash;</option>
            <?php 
        if ($type != 'field_opt' && $type != 'calc') {
            ?>
            <option value="id"><?php 
            _e('Entry ID', 'formidable');
            ?>
</option>
            <option value="key"><?php 
            _e('Entry Key', 'formidable');
            ?>
</option>
            <option value="post_id"><?php 
            _e('Post ID', 'formidable');
            ?>
</option>
            <option value="ip"><?php 
            _e('User IP', 'formidable');
            ?>
</option>
            <option value="created-at"><?php 
            _e('Entry creation date', 'formidable');
            ?>
</option>
            <option value="updated-at"><?php 
            _e('Entry update date', 'formidable');
            ?>
</option>

			<optgroup label="<?php 
            esc_attr_e('Form Fields', 'formidable');
            ?>
">
            <?php 
        }
        if (!empty($field_list)) {
            foreach ($field_list as $field) {
                if (in_array($field->type, $exclude)) {
                    continue;
                }
                if ($type != 'calc' && FrmProField::is_list_field($field)) {
                    continue;
                }
                ?>
                <option value="<?php 
                echo esc_attr($field->id);
                ?>
"><?php 
                echo $field_name = esc_html(FrmAppHelper::truncate($field->name, 60));
                ?>
 (<?php 
                _e('ID', 'formidable');
                ?>
)</option>
                <option value="<?php 
                echo esc_attr($field->field_key);
                ?>
"><?php 
                echo $field_name;
                ?>
 (<?php 
                _e('Key', 'formidable');
                ?>
)</option>
                <?php 
                if ($field->type == 'file' && $type != 'field_opt' && $type != 'calc') {
                    ?>
                    <option class="frm_subopt" value="<?php 
                    echo esc_attr($field->field_key);
                    ?>
 size=thumbnail"><?php 
                    _e('Thumbnail', 'formidable');
                    ?>
</option>
                    <option class="frm_subopt" value="<?php 
                    echo esc_attr($field->field_key);
                    ?>
 size=medium"><?php 
                    _e('Medium', 'formidable');
                    ?>
</option>
                    <option class="frm_subopt" value="<?php 
                    echo esc_attr($field->field_key);
                    ?>
 size=large"><?php 
                    _e('Large', 'formidable');
                    ?>
</option>
                    <option class="frm_subopt" value="<?php 
                    echo esc_attr($field->field_key);
                    ?>
 size=full"><?php 
                    _e('Full Size', 'formidable');
                    ?>
</option>
                <?php 
                } else {
                    if ($field->type == 'data') {
                        //get all fields from linked form
                        if (isset($field->field_options['form_select']) && is_numeric($field->field_options['form_select'])) {
                            $linked_form = FrmDb::get_var('frm_fields', array('id' => $field->field_options['form_select']), 'form_id');
                            if (!in_array($linked_form, $linked_forms)) {
                                $linked_forms[] = $linked_form;
                                $linked_fields = FrmField::getAll(array('fi.type not' => FrmField::no_save_fields(), 'fi.form_id' => (int) $linked_form));
                                foreach ($linked_fields as $linked_field) {
                                    ?>
                    <option class="frm_subopt" value="<?php 
                                    echo esc_attr($field->id . ' show=' . $linked_field->id);
                                    ?>
"><?php 
                                    echo esc_html(FrmAppHelper::truncate($linked_field->name, 60));
                                    ?>
 (<?php 
                                    _e('ID', 'formidable');
                                    ?>
)</option>
                    <option class="frm_subopt" value="<?php 
                                    echo esc_attr($field->field_key . ' show=' . $linked_field->field_key);
                                    ?>
"><?php 
                                    echo esc_html(FrmAppHelper::truncate($linked_field->name, 60));
                                    ?>
 (<?php 
                                    _e('Key', 'formidable');
                                    ?>
)</option>
                    <?php 
                                }
                            }
                        }
                    }
                }
            }
        }
        if ($type != 'field_opt' && $type != 'calc') {
            ?>
            </optgroup>
			<optgroup label="<?php 
            esc_attr_e('Helpers', 'formidable');
            ?>
">
                <option value="editlink"><?php 
            _e('Admin link to edit the entry', 'formidable');
            ?>
</option>
                <?php 
            if ($target_id == 'content') {
                ?>
                <option value="detaillink"><?php 
                _e('Link to view single page if showing dynamic entries', 'formidable');
                ?>
</option>
                <?php 
            }
            if ($type != 'email') {
                ?>
                <option value="evenodd"><?php 
                _e('Add a rotating \'even\' or \'odd\' class', 'formidable');
                ?>
</option>
                <?php 
            } else {
                if ($target_id == 'email_message') {
                    ?>
                <option value="default-message"><?php 
                    _e('Default Email Message', 'formidable');
                    ?>
</option>
                <?php 
                }
            }
            ?>
                <option value="siteurl"><?php 
            _e('Site URL', 'formidable');
            ?>
</option>
                <option value="sitename"><?php 
            _e('Site Name', 'formidable');
            ?>
</option>
            </optgroup>
            <?php 
        }
        ?>
        </select>
    <?php 
    }
Esempio n. 16
0
 /**
  * @return int count of forms
  */
 public static function &get_count()
 {
     global $wpdb;
     $cache_key = 'frm_form_counts';
     $counts = wp_cache_get($cache_key, 'counts');
     if (false !== $counts) {
         return $counts;
     }
     $results = (array) FrmDb::get_results('frm_forms', array('or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0), 'status, is_template');
     $statuses = array('published', 'draft', 'template', 'trash');
     $counts = array_fill_keys($statuses, 0);
     foreach ($results as $row) {
         if ('trash' != $row->status) {
             if ($row->is_template) {
                 $counts['template']++;
             } else {
                 $counts['published']++;
             }
         } else {
             $counts['trash']++;
         }
         if ('draft' == $row->status) {
             $counts['draft']++;
         }
         unset($row);
     }
     $counts = (object) $counts;
     wp_cache_set($cache_key, $counts, 'counts');
     return $counts;
 }
 /**
  * @covers FrmProFieldsHelper::move_entries_to_child_form
  */
 function _check_if_child_entries_created($args, $child_form_id)
 {
     global $wpdb;
     // Check for value in repeating section
     $rep_meta_values = $wpdb->get_col("SELECT meta_value FROM " . $wpdb->prefix . "frm_item_metas WHERE field_id=" . $args['field_id']);
     $this->assertNotEmpty($rep_meta_values, 'When switching from non-repeating to repeating, the repeating section frm_item_metas is not saving the IDs of the child entries.');
     // Check if entries were created in child form
     $child_items = FrmEntry::getAll(array('it.form_id' => $child_form_id));
     $parent_items = FrmEntry::getAll(array('it.form_id' => $args['parent_form_id']));
     $this->assertEquals(count($parent_items), count($child_items), 'When switching from non-repeating to repeating section, child entries are not created. ');
     // Check if entries in child form match IDs saved in repeating section frm_item_metas
     $child_ids = array_keys($child_items);
     $this->assertEquals($child_ids, $rep_meta_values, 'When switching from non-repeating to repeating, created entry IDs do not match IDs saved in repeating section field frm_item_metas.');
     // Check if the item_id for child field frm_item_metas was updated to match new child entry IDs
     $new_child_metas = FrmDb::get_col($wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_items it ON it.id=m.item_id', array('field_id' => $args['children']), 'm.item_id', array('order_by' => 'it.created_at ASC'));
     $new_child_metas = array_unique($new_child_metas);
     $this->assertEquals($child_ids, $new_child_metas, 'When switching from non-repeating to repeating, the item_id is not updated on frm_item_metas for child fields');
 }
Esempio n. 18
0
 public static function get_default_field_opts($type, $field, $limit = false)
 {
     $field_options = array('size' => '', 'max' => '', 'label' => '', 'blank' => '', 'required_indicator' => '*', 'invalid' => '', 'separate_value' => 0, 'clear_on_focus' => 0, 'default_blank' => 0, 'classes' => '', 'custom_html' => '');
     if ($limit) {
         return $field_options;
     }
     global $wpdb;
     $form_id = is_numeric($field) ? $field : $field->form_id;
     $key = is_numeric($field) ? FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_fields', 'field_key') : $field->field_key;
     $field_count = FrmDb::get_var('frm_fields', array('form_id' => $form_id), 'field_order', array('order_by' => 'field_order DESC'));
     $frm_settings = FrmAppHelper::get_settings();
     return array('name' => __('Untitled', 'formidable'), 'description' => '', 'field_key' => $key, 'type' => $type, 'options' => '', 'default_value' => '', 'field_order' => $field_count + 1, 'required' => false, 'blank' => $frm_settings->blank_msg, 'unique_msg' => $frm_settings->unique_msg, 'invalid' => __('This field is invalid', 'formidable'), 'form_id' => $form_id, 'field_options' => $field_options);
 }
Esempio n. 19
0
 $linked_forms[] = array();
 foreach ($fields as $f) {
     if (FrmField::is_repeating_field($f)) {
         $repeat_field = $f->id;
     }
     if (FrmField::is_no_save_field($f->type)) {
         continue;
     }
     if ($f->type == 'data' && (!isset($f->field_options['data_type']) || $f->field_options['data_type'] == 'data' || $f->field_options['data_type'] == '')) {
         continue;
     }
     FrmAppHelper::insert_opt_html(array('id' => $f->id, 'key' => $f->field_key, 'name' => $f->name, 'type' => $f->type));
     if ($f->type == 'data') {
         //get all fields from linked form
         if (isset($f->field_options['form_select']) && is_numeric($f->field_options['form_select'])) {
             $linked_form = FrmDb::get_var($wpdb->prefix . 'frm_fields', array('id' => $f->field_options['form_select']), 'form_id');
             if (!in_array($linked_form, $linked_forms)) {
                 $linked_forms[] = $linked_form;
                 $linked_fields = FrmField::getAll(array('fi.type not' => FrmField::no_save_fields(), 'fi.form_id' => $linked_form));
                 $ldfe = '';
                 if ($linked_fields) {
                     foreach ($linked_fields as $linked_field) {
                         FrmAppHelper::insert_opt_html(array('id' => $f->id . ' show=' . $linked_field->id, 'key' => $f->field_key . ' show=' . $linked_field->field_key, 'name' => $linked_field->name, 'type' => $linked_field->type));
                         $ldfe = $linked_field->id;
                         unset($linked_field);
                     }
                 }
             }
         }
         $dfe = $f->id;
     }
Esempio n. 20
0
 static function generate_xml($type, $xml_args)
 {
     // Code copied from FrmXMLController::generate_xml
     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($xml_args, $defaults);
     //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);
     }
     $xml_header = '<?xml version="1.0" encoding="' . esc_attr(get_bloginfo('charset')) . "\" ?>\n";
     ob_start();
     include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php';
     $xml_body = ob_get_contents();
     ob_end_clean();
     $xml = $xml_header . $xml_body;
     $cwd = getcwd();
     $path = "{$cwd}" . '/' . "temp.xml";
     @chmod($path, 0755);
     $fw = fopen($path, "w");
     fputs($fw, $xml, strlen($xml));
     fclose($fw);
     return $path;
 }
 /**
  * @covers FrmProFieldsHelper::move_entries_to_parent_form
  */
 function _check_if_child_entries_moved($args)
 {
     global $wpdb;
     // First check if old frm_items are gone from child form
     $items = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "frm_items WHERE form_id=" . $args['form_id']);
     $this->assertEmpty($items, 'Rows in wp_frm_items were not deleted when switching from repeating to non-repeating.');
     // Check if frm_item_metas were moved to parent entries
     $new_child_metas = FrmDb::get_results($wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_items i ON i.id=m.item_id', array('field_id' => $args['children']), 'i.form_id', array('order_by' => 'i.created_at ASC'));
     $this->assertNotEmpty($new_child_metas, 'No entries to check (when switching divider to non-repeatable).');
     foreach ($new_child_metas as $item_meta) {
         $this->assertEquals($args['parent_form_id'], $item_meta->form_id, 'Child entries are not moved to parent form when a divider is switched from repeating to non-repeating.');
     }
     // Make sure frm_item_metas for repeating section are cleaned up
     $rep_meta_values = $wpdb->get_col("SELECT meta_value FROM " . $wpdb->prefix . "frm_item_metas WHERE field_id=" . $args['field_id']);
     $this->assertEmpty($rep_meta_values, 'frm_item_metas for repeating section were not deleted when switching to non-repeatable.');
     self::_check_if_child_form_deleted($args['form_id']);
 }
Esempio n. 22
0
 /**
  * Prepare the form options for export
  *
  * @since 2.0.19
  * @param string $options
  * @return string
  */
 public static function prepare_form_options_for_export($options)
 {
     $options = maybe_unserialize($options);
     // Change custom_style to the post_name instead of ID
     if (isset($options['custom_style']) && 1 !== $options['custom_style']) {
         global $wpdb;
         $table = $wpdb->prefix . 'posts';
         $where = array('ID' => $options['custom_style']);
         $select = 'post_name';
         $style_name = FrmDb::get_var($table, $where, $select);
         if ($style_name) {
             $options['custom_style'] = $style_name;
         } else {
             $options['custom_style'] = 1;
         }
     }
     $options = serialize($options);
     return self::cdata($options);
 }
Esempio n. 23
0
    private function migrate_to_6()
    {
        global $wpdb;
        $no_save = array_merge(FrmField::no_save_fields(), array('form', 'hidden', 'user_id'));
        $fields = FrmDb::get_results($this->fields, array('type NOT' => $no_save), 'id, field_options');
        $default_html = <<<DEFAULT_HTML
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
    <label class="frm_pos_[label_position]">[field_name]
        <span class="frm_required">[required_label]</span>
    </label>
    [input]
    [if description]<div class="frm_description">[description]</div>[/if description]
</div>
DEFAULT_HTML;
        $old_default_html = <<<DEFAULT_HTML
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
    <label class="frm_pos_[label_position]">[field_name]
        <span class="frm_required">[required_label]</span>
    </label>
    [input]
    [if description]<p class="frm_description">[description]</p>[/if description]
</div>
DEFAULT_HTML;
        $new_default_html = FrmFieldsHelper::get_default_html('text');
        foreach ($fields as $field) {
            $field->field_options = maybe_unserialize($field->field_options);
            if (!FrmField::is_option_empty($field, 'custom_html') || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html) {
                $field->field_options['custom_html'] = $new_default_html;
                $wpdb->update($this->fields, array('field_options' => maybe_serialize($field->field_options)), array('id' => $field->id));
            }
            unset($field);
        }
        unset($default_html, $old_default_html, $fields);
    }
 public function destroy($form_id = false, $type = 'default')
 {
     global $wpdb;
     $this->form_id = $form_id;
     $query = array('post_type' => FrmFormActionsController::$action_post_type);
     if ($form_id) {
         $query['menu_order'] = $form_id;
     }
     if ('all' != $type) {
         $query['post_excerpt'] = $this->id_base;
     }
     $post_ids = FrmDb::get_col($wpdb->posts, $query, 'ID');
     foreach ($post_ids as $id) {
         wp_delete_post($id);
     }
     self::clear_cache();
 }
Esempio n. 25
0
 public static function getRecordCount($where = '')
 {
     global $wpdb;
     $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
     if (is_numeric($where)) {
         $table_join = 'frm_items';
         $where = array('form_id' => $where);
     }
     if (is_array($where)) {
         $count = FrmDb::get_count($table_join, $where);
     } else {
         global $wpdb;
         $cache_key = 'count_' . maybe_serialize($where);
         $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmAppHelper::prepend_and_or_where(' WHERE ', $where);
         $count = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_var');
     }
     return $count;
 }
 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 update_settings($form_id)
 {
     global $wpdb;
     $registered_actions = self::$registered_actions->actions;
     $old_actions = FrmDb::get_col($wpdb->posts, array('post_type' => self::$action_post_type, 'menu_order' => $form_id), 'ID');
     $new_actions = array();
     foreach ($registered_actions as $registered_action) {
         $action_ids = $registered_action->update_callback($form_id);
         if (!empty($action_ids)) {
             $new_actions[] = $action_ids;
         }
     }
     //Only use array_merge if there are new actions
     if (!empty($new_actions)) {
         $new_actions = call_user_func_array('array_merge', $new_actions);
     }
     $old_actions = array_diff($old_actions, $new_actions);
     self::delete_missing_actions($old_actions);
 }
Esempio n. 28
0
        ?>
</editable>
		<options><?php 
        echo FrmXMLHelper::prepare_form_options_for_export($form->options);
        ?>
</options>
		<status><?php 
        echo FrmXMLHelper::cdata($form->status);
        ?>
</status>
        <parent_form_id><?php 
        echo $form->parent_form_id;
        ?>
</parent_form_id>
<?php 
        $fields = FrmDb::get_results($wpdb->prefix . 'frm_fields', array('form_id' => $form->id), '*', array('order_by' => 'field_order'));
        foreach ($fields as $field) {
            ?>
		<field>
		    <id><?php 
            echo $field->id;
            ?>
</id>
            <field_key><?php 
            echo FrmXMLHelper::cdata($field->field_key);
            ?>
</field_key>
            <name><?php 
            echo FrmXMLHelper::cdata($field->name);
            ?>
</name>
 public static function uninstall()
 {
     check_ajax_referer('frm_ajax', 'nonce');
     if (current_user_can('administrator')) {
         $frmdb = new FrmDb();
         $frmdb->uninstall();
         //disable the plugin and redirect after uninstall so the tables don't get added right back
         deactivate_plugins(FrmAppHelper::plugin_folder() . '/formidable.php', false, false);
         echo esc_url_raw(admin_url('plugins.php?deactivate=true'));
     } else {
         $frm_settings = FrmAppHelper::get_settings();
         wp_die($frm_settings->admin_permission);
     }
     wp_die();
 }
Esempio n. 30
0
 /**
  * @param string $key
  * @return int field id
  */
 public static function get_id_by_key($key)
 {
     $id = FrmDb::get_var('frm_fields', array('field_key' => sanitize_title($key)));
     return $id;
 }