/** * Output field based on a certain html markup * * markup - string to be used on a sprintf statement. * Use: * {{label}} - field label * {{value}} - entry field value * {{class}} - field class * * wpautop - true will filter the value using wpautop function * * @since 1.1.5 * @param array $passed_args Associative array with field data. `field` and `form` are required. * @return string Field output. If empty value and hide empty is true, return empty. */ function gravityview_field_output($passed_args) { $defaults = array('entry' => null, 'field' => null, 'form' => null, 'hide_empty' => true, 'markup' => '<div id="{{ field_id }}" class="{{ class }}">{{label}}{{value}}</div>', 'label_markup' => '', 'wpautop' => false, 'zone_id' => null); $args = wp_parse_args($passed_args, $defaults); /** * @filter `gravityview/field_output/args` Modify the args before generation begins * @since 1.7 * @param array $args Associative array; `field` and `form` is required. * @param array $passed_args Original associative array with field data. `field` and `form` are required. */ $args = apply_filters('gravityview/field_output/args', $args, $passed_args); // Required fields. if (empty($args['field']) || empty($args['form'])) { do_action('gravityview_log_error', '[gravityview_field_output] Field or form are empty.', $args); return ''; } $entry = empty($args['entry']) ? array() : $args['entry']; /** * Create the Context for replacing. * @since 1.11 */ $context = array(); $context['value'] = gv_value($entry, $args['field']); // If the value is empty and we're hiding empty, return empty. if ($context['value'] === '' && !empty($args['hide_empty'])) { return ''; } if ($context['value'] !== '' && !empty($args['wpautop'])) { $context['value'] = wpautop($context['value']); } // Get width setting, if exists $context['width'] = GravityView_API::field_width($args['field']); // If replacing with CSS inline formatting, let's do it. $context['width:style'] = GravityView_API::field_width($args['field'], 'width:' . $context['width'] . '%;'); // Grab the Class using `gv_class` $context['class'] = gv_class($args['field'], $args['form'], $entry); $context['field_id'] = GravityView_API::field_html_attr_id($args['field'], $args['form'], $entry); // Get field label if needed if (!empty($args['label_markup'])) { $context['label'] = str_replace(array('{{label}}', '{{ label }}'), '<span class="gv-field-label">{{ label_value }}</span>', $args['label_markup']); } if (empty($context['label'])) { $context['label'] = '<span class="gv-field-label">{{ label_value }}</span>'; } // Default Label value $context['label_value'] = gv_label($args['field'], $entry); /** * @filter `gravityview/field_output/pre_html` Allow Pre filtering of the HTML * @since 1.11 * @param string $markup The HTML for the markup * @param array $args All args for the field output */ $html = apply_filters('gravityview/field_output/pre_html', $args['markup'], $args); /** * @filter `gravityview/field_output/open_tag` Modify the opening tags for the template content placeholders * @since 1.11 * @param string $open_tag Open tag for template content placeholders. Default: `{{` */ $open_tag = apply_filters('gravityview/field_output/open_tag', '{{', $args); /** * @filter `gravityview/field_output/close_tag` Modify the closing tags for the template content placeholders * @since 1.11 * @param string $close_tag Close tag for template content placeholders. Default: `}}` */ $close_tag = apply_filters('gravityview/field_output/close_tag', '}}', $args); /** * Loop through each of the tags to replace and replace both `{{tag}}` and `{{ tag }}` with the values * @since 1.11 */ foreach ($context as $tag => $value) { // If the tag doesn't exist just skip it if (false === strpos($html, $open_tag . $tag . $close_tag) && false === strpos($html, $open_tag . ' ' . $tag . ' ' . $close_tag)) { continue; } // Array to search $search = array($open_tag . $tag . $close_tag, $open_tag . ' ' . $tag . ' ' . $close_tag); /** * `gravityview/field_output/context/{$tag}` Allow users to filter content on context * @since 1.11 * @param string $value The content to be shown instead of the {{tag}} placeholder * @param array $args Arguments passed to the function */ $value = apply_filters('gravityview/field_output/context/' . $tag, $value, $args); // Finally do the replace $html = str_replace($search, $value, $html); } /** * @todo Depricate `gravityview_field_output` */ $html = apply_filters('gravityview_field_output', $html, $args); /** * @filter `gravityview/field_output/html` Modify field HTML output * @param string $html Existing HTML output * @param array $args Arguments passed to the function */ $html = apply_filters('gravityview/field_output/html', $html, $args); // Just free up a tiny amount of memory unset($value, $args, $passed_args, $entry, $context, $search, $open_tag, $tag, $close_tag); return $html; }
<tfoot> <tr> <?php if (!empty($this->fields['directory_table-columns'])) { foreach ($this->fields['directory_table-columns'] as $field) { echo '<th class="' . gv_class($field) . '">' . esc_html(gv_label($field)) . '</th>'; } } ?> </tr> <?php gravityview_footer(); ?> </tfoot> </table> </div> <?php gravityview_after();
<?php /** * Display the fileupload field type * * @package GravityView * @subpackage GravityView/templates/fields */ $gravityview_view = GravityView_View::getInstance(); extract($gravityview_view->getCurrentField()); $output = ''; if (!empty($value)) { $gv_class = gv_class($field, $gravityview_view->getForm(), $entry); $output_arr = gravityview_get_files_array($value, $gv_class); // If the output array is just one item, let's not show a list. if (sizeof($output_arr) === 1) { $output = $output_arr[0]['content']; } else { // For each file, show as a list foreach ($output_arr as $key => $item) { // Fix empty lists if (empty($item['content'])) { continue; } $output .= '<li>' . $item['content'] . '</li>'; } if (!empty($output)) { $output = sprintf("<ul class='gv-field-file-uploads %s'>%s</ul>", $gv_class, $output); } } }
/** * Output field based on a certain html markup * * markup - string to be used on a sprintf statement. * Use: * {{label}} - field label * {{value}} - entry field value * {{class}} - field class * * wpautop - true will filter the value using wpautop function * * @since 1.1.5 * @param array $passed_args Associative array with field data. `field` and `form` are required. * @return string */ function gravityview_field_output($passed_args) { $defaults = array('entry' => NULL, 'field' => NULL, 'form' => NULL, 'hide_empty' => true, 'markup' => '<div class="{{class}}">{{label}}{{value}}</div>', 'label_markup' => '', 'wpautop' => false, 'zone_id' => NULL); $args = wp_parse_args($passed_args, $defaults); /** * Modify the args before generation begins * * @since 1.7 * * @param array $args Associative array; `field` and `form` is required. * @param array $passed_args Original associative array with field data. `field` and `form` are required. * */ $args = apply_filters('gravityview/field_output/args', $args, $passed_args); // Required fields. if (empty($args['field']) || empty($args['form'])) { do_action('gravityview_log_error', '[gravityview_field_output] Field or form are empty.', $args); return ''; } $entry = empty($args['entry']) ? array() : $args['entry']; $value = gv_value($entry, $args['field']); // If the value is empty and we're hiding empty, return empty. if ($value === '' && !empty($args['hide_empty'])) { return ''; } if ($value !== '' && !empty($args['wpautop'])) { $value = wpautop($value); } // Get width setting, if exists $width = GravityView_API::field_width($args['field']); //If replacing with CSS inline formatting, let's do it. $width_style = GravityView_API::field_width($args['field'], 'width:' . $width . '%%;'); $class = gv_class($args['field'], $args['form'], $entry); // get field label if needed if (!empty($args['label_markup']) || false !== strpos($args['markup'], '{{label}}')) { $label = gv_label($args['field'], $entry); } else { $label = ''; } if (!empty($label)) { // If the label markup is overridden if (!empty($args['label_markup'])) { $label = str_replace('{{label}}', '<span class="gv-field-label">' . $label . '</span>', $args['label_markup']); } else { $args['markup'] = str_replace('{{label}}', '<span class="gv-field-label">{{label}}</span>', $args['markup']); } } $html = $args['markup']; $html = str_replace('{{width}}', $width, $html); $html = str_replace('{{width:style}}', $width_style, $html); $html = str_replace('{{class}}', $class, $html); $html = str_replace('{{label}}', $label, $html); $html = str_replace('{{value}}', $value, $html); /** * Modify the output * @param string $html Existing HTML output * @param array $args Arguments passed to the function */ $html = apply_filters('gravityview_field_output', $html, $args); unset($value, $label, $class, $width, $width_style, $args, $passed_args, $entry); return $html; }
gravityview_header(); ?> </thead> <tbody> <?php foreach ($this->entries as $entry) { ?> <?php foreach ($this->fields['single_table-columns'] as $field) { $value = gv_value($entry, $field); if ($value === '' && $this->atts['hide_empty']) { continue; } ?> <tr class="<?php echo gv_class($field, $this->form, $entry); ?> "> <th scope="row"><?php echo esc_html(gv_label($field)); ?> </th> <td><?php echo $value; ?> </td> </tr> <?php } ?> <?php