function more_settings($frm_settings)
 {
     global $frmpro_settings, $wp_scripts;
     $error_icons = glob(FRMPRO_PATH . "/images/error_icons/*.png");
     $jquery_themes = FrmProAppHelper::jquery_themes();
     require FRMPRO_VIEWS_PATH . '/settings/form.php';
 }
Beispiel #2
0
 public static function get_formatted_time($date, $date_format = false, $time_format = false)
 {
     if (empty($date)) {
         return $date;
     }
     if (!$date_format) {
         $date_format = get_option('date_format');
     }
     if (preg_match('/^\\d{1-2}\\/\\d{1-2}\\/\\d{4}$/', $date)) {
         global $frmpro_settings;
         $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
     }
     $do_time = date('H:i:s', strtotime($date)) == '00:00:00' ? false : true;
     $date = get_date_from_gmt($date);
     $formatted = date_i18n($date_format, strtotime($date));
     if ($do_time) {
         if (!$time_format) {
             $time_format = get_option('time_format');
         }
         $trimmed_format = trim($time_format);
         if ($time_format and !empty($trimmed_format)) {
             $formatted .= ' ' . __('at', 'formidable') . ' ' . date_i18n($time_format, strtotime($date));
         }
     }
     return $formatted;
 }
 public static function styling_tab()
 {
     global $frmpro_settings, $frm_settings;
     $jquery_themes = FrmProAppHelper::jquery_themes();
     $a = isset($_GET['t']) ? $_GET['t'] : 'general_settings';
     include FrmAppHelper::plugin_path() . '/pro/classes/views/settings/styling_tab.php';
 }
Beispiel #4
0
 /**
  * Get the conversions from php date format to datepicker
  * Set the cal_date_format to make sure it's not empty
  *
  * @since 2.0.2
  */
 function get_cal_date()
 {
     $formats = FrmProAppHelper::display_to_datepicker_format();
     if (isset($formats[$this->date_format])) {
         $this->cal_date_format = $formats[$this->date_format];
     } else {
         $this->cal_date_format = 'mm/dd/yy';
     }
 }
Beispiel #5
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';
 }
 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);
 }
