Example #1
0
 function conditional_replace_with_value($replace_with, $atts, $field, $tag)
 {
     if ($field and isset($atts['show']) and $field->type == 'data') {
         $old_replace_with = $replace_with;
         $replace_with = FrmProFieldsHelper::get_display_value($replace_with, $field, $atts);
         if ($old_replace_with == $replace_with) {
             $replace_with = '';
         }
     }
     if (isset($atts['equals']) and $replace_with != $atts['equals']) {
         if ($field and $field->type == 'data') {
             $replace_with = FrmProFieldsHelper::get_display_value($replace_with, $field, $atts);
             if ($replace_with != $atts['equals']) {
                 $replace_with = '';
             }
         } else {
             if ($field->field_options['post_field'] == 'post_category') {
                 $cats = explode(', ', $replace_with);
                 $replace_with = '';
                 foreach ($cats as $cat) {
                     if ($replace_with == true) {
                         continue;
                     }
                     if ($atts['equals'] == strip_tags($cat)) {
                         $replace_with = true;
                     }
                 }
             } else {
                 $replace_with = '';
             }
         }
     } else {
         if (isset($atts['equals']) and ($atts['equals'] == '' and $replace_with == '' or $atts['equals'] == '0' and $replace_with == '0')) {
             $replace_with = true;
             //if the field is blank, give it a value
         }
     }
     if (isset($atts['not_equal'])) {
         if ($replace_with == $atts['not_equal']) {
             $replace_with = '';
         } else {
             if (!empty($replace_with) and $field->field_options['post_field'] == 'post_category') {
                 $cats = explode(', ', $replace_with);
                 foreach ($cats as $cat) {
                     if (empty($replace_with)) {
                         continue;
                     }
                     if ($atts['not_equal'] == strip_tags($cat)) {
                         $replace_with = '';
                     }
                 }
             }
         }
     }
     if (isset($atts['like'])) {
         if (strpos($replace_with, $atts['like']) === false) {
             $replace_with = '';
         }
     }
     if (isset($atts['not_like'])) {
         if (strpos($replace_with, $atts['not_like']) !== false) {
             $replace_with = '';
         }
     }
     if (isset($atts['less_than'])) {
         if ($field and $field->type == 'date' and !preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', trim($atts['less_than']))) {
             $atts['less_than'] = date_i18n('Y-m-d', strtotime($atts['less_than']));
         }
         if ($atts['less_than'] < $replace_with) {
             $replace_with = '';
         }
     }
     if (isset($atts['greater_than'])) {
         if ($field and $field->type == 'date' and !preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', trim($atts['greater_than']))) {
             $atts['greater_than'] = date_i18n('Y-m-d', strtotime($atts['greater_than']));
         }
         if ($atts['greater_than'] > $replace_with) {
             $replace_with = '';
         }
     }
     return $replace_with;
 }
 public static function conditional_replace_with_value($replace_with, $atts, $field, $tag)
 {
     if ($field && isset($atts['show']) && $field->type == 'data') {
         $old_replace_with = $replace_with;
         $replace_with = FrmProFieldsHelper::get_display_value($replace_with, $field, $atts);
         if ($old_replace_with == $replace_with) {
             $replace_with = '';
         }
     } else {
         if ($field && $field->type == 'user_id' || in_array($tag, array('updated_by', 'created_by'))) {
             // check if conditional is for current user
             if (isset($atts['equals']) && $atts['equals'] == 'current') {
                 $atts['equals'] = get_current_user_id();
             }
             if (isset($atts['not_equal']) && $atts['not_equal'] == 'current') {
                 $atts['not_equal'] = get_current_user_id();
             }
         } else {
             if (in_array($tag, array('created-at', 'created_at', 'updated-at', 'updated_at')) || $field && $field->type == 'date') {
                 foreach (array('equals', 'not_equal', 'like', 'not_like', 'less_than', 'greater_than') as $att_name) {
                     if (isset($atts[$att_name]) && $atts[$att_name] != '' && !preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', trim($atts[$att_name]))) {
                         $atts[$att_name] = date_i18n('Y-m-d', strtotime($atts[$att_name]));
                     }
                     unset($att_name);
                 }
             }
         }
     }
     if (isset($atts['equals']) && $replace_with != $atts['equals']) {
         if ($field && $field->type == 'data') {
             $replace_with = FrmProFieldsHelper::get_display_value($replace_with, $field, $atts);
             if ($replace_with != $atts['equals']) {
                 $replace_with = '';
             }
         } else {
             if (isset($field->field_options['post_field']) && $field->field_options['post_field'] == 'post_category') {
                 $cats = explode(', ', $replace_with);
                 $replace_with = '';
                 foreach ($cats as $cat) {
                     if ($replace_with == true) {
                         continue;
                     }
                     if ($atts['equals'] == strip_tags($cat)) {
                         $replace_with = true;
                     }
                 }
             } else {
                 $replace_with = '';
             }
         }
     } else {
         if (isset($atts['equals']) && ($atts['equals'] == '' && $replace_with == '' || $atts['equals'] == '0' && $replace_with == '0')) {
             $replace_with = true;
             //if the field is blank, give it a value
         }
     }
     if (isset($atts['not_equal'])) {
         if ($replace_with == $atts['not_equal']) {
             $replace_with = '';
         } else {
             if ($replace_with == '' && $atts['not_equal'] !== '') {
                 $replace_with = true;
             } else {
                 if (!empty($replace_with) && isset($field->field_options['post_field']) && $field->field_options['post_field'] == 'post_category') {
                     $cats = explode(', ', $replace_with);
                     foreach ($cats as $cat) {
                         if (empty($replace_with)) {
                             continue;
                         }
                         if ($atts['not_equal'] == strip_tags($cat)) {
                             $replace_with = '';
                         }
                         unset($cat);
                     }
                 }
             }
         }
     }
     if (isset($atts['like']) && $atts['like'] != '') {
         if (strpos($replace_with, $atts['like']) === false) {
             $replace_with = '';
         }
     }
     if (isset($atts['not_like']) && $atts['not_like'] != '') {
         if ($replace_with == '') {
             $replace_with = true;
         } else {
             if (strpos($replace_with, $atts['not_like']) !== false) {
                 $replace_with = '';
             }
         }
     }
     if (isset($atts['less_than'])) {
         if ($atts['less_than'] <= $replace_with) {
             $replace_with = '';
         } else {
             if ($atts['less_than'] > 0 && $replace_with == '0') {
                 $replace_with = true;
             }
         }
     }
     if (isset($atts['greater_than'])) {
         if ($atts['greater_than'] >= $replace_with) {
             $replace_with = '';
         }
     }
     return $replace_with;
 }
 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 ajax_get_data()
 {
     $entry_id = trim(FrmAppHelper::get_param('entry_id'), ',');
     $field_id = FrmAppHelper::get_param('field_id');
     $current_field = (int) FrmAppHelper::get_param('current_field');
     global $frm_entry_meta, $frm_field;
     $data_field = $frm_field->getOne($field_id);
     $current = $frm_field->getOne($current_field);
     if (strpos($entry_id, ',')) {
         $entry_id = explode(',', $entry_id);
         $meta_value = array();
         foreach ($entry_id as $eid) {
             $new_meta = FrmProEntryMetaHelper::get_post_or_meta_value($eid, $data_field);
             if ($new_meta) {
                 if (is_array($new_meta)) {
                     foreach ($new_meta as $nm) {
                         array_push($meta_value, $nm);
                         unset($nm);
                     }
                 } else {
                     array_push($meta_value, $new_meta);
                 }
             }
             unset($new_meta);
             unset($eid);
         }
     } else {
         $meta_value = FrmProEntryMetaHelper::get_post_or_meta_value($entry_id, $data_field);
     }
     $value = FrmProFieldsHelper::get_display_value($meta_value, $data_field, array('html' => true));
     if (is_array($value)) {
         $value = implode(', ', $value);
     }
     if (is_array($meta_value)) {
         $meta_value = implode(', ', $meta_value);
     }
     if ($value && !empty($value)) {
         echo apply_filters('frm_show_it', "<p class='frm_show_it'>" . $value . "</p>\n", $value, array('field' => $data_field, 'value' => $meta_value, 'entry_id' => $entry_id));
     }
     $current_field = (array) $current;
     foreach ($current->field_options as $o => $v) {
         if (!isset($current_field[$o])) {
             $current_field[$o] = $v;
         }
         unset($o);
         unset($v);
     }
     echo '<input type="hidden" id="field_' . $current->field_key . '" name="item_meta[' . $current->id . ']" value="' . esc_attr($meta_value) . '" ' . do_action('frm_field_input_html', $current_field, false) . '/>';
     die;
 }
 function ajax_get_data($entry_id, $field_id, $current_field)
 {
     global $frm_entry_meta, $frm_field;
     $data_field = $frm_field->getOne($field_id);
     $current = $frm_field->getOne($current_field);
     $meta_value = FrmProEntryMetaHelper::get_post_or_meta_value($entry_id, $data_field);
     $value = FrmProFieldsHelper::get_display_value($meta_value, $data_field);
     if ($value and !empty($value)) {
         echo "<p class='frm_show_it'>" . $value . "</p>\n";
     }
     echo '<input type="hidden" id="field_' . $current->field_key . '" name="item_meta[' . $current_field . ']" value="' . stripslashes(esc_attr($meta_value)) . '"/>';
     die;
 }
Example #6
0
" id="<?php 
                        echo esc_attr($html_id);
                        ?>
" name="<?php 
                        echo esc_attr($field_name);
                        ?>
" value="<?php 
                        echo esc_attr($field['value']);
                        ?>
" <?php 
                        do_action('frm_field_input_html', $field);
                        ?>
/>
<?php 
                        if ($field['value']) {
                            echo FrmProFieldsHelper::get_display_value($field['value'], $field, array('html' => true));
                        }
                    } else {
                        if ($field['type'] == 'scale') {
                            require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/10radio.php';
                            if (FrmField::is_option_true($field, 'star')) {
                                if (!isset($frm_vars['star_loaded']) || !is_array($frm_vars['star_loaded'])) {
                                    $frm_vars['star_loaded'] = array(true);
                                }
                            }
                            // Rich Text for back-end
                        } else {
                            if ($field['type'] == 'rte' && FrmAppHelper::is_admin()) {
                                ?>
<div id="<?php 
                                echo user_can_richedit() ? 'postdivrich' : 'postdiv';