Example #1
0
 public static function get_meta_value($field_id, $entry)
 {
     _deprecated_function(__FUNCTION__, '2.0.9', 'FrmEntryMeta::get_meta_value');
     return FrmEntryMeta::get_meta_value($entry, $field_id);
 }
 public static function get_post_or_meta_value($entry, $field, $atts = array())
 {
     $defaults = array('links' => true, 'show' => '', 'truncate' => true, 'sep' => ', ');
     $atts = wp_parse_args((array) $atts, $defaults);
     FrmEntry::maybe_get_entry($entry);
     if (empty($entry) || empty($field)) {
         return '';
     }
     if ($entry->post_id) {
         if (!isset($field->field_options['custom_field'])) {
             $field->field_options['custom_field'] = '';
         }
         if (!isset($field->field_options['post_field'])) {
             $field->field_options['post_field'] = '';
         }
         $links = $atts['links'];
         if ($field->type == 'tag' || $field->field_options['post_field']) {
             $post_args = array('type' => $field->type, 'form_id' => $field->form_id, 'field' => $field, 'links' => $links, 'exclude_cat' => $field->field_options['exclude_cat']);
             foreach (array('show', 'truncate', 'sep') as $p) {
                 $post_args[$p] = $atts[$p];
                 unset($p);
             }
             $value = self::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], $post_args);
             unset($post_args);
         } else {
             $value = FrmEntryMeta::get_meta_value($entry, $field->id);
         }
     } else {
         $value = FrmEntryMeta::get_meta_value($entry, $field->id);
         if (('tag' == $field->type || isset($field->field_options['post_field']) && $field->field_options['post_field'] == 'post_category') && !empty($value)) {
             $value = maybe_unserialize($value);
             $new_value = array();
             foreach ((array) $value as $tax_id) {
                 if (is_numeric($tax_id)) {
                     $cat = get_term($tax_id, $field->field_options['taxonomy']);
                     $new_value[] = $cat ? $cat->name : $tax_id;
                     unset($cat);
                 } else {
                     $new_value[] = $tax_id;
                 }
             }
             $value = $new_value;
         }
     }
     return $value;
 }
 public static function replace_content_shortcodes($content, $entry, $shortcodes)
 {
     $shortcode_values = array('id' => $entry->id, 'key' => $entry->item_key, 'ip' => $entry->ip);
     foreach ($shortcodes[0] as $short_key => $tag) {
         $atts = shortcode_parse_atts($shortcodes[3][$short_key]);
         if (!empty($shortcodes[3][$short_key])) {
             $tag = str_replace(array('[', ']'), '', $shortcodes[0][$short_key]);
             $tags = explode(' ', $tag);
             if (is_array($tags)) {
                 $tag = $tags[0];
             }
         } else {
             $tag = $shortcodes[2][$short_key];
         }
         switch ($tag) {
             case 'id':
             case 'key':
             case 'ip':
                 $replace_with = $shortcode_values[$tag];
                 break;
             case 'user_agent':
             case 'user-agent':
                 $entry->description = maybe_unserialize($entry->description);
                 $replace_with = FrmEntryFormat::get_browser($entry->description['browser']);
                 break;
             case 'created_at':
             case 'created-at':
             case 'updated_at':
             case 'updated-at':
                 if (isset($atts['format'])) {
                     $time_format = ' ';
                 } else {
                     $atts['format'] = get_option('date_format');
                     $time_format = '';
                 }
                 $this_tag = str_replace('-', '_', $tag);
                 $replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format);
                 unset($this_tag);
                 break;
             case 'created_by':
             case 'created-by':
             case 'updated_by':
             case 'updated-by':
                 $this_tag = str_replace('-', '_', $tag);
                 $replace_with = self::get_display_value($entry->{$this_tag}, (object) array('type' => 'user_id'), $atts);
                 unset($this_tag);
                 break;
             case 'admin_email':
             case 'siteurl':
             case 'frmurl':
             case 'sitename':
             case 'get':
                 $replace_with = self::dynamic_default_values($tag, $atts);
                 break;
             default:
                 $field = FrmField::getOne($tag);
                 if (!$field) {
                     break;
                 }
                 $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
                 $replace_with = FrmEntryMeta::get_meta_value($entry, $field->id);
                 $atts['entry_id'] = $entry->id;
                 $atts['entry_key'] = $entry->item_key;
                 //$replace_with = apply_filters('frmpro_fields_replace_shortcodes', $replace_with, $tag, $atts, $field);
                 if (is_array($replace_with)) {
                     $replace_with = implode($sep, $replace_with);
                 }
                 if (isset($atts['show']) && $atts['show'] == 'field_label') {
                     $replace_with = $field->name;
                 } else {
                     if (isset($atts['show']) && $atts['show'] == 'description') {
                         $replace_with = $field->description;
                     } else {
                         if (empty($replace_with) && $replace_with != '0') {
                             $replace_with = '';
                         } else {
                             $replace_with = self::get_display_value($replace_with, $field, $atts);
                         }
                     }
                 }
                 unset($field);
                 break;
         }
         if (isset($replace_with)) {
             $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
         }
         unset($atts, $conditional, $replace_with);
     }
     return $content;
 }
 private static function calendar_daily_entries($entry, $display, $args, array &$daily_entries)
 {
     $i18n = false;
     if (is_numeric($display->frm_date_field_id)) {
         $date = FrmEntryMeta::get_meta_value($entry, $display->frm_date_field_id);
         if ($entry->post_id && !$date && $args['field'] && isset($args['field']->field_options['post_field']) && $args['field']->field_options['post_field']) {
             $date = FrmProEntryMetaHelper::get_post_value($entry->post_id, $args['field']->field_options['post_field'], $args['field']->field_options['custom_field'], array('form_id' => $display->frm_form_id, 'type' => $args['field']->type, 'field' => $args['field']));
         }
     } else {
         $date = $display->frm_date_field_id == 'updated_at' ? $entry->updated_at : $entry->created_at;
         $i18n = true;
     }
     if (empty($date)) {
         return;
     }
     if ($i18n) {
         $date = FrmAppHelper::get_localized_date('Y-m-d', $date);
     } else {
         $date = date('Y-m-d', strtotime($date));
     }
     unset($i18n);
     $dates = array($date);
     if (!empty($display->frm_edate_field_id)) {
         if (is_numeric($display->frm_edate_field_id) && $args['efield']) {
             $edate = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $args['efield']);
             if ($args['efield'] && $args['efield']->type == 'number' && is_numeric($edate)) {
                 $edate = date('Y-m-d', strtotime('+' . ($edate - 1) . ' days', strtotime($date)));
             }
         } else {
             if ($display->frm_edate_field_id == 'updated_at') {
                 $edate = FrmAppHelper::get_localized_date('Y-m-d', $entry->updated_at);
             } else {
                 $edate = FrmAppHelper::get_localized_date('Y-m-d', $entry->created_at);
             }
         }
         if ($edate && !empty($edate)) {
             $from_date = strtotime($date);
             $to_date = strtotime($edate);
             if (!empty($from_date) && $from_date < $to_date) {
                 for ($current_ts = $from_date; $current_ts <= $to_date; $current_ts += 60 * 60 * 24) {
                     $dates[] = date('Y-m-d', $current_ts);
                 }
                 unset($current_ts);
             }
             unset($from_date, $to_date);
         }
         unset($edate);
     }
     unset($date);
     self::get_repeating_dates($entry, $display, $args, $dates);
     $dates = apply_filters('frm_show_entry_dates', $dates, $entry);
     for ($i = 0; $i < $args['maxday'] + $args['startday']; $i++) {
         $day = $i - $args['startday'] + 1;
         if (in_array(date('Y-m-d', strtotime($args['year'] . '-' . $args['month'] . '-' . $day)), $dates)) {
             $daily_entries[$i][] = $entry;
         }
         unset($day);
     }
 }