Beispiel #7
0
 function validate($values)
 {
     $errors = array();
     if ($values['post_title'] == '') {
         $errors[] = __('Name cannot be blank', 'formidable');
     }
     if ($values['excerpt'] == __('This is not displayed anywhere, but is just for your reference. (optional)', 'formidable')) {
         $_POST['excerpt'] = '';
     }
     if ($values['content'] == '') {
         $errors[] = __('Content cannot be blank', 'formidable');
     }
     if ($values['insert_loc'] != 'none' && $values['post_id'] == '') {
         $errors[] = __('Page cannot be blank if you want the content inserted automatically', 'formidable');
     }
     if (!empty($values['options']['limit']) && !is_numeric($values['options']['limit'])) {
         $errors[] = __('Limit must be a number', 'formidable');
     }
     if ($values['show_count'] == 'dynamic') {
         if ($values['dyncontent'] == '') {
             $errors[] = __('Dynamic Content cannot be blank', 'formidable');
         }
         if (!FrmProAppHelper::rewriting_on()) {
             if ($values['param'] == '') {
                 $errors[] = __('Parameter Name cannot be blank if content is dynamic', 'formidable');
             }
             if ($values['type'] == '') {
                 $errors[] = __('Parameter Value cannot be blank if content is dynamic', 'formidable');
             }
         } else {
             if ($values['type'] == '') {
                 $errors[] = __('Detail Link cannot be blank if content is dynamic', 'formidable');
             }
         }
     }
     if (isset($values['options']['where'])) {
         $_POST['options']['where'] = FrmProAppHelper::reset_keys($values['options']['where']);
         $_POST['options']['where_is'] = FrmProAppHelper::reset_keys($values['options']['where_is']);
         $_POST['options']['where_val'] = FrmProAppHelper::reset_keys($values['options']['where_val']);
     }
     return $errors;
 }
 function dropdown_categories($args)
 {
     $defaults = array('field' => false, 'name' => false);
     extract(wp_parse_args($args, $defaults));
     if (!$field) {
         return;
     }
     if (!$name) {
         $name = "item_meta[{$field['id']}]";
     }
     $selected = is_array($field['value']) ? reset($field['value']) : $field['value'];
     $exclude = is_array($field['exclude_cat']) ? implode(',', $field['exclude_cat']) : $field['exclude_cat'];
     $exclude = apply_filters('frm_exclude_cats', $exclude, $field);
     $args = array('show_option_all' => ' ', 'hierarchical' => 1, 'name' => $name, 'id' => 'field_' . $field['field_key'], 'exclude' => $exclude, 'class' => $field['type'], 'selected' => $selected, 'hide_empty' => false, 'echo' => 0, 'orderby' => 'name');
     if (class_exists('FrmProForm')) {
         $post_type = FrmProForm::post_type($field['form_id']);
         if (function_exists('get_object_taxonomies')) {
             $args['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $field);
             if (!$args['taxonomy']) {
                 return;
             }
         }
     }
     return wp_dropdown_categories($args);
 }
 function ary2xml($cary, $d = 0, $forcetag = '')
 {
     $res = array();
     foreach ($cary as $tag => $r) {
         if (isset($r[0])) {
             $res[] = FrmProAppHelper::ary2xml($r, $d, $tag);
         } else {
             if ($forcetag) {
                 $tag = $forcetag;
             }
             $sp = str_repeat("\t", $d);
             $res[] = "{$sp}<{$tag}";
             if (isset($r['_a'])) {
                 foreach ($r['_a'] as $at => $av) {
                     $res[] = " {$at}=\"{$av}\"";
                 }
             }
             $res[] = ">" . (isset($r['_c']) ? "\n" : '');
             if (isset($r['_c'])) {
                 $res[] = ary2xml($r['_c'], $d + 1);
             } elseif (isset($r['_v'])) {
                 $res[] = $r['_v'];
             }
             $res[] = (isset($r['_c']) ? $sp : '') . "</{$tag}>\n";
         }
     }
     return implode('', $res);
 }
Beispiel #10
0
 /**
  * Get media ID(s) to be saved to database and set global media ID values
  *
  * @since 2.0
  * @param array $values (posted values), pass by reference
  * @param integer $field_id
  * @param integer $entry_id
  *
  */
 private static function prepare_file_upload_meta(&$values, $field, $entry_id)
 {
     // If there are no files to be uploaded, exit now
     if (!isset($_FILES)) {
         return;
     }
     // Assume this field is not repeating
     $repeating = $key_pointer = $parent_field = $file_name = false;
     // Get file name
     self::get_file_name($field->id, $file_name, $parent_field, $key_pointer, $repeating);
     // If there isn't a file uploaded in this field, exit now
     if (!isset($_FILES[$file_name]) || empty($_FILES[$file_name]['name']) || (int) $_FILES[$file_name]['size'] == 0) {
         return;
     }
     // Upload the file now
     $media_ids = FrmProAppHelper::upload_file($file_name);
     // Get filtered media IDs
     $mids = self::get_final_media_ids($media_ids, $field, $values);
     // If no media IDs to upload, end now
     if (empty($mids)) {
         return;
     }
     // Get global frm_vars variable
     global $frm_vars;
     // Set up progress bar to display on form submission
     if (!isset($frm_vars['loading']) || !$frm_vars['loading']) {
         $frm_vars['loading'] = true;
     }
     // Set up global media_id vars. This will be used for post fields.
     if (!isset($frm_vars['media_id'])) {
         $frm_vars['media_id'] = array();
     }
     // If not inside of a repeating section, set the media IDs for this field
     if (!$repeating) {
         $frm_vars['media_id'][$field->id] = $mids;
     }
     // Set new posted values
     self::set_file_posted_vals($field->id, $values[$field->id], array('repeating' => $repeating, 'parent_field' => $parent_field, 'key_pointer' => $key_pointer));
     // If this is a post field
     if (isset($_POST['frm_wp_post']) && FrmField::is_option_true($field, 'post_field')) {
         $_POST['frm_wp_post_custom'][$field->id . '=' . $field->field_options['custom_field']] = $mids;
     }
 }
 function get_form_results($atts)
 {
     extract(shortcode_atts(array('id' => false, 'cols' => 99, 'style' => true, 'no_entries' => __('No Entries Found', 'formidable'), 'fields' => false, 'clickable' => false, 'user_id' => false, 'google' => false, 'pagesize' => 20, 'sort' => true, 'edit_link' => false, 'page_id' => false), $atts));
     if (!$id) {
         return;
     }
     global $frm_form, $frm_field, $frm_entry, $frm_entry_meta, $frmpro_settings;
     $form = $frm_form->getOne($id);
     if (!$form) {
         return;
     }
     $where = "fi.type not in ('divider', 'captcha', 'break', 'html') and fi.form_id=" . (int) $form->id;
     if ($fields) {
         $fields = explode(',', $fields);
         $f_list = array();
         foreach ($fields as $k => $f) {
             $f = trim($f);
             $fields[$k] = $f;
             $f_list[] = esc_sql(like_escape($f));
             unset($k);
             unset($f);
         }
         if (count($fields) == 1 and in_array('id', $fields)) {
             $where .= '';
         } else {
             $where .= " and (fi.id in ('" . implode("','", $f_list) . "') or fi.field_key in ('" . implode("','", $f_list) . "'))";
         }
     }
     $fields = (array) $fields;
     $form_cols = $frm_field->getAll($where, 'field_order ASC', $cols);
     unset($where);
     $where = array('it.form_id' => $form->id);
     if ($user_id) {
         $where['user_id'] = FrmProAppHelper::get_user_id_param($user_id);
     }
     $entries = $frm_entry->getAll($where, '', '', true, false);
     if ($edit_link) {
         $anchor = '';
         if (!$page_id) {
             global $post;
             $page_id = $post->ID;
             $anchor = '#form_' . $form->form_key;
         }
         if ($edit_link === '1') {
             $edit_link = __('Edit', 'formidable');
         }
         $permalink = get_permalink($page_id);
     }
     if ($style) {
         global $frm_load_css;
         $frm_load_css = true;
     }
     $filename = 'table';
     if ($google) {
         global $frm_google_chart;
         $filename = 'google_table';
         $options = array();
         if ($pagesize) {
             $options = array('page' => 'enable', 'pageSize' => (int) $pagesize);
         }
         $options['allowHtml'] = true;
         $options['sort'] = $sort ? 'enable' : 'disable';
         if ($style) {
             $options['cssClassNames'] = array('oddTableRow' => 'frm_even');
         }
     }
     ob_start();
     include FRMPRO_VIEWS_PATH . '/frmpro-entries/' . $filename . '.php';
     $contents = ob_get_contents();
     ob_end_clean();
     if (!$google and $clickable) {
         $contents = make_clickable($contents);
     }
     return $contents;
 }
Beispiel #12
0
 function get_display_value($replace_with, $field, $atts = array())
 {
     $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
     if ($field->type == 'user_id') {
         $user_info = isset($atts['show']) ? $atts['show'] : 'display_name';
         $replace_with = FrmProFieldsHelper::get_display_name($replace_with, $user_info, $atts);
         if (is_array($replace_with)) {
             $new_val = '';
             foreach ($replace_with as $key => $val) {
                 if (!empty($new_val)) {
                     $new_val .= ', ';
                 }
                 $new_val .= $key . '. ' . $val;
             }
             $replace_with = $new_val;
         }
     } else {
         if ($field->type == 'date') {
             if (isset($atts['time_ago'])) {
                 $atts['format'] = 'Y-m-d H:i:s';
             }
             if (!isset($atts['format'])) {
                 $atts['format'] = false;
             }
             $replace_with = FrmProFieldsHelper::get_date($replace_with, $atts['format']);
             if (isset($atts['time_ago'])) {
                 $replace_with = FrmProAppHelper::human_time_diff(strtotime($replace_with), strtotime(date_i18n('Y-m-d')));
             }
         } else {
             if (is_numeric($replace_with) and $field->type == 'file') {
                 //size options are thumbnail, medium, large, or full
                 $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
                 if ($size != 'id') {
                     $replace_with = FrmProFieldsHelper::get_media_from_id($replace_with, $size);
                 }
             } else {
                 if ($field->type == 'data') {
                     //and (is_numeric($replace_with) or is_array($replace_with))
                     $field->field_options = maybe_unserialize($field->field_options);
                     if (isset($field->field_options['form_select']) and $field->field_options['form_select'] == 'taxonomy') {
                         return $replace_with;
                     }
                     $replace_with = explode($sep, $replace_with);
                     if (isset($atts['show'])) {
                         if (in_array($atts['show'], array('key', 'created-at', 'created_at', 'updated-at', 'updated_at', 'post_id'))) {
                             global $frm_entry;
                             if (is_array($replace_with)) {
                                 $linked_ids = $replace_with;
                                 $replace_with = '';
                                 foreach ($linked_ids as $linked_id) {
                                     $linked_entry = FrmEntry::getOne($linked_id);
                                     if (!empty($replace_with)) {
                                         $replace_with .= $sep;
                                     }
                                     if ($atts['show'] == 'created-at') {
                                         $replace_with .= $linked_entry->created_at;
                                     } else {
                                         if ($atts['show'] == 'updated-at') {
                                             $replace_with .= $linked_entry->updated_at;
                                         } else {
                                             if ($atts['show'] == 'key') {
                                                 $replace_with .= $linked_entry->item_key;
                                             } else {
                                                 $replace_with .= isset($linked_entry->{$atts['show']}) ? $linked_entry->{$atts['show']} : $linked_entry->item_key;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 $linked_entry = FrmEntry::getOne($replace_with);
                                 if ($atts['show'] == 'created-at') {
                                     $replace_with = $linked_entry->created_at;
                                 } else {
                                     if ($atts['show'] == 'updated-at') {
                                         $replace_with = $linked_entry->updated_at;
                                     } else {
                                         if ($atts['show'] == 'key') {
                                             $replace_with = $linked_entry->item_key;
                                         } else {
                                             $replace_with = isset($linked_entry->{$atts['show']}) ? $linked_entry->{$atts['show']} : $linked_entry->item_key;
                                         }
                                     }
                                 }
                             }
                         } else {
                             if ($atts['show'] == 'id') {
                                 if (is_array($replace_with)) {
                                     $replace_with = implode($sep, $replace_with);
                                 }
                                 //just keep the value since it's already the id
                             } else {
                                 if (is_array($replace_with)) {
                                     $linked_ids = $replace_with;
                                     $replace_with = array();
                                     foreach ($linked_ids as $linked_id) {
                                         $new_val = FrmProFieldsHelper::get_data_value($linked_id, $field, $atts);
                                         if ($linked_id != $new_val) {
                                             $replace_with[] = $new_val;
                                         }
                                         unset($new_val);
                                     }
                                     $replace_with = implode($sep, $replace_with);
                                 } else {
                                     $replace_with = FrmProFieldsHelper::get_data_value($replace_with, $field, $atts);
                                 }
                             }
                         }
                     } else {
                         if (is_array($replace_with)) {
                             $linked_ids = $replace_with;
                             $replace_with = array();
                             foreach ($linked_ids as $linked_id) {
                                 $new_val = FrmProFieldsHelper::get_data_value($linked_id, $field, $atts);
                                 if ($linked_id != $new_val) {
                                     $replace_with[] = $new_val;
                                 }
                                 unset($new_val);
                             }
                             $replace_with = implode($sep, $replace_with);
                         } else {
                             $replace_with = FrmProFieldsHelper::get_data_value($replace_with, $field, $atts);
                         }
                     }
                 } else {
                     if ($field->type == 'textarea') {
                         $autop = isset($atts['wpautop']) ? $atts['wpautop'] : true;
                         if (apply_filters('frm_use_wpautop', $autop)) {
                             $replace_with = wpautop($replace_with);
                         }
                         unset($autop);
                     } else {
                         if ($field->type == 'number') {
                             if (!isset($atts['decimal'])) {
                                 $num = explode('.', $replace_with);
                                 $atts['decimal'] = isset($num[1]) ? strlen($num[1]) : 0;
                             }
                             if (!isset($atts['dec_point'])) {
                                 $atts['dec_point'] = '.';
                             }
                             if (!isset($atts['thousands_sep'])) {
                                 $atts['thousands_sep'] = '';
                             }
                             $replace_with = number_format($replace_with, $atts['decimal'], $atts['dec_point'], $atts['thousands_sep']);
                         }
                     }
                 }
             }
         }
     }
     $replace_with = stripslashes_deep($replace_with);
     return $replace_with;
 }
 function get_post_value($post_id, $post_field, $custom_field, $atts)
 {
     if (!$post_id) {
         return '';
     }
     $post = get_post($post_id);
     if (!$post) {
         return '';
     }
     $defaults = array('sep' => ', ', 'truncate' => true, 'form_id' => false, 'field' => array(), 'links' => false, 'show' => '');
     $atts = wp_parse_args($atts, $defaults);
     $value = '';
     if ($atts['type'] == 'tag') {
         if (isset($atts['field']->field_options)) {
             $field_options = maybe_unserialize($atts['field']->field_options);
             $tax = $field_options['taxonomy'];
             if ($tags = get_the_terms($post_id, $tax)) {
                 $names = array();
                 foreach ($tags as $tag) {
                     $tag_name = $tag->name;
                     if ($atts['links']) {
                         $tag_name = '<a href="' . esc_attr(get_term_link($tag)) . '" title="' . esc_attr(sprintf(__('View all posts filed under %s', 'formidable'), $tag_name)) . '">' . $tag_name . '</a>';
                     }
                     $names[] = $tag_name;
                 }
                 $value = implode($atts['sep'], $names);
             }
         }
     } else {
         if ($post_field == 'post_custom') {
             //get custom post field value
             $value = get_post_meta($post_id, $custom_field, true);
         } else {
             if ($post_field == 'post_category') {
                 if ($atts['form_id']) {
                     $post_type = FrmProForm::post_type($atts['form_id']);
                     $taxonomy = FrmProAppHelper::get_custom_taxonomy($post_type, $atts['field']);
                 } else {
                     $taxonomy = 'category';
                 }
                 $categories = get_the_terms($post_id, $taxonomy);
                 $names = array();
                 $cat_ids = array();
                 if ($categories) {
                     foreach ($categories as $cat) {
                         if (isset($atts['exclude_cat']) and in_array($cat->term_id, (array) $atts['exclude_cat'])) {
                             continue;
                         }
                         $cat_name = $cat->name;
                         if ($atts['links']) {
                             $cat_name = '<a href="' . esc_attr(get_term_link($cat)) . '" title="' . esc_attr(sprintf(__('View all posts filed under %s', 'formidable'), $cat_name)) . '">' . $cat_name . '</a>';
                         }
                         $names[] = $cat_name;
                         $cat_ids[] = $cat->term_id;
                     }
                 }
                 if ($atts['show'] == 'id') {
                     $value = implode($atts['sep'], $cat_ids);
                 } else {
                     if ($atts['truncate']) {
                         $value = implode($atts['sep'], $names);
                     } else {
                         $value = $cat_ids;
                     }
                 }
             } else {
                 $post = (array) $post;
                 $value = $post[$post_field];
             }
         }
     }
     return $value;
 }
Beispiel #14
0
 function validate($errors, $field)
 {
     if ($field->type == 'user_id') {
         // make sure we have a user ID
         if (!is_numeric($_POST['item_meta'][$field->id])) {
             $_POST['item_meta'][$field->id] = FrmProAppHelper::get_user_id_param($_POST['item_meta'][$field->id]);
         }
         //add user id to post variables to be saved with entry
         $_POST['frm_user_id'] = $_POST['item_meta'][$field->id];
     } else {
         if ($field->type == 'time' and is_array($_POST['item_meta'][$field->id])) {
             $_POST['item_meta'][$field->id] = $value = $_POST['item_meta'][$field->id]['H'] . ':' . $_POST['item_meta'][$field->id]['m'] . (isset($_POST['item_meta'][$field->id]['A']) ? ' ' . $_POST['item_meta'][$field->id]['A'] : '');
         }
     }
     // don't validate if going backwards
     if (FrmProFormsHelper::going_to_prev($field->form_id)) {
         return array();
     }
     // clear any existing errors if draft
     if (FrmProFormsHelper::saving_draft($field->form_id) && isset($errors['field' . $field->id])) {
         unset($errors['field' . $field->id]);
     }
     //if the field is a file upload, check for a file
     if ($field->type == 'file' && isset($_FILES['file' . $field->id]) && !empty($_FILES['file' . $field->id]['name'])) {
         $filled = true;
         if (is_array($_FILES['file' . $field->id]['name'])) {
             $filled = false;
             foreach ($_FILES['file' . $field->id]['name'] as $n) {
                 if (!empty($n)) {
                     $filled = true;
                 }
             }
         }
         if ($filled) {
             if (isset($errors['field' . $field->id])) {
                 unset($errors['field' . $field->id]);
             }
             if (isset($field->field_options['restrict']) && $field->field_options['restrict'] && isset($field->field_options['ftypes']) && !empty($field->field_options['ftypes'])) {
                 $mimes = $field->field_options['ftypes'];
             } else {
                 $mimes = null;
             }
             //check allowed mime types for this field
             if (is_array($_FILES['file' . $field->id]['name'])) {
                 foreach ($_FILES['file' . $field->id]['name'] as $name) {
                     if (empty($name)) {
                         continue;
                     }
                     $file_type = wp_check_filetype($name, $mimes);
                     unset($name);
                     if (!$file_type['ext']) {
                         break;
                     }
                 }
             } else {
                 $file_type = wp_check_filetype($_FILES['file' . $field->id]['name'], $mimes);
             }
             if (isset($file_type) && !$file_type['ext']) {
                 $errors['field' . $field->id] = $field->field_options['invalid'] == __('This field is invalid', 'formidable') || $field->field_options['invalid'] == '' || $field->field_options['invalid'] == $field->name . ' ' . __('is invalid', 'formidable') ? __('Sorry, this file type is not permitted for security reasons.', 'formidable') : $field->field_options['invalid'];
             }
             unset($file_type);
         }
         unset($filled);
     }
     // if saving draft, only check file type since it won't be checked later
     if (FrmProFormsHelper::saving_draft($field->form_id)) {
         return $errors;
     }
     if (in_array($field->type, array('break', 'html', 'divider'))) {
         $hidden = FrmProFieldsHelper::is_field_hidden($field, stripslashes_deep($_POST));
         global $frm_hidden_break, $frm_hidden_divider;
         if ($field->type == 'break') {
             $frm_hidden_break = array('field_order' => $field->field_order, 'hidden' => $hidden);
         } else {
             if ($field->type == 'divider') {
                 $frm_hidden_divider = array('field_order' => $field->field_order, 'hidden' => $hidden);
             }
         }
         if (isset($errors['field' . $field->id])) {
             unset($errors['field' . $field->id]);
         }
     }
     $value = $_POST['item_meta'][$field->id];
     if (($field->type != 'tag' and $value == 0 or $field->type == 'tag' and $value == '') and isset($field->field_options['post_field']) and $field->field_options['post_field'] == 'post_category' and $field->required == '1') {
         global $frm_settings;
         $errors['field' . $field->id] = (!isset($field->field_options['blank']) or $field->field_options['blank'] == '' or $field->field_options['blank'] == 'Untitled cannot be blank') ? $frm_settings->blank_msg : $field->field_options['blank'];
     }
     //Don't require fields hidden with shortcode fields="25,26,27"
     global $frm_vars;
     if (isset($frm_vars['show_fields']) and !empty($frm_vars['show_fields']) and is_array($frm_vars['show_fields']) and $field->required == '1' and isset($errors['field' . $field->id]) and !in_array($field->id, $frm_vars['show_fields']) and !in_array($field->field_key, $frm_vars['show_fields'])) {
         unset($errors['field' . $field->id]);
         $_POST['item_meta'][$field->id] = $value = '';
     }
     //Don't require a conditionally hidden field
     if (isset($field->field_options['hide_field']) and !empty($field->field_options['hide_field'])) {
         if (FrmProFieldsHelper::is_field_hidden($field, stripslashes_deep($_POST))) {
             if (isset($errors['field' . $field->id])) {
                 unset($errors['field' . $field->id]);
             }
             $_POST['item_meta'][$field->id] = $value = '';
         }
     }
     //Don't require a field hidden in a conditional page or section heading
     if (isset($errors['field' . $field->id]) or $_POST['item_meta'][$field->id] != '') {
         global $frm_hidden_break, $frm_hidden_divider;
         if ($frm_hidden_break and $frm_hidden_break['hidden'] or $frm_hidden_divider and $frm_hidden_divider['hidden'] and (!$frm_hidden_break or $frm_hidden_break['field_order'] < $frm_hidden_divider['field_order'])) {
             if (isset($errors['field' . $field->id])) {
                 unset($errors['field' . $field->id]);
             }
             $_POST['item_meta'][$field->id] = $value = '';
         }
     }
     //make sure the [auto_id] is still unique
     if (!empty($field->default_value) and !is_array($field->default_value) and !empty($value) and is_numeric($value) and strpos($field->default_value, '[auto_id') !== false) {
         //make sure we are not editing
         if (isset($_POST) and !isset($_POST['id']) or !is_numeric($_POST['id'])) {
             $_POST['item_meta'][$field->id] = $value = FrmProFieldsHelper::get_default_value($field->default_value, $field);
         }
     }
     //check uniqueness
     if ($value and !empty($value) and isset($field->field_options['unique']) and $field->field_options['unique']) {
         $entry_id = (isset($_POST) and isset($_POST['id'])) ? $_POST['id'] : false;
         if ($field->type == 'time') {
             //TODO: add server-side validation for unique date-time
         } else {
             if ($field->type == 'date') {
                 global $frmpro_settings;
                 $old_value = $value;
                 if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', trim($value))) {
                     $value = FrmProAppHelper::convert_date($value, $frmpro_settings->date_format, 'Y-m-d');
                 }
                 if (FrmProEntryMetaHelper::value_exists($field->id, $value, $entry_id)) {
                     $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'unique_msg');
                 }
                 $value = $old_value;
             } else {
                 if (FrmProEntryMetaHelper::value_exists($field->id, $value, $entry_id)) {
                     $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'unique_msg');
                 }
             }
         }
         unset($entry_id);
     }
     // validate number settings
     if ('number' == $field->type && $value != '') {
         global $frm_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->id] = __('Please select a higher number', 'formidable');
             } else {
                 if ((double) $value > $field->field_options['maxnum']) {
                     $errors['field' . $field->id] = __('Please select a lower number', 'formidable');
                 }
             }
         }
     }
     if (!empty($value) and ($field->type == 'website' or $field->type == 'url' or $field->type == 'image')) {
         if (trim($value) == 'http://') {
             $_POST['item_meta'][$field->id] = $value = '';
         } else {
             $value = esc_url_raw($value);
             $_POST['item_meta'][$field->id] = $value = preg_match('/^(https?|ftps?|mailto|news|feed|telnet):/is', $value) ? $value : 'http://' . $value;
         }
     }
     $errors = FrmProEntryMetaHelper::set_post_fields($field, $value, $errors);
     if (!FrmProFieldsHelper::is_field_visible_to_user($field)) {
         //don't validate admin only fields that can't be seen
         unset($errors['field' . $field->id]);
         return $errors;
     }
     if (false and isset($field->field_options['use_calc']) and !empty($field->field_options['use_calc']) and !empty($field->field_options['calc'])) {
         $field->field_options['calc'] = trim($field->field_options['calc']);
         preg_match_all("/\\[(.*?)\\]/s", $field->field_options['calc'], $calc_matches, PREG_PATTERN_ORDER);
         if (isset($calc_matches[1])) {
             foreach ($calc_matches[1] as $c) {
                 if (is_numeric($c)) {
                     $c_id = $c;
                 } else {
                     global $frm_field;
                     $c_field = $frm_field->getOne($c);
                     if (!$c_field) {
                         $field->field_options['calc'] = str_replace('[' . $c . ']', 0, $field->field_options['calc']);
                         continue;
                     }
                     $c_id = $c_field->id;
                     unset($c_field);
                 }
                 $c_val = trim($_POST['item_meta'][$c_id]);
                 if (!is_numeric($c_val)) {
                     preg_match_all('/[0-9,]*\\.?[0-9]+/', $c_val, $c_matches);
                     $c_val = $c_matches ? end($c_matches[0]) : 0;
                     unset($c_matches);
                 }
                 if ($c_val == '') {
                     $c_val = 0;
                 }
                 $field->field_options['calc'] = str_replace('[' . $c . ']', $c_val, $field->field_options['calc']);
                 unset($c);
                 unset($c_id);
             }
             include FrmAppHelper::plugin_path() . '/pro/classes/helpers/FrmProMathHelper.php';
             $m = new EvalMath();
             if (strpos($field->field_options['calc'], ').toFixed(')) {
                 $field->field_options['calc'] = str_replace(').toFixed(2', '', $field->field_options['calc']);
                 $round = 2;
             }
             $result = $m->evaluate(str_replace('Math.', '', '(' . $field->field_options['calc'] . ')'));
             if (isset($round) and $round) {
                 $result = sprintf('%.' . $round . 'f', $result);
             }
             unset($m);
             $_POST['item_meta'][$field->id] = $value = $result;
             unset($result);
         }
         unset($calc_matches);
     }
     //Don't validate the format if field is blank
     if ($value == '' or is_array($value)) {
         return $errors;
     }
     $value = trim($value);
     //validate the format
     if ($field->type == 'number' and !is_numeric($value) or $field->type == 'email' and !is_email($value) or ($field->type == 'website' or $field->type == 'url' or $field->type == 'image') and !preg_match('/^http(s)?:\\/\\/([\\da-z\\.-]+)\\.([\\da-z\\.-]+)/i', $value)) {
         $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'invalid');
     }
     if ($field->type == 'phone') {
         $pattern = (isset($field->field_options['format']) and !empty($field->field_options['format'])) ? $field->field_options['format'] : '^((\\+\\d{1,3}(-|.| )?\\(?\\d\\)?(-| |.)?\\d{1,5})|(\\(?\\d{2,6}\\)?))(-|.| )?(\\d{3,4})(-|.| )?(\\d{4})(( x| ext)\\d{1,5}){0,1}$';
         $pattern = apply_filters('frm_phone_pattern', $pattern, $field);
         //check if format is already a regular expression
         if (strpos($pattern, '^') !== 0) {
             //if not, create a regular expression
             $pattern = preg_replace('/\\d/', '\\d', preg_quote($pattern));
             $pattern = '/^' . $pattern . '$/';
         } else {
             $pattern = '/' . $pattern . '/';
         }
         if (!preg_match($pattern, $value)) {
             $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'invalid');
         }
         unset($pattern);
     }
     if ($field->type == 'date') {
         if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $value)) {
             global $frmpro_settings;
             $formated_date = FrmProAppHelper::convert_date($value, $frmpro_settings->date_format, 'Y-m-d');
             //check format before converting
             if ($value != date($frmpro_settings->date_format, strtotime($formated_date))) {
                 $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'invalid');
             }
             $value = $formated_date;
             unset($formated_date);
         }
         $date = explode('-', $value);
         if (count($date) != 3 or !checkdate((int) $date[1], (int) $date[2], (int) $date[0])) {
             $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'invalid');
         }
     }
     return $errors;
 }
 public static function get_time_display_value($replace_with, $atts, $field)
 {
     $time_clock = isset($field->field_options['clock']) ? $field->field_options['clock'] : 12;
     $defaults = array('format' => $time_clock == 24 ? 'H:i' : 'g:i A');
     $atts = wp_parse_args($atts, $defaults);
     if (strpos($replace_with, ',')) {
         $replace_with = explode(',', $replace_with);
     }
     if (is_array($replace_with)) {
         foreach ($replace_with as $k => $v) {
             $replace_with[$k] = FrmProAppHelper::format_time($replace_with[$k], $atts['format']);
         }
     } else {
         $replace_with = FrmProAppHelper::format_time($replace_with, $atts['format']);
     }
     return $replace_with;
 }
