Esempio n. 1
0
 public static function replace_single_shortcode($shortcodes, $short_key, $tag, $entry, $display, $args, &$content)
 {
     global $post;
     $conditional = preg_match('/^\\[if/s', $shortcodes[0][$short_key]) ? true : false;
     $foreach = preg_match('/^\\[foreach/s', $shortcodes[0][$short_key]) ? true : false;
     $atts = shortcode_parse_atts($shortcodes[3][$short_key]);
     $tag = FrmFieldsHelper::get_shortcode_tag($shortcodes, $short_key, compact('conditional', 'foreach'));
     if (strpos($tag, '-')) {
         $switch_tags = array('post-id', 'created-at', 'updated-at', 'created-by', 'updated-by', 'parent-id');
         if (in_array($tag, $switch_tags)) {
             $tag = str_replace('-', '_', $tag);
         }
         unset($switch_tags);
     }
     $tags = array('event_date', 'entry_count', 'detaillink', 'editlink', 'deletelink', 'created_at', 'updated_at', 'created_by', 'updated_by', 'evenodd', 'post_id', 'parent_id', 'id');
     if (in_array($tag, $tags)) {
         $args['entry'] = $entry;
         $args['tag'] = $tag;
         $args['conditional'] = $conditional;
         $function = 'do_shortcode_' . $tag;
         self::$function($content, $atts, $shortcodes, $short_key, $args, $display);
         return;
     }
     $field = FrmField::getOne($tag);
     if (!$field) {
         return;
     }
     if (!$foreach && !$conditional && isset($atts['show']) && ($atts['show'] == 'field_label' || $atts['show'] == 'description')) {
         // get the field label or description and return before any other checking
         $replace_with = $atts['show'] == 'field_label' ? $field->name : $field->description;
         $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
         return;
     }
     $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
     if ($field->form_id == $entry->form_id) {
         $replace_with = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, $atts);
     } else {
         // get entry ids linked through repeat field or embeded form
         $child_entries = FrmProEntry::get_sub_entries($entry->id, true);
         $replace_with = FrmProEntryMetaHelper::get_sub_meta_values($child_entries, $field, $atts);
         $replace_with = FrmAppHelper::array_flatten($replace_with);
     }
     $atts['entry_id'] = $entry->id;
     $atts['entry_key'] = $entry->item_key;
     $atts['post_id'] = $entry->post_id;
     $replace_with = apply_filters('frmpro_fields_replace_shortcodes', $replace_with, $tag, $atts, $field);
     self::get_file_from_atts($atts, $field, $replace_with);
     if (isset($atts['show']) && $atts['show'] == 'count') {
         $replace_with = is_array($replace_with) ? count($replace_with) : !empty($replace_with);
     } else {
         if (is_array($replace_with) && !$foreach) {
             $replace_with = FrmAppHelper::array_flatten($replace_with);
             $replace_with = implode($sep, $replace_with);
         }
     }
     if ($foreach) {
         $atts['short_key'] = $shortcodes[0][$short_key];
         $args['display'] = $display;
         self::check_conditional_shortcode($content, $replace_with, $atts, $tag, 'foreach', $args);
     } else {
         if ($conditional) {
             $atts['short_key'] = $shortcodes[0][$short_key];
             self::check_conditional_shortcode($content, $replace_with, $atts, $tag, 'if', array('field' => $field));
         } else {
             if (empty($replace_with) && $replace_with != '0') {
                 $replace_with = '';
                 if ($field->type == 'number') {
                     $replace_with = '0';
                 }
             } else {
                 $replace_with = FrmFieldsHelper::get_display_value($replace_with, $field, $atts);
             }
             self::trigger_shortcode_atts($atts, $display, $args, $replace_with);
             $content = str_replace($shortcodes[0][$short_key], $replace_with, $content);
         }
     }
 }
Esempio n. 2
0
 public static function add_repeating_value_to_entry($field, &$entry)
 {
     // If field is in a repeating section
     if ($entry->form_id != $field->form_id) {
         // get entry ids linked through repeat field or embeded form
         $child_entries = FrmProEntry::get_sub_entries($entry->id, true);
         $val = FrmProEntryMetaHelper::get_sub_meta_values($child_entries, $field);
         if (!empty($val)) {
             //Flatten multi-dimensional arrays
             if (is_array($val)) {
                 $val = FrmAppHelper::array_flatten($val);
             }
             $entry->metas[$field->id] = $val;
         }
     } else {
         $val = '';
         FrmProEntriesHelper::get_dynamic_list_values($field, $entry, $val);
         $entry->metas[$field->id] = $val;
     }
 }