23 add_filter(
'gform_replace_merge_tags', array(
'GravityView_Merge_Tags',
'replace_gv_merge_tags' ), 10, 7 );
26 add_filter(
'gform_merge_tag_filter', array(
'GravityView_Merge_Tags',
'process_modifiers' ), 20, 5 );
48 if (
'all_fields' === $merge_tag ||
'' === $modifier || ! is_string( $raw_value ) ||
'' === $raw_value ) {
53 $gv_modifiers = array(
54 'maxwords:(\d+)' =>
'modifier_maxwords',
55 'timestamp' =>
'modifier_timestamp',
56 'explode' =>
'modifier_explode',
59 'urlencode' =>
'modifier_strings',
60 'wpautop' =>
'modifier_strings',
61 'esc_html' =>
'modifier_strings',
62 'sanitize_html_class' =>
'modifier_strings',
63 'sanitize_title' =>
'modifier_strings',
64 'strtolower' =>
'modifier_strings',
65 'strtoupper' =>
'modifier_strings',
66 'ucfirst' =>
'modifier_strings',
67 'ucwords' =>
'modifier_strings',
68 'wptexturize' =>
'modifier_strings',
71 $modifiers = explode(
',', $modifier );
75 $unserialized = maybe_unserialize( $raw_value );
77 if ( method_exists(
$field,
'get_value_merge_tag' ) && is_array( $unserialized ) ) {
79 $non_gv_modifiers = array_diff( $modifiers, array_keys( $gv_modifiers ) );
81 $return =
$field->get_value_merge_tag(
$value,
'', array(
'currency' =>
'' ), array(), implode(
'', $non_gv_modifiers ), $raw_value,
false,
false,
'text',
false);
84 foreach ( $modifiers as $passed_modifier ) {
86 foreach( $gv_modifiers as $gv_modifier => $method ) {
89 preg_match(
'/^' . $gv_modifier .
'/ism', $passed_modifier, $matches );
91 if ( empty( $matches ) ) {
96 $return = self::$method( $return, $matches,
$value,
$field );
102 if ( $raw_value === $return ) {
116 $return = apply_filters(
'gravityview/merge_tags/modifiers/value', $return, $raw_value,
$value, $merge_tag, $modifier,
$field );
135 if( empty( $matches[0] ) ) {
139 $timestamp = strtotime( $raw_value );
142 return ( $timestamp && $timestamp > 0 ) ? $timestamp : -1;
164 if( ! is_string( $raw_value ) || empty( $matches[1] ) || ! function_exists(
'wp_trim_words' ) ) {
168 $max = intval( $matches[1] );
170 $more_placeholder =
'[GVMORE]';
176 $return = force_balance_tags( wp_specialchars_decode( wp_trim_words( htmlentities( $raw_value ), $max, $more_placeholder ) ) );
178 $return = str_replace( $more_placeholder,
'…', $return );
180 return self::maybe_urlencode(
$field, $return );
207 if (
$field && method_exists(
$field,
'get_modifiers' ) ) {
209 $modifiers =
$field->get_modifiers();
211 if ( in_array(
'urlencode', $modifiers ) ) {
212 $return = urlencode( $return );
237 if( $json_array = json_decode( $raw_value,
true ) ) {
238 return implode(
' ', $json_array );
241 return implode(
' ', explode(
',', $raw_value ) );
258 if( empty( $matches[0] ) ) {
262 $return = $raw_value;
264 switch( $matches[0] ) {
266 $return = urlencode( $raw_value );
269 $return = trim( wpautop( $raw_value ) );
272 $return = esc_html( $raw_value );
274 case 'sanitize_html_class':
275 $return = function_exists(
'gravityview_sanitize_html_class' ) ? gravityview_sanitize_html_class( $raw_value ) : sanitize_html_class( $raw_value );
277 case 'sanitize_title':
278 $return = sanitize_title( $raw_value,
'',
'gravityview/merge-tags/modifier' );
281 $return = function_exists(
'mb_strtoupper' ) ? mb_strtoupper( $raw_value ) : strtoupper( $raw_value );
284 $return = function_exists(
'mb_strtolower' ) ? mb_strtolower( $raw_value ) : strtolower( $raw_value );
287 $return = ucwords( $raw_value );
290 $return = ucfirst( $raw_value );
293 $return = wptexturize( $raw_value );
323 if ( ! is_string( $text ) ) {
324 gravityview()->log->notice(
'$text is not a string.', array(
'data' => $text ) );
338 $do_replace_variables = apply_filters(
'gravityview/merge_tags/do_replace_variables',
true, $text,
$form,
$entry );
340 if ( strpos( $text,
'{' ) ===
false || ! $do_replace_variables ) {
353 $form[
'fields'] = isset(
$form[
'fields'] ) ?
$form[
'fields'] : array();
355 return GFCommon::replace_variables( $text,
$form,
$entry, $url_encode, $esc_html, $nl2br,
$format, $aux_data );
375 if (
'' === $text ) {
385 if (
false ===
$form ) {
389 $text = self::replace_is_starred( $text,
$form,
$entry, $url_encode, $esc_html );
391 $text = self::replace_site_url( $text,
$form,
$entry, $url_encode, $esc_html );
393 $text = self::replace_get_variables( $text,
$form,
$entry, $url_encode );
395 $text = self::replace_current_post( $text,
$form,
$entry, $url_encode, $esc_html );
397 $text = self::replace_entry_link( $text,
$form,
$entry, $url_encode, $esc_html );
417 if (
false === strpos( $original_text,
'{is_starred}' ) ) {
418 return $original_text;
421 return str_replace(
'{is_starred}', rgar(
$entry,
'is_starred',
'' ), $original_text );
439 if (
false === strpos( $original_text,
'{site_url}' ) ) {
440 return $original_text;
443 $site_url = get_site_url();
446 $site_url = urlencode( $site_url );
450 $site_url = esc_html( $site_url );
453 return str_replace(
'{site_url}', $site_url, $original_text );
470 preg_match_all(
"/{gv_entry_link(?:\:(\d+)\:?(.*?))?}/ism", $original_text, $matches, PREG_SET_ORDER );
472 if( empty( $matches ) ) {
473 return $original_text;
476 if ( ! class_exists(
'GravityView_Entry_Link_Shortcode' ) ) {
477 gravityview()->log->error(
'GravityView_Entry_Link_Shortcode not found' );
478 return $original_text;
483 $return = $original_text;
492 foreach ( $matches as $match ) {
493 $full_tag = $match[0];
497 'entry_id' =>
$entry[
'id'],
498 'post_id' => \
GV\Utils::get( $match, 1, null ),
499 'action' => \
GV\Utils::get( $match, 2,
'read' ),
502 $entry_link = $Shortcode->read_shortcode( $link_args, null,
'gv_entry_link_merge_tag' );
505 $entry_link = urlencode( $entry_link );
509 $entry_link = esc_html( $entry_link );
512 $return = str_replace( $full_tag, $entry_link, $return );
531 public static function format_date( $date_created =
'', $property =
'' ) {
534 $exploded = explode(
':', str_replace(
'\:',
'|COLON|', $property ) );
537 'format' => self::get_format_from_modifiers( $exploded,
false ),
538 'human' => in_array(
'human', $exploded ),
539 'diff' => in_array(
'diff', $exploded ),
540 'raw' => in_array(
'raw', $exploded ),
541 'timestamp' => in_array(
'timestamp', $exploded ),
542 'time' => in_array(
'time', $exploded ),
547 return $formatted_date;
567 $format_key_index = array_search(
'format', $exploded );
570 if (
false !== $format_key_index && isset( $exploded[ $format_key_index + 1 ] ) ) {
572 $return = str_replace(
'|COLON|',
':', $exploded[ $format_key_index + 1 ] );
602 $return = $original_text;
605 preg_match_all(
"/{current_post(:(.*?))?}/ism", $original_text, $matches, PREG_SET_ORDER );
608 if ( empty( $matches ) ) {
609 return $original_text;
612 $current_post = get_post();
615 if ( ! $current_post || ! is_a( $current_post,
'WP_Post' ) ) {
616 return $original_text;
619 foreach ( (array) $matches as $match ) {
620 $full_tag = $match[0];
623 $replacement =
false;
625 if (
'permalink' === $modifier ) {
626 $replacement = get_permalink( $current_post );
627 } elseif ( isset( $current_post->{$modifier} ) ) {
629 $replacement = $current_post->{$modifier};
632 if ( $replacement ) {
635 $replacement = esc_html( $replacement );
639 $replacement = urlencode( $replacement );
642 $return = str_replace( $full_tag, $replacement, $return );
675 preg_match_all(
"/{get:(.*?)}/ism", $text, $matches, PREG_SET_ORDER );
678 if( empty( $matches ) ) {
682 foreach ( $matches as $match ) {
684 $full_tag = $match[0];
685 $property = $match[1];
687 $value = stripslashes_deep( \
GV\Utils::_GET( $property ) );
695 $glue = apply_filters(
'gravityview/merge_tags/get/glue/',
', ', $property );
709 $esc_html = apply_filters(
'gravityview/merge_tags/get/esc_html/' . $property,
true );
722 $text = str_replace( $full_tag,
$value, $text );
if(gv_empty( $field['value'], false, false)) $format
if(gravityview() ->plugin->is_GF_25()) $form
static format_date( $date_string='', $args=array())
Allow formatting date and time based on GravityView standards.
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
gravityview()
The main GravityView wrapper function.
new GravityView_Entry_Link_Shortcode