Beispiel #16
0
 function single_row($item, $style = '')
 {
     global $frmpro_settings;
     $checkbox = '';
     // Set up the hover actions for this user
     $actions = array();
     $edit_link = "?page=formidable-{$this->page_name}&frm_action=edit&id={$item->id}";
     $actions['edit'] = "<a href='" . wp_nonce_url($edit_link) . "'>" . __('Edit') . "</a>";
     $duplicate_link = "?page=formidable-{$this->page_name}&frm_action=duplicate&id={$item->id}";
     $delete_link = "?page=formidable-{$this->page_name}&frm_action=destroy&id={$item->id}";
     if ($this->plural == 'entries') {
         $duplicate_link .= "&form=" . $this->params['form'];
         $delete_link .= "&form=" . $this->params['form'];
         $view_link = "?page=formidable-{$this->page_name}&frm_action=show&id={$item->id}";
         $actions['view'] = "<a href='" . wp_nonce_url($view_link) . "'>" . __('View', 'formidable') . "</a>";
     }
     $actions['duplicate'] = "<a href='" . wp_nonce_url($duplicate_link) . "'>" . __('Duplicate', 'formidable') . "</a>";
     $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url($delete_link) . "' onclick='return confirm(\"" . __('Are you sure you want to delete that?', 'formidable') . "\")'>" . __('Delete') . "</a>";
     if ($this->plural == 'entries') {
         if (!current_user_can('frm_edit_entries')) {
             unset($actions['edit']);
         }
         if (!current_user_can('frm_create_entries')) {
             unset($actions['duplicate']);
         }
         if (!current_user_can('frm_delete_entries')) {
             unset($actions['delete']);
         }
     }
     $actions = apply_filters('frm_row_actions', $actions, $item);
     $action_links = $this->row_actions($actions);
     // Set up the checkbox ( because the user is editable, otherwise its empty )
     $checkbox = "<input type='checkbox' name='item-action[]' id='cb-item-action-{$item->id}' value='{$item->id}' />";
     $r = "<tr id='item-action-{$item->id}'{$style}>";
     list($columns, $hidden) = $this->get_column_info();
     $action_col = false;
     foreach ($columns as $column_name => $column_display_name) {
         $class = "class=\"{$column_name} column-{$column_name}\"";
         $style = '';
         if (in_array($column_name, $hidden)) {
             $style = ' style="display:none;"';
         } else {
             if (!$action_col and !in_array($column_name, array('cb', 'id', 'form_id', 'post_id'))) {
                 $action_col = $column_name;
             }
         }
         $attributes = "{$class}{$style}";
         $col_name = preg_replace('/^(' . $this->params['form'] . '_)/', '', $column_name);
         switch ($col_name) {
             case 'cb':
                 $r .= "<th scope='row' class='check-column'>{$checkbox}</th>";
                 break;
             case 'ip':
             case 'id':
             case 'item_key':
             case 'display_key':
             case 'show_count':
                 $val = $item->{$col_name};
                 break;
             case 'name':
             case 'description':
             case 'content':
             case 'dyncontent':
                 $val = FrmAppHelper::truncate(strip_tags($item->{$col_name}), 100);
                 break;
             case 'created_at':
             case 'updated_at':
                 $date = FrmProAppHelper::get_formatted_time($item->{$col_name}, $frmpro_settings->date_format);
                 $val = "<abbr title='" . FrmProAppHelper::get_formatted_time($item->{$col_name}, $frmpro_settings->date_format, 'g:i:s A') . "'>" . $date . "</abbr>";
                 break;
             case 'is_draft':
                 $val = empty($item->is_draft) ? __('No') : __('Yes');
                 break;
             case 'form_id':
                 $frm_form = new FrmForm();
                 $form = $frm_form->getName($item->form_id);
                 if ($form) {
                     $val = '<a href="' . admin_url('admin.php') . '?page=formidable&frm_action=edit&id=' . $item->form_id . '">' . FrmAppHelper::truncate($form, 40) . '</a>';
                 } else {
                     $val = '';
                 }
                 break;
             case 'post_id':
                 $post = get_post($item->{$col_name});
                 if ($post) {
                     $val = '<a href="' . admin_url('post.php') . '?post=' . $item->{$col_name} . '&amp;action=edit">' . FrmAppHelper::truncate($post->post_title, 50) . '</a>';
                 } else {
                     $val = '';
                 }
                 break;
             case 'user_id':
                 $user = get_userdata($item->user_id);
                 $val = $user->user_login;
                 break;
             case 'shortcode':
                 $code = '';
                 $val = '<input type="text" readonly="true" class="frm_select_box" value="' . esc_attr($code) . '" />';
                 break;
             default:
                 if ($this->plural == 'entries') {
                     global $frm_field;
                     if (strpos($col_name, 'frmsep_') === 0) {
                         $sep_val = true;
                         $col_name = str_replace('frmsep_', '', $col_name);
                     } else {
                         $sep_val = false;
                     }
                     $col = $frm_field->getOne($col_name);
                     $field_value = isset($item->metas[$col->id]) ? $item->metas[$col->id] : false;
                     if (!$field_value and $col->type == 'data' and (!isset($col->field_options['data_type']) or $col->field_options['data_type'] == 'data') and isset($col->field_options['hide_field'])) {
                         $field_value = array();
                         foreach ((array) $col->field_options['hide_field'] as $hfield) {
                             if (isset($item->metas[$hfield])) {
                                 $field_value[] = maybe_unserialize($item->metas[$hfield]);
                             }
                         }
                     }
                     $atts = array('type' => $col->type, 'truncate' => true, 'post_id' => $item->post_id, 'entry_id' => $item->id);
                     if ($sep_val) {
                         $atts['saved_value'] = true;
                     }
                     $val = FrmProEntryMetaHelper::display_value($field_value, $col, $atts);
                 } else {
                     $val = $col_name;
                 }
                 break;
         }
         if (isset($val)) {
             $r .= "<td {$attributes}>";
             if ($column_name == $action_col) {
                 $r .= '<a class="row-title" href="' . (isset($actions['edit']) ? $edit_link : $view_link) . '">' . $val . '</a> ';
                 $r .= $action_links;
             } else {
                 $r .= $val;
             }
             $r .= '</td>';
         }
         unset($val);
     }
     $r .= '</tr>';
     return $r;
 }
 public static function confirmation($method, $form, $form_options, $entry_id, $args = array())
 {
     $opt = !isset($args['action']) || $args['action'] == 'create' ? 'success' : 'edit';
     if ($method == 'page' && is_numeric($form_options[$opt . '_page_id'])) {
         global $post;
         if (!$post || $form_options[$opt . '_page_id'] != $post->ID) {
             $page = get_post($form_options[$opt . '_page_id']);
             $old_post = $post;
             $post = $page;
             $content = apply_filters('frm_content', $page->post_content, $form, $entry_id);
             echo apply_filters('the_content', $content);
             $post = $old_post;
         }
     } else {
         if ($method == 'redirect') {
             global $frm_vars;
             add_filter('frm_use_wpautop', '__return_false');
             $success_url = apply_filters('frm_content', trim($form_options[$opt . '_url']), $form, $entry_id);
             $success_msg = isset($form_options[$opt . '_msg']) ? $form_options[$opt . '_msg'] : __('Please wait while you are redirected.', 'formidable');
             $redirect_msg = '<div class="' . esc_attr(FrmFormsHelper::get_form_style_class($form)) . '"><div class="frm-redirect-msg frm_message">' . $success_msg . '<br/>' . sprintf(__('%1$sClick here%2$s if you are not automatically redirected.', 'formidable'), '<a href="' . esc_url($success_url) . '">', '</a>') . '</div></div>';
             $redirect_msg = apply_filters('frm_redirect_msg', $redirect_msg, array('entry_id' => $entry_id, 'form_id' => $form->id, 'form' => $form));
             $args['id'] = $entry_id;
             add_filter('frm_redirect_url', 'FrmProEntriesController::redirect_url');
             //delete the entry on frm_redirect_url hook
             $success_url = apply_filters('frm_redirect_url', $success_url, $form, $args);
             $doing_ajax = FrmAppHelper::doing_ajax();
             if (isset($args['ajax']) && $args['ajax'] && $doing_ajax) {
                 echo json_encode(array('redirect' => $success_url));
                 die;
             } else {
                 if (!$doing_ajax && !headers_sent()) {
                     wp_redirect(esc_url_raw($success_url));
                     die;
                 }
             }
             add_filter('frm_use_wpautop', '__return_true');
             $response = $redirect_msg;
             $response .= "<script type='text/javascript'>jQuery(document).ready(function(){ setTimeout(window.location='" . esc_url_raw($success_url) . "', 8000); });</script>";
             if (headers_sent()) {
                 echo $response;
             } else {
                 wp_redirect(esc_url_raw($success_url));
                 die;
             }
         } else {
             $frm_settings = FrmAppHelper::get_settings();
             $frmpro_settings = FrmProAppHelper::get_settings();
             $msg = $opt == 'edit' ? $frmpro_settings->edit_msg : $frm_settings->success_msg;
             $message = isset($form->options[$opt . '_msg']) ? $form->options[$opt . '_msg'] : $msg;
             // Replace $message with save draft message if we are saving a draft
             FrmProFormsHelper::save_draft_msg($message, $form);
             $class = 'frm_message';
             $message = FrmFormsHelper::get_success_message(compact('message', 'form', 'entry_id', 'class'));
             return $message;
         }
     }
 }
 public static function get_field_value_shortcode($atts)
 {
     extract(shortcode_atts(array('entry_id' => false, 'field_id' => false, 'user_id' => false, 'ip' => false, 'show' => '', 'format' => ''), $atts));
     if (!$field_id) {
         return __('You are missing options in your shortcode. field_id is required.', 'formidable');
     }
     global $frm_field, $wpdb, $frmdb;
     $field = $frm_field->getOne($field_id);
     if (!$field) {
         return '';
     }
     $query = $wpdb->prepare("SELECT post_id, id FROM {$frmdb->entries} WHERE form_id=%d", $field->form_id);
     if ($user_id) {
         // make sure we are not getting entries for logged-out users
         $query .= $wpdb->prepare(' AND user_id=%d AND user_id > 0', (int) FrmProAppHelper::get_user_id_param($user_id));
     }
     if ($entry_id) {
         if (!is_numeric($entry_id)) {
             $entry_id = isset($_GET[$entry_id]) ? $_GET[$entry_id] : $entry_id;
         }
         if ((int) $entry_id < 1) {
             // don't run the sql query if we know there will be no results
             return;
         }
         $query .= $wpdb->prepare(' AND id=%d', (int) $entry_id);
     }
     if ($ip) {
         $query .= $wpdb->prepare(' AND ip=%s', $ip == true ? $_SERVER['REMOTE_ADDR'] : $ip);
     }
     $query .= " ORDER BY created_at DESC LIMIT 1";
     $entry = $wpdb->get_row($query);
     if (!$entry) {
         return;
     }
     $value = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, $atts);
     $atts['type'] = $field->type;
     $atts['post_id'] = $entry->post_id;
     $atts['entry_id'] = $entry->id;
     if (!isset($atts['show_filename'])) {
         $atts['show_filename'] = false;
     }
     if (isset($show) and !empty($show)) {
         $atts['show'] = $show;
         $value = FrmProFieldsHelper::get_display_value($value, $field, $atts);
     } else {
         $value = FrmProEntryMetaHelper::display_value($value, $field, $atts);
     }
     return $value;
 }
 public static function dropdown_categories($args)
 {
     $defaults = array('field' => false, 'name' => false, 'show_option_all' => ' ');
     $args = wp_parse_args($args, $defaults);
     if (!$args['field']) {
         return;
     }
     if (!$args['name']) {
         $args['name'] = 'item_meta[' . $args['field']['id'] . ']';
     }
     $id = self::get_html_id($args['field']);
     $class = $args['field']['type'];
     $exclude = is_array($args['field']['exclude_cat']) ? implode(',', $args['field']['exclude_cat']) : $args['field']['exclude_cat'];
     $exclude = apply_filters('frm_exclude_cats', $exclude, $args['field']);
     if (is_array($args['field']['value'])) {
         if (!empty($exclude)) {
             $args['field']['value'] = array_diff($args['field']['value'], explode(',', $exclude));
         }
         $selected = reset($args['field']['value']);
     } else {
         $selected = $args['field']['value'];
     }
     $tax_atts = array('show_option_all' => $args['show_option_all'], 'hierarchical' => 1, 'name' => $args['name'], 'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected, 'hide_empty' => false, 'echo' => 0, 'orderby' => 'name');
     $tax_atts = apply_filters('frm_dropdown_cat', $tax_atts, $args['field']);
     if (FrmAppHelper::pro_is_installed()) {
         $post_type = FrmProFormsHelper::post_type($args['field']['form_id']);
         $tax_atts['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $args['field']);
         if (!$tax_atts['taxonomy']) {
             return;
         }
         // If field type is dropdown (not Dynamic), exclude children when parent is excluded
         if ($args['field']['type'] != 'data' && is_taxonomy_hierarchical($tax_atts['taxonomy'])) {
             $tax_atts['exclude_tree'] = $exclude;
         }
     }
     $dropdown = wp_dropdown_categories($tax_atts);
     $add_html = FrmFieldsController::input_html($args['field'], false);
     if (FrmAppHelper::pro_is_installed()) {
         $add_html .= FrmProFieldsController::input_html($args['field'], false);
     }
     $dropdown = str_replace("<select name='" . esc_attr($args['name']) . "' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "'", "<select name='" . esc_attr($args['name']) . "' id='" . esc_attr($id) . "' " . $add_html, $dropdown);
     if (is_array($args['field']['value'])) {
         $skip = true;
         foreach ($args['field']['value'] as $v) {
             if ($skip) {
                 $skip = false;
                 continue;
             }
             $dropdown = str_replace(' value="' . esc_attr($v) . '"', ' value="' . esc_attr($v) . '" selected="selected"', $dropdown);
             unset($v);
         }
     }
     return $dropdown;
 }
#frm_show_cal.theme_smoothness{ background-position: 0 -420px; } 
#frm_show_cal.theme_south-street{ background-position: 0 -448px; } 
#frm_show_cal.theme_start{ background-position: 0 -476px; } 
#frm_show_cal.theme_sunny{ background-position: 0 -504px; } 
#frm_show_cal.theme_swanky-purse{ background-position: 0 -532px; } 
#frm_show_cal.theme_trontastic{ background-position: 0 -560px; } 
#frm_show_cal.theme_ui-darkness{ background-position: 0 -588px; } 
#frm_show_cal.theme_ui-lightness{ background-position: 0 -616px; } 
#frm_show_cal.theme_vader{ background-position: 0 -644px; } 
</style>


<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function($){ $("#datepicker_sample").datepicker(); frmUpdateCSS('<?php 
echo FrmProAppHelper::jquery_css_url($frmpro_settings->theme_css);
?>
'); });
//function to append a new theme stylesheet with the new style changes
function updateCSS(locStr){
	jQuery("head").append('<link href="<?php 
echo FRM_SCRIPT_URL;
?>
&amp;controller=settings&amp;'+ locStr +'" type="text/css" rel="Stylesheet" class="frm-custom-theme"/>');
	if( jQuery("link.frm-custom-theme").size() > 3){
		jQuery("link.frm-custom-theme:first").remove();
	}
};

function frm_import_templates(thisid){
    jQuery('#'+thisid).replaceWith('<img id="' + thisid + '" src="<?php 
 public static function set_post_fields($field, $value, $errors = null)
 {
     $field->field_options = maybe_unserialize($field->field_options);
     if (!isset($field->field_options['post_field']) || $field->field_options['post_field'] == '') {
         if (isset($errors)) {
             return $errors;
         }
         return;
     }
     if ($field->type == 'file') {
         global $frm_vars;
         if (!isset($frm_vars['media_id'])) {
             $frm_vars['media_id'] = array();
         }
         $frm_vars['media_id'][$field->id] = $value;
     }
     global $frmpro_settings;
     if ($value && !empty($value) && isset($field->field_options['unique']) && $field->field_options['unique']) {
         global $frmdb;
         $entry_id = isset($_POST) && isset($_POST['id']) ? $_POST['id'] : false;
         $post_id = $entry_id ? $frmdb->get_var($frmdb->entries, array('id' => $entry_id), 'post_id') : false;
         if (isset($errors) && FrmProEntryMetaHelper::post_value_exists($field->field_options['post_field'], $value, $post_id, $field->field_options['custom_field'])) {
             $errors['field' . $field->id] = FrmProFieldsHelper::get_error_msg($field, 'unique_msg');
         }
         unset($entry_id);
         unset($post_id);
     }
     if ($field->field_options['post_field'] == 'post_custom') {
         if ($field->type == 'date' and !preg_match('/^\\d{4}-\\d{2}-\\d{2}/', trim($value))) {
             $value = FrmProAppHelper::convert_date($value, $frmpro_settings->date_format, 'Y-m-d');
         }
         $_POST['frm_wp_post_custom'][$field->id . '=' . $field->field_options['custom_field']] = $value;
         if (isset($errors)) {
             return $errors;
         }
         return;
     }
     if ($field->field_options['post_field'] == 'post_date') {
         if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}/', trim($value))) {
             $value = FrmProAppHelper::convert_date($value, $frmpro_settings->date_format, 'Y-m-d H:i:s');
         }
     } else {
         if ($field->type != 'tag' && $field->field_options['post_field'] == 'post_category') {
             $value = (array) $value;
             // change text to numeric ids
             if (defined('WP_IMPORTING')) {
                 foreach ($value as $k => $val) {
                     if (empty($val)) {
                         continue;
                     }
                     $term = term_exists($val, $field->field_options['taxonomy']);
                     if ($term) {
                         $value[$k] = is_array($term) ? $term['term_id'] : $term;
                     }
                     unset($k, $val, $term);
                 }
             }
             if (isset($field->field_options['taxonomy']) && $field->field_options['taxonomy'] != 'category') {
                 $new_value = array();
                 foreach ($value as $val) {
                     if ($val == 0) {
                         continue;
                     }
                     $term = get_term($val, $field->field_options['taxonomy']);
                     if (!isset($term->errors)) {
                         $new_value[$val] = $term->name;
                     } else {
                         $new_value[$val] = $val;
                     }
                     unset($term);
                 }
                 if (!isset($_POST['frm_tax_input'])) {
                     $_POST['frm_tax_input'] = array();
                 }
                 if (isset($_POST['frm_tax_input'][$field->field_options['taxonomy']])) {
                     foreach ($new_value as $new_key => $new_name) {
                         $_POST['frm_tax_input'][$field->field_options['taxonomy']][$new_key] = $new_name;
                     }
                 } else {
                     $_POST['frm_tax_input'][$field->field_options['taxonomy']] = $new_value;
                 }
             } else {
                 $_POST['frm_wp_post'][$field->id . '=' . $field->field_options['post_field']] = $value;
             }
         } else {
             if ($field->type == 'tag' && $field->field_options['post_field'] == 'post_category') {
                 $value = trim($value);
                 $value = array_map('trim', explode(',', $value));
                 $tax_type = isset($field->field_options['taxonomy']) && !empty($field->field_options['taxonomy']) ? $field->field_options['taxonomy'] : 'frm_tag';
                 if (!isset($_POST['frm_tax_input'])) {
                     $_POST['frm_tax_input'] = array();
                 }
                 if (is_taxonomy_hierarchical($tax_type)) {
                     //create the term or check to see if it exists
                     $terms = array();
                     foreach ($value as $v) {
                         $term_id = term_exists($v, $tax_type);
                         if (!$term_id) {
                             $term_id = wp_insert_term($v, $tax_type);
                         }
                         if ($term_id && is_array($term_id)) {
                             $term_id = $term_id['term_id'];
                         }
                         if (is_numeric($term_id)) {
                             $terms[$term_id] = $v;
                         }
                         unset($term_id);
                         unset($v);
                     }
                     $value = $terms;
                     unset($terms);
                 }
                 if (!isset($_POST['frm_tax_input'][$tax_type])) {
                     $_POST['frm_tax_input'][$tax_type] = (array) $value;
                 } else {
                     $_POST['frm_tax_input'][$tax_type] += (array) $value;
                 }
             }
         }
     }
     if ($field->field_options['post_field'] != 'post_category') {
         $_POST['frm_wp_post'][$field->id . '=' . $field->field_options['post_field']] = $value;
     }
     if (isset($errors)) {
         return $errors;
     }
 }
 public static function add_form_msg_options($values)
 {
     global $frm_vars;
     $post_types = FrmProAppHelper::get_custom_post_types();
     require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-forms/add_form_msg_options.php';
 }
 public static function add_bulk_actions($footer)
 {
     FrmProAppHelper::bulk_actions($footer);
 }
 public static function ajax_time_options()
 {
     global $frmpro_settings, $frmdb, $wpdb, $frm_entry_meta;
     //posted vars = $time_field, $date_field, $date
     extract($_POST);
     $time_key = str_replace('field_', '', $time_field);
     $date_key = str_replace('field_', '', $date_field);
     if (!preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', trim($date))) {
         $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
     }
     $date_entries = $frm_entry_meta->getEntryIds(array('fi.field_key' => $date_key, 'meta_value' => $date));
     $remove = array();
     if ($date_entries and !empty($date_entries)) {
         $query = $wpdb->prepare("SELECT meta_value FROM {$frmdb->entry_metas} it LEFT JOIN {$frmdb->fields} fi ON (it.field_id = fi.id) WHERE fi.field_key=%s", $time_key);
         if (is_numeric($entry_id)) {
             $query = $wpdb->prepare(' and it.item_id != %d', $entry_id);
         }
         $used_times = $wpdb->get_col("{$query} and it.item_id in (" . implode(',', $date_entries) . ")");
         if ($used_times and !empty($used_times)) {
             $number_allowed = apply_filters('frm_allowed_time_count', 1, $time_key, $date_key);
             $count = array();
             foreach ($used_times as $used) {
                 if (isset($remove[$used])) {
                     continue;
                 }
                 if (!isset($count[$used])) {
                     $count[$used] = 0;
                 }
                 $count[$used]++;
                 if ((int) $count[$used] >= $number_allowed) {
                     $remove[$used] = $used;
                 }
             }
             unset($count);
         }
     }
     echo json_encode($remove);
     die;
 }
 function parse_pretty_entry_url()
 {
     global $frm_entry, $wpdb, $post;
     $post_url = get_permalink($post->ID);
     $request_uri = FrmProAppHelper::current_url();
     $match_str = '#^' . $post_url . '(.*?)([\\?/].*?)?$#';
     if (preg_match($match_str, $request_uri, $match_val)) {
         // match short slugs (most common)
         if (isset($match_val[1]) and !empty($match_val[1]) and $frm_entry->exists($match_val[1])) {
             // Artificially set the GET variable
             $_GET['entry'] = $match_val[1];
         }
     }
 }
 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;
 }
Beispiel #27
0
        </td>
    </tr>
    <tr class="hide_dyncontent">
        <th valign="top" scope="row"><?php 
_e('Detail Link', 'formidable');
?>
 <img src="<?php 
echo FRM_IMAGES_URL;
?>
/tooltip.png" alt="?" class="frm_help" title="<?php 
printf(__('Example: If parameter name is \'contact\', the url would be like %1$s/selected-page?contact=2. If this entry is linked to a post, the post permalink will be used instead.', 'formidable'), $frm_siteurl);
?>
" /></th>
        <td>
            <?php 
if (FrmProAppHelper::rewriting_on() && $frmpro_settings->permalinks) {
    ?>
                <select id="type" name="type">
                    <option value=""></option>
                    <option value="id" <?php 
    selected($values['type'], 'id');
    ?>
><?php 
    _e('ID', 'formidable');
    ?>
</option>
                    <option value="display_key" <?php 
    selected($values['type'], 'display_key');
    ?>
><?php 
    _e('Key', 'formidable');
Beispiel #28
0
<div class="frm_form_fields">
<?php 
global $frm_vars;
if (!isset($frm_vars['star_loaded']) or !is_array($frm_vars['star_loaded'])) {
    $frm_vars['star_loaded'] = array();
}
if (!$frm_vars['forms_loaded'] or empty($frm_vars['forms_loaded'])) {
    $frm_vars['forms_loaded'][] = true;
}
$rand = FrmProAppHelper::get_rand(3);
$name = $field->id . $rand;
if (in_array($name, $frm_vars['star_loaded'])) {
    $rand = FrmProAppHelper::get_rand(3);
    $name = $field->id . $rand;
}
$frm_vars['star_loaded'][] = $name;
$field->options = maybe_unserialize($field->options);
$max = max($field->options);
$d = 0;
if ($stat != floor($stat)) {
    $stat = round($stat, 2);
    list($n, $d) = explode('.', $stat);
    if ($d < 25) {
        $d = 0;
    } else {
        if ($d < 75) {
            $d = 5;
        } else {
            $d = 0;
            $n++;
        }
 public static function get_formatted_time($date, $date_format = '', $time_format = '')
 {
     if (empty($date)) {
         return $date;
     }
     if (empty($date_format)) {
         $date_format = get_option('date_format');
     }
     if (preg_match('/^\\d{1-2}\\/\\d{1-2}\\/\\d{4}$/', $date) && self::pro_is_installed()) {
         $frmpro_settings = new FrmProSettings();
         $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d');
     }
     $formatted = self::get_localized_date($date_format, $date);
     $do_time = date('H:i:s', strtotime($date)) != '00:00:00';
     if ($do_time) {
         $formatted .= self::add_time_to_date($time_format, $date);
     }
     return $formatted;
 }
Beispiel #30
0
                    <div class="inside">
                        <table class="form-table"><tbody> 
                        <?php 
    foreach ($comments as $comment) {
        $meta = $comment->meta_value;
        if (!isset($meta['comment'])) {
            continue;
        }
        ?>
                            <tr class="frm_comment_block">
                                <th scope="row"><p><strong><?php 
        echo FrmProFieldsHelper::get_display_name($meta['user_id'], 'display_name', array('link' => true));
        ?>
</strong><br/>
                                    <?php 
        echo FrmProAppHelper::get_formatted_time($comment->created_at, $date_format, $time_format);
        ?>
</p>
                                </th>
                                <td><div class="frm_comment"><?php 
        echo wpautop(strip_tags($meta['comment']));
        ?>
</div></td>
                            </tr>
                        <?php 
    }
    ?>
                        </table>
                        <a onclick="jQuery('#frm_comment_form').toggle('slow');" class="button-secondary alignright">+ <?php 
    _e('Add Note/Comment', 'formidable');
    ?>