Skip to content

Commit ecef10d

Browse files
committed
Updated from 1.7.2 to 1.7.8.
1 parent e9918a9 commit ecef10d

File tree

224 files changed

+21965
-17833
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

224 files changed

+21965
-17833
lines changed

change_log.txt

100755100644
Lines changed: 1895 additions & 1786 deletions
Large diffs are not rendered by default.

common.php

100755100644
Lines changed: 82 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
class GFCommon{
33

4-
public static $version = "1.7.2";
4+
public static $version = "1.7.8";
55
public static $tab_index = 1;
66
public static $errors = array();
77

@@ -360,8 +360,10 @@ public static function OLD_insert_variables($fields, $element_id, $hide_all_fiel
360360
<option value='{entry_url}'><?php _e("Entry URL", "gravityforms"); ?></option>
361361
<option value='{form_id}'><?php _e("Form Id", "gravityforms"); ?></option>
362362
<option value='{form_title}'><?php _e("Form Title", "gravityforms"); ?></option>
363+
<option value='{referer}'><?php _e("HTTP Referer URL", "gravityforms"); ?></option>
363364
<option value='{user_agent}'><?php _e("HTTP User Agent", "gravityforms"); ?></option>
364365

366+
365367
<?php if(self::has_post_field($fields)){ ?>
366368
<option value='{post_id}'><?php _e("Post Id", "gravityforms"); ?></option>
367369
<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
506508
$other_group[] = array('tag' => '{form_id}', 'label' => __("Form Id", "gravityforms"));
507509
$other_group[] = array('tag' => '{form_title}', 'label' => __("Form Title", "gravityforms"));
508510
$other_group[] = array('tag' => '{user_agent}', 'label' => __("HTTP User Agent", "gravityforms"));
511+
$other_group[] = array('tag' => '{referer}', 'label' => __("HTTP Referer URL", "gravityforms"));
509512

510513
if(self::has_post_field($fields)) {
511514
$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
777780
public static function replace_variables($text, $form, $lead, $url_encode = false, $esc_html=true, $nl2br = true, $format="html"){
778781
$text = $nl2br ? nl2br($text) : $text;
779782

780-
//Replacing field variables
783+
//Replacing field variables: {FIELD_LABEL:FIELD_ID} {My Field:2}
781784
preg_match_all('/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}/mi', $text, $matches, PREG_SET_ORDER);
782785
if(is_array($matches))
783786
{
@@ -928,14 +931,20 @@ public static function replace_variables($text, $form, $lead, $url_encode = fals
928931
$use_admin_label = in_array("admin", $options);
929932

930933
//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+
}
932937
}
933938

934939
//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+
}
936943

937944
//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+
}
939948

940949
//form id
941950
$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
962971

963972
// hook allows for custom merge tags
964973
$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+
965978
return $text;
966979
}
967980

@@ -1394,7 +1407,7 @@ private static function prepare_admin_notification($form, $lead, $override_optio
13941407
$replyTo = rgempty("replyToField", $form["notification"]) ? rgget("replyTo", $form["notification"]): rgget($form["notification"]["replyToField"], $lead);
13951408

13961409
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"]);
13981411
}
13991412
else{
14001413
$email_to = array();
@@ -1611,15 +1624,21 @@ private static function send_email($from, $to, $bcc, $reply_to, $subject, $messa
16111624
$bcc = str_replace(" ", "", $bcc);
16121625

16131626
//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));
16151630
return;
1631+
}
16161632

16171633
if(!GFCommon::is_valid_email($from))
16181634
$from = get_bloginfo("admin_email");
16191635

16201636
//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));
16221640
return;
1641+
}
16231642

16241643
$content_type = $message_format == "html" ? "text/html" : "text/plain";
16251644

@@ -1642,7 +1661,7 @@ private static function send_email($from, $to, $bcc, $reply_to, $subject, $messa
16421661
$is_success = false;
16431662
if(!$abort_email){
16441663
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));
16461665
$is_success = wp_mail($to, $subject, $message, $headers, $attachments);
16471666
GFCommon::log_debug("Result from wp_mail(): {$is_success}");
16481667
}
@@ -1679,15 +1698,19 @@ private static function has_field_by_type($form, $type) {
16791698

16801699
public static function current_user_can_any($caps){
16811700

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+
}
16841705

16851706
foreach($caps as $cap){
1686-
if(current_user_can($cap))
1707+
if(current_user_can($cap)){
16871708
return true;
1709+
}
16881710
}
16891711

1690-
return current_user_can("gform_full_access");
1712+
$has_full_access = current_user_can("gform_full_access");
1713+
return $has_full_access;
16911714
}
16921715

16931716
public static function current_user_can_which($caps){
@@ -2074,7 +2097,7 @@ public static function get_checkbox_choices($field, $value, $disabled_text){
20742097
$tabindex = self::get_tabindex();
20752098
$choice_value = $choice["value"];
20762099
if(rgget("enablePrice", $field))
2077-
$choice_value .= "|" . GFCommon::to_number($choice["price"]);
2100+
$choice_value .= "|" . GFCommon::to_number(rgar($choice,"price"));
20782101

20792102
$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"]);
20802103

@@ -3594,7 +3617,7 @@ public static function get_field_input($field, $value="", $lead_id=0, $form_id=0
35943617
}
35953618
$checked = rgpost("gform_payment_method") == "creditcard" || rgempty("gform_payment_method") ? "checked='checked'" : "";
35963619
$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>";
35983621

35993622

36003623

@@ -3633,7 +3656,7 @@ public static function get_field_input($field, $value="", $lead_id=0, $form_id=0
36333656
$tabindex = self::get_tabindex();
36343657
$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);
36353658

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>";
36373660

36383661
break;
36393662

@@ -4720,19 +4743,25 @@ public static function create_post($form, &$lead) {
47204743

47214744
public static function evaluate_conditional_logic($logic, $form, $lead) {
47224745

4723-
if(!$logic)
4746+
if(!$logic || !is_array($logic["rules"]))
47244747
return true;
4725-
4748+
$entry_meta_keys = array_keys(GFFormsModel::get_entry_meta($form["id"]));
47264749
$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+
}
47324760

4733-
if($is_value_match)
4734-
$match_count++;
4761+
if($is_value_match)
4762+
$match_count++;
47354763

4764+
}
47364765
}
47374766

47384767
$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) {
50195048
'value' => ''
50205049
), $attributes));
50215050

