function get_display_data($display, $content = '', $entry_id = false, $extra_atts = array())
 {
     global $frmpro_display, $frm_entry, $frmpro_settings, $frm_entry_meta, $frm_forms_loaded;
     $frm_forms_loaded[] = true;
     $defaults = array('filter' => false, 'user_id' => '', 'limit' => '', 'page_size' => '', 'order_by' => '', 'order' => '');
     extract(wp_parse_args($extra_atts, $defaults));
     if (FrmProAppHelper::rewriting_on() && $frmpro_settings->permalinks) {
         $this->parse_pretty_entry_url();
     }
     if (is_numeric($display->entry_id) && $display->entry_id > 0 and !$entry_id) {
         $entry_id = $display->entry_id;
     }
     $entry = false;
     $show = 'all';
     if (in_array($display->show_count, array('dynamic', 'calendar', 'one'))) {
         $one_param = isset($_GET['entry']) ? $_GET['entry'] : $entry_id;
         $get_param = isset($_GET[$display->param]) ? $_GET[$display->param] : ($display->show_count == 'one' ? $one_param : $entry_id);
         unset($one_param);
         if ($get_param) {
             $where_entry = array('it.form_id' => $display->form_id);
             if (($display->type == 'id' or $display->show_count == 'one') and is_numeric($get_param)) {
                 $where_entry['it.id'] = $get_param;
             } else {
                 $where_entry['it.item_key'] = $get_param;
             }
             $entry = $frm_entry->getAll($where_entry, '', 1, 0);
             if ($entry) {
                 $entry = reset($entry);
             }
             if ($entry and $entry->post_id) {
                 //redirect to single post page if this entry is a post
                 global $post;
                 if (in_the_loop() and $display->show_count != 'one' and !is_single($entry->post_id) and $post->ID != $entry->post_id) {
                     $this_post = get_post($entry->post_id);
                     if (in_array($this_post->post_status, array('publish', 'private'))) {
                         die('<script type="text/javascript">window.location="' . get_permalink($entry->post_id) . '"</script>');
                     }
                 }
             }
         }
         unset($get_param);
     }
     if ($entry and in_array($display->show_count, array('dynamic', 'calendar'))) {
         $new_content = stripslashes($display->dyncontent);
         $show = 'one';
     } else {
         $new_content = stripslashes($display->content);
     }
     $show = ($display->show_count == 'one' or $entry_id and is_numeric($entry_id)) ? 'one' : $show;
     $shortcodes = FrmProDisplaysHelper::get_shortcodes($new_content, $display->form_id);
     $pagination = '';
     if ($entry and $entry->form_id == $display->form_id) {
         $display_content = FrmProFieldsHelper::replace_shortcodes($new_content, $entry, $shortcodes, $display, $show);
     } else {
         global $frmdb, $wpdb;
         $options = maybe_unserialize($display->options);
         $empty_msg = '<div class="frm_no_entries">' . (isset($options['empty_msg']) ? stripslashes($options['empty_msg']) : '') . '</div>';
         $display_content = '';
         if ($show == 'all') {
             $display_content .= isset($options['before_content']) ? stripslashes($options['before_content']) : '';
         }
         $display_content = apply_filters('frm_before_display_content', $display_content, $display, $show);
         $where = 'it.form_id=' . $display->form_id;
         $form_posts = $frmdb->get_records($frmdb->entries, array('form_id' => $display->form_id, 'post_id >' => 1), '', '', 'id,post_id');
         $entry_ids = $frmdb->get_col($frmdb->entries, array('form_id' => $display->form_id), 'id');
         $after_where = false;
         if ($user_id and !empty($user_id)) {
             $user_id = FrmProAppHelper::get_user_id_param($user_id);
             $uid_used = false;
         }
         if (isset($options['where']) and !empty($options['where'])) {
             $options['where'] = apply_filters('frm_custom_where_opt', $options['where'], array('display' => $display, 'entry' => $entry));
             $continue = false;
             foreach ($options['where'] as $where_key => $where_opt) {
                 $where_val = isset($options['where_val'][$where_key]) ? $options['where_val'][$where_key] : '';
                 if (preg_match("/\\[(get|get-(.?))\\b(.*?)(?:(\\/))?\\]/s", $where_val)) {
                     $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
                     //if this param doesn't exist, then don't include it
                     if ($where_val == '') {
                         if (!$after_where) {
                             $continue = true;
                         }
                         continue;
                     }
                 } else {
                     $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
                 }
                 $continue = false;
                 if ($where_val == 'current_user') {
                     if ($user_id and is_numeric($user_id)) {
                         $where_val = $user_id;
                         $uid_used = true;
                     } else {
                         global $user_ID;
                         $where_val = $user_ID;
                     }
                 }
                 $where_val = do_shortcode($where_val);
                 if (is_array($where_val) and !empty($where_val)) {
                     $new_where = '(';
                     if (strpos($options['where_is'][$where_key], 'LIKE') !== false) {
                         foreach ($where_val as $w) {
                             if ($new_where != '(') {
                                 $new_where .= ',';
                             }
                             $new_where .= "'%" . esc_sql(like_escape($w)) . "%'";
                             unset($w);
                         }
                     } else {
                         foreach ($where_val as $w) {
                             if ($new_where != '(') {
                                 $new_where .= ',';
                             }
                             $new_where .= "'" . esc_sql($w) . "'";
                             unset($w);
                         }
                     }
                     $new_where .= ')';
                     $where_val = $new_where;
                     unset($new_where);
                     if (strpos($options['where_is'][$where_key], '!') === false and strpos($options['where_is'][$where_key], 'not') === false) {
                         $options['where_is'][$where_key] = ' in ';
                     } else {
                         $options['where_is'][$where_key] = ' not in ';
                     }
                 }
                 if (is_numeric($where_opt)) {
                     $entry_ids = FrmProAppHelper::filter_where($entry_ids, array('where_opt' => $where_opt, 'where_is' => $options['where_is'][$where_key], 'where_val' => $where_val, 'form_id' => $display->form_id, 'form_posts' => $form_posts, 'after_where' => $after_where));
                     $after_where = true;
                     $continue = false;
                     if (empty($entry_ids)) {
                         break;
                     }
                 } else {
                     if ($where_opt == 'created_at') {
                         if ($where_val == 'NOW') {
                             $where_val = current_time('mysql', 1);
                         }
                         $where_val = date('Y-m-d H:i:s', strtotime($where_val));
                         $where .= " and it.created_at " . $options['where_is'][$where_key];
                         if (strpos($options['where_is'][$where_key], 'in')) {
                             $where .= " {$where_val}";
                         } else {
                             $where .= " '" . esc_sql($where_val) . "'";
                         }
                         $continue = true;
                     } else {
                         if ($where_opt == 'id' or $where_opt == 'item_key') {
                             $where .= " and it.{$where_opt} " . $options['where_is'][$where_key];
                             if (strpos($options['where_is'][$where_key], 'in')) {
                                 $where .= " {$where_val}";
                             } else {
                                 $where .= " '" . esc_sql($where_val) . "'";
                             }
                             $continue = true;
                         }
                     }
                 }
             }
             if (!$continue and empty($entry_ids)) {
                 return $content . ' ' . $empty_msg;
             }
         }
         if ($user_id and is_numeric($user_id) and !$uid_used) {
             $where .= " AND it.user_id=" . (int) $user_id;
         }
         $s = FrmAppHelper::get_param('frm_search', false);
         if ($s) {
             $new_ids = FrmProEntriesHelper::get_search_ids($s, $display->form_id);
             if ($after_where and isset($entry_ids) and !empty($entry_ids)) {
                 $entry_ids = array_intersect($new_ids, $entry_ids);
             } else {
                 $entry_ids = $new_ids;
             }
             if (empty($entry_ids)) {
                 return $content . ' ' . $empty_msg;
             }
         }
         if (isset($entry_ids) and !empty($entry_ids)) {
             $where .= ' and it.id in (' . implode(',', $entry_ids) . ')';
         }
         if ($entry_id) {
             $where .= " and it.id in ({$entry_id})";
         }
         if ($show == 'one') {
             $limit = ' LIMIT 1';
         } else {
             if (isset($_GET['frm_cat']) and isset($_GET['frm_cat_id'])) {
                 //Get fields with specified field value 'frm_cat' = field key/id, 'frm_cat_id' = order position of selected option
                 global $frm_field;
                 if ($cat_field = $frm_field->getOne($_GET['frm_cat'])) {
                     $categories = maybe_unserialize($cat_field->options);
                     if (isset($categories[$_GET['frm_cat_id']])) {
                         $cat_entry_ids = $frm_entry_meta->getEntryIds("meta_value='" . $categories[$_GET['frm_cat_id']] . "' and fi.field_key='{$_GET['frm_cat']}'");
                     }
                     if ($cat_entry_ids) {
                         $where .= " and it.id in (" . implode(',', $cat_entry_ids) . ")";
                     }
                 }
             }
         }
         if (is_array($options)) {
             if (!empty($limit) and is_numeric($limit)) {
                 $options['limit'] = (int) $limit;
             }
             if (is_numeric($options['limit'])) {
                 $num_limit = (int) $options['limit'];
                 $limit = ' LIMIT ' . $options['limit'];
             }
             if (!empty($order_by)) {
                 $options['order_by'] = $order_by;
             }
             if (!empty($order)) {
                 $options['order'] = $order;
             }
             if (isset($options['order_by']) && $options['order_by'] != '') {
                 /*if( $wpdb->has_cap( 'collation' ) ){
                       $charset_collate = '';
                       if( !empty($wpdb->charset) )
                           $charset_collate .= "DEFAULT CHARACTER SET $wpdb->charset";
                       if( !empty($wpdb->collate) )
                           $charset_collate .= " COLLATE $wpdb->collate";
                   }*/
                 $order = isset($options['order']) ? ' ' . $options['order'] : '';
                 if ($options['order_by'] == 'rand') {
                     $order_by = ' RAND()';
                 } else {
                     if (is_numeric($options['order_by'])) {
                         global $frm_entry_meta, $frm_field;
                         $order_field = $frm_field->getOne($options['order_by']);
                         $order_field->field_options = maybe_unserialize($order_field->field_options);
                         $meta_order = $order_field->type == 'number' ? ' LENGTH(meta_value),' : '';
                         if (isset($order_field->field_options['post_field']) and $order_field->field_options['post_field']) {
                             $posts = $form_posts;
                             //$frmdb->get_records($frmdb->entries, array('form_id' => $display->form_id, 'post_id >' => 1), '', '', 'id, post_id');
                             $linked_posts = array();
                             foreach ($posts as $post_meta) {
                                 $linked_posts[$post_meta->post_id] = $post_meta->id;
                             }
                             if ($order_field->field_options['post_field'] == 'post_custom') {
                                 $ordered_ids = $wpdb->get_col("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='" . $order_field->field_options['custom_field'] . "' AND post_id in (" . implode(',', array_keys($linked_posts)) . ") ORDER BY meta_value" . $order);
                                 $metas = array();
                                 foreach ($ordered_ids as $ordered_id) {
                                     $metas[] = array('item_id' => $linked_posts[$ordered_id]);
                                 }
                             } else {
                                 if ($order_field->field_options['post_field'] != 'post_category') {
                                     $ordered_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE ID in (" . implode(',', array_keys($linked_posts)) . ") ORDER BY " . $order_field->field_options['post_field'] . ' ' . $order);
                                     $metas = array();
                                     foreach ($ordered_ids as $ordered_id) {
                                         $metas[] = array('item_id' => $linked_posts[$ordered_id]);
                                     }
                                 }
                             }
                         } else {
                             if ($order_field->type == 'number') {
                                 $query = "SELECT it.*, meta_value +0 as odr FROM {$frmdb->entry_metas} it LEFT OUTER JOIN {$frmdb->fields} fi ON it.field_id=fi.id WHERE fi.form_id={$display->form_id} and fi.id={$options['order_by']}";
                                 if (isset($entry_ids) and !empty($entry_ids)) {
                                     $query .= " AND it.item_id in (" . implode(',', $entry_ids) . ")";
                                 }
                                 $query .= " ORDER BY odr {$order} {$limit}";
                                 if ($limit == ' LIMIT 1') {
                                     $metas = $wpdb->get_row($query);
                                 } else {
                                     $metas = $wpdb->get_results($query);
                                 }
                             } else {
                                 $metas = $frm_entry_meta->getAll('fi.form_id=' . $display->form_id . ' and fi.id=' . $options['order_by'], ' ORDER BY ' . $meta_order . ' meta_value' . $order);
                                 //TODO: add previous $where and $limit
                             }
                         }
                         if (isset($metas) and is_array($metas) and !empty($metas)) {
                             if ($order_field->type == 'time' and (!isset($order_field->field_options['clock']) or $order_field->field_options['clock'] == 12)) {
                                 $new_order = array();
                                 foreach ($metas as $key => $meta) {
                                     $parts = str_replace(array(' PM', ' AM'), '', $meta->meta_value);
                                     $parts = explode(':', $parts);
                                     if (is_array($parts)) {
                                         if (preg_match('/PM/', $meta->meta_value) and (int) $parts[0] != 12 or (int) $parts[0] == 12 and preg_match('/AM/', $meta->meta_value)) {
                                             $parts[0] = (int) $parts[0] + 12;
                                         }
                                     }
                                     $new_order[$key] = (int) $parts[0] . $parts[1];
                                     unset($key);
                                     unset($meta);
                                 }
                                 //array with sorted times
                                 asort($new_order);
                                 $final_order = array();
                                 foreach ($new_order as $key => $time) {
                                     $final_order[] = $metas[$key];
                                     unset($key);
                                     unset($time);
                                 }
                                 $metas = $final_order;
                                 unset($final_order);
                             }
                             $rev_order = ($order == 'DESC' or $order == '') ? ' ASC' : ' DESC';
                             foreach ($metas as $meta) {
                                 $meta = (array) $meta;
                                 $order_by .= 'it.id=' . $meta['item_id'] . $rev_order . ', ';
                             }
                             $order_by = rtrim($order_by, ', ');
                         } else {
                             $order_by .= 'it.created_at' . $order;
                         }
                     } else {
                         $order_by = 'it.' . $options['order_by'] . $order;
                     }
                 }
                 $order_by = ' ORDER BY ' . $order_by;
             }
         }
         if (!empty($page_size) and is_numeric($page_size)) {
             $options['page_size'] = (int) $page_size;
         }
         if (isset($options['page_size']) && is_numeric($options['page_size'])) {
             global $frm_app_helper;
             $current_page = FrmAppHelper::get_param('frm-page', 1);
             $record_where = $where == "it.form_id={$display->form_id}" ? $display->form_id : $where;
             $record_count = $frm_entry->getRecordCount($record_where);
             if (isset($num_limit) and $record_count > (int) $num_limit) {
                 $record_count = (int) $num_limit;
             }
             $page_count = $frm_entry->getPageCount($options['page_size'], $record_count);
             $entries = $frm_entry->getPage($current_page, $options['page_size'], $where, $order_by);
             $page_last_record = $frm_app_helper->getLastRecordNum($record_count, $current_page, $options['page_size']);
             $page_first_record = $frm_app_helper->getFirstRecordNum($record_count, $current_page, $options['page_size']);
             if ($page_count > 1) {
                 $pagination = FrmProDisplaysController::get_pagination_file(FRMPRO_VIEWS_PATH . '/displays/pagination.php', compact('current_page', 'record_count', 'page_count', 'page_last_record', 'page_first_record'));
             }
         } else {
             $entries = $frm_entry->getAll($where, $order_by, $limit, true, false);
         }
         $filtered_content = apply_filters('frm_display_entries_content', $new_content, $entries, $shortcodes, $display, $show);
         if ($filtered_content != $new_content) {
             $display_content .= $filtered_content;
         } else {
             $odd = 'odd';
             $count = 0;
             if (!empty($entries)) {
                 foreach ($entries as $entry) {
                     $count++;
                     //TODO: use the count with conditionals
                     $display_content .= apply_filters('frm_display_entry_content', $new_content, $entry, $shortcodes, $display, $show, $odd);
                     $odd = $odd == 'odd' ? 'even' : 'odd';
                     unset($entry);
                 }
                 unset($count);
             } else {
                 $display_content .= $empty_msg;
             }
         }
         if ($show == 'all') {
             $display_content .= isset($options['after_content']) ? stripslashes($options['after_content']) : '';
         }
     }
     $display_content .= apply_filters('frm_after_display_content', $pagination, $display, $show);
     if ($display->insert_loc == 'after') {
         $content .= $display_content;
     } else {
         if ($display->insert_loc == 'before') {
             $content = $display_content . $content;
         } else {
             if ($filter) {
                 $display_content = apply_filters('the_content', $display_content);
             }
             $content = $display_content;
         }
     }
     return $content;
 }
 public static function do_mergetags($string, $form_id, $entry_id)
 {
     global $frm_entry;
     /* strip {all_fields} merge tag from $string */
     $string = str_replace('[default-message]', '', $string);
     $entry = $frm_entry->getOne($entry_id, true);
     $shortcodes = FrmProAppHelper::get_shortcodes($string, $form_id);
     return FrmProFieldsHelper::replace_shortcodes($string, $entry, $shortcodes);
 }
 public static function replace_content_shortcodes($content, $entry, $shortcodes)
 {
     remove_filter('frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20);
     return FrmProFieldsHelper::replace_shortcodes($content, $entry, $shortcodes);
 }
 function autoresponder($entry_id, $form_id)
 {
     if (defined('WP_IMPORTING')) {
         return;
     }
     global $frm_form, $frm_entry, $frm_entry_meta, $frm_notification;
     $form = $frm_form->getOne($form_id);
     $form_options = maybe_unserialize($form->options);
     if (!isset($form_options['auto_responder']) or !$form_options['auto_responder'] or !isset($form_options['ar_email_message']) or $form_options['ar_email_message'] == '') {
         return;
     }
     //don't continue forward unless a message has been inserted
     $entry = $frm_entry->getOne($entry_id, true);
     $entry_ids = array($entry->id);
     $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0;
     if (preg_match('/|/', $email_field)) {
         $email_fields = explode('|', $email_field);
         if (isset($email_fields[1])) {
             if (isset($entry->metas[$email_fields[0]])) {
                 $add_id = $entry->metas[$email_fields[0]];
                 $add_id = maybe_unserialize($add_id);
                 if (is_array($add_id)) {
                     foreach ($add_id as $add) {
                         $entry_ids[] = $add;
                     }
                 } else {
                     $entry_ids[] = $add_id;
                 }
             }
             $email_field = $email_fields[1];
         }
         unset($email_fields);
     }
     $inc_fields = array();
     foreach (array($email_field) as $inc_field) {
         if ($inc_field) {
             $inc_fields[] = $inc_field;
         }
     }
     $where = "it.item_id in (" . implode(',', $entry_ids) . ")";
     if (!empty($inc_fields)) {
         $inc_fields = implode(',', $inc_fields);
         $where .= " and it.field_id in ({$inc_fields})";
     }
     $values = $frm_entry_meta->getAll($where, " ORDER BY fi.field_order");
     $plain_text = (isset($form_options['ar_plain_text']) and $form_options['ar_plain_text']) ? true : false;
     $message = apply_filters('frm_ar_message', $form_options['ar_email_message'], array('entry' => $entry, 'form' => $form));
     $shortcodes = FrmProAppHelper::get_shortcodes($message, $form_id);
     $mail_body = FrmProFieldsHelper::replace_shortcodes($message, $entry, $shortcodes);
     $frm_blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     $reply_to_name = isset($form_options['ar_reply_to_name']) ? $form_options['ar_reply_to_name'] : $frm_blogname;
     //default sender name
     $reply_to = isset($form_options['ar_reply_to']) ? $form_options['ar_reply_to'] : '[admin_email]';
     //default sender email
     foreach ($values as $value) {
         /*
                     if((int)$reply_field == $value->field_id){
                         if($value->field_type == 'user_id'){
                             $user_data = get_userdata($value->meta_value);
                             $reply_to = $user_data->user_email;
                         }else{
                             $val = apply_filters('frm_email_value', maybe_unserialize($value->meta_value), $value, $entry);
                             if(is_email($val))
                                 $reply_to = $val;
                         }
                     }
                     
                     if((int)$reply_name_field == $value->field_id){
                         if($value->field_type == 'user_id'){
                             $user_data = get_userdata($value->meta_value);
                             $reply_to_name = $user_data->display_name;
                         }else
                             $reply_to_name = apply_filters('frm_email_value', maybe_unserialize($value->meta_value), $value, $entry);
                     } */
         if ((int) $email_field == $value->field_id) {
             if ($value->field_type == 'user_id') {
                 $user_data = get_userdata($value->meta_value);
                 $to_email = $user_data->user_email;
             } else {
                 $val = apply_filters('frm_email_value', maybe_unserialize($value->meta_value), $value, $entry);
                 if (is_email($val)) {
                     $to_email = $val;
                 }
             }
         }
     }
     if (!isset($to_email)) {
         return;
     }
     if (isset($form_options['ar_email_subject']) and $form_options['ar_email_subject'] != '') {
         $shortcodes = FrmProAppHelper::get_shortcodes($form_options['ar_email_subject'], $form_id);
         $subject = FrmProFieldsHelper::replace_shortcodes($form_options['ar_email_subject'], $entry, $shortcodes);
     } else {
         $subject = sprintf(__('%1$s Form submitted on %2$s', 'formidable'), stripslashes($form->name), $frm_blogname);
         //subject
     }
     $attachments = apply_filters('frm_autoresponder_attachment', array(), $form);
     $frm_notification->send_notification_email($to_email, $subject, $mail_body, $reply_to, $reply_to_name, $plain_text, $attachments);
     return $to_email;
 }
 public static function filter_content($content, $form, $entry = false)
 {
     if ($entry and is_numeric($entry)) {
         global $frm_entry;
         $entry = $frm_entry->getOne($entry);
     } else {
         $entry_id = (isset($_POST) and isset($_POST['id'])) ? $_POST['id'] : false;
         if ($entry_id) {
             global $frm_entry;
             $entry = $frm_entry->getOne($entry_id);
         }
     }
     if (!$entry) {
         return $content;
     }
     if (is_object($form)) {
         $form = $form->id;
     }
     $shortcodes = FrmProAppHelper::get_shortcodes($content, $form);
     $content = FrmProFieldsHelper::replace_shortcodes($content, $entry, $shortcodes);
     return $content;
 }