Exemplo n.º 1
0
/**
 * 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;
}
Exemplo n.º 2
0
	<table class="gv-table-view-content">
		<?php 
if (!empty($this->fields['single_table-columns'])) {
    ?>
			<thead>
				<?php 
    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;
            ?>
Exemplo n.º 3
0
/**
 * 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;
}
Exemplo n.º 4
0
 /**
  * @group fieldoutput
  * @see gravityview_field_output
  * @covers ::gravityview_field_output()
  */
 public function test_gravityview_field_output()
 {
     /**
      *
      * '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,
      */
     $form = $this->factory->form->create_and_get();
     $entry = $this->factory->entry->create_and_get(array('form_id' => $form['id']));
     $markup = '<div id="{{ field_id }}" class="{{ class }}">{{label}}{{value}}</div>';
     $markup_without_spaces = '<div id="{{field_id}}" class="{{class}}">{{label}}{{value}}</div>';
     $markup_just_label = '{{label}}';
     $markup_just_value = '{{value}}';
     $args = array('entry' => $entry, 'form' => $form, 'hide_empty' => $this->atts['hide_empty']);
     return;
     foreach ($entry as $field_id => $raw_field_value) {
         if (!is_numeric($field_id)) {
             continue;
         }
         $field = gravityview_get_field($form, $field_id);
         $args['field'] = $field;
         $value = gv_value($entry, $args['field']);
         $args['markup'] = $markup;
         $output = gravityview_field_output($args);
         //$this->assertEquals( , $output );
         // Test hide empty
     }
     // Test gravityview/field_output/args filter
     add_filter('gravityview/field_output/args', array($this, '_filter_test_gravityview_field_output_args'), 10, 2);
     remove_filter('gravityview/field_output/args', array($this, '_filter_test_gravityview_field_output_args'));
 }