/** * @covers GravityView_API::replace_variables() * @covers GravityView_Merge_Tags::replace_variables() */ public function test_replace_variables() { $entry = GV_Unit_Tests_Bootstrap::instance()->get_entry(); $form = GV_Unit_Tests_Bootstrap::instance()->get_form(); // No match $this->assertEquals('no bracket', GravityView_API::replace_variables('no bracket', $form, $entry)); // Include bracket with nomatch $this->assertEquals($entry['id'] . ' {nomatch}', GravityView_API::replace_variables('{entry_id} {nomatch}', $form, $entry)); // Match tag, empty value $this->assertEquals('', GravityView_API::replace_variables('{user:example}', $form, $entry)); // Open matching tag $this->assertEquals('{entry_id', GravityView_API::replace_variables('{entry_id', $form, $entry)); // Form ID $this->assertEquals($form['id'], GravityView_API::replace_variables('{form_id}', $form, $entry)); // Form title $this->assertEquals('Example ' . $form['title'], GravityView_API::replace_variables('Example {form_title}', $form, $entry)); $this->assertEquals($entry['post_id'], GravityView_API::replace_variables('{post_id}', $form, $entry)); $this->assertEquals(date('m/d/Y'), GravityView_API::replace_variables('{date_mdy}', $form, $entry)); $this->assertEquals(get_option('admin_email'), GravityView_API::replace_variables('{admin_email}', $form, $entry)); $user = wp_set_current_user($entry['created_by']); // Test new Roles merge tag $this->assertEquals(implode(', ', $user->roles), GravityView_API::replace_variables('{created_by:roles}', $form, $entry)); $user->add_role('editor'); // Test new Roles merge tag again, with another role. $this->assertEquals(implode(', ', $user->roles), GravityView_API::replace_variables('{created_by:roles}', $form, $entry)); $var_content = '<p>I expect <strong>Entry #{entry_id}</strong> will be in Form #{form_id}</p>'; $expected_content = '<p>I expect <strong>Entry #' . $entry['id'] . '</strong> will be in Form #' . $form['id'] . '</p>'; $this->assertEquals($expected_content, GravityView_API::replace_variables($var_content, $form, $entry)); }
<?php /** * Display the entry_link field type * * @package GravityView * @subpackage GravityView/templates/fields */ $gravityview_view = GravityView_View::getInstance(); extract($gravityview_view->getCurrentField()); // Don't show on single entry if ($gravityview_view->getContext() === 'single') { return; } $link_text = empty($field_settings['entry_link_text']) ? __('View Details', 'gravityview') : $field_settings['entry_link_text']; $output = apply_filters('gravityview_entry_link', GravityView_API::replace_variables($link_text, $form, $entry)); echo GravityView_API::entry_link_html($entry, $output, array(), $field_settings);
<?php /** * Generate output for the Source URL field * @package GravityView * @subpackage GravityView/templates/fields * @since 1.1.6 */ $gravityview_view = GravityView_View::getInstance(); extract($gravityview_view->getCurrentField()); // If linking to the source URL if (!empty($field_settings['link_to_source'])) { // If customizing the anchor text if (!empty($field_settings['source_link_text'])) { $link_text = GravityView_API::replace_variables($field_settings['source_link_text'], $form, $entry); } else { // Otherwise, it's just the URL $link_text = esc_html($value); } $output = gravityview_get_link($value, $link_text); } else { // Otherwise, it's just the URL $output = $value; } echo $output;
<?php /** * Display the HTML field type * * @package GravityView * @subpackage GravityView/templates/fields */ $gravityview_view = GravityView_View::getInstance(); extract($gravityview_view->getCurrentField()); // Tell the renderer not to wrap this field in an anchor tag. $gravityview_view->setCurrentFieldSetting('show_as_link', false); echo GravityView_API::replace_variables($field['content'], $form, $entry);
<?php /** * Display the website field type * * @package GravityView * @subpackage GravityView/templates/fields */ $gravityview_view = GravityView_View::getInstance(); extract($gravityview_view->getCurrentField()); if (!empty($value) && function_exists('gravityview_format_link')) { /** @since 1.8 */ $anchor_text = !empty($field_settings['anchor_text']) ? trim(rtrim($field_settings['anchor_text'])) : false; // Check empty again, just in case trim removed whitespace didn't work if (!empty($anchor_text)) { // Replace the variables $anchor_text = GravityView_API::replace_variables($anchor_text, $form, $entry); } else { $anchor_text = empty($field_settings['truncatelink']) ? $value : gravityview_format_link($value); } $attributes = empty($field_settings['open_same_window']) ? 'target=_blank' : ''; echo gravityview_get_link($value, $anchor_text, $attributes); } else { echo $display_value; }
/** * Filter the title for the single entry view * * @param string $title current title * @param int $passed_post_id Post ID * @return string (modified) title */ public function single_entry_title($title, $passed_post_id = null) { global $post; // If this is the directory view, return. if (!$this->getSingleEntry()) { return $title; } $entry = $this->getEntry(); /** * @filter `gravityview/single/title/out_loop` Apply the Single Entry Title filter outside the WordPress loop? * @param boolean $in_the_loop Whether to apply the filter to the menu title and the meta tag <title> - outside the loop * @param array $entry Current entry */ $apply_outside_loop = apply_filters('gravityview/single/title/out_loop', in_the_loop(), $entry); if (!$apply_outside_loop) { return $title; } // User reported WooCommerce doesn't pass two args. if (empty($passed_post_id)) { return $title; } // Don't modify the title for anything other than the current view/post. // This is true for embedded shortcodes and Views. if (is_object($post) && (int) $post->ID !== (int) $passed_post_id) { return $title; } $context_view_id = $this->get_context_view_id(); if ($this->getGvOutputData()->has_multiple_views() && !empty($context_view_id)) { $view_meta = $this->getGvOutputData()->get_view($context_view_id); } else { foreach ($this->getGvOutputData()->get_views() as $view_id => $view_data) { if (intval($view_data['form_id']) === intval($entry['form_id'])) { $view_meta = $view_data; break; } } } if (!empty($view_meta['atts']['single_title'])) { $title = $view_meta['atts']['single_title']; // We are allowing HTML in the fields, so no escaping the output $title = GravityView_API::replace_variables($title, $view_meta['form'], $entry); $title = do_shortcode($title); } return $title; }
return; } // Default: plain email, no link $output = $value; if (!isset($field_settings['emailmailto']) || !empty($field_settings['emailmailto'])) { $params = array(); // The default link is a mailto link $link = 'mailto:' . $value; // Is the subject set? if (!empty($field_settings['emailsubject'])) { $subject = GravityView_API::replace_variables($field_settings['emailsubject'], $form, $entry); $params[] = 'subject=' . str_replace('+', '%20', urlencode($subject)); } // Is the body set? if (!empty($field_settings['emailbody'])) { $body = GravityView_API::replace_variables($field_settings['emailbody'], $form, $entry); $params[] = 'body=' . str_replace('+', '%20', urlencode($body)); } // If the subject and body have been set, use them if (!empty($params)) { $link .= '?' . implode('&', $params); } // Generate the link HTML $output = gravityview_get_link($link, $value); } /** * Prevent encrypting emails no matter what - this is handy for DataTables exports, for example * @since 1.1.6 * @var boolean */ $prevent_encrypt = apply_filters('gravityview_email_prevent_encrypt', false);
/** * Get the output for a specific entry * * @param array $entry GF Entry array * * @since 1.7.2 * * @uses gravityview_get_link * @uses GravityView_API::entry_link * @uses GravityView_API::replace_variables * * @return string HTML output for the entry */ private function get_item_output($entry) { $link = GravityView_API::entry_link($entry, $this->post_id); $item_output = gravityview_get_link($link, $this->link_format); if (!empty($this->after_link)) { /** * Modify the item output HTML * * @since 1.7.2 * * @param string $item_output The HTML output for the after_link content * @param array $entry Gravity Forms entry array * @param GravityView_Entry_List $this The current class instance */ $after_link = apply_filters('gravityview/entry-list/after-link', '<div>' . $this->after_link . '</div>', $entry, $this); $item_output .= $after_link; } $item_output = GravityView_API::replace_variables($item_output, $this->form, $entry); $item_output = '<' . $this->item_tag . '>' . $item_output . '</' . $this->item_tag . '>'; /** * Modify the item output HTML * * @since 1.7.2 * * @param string $item_output The HTML output for the item * @param array $entry Gravity Forms entry array * @param GravityView_Entry_List $this The current class instance */ $item_output = apply_filters('gravityview/entry-list/item', $item_output, $entry, $this); return $item_output; }
/** * For some specific field types prepare the filter value before adding it to search criteria * @param array $filter * @return array */ static function parse_advanced_filters($filter = array(), $view_id = NULL) { if (empty($filter['key']) || !function_exists('gravityview_get_field_type') || !class_exists('GFCommon') || !class_exists('GravityView_API')) { return $filter; } if (!empty($view_id)) { $form_id = gravityview_get_form_id($view_id); $form = gravityview_get_form($form_id); } else { global $gravityview_view; $form = $gravityview_view->form; } // replace merge tags $filter['value'] = GravityView_API::replace_variables($filter['value'], $form, array()); $field_type = gravityview_get_field_type($form, $filter['key']); switch ($field_type) { case 'date': $local_timestamp = GFCommon::get_local_timestamp(); $date = strtotime($filter['value'], $local_timestamp); if ($date) { $filter['value'] = date('Y-m-d', $date); } else { do_action('gravityview_log_error', __METHOD__ . ' - Date formatting passed to Advanced Filter is invalid', $filter['value']); } break; } return $filter; }
/** * @return string */ public function getBackLinkLabel() { $back_link_label = GravityView_API::replace_variables($this->back_link_label, $this->getForm(), $this->getCurrentEntry()); $back_link_label = do_shortcode($back_link_label); return $back_link_label; }
<?php /** * Display the Section field type * * @package GravityView * @subpackage GravityView/templates/fields */ $gravityview_view = GravityView_View::getInstance(); extract($gravityview_view->getCurrentField()); // Tell the renderer not to wrap this field in an anchor tag. $gravityview_view->setCurrentFieldSetting('show_as_link', false); if (!empty($field['description'])) { echo GravityView_API::replace_variables($field['description'], $form, $entry); }
} // Tell the renderer not to wrap this field in an anchor tag. $gravityview_view->setCurrentFieldSetting('show_as_link', false); /** * @filter `gravityview/fields/custom/content_before` Modify Custom Content field output before Merge Tag processing * @since 1.6.2 * @param string $content HTML content of field */ $field_settings['content'] = apply_filters('gravityview/fields/custom/content_before', $field_settings['content']); $field_settings['content'] = trim(rtrim($field_settings['content'])); // No custom content if (empty($field_settings['content'])) { return; } // Replace the variables $content = GravityView_API::replace_variables($field_settings['content'], $form, $entry); /** * @filter `gravityview/fields/custom/decode_shortcodes` Decode brackets in shortcodes * @since 1.16.5 * @param boolean $decode Enable/Disable decoding of brackets in the content (default: false) * @param string $content HTML content of field */ if (apply_filters('gravityview/fields/custom/decode_shortcodes', false, $content)) { $content = GVCommon::decode_shortcodes($content); } // Add paragraphs? if (!empty($field_settings['wpautop'])) { $content = wpautop($content); } /** * @filter `gravityview/fields/custom/content_after` Modify Custom Content field output after Merge Tag variables get replaced, before shortcodes get processed