1
1
<?php
2
2
class GFCommon{
3
3
4
- public static $ version = "1.7.2 " ;
4
+ public static $ version = "1.7.8 " ;
5
5
public static $ tab_index = 1 ;
6
6
public static $ errors = array ();
7
7
@@ -360,8 +360,10 @@ public static function OLD_insert_variables($fields, $element_id, $hide_all_fiel
360
360
<option value='{entry_url}'><?php _e ("Entry URL " , "gravityforms " ); ?> </option>
361
361
<option value='{form_id}'><?php _e ("Form Id " , "gravityforms " ); ?> </option>
362
362
<option value='{form_title}'><?php _e ("Form Title " , "gravityforms " ); ?> </option>
363
+ <option value='{referer}'><?php _e ("HTTP Referer URL " , "gravityforms " ); ?> </option>
363
364
<option value='{user_agent}'><?php _e ("HTTP User Agent " , "gravityforms " ); ?> </option>
364
365
366
+
365
367
<?php if (self ::has_post_field ($ fields )){ ?>
366
368
<option value='{post_id}'><?php _e ("Post Id " , "gravityforms " ); ?> </option>
367
369
<option value='{post_edit_url}'><?php _e ("Post Edit URL " , "gravityforms " ); ?> </option>
@@ -506,6 +508,7 @@ public static function get_merge_tags($fields, $element_id, $hide_all_fields = f
506
508
$ other_group [] = array ('tag ' => '{form_id} ' , 'label ' => __ ("Form Id " , "gravityforms " ));
507
509
$ other_group [] = array ('tag ' => '{form_title} ' , 'label ' => __ ("Form Title " , "gravityforms " ));
508
510
$ other_group [] = array ('tag ' => '{user_agent} ' , 'label ' => __ ("HTTP User Agent " , "gravityforms " ));
511
+ $ other_group [] = array ('tag ' => '{referer} ' , 'label ' => __ ("HTTP Referer URL " , "gravityforms " ));
509
512
510
513
if (self ::has_post_field ($ fields )) {
511
514
$ other_group [] = array ('tag ' => '{post_id} ' , 'label ' => __ ("Post Id " , "gravityforms " ));
@@ -777,7 +780,7 @@ private static function format_variable_value($value, $url_encode, $esc_html, $f
777
780
public static function replace_variables ($ text , $ form , $ lead , $ url_encode = false , $ esc_html =true , $ nl2br = true , $ format ="html " ){
778
781
$ text = $ nl2br ? nl2br ($ text ) : $ text ;
779
782
780
- //Replacing field variables
783
+ //Replacing field variables: {FIELD_LABEL:FIELD_ID} {My Field:2}
781
784
preg_match_all ('/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}/mi ' , $ text , $ matches , PREG_SET_ORDER );
782
785
if (is_array ($ matches ))
783
786
{
@@ -928,14 +931,20 @@ public static function replace_variables($text, $form, $lead, $url_encode = fals
928
931
$ use_admin_label = in_array ("admin " , $ options );
929
932
930
933
//all submitted fields using text
931
- $ text = str_replace ($ match [0 ], self ::get_submitted_fields ($ form , $ lead , $ display_empty , !$ use_value , $ format , $ use_admin_label , "all_fields " , rgar ($ match ,2 )), $ text );
934
+ if (strpos ($ text , $ match [0 ]) !== false ){
935
+ $ text = str_replace ($ match [0 ], self ::get_submitted_fields ($ form , $ lead , $ display_empty , !$ use_value , $ format , $ use_admin_label , "all_fields " , rgar ($ match ,2 )), $ text );
936
+ }
932
937
}
933
938
934
939
//all submitted fields including empty fields
935
- $ text = str_replace ("{all_fields_display_empty} " , self ::get_submitted_fields ($ form , $ lead , true , true , $ format , false , "all_fields_display_empty " ), $ text );
940
+ if (strpos ($ text , "{all_fields_display_empty} " ) !== false ){
941
+ $ text = str_replace ("{all_fields_display_empty} " , self ::get_submitted_fields ($ form , $ lead , true , true , $ format , false , "all_fields_display_empty " ), $ text );
942
+ }
936
943
937
944
//pricing fields
938
- $ text = str_replace ("{pricing_fields} " , self ::get_submitted_pricing_fields ($ form , $ lead , $ format ), $ text );
945
+ if (strpos ($ text , "{pricing_fields} " ) !== false ){
946
+ $ text = str_replace ("{pricing_fields} " , self ::get_submitted_pricing_fields ($ form , $ lead , $ format ), $ text );
947
+ }
939
948
940
949
//form id
941
950
$ text = str_replace ("{form_id} " , $ url_encode ? urlencode ($ form ["id " ]) : $ form ["id " ], $ text );
@@ -962,6 +971,10 @@ public static function replace_variables($text, $form, $lead, $url_encode = fals
962
971
963
972
// hook allows for custom merge tags
964
973
$ text = apply_filters ('gform_replace_merge_tags ' , $ text , $ form , $ lead , $ url_encode , $ esc_html , $ nl2br , $ format );
974
+
975
+ // TODO: Deprecate the 'gform_replace_merge_tags' and replace it with a call to the 'gform_merge_tag_filter'
976
+ //$text = apply_filters('gform_merge_tag_filter', $text, false, false, false );
977
+
965
978
return $ text ;
966
979
}
967
980
@@ -1394,7 +1407,7 @@ private static function prepare_admin_notification($form, $lead, $override_optio
1394
1407
$ replyTo = rgempty ("replyToField " , $ form ["notification " ]) ? rgget ("replyTo " , $ form ["notification " ]): rgget ($ form ["notification " ]["replyToField " ], $ lead );
1395
1408
1396
1409
if (rgempty ("routing " , $ form ["notification " ])){
1397
- $ email_to = rgget ("to " , $ form ["notification " ]);
1410
+ $ email_to = rgempty ( " toField " , $ form [ " notification " ]) ? rgget ("to " , $ form [ " notification " ]) : rgget ( " toField " , $ form ["notification " ]);
1398
1411
}
1399
1412
else {
1400
1413
$ email_to = array ();
@@ -1611,15 +1624,21 @@ private static function send_email($from, $to, $bcc, $reply_to, $subject, $messa
1611
1624
$ bcc = str_replace (" " , "" , $ bcc );
1612
1625
1613
1626
//invalid to email address or no content. can't send email
1614
- if (!GFCommon::is_valid_email ($ to ) || (empty ($ subject ) && empty ($ message )))
1627
+ if (!GFCommon::is_valid_email ($ to ) || (empty ($ subject ) && empty ($ message ))){
1628
+ GFCommon::log_debug ("Cannot send email because either the TO address is invalid or there is no SUBJECT or MESSAGE. " );
1629
+ GFCommon::log_debug (print_r (compact ("to " , "subject " , "message " ), true ));
1615
1630
return ;
1631
+ }
1616
1632
1617
1633
if (!GFCommon::is_valid_email ($ from ))
1618
1634
$ from = get_bloginfo ("admin_email " );
1619
1635
1620
1636
//invalid from address. can't send email
1621
- if (!GFCommon::is_valid_email ($ from ))
1637
+ if (!GFCommon::is_valid_email ($ from )){
1638
+ GFCommon::log_debug ("Cannot send email because the FROM address is invalid. " );
1639
+ GFCommon::log_debug (print_r (compact ("to " , "from " , "subject " ), true ));
1622
1640
return ;
1641
+ }
1623
1642
1624
1643
$ content_type = $ message_format == "html " ? "text/html " : "text/plain " ;
1625
1644
@@ -1642,7 +1661,7 @@ private static function send_email($from, $to, $bcc, $reply_to, $subject, $messa
1642
1661
$ is_success = false ;
1643
1662
if (!$ abort_email ){
1644
1663
GFCommon::log_debug ("Sending email via wp_mail() " );
1645
- GFCommon::log_debug (compact ("to " , "subject " , "message " , "headers " , "attachments " , "abort_email " ));
1664
+ GFCommon::log_debug (print_r ( compact ("to " , "subject " , "message " , "headers " , "attachments " , "abort_email " ), true ));
1646
1665
$ is_success = wp_mail ($ to , $ subject , $ message , $ headers , $ attachments );
1647
1666
GFCommon::log_debug ("Result from wp_mail(): {$ is_success }" );
1648
1667
}
@@ -1679,15 +1698,19 @@ private static function has_field_by_type($form, $type) {
1679
1698
1680
1699
public static function current_user_can_any ($ caps ){
1681
1700
1682
- if (!is_array ($ caps ))
1683
- return current_user_can ($ caps ) || current_user_can ("gform_full_access " );
1701
+ if (!is_array ($ caps )){
1702
+ $ has_cap = current_user_can ($ caps ) || current_user_can ("gform_full_access " );
1703
+ return $ has_cap ;
1704
+ }
1684
1705
1685
1706
foreach ($ caps as $ cap ){
1686
- if (current_user_can ($ cap ))
1707
+ if (current_user_can ($ cap )){
1687
1708
return true ;
1709
+ }
1688
1710
}
1689
1711
1690
- return current_user_can ("gform_full_access " );
1712
+ $ has_full_access = current_user_can ("gform_full_access " );
1713
+ return $ has_full_access ;
1691
1714
}
1692
1715
1693
1716
public static function current_user_can_which ($ caps ){
@@ -2074,7 +2097,7 @@ public static function get_checkbox_choices($field, $value, $disabled_text){
2074
2097
$ tabindex = self ::get_tabindex ();
2075
2098
$ choice_value = $ choice ["value " ];
2076
2099
if (rgget ("enablePrice " , $ field ))
2077
- $ choice_value .= "| " . GFCommon::to_number ($ choice[ "price " ] );
2100
+ $ choice_value .= "| " . GFCommon::to_number (rgar ( $ choice, "price " ) );
2078
2101
2079
2102
$ choices .= sprintf ("<li class='gchoice_ $ id'><input name='input_%s' type='checkbox' $ logic_event value='%s' %s id='choice_%s' $ tabindex %s /><label for='choice_%s'>%s</label></li> " , $ input_id , esc_attr ($ choice_value ), $ checked , $ id , $ disabled_text , $ id , $ choice ["text " ]);
2080
2103
@@ -3594,7 +3617,7 @@ public static function get_field_input($field, $value="", $lead_id=0, $form_id=0
3594
3617
}
3595
3618
$ checked = rgpost ("gform_payment_method " ) == "creditcard " || rgempty ("gform_payment_method " ) ? "checked='checked' " : "" ;
3596
3619
$ card_radio_button = empty ($ payment_options ) ? "" : "<input type='radio' name='gform_payment_method' id='gform_payment_method_creditcard' value='creditcard' onclick='gformToggleCreditCard();' {$ checked }/> " ;
3597
- $ card_icons = "{$ payment_options }<div class='gform_card_icon_container gform_card_icon_ {$ card_style }'> {$ card_radio_button }{$ card_icons }</div><div class='gform_card_fields_container'> " ;
3620
+ $ card_icons = "{$ payment_options }<div class='gform_card_icon_container gform_card_icon_ {$ card_style }'> {$ card_radio_button }{$ card_icons }</div> " ;
3598
3621
3599
3622
3600
3623
@@ -3633,7 +3656,7 @@ public static function get_field_input($field, $value="", $lead_id=0, $form_id=0
3633
3656
$ tabindex = self ::get_tabindex ();
3634
3657
$ card_name_field = sprintf ("<span class='ginput_full {$ class_suffix }' id=' {$ field_id }_5_container'><input type='text' name='input_%d.5' id='%s_5' value='%s' {$ tabindex } %s /><label for='%s_5' id=' {$ field_id }_5_label'> " . apply_filters ("gform_card_name_ {$ form_id }" , apply_filters ("gform_card_name " ,__ ("Cardholder Name " , "gravityforms " ), $ form_id ), $ form_id ) . "</label></span> " , $ id , $ field_id , $ card_name , $ disabled_text , $ field_id );
3635
3658
3636
- return "<div class='ginput_complex {$ class_suffix } ginput_container' id=' {$ field_id }'> " . $ card_field . $ expiration_field . $ security_field . $ card_name_field . " </div></div> " ;
3659
+ return "<div class='ginput_complex {$ class_suffix } ginput_container' id=' {$ field_id }'> " . $ card_field . $ expiration_field . $ security_field . $ card_name_field . " </div> " ;
3637
3660
3638
3661
break ;
3639
3662
@@ -4720,19 +4743,25 @@ public static function create_post($form, &$lead) {
4720
4743
4721
4744
public static function evaluate_conditional_logic ($ logic , $ form , $ lead ) {
4722
4745
4723
- if (!$ logic )
4746
+ if (!$ logic || ! is_array ( $ logic [ " rules " ]) )
4724
4747
return true ;
4725
-
4748
+ $ entry_meta_keys = array_keys (GFFormsModel:: get_entry_meta ( $ form [ " id " ]));
4726
4749
$ match_count = 0 ;
4727
- foreach ($ logic ["rules " ] as $ rule ) {
4728
-
4729
- $ source_field = GFFormsModel::get_field ($ form , $ rule ["fieldId " ]);
4730
- $ field_value = empty ($ lead ) ? GFFormsModel::get_field_value ($ source_field , array ()) : GFFormsModel::get_lead_field_value ($ lead , $ source_field );
4731
- $ is_value_match = GFFormsModel::is_value_match ($ field_value , $ rule ["value " ], $ rule ["operator " ], $ source_field );
4750
+ if (is_array ($ logic ["rules " ])){
4751
+ foreach ($ logic ["rules " ] as $ rule ) {
4752
+
4753
+ if (in_array ($ rule ["fieldId " ], $ entry_meta_keys )){
4754
+ $ is_value_match = GFFormsModel::is_value_match (rgar ($ lead ,$ rule ["fieldId " ]), $ rule ["value " ], $ rule ["operator " ]);;
4755
+ } else {
4756
+ $ source_field = GFFormsModel::get_field ($ form , $ rule ["fieldId " ]);
4757
+ $ field_value = empty ($ lead ) ? GFFormsModel::get_field_value ($ source_field , array ()) : GFFormsModel::get_lead_field_value ($ lead , $ source_field );
4758
+ $ is_value_match = GFFormsModel::is_value_match ($ field_value , $ rule ["value " ], $ rule ["operator " ], $ source_field );
4759
+ }
4732
4760
4733
- if ($ is_value_match )
4734
- $ match_count ++;
4761
+ if ($ is_value_match )
4762
+ $ match_count ++;
4735
4763
4764
+ }
4736
4765
}
4737
4766
4738
4767
$ do_action = ($ logic ["logicType " ] == "all " && $ match_count == sizeof ($ logic ["rules " ]) ) || ($ logic ["logicType " ] == "any " && $ match_count > 0 );
@@ -5019,8 +5048,6 @@ public static function conditional_shortcode($attributes, $content = null) {
5019
5048
'value ' => ''
5020
5049
), $ attributes ));
5021
5050
5022
- $ result = RGFormsModel::matches_operation ($ merge_tag , $ value , $ condition );
5023
-
5024
5051
return RGFormsModel::matches_operation ($ merge_tag , $ value , $ condition ) ? do_shortcode ($ content ) : '' ;
5025
5052
5026
5053
}
@@ -5080,6 +5107,8 @@ public static function gf_global($echo = true) {
5080
5107
}
5081
5108
5082
5109
public static function gf_vars ($ echo = true ) {
5110
+ if (!class_exists ("RGCurrency " ))
5111
+ require_once ("currency.php " );
5083
5112
5084
5113
$ gf_vars = array ();
5085
5114
$ gf_vars ["active " ] = __ ("Active " , "gravityforms " );
@@ -5133,6 +5162,7 @@ public static function gf_vars($echo = true) {
5133
5162
$ gf_vars ["mergeTagsTooltip " ] = __ ('<h6>Merge Tags</h6>Merge tags allow you to dynamically populate submitted field values in your form content wherever this merge tag icon is present. ' , 'gravityforms ' );
5134
5163
5135
5164
$ gf_vars ["baseUrl " ] = GFCommon::get_base_url ();
5165
+ $ gf_vars ["gf_currency_config " ] = RGCurrency::get_currency (GFCommon::get_currency ());
5136
5166
$ gf_vars ["otherChoiceValue " ] = GFCommon::get_other_choice_value ();
5137
5167
$ gf_vars ["isFormDelete " ] = false ;
5138
5168
@@ -5203,6 +5233,21 @@ public static function display_admin_message($errors = false, $messages = false)
5203
5233
5204
5234
}
5205
5235
5236
+ private static function requires_gf_vars () {
5237
+ $ dependent_scripts = array ( 'gform_form_admin ' , 'gform_gravityforms ' , 'gform_form_editor ' );
5238
+ foreach ( $ dependent_scripts as $ script ) {
5239
+ if ( wp_script_is ( $ script ) )
5240
+ return true ;
5241
+ }
5242
+ return false ;
5243
+ }
5244
+
5245
+ public static function maybe_output_gf_vars () {
5246
+ if ( self ::requires_gf_vars () ){
5247
+ echo '<script type="text/javascript"> ' . self ::gf_vars (false ) . '</script> ' ;
5248
+ }
5249
+ }
5250
+
5206
5251
}
5207
5252
5208
5253
class GFCategoryWalker extends Walker {
@@ -5230,10 +5275,10 @@ class GFCategoryWalker extends Walker {
5230
5275
* @param int $depth Depth of category. Used for padding.
5231
5276
* @param array $args Uses 'selected' and 'show_count' keys, if they exist.
5232
5277
*/
5233
- function start_el ( &$ output , $ term , $ depth ) {
5278
+ function start_el ( &$ output , $ object , $ depth = 0 , $ args = array (), $ current_object_id = 0 ) {
5234
5279
$ pad = str_repeat (' ' , $ depth * 3 );
5235
- $ term ->name = "{$ pad }{$ term ->name }" ;
5236
- $ output [] = $ term ;
5280
+ $ object ->name = "{$ pad }{$ object ->name }" ;
5281
+ $ output [] = $ object ;
5237
5282
}
5238
5283
}
5239
5284
@@ -5315,9 +5360,14 @@ public static function delete($key) {
5315
5360
return $ success ;
5316
5361
}
5317
5362
5318
- public static function flush () {
5363
+ public static function flush ($ flush_persistent = false ) {
5319
5364
global $ wpdb ;
5320
5365
5366
+ self ::$ _cache = array ();
5367
+
5368
+ if (false === $ flush_persistent )
5369
+ return true ;
5370
+
5321
5371
if (is_multisite ()) {
5322
5372
$ sql = "
5323
5373
DELETE FROM $ wpdb ->sitemeta
@@ -5336,8 +5386,6 @@ public static function flush() {
5336
5386
5337
5387
$ success = $ rows_deleted !== false ? true : false ;
5338
5388
5339
- self ::$ _cache = array ();
5340
-
5341
5389
return $ success ;
5342
5390
}
5343
5391
@@ -5371,7 +5419,4 @@ private static function get_transient($key) {
5371
5419
return $ data ;
5372
5420
}
5373
5421
5374
- }
5375
-
5376
-
5377
- ?>
5422
+ }
0 commit comments