5022-
$result = RGFormsModel::matches_operation($merge_tag, $value, $condition);
5023-
50245051
return RGFormsModel::matches_operation($merge_tag, $value, $condition) ? do_shortcode($content) : '';
50255052

50265053
}
@@ -5080,6 +5107,8 @@ public static function gf_global($echo = true) {
50805107
}
50815108

50825109
public static function gf_vars($echo = true) {
5110+
if(!class_exists("RGCurrency"))
5111+
require_once("currency.php");
50835112

50845113
$gf_vars = array();
50855114
$gf_vars["active"] = __("Active", "gravityforms");
@@ -5133,6 +5162,7 @@ public static function gf_vars($echo = true) {
51335162
$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');
51345163

51355164
$gf_vars["baseUrl"] = GFCommon::get_base_url();
5165+
$gf_vars["gf_currency_config"] = RGCurrency::get_currency(GFCommon::get_currency());
51365166
$gf_vars["otherChoiceValue"] = GFCommon::get_other_choice_value();
51375167
$gf_vars["isFormDelete"] = false;
51385168

@@ -5203,6 +5233,21 @@ public static function display_admin_message($errors = false, $messages = false)
52035233

52045234
}
52055235

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+
52065251
}
52075252

52085253
class GFCategoryWalker extends Walker {
@@ -5230,10 +5275,10 @@ class GFCategoryWalker extends Walker {
52305275
* @param int $depth Depth of category. Used for padding.
52315276
* @param array $args Uses 'selected' and 'show_count' keys, if they exist.
52325277
*/
5233-
function start_el( &$output, $term, $depth) {
5278+
function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0) {
52345279
$pad = str_repeat('&nbsp;', $depth * 3);
5235-
$term->name = "{$pad}{$term->name}";
5236-
$output[] = $term;
5280+
$object->name = "{$pad}{$object->name}";
5281+
$output[] = $object;
52375282
}
52385283
}
52395284

@@ -5315,9 +5360,14 @@ public static function delete($key) {
53155360
return $success;
53165361
}
53175362

5318-
public static function flush() {
5363+
public static function flush($flush_persistent = false) {
53195364
global $wpdb;
53205365

5366+
self::$_cache = array();
5367+
5368+
if(false === $flush_persistent)
5369+
return true;
5370+
53215371
if (is_multisite()) {
53225372
$sql = "
53235373
DELETE FROM $wpdb->sitemeta
@@ -5336,8 +5386,6 @@ public static function flush() {
53365386

53375387
$success = $rows_deleted !== false ? true : false;
53385388

5339-
self::$_cache = array();
5340-
53415389
return $success;
53425390
}
53435391

@@ -5371,7 +5419,4 @@ private static function get_transient($key) {
53715419
return $data;
53725420
}
53735421

5374-
}
5375-
5376-
5377-
?>
5422+
}

0 commit comments

Comments
 (0)