GFCommon

The Gravity Forms GFCommon class.

Defined (1)

The class is defined in the following location(s).

/common.php  
  1. class GFCommon { 
  2.  
  3. // deprecated; set to GFForms::$version in GFForms::init() for backwards compat 
  4. public static $version = null; 
  5.  
  6. public static $tab_index = 1; 
  7. public static $errors = array(); 
  8. public static $messages = array(); 
  9.  
  10. public static function get_selection_fields( $form, $selected_field_id ) { 
  11.  
  12. $str = ''; 
  13. foreach ( $form['fields'] as $field ) { 
  14. $input_type = RGFormsModel::get_input_type( $field ); 
  15. $field_label = RGFormsModel::get_label( $field ); 
  16. if ( $input_type == 'checkbox' || $input_type == 'radio' || $input_type == 'select' ) { 
  17. $selected = $field->id == $selected_field_id ? "selected='selected'" : ''; 
  18. $str .= "<option value='" . $field->id . "' " . $selected . '>' . $field_label . '</option>'; 
  19.  
  20. return $str; 
  21.  
  22. public static function is_numeric( $value, $number_format = '' ) { 
  23.  
  24. if ( $number_format == 'currency' ) { 
  25.  
  26. $number_format = self::is_currency_decimal_dot() ? 'decimal_dot' : 'decimal_comma'; 
  27. $value = self::remove_currency_symbol( $value ); 
  28.  
  29. switch ( $number_format ) { 
  30. case 'decimal_dot' : 
  31. return preg_match( "/^(-?[0-9]{1, 3}(?:, ?[0-9]{3})*(?:\.[0-9]+)?)$/", $value ); 
  32. break; 
  33.  
  34. case 'decimal_comma' : 
  35. return preg_match( "/^(-?[0-9]{1, 3}(?:\.?[0-9]{3})*(?:, [0-9]+)?)$/", $value ); 
  36. break; 
  37.  
  38. default : 
  39. return preg_match( "/^(-?[0-9]{1, 3}(?:, ?[0-9]{3})*(?:\.[0-9]{2})?)$/", $value ) || preg_match( "/^(-?[0-9]{1, 3}(?:\.?[0-9]{3})*(?:, [0-9]{2})?)$/", $value ); 
  40.  
  41.  
  42. public static function remove_currency_symbol( $value, $currency = null ) { 
  43. if ( $currency == null ) { 
  44. $code = GFCommon::get_currency(); 
  45. if ( empty( $code ) ) { 
  46. $code = 'USD'; 
  47.  
  48. $currency = RGCurrency::get_currency( $code ); 
  49.  
  50. $value = str_replace( $currency['symbol_left'], '', $value ); 
  51. $value = str_replace( $currency['symbol_right'], '', $value ); 
  52.  
  53. //some symbols can't be easily matched up, so this will catch any of them 
  54. $value = preg_replace( '/[^, .\d]/', '', $value ); 
  55.  
  56. return $value; 
  57.  
  58. public static function is_currency_decimal_dot( $currency = null ) { 
  59.  
  60. if ( $currency == null ) { 
  61. $code = GFCommon::get_currency(); 
  62. if ( empty( $code ) ) { 
  63. $code = 'USD'; 
  64.  
  65. $currency = RGCurrency::get_currency( $code ); 
  66.  
  67. return rgar( $currency, 'decimal_separator' ) == '.'; 
  68.  
  69. public static function trim_all( $text ) { 
  70. $text = trim( $text ); 
  71. do { 
  72. $prev_text = $text; 
  73. $text = str_replace( ' ', ' ', $text ); 
  74. } while ( $text != $prev_text ); 
  75.  
  76. return $text; 
  77.  
  78. public static function format_number( $number, $number_format, $currency = '', $include_thousands_sep = false ) { 
  79. if ( ! is_numeric( $number ) ) { 
  80. return $number; 
  81.  
  82. //replacing commas with dots and dots with commas 
  83. if ( $number_format == 'currency' ) { 
  84. if ( empty( $currency ) ) { 
  85. $currency = GFCommon::get_currency(); 
  86.  
  87. if ( false === class_exists( 'RGCurrency' ) ) { 
  88. require_once( GFCommon::get_base_path() . '/currency.php' ); 
  89. $currency = new RGCurrency( $currency ); 
  90. $number = $currency->to_money( $number ); 
  91. } else { 
  92. if ( $number_format == 'decimal_comma' ) { 
  93. $dec_point = ', '; 
  94. $thousands_sep = $include_thousands_sep ? '.' : ''; 
  95. } else { 
  96. $dec_point = '.'; 
  97. $thousands_sep = $include_thousands_sep ? ', ' : ''; 
  98.  
  99. $is_negative = $number < 0; 
  100.  
  101. $number = explode( '.', $number ); 
  102. $number[0] = number_format( absint( $number[0] ), 0, '', $thousands_sep ); 
  103. $number = implode( $dec_point, $number ); 
  104.  
  105. if ( $is_negative ) { 
  106. $number = '-' . $number; 
  107.  
  108. return $number; 
  109.  
  110. public static function recursive_add_index_file( $dir ) { 
  111. if ( ! is_dir( $dir ) || is_link( $dir ) ) { 
  112. return; 
  113.  
  114. if ( ! ( $dp = opendir( $dir ) ) ) { 
  115. return; 
  116.  
  117. //ignores all errors 
  118. set_error_handler( create_function( '', 'return 0;' ), E_ALL ); 
  119.  
  120. //creates an empty index.html file 
  121. if ( $f = fopen( $dir . '/index.html', 'w' ) ) { 
  122. fclose( $f ); 
  123.  
  124. //restores error handler 
  125. restore_error_handler(); 
  126.  
  127. while ( ( false !== $file = readdir( $dp ) ) ) { 
  128. if ( is_dir( "$dir/$file" ) && $file != '.' && $file != '..' ) { 
  129. self::recursive_add_index_file( "$dir/$file" ); 
  130.  
  131. closedir( $dp ); 
  132.  
  133. public static function add_htaccess_file() { 
  134.  
  135. $upload_root = GFFormsModel::get_upload_root(); 
  136.  
  137. if ( ! is_dir( $upload_root ) ) { 
  138. return; 
  139. $htaccess_file = $upload_root . '/.htaccess'; 
  140. if ( file_exists( $htaccess_file ) ) { 
  141. unlink($htaccess_file); 
  142. $txt= '# Disable parsing of PHP for some server configurations. This file may be removed or modified on certain server configurations by using by the gform_upload_root_htaccess_rules filter. Please consult your system administrator before removing this file. 
  143. <Files *> 
  144. SetHandler none 
  145. SetHandler default-handler 
  146. Options -ExecCGI 
  147. RemoveHandler .cgi .php .php3 .php4 .php5 .phtml .pl .py .pyc .pyo 
  148. </Files> 
  149. <IfModule mod_php5.c> 
  150. php_flag engine off 
  151. </IfModule>'; 
  152. $rules = explode( "\n", $txt ); 
  153.  
  154. /** 
  155. * A filter to allow the modification/disabling of parsing certain PHP within Gravity Forms 
  156. * @param mixed $rules The Rules of what to parse or not to parse 
  157. */ 
  158. $rules = apply_filters( 'gform_upload_root_htaccess_rules', $rules ); 
  159. if ( ! empty( $rules ) ) { 
  160. if ( ! function_exists( 'insert_with_markers' ) ) { 
  161. require_once( ABSPATH . 'wp-admin/includes/misc.php' ); 
  162. insert_with_markers( $htaccess_file, 'Gravity Forms', $rules ); 
  163.  
  164. public static function clean_number( $number, $number_format = '' ) { 
  165. if ( rgblank( $number ) ) { 
  166. return $number; 
  167.  
  168. $decimal_char = ''; 
  169. if ( $number_format == 'decimal_dot' ) { 
  170. $decimal_char = '.'; 
  171. } else if ( $number_format == 'decimal_comma' ) { 
  172. $decimal_char = ', '; 
  173.  
  174. $float_number = ''; 
  175. $clean_number = ''; 
  176. $is_negative = false; 
  177.  
  178. //Removing all non-numeric characters 
  179. $array = str_split( $number ); 
  180. foreach ( $array as $char ) { 
  181. if ( ( $char >= '0' && $char <= '9' ) || $char == ', ' || $char == '.' ) { 
  182. $clean_number .= $char; 
  183. } else if ( $char == '-' ) { 
  184. $is_negative = true; 
  185.  
  186. //Removing thousand separators but keeping decimal point 
  187. $array = str_split( $clean_number ); 
  188. for ( $i = 0, $count = sizeof( $array ); $i < $count; $i ++ ) { 
  189. $char = $array[ $i ]; 
  190. if ( $char >= '0' && $char <= '9' ) { 
  191. $float_number .= $char; 
  192. } else if ( empty( $decimal_char ) && ( $char == '.' || $char == ', ' ) && strlen( $clean_number ) - $i <= 3 ) { 
  193. $float_number .= '.'; 
  194. } else if ( $decimal_char == $char ) { 
  195. $float_number .= '.'; 
  196.  
  197. if ( $is_negative ) { 
  198. $float_number = '-' . $float_number; 
  199.  
  200. return $float_number; 
  201.  
  202.  
  203. public static function json_encode( $value ) { 
  204. return json_encode( $value ); 
  205.  
  206. public static function json_decode( $str, $is_assoc = true ) { 
  207. return json_decode( $str, $is_assoc ); 
  208.  
  209. //Returns the url of the plugin's root folder 
  210. public static function get_base_url() { 
  211. return plugins_url( '', __FILE__ ); 
  212.  
  213. //Returns the physical path of the plugin's root folder 
  214. public static function get_base_path() { 
  215. return dirname( __FILE__ ); 
  216.  
  217. public static function get_email_fields( $form ) { 
  218. $fields = array(); 
  219. foreach ( $form['fields'] as $field ) { 
  220. if ( $field->type == 'email' || $field->inputType == 'email' ) { 
  221. $fields[] = $field; 
  222.  
  223. return $fields; 
  224.  
  225. public static function truncate_middle( $text, $max_length ) { 
  226. if ( strlen( $text ) <= $max_length ) { 
  227. return $text; 
  228.  
  229. $middle = intval( $max_length / 2 ); 
  230.  
  231. return self::safe_substr( $text, 0, $middle ) . '...' . self::safe_substr( $text, strlen( $text ) - $middle, $middle ); 
  232.  
  233. public static function is_invalid_or_empty_email( $email ) { 
  234. return empty( $email ) || ! self::is_valid_email( $email ); 
  235.  
  236. public static function is_valid_url( $url ) { 
  237. $url = trim( $url ); 
  238.  
  239. return ( ( strpos( $url, 'http://' ) === 0 || strpos( $url, 'https://' ) === 0 ) && 
  240. filter_var( $url, FILTER_VALIDATE_URL ) !== false ); 
  241.  
  242. public static function is_valid_email( $email ) { 
  243.  
  244. return filter_var( $email, FILTER_VALIDATE_EMAIL ); 
  245.  
  246. public static function is_valid_email_list( $email_list ) { 
  247. $emails = explode( ', ', $email_list ); 
  248. if ( ! is_array( $emails ) ) { 
  249. return false; 
  250.  
  251. foreach( $emails as $email ) { 
  252. if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) { 
  253. return false; 
  254.  
  255. return true; 
  256.  
  257. public static function get_label( $field, $input_id = 0, $input_only = false, $allow_admin_label = true ) { 
  258. return RGFormsModel::get_label( $field, $input_id, $input_only, $allow_admin_label ); 
  259.  
  260. public static function get_input( $field, $id ) { 
  261. return RGFormsModel::get_input( $field, $id ); 
  262.  
  263. public static function insert_variables( $fields, $element_id, $hide_all_fields = false, $callback = '', $onchange = '', $max_label_size = 40, $exclude = null, $args = '', $class_name = '' ) { 
  264.  
  265. if ( $fields == null ) { 
  266. $fields = array(); 
  267.  
  268. if ( $exclude == null ) { 
  269. $exclude = array(); 
  270.  
  271. $exclude = apply_filters( 'gform_merge_tag_list_exclude', $exclude, $element_id, $fields ); 
  272. $merge_tags = self::get_merge_tags( $fields, $element_id, $hide_all_fields, $exclude, $args ); 
  273.  
  274. $onchange = empty( $onchange ) ? "InsertVariable('{$element_id}', '{$callback}');" : $onchange; 
  275. $class = trim( $class_name . ' gform_merge_tags' ); 
  276.  
  277. ?> 
  278.  
  279. <select id="<?php echo esc_attr( $element_id ); ?>_variable_select" onchange="<?php echo $onchange ?>" class="<?php echo esc_attr( $class ) ?>"> 
  280. <option value=''><?php esc_html_e( 'Insert Merge Tag' , 'gravityforms' ); ?></option> 
  281.  
  282. <?php foreach ( $merge_tags as $group => $group_tags ) { 
  283.  
  284. $group_label = rgar( $group_tags, 'label' ); 
  285. $tags = rgar( $group_tags, 'tags' ); 
  286.  
  287. if ( empty( $group_tags['tags'] ) ) { 
  288. continue; 
  289.  
  290. if ( $group_label ) { 
  291. ?> 
  292. <optgroup label="<?php echo $group_label; ?>"> 
  293. <?php } ?> 
  294.  
  295. <?php foreach ( $tags as $tag ) { ?> 
  296. <option value="<?php echo $tag['tag']; ?>"><?php echo $tag['label']; ?></option> 
  297. <?php 
  298. if ( $group_label ) { 
  299. ?> 
  300. </optgroup> 
  301. <?php 
  302. } ?> 
  303.  
  304. </select> 
  305.  
  306. <?php 
  307.  
  308. /** 
  309. * This function is used by the gfMergeTags JS object to get the localized label for non-field merge tags as well as 
  310. * for backwards compatibility with the gform_custom_merge_tags hook. Lastly, this plugin is used by the soon-to-be 
  311. * deprecated insert_variables() function as the new gfMergeTags object has not yet been applied to the Post Content 
  312. * Template setting. 
  313. * @param GF_Field[] $fields 
  314. * @param $element_id 
  315. * @param bool $hide_all_fields 
  316. * @param array $exclude_field_types 
  317. * @param string $option 
  318. * @return array 
  319. */ 
  320. public static function get_merge_tags( $fields, $element_id, $hide_all_fields = false, $exclude_field_types = array(), $option = '' ) { 
  321.  
  322. if ( $fields == null ) { 
  323. $fields = array(); 
  324.  
  325. if ( $exclude_field_types == null ) { 
  326. $exclude_field_types = array(); 
  327.  
  328. $required_fields = $optional_fields = $pricing_fields = array(); 
  329. $ungrouped = $required_group = $optional_group = $pricing_group = $other_group = array(); 
  330.  
  331. if ( ! $hide_all_fields ) { 
  332. $ungrouped[] = array( 'tag' => '{all_fields}', 'label' => esc_html__( 'All Submitted Fields', 'gravityforms' ) ); 
  333.  
  334. // group fields by required, optional, and pricing 
  335. foreach ( $fields as $field ) { 
  336.  
  337. if ( $field->displayOnly ) { 
  338. continue; 
  339.  
  340. $input_type = RGFormsModel::get_input_type( $field ); 
  341.  
  342. // skip field types that should be excluded 
  343. if ( is_array( $exclude_field_types ) && in_array( $input_type, $exclude_field_types ) ) { 
  344. continue; 
  345.  
  346. if ( $field->isRequired ) { 
  347.  
  348. switch ( $input_type ) { 
  349.  
  350. case 'name' : 
  351.  
  352. if ( $field->nameFormat == 'extended' ) { 
  353.  
  354. $prefix = GFCommon::get_input( $field, $field->id . '.2' ); 
  355. $suffix = GFCommon::get_input( $field, $field->id . '.8' ); 
  356. $optional_field = $field; 
  357. $optional_field['inputs'] = array( $prefix, $suffix ); 
  358.  
  359. //Add optional name fields to the optional list 
  360. $optional_fields[] = $optional_field; 
  361.  
  362. //Remove optional name field from required list 
  363. unset( $field->inputs[0] ); 
  364. unset( $field->inputs[3] ); 
  365.  
  366.  
  367. $required_fields[] = $field; 
  368.  
  369. break; 
  370.  
  371. default: 
  372. $required_fields[] = $field; 
  373. } else { 
  374. $optional_fields[] = $field; 
  375.  
  376. if ( self::is_pricing_field( $field->type ) ) { 
  377. $pricing_fields[] = $field; 
  378.  
  379. if ( ! empty( $required_fields ) ) { 
  380. foreach ( $required_fields as $field ) { 
  381. $required_group = array_merge( $required_group, self::get_field_merge_tags( $field, $option ) ); 
  382.  
  383. if ( ! empty( $optional_fields ) ) { 
  384. foreach ( $optional_fields as $field ) { 
  385. $optional_group = array_merge( $optional_group, self::get_field_merge_tags( $field, $option ) ); 
  386.  
  387. if ( ! empty( $pricing_fields ) ) { 
  388.  
  389. if ( ! $hide_all_fields ) { 
  390. $pricing_group[] = array( 'tag' => '{pricing_fields}', 'label' => esc_html__( 'All Pricing Fields', 'gravityforms' ) ); 
  391.  
  392. foreach ( $pricing_fields as $field ) { 
  393. $pricing_group = array_merge( $pricing_group, self::get_field_merge_tags( $field, $option ) ); 
  394.  
  395. $other_group[] = array( 'tag' => '{ip}', 'label' => esc_html__( 'User IP Address', 'gravityforms' ) ); 
  396. $other_group[] = array( 'tag' => '{date_mdy}', 'label' => esc_html__( 'Date', 'gravityforms' ) . ' (mm/dd/yyyy)' ); 
  397. $other_group[] = array( 'tag' => '{date_dmy}', 'label' => esc_html__( 'Date', 'gravityforms' ) . ' (dd/mm/yyyy)' ); 
  398. $other_group[] = array( 'tag' => '{embed_post:ID}', 'label' => esc_html__( 'Embed Post/Page Id', 'gravityforms' ) ); 
  399. $other_group[] = array( 'tag' => '{embed_post:post_title}', 'label' => esc_html__( 'Embed Post/Page Title', 'gravityforms' ) ); 
  400. $other_group[] = array( 'tag' => '{embed_url}', 'label' => esc_html__( 'Embed URL', 'gravityforms' ) ); 
  401. $other_group[] = array( 'tag' => '{entry_id}', 'label' => esc_html__( 'Entry Id', 'gravityforms' ) ); 
  402. $other_group[] = array( 'tag' => '{entry_url}', 'label' => esc_html__( 'Entry URL', 'gravityforms' ) ); 
  403. $other_group[] = array( 'tag' => '{form_id}', 'label' => esc_html__( 'Form Id', 'gravityforms' ) ); 
  404. $other_group[] = array( 'tag' => '{form_title}', 'label' => esc_html__( 'Form Title', 'gravityforms' ) ); 
  405. $other_group[] = array( 'tag' => '{user_agent}', 'label' => esc_html__( 'HTTP User Agent', 'gravityforms' ) ); 
  406. $other_group[] = array( 'tag' => '{referer}', 'label' => esc_html__( 'HTTP Referer URL', 'gravityforms' ) ); 
  407.  
  408. if ( self::has_post_field( $fields ) ) { 
  409. $other_group[] = array( 'tag' => '{post_id}', 'label' => esc_html__( 'Post Id', 'gravityforms' ) ); 
  410. $other_group[] = array( 'tag' => '{post_edit_url}', 'label' => esc_html__( 'Post Edit URL', 'gravityforms' ) ); 
  411.  
  412. $other_group[] = array( 'tag' => '{user:display_name}', 'label' => esc_html__( 'User Display Name', 'gravityforms' ) ); 
  413. $other_group[] = array( 'tag' => '{user:user_email}', 'label' => esc_html__( 'User Email', 'gravityforms' ) ); 
  414. $other_group[] = array( 'tag' => '{user:user_login}', 'label' => esc_html__( 'User Login', 'gravityforms' ) ); 
  415.  
  416. $form_id = isset($fields[0]) ? $fields[0]->formId : 0; 
  417.  
  418. $custom_group = apply_filters( 'gform_custom_merge_tags', array(), $form_id, $fields, $element_id ); 
  419.  
  420. $merge_tags = array( 
  421. 'ungrouped' => array( 
  422. 'label' => false,  
  423. 'tags' => $ungrouped,  
  424. ),  
  425. 'required' => array( 
  426. 'label' => esc_html__( 'Required form fields', 'gravityforms' ),  
  427. 'tags' => $required_group,  
  428. ),  
  429. 'optional' => array( 
  430. 'label' => esc_html__( 'Optional form fields', 'gravityforms' ),  
  431. 'tags' => $optional_group,  
  432. ),  
  433. 'pricing' => array( 
  434. 'label' => esc_html__( 'Pricing form fields', 'gravityforms' ),  
  435. 'tags' => $pricing_group,  
  436. ),  
  437. 'other' => array( 
  438. 'label' => esc_html__( 'Other', 'gravityforms' ),  
  439. 'tags' => $other_group,  
  440. ),  
  441. 'custom' => array( 
  442. 'label' => esc_html__( 'Custom', 'gravityforms' ),  
  443. 'tags' => $custom_group,  
  444. ); 
  445.  
  446. return $merge_tags; 
  447.  
  448. /** 
  449. * @param GF_Field $field 
  450. * @param string $option 
  451. * @return string 
  452. */ 
  453. public static function get_field_merge_tags( $field, $option = '' ) { 
  454.  
  455. $merge_tags = array(); 
  456. $tag_args = RGFormsModel::get_input_type( $field ) == 'list' ? ":{$option}" : ''; //args currently only supported by list field 
  457.  
  458. $inputs = $field->get_entry_inputs(); 
  459.  
  460. if ( is_array( $inputs ) ) { 
  461.  
  462. if ( RGFormsModel::get_input_type( $field ) == 'checkbox' ) { 
  463. $value = '{' . esc_html( GFCommon::get_label( $field, $field->id ) ) . ':' . $field->id . "{$tag_args}}"; 
  464. $merge_tags[] = array( 
  465. 'tag' => $value,  
  466. 'label' => esc_html( GFCommon::get_label( $field, $field->id ) ) 
  467. ); 
  468.  
  469. foreach ( $field->inputs as $input ) { 
  470. if ( RGFormsModel::get_input_type( $field ) == 'creditcard' ) { 
  471. //only include the credit card type (field_id.4) and number (field_id.1) 
  472. if ( $input['id'] == $field['id'] . '.1' || $input['id'] == $field['id'] . '.4' ) { 
  473. $value = '{' . esc_html( GFCommon::get_label( $field, $input['id'] ) ) . ':' . $input['id'] . "{$tag_args}}"; 
  474. $merge_tags[] = array( 
  475. 'tag' => $value,  
  476. 'label' => esc_html( GFCommon::get_label( $field, $input['id'] ) ) 
  477. ); 
  478. } else { 
  479. $value = '{' . esc_html( GFCommon::get_label( $field, $input['id'] ) ) . ':' . $input['id'] . "{$tag_args}}"; 
  480. $merge_tags[] = array( 
  481. 'tag' => $value,  
  482. 'label' => esc_html( GFCommon::get_label( $field, $input['id'] ) ) 
  483. ); 
  484. } else { 
  485. $value = '{' . esc_html( GFCommon::get_label( $field ) ) . ':' . $field->id . "{$tag_args}}"; 
  486. $merge_tags[] = array( 
  487. 'tag' => $value,  
  488. 'label' => esc_html( GFCommon::get_label( $field ) ) 
  489. ); 
  490.  
  491. return $merge_tags; 
  492.  
  493. public static function insert_field_variable( $field, $max_label_size = 40, $args = '' ) { 
  494.  
  495. $tag_args = RGFormsModel::get_input_type( $field ) == 'list' ? ":{$args}" : ''; //args currently only supported by list field 
  496.  
  497. if ( is_array( $field->inputs ) ) { 
  498. if ( RGFormsModel::get_input_type( $field ) == 'checkbox' ) { 
  499. ?> 
  500. <option value='<?php echo '{' . esc_html( GFCommon::get_label( $field, $field->id ) ) . ':' . $field->id . "{$tag_args}}" ?>'><?php echo esc_html( GFCommon::get_label( $field, $field->id ) ) ?></option> 
  501. <?php 
  502.  
  503. foreach ( $field->inputs as $input ) { 
  504. ?> 
  505. <option value='<?php echo '{' . esc_html( GFCommon::get_label( $field, $input['id'] ) ) . ':' . $input['id'] . "{$tag_args}}" ?>'><?php echo esc_html( GFCommon::get_label( $field, $input['id'] ) ) ?></option> 
  506. <?php 
  507. } else { 
  508. ?> 
  509. <option value='<?php echo '{' . esc_html( GFCommon::get_label( $field ) ) . ':' . $field->id . "{$tag_args}}" ?>'><?php echo esc_html( GFCommon::get_label( $field ) ) ?></option> 
  510. <?php 
  511.  
  512. public static function insert_post_content_variables( $fields, $element_id, $callback, $max_label_size = 25 ) { 
  513. // TODO: replace with class-powered merge tags 
  514. $insert_variables_onchange = sprintf( "InsertPostContentVariable('%s', '%s');", esc_js( $element_id ), esc_js( $callback ) ); 
  515. self::insert_variables( $fields, $element_id, true, '', $insert_variables_onchange, $max_label_size, null, '', 'gform_content_template_merge_tags' ); 
  516. ?> 
  517.    
  518. <select id="<?php echo $element_id ?>_image_size_select" onchange="InsertPostImageVariable('<?php echo esc_js( $element_id ); ?>', '<?php echo esc_js( $element_id ); ?>'); SetCustomFieldTemplate();" style="display:none;"> 
  519. <option value=""><?php esc_html_e( 'Select image size' , 'gravityforms' ) ?></option> 
  520. <option value="thumbnail"><?php esc_html_e( 'Thumbnail' , 'gravityforms' ) ?></option> 
  521. <option value="thumbnail:left"><?php esc_html_e( 'Thumbnail - Left Aligned' , 'gravityforms' ) ?></option> 
  522. <option value="thumbnail:center"><?php esc_html_e( 'Thumbnail - Centered' , 'gravityforms' ) ?></option> 
  523. <option value="thumbnail:right"><?php esc_html_e( 'Thumbnail - Right Aligned' , 'gravityforms' ) ?></option> 
  524.  
  525. <option value="medium"><?php esc_html_e( 'Medium' , 'gravityforms' ) ?></option> 
  526. <option value="medium:left"><?php esc_html_e( 'Medium - Left Aligned' , 'gravityforms' ) ?></option> 
  527. <option value="medium:center"><?php esc_html_e( 'Medium - Centered' , 'gravityforms' ) ?></option> 
  528. <option value="medium:right"><?php esc_html_e( 'Medium - Right Aligned' , 'gravityforms' ) ?></option> 
  529.  
  530. <option value="large"><?php esc_html_e( 'Large' , 'gravityforms' ) ?></option> 
  531. <option value="large:left"><?php esc_html_e( 'Large - Left Aligned' , 'gravityforms' ) ?></option> 
  532. <option value="large:center"><?php esc_html_e( 'Large - Centered' , 'gravityforms' ) ?></option> 
  533. <option value="large:right"><?php esc_html_e( 'Large - Right Aligned' , 'gravityforms' ) ?></option> 
  534.  
  535. <option value="full"><?php esc_html_e( 'Full Size' , 'gravityforms' ) ?></option> 
  536. <option value="full:left"><?php esc_html_e( 'Full Size - Left Aligned' , 'gravityforms' ) ?></option> 
  537. <option value="full:center"><?php esc_html_e( 'Full Size - Centered' , 'gravityforms' ) ?></option> 
  538. <option value="full:right"><?php esc_html_e( 'Full Size - Right Aligned' , 'gravityforms' ) ?></option> 
  539. </select> 
  540. <?php 
  541.  
  542. public static function insert_calculation_variables( $fields, $element_id, $onchange = '', $callback = '', $max_label_size = 40 ) { 
  543.  
  544. if ( $fields == null ) { 
  545. $fields = array(); 
  546.  
  547. $onchange = empty( $onchange ) ? sprintf( "InsertVariable('%s', '%s');", esc_js( $element_id ), esc_js( $callback ) ): $onchange; 
  548. $class = 'gform_merge_tags'; 
  549. ?> 
  550.  
  551. <select id="<?php echo esc_attr( $element_id ); ?>_variable_select" onchange="<?php echo $onchange ?>" class="<?php echo esc_attr( $class ) ?>"> 
  552. <option value=''><?php esc_html_e( 'Insert Merge Tag' , 'gravityforms' ); ?></option> 
  553. <optgroup label="<?php esc_attr_e( 'Allowable form fields', 'gravityforms' ); ?>"> 
  554.  
  555. <?php 
  556. foreach ( $fields as $field ) { 
  557.  
  558. if ( ! self::is_valid_for_calcuation( $field ) ) { 
  559. continue; 
  560.  
  561. if ( RGFormsModel::get_input_type( $field ) == 'checkbox' ) { 
  562. foreach ( $field->inputs as $input ) { 
  563. ?> 
  564. <option value='<?php echo esc_attr( '{' . esc_html( GFCommon::get_label( $field, $input['id'] ) ) . ':' . $input['id'] . '}' ); ?>'><?php echo esc_html( GFCommon::get_label( $field, $input['id'] ) ) ?></option> 
  565. <?php 
  566. } else { 
  567. self::insert_field_variable( $field, $max_label_size ); 
  568. ?> 
  569.  
  570. </optgroup> 
  571.  
  572. <?php 
  573. $form_id = isset($forms[0]) ? $fields[0]->formId : 0; 
  574. $custom_merge_tags = apply_filters( 'gform_custom_merge_tags', array(), $form_id, $fields, $element_id ); 
  575.  
  576. if ( is_array( $custom_merge_tags ) && ! empty( $custom_merge_tags ) ) { 
  577. ?> 
  578.  
  579. <optgroup label="<?php esc_attr_e( 'Custom' , 'gravityforms' ); ?>"> 
  580.  
  581. <?php foreach ( $custom_merge_tags as $custom_merge_tag ) { ?> 
  582.  
  583. <option value='<?php echo esc_attr( rgar( $custom_merge_tag, 'tag' ) ); ?>'><?php echo esc_html( rgar( $custom_merge_tag, 'label' ) ); ?></option> 
  584.  
  585. <?php } ?> 
  586.  
  587. </optgroup> 
  588.  
  589. <?php } ?> 
  590.  
  591. </select> 
  592.  
  593. <?php 
  594.  
  595. private static function get_post_image_variable( $media_id, $arg1, $arg2, $is_url = false ) { 
  596.  
  597. if ( $is_url ) { 
  598. $image = wp_get_attachment_image_src( $media_id, $arg1 ); 
  599. if ( $image ) { 
  600. list( $src, $width, $height ) = $image; 
  601.  
  602. return $src; 
  603.  
  604. switch ( $arg1 ) { 
  605. case 'title' : 
  606. $media = get_post( $media_id ); 
  607.  
  608. return $media->post_title; 
  609. case 'caption' : 
  610. $media = get_post( $media_id ); 
  611.  
  612. return $media->post_excerpt; 
  613. case 'description' : 
  614. $media = get_post( $media_id ); 
  615.  
  616. return $media->post_content; 
  617.  
  618. default : 
  619.  
  620. $img = wp_get_attachment_image( $media_id, $arg1, false, array( 'class' => "size-{$arg1} align{$arg2} wp-image-{$media_id}" ) ); 
  621.  
  622. return $img; 
  623.  
  624. public static function replace_variables_post_image( $text, $post_images, $lead ) { 
  625.  
  626. preg_match_all( '/{[^{]*?:(\d+)(:([^:]*?))?(:([^:]*?))?(:url)?}/mi', $text, $matches, PREG_SET_ORDER ); 
  627. if ( is_array( $matches ) ) { 
  628. foreach ( $matches as $match ) { 
  629. $input_id = $match[1]; 
  630.  
  631. //ignore fields that are not post images 
  632. if ( ! isset( $post_images[ $input_id ] ) ) { 
  633. continue; 
  634.  
  635. //Reading alignment and 'url' parameters. 
  636. //Format could be {image:5:medium:left:url} or {image:5:medium:url} 
  637. $size_meta = empty( $match[3] ) ? 'full' : $match[3]; 
  638. $align = empty( $match[5] ) ? 'none' : $match[5]; 
  639. if ( $align == 'url' ) { 
  640. $align = 'none'; 
  641. $is_url = true; 
  642. } else { 
  643. $is_url = rgar( $match, 6 ) == ':url'; 
  644.  
  645. $media_id = $post_images[ $input_id ]; 
  646. $value = is_wp_error( $media_id ) ? '' : self::get_post_image_variable( $media_id, $size_meta, $align, $is_url ); 
  647.  
  648. $text = str_replace( $match[0], $value, $text ); 
  649.  
  650. return $text; 
  651.  
  652. public static function implode_non_blank( $separator, $array ) { 
  653.  
  654. if ( ! is_array( $array ) ) { 
  655. return ''; 
  656.  
  657. $ary = array(); 
  658. foreach ( $array as $item ) { 
  659. if ( ! rgblank( $item ) ) { 
  660. $ary[] = $item; 
  661.  
  662. return implode( $separator, $ary ); 
  663.  
  664. public static function format_variable_value( $value, $url_encode, $esc_html, $format, $nl2br = true ) { 
  665. if ( $esc_html ) { 
  666. $value = esc_html( $value ); 
  667.  
  668. if ( $format == 'html' && $nl2br ) { 
  669. $value = nl2br( $value ); 
  670.  
  671. if ( $url_encode ) { 
  672. $value = urlencode( $value ); 
  673.  
  674. return $value; 
  675.  
  676. public static function replace_variables( $text, $form, $lead, $url_encode = false, $esc_html = true, $nl2br = true, $format = 'html' ) { 
  677.  
  678. $text = $nl2br ? nl2br( $text ) : $text; 
  679.  
  680. $text = apply_filters( 'gform_pre_replace_merge_tags', $text, $form, $lead, $url_encode, $esc_html, $nl2br, $format ); 
  681.  
  682. if ( strpos( $text, '{' ) === false ) { 
  683. return $text; 
  684.  
  685. //Replacing conditional merge tag variables: [gravityforms action="conditional" merge_tag="{Other Services:4}" .... 
  686. preg_match_all( '/merge_tag\s*=\s*["|\']({[^{]*?:(\d+(\.\d+)?)(:(.*?))?})["|\']/mi', $text, $matches, PREG_SET_ORDER ); 
  687. if ( is_array( $matches ) ) { 
  688. foreach ( $matches as $match ) { 
  689. $input_id = $match[2]; 
  690.  
  691. $text = self::replace_field_variable( $text, $form, $lead, $url_encode, $esc_html, $nl2br, $format, $input_id, $match, true ); 
  692.  
  693. //Replacing field variables: {FIELD_LABEL:FIELD_ID} {My Field:2} 
  694. preg_match_all( '/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}/mi', $text, $matches, PREG_SET_ORDER ); 
  695. if ( is_array( $matches ) ) { 
  696. foreach ( $matches as $match ) { 
  697. $input_id = $match[1]; 
  698.  
  699. $text = self::replace_field_variable( $text, $form, $lead, $url_encode, $esc_html, $nl2br, $format, $input_id, $match ); 
  700.  
  701. //replacing global variables 
  702. //form title 
  703. $text = str_replace( '{form_title}', $url_encode ? urlencode( $form['title'] ) : $form['title'], $text ); 
  704.  
  705. $matches = array(); 
  706. preg_match_all( "/{all_fields(:(.*?))?}/", $text, $matches, PREG_SET_ORDER ); 
  707. foreach ( $matches as $match ) { 
  708. $options = explode( ', ', rgar( $match, 2 ) ); 
  709. $use_value = in_array( 'value', $options ); 
  710. $display_empty = in_array( 'empty', $options ); 
  711. $use_admin_label = in_array( 'admin', $options ); 
  712.  
  713. //all submitted fields using text 
  714. if ( strpos( $text, $match[0] ) !== false ) { 
  715. $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 ); 
  716.  
  717. //all submitted fields including empty fields 
  718. if ( strpos( $text, '{all_fields_display_empty}' ) !== false ) { 
  719. $text = str_replace( '{all_fields_display_empty}', self::get_submitted_fields( $form, $lead, true, true, $format, false, 'all_fields_display_empty' ), $text ); 
  720.  
  721. //pricing fields 
  722. $pricing_matches = array(); 
  723. preg_match_all( "/{pricing_fields(:(.*?))?}/", $text, $pricing_matches, PREG_SET_ORDER ); 
  724. foreach ( $pricing_matches as $match ) { 
  725. $options = explode( ', ', rgar( $match, 2 ) ); 
  726. $use_value = in_array( 'value', $options ); 
  727. $use_admin_label = in_array( 'admin', $options ); 
  728.  
  729. //all submitted pricing fields using text 
  730. if ( strpos( $text, $match[0] ) !== false ) { 
  731. $pricing_fields = self::get_submitted_pricing_fields( $form, $lead, $format, ! $use_value, $use_admin_label ); 
  732.  
  733. if ( $format == 'html' ) { 
  734. $text = str_replace( 
  735. $match[0], '<table width="99%" border="0" cellpadding="1" cellspacing="0" bgcolor="#EAEAEA"> 
  736. <tr><td> 
  737. <table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">' . 
  738. $pricing_fields . 
  739. '</table> 
  740. </tr></td> 
  741. </table>',  
  742. $text 
  743. ); 
  744. else { 
  745. $text = str_replace( $match[0], $pricing_fields, $text ); 
  746.  
  747. //form id 
  748. $text = str_replace( '{form_id}', $url_encode ? urlencode( $form['id'] ) : $form['id'], $text ); 
  749.  
  750. //entry id 
  751. $text = str_replace( '{entry_id}', $url_encode ? urlencode( rgar( $lead, 'id' ) ) : rgar( $lead, 'id' ), $text ); 
  752.  
  753. //entry url 
  754. $entry_url = get_bloginfo( 'wpurl' ) . '/wp-admin/admin.php?page=gf_entries&view=entry&id=' . $form['id'] . '&lid=' . rgar( $lead, 'id' ); 
  755. $text = str_replace( '{entry_url}', $url_encode ? urlencode( $entry_url ) : $entry_url, $text ); 
  756.  
  757. //post id 
  758. $text = str_replace( '{post_id}', $url_encode ? urlencode( rgar( $lead, 'post_id' ) ) : rgar( $lead, 'post_id' ), $text ); 
  759.  
  760. //admin email 
  761. $wp_email = get_bloginfo( 'admin_email' ); 
  762. $text = str_replace( '{admin_email}', $url_encode ? urlencode( $wp_email ) : $wp_email, $text ); 
  763.  
  764. //post edit url 
  765. $post_url = get_bloginfo( 'wpurl' ) . '/wp-admin/post.php?action=edit&post=' . rgar( $lead, 'post_id' ); 
  766. $text = str_replace( '{post_edit_url}', $url_encode ? urlencode( $post_url ) : $post_url, $text ); 
  767.  
  768. $text = self::replace_variables_prepopulate( $text, $url_encode, $lead, $esc_html, $form, $nl2br, $format ); 
  769.  
  770. // TODO: Deprecate the 'gform_replace_merge_tags' and replace it with a call to the 'gform_merge_tag_filter' 
  771. //$text = apply_filters('gform_merge_tag_filter', $text, false, false, false ); 
  772.  
  773. $text = self::decode_merge_tag( $text ); 
  774.  
  775. return $text; 
  776.  
  777. public static function encode_merge_tag( $text ) { 
  778. return str_replace( '{', '{', $text ); 
  779.  
  780. public static function decode_merge_tag( $text ) { 
  781. return str_replace( '{', '{', $text ); 
  782.  
  783. public static function format_post_category( $value, $use_id ) { 
  784.  
  785. list( $item_value, $item_id ) = rgexplode( ':', $value, 2 ); 
  786.  
  787. if ( $use_id && ! empty( $item_id ) ) { 
  788. $item_value = $item_id; 
  789.  
  790. return $item_value; 
  791.  
  792. public static function get_embed_post() { 
  793. global $embed_post, $post, $wp_query; 
  794.  
  795. if ( $embed_post ) { 
  796. return $embed_post; 
  797.  
  798. if ( ! rgempty( 'gform_embed_post' ) ) { 
  799. $post_id = absint( rgpost( 'gform_embed_post' ) ); 
  800. $embed_post = get_post( $post_id ); 
  801. } else if ( $wp_query->is_in_loop ) { 
  802. $embed_post = $post; 
  803. } else { 
  804. $embed_post = array(); 
  805.  
  806. public static function get_ul_classes( $form ) { 
  807.  
  808. $description_class = rgar( $form, 'descriptionPlacement' ) == 'above' ? 'description_above' : 'description_below'; 
  809. $sublabel_class = rgar( $form, 'subLabelPlacement' ) == 'above' ? 'form_sublabel_above' : 'form_sublabel_below'; 
  810. $label_class = rgempty( 'labelPlacement', $form ) ? 'top_label' : rgar( $form, 'labelPlacement' ); 
  811.  
  812. $css_class = preg_replace( '/\s+/', ' ', "gform_fields {$label_class} {$sublabel_class} {$description_class}" ); //removing extra spaces 
  813.  
  814. return $css_class; 
  815.  
  816.  
  817. public static function replace_variables_prepopulate( $text, $url_encode = false, $entry = false, $esc_html = false, $form = false, $nl2br = false, $format = 'html' ) { 
  818.  
  819. //embed url 
  820. $current_page_url = RGFormsModel::get_current_page_url(); 
  821. if ( $esc_html ) { 
  822. $current_page_url = esc_html( $current_page_url ); 
  823. if ( $url_encode ) { 
  824. $current_page_url = urlencode( $current_page_url ); 
  825. $text = str_replace( '{embed_url}', $current_page_url, $text ); 
  826.  
  827. $local_timestamp = self::get_local_timestamp( time() ); 
  828.  
  829. //date (mm/dd/yyyy) 
  830. $local_date_mdy = date_i18n( 'm/d/Y', $local_timestamp, true ); 
  831. $text = str_replace( '{date_mdy}', $url_encode ? urlencode( $local_date_mdy ) : $local_date_mdy, $text ); 
  832.  
  833. //date (dd/mm/yyyy) 
  834. $local_date_dmy = date_i18n( 'd/m/Y', $local_timestamp, true ); 
  835. $text = str_replace( '{date_dmy}', $url_encode ? urlencode( $local_date_dmy ) : $local_date_dmy, $text ); 
  836.  
  837. // ip 
  838. $ip = isset( $entry['ip'] ) ? $entry['ip'] : GFFormsModel::get_ip(); 
  839. $text = str_replace( '{ip}', $url_encode ? urlencode( $ip ) : $ip, $text ); 
  840.  
  841. global $post; 
  842. $post_array = self::object_to_array( $post ); 
  843. preg_match_all( "/\{embed_post:(.*?)\}/", $text, $matches, PREG_SET_ORDER ); 
  844. foreach ( $matches as $match ) { 
  845. $full_tag = $match[0]; 
  846. $property = $match[1]; 
  847. $text = str_replace( $full_tag, $url_encode ? urlencode( $post_array[ $property ] ) : $post_array[ $property ], $text ); 
  848.  
  849. //embed post custom fields 
  850. preg_match_all( "/\{custom_field:(.*?)\}/", $text, $matches, PREG_SET_ORDER ); 
  851. foreach ( $matches as $match ) { 
  852.  
  853. $full_tag = $match[0]; 
  854. $custom_field_name = $match[1]; 
  855. $custom_field_value = ! empty( $post_array['ID'] ) ? get_post_meta( $post_array['ID'], $custom_field_name, true ) : ''; 
  856. $text = str_replace( $full_tag, $url_encode ? urlencode( $custom_field_value ) : $custom_field_value, $text ); 
  857.  
  858. //user agent 
  859. $user_agent = RGForms::get( 'HTTP_USER_AGENT', $_SERVER ); 
  860. if ( $esc_html ) { 
  861. $user_agent = esc_html( $user_agent ); 
  862. if ( $url_encode ) { 
  863. $user_agent = urlencode( $user_agent ); 
  864. $text = str_replace( '{user_agent}', $user_agent, $text ); 
  865.  
  866. //referrer 
  867. $referer = RGForms::get( 'HTTP_REFERER', $_SERVER ); 
  868. if ( $esc_html ) { 
  869. $referer = esc_html( $referer ); 
  870. if ( $url_encode ) { 
  871. $referer = urlencode( $referer ); 
  872. $text = str_replace( '{referer}', $referer, $text ); 
  873.  
  874. //logged in user info 
  875. global $userdata, $wp_version, $current_user; 
  876. $user_array = self::object_to_array( $userdata ); 
  877.  
  878. preg_match_all( "/\{user:(.*?)\}/", $text, $matches, PREG_SET_ORDER ); 
  879. foreach ( $matches as $match ) { 
  880. $full_tag = $match[0]; 
  881. $property = $match[1]; 
  882.  
  883. $value = version_compare( $wp_version, '3.3', '>=' ) ? $current_user->get( $property ) : $user_array[ $property ]; 
  884. $value = $url_encode ? urlencode( $value ) : $value; 
  885.  
  886. $text = str_replace( $full_tag, $value, $text ); 
  887.  
  888. /** 
  889. * Allow the text to be filtered so custom merge tags can be replaced. 
  890. * @param string $text The text in which merge tags are being processed. 
  891. * @param false|array $form The Form object if available or false. 
  892. * @param false|array $entry The Entry object if available or false. 
  893. * @param bool $url_encode Indicates if the urlencode function should be applied. 
  894. * @param bool $esc_html Indicates if the esc_html function should be applied. 
  895. * @param bool $nl2br Indicates if the nl2br function should be applied. 
  896. * @param string $format The format requested for the location the merge is being used. Possible values: html, text or url. 
  897. */ 
  898. $text = apply_filters( 'gform_replace_merge_tags', $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ); 
  899.  
  900. return $text; 
  901.  
  902. public static function object_to_array( $object ) { 
  903. $array = array(); 
  904. if ( ! empty( $object ) ) { 
  905. foreach ( $object as $member => $data ) { 
  906. $array[ $member ] = $data; 
  907.  
  908. return $array; 
  909.  
  910. public static function is_empty_array( $val ) { 
  911. if ( ! is_array( $val ) ) { 
  912. $val = array( $val ); 
  913.  
  914. $ary = array_values( $val ); 
  915. foreach ( $ary as $item ) { 
  916. if ( ! rgblank( $item ) ) { 
  917. return false; 
  918.  
  919. return true; 
  920.  
  921. public static function get_submitted_fields( $form, $lead, $display_empty = false, $use_text = false, $format = 'html', $use_admin_label = false, $merge_tag = '', $options = '' ) { 
  922.  
  923. $field_data = ''; 
  924. if ( $format == 'html' ) { 
  925. $field_data = '<table width="99%" border="0" cellpadding="1" cellspacing="0" bgcolor="#EAEAEA"><tr><td> 
  926. <table width="100%" border="0" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF"> 
  927. '; 
  928.  
  929. $options_array = explode( ', ', $options ); 
  930. $no_admin = in_array( 'noadmin', $options_array ); 
  931. $no_hidden = in_array( 'nohidden', $options_array ); 
  932. $display_product_summary = false; 
  933.  
  934. foreach ( $form['fields'] as $field ) { 
  935. /** @var GF_Field $field */ 
  936.  
  937. $field_value = ''; 
  938.  
  939. $field_label = $use_admin_label && ! empty( $field->adminLabel ) ? $field->adminLabel : esc_html( GFCommon::get_label( $field, 0, false, $use_admin_label ) ); 
  940.  
  941. switch ( $field->type ) { 
  942. case 'captcha' : 
  943. break; 
  944.  
  945. case 'section' : 
  946.  
  947. if ( GFFormsModel::is_field_hidden( $form, $field, array(), $lead ) ) { 
  948. continue; 
  949.  
  950. if ( ( ! GFCommon::is_section_empty( $field, $form, $lead ) || $display_empty ) && ! $field->adminOnly ) { 
  951.  
  952. switch ( $format ) { 
  953. case 'text' : 
  954. $field_value = "--------------------------------\n{$field_label}\n\n"; 
  955. break; 
  956.  
  957. default: 
  958. $field_value = sprintf( 
  959. '<tr> 
  960. <td colspan="2" style="font-size:14px; font-weight:bold; background-color:#EEE; border-bottom:1px solid #DFDFDF; padding:7px 7px">%s</td> 
  961. </tr> 
  962. ', $field_label 
  963. ); 
  964. break; 
  965.  
  966. $field_value = apply_filters( 'gform_merge_tag_filter', $field_value, $merge_tag, $options, $field, $field_label ); 
  967.  
  968. $field_data .= $field_value; 
  969.  
  970. break; 
  971. case 'password' : 
  972. //ignore password fields 
  973. break; 
  974.  
  975. default : 
  976.  
  977. if ( self::is_product_field( $field->type ) ) { 
  978.  
  979. // ignore product fields as they will be grouped together at the end of the grid 
  980. $display_product_summary = apply_filters( 'gform_display_product_summary', true, $field, $form, $lead ); 
  981. if ( $display_product_summary ) { 
  982. continue; 
  983. } else if ( GFFormsModel::is_field_hidden( $form, $field, array(), $lead ) ) { 
  984. // ignore fields hidden by conditional logic 
  985. continue; 
  986.  
  987. $raw_field_value = RGFormsModel::get_lead_field_value( $lead, $field ); 
  988. $field_value = GFCommon::get_lead_field_display( $field, $raw_field_value, rgar( $lead, 'currency' ), $use_text, $format, 'email' ); 
  989.  
  990. $display_field = true; 
  991. //depending on parameters, don't display adminOnly or hidden fields 
  992. if ( $no_admin && $field->adminOnly ) { 
  993. $display_field = false; 
  994. } else if ( $no_hidden && RGFormsModel::get_input_type( $field ) == 'hidden' ) { 
  995. $display_field = false; 
  996.  
  997. //if field is not supposed to be displayed, pass false to filter. otherwise, pass field's value 
  998. if ( ! $display_field ) { 
  999. $field_value = false; 
  1000.  
  1001. $field_value = apply_filters( 'gform_merge_tag_filter', $field_value, $merge_tag, $options, $field, $raw_field_value ); 
  1002.  
  1003. if ( $field_value === false ) { 
  1004. continue; 
  1005.  
  1006. if ( ! empty( $field_value ) || strlen( $field_value ) > 0 || $display_empty ) { 
  1007. switch ( $format ) { 
  1008. case 'text' : 
  1009. $field_data .= "{$field_label}: {$field_value}\n\n"; 
  1010. break; 
  1011.  
  1012. default: 
  1013.  
  1014. $field_data .= sprintf( 
  1015. '<tr bgcolor="%3$s"> 
  1016. <td colspan="2"> 
  1017. <font style="font-family: sans-serif; font-size:12px;"><strong>%1$s</strong></font> 
  1018. </td> 
  1019. </tr> 
  1020. <tr bgcolor="%4$s"> 
  1021. <td width="20"> </td> 
  1022. <td> 
  1023. <font style="font-family: sans-serif; font-size:12px;">%2$s</font> 
  1024. </td> 
  1025. </tr> 
  1026. ', $field_label, empty( $field_value ) && strlen( $field_value ) == 0 ? ' ' : $field_value, esc_attr( apply_filters( 'gform_email_background_color_label', '#EAF2FA', $field, $lead ) ), esc_attr( apply_filters( 'gform_email_background_color_data', '#FFFFFF', $field, $lead ) ) 
  1027. ); 
  1028. break; 
  1029.  
  1030. if ( $display_product_summary ) { 
  1031. $field_data .= self::get_submitted_pricing_fields( $form, $lead, $format, $use_text, $use_admin_label ); 
  1032.  
  1033. if ( $format == 'html' ) { 
  1034. $field_data .= '</table> 
  1035. </td> 
  1036. </tr> 
  1037. </table>'; 
  1038.  
  1039. return $field_data; 
  1040.  
  1041. public static function get_submitted_pricing_fields( $form, $lead, $format, $use_text = true, $use_admin_label = false ) { 
  1042. $form_id = $form['id']; 
  1043. $order_label = gf_apply_filters( array( 'gform_order_label', $form_id ), esc_html__( 'Order' , 'gravityforms' ), $form['id'] ); 
  1044. $products = GFCommon::get_product_fields( $form, $lead, $use_text, $use_admin_label ); 
  1045. $total = 0; 
  1046. $field_data = ''; 
  1047.  
  1048. switch ( $format ) { 
  1049. case 'text' : 
  1050. if ( ! empty( $products['products'] ) ) { 
  1051. $field_data = "--------------------------------\n" . $order_label . "\n\n"; 
  1052. foreach ( $products['products'] as $product ) { 
  1053. $product_name = $product['quantity'] . ' ' . $product['name']; 
  1054. $price = self::to_number( $product['price'] ); 
  1055. if ( ! empty( $product['options'] ) ) { 
  1056. $product_name .= ' ('; 
  1057. $options = array(); 
  1058. foreach ( $product['options'] as $option ) { 
  1059. $price += self::to_number( $option['price'] ); 
  1060. $options[] = $option['option_name']; 
  1061. $product_name .= implode( ', ', $options ) . ')'; 
  1062. $subtotal = floatval( $product['quantity'] ) * $price; 
  1063. $total += $subtotal; 
  1064.  
  1065. $field_data .= "{$product_name}: " . self::to_money( $subtotal, $lead['currency'] ) . "\n\n"; 
  1066. $total += floatval( $products['shipping']['price'] ); 
  1067.  
  1068. if ( ! empty( $products['shipping']['name'] ) ) { 
  1069. $field_data .= $products['shipping']['name'] . ': ' . self::to_money( $products['shipping']['price'], $lead['currency'] ) . "\n\n"; 
  1070.  
  1071. $field_data .= esc_html__( 'Total' , 'gravityforms' ) . ': ' . self::to_money( $total, $lead['currency'] ) . "\n\n"; 
  1072. break; 
  1073.  
  1074.  
  1075. default : 
  1076. if ( ! empty( $products['products'] ) ) { 
  1077. $field_data = '<tr bgcolor="#EAF2FA"> 
  1078. <td colspan="2"> 
  1079. <font style="font-family: sans-serif; font-size:12px;"><strong>' . $order_label . '</strong></font> 
  1080. </td> 
  1081. </tr> 
  1082. <tr bgcolor="#FFFFFF"> 
  1083. <td width="20"> </td> 
  1084. <td> 
  1085. <table cellspacing="0" width="97%" style="border-left:1px solid #DFDFDF; border-top:1px solid #DFDFDF"> 
  1086. <thead> 
  1087. <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-family: sans-serif; font-size:12px; text-align:left">' . gf_apply_filters( array( 'gform_product', $form_id ), esc_html__( 'Product' , 'gravityforms' ), $form_id ) . '</th> 
  1088. <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:50px; font-family: sans-serif; font-size:12px; text-align:center">' . gf_apply_filters( array( 'gform_product_qty', $form_id ), esc_html__( 'Qty' , 'gravityforms' ), $form_id ) . '</th> 
  1089. <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:12px; text-align:left">' . gf_apply_filters( array( 'gform_product_unitprice', $form_id ), esc_html__( 'Unit Price' , 'gravityforms' ), $form_id ) . '</th> 
  1090. <th style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:12px; text-align:left">' . gf_apply_filters( array( 'gform_product_price', $form_id ), esc_html__( 'Price' , 'gravityforms' ), $form_id ) . '</th> 
  1091. </thead> 
  1092. <tbody>'; 
  1093.  
  1094.  
  1095. foreach ( $products['products'] as $product ) { 
  1096.  
  1097. $field_data .= '<tr> 
  1098. <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-family: sans-serif; font-size:11px;" > 
  1099. <strong style="color:#BF461E; font-size:12px; margin-bottom:5px">' . $product['name'] . '</strong> 
  1100. <ul style="margin:0">'; 
  1101.  
  1102. $price = self::to_number( $product['price'] ); 
  1103. if ( is_array( rgar( $product, 'options' ) ) ) { 
  1104. foreach ( $product['options'] as $option ) { 
  1105. $price += self::to_number( $option['price'] ); 
  1106. $field_data .= '<li style="padding:4px 0 4px 0">' . $option['option_label'] . '</li>'; 
  1107. $subtotal = floatval( $product['quantity'] ) * $price; 
  1108. $total += $subtotal; 
  1109.  
  1110. $field_data .= '</ul> 
  1111. </td> 
  1112. <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:center; width:50px; font-family: sans-serif; font-size:11px;" >' . $product['quantity'] . '</td> 
  1113. <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:11px;" >' . self::to_money( $price, $lead['currency'] ) . '</td> 
  1114. <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif; font-size:11px;" >' . self::to_money( $subtotal, $lead['currency'] ) . '</td> 
  1115. </tr>'; 
  1116. $total += floatval( $products['shipping']['price'] ); 
  1117. $field_data .= '</tbody> 
  1118. <tfoot>'; 
  1119.  
  1120. if ( ! empty( $products['shipping']['name'] ) ) { 
  1121. $field_data .= ' 
  1122. <tr> 
  1123. <td colspan="2" rowspan="2" style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-size:11px;"> </td> 
  1124. <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:right; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . $products['shipping']['name'] . '</strong></td> 
  1125. <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . self::to_money( $products['shipping']['price'], $lead['currency'] ) . '</strong></td> 
  1126. </tr> 
  1127. '; 
  1128.  
  1129. $field_data .= ' 
  1130. <tr>'; 
  1131.  
  1132. if ( empty( $products['shipping']['name'] ) ) { 
  1133. $field_data .= ' 
  1134. <td colspan="2" style="background-color:#F4F4F4; border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; font-size:11px;"> </td>'; 
  1135.  
  1136. $field_data .= ' 
  1137. <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; text-align:right; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . esc_html__( 'Total:' , 'gravityforms' ) . '</strong></td> 
  1138. <td style="border-bottom:1px solid #DFDFDF; border-right:1px solid #DFDFDF; padding:7px; width:155px; font-family: sans-serif;"><strong style="font-size:12px;">' . self::to_money( $total, $lead['currency'] ) . '</strong></td> 
  1139. </tr> 
  1140. </tfoot> 
  1141. </table> 
  1142. </td> 
  1143. </tr>'; 
  1144. break; 
  1145.  
  1146. return $field_data; 
  1147.  
  1148. public static function send_user_notification( $form, $lead, $override_options = false ) { 
  1149. _deprecated_function( 'send_user_notification', '1.7', 'send_notification' ); 
  1150.  
  1151. $notification = self::prepare_user_notification( $form, $lead, $override_options ); 
  1152. self::send_email( $notification['from'], $notification['to'], $notification['bcc'], $notification['reply_to'], $notification['subject'], $notification['message'], $notification['from_name'], $notification['message_format'], $notification['attachments'], $lead ); 
  1153.  
  1154. public static function send_admin_notification( $form, $lead, $override_options = false ) { 
  1155. _deprecated_function( 'send_admin_notification', '1.7', 'send_notification' ); 
  1156.  
  1157. $notification = self::prepare_admin_notification( $form, $lead, $override_options ); 
  1158. self::send_email( $notification['from'], $notification['to'], $notification['bcc'], $notification['replyTo'], $notification['subject'], $notification['message'], $notification['from_name'], $notification['message_format'], $notification['attachments'], $lead ); 
  1159.  
  1160. private static function prepare_user_notification( $form, $lead, $override_options = false ) { 
  1161. $form_id = $form['id']; 
  1162.  
  1163. if ( ! isset( $form['autoResponder'] ) ) { 
  1164. return; 
  1165.  
  1166. //handling autoresponder email 
  1167. $to_field = isset( $form['autoResponder']['toField'] ) ? rgget( $form['autoResponder']['toField'], $lead ) : ''; 
  1168. $to = gf_apply_filters( array( 'gform_autoresponder_email', $form_id ), $to_field, $form ); 
  1169. $subject = GFCommon::replace_variables( rgget( 'subject', $form['autoResponder'] ), $form, $lead, false, false ); 
  1170.  
  1171. $message_format = gf_apply_filters( array( 'gform_notification_format', $form_id ), 'html', 'user', $form, $lead ); 
  1172. $message = GFCommon::replace_variables( rgget( 'message', $form['autoResponder'] ), $form, $lead, false, false, ! rgget( 'disableAutoformat', $form['autoResponder'] ), $message_format ); 
  1173.  
  1174. if ( apply_filters( 'gform_enable_shortcode_notification_message', true, $form, $lead ) ) { 
  1175. $message = do_shortcode( $message ); 
  1176.  
  1177. //Running trough variable replacement 
  1178. $to = GFCommon::replace_variables( $to, $form, $lead, false, false ); 
  1179. $from = GFCommon::replace_variables( rgget( 'from', $form['autoResponder'] ), $form, $lead, false, false ); 
  1180. $bcc = GFCommon::replace_variables( rgget( 'bcc', $form['autoResponder'] ), $form, $lead, false, false ); 
  1181. $reply_to = GFCommon::replace_variables( rgget( 'replyTo', $form['autoResponder'] ), $form, $lead, false, false ); 
  1182. $from_name = GFCommon::replace_variables( rgget( 'fromName', $form['autoResponder'] ), $form, $lead, false, false ); 
  1183.  
  1184. // override default values if override options provided 
  1185. if ( $override_options && is_array( $override_options ) ) { 
  1186. foreach ( $override_options as $override_key => $override_value ) { 
  1187. ${$override_key} = $override_value; 
  1188.  
  1189. $attachments = gf_apply_filters( array( 'gform_user_notification_attachments', $form_id ), array(), $lead, $form ); 
  1190.  
  1191. //Disabling autoformat to prevent double autoformatting of messages 
  1192. $disableAutoformat = '1'; 
  1193.  
  1194. return compact( 'to', 'from', 'bcc', 'reply_to', 'subject', 'message', 'from_name', 'message_format', 'attachments', 'disableAutoformat' ); 
  1195.  
  1196. private static function prepare_admin_notification( $form, $lead, $override_options = false ) { 
  1197. $form_id = $form['id']; 
  1198.  
  1199. //handling admin notification email 
  1200. $subject = GFCommon::replace_variables( rgget( 'subject', $form['notification'] ), $form, $lead, false, false ); 
  1201.  
  1202. $message_format = gf_apply_filters( array( 'gform_notification_format', $form_id ), 'html', 'admin', $form, $lead ); 
  1203. $message = GFCommon::replace_variables( rgget( 'message', $form['notification'] ), $form, $lead, false, false, ! rgget( 'disableAutoformat', $form['notification'] ), $message_format ); 
  1204.  
  1205. if ( apply_filters( 'gform_enable_shortcode_notification_message', true, $form, $lead ) ) { 
  1206. $message = do_shortcode( $message ); 
  1207.  
  1208. $version_info = self::get_version_info(); 
  1209. $is_expired = ! rgempty( 'expiration_time', $version_info ) && $version_info['expiration_time'] < time(); 
  1210. if ( ! rgar( $version_info, 'is_valid_key' ) && $is_expired ) { 
  1211. $message .= "<br/><br/>Your Gravity Forms License Key has expired. In order to continue receiving support and software updates you must renew your license key. You can do so by following the renewal instructions on the Gravity Forms Settings page in your WordPress Dashboard or by <a href='http://www.gravityhelp.com/renew-license/?key=" . self::get_key() . "'>clicking here</a>."; 
  1212.  
  1213. $from = rgempty( 'fromField', $form['notification'] ) ? rgget( 'from', $form['notification'] ) : rgget( $form['notification']['fromField'], $lead ); 
  1214.  
  1215. if ( rgempty( 'fromNameField', $form['notification'] ) ) { 
  1216. $from_name = rgget( 'fromName', $form['notification'] ); 
  1217. } else { 
  1218. $field = RGFormsModel::get_field( $form, rgget( 'fromNameField', $form['notification'] ) ); 
  1219. $value = RGFormsModel::get_lead_field_value( $lead, $field ); 
  1220. $from_name = GFCommon::get_lead_field_display( $field, $value ); 
  1221.  
  1222. $replyTo = rgempty( 'replyToField', $form['notification'] ) ? rgget( 'replyTo', $form['notification'] ) : rgget( $form['notification']['replyToField'], $lead ); 
  1223.  
  1224. if ( rgempty( 'routing', $form['notification'] ) ) { 
  1225. $email_to = rgempty( 'toField', $form['notification'] ) ? rgget( 'to', $form['notification'] ) : rgget( 'toField', $form['notification'] ); 
  1226. } else { 
  1227. $email_to = array(); 
  1228. foreach ( $form['notification']['routing'] as $routing ) { 
  1229.  
  1230. $source_field = RGFormsModel::get_field( $form, $routing['fieldId'] ); 
  1231. $field_value = RGFormsModel::get_lead_field_value( $lead, $source_field ); 
  1232. $is_value_match = RGFormsModel::is_value_match( $field_value, $routing['value'], $routing['operator'], $source_field, $routing, $form ) && ! RGFormsModel::is_field_hidden( $form, $source_field, array(), $lead ); 
  1233.  
  1234. if ( $is_value_match ) { 
  1235. $email_to[] = $routing['email']; 
  1236.  
  1237. $email_to = join( ', ', $email_to ); 
  1238.  
  1239. //Running through variable replacement 
  1240. $email_to = GFCommon::replace_variables( $email_to, $form, $lead, false, false ); 
  1241. $from = GFCommon::replace_variables( $from, $form, $lead, false, false ); 
  1242. $bcc = GFCommon::replace_variables( rgget( 'bcc', $form['notification'] ), $form, $lead, false, false ); 
  1243. $reply_to = GFCommon::replace_variables( $replyTo, $form, $lead, false, false ); 
  1244. $from_name = GFCommon::replace_variables( $from_name, $form, $lead, false, false ); 
  1245.  
  1246. //Filters the admin notification email to address. Allows users to change email address before notification is sent 
  1247. $to = gf_apply_filters( array( 'gform_notification_email', $form_id ), $email_to, $lead ); 
  1248.  
  1249. // override default values if override options provided 
  1250. if ( $override_options && is_array( $override_options ) ) { 
  1251. foreach ( $override_options as $override_key => $override_value ) { 
  1252. ${$override_key} = $override_value; 
  1253.  
  1254. $attachments = gf_apply_filters( array( 'gform_admin_notification_attachments', $form_id ), array(), $lead, $form ); 
  1255.  
  1256. //Disabling autoformat to prevent double autoformatting of messages 
  1257. $disableAutoformat = '1'; 
  1258.  
  1259. return compact( 'to', 'from', 'bcc', 'replyTo', 'subject', 'message', 'from_name', 'message_format', 'attachments', 'disableAutoformat' ); 
  1260.  
  1261.  
  1262. public static function send_notification( $notification, $form, $lead ) { 
  1263.  
  1264. GFCommon::log_debug( "GFCommon::send_notification(): Starting to process notification (#{$notification['id']} - {$notification['name']})." ); 
  1265. $notification = gf_apply_filters( array( 'gform_notification', $form['id'] ), $notification, $form, $lead ); 
  1266.  
  1267. $to_field = ''; 
  1268. if ( rgar( $notification, 'toType' ) == 'field' ) { 
  1269. $to_field = rgar( $notification, 'toField' ); 
  1270. if ( rgempty( 'toField', $notification ) ) { 
  1271. $to_field = rgar( $notification, 'to' ); 
  1272.  
  1273. $email_to = rgar( $notification, 'to' ); 
  1274. //do routing logic if "to" field doesn't have a value (to support legacy notifications that will run routing prior to this method) 
  1275. if ( empty( $email_to ) && rgar( $notification, 'toType' ) == 'routing' ) { 
  1276. $email_to = array(); 
  1277. foreach ( $notification['routing'] as $routing ) { 
  1278. GFCommon::log_debug( __METHOD__ . '(): Evaluating Routing - rule => ' . print_r( $routing, 1 ) ); 
  1279.  
  1280. $source_field = RGFormsModel::get_field( $form, $routing['fieldId'] ); 
  1281. $field_value = RGFormsModel::get_lead_field_value( $lead, $source_field ); 
  1282. $is_value_match = RGFormsModel::is_value_match( $field_value, $routing['value'], $routing['operator'], $source_field, $routing, $form ) && ! RGFormsModel::is_field_hidden( $form, $source_field, array(), $lead ); 
  1283.  
  1284. if ( $is_value_match ) { 
  1285. $email_to[] = $routing['email']; 
  1286.  
  1287. GFCommon::log_debug( __METHOD__ . '(): Evaluating Routing - field value => ' . print_r( $field_value, 1 ) ); 
  1288. $is_value_match = $is_value_match ? 'Yes' : 'No'; 
  1289. GFCommon::log_debug( __METHOD__ . '(): Evaluating Routing - is value match? ' . $is_value_match ); 
  1290.  
  1291. $email_to = join( ', ', $email_to ); 
  1292. } else if ( ! empty( $to_field ) ) { 
  1293. $source_field = RGFormsModel::get_field( $form, $to_field ); 
  1294. $email_to = RGFormsModel::get_lead_field_value( $lead, $source_field ); 
  1295.  
  1296. //Running through variable replacement 
  1297. $to = GFCommon::replace_variables( $email_to, $form, $lead, false, false ); 
  1298. $subject = GFCommon::replace_variables( rgar( $notification, 'subject' ), $form, $lead, false, false, true, 'text' ); 
  1299. $from = GFCommon::replace_variables( rgar( $notification, 'from' ), $form, $lead, false, false ); 
  1300. $from_name = GFCommon::replace_variables( rgar( $notification, 'fromName' ), $form, $lead, false, false, true, 'text' ); 
  1301. $bcc = GFCommon::replace_variables( rgar( $notification, 'bcc' ), $form, $lead, false, false ); 
  1302. $replyTo = GFCommon::replace_variables( rgar( $notification, 'replyTo' ), $form, $lead, false, false ); 
  1303.  
  1304. $message_format = rgempty( 'message_format', $notification ) ? 'html' : rgar( $notification, 'message_format' ); 
  1305. $message = GFCommon::replace_variables( rgar( $notification, 'message' ), $form, $lead, false, false, ! rgar( $notification, 'disableAutoformat' ), $message_format ); 
  1306.  
  1307. if ( apply_filters( 'gform_enable_shortcode_notification_message', true, $form, $lead ) ) { 
  1308. $message = do_shortcode( $message ); 
  1309.  
  1310. // allow attachments to be passed as a single path (string) or an array of paths, if string provided, add to array 
  1311. $attachments = rgar( $notification, 'attachments' ); 
  1312. if ( ! empty( $attachments ) ) { 
  1313. $attachments = is_array( $attachments ) ? $attachments : array( $attachments ); 
  1314. } else { 
  1315. $attachments = array(); 
  1316.  
  1317. self::send_email( $from, $to, $bcc, $replyTo, $subject, $message, $from_name, $message_format, $attachments, $lead ); 
  1318.  
  1319. return compact( 'to', 'from', 'bcc', 'replyTo', 'subject', 'message', 'from_name', 'message_format', 'attachments' ); 
  1320.  
  1321.  
  1322. public static function send_notifications( $notification_ids, $form, $lead, $do_conditional_logic = true, $event = 'form_submission' ) { 
  1323. $entry_id = rgar( $lead, 'id' ); 
  1324. if ( ! is_array( $notification_ids ) || empty( $notification_ids ) ) { 
  1325. GFCommon::log_debug( "GFCommon::send_notifications(): Aborting. No notifications to process for {$event} event for entry #{$entry_id}." ); 
  1326.  
  1327. return; 
  1328.  
  1329. GFCommon::log_debug( "GFCommon::send_notifications(): Processing notifications for {$event} event for entry #{$entry_id}: " . print_r( $notification_ids, true ) . "\n(only active/applicable notifications are sent)" ); 
  1330.  
  1331. foreach ( $notification_ids as $notification_id ) { 
  1332. if ( ! isset( $form['notifications'][ $notification_id ] ) ) { 
  1333. continue; 
  1334. if ( isset( $form['notifications'][ $notification_id ]['isActive'] ) && ! $form['notifications'][ $notification_id ]['isActive'] ) { 
  1335. GFCommon::log_debug( "GFCommon::send_notifications(): Notification is inactive, not processing notification (#{$notification_id} - {$form['notifications'][$notification_id]['name']})." ); 
  1336. continue; 
  1337.  
  1338. $notification = $form['notifications'][ $notification_id ]; 
  1339.  
  1340. //check conditional logic when appropriate 
  1341. if ( $do_conditional_logic && ! GFCommon::evaluate_conditional_logic( rgar( $notification, 'conditionalLogic' ), $form, $lead ) ) { 
  1342. GFCommon::log_debug( "GFCommon::send_notifications(): Notification conditional logic not met, not processing notification (#{$notification_id} - {$notification['name']})." ); 
  1343. continue; 
  1344.  
  1345. if ( rgar( $notification, 'type' ) == 'user' ) { 
  1346.  
  1347. //Getting user notification from legacy structure (for backwards compatibility) 
  1348. $legacy_notification = GFCommon::prepare_user_notification( $form, $lead ); 
  1349. $notification = self::merge_legacy_notification( $notification, $legacy_notification ); 
  1350. } else if ( rgar( $notification, 'type' ) == 'admin' ) { 
  1351.  
  1352. //Getting admin notification from legacy structure (for backwards compatibility) 
  1353. $legacy_notification = GFCommon::prepare_admin_notification( $form, $lead ); 
  1354. $notification = self::merge_legacy_notification( $notification, $legacy_notification ); 
  1355.  
  1356. //sending notification 
  1357. self::send_notification( $notification, $form, $lead ); 
  1358.  
  1359.  
  1360. public static function send_form_submission_notifications( $form, $lead ) { 
  1361. GFAPI::send_notifications( $form, $lead ); 
  1362.  
  1363. private static function merge_legacy_notification( $notification, $notification_data ) { 
  1364.  
  1365. $keys = array( 'to', 'from', 'bcc', 'replyTo', 'subject', 'message', 'from_name', 'message_format', 'attachments', 'disableAutoformat' ); 
  1366. foreach ( $keys as $key ) { 
  1367. $notification[ $key ] = rgar( $notification_data, $key ); 
  1368.  
  1369. return $notification; 
  1370.  
  1371. public static function get_notifications_to_send( $event, $form, $lead ) { 
  1372. $notifications = self::get_notifications( $event, $form ); 
  1373. $notifications_to_send = array(); 
  1374. foreach ( $notifications as $notification ) { 
  1375. if ( GFCommon::evaluate_conditional_logic( rgar( $notification, 'conditionalLogic' ), $form, $lead ) ) { 
  1376. $notifications_to_send[] = $notification; 
  1377.  
  1378. return $notifications_to_send; 
  1379.  
  1380. public static function get_notifications( $event, $form ) { 
  1381. if ( rgempty( 'notifications', $form ) ) { 
  1382. return array(); 
  1383.  
  1384. $notifications = array(); 
  1385. foreach ( $form['notifications'] as $notification ) { 
  1386. $notification_event = rgar( $notification, 'event' ); 
  1387. $omit_from_resend = array( 'form_saved', 'form_save_email_requested' ); 
  1388. if ( $notification_event == $event || ( $event == 'resend_notifications' && ! in_array( $notification_event, $omit_from_resend ) ) ) { 
  1389. $notifications[] = $notification; 
  1390.  
  1391. return $notifications; 
  1392.  
  1393. public static function has_admin_notification( $form ) { 
  1394.  
  1395. return ( ! empty( $form['notification']['to'] ) || ! empty( $form['notification']['routing'] ) ) && ( ! empty( $form['notification']['subject'] ) || ! empty( $form['notification']['message'] ) ); 
  1396.  
  1397.  
  1398. public static function has_user_notification( $form ) { 
  1399.  
  1400. return ! empty( $form['autoResponder']['toField'] ) && ( ! empty( $form['autoResponder']['subject'] ) || ! empty( $form['autoResponder']['message'] ) ); 
  1401.  
  1402.  
  1403. private static function send_email( $from, $to, $bcc, $reply_to, $subject, $message, $from_name = '', $message_format = 'html', $attachments = '', $entry = false ) { 
  1404.  
  1405. global $phpmailer; 
  1406.  
  1407. $to = str_replace( ' ', '', $to ); 
  1408. $bcc = str_replace( ' ', '', $bcc ); 
  1409. $error = false; 
  1410.  
  1411. if ( ! GFCommon::is_valid_email( $from ) ) { 
  1412. $from = get_bloginfo( 'admin_email' ); 
  1413.  
  1414. if ( ! GFCommon::is_valid_email_list( $to ) ) { 
  1415. $error = new WP_Error( 'invalid_to', 'Cannot send email because the TO address is invalid.' ); 
  1416. } else if ( empty( $subject ) && empty( $message ) ) { 
  1417. $error = new WP_Error( 'missing_subject_and_message', 'Cannot send email because there is no SUBJECT and no MESSAGE.' ); 
  1418. } else if ( ! GFCommon::is_valid_email( $from ) ) { 
  1419. $error = new WP_Error( 'invalid_from', 'Cannot send email because the FROM address is invalid.' ); 
  1420.  
  1421. if ( is_wp_error( $error ) ) { 
  1422. GFCommon::log_error( 'GFCommon::send_email(): ' . $error->get_error_message() ); 
  1423. GFCommon::log_error( print_r( compact( 'to', 'subject', 'message' ), true ) ); 
  1424.  
  1425. /** 
  1426. * Fires when an email from Gravity Forms has failed to send 
  1427. * @param string $error The Error message returned after the email fails to send 
  1428. */ 
  1429. do_action( 'gform_send_email_failed', $error, compact( 'from', 'to', 'bcc', 'reply_to', 'subject', 'message', 'from_name', 'message_format', 'attachments' ), $entry ); 
  1430.  
  1431. return; 
  1432.  
  1433. $content_type = $message_format == 'html' ? 'text/html' : 'text/plain'; 
  1434. $name = empty( $from_name ) ? $from : $from_name; 
  1435.  
  1436. $headers = array(); 
  1437. $headers['From'] = "From: \"" . wp_strip_all_tags( $name, true ) . "\" <{$from}>"; 
  1438.  
  1439. if ( GFCommon::is_valid_email_list( $reply_to ) ) { 
  1440. $headers['Reply-To'] = "Reply-To: {$reply_to}"; 
  1441.  
  1442. if ( GFCommon::is_valid_email_list( $bcc ) ) { 
  1443. $headers['Bcc'] = "Bcc: $bcc"; 
  1444.  
  1445. $headers['Content-type'] = "Content-type: {$content_type}; charset=" . get_option( 'blog_charset' ); 
  1446.  
  1447. $abort_email = false; 
  1448. extract( apply_filters( 'gform_pre_send_email', compact( 'to', 'subject', 'message', 'headers', 'attachments', 'abort_email' ), $message_format ) ); 
  1449.  
  1450. $is_success = false; 
  1451. if ( ! $abort_email ) { 
  1452. GFCommon::log_debug( 'GFCommon::send_email(): Sending email via wp_mail().' ); 
  1453. GFCommon::log_debug( print_r( compact( 'to', 'subject', 'message', 'headers', 'attachments', 'abort_email' ), true ) ); 
  1454. $is_success = wp_mail( $to, $subject, $message, $headers, $attachments ); 
  1455. $result = is_wp_error( $is_success ) ? $is_success->get_error_message() : $is_success; 
  1456. GFCommon::log_debug( "GFCommon::send_email(): Result from wp_mail(): {$result}" ); 
  1457. if ( ! is_wp_error( $is_success ) && $is_success ) { 
  1458. GFCommon::log_debug( 'GFCommon::send_email(): Mail was passed from WordPress to the mail server.' ); 
  1459. } else { 
  1460. GFCommon::log_error( 'GFCommon::send_email(): The mail message was passed off to WordPress for processing, but WordPress was unable to send the message.' ); 
  1461.  
  1462. if ( has_filter( 'phpmailer_init' ) ) { 
  1463. GFCommon::log_debug( __METHOD__ . '(): The WordPress phpmailer_init hook has been detected, usually used by SMTP plugins, it can impact mail delivery.' ); 
  1464.  
  1465. if ( ! empty( $phpmailer->ErrorInfo ) ) { 
  1466. GFCommon::log_debug( __METHOD__ . '(): PHPMailer class returned an error message: ' . $phpmailer->ErrorInfo ); 
  1467. }  
  1468. } else { 
  1469. GFCommon::log_debug( 'GFCommon::send_email(): Aborting. The gform_pre_send_email hook was used to set the abort_email parameter to true.' ); 
  1470.  
  1471. self::add_emails_sent(); 
  1472.  
  1473.  
  1474. do_action( 'gform_after_email', $is_success, $to, $subject, $message, $headers, $attachments, $message_format, $from, $from_name, $bcc, $reply_to, $entry ); 
  1475.  
  1476. public static function add_emails_sent() { 
  1477.  
  1478. $count = self::get_emails_sent(); 
  1479.  
  1480. update_option( 'gform_email_count', ++$count ); 
  1481.  
  1482.  
  1483. public static function get_emails_sent() { 
  1484. $count = get_option( 'gform_email_count' ); 
  1485.  
  1486. if ( ! $count ) { 
  1487. $count = 0; 
  1488.  
  1489. return $count; 
  1490.  
  1491. public static function get_api_calls() { 
  1492. $count = get_option( 'gform_api_count' ); 
  1493.  
  1494. if ( ! $count ) { 
  1495. $count = 0; 
  1496.  
  1497. return $count; 
  1498.  
  1499. public static function add_api_call() { 
  1500.  
  1501. $count = self::get_api_calls(); 
  1502.  
  1503. update_option( 'gform_api_count', ++$count ); 
  1504.  
  1505.  
  1506. public static function has_post_field( $fields ) { 
  1507. foreach ( $fields as $field ) { 
  1508. if ( in_array( $field->type, array( 'post_title', 'post_content', 'post_excerpt', 'post_category', 'post_image', 'post_tags', 'post_custom_field' ) ) ) { 
  1509. return true; 
  1510.  
  1511. return false; 
  1512.  
  1513. public static function has_list_field( $form ) { 
  1514. return self::has_field_by_type( $form, 'list' ); 
  1515.  
  1516. public static function has_credit_card_field( $form ) { 
  1517. return self::has_field_by_type( $form, 'creditcard' ); 
  1518.  
  1519. private static function has_field_by_type( $form, $type ) { 
  1520. if ( is_array( $form['fields'] ) ) { 
  1521. foreach ( $form['fields'] as $field ) { 
  1522.  
  1523. if ( RGFormsModel::get_input_type( $field ) == $type ) { 
  1524. return true; 
  1525.  
  1526. return false; 
  1527.  
  1528. public static function current_user_can_any( $caps ) { 
  1529.  
  1530. if ( ! is_array( $caps ) ) { 
  1531. $has_cap = current_user_can( $caps ) || current_user_can( 'gform_full_access' ); 
  1532.  
  1533. return $has_cap; 
  1534.  
  1535. foreach ( $caps as $cap ) { 
  1536. if ( current_user_can( $cap ) ) { 
  1537. return true; 
  1538.  
  1539. $has_full_access = current_user_can( 'gform_full_access' ); 
  1540.  
  1541. return $has_full_access; 
  1542.  
  1543. public static function current_user_can_which( $caps ) { 
  1544.  
  1545. foreach ( $caps as $cap ) { 
  1546. if ( current_user_can( $cap ) ) { 
  1547. return $cap; 
  1548.  
  1549. return ''; 
  1550.  
  1551. public static function is_pricing_field( $field_type ) { 
  1552. return self::is_product_field( $field_type ) || $field_type == 'donation'; 
  1553.  
  1554. public static function is_product_field( $field_type ) { 
  1555. $product_fields = apply_filters( 'gform_product_field_types', array( 'option', 'quantity', 'product', 'total', 'shipping', 'calculation', 'price' ) ); 
  1556. return in_array( $field_type, $product_fields ); 
  1557.  
  1558. public static function all_caps() { 
  1559. return array( 
  1560. 'gravityforms_edit_forms',  
  1561. 'gravityforms_delete_forms',  
  1562. 'gravityforms_create_form',  
  1563. 'gravityforms_view_entries',  
  1564. 'gravityforms_edit_entries',  
  1565. 'gravityforms_delete_entries',  
  1566. 'gravityforms_view_settings',  
  1567. 'gravityforms_edit_settings',  
  1568. 'gravityforms_export_entries',  
  1569. 'gravityforms_uninstall',  
  1570. 'gravityforms_view_entry_notes',  
  1571. 'gravityforms_edit_entry_notes',  
  1572. 'gravityforms_view_updates',  
  1573. 'gravityforms_view_addons',  
  1574. 'gravityforms_preview_forms',  
  1575. ); 
  1576.  
  1577. public static function delete_directory( $dir ) { 
  1578. if ( ! file_exists( $dir ) ) { 
  1579. return; 
  1580.  
  1581. if ( $handle = opendir( $dir ) ) { 
  1582. $array = array(); 
  1583. while ( false !== ( $file = readdir( $handle ) ) ) { 
  1584. if ( $file != '.' && $file != '..' ) { 
  1585. if ( is_dir( $dir . $file ) ) { 
  1586. if ( ! @rmdir( $dir . $file ) ) { 
  1587. // Empty directory? Remove it 
  1588. self::delete_directory( $dir . $file . '/' ); 
  1589. } // Not empty? Delete the files inside it 
  1590. } else { 
  1591. @unlink( $dir . $file ); 
  1592. closedir( $handle ); 
  1593. @rmdir( $dir ); 
  1594.  
  1595. public static function get_remote_message() { 
  1596. return stripslashes( get_option( 'rg_gforms_message' ) ); 
  1597.  
  1598. public static function get_key() { 
  1599. return get_option( 'rg_gforms_key' ); 
  1600.  
  1601. public static function has_update( $use_cache = true ) { 
  1602. $version_info = GFCommon::get_version_info( $use_cache ); 
  1603. $version = rgar( $version_info, 'version' ); 
  1604.  
  1605. return empty( $version ) ? false : version_compare( GFCommon::$version, $version, '<' ); 
  1606.  
  1607. public static function get_key_info( $key ) { 
  1608.  
  1609. $options = array( 'method' => 'POST', 'timeout' => 3 ); 
  1610. $options['headers'] = array( 
  1611. 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),  
  1612. 'User-Agent' => 'WordPress/' . get_bloginfo( 'version' ),  
  1613. 'Referer' => get_bloginfo( 'url' ) 
  1614. ); 
  1615.  
  1616. $raw_response = self::post_to_manager( 'api.php', "op=get_key&key={$key}", $options ); 
  1617.  
  1618. if ( is_wp_error( $raw_response ) || $raw_response['response']['code'] != 200 ) { 
  1619. return array(); 
  1620.  
  1621. $key_info = unserialize( trim( $raw_response['body'] ) ); 
  1622.  
  1623. return $key_info ? $key_info : array(); 
  1624.  
  1625. public static function get_version_info( $cache = true ) { 
  1626.  
  1627. $raw_response = get_transient( 'gform_update_info' ); 
  1628. if ( ! $cache ) { 
  1629. $raw_response = null; 
  1630.  
  1631. if ( ! $raw_response ) { 
  1632. //Getting version number 
  1633. $options = array( 'method' => 'POST', 'timeout' => 20 ); 
  1634. $options['headers'] = array( 
  1635. 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),  
  1636. 'User-Agent' => 'WordPress/' . get_bloginfo( 'version' ),  
  1637. 'Referer' => get_bloginfo( 'url' ) 
  1638. ); 
  1639. $options['body'] = self::get_remote_post_params(); 
  1640. $options['timeout'] = 15; 
  1641.  
  1642. $nocache = $cache ? '' : 'nocache=1'; //disabling server side caching 
  1643.  
  1644. $raw_response = self::post_to_manager( 'version.php', $nocache, $options ); 
  1645.  
  1646. //caching responses. 
  1647. set_transient( 'gform_update_info', $raw_response, 86400 ); //caching for 24 hours 
  1648.  
  1649. if ( is_wp_error( $raw_response ) || rgars( $raw_response, 'response/code' ) != 200 ) { 
  1650.  
  1651. return array( 'is_valid_key' => '1', 'version' => '', 'url' => '', 'is_error' => '1' ); 
  1652.  
  1653. $version_info = json_decode( $raw_response['body'], true ); 
  1654.  
  1655. if ( empty( $version_info ) ) { 
  1656. return array( 'is_valid_key' => '1', 'version' => '', 'url' => '', 'is_error' => '1' ); 
  1657.  
  1658. return $version_info; 
  1659.  
  1660. public static function get_remote_request_params() { 
  1661. global $wpdb; 
  1662.  
  1663. return sprintf( 'of=GravityForms&key=%s&v=%s&wp=%s&php=%s&mysql=%s&version=2', urlencode( self::get_key() ), urlencode( self::$version ), urlencode( get_bloginfo( 'version' ) ), urlencode( phpversion() ), urlencode( $wpdb->db_version() ) ); 
  1664.  
  1665. public static function get_remote_post_params() { 
  1666. global $wpdb; 
  1667.  
  1668. if ( ! function_exists( 'get_plugins' ) ) { 
  1669. require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
  1670. $plugin_list = get_plugins(); 
  1671. $site_url = get_bloginfo( 'url' ); 
  1672. $plugins = array(); 
  1673.  
  1674. $active_plugins = get_option( 'active_plugins' ); 
  1675.  
  1676. foreach ( $plugin_list as $key => $plugin ) { 
  1677. $is_active = in_array( $key, $active_plugins ); 
  1678.  
  1679. //filter for only gravityforms ones, may get some others if using our naming convention 
  1680. if ( strpos( strtolower( $plugin['Title'] ), 'gravity forms' ) !== false ) { 
  1681. $name = substr( $key, 0, strpos( $key, '/' ) ); 
  1682. $plugins[] = array( 'name' => $name, 'version' => $plugin['Version'], 'is_active' => $is_active ); 
  1683. $plugins = json_encode( $plugins ); 
  1684.  
  1685. //get theme info 
  1686. $theme = wp_get_theme(); 
  1687. $theme_name = $theme->get( 'Name' ); 
  1688. $theme_uri = $theme->get( 'ThemeURI' ); 
  1689. $theme_version = $theme->get( 'Version' ); 
  1690. $theme_author = $theme->get( 'Author' ); 
  1691. $theme_author_uri = $theme->get( 'AuthorURI' ); 
  1692.  
  1693. $form_counts = GFFormsModel::get_form_count(); 
  1694. $active_count = $form_counts['active']; 
  1695. $inactive_count = $form_counts['inactive']; 
  1696. $fc = abs( $active_count ) + abs( $inactive_count ); 
  1697. $entry_count = GFFormsModel::get_lead_count_all_forms( 'active' ); 
  1698. $im = is_multisite(); 
  1699.  
  1700. $post = array( 'of' => 'gravityforms', 'key' => self::get_key(), 'v' => self::$version, 'wp' => get_bloginfo( 'version' ), 'php' => phpversion(), 'mysql' => $wpdb->db_version(), 'version' => '2', 'plugins' => $plugins, 'tn' => $theme_name, 'tu' => $theme_uri, 'tv' => $theme_version, 'ta' => $theme_author, 'tau' => $theme_author_uri, 'im' => $im, 'fc' => $fc, 'ec' => $entry_count, 'emc' => self::get_emails_sent(), 'api' => self::get_api_calls() ); 
  1701.  
  1702. return $post; 
  1703.  
  1704. public static function ensure_wp_version() { 
  1705. if ( ! GF_SUPPORTED_WP_VERSION ) { 
  1706. echo "<div class='error' style='padding:10px;'>" . sprintf( esc_html__( 'Gravity Forms require WordPress %s or greater. You must upgrade WordPress in order to use Gravity Forms' , 'gravityforms' ), GF_MIN_WP_VERSION ) . '</div>'; 
  1707.  
  1708. return false; 
  1709.  
  1710. return true; 
  1711.  
  1712. public static function check_update( $option, $cache = true ) { 
  1713.  
  1714. if ( ! is_object( $option ) ) { 
  1715. return $option; 
  1716.  
  1717. $version_info = self::get_version_info( $cache ); 
  1718.  
  1719. if ( ! $version_info ) { 
  1720. return $option; 
  1721.  
  1722. $plugin_path = 'gravityforms/gravityforms.php'; 
  1723. if ( empty( $option->response[ $plugin_path ] ) ) { 
  1724. $option->response[ $plugin_path ] = new stdClass(); 
  1725.  
  1726. $version = rgar( $version_info, 'version' ); 
  1727. //Empty response means that the key is invalid. Do not queue for upgrade 
  1728. if ( ! rgar( $version_info, 'is_valid_key' ) || version_compare( GFCommon::$version, $version, '>=' ) ) { 
  1729. unset( $option->response[ $plugin_path ] ); 
  1730. } else { 
  1731. $url = rgar( $version_info, 'url' ); 
  1732. $option->response[ $plugin_path ]->url = 'http://www.gravityforms.com'; 
  1733. $option->response[ $plugin_path ]->slug = 'gravityforms'; 
  1734. $option->response[ $plugin_path ]->plugin = $plugin_path; 
  1735. $option->response[ $plugin_path ]->package = str_replace( '{KEY}', GFCommon::get_key(), $url ); 
  1736. $option->response[ $plugin_path ]->new_version = $version; 
  1737. $option->response[ $plugin_path ]->id = '0'; 
  1738.  
  1739. return $option; 
  1740.  
  1741.  
  1742. public static function cache_remote_message() { 
  1743. //Getting version number 
  1744. $key = GFCommon::get_key(); 
  1745. $body = "key=$key"; 
  1746. $options = array( 'method' => 'POST', 'timeout' => 3, 'body' => $body ); 
  1747. $options['headers'] = array( 
  1748. 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ),  
  1749. 'Content-Length' => strlen( $body ),  
  1750. 'User-Agent' => 'WordPress/' . get_bloginfo( 'version' ),  
  1751. 'Referer' => get_bloginfo( 'url' ) 
  1752. ); 
  1753.  
  1754. $raw_response = self::post_to_manager( 'message.php', GFCommon::get_remote_request_params(), $options ); 
  1755.  
  1756. if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code'] ) { 
  1757. $message = ''; 
  1758. } else { 
  1759. $message = $raw_response['body']; 
  1760.  
  1761. //validating that message is a valid Gravity Form message. If message is invalid, don't display anything 
  1762. if ( substr( $message, 0, 10 ) != '<!--GFM-->' ) { 
  1763. $message = ''; 
  1764.  
  1765. update_option( 'rg_gforms_message', $message ); 
  1766.  
  1767. public static function post_to_manager( $file, $query, $options ) { 
  1768.  
  1769. $request_url = GRAVITY_MANAGER_URL . '/' . $file . '?' . $query; 
  1770. self::log_debug( 'Posting to manager: ' . $request_url ); 
  1771. $raw_response = wp_remote_post( $request_url, $options ); 
  1772. self::log_debug( print_r( $raw_response, true ) ); 
  1773.  
  1774. if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code'] ) { 
  1775. self::log_error( 'Error from manager. Sending to proxy...' ); 
  1776. $request_url = GRAVITY_MANAGER_PROXY_URL . '/proxy.php?f=' . $file . '&' . $query; 
  1777. $raw_response = wp_remote_post( $request_url, $options ); 
  1778. self::log_debug( print_r( $raw_response, true ) ); 
  1779.  
  1780. return $raw_response; 
  1781.  
  1782. public static function get_local_timestamp( $timestamp = null ) { 
  1783. if ( $timestamp == null ) { 
  1784. $timestamp = time(); 
  1785.  
  1786. return $timestamp + ( get_option( 'gmt_offset' ) * 3600 ); 
  1787.  
  1788. public static function get_gmt_timestamp( $local_timestamp ) { 
  1789. return $local_timestamp - ( get_option( 'gmt_offset' ) * 3600 ); 
  1790.  
  1791. public static function format_date( $gmt_datetime, $is_human = true, $date_format = '', $include_time = true ) { 
  1792. if ( empty( $gmt_datetime ) ) { 
  1793. return ''; 
  1794.  
  1795. //adjusting date to local configured Time Zone 
  1796. $lead_gmt_time = mysql2date( 'G', $gmt_datetime ); 
  1797. $lead_local_time = self::get_local_timestamp( $lead_gmt_time ); 
  1798.  
  1799. if ( empty( $date_format ) ) { 
  1800. $date_format = get_option( 'date_format' ); 
  1801.  
  1802. if ( $is_human ) { 
  1803. $time_diff = time() - $lead_gmt_time; 
  1804.  
  1805. if ( $time_diff > 0 && $time_diff < 24 * 60 * 60 ) { 
  1806. $date_display = sprintf( esc_html__( '%s ago', 'gravityforms' ), human_time_diff( $lead_gmt_time ) ); 
  1807. } else { 
  1808. $date_display = $include_time ? sprintf( esc_html__( '%1$s at %2$s', 'gravityforms' ), date_i18n( $date_format, $lead_local_time, true ), date_i18n( get_option( 'time_format' ), $lead_local_time, true ) ) : date_i18n( $date_format, $lead_local_time, true ); 
  1809. } else { 
  1810. $date_display = $include_time ? sprintf( esc_html__( '%1$s at %2$s', 'gravityforms' ), date_i18n( $date_format, $lead_local_time, true ), date_i18n( get_option( 'time_format' ), $lead_local_time, true ) ) : date_i18n( $date_format, $lead_local_time, true ); 
  1811.  
  1812. return $date_display; 
  1813.  
  1814. public static function get_selection_value( $value ) { 
  1815. $ary = explode( '|', $value ); 
  1816. $val = $ary[0]; 
  1817.  
  1818. return $val; 
  1819.  
  1820. public static function selection_display( $value, $field, $currency = '', $use_text = false ) { 
  1821. if ( is_array( $value ) ) { 
  1822. return ''; 
  1823.  
  1824. if ( $field !== null && $field->enablePrice ) { 
  1825. $ary = explode( '|', $value ); 
  1826. $val = $ary[0]; 
  1827. $price = count( $ary ) > 1 ? $ary[1] : ''; 
  1828. } else { 
  1829. $val = $value; 
  1830. $price = ''; 
  1831.  
  1832. if ( $use_text ) { 
  1833. $val = RGFormsModel::get_choice_text( $field, $val ); 
  1834.  
  1835. if ( ! empty( $price ) ) { 
  1836. return "$val (" . self::to_money( $price, $currency ) . ')'; 
  1837. } else { 
  1838. return $val; 
  1839.  
  1840. public static function date_display( $value, $input_format = 'mdy', $output_format = false ) { 
  1841.  
  1842. if ( ! $output_format ) { 
  1843. $output_format = $input_format; 
  1844.  
  1845. $date = self::parse_date( $value, $input_format ); 
  1846. if ( empty( $date ) ) { 
  1847. return $value; 
  1848.  
  1849. list( $position, $separator ) = rgexplode( '_', $output_format, 2 ); 
  1850. switch ( $separator ) { 
  1851. case 'dash' : 
  1852. $separator = '-'; 
  1853. break; 
  1854. case 'dot' : 
  1855. $separator = '.'; 
  1856. break; 
  1857. default : 
  1858. $separator = '/'; 
  1859. break; 
  1860.  
  1861. switch ( $position ) { 
  1862. case 'year' : 
  1863. case 'month' : 
  1864. case 'day' : 
  1865. return $date[ $position ]; 
  1866.  
  1867. case 'ymd' : 
  1868. return $date['year'] . $separator . $date['month'] . $separator . $date['day']; 
  1869. break; 
  1870.  
  1871. case 'dmy' : 
  1872. return $date['day'] . $separator . $date['month'] . $separator . $date['year']; 
  1873. break; 
  1874.  
  1875. default : 
  1876. return $date['month'] . $separator . $date['day'] . $separator . $date['year']; 
  1877. break; 
  1878.  
  1879.  
  1880. public static function parse_date( $date, $format = 'mdy' ) { 
  1881. $date_info = array(); 
  1882.  
  1883. $position = substr( $format, 0, 3 ); 
  1884.  
  1885. if ( is_array( $date ) ) { 
  1886.  
  1887. switch ( $position ) { 
  1888. case 'mdy' : 
  1889. $date_info['month'] = rgar( $date, 0 ); 
  1890. $date_info['day'] = rgar( $date, 1 ); 
  1891. $date_info['year'] = rgar( $date, 2 ); 
  1892. break; 
  1893.  
  1894. case 'dmy' : 
  1895. $date_info['day'] = rgar( $date, 0 ); 
  1896. $date_info['month'] = rgar( $date, 1 ); 
  1897. $date_info['year'] = rgar( $date, 2 ); 
  1898. break; 
  1899.  
  1900. case 'ymd' : 
  1901. $date_info['year'] = rgar( $date, 0 ); 
  1902. $date_info['month'] = rgar( $date, 1 ); 
  1903. $date_info['day'] = rgar( $date, 2 ); 
  1904. break; 
  1905. return $date_info; 
  1906.  
  1907. $date = preg_replace( "|[/\.]|", '-', $date ); 
  1908. if ( preg_match( '/^(\d{1, 4})-(\d{1, 2})-(\d{1, 4})$/', $date, $matches ) ) { 
  1909.  
  1910. if ( strlen( $matches[1] ) == 4 ) { 
  1911. //format yyyy-mm-dd 
  1912. $date_info['year'] = $matches[1]; 
  1913. $date_info['month'] = $matches[2]; 
  1914. $date_info['day'] = $matches[3]; 
  1915. } else if ( $position == 'mdy' ) { 
  1916. //format mm-dd-yyyy 
  1917. $date_info['month'] = $matches[1]; 
  1918. $date_info['day'] = $matches[2]; 
  1919. $date_info['year'] = $matches[3]; 
  1920. } else { 
  1921. //format dd-mm-yyyy 
  1922. $date_info['day'] = $matches[1]; 
  1923. $date_info['month'] = $matches[2]; 
  1924. $date_info['year'] = $matches[3]; 
  1925.  
  1926. return $date_info; 
  1927.  
  1928.  
  1929. public static function truncate_url( $url ) { 
  1930. $truncated_url = basename( $url ); 
  1931. if ( empty( $truncated_url ) ) { 
  1932. $truncated_url = dirname( $url ); 
  1933.  
  1934. $ary = explode( '?', $truncated_url ); 
  1935.  
  1936. return $ary[0]; 
  1937.  
  1938. public static function get_field_placeholder_attribute( $field ) { 
  1939.  
  1940. $placeholder_value = GFCommon::replace_variables_prepopulate( $field->placeholder ); 
  1941.  
  1942. return ! empty( $placeholder_value ) ? sprintf( "placeholder='%s'", esc_attr( $placeholder_value ) ) : ''; 
  1943.  
  1944. public static function get_input_placeholder_attribute( $input ) { 
  1945.  
  1946. $placeholder_value = self::get_input_placeholder_value( $input ); 
  1947.  
  1948. return ! empty( $placeholder_value ) ? sprintf( "placeholder='%s'", esc_attr( $placeholder_value ) ) : ''; 
  1949.  
  1950. public static function get_input_placeholder_value( $input ) { 
  1951.  
  1952. $placeholder = rgar( $input, 'placeholder' ); 
  1953.  
  1954. return empty( $placeholder ) ? '' : GFCommon::replace_variables_prepopulate( $placeholder ); 
  1955.  
  1956. public static function get_tabindex() { 
  1957. return GFCommon::$tab_index > 0 ? "tabindex='" . GFCommon::$tab_index ++ . "'" : ''; 
  1958.  
  1959. /** 
  1960. * @deprecated 
  1961. * @param GF_Field_Checkbox $field 
  1962. * @param $value 
  1963. * @param $disabled_text 
  1964. * @return mixed 
  1965. */ 
  1966. public static function get_checkbox_choices( $field, $value, $disabled_text ) { 
  1967. _deprecated_function( 'get_checkbox_choices', '1.9', 'GF_Field_Checkbox::get_checkbox_choices' ); 
  1968.  
  1969. return $field->get_checkbox_choices( $value, $disabled_text ); 
  1970.  
  1971. /** 
  1972. * @deprecated Deprecated since 1.9. Use GF_Field_Checkbox::get_radio_choices() instead. 
  1973. * @param GF_Field_Radio $field 
  1974. * @param string $value 
  1975. * @param $disabled_text 
  1976. * @return mixed 
  1977. */ 
  1978. public static function get_radio_choices( $field, $value = '', $disabled_text ) { 
  1979. _deprecated_function( 'get_radio_choices', '1.9', 'GF_Field_Checkbox::get_radio_choices' ); 
  1980.  
  1981. return $field->get_radio_choices( $value, $disabled_text ); 
  1982.  
  1983. public static function get_field_type_title( $type ) { 
  1984. $gf_field = GF_Fields::get( $type ); 
  1985. if ( ! empty( $gf_field ) ) { 
  1986. return $gf_field->get_form_editor_field_title(); 
  1987.  
  1988. return apply_filters( 'gform_field_type_title', $type, $type ); 
  1989.  
  1990. public static function get_select_choices( $field, $value = '', $support_placeholders = true ) { 
  1991. $choices = ''; 
  1992.  
  1993. if ( RG_CURRENT_VIEW == 'entry' && empty( $value ) && empty( $field->placeholder ) ) { 
  1994. $choices .= "<option value=''></option>"; 
  1995.  
  1996. if ( is_array( $field->choices ) ) { 
  1997.  
  1998. if ( $support_placeholders && ! empty( $field->placeholder ) ) { 
  1999. $selected = empty( $value ) ? "selected='selected'" : ''; 
  2000. $choices .= sprintf( "<option value='' %s class='gf_placeholder'>%s</option>", $selected, esc_html( $field->placeholder ) ); 
  2001.  
  2002. foreach ( $field->choices as $choice ) { 
  2003.  
  2004. //needed for users upgrading from 1.0 
  2005. $field_value = ! empty( $choice['value'] ) || $field->enableChoiceValue || $field->type == 'post_category' ? $choice['value'] : $choice['text']; 
  2006. if ( $field->enablePrice ) { 
  2007. $price = rgempty( 'price', $choice ) ? 0 : GFCommon::to_number( rgar( $choice, 'price' ) ); 
  2008. $field_value .= '|' . $price; 
  2009.  
  2010. if ( ! isset( $_GET['gf_token'] ) && empty( $_POST ) && rgblank( $value ) && RG_CURRENT_VIEW != 'entry' ) { 
  2011. $selected = rgar( $choice, 'isSelected' ) ? "selected='selected'" : ''; 
  2012. } else { 
  2013. if ( is_array( $value ) ) { 
  2014. $is_match = false; 
  2015. foreach ( $value as $item ) { 
  2016. if ( RGFormsModel::choice_value_match( $field, $choice, $item ) ) { 
  2017. $is_match = true; 
  2018. break; 
  2019. $selected = $is_match ? "selected='selected'" : ''; 
  2020. } else { 
  2021. $selected = RGFormsModel::choice_value_match( $field, $choice, $value ) ? "selected='selected'" : ''; 
  2022.  
  2023. $choice_markup = sprintf( "<option value='%s' %s>%s</option>", esc_attr( $field_value ), $selected, esc_html( $choice['text'] ) ); 
  2024.  
  2025. $choices .= gf_apply_filters( array( 'gform_field_choice_markup_pre_render', $field->formId, $field->id ), $choice_markup, $choice, $field, $value ); 
  2026.  
  2027.  
  2028. return $choices; 
  2029.  
  2030. public static function is_section_empty( $section_field, $form, $entry ) { 
  2031.  
  2032. $cache_key = "GFCommon::is_section_empty_{$form['id']}_{$section_field['id']}"; 
  2033. $value = GFCache::get( $cache_key ); 
  2034.  
  2035. if ( $value !== false ) { 
  2036. return $value == true; 
  2037.  
  2038. $fields = self::get_section_fields( $form, $section_field['id'] ); 
  2039. if ( ! is_array( $fields ) ) { 
  2040. GFCache::set( $cache_key, 1 ); 
  2041.  
  2042. return true; 
  2043.  
  2044. foreach ( $fields as $field ) { 
  2045.  
  2046. $value = GFFormsModel::get_lead_field_value( $entry, $field ); 
  2047. $value = GFCommon::get_lead_field_display( $field, $value, rgar( $entry, 'currency' ) ); 
  2048.  
  2049. if ( rgblank( $value ) ) { 
  2050. continue; 
  2051.  
  2052. // most fields are displayed in the section by default, exceptions are handled below 
  2053. $is_field_displayed_in_section = true; 
  2054.  
  2055. // by default, product fields are not displayed in their containing section (displayed in a product summary table) 
  2056. // if the filter is used to disable this, product fields are displayed in the section like other fields 
  2057. if ( self::is_product_field( $field['type'] ) ) { 
  2058.  
  2059. /** 
  2060. * By default, product fields are not displayed in their containing section (displayed in a product summary table). If the filter is used to disable this, product fields are displayed in the section like other fields 
  2061. * @param array $field The Form Fields Object 
  2062. * @param array $form The Form Object 
  2063. * @param array $entry The Entry object 
  2064. */ 
  2065. $display_product_summary = apply_filters( 'gform_display_product_summary', true, $field, $form, $entry ); 
  2066.  
  2067. $is_field_displayed_in_section = ! $display_product_summary; 
  2068.  
  2069. if ( $is_field_displayed_in_section ) { 
  2070. GFCache::set( $cache_key, 0 ); 
  2071.  
  2072. return false; 
  2073.  
  2074. GFCache::set( $cache_key, 1 ); 
  2075.  
  2076. return true; 
  2077.  
  2078. public static function get_section_fields( $form, $section_field_id ) { 
  2079. $fields = array(); 
  2080. $in_section = false; 
  2081. foreach ( $form['fields'] as $field ) { 
  2082. if ( in_array( $field->type, array( 'section', 'page' ) ) && $in_section ) { 
  2083. return $fields; 
  2084.  
  2085. if ( $field->id == $section_field_id ) { 
  2086. $in_section = true; 
  2087.  
  2088. if ( $in_section ) { 
  2089. $fields[] = $field; 
  2090.  
  2091. return $fields; 
  2092.  
  2093. public static function get_us_state_code( $state_name ) { 
  2094. return GF_Fields::get( 'address' )->get_us_state_code( $state_name ); 
  2095.  
  2096. public static function get_country_code( $country_name ) { 
  2097. return GF_Fields::get( 'address' )->get_country_code( $country_name ); 
  2098.  
  2099. public static function get_us_states() { 
  2100. return GF_Fields::get( 'address' )->get_us_states(); 
  2101.  
  2102. public static function get_canadian_provinces() { 
  2103. return GF_Fields::get( 'address' )->get_canadian_provinces(); 
  2104.  
  2105. public static function is_post_field( $field ) { 
  2106. return in_array( $field->type, array( 'post_title', 'post_tags', 'post_category', 'post_custom_field', 'post_content', 'post_excerpt', 'post_image' ) ); 
  2107.  
  2108. public static function get_fields_by_type( $form, $types ) { 
  2109. return GFAPI::get_fields_by_type( $form, $types ); 
  2110.  
  2111. public static function has_pages( $form ) { 
  2112. return sizeof( GFAPI::get_fields_by_type( $form, array( 'page' ) ) ) > 0; 
  2113.  
  2114. public static function get_product_fields_by_type( $form, $types, $product_id ) { 
  2115. global $_product_fields; 
  2116. $key = json_encode( $types ) . '_' . $product_id . '_' . $form['id']; 
  2117. if ( ! isset( $_product_fields[ $key ] ) ) { 
  2118. $fields = array(); 
  2119. for ( $i = 0, $count = sizeof( $form['fields'] ); $i < $count; $i ++ ) { 
  2120. $field = $form['fields'][ $i ]; 
  2121. if ( in_array( $field->type, $types ) && $field->productField == $product_id ) { 
  2122. $fields[] = $field; 
  2123. $_product_fields[ $key ] = $fields; 
  2124.  
  2125. return $_product_fields[ $key ]; 
  2126.  
  2127. /** 
  2128. * @deprecated 
  2129. * @param GF_Field $field 
  2130. * @return mixed 
  2131. */ 
  2132. public static function has_field_calculation( $field ) { 
  2133. _deprecated_function( 'has_field_calculation', '1.7', 'GF_Field::has_calculation' ); 
  2134.  
  2135. return $field->has_calculation(); 
  2136.  
  2137. /** 
  2138. * @param GF_Field $field 
  2139. * @param string $value 
  2140. * @param int $lead_id 
  2141. * @param int $form_id 
  2142. * @param null $form 
  2143. * @return mixed|string|void 
  2144. */ 
  2145. public static function get_field_input( $field, $value = '', $lead_id = 0, $form_id = 0, $form = null ) { 
  2146.  
  2147. if ( ! $field instanceof GF_Field ) { 
  2148. $field = GF_Fields::create( $field ); 
  2149.  
  2150. $is_form_editor = GFCommon::is_form_editor(); 
  2151. $is_entry_detail = GFCommon::is_entry_detail(); 
  2152. $is_admin = $is_form_editor || $is_entry_detail; 
  2153.  
  2154. $id = intval( $field->id ); 
  2155. $field_id = $is_admin || $form_id == 0 ? "input_$id" : 'input_' . $form_id . "_$id"; 
  2156. $form_id = $is_admin && empty( $form_id ) ? rgget( 'id' ) : $form_id; 
  2157.  
  2158. if ( RG_CURRENT_VIEW == 'entry' ) { 
  2159. $lead = RGFormsModel::get_lead( $lead_id ); 
  2160. $post_id = $lead['post_id']; 
  2161. $post_link = ''; 
  2162. if ( is_numeric( $post_id ) && self::is_post_field( $field ) ) { 
  2163. $post_link = "<div>You can <a href='post.php?action=edit&post=$post_id'>edit this post</a> from the post page.</div>"; 
  2164.  
  2165. $field_input = apply_filters( 'gform_field_input', '', $field, $value, $lead_id, $form_id ); 
  2166. if ( $field_input ) { 
  2167. return $field_input; 
  2168.  
  2169. //product fields are not editable 
  2170. if ( RG_CURRENT_VIEW == 'entry' && self::is_product_field( $field->type ) ) { 
  2171. return "<div class='ginput_container'>" . esc_html__( 'Product fields are not editable' , 'gravityforms' ) . '</div>'; 
  2172. } else if ( RG_CURRENT_VIEW == 'entry' && $field->type == 'donation' ) { 
  2173. return "<div class='ginput_container'>" . esc_html__( 'Donations are not editable' , 'gravityforms' ) . '</div>'; 
  2174.  
  2175. // add categories as choices for Post Category field 
  2176. if ( $field->type == 'post_category' ) { 
  2177. $field = self::add_categories_as_choices( $field, $value ); 
  2178.  
  2179. $type = RGFormsModel::get_input_type( $field ); 
  2180. switch ( $type ) { 
  2181.  
  2182. case 'honeypot': 
  2183. $autocomplete = RGFormsModel::is_html5_enabled() ? "autocomplete='off'" : ''; 
  2184.  
  2185. return "<div class='ginput_container'><input name='input_{$id}' id='{$field_id}' type='text' value='' {$autocomplete}/></div>"; 
  2186. break; 
  2187.  
  2188. case 'adminonly_hidden' : 
  2189. if ( ! is_array( $field->inputs ) ) { 
  2190. if ( is_array( $value ) ) { 
  2191. $value = json_encode( $value ); 
  2192.  
  2193. return sprintf( "<input name='input_%d' id='%s' class='gform_hidden' type='hidden' value='%s'/>", $id, esc_attr( $field_id ), esc_attr( $value ) ); 
  2194.  
  2195.  
  2196. $fields = ''; 
  2197. foreach ( $field->inputs as $input ) { 
  2198. $fields .= sprintf( "<input name='input_%s' class='gform_hidden' type='hidden' value='%s'/>", $input['id'], esc_attr( rgar( $value, strval( $input['id'] ) ) ) ); 
  2199.  
  2200. return $fields; 
  2201. break; 
  2202.  
  2203. default : 
  2204.  
  2205. if ( ! empty( $post_link ) ) { 
  2206. return $post_link; 
  2207.  
  2208. if ( ! isset( $lead ) ) { 
  2209. $lead = null; 
  2210.  
  2211. return $field->get_field_input( $form, $value, $lead ); 
  2212.  
  2213. break; 
  2214.  
  2215.  
  2216. public static function is_ssl() { 
  2217. global $wordpress_https; 
  2218. $is_ssl = false; 
  2219.  
  2220. $has_https_plugin = class_exists( 'WordPressHTTPS' ) && isset( $wordpress_https ); 
  2221. $has_is_ssl_method = $has_https_plugin && method_exists( 'WordPressHTTPS', 'is_ssl' ); 
  2222. $has_isSsl_method = $has_https_plugin && method_exists( 'WordPressHTTPS', 'isSsl' ); 
  2223.  
  2224. //Use the WordPress HTTPs plugin if installed 
  2225. if ( $has_https_plugin && $has_is_ssl_method ) { 
  2226. $is_ssl = $wordpress_https->is_ssl(); 
  2227. } else if ( $has_https_plugin && $has_isSsl_method ) { 
  2228. $is_ssl = $wordpress_https->isSsl(); 
  2229. } else { 
  2230. $is_ssl = is_ssl(); 
  2231.  
  2232.  
  2233. if ( ! $is_ssl && isset( $_SERVER['HTTP_CF_VISITOR'] ) && strpos( $_SERVER['HTTP_CF_VISITOR'], 'https' ) ) { 
  2234. $is_ssl = true; 
  2235.  
  2236. return apply_filters( 'gform_is_ssl', $is_ssl ); 
  2237.  
  2238. public static function is_preview() { 
  2239. $url_info = parse_url( RGFormsModel::get_current_page_url() ); 
  2240. $file_name = basename( $url_info['path'] ); 
  2241.  
  2242. return $file_name == 'preview.php' || rgget( 'gf_page', $_GET ) == 'preview'; 
  2243.  
  2244. public static function clean_extensions( $extensions ) { 
  2245. $count = sizeof( $extensions ); 
  2246. for ( $i = 0; $i < $count; $i ++ ) { 
  2247. $extensions[ $i ] = str_replace( '.', '', str_replace( ' ', '', $extensions[ $i ] ) ); 
  2248.  
  2249. return $extensions; 
  2250.  
  2251. public static function get_disallowed_file_extensions() { 
  2252.  
  2253. $extensions = array( 'php', 'asp', 'aspx', 'cmd', 'csh', 'bat', 'html', 'hta', 'jar', 'exe', 'com', 'js', 'lnk', 'htaccess', 'phtml', 'ps1', 'ps2', 'php3', 'php4', 'php5', 'php6', 'py', 'rb', 'tmp' ); 
  2254.  
  2255. // Intended for internal use - not to be included in the documentation. 
  2256. $extensions = apply_filters( 'gform_disallowed_file_extensions', $extensions ); 
  2257.  
  2258. return $extensions; 
  2259.  
  2260. public static function match_file_extension( $file_name, $extensions ) { 
  2261. if ( empty ( $extensions ) || ! is_array( $extensions ) ) { 
  2262. return false; 
  2263.  
  2264. $ext = strtolower( pathinfo( $file_name, PATHINFO_EXTENSION ) ); 
  2265. if ( in_array( $ext, $extensions ) ) { 
  2266. return true; 
  2267.  
  2268. return false; 
  2269.  
  2270. public static function file_name_has_disallowed_extension( $file_name ) { 
  2271.  
  2272. return self::match_file_extension( $file_name, self::get_disallowed_file_extensions() ) || strpos( strtolower( $file_name ), '.php.' ) !== false; 
  2273.  
  2274. public static function check_type_and_ext( $file, $file_name = '') { 
  2275. if ( empty( $file_name ) ) { 
  2276. $file_name = $file['name']; 
  2277. $tmp_name = $file['tmp_name']; 
  2278. // Whitelist the mime type and extension 
  2279. $wp_filetype = wp_check_filetype_and_ext( $tmp_name, $file_name ); 
  2280. $ext = empty( $wp_filetype['ext'] ) ? '' : $wp_filetype['ext']; 
  2281. $type = empty( $wp_filetype['type'] ) ? '' : $wp_filetype['type']; 
  2282. $proper_filename = empty( $wp_filetype['proper_filename'] ) ? '' : $wp_filetype['proper_filename']; 
  2283.  
  2284. if ( $proper_filename ) { 
  2285. return new WP_Error( 'invalid_file', esc_html__( 'There was an problem while verifying your file.' ) ); 
  2286. if ( ! $ext ) { 
  2287. return new WP_Error( 'illegal_extension', esc_html__( 'Sorry, this file extension is not permitted for security reasons.' ) ); 
  2288. if ( ! $type ) { 
  2289. return new WP_Error( 'illegal_type', esc_html__( 'Sorry, this file type is not permitted for security reasons.' ) ); 
  2290.  
  2291. return true; 
  2292.  
  2293. public static function to_money( $number, $currency_code = '' ) { 
  2294. if ( ! class_exists( 'RGCurrency' ) ) { 
  2295. require_once( 'currency.php' ); 
  2296.  
  2297. if ( empty( $currency_code ) ) { 
  2298. $currency_code = self::get_currency(); 
  2299.  
  2300. $currency = new RGCurrency( $currency_code ); 
  2301.  
  2302. return $currency->to_money( $number ); 
  2303.  
  2304. public static function to_number( $text, $currency_code = '' ) { 
  2305. if ( ! class_exists( 'RGCurrency' ) ) { 
  2306. require_once( 'currency.php' ); 
  2307.  
  2308.  
  2309. if ( empty( $currency_code ) ) { 
  2310. $currency_code = self::get_currency(); 
  2311.  
  2312.  
  2313. $currency = new RGCurrency( $currency_code ); 
  2314.  
  2315. return $currency->to_number( $text ); 
  2316.  
  2317. public static function get_currency() { 
  2318. $currency = get_option( 'rg_gforms_currency' ); 
  2319. $currency = empty( $currency ) ? 'USD' : $currency; 
  2320.  
  2321. return apply_filters( 'gform_currency', $currency ); 
  2322.  
  2323. public static function get_simple_captcha() { 
  2324. _deprecated_function( 'GFCommon::get_simple_captcha', '1.9', 'GFField_CAPTCHA::get_simple_captcha' ); 
  2325. $captcha = new ReallySimpleCaptcha(); 
  2326. $captcha->tmp_dir = RGFormsModel::get_upload_path( 'captcha' ) . '/'; 
  2327.  
  2328. return $captcha; 
  2329.  
  2330. /** 
  2331. * @deprecated 
  2332. * @param GF_Field_CAPTCH $field 
  2333. * @return mixed 
  2334. */ 
  2335. public static function get_captcha( $field ) { 
  2336. _deprecated_function( 'GFCommon::get_captcha', '1.9', 'GFField_CAPTCHA::get_captcha' ); 
  2337.  
  2338. return $field->get_captcha(); 
  2339.  
  2340. /** 
  2341. * @deprecated 
  2342. * @param $field 
  2343. * @param $pos 
  2344. * @return mixed 
  2345. */ 
  2346. public static function get_math_captcha( $field, $pos ) { 
  2347. _deprecated_function( 'GFCommon::get_math_captcha', '1.9', 'GFField_CAPTCHA::get_math_captcha' ); 
  2348.  
  2349. return $field->get_math_captcha( $pos ); 
  2350.  
  2351. /** 
  2352. * @param GF_Field $field 
  2353. * @param $value 
  2354. * @param string $currency 
  2355. * @param bool $use_text 
  2356. * @param string $format 
  2357. * @param string $media 
  2358. * @return array|mixed|string 
  2359. */ 
  2360. public static function get_lead_field_display( $field, $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) { 
  2361.  
  2362. if ( ! $field instanceof GF_Field ) { 
  2363. $field = GF_Fields::create( $field ); 
  2364.  
  2365. if ( $field->type == 'post_category' ) { 
  2366. $value = self::prepare_post_category_value( $value, $field ); 
  2367.  
  2368. return $field->get_value_entry_detail( $value, $currency, $use_text, $format, $media ); 
  2369.  
  2370. public static function get_product_fields( $form, $lead, $use_choice_text = false, $use_admin_label = false ) { 
  2371. $products = array(); 
  2372.  
  2373. $product_info = null; 
  2374. // retrieve static copy of product info (only for 'real' entries) 
  2375. if ( ! rgempty( 'id', $lead ) ) { 
  2376. $product_info = gform_get_meta( rgar( $lead, 'id' ), "gform_product_info_{$use_choice_text}_{$use_admin_label}" ); 
  2377.  
  2378. // if no static copy, generate from form/lead info 
  2379. if ( ! $product_info ) { 
  2380.  
  2381. foreach ( $form['fields'] as $field ) { 
  2382. $id = $field->id; 
  2383. $lead_value = RGFormsModel::get_lead_field_value( $lead, $field ); 
  2384.  
  2385. $quantity_field = self::get_product_fields_by_type( $form, array( 'quantity' ), $id ); 
  2386. $quantity = sizeof( $quantity_field ) > 0 && ! RGFormsModel::is_field_hidden( $form, $quantity_field[0], array(), $lead ) ? RGFormsModel::get_lead_field_value( $lead, $quantity_field[0] ) : 1; 
  2387.  
  2388. switch ( $field->type ) { 
  2389.  
  2390. case 'product' : 
  2391.  
  2392. //ignore products that have been hidden by conditional logic 
  2393. $is_hidden = RGFormsModel::is_field_hidden( $form, $field, array(), $lead ); 
  2394. if ( $is_hidden ) { 
  2395. continue; 
  2396.  
  2397. //if single product, get values from the multiple inputs 
  2398. if ( is_array( $lead_value ) ) { 
  2399. $product_quantity = sizeof( $quantity_field ) == 0 && ! $field->disableQuantity ? rgget( $id . '.3', $lead_value ) : $quantity; 
  2400. if ( empty( $product_quantity ) ) { 
  2401. continue; 
  2402.  
  2403. if ( ! rgget( $id, $products ) ) { 
  2404. $products[ $id ] = array(); 
  2405.  
  2406. $products[ $id ]['name'] = $use_admin_label && ! rgempty( 'adminLabel', $field ) ? $field->adminLabel : $lead_value[ $id . '.1' ]; 
  2407. $products[ $id ]['price'] = rgar( $lead_value, $id . '.2' ); 
  2408. $products[ $id ]['quantity'] = $product_quantity; 
  2409. } elseif ( ! empty( $lead_value ) ) { 
  2410.  
  2411. if ( empty( $quantity ) ) { 
  2412. continue; 
  2413.  
  2414. if ( ! rgar( $products, $id ) ) { 
  2415. $products[ $id ] = array(); 
  2416.  
  2417. if ( $field->inputType == 'price' ) { 
  2418. $name = $field->label; 
  2419. $price = $lead_value; 
  2420. } else { 
  2421. list( $name, $price ) = explode( '|', $lead_value ); 
  2422.  
  2423. $products[ $id ]['name'] = ! $use_choice_text ? $name : RGFormsModel::get_choice_text( $field, $name ); 
  2424. $include_field_label = apply_filters( 'gform_product_info_name_include_field_label', false ); 
  2425. if ( $field->inputType == ( 'radio' || 'select' ) && $include_field_label ) { 
  2426. $products[ $id ]['name'] = $field->label . " ({$products[$id]['name']})"; 
  2427.  
  2428. $products[ $id ]['price'] = $price; 
  2429. $products[ $id ]['quantity'] = $quantity; 
  2430. $products[ $id ]['options'] = array(); 
  2431.  
  2432. if ( isset( $products[ $id ] ) ) { 
  2433. $options = self::get_product_fields_by_type( $form, array( 'option' ), $id ); 
  2434. foreach ( $options as $option ) { 
  2435. $option_value = RGFormsModel::get_lead_field_value( $lead, $option ); 
  2436. $option_label = empty( $option['adminLabel'] ) ? $option['label'] : $option['adminLabel']; 
  2437. if ( is_array( $option_value ) ) { 
  2438. foreach ( $option_value as $value ) { 
  2439. $option_info = self::get_option_info( $value, $option, $use_choice_text ); 
  2440. if ( ! empty( $option_info ) ) { 
  2441. $products[ $id ]['options'][] = array( 'field_label' => rgar( $option, 'label' ),  
  2442. 'option_name' => rgar( $option_info, 'name' ),  
  2443. 'option_label' => $option_label . ': ' . rgar( $option_info, 'name' ),  
  2444. 'price' => rgar( $option_info, 'price' ) 
  2445. ); 
  2446. } elseif ( ! empty( $option_value ) ) { 
  2447. $option_info = self::get_option_info( $option_value, $option, $use_choice_text ); 
  2448. $products[ $id ]['options'][] = array( 'field_label' => rgar( $option, 'label' ),  
  2449. 'option_name' => rgar( $option_info, 'name' ),  
  2450. 'option_label' => $option_label . ': ' . rgar( $option_info, 'name' ),  
  2451. 'price' => rgar( $option_info, 'price' ) 
  2452. ); 
  2453. break; 
  2454.  
  2455. $shipping_field = GFAPI::get_fields_by_type( $form, array( 'shipping' ) ); 
  2456. $shipping_price = $shipping_name = ''; 
  2457. $shipping_field_id = ''; 
  2458. if ( ! empty( $shipping_field ) && ! RGFormsModel::is_field_hidden( $form, $shipping_field[0], array(), $lead ) ) { 
  2459. $shipping_price = RGFormsModel::get_lead_field_value( $lead, $shipping_field[0] ); 
  2460. $shipping_name = $shipping_field[0]['label']; 
  2461. $shipping_field_id = $shipping_field[0]['id']; 
  2462. if ( $shipping_field[0]['inputType'] != 'singleshipping' && ! empty( $shipping_price ) ) { 
  2463. list( $shipping_method, $shipping_price ) = explode( '|', $shipping_price ); 
  2464. $shipping_name = $shipping_field[0]['label'] . " ($shipping_method)"; 
  2465. $shipping_price = self::to_number( $shipping_price ); 
  2466.  
  2467. $product_info = array( 'products' => $products, 'shipping' => array( 'id' => $shipping_field_id, 'name' => $shipping_name, 'price' => $shipping_price ) ); 
  2468.  
  2469. $product_info = gf_apply_filters( array( 'gform_product_info', $form['id'] ), $product_info, $form, $lead ); 
  2470.  
  2471. // save static copy of product info (only for 'real' entries) 
  2472. if ( ! rgempty( 'id', $lead ) && ! empty( $product_info['products'] ) ) { 
  2473. gform_update_meta( $lead['id'], "gform_product_info_{$use_choice_text}_{$use_admin_label}", $product_info ); 
  2474.  
  2475. return $product_info; 
  2476.  
  2477. public static function get_order_total( $form, $lead ) { 
  2478.  
  2479. $products = self::get_product_fields( $form, $lead, false ); 
  2480.  
  2481. return self::get_total( $products ); 
  2482.  
  2483. public static function get_total( $products ) { 
  2484.  
  2485. $total = 0; 
  2486. foreach ( $products['products'] as $product ) { 
  2487.  
  2488. $price = self::to_number( $product['price'] ); 
  2489. if ( is_array( rgar( $product, 'options' ) ) ) { 
  2490. foreach ( $product['options'] as $option ) { 
  2491. $price += self::to_number( $option['price'] ); 
  2492. $subtotal = floatval( $product['quantity'] ) * $price; 
  2493. $total += $subtotal; 
  2494.  
  2495.  
  2496. $total += floatval( $products['shipping']['price'] ); 
  2497.  
  2498. return $total; 
  2499.  
  2500. public static function get_option_info( $value, $option, $use_choice_text ) { 
  2501. if ( empty( $value ) ) { 
  2502. return array(); 
  2503.  
  2504. list( $name, $price ) = explode( '|', $value ); 
  2505. if ( $use_choice_text ) { 
  2506. $name = RGFormsModel::get_choice_text( $option, $name ); 
  2507.  
  2508. return array( 'name' => $name, 'price' => $price ); 
  2509.  
  2510. public static function gform_do_shortcode( $content ) { 
  2511.  
  2512. $is_ajax = false; 
  2513. $forms = GFFormDisplay::get_embedded_forms( $content, $is_ajax ); 
  2514.  
  2515. foreach ( $forms as $form ) { 
  2516. if ( headers_sent() ) { 
  2517. GFFormDisplay::print_form_scripts( $form, $is_ajax ); 
  2518. } else { 
  2519. GFFormDisplay::enqueue_form_scripts( $form, $is_ajax ); 
  2520.  
  2521. return do_shortcode( $content ); 
  2522.  
  2523. public static function spam_enabled( $form_id ) { 
  2524. $spam_enabled = self::akismet_enabled( $form_id ) || has_filter( 'gform_entry_is_spam' ) || has_filter( "gform_entry_is_spam_{$form_id}" ); 
  2525.  
  2526. return $spam_enabled; 
  2527.  
  2528. public static function has_akismet() { 
  2529. $akismet_exists = function_exists( 'akismet_http_post' ) || function_exists( 'Akismet::http_post' ); 
  2530.  
  2531. return $akismet_exists; 
  2532.  
  2533. public static function akismet_enabled( $form_id ) { 
  2534.  
  2535. if ( ! self::has_akismet() ) { 
  2536. return false; 
  2537.  
  2538. // if no option is set, leave akismet enabled; otherwise, use option value true/false 
  2539. $enabled_by_setting = get_option( 'rg_gforms_enable_akismet' ) === false ? true : get_option( 'rg_gforms_enable_akismet' ) == true; 
  2540. $enabled_by_filter = gf_apply_filters( array( 'gform_akismet_enabled', $form_id ), $enabled_by_setting ); 
  2541.  
  2542. return $enabled_by_filter; 
  2543.  
  2544.  
  2545. public static function is_akismet_spam( $form, $lead ) { 
  2546.  
  2547. global $akismet_api_host, $akismet_api_port; 
  2548.  
  2549. $fields = self::get_akismet_fields( $form, $lead ); 
  2550.  
  2551. //Submitting info to Akismet 
  2552. if ( defined( 'AKISMET_VERSION' ) && AKISMET_VERSION < 3.0 ) { 
  2553. //Akismet versions before 3.0 
  2554. $response = akismet_http_post( $fields, $akismet_api_host, '/1.1/comment-check', $akismet_api_port ); 
  2555. } else { 
  2556. $response = Akismet::http_post( $fields, 'comment-check' ); 
  2557. $is_spam = trim( rgar( $response, 1 ) ) == 'true'; 
  2558.  
  2559. return $is_spam; 
  2560.  
  2561. public static function mark_akismet_spam( $form, $lead, $is_spam ) { 
  2562.  
  2563. global $akismet_api_host, $akismet_api_port; 
  2564.  
  2565. $fields = self::get_akismet_fields( $form, $lead ); 
  2566. $as = $is_spam ? 'spam' : 'ham'; 
  2567.  
  2568. //Submitting info to Akismet 
  2569. if ( defined( 'AKISMET_VERSION' ) && AKISMET_VERSION < 3.0 ) { 
  2570. //Akismet versions before 3.0 
  2571. akismet_http_post( $fields, $akismet_api_host, '/1.1/submit-' . $as, $akismet_api_port ); 
  2572. } else { 
  2573. Akismet::http_post( $fields, 'submit-' . $as ); 
  2574.  
  2575. private static function get_akismet_fields( $form, $lead ) { 
  2576.  
  2577. $is_form_editor = GFCommon::is_form_editor(); 
  2578. $is_entry_detail = GFCommon::is_entry_detail(); 
  2579. $is_admin = $is_form_editor || $is_entry_detail; 
  2580.  
  2581. //Gathering Akismet information 
  2582. $akismet_info = array(); 
  2583. $akismet_info['comment_type'] = 'gravity_form'; 
  2584. $akismet_info['comment_author'] = self::get_akismet_field( 'name', $form, $lead ); 
  2585. $akismet_info['comment_author_email'] = self::get_akismet_field( 'email', $form, $lead ); 
  2586. $akismet_info['comment_author_url'] = self::get_akismet_field( 'website', $form, $lead ); 
  2587. $akismet_info['comment_content'] = self::get_akismet_field( 'textarea', $form, $lead ); 
  2588. $akismet_info['contact_form_subject'] = $form['title']; 
  2589. $akismet_info['comment_author_IP'] = $lead['ip']; 
  2590. $akismet_info['permalink'] = $lead['source_url']; 
  2591. $akismet_info['user_ip'] = preg_replace( '/[^0-9., ]/', '', $lead['ip'] ); 
  2592. $akismet_info['user_agent'] = $lead['user_agent']; 
  2593. $akismet_info['referrer'] = $is_admin ? '' : $_SERVER['HTTP_REFERER']; 
  2594. $akismet_info['blog'] = get_option( 'home' ); 
  2595.  
  2596. $akismet_info = gf_apply_filters( array( 'gform_akismet_fields', $form['id'] ), $akismet_info, $form, $lead ); 
  2597.  
  2598. return http_build_query( $akismet_info ); 
  2599.  
  2600. private static function get_akismet_field( $field_type, $form, $lead ) { 
  2601. $fields = GFAPI::get_fields_by_type( $form, array( $field_type ) ); 
  2602. if ( empty( $fields ) ) { 
  2603. return ''; 
  2604.  
  2605. $value = RGFormsModel::get_lead_field_value( $lead, $fields[0] ); 
  2606. switch ( $field_type ) { 
  2607. case 'name' : 
  2608. $value = GFCommon::get_lead_field_display( $fields[0], $value ); 
  2609. break; 
  2610.  
  2611. return $value; 
  2612.  
  2613. public static function get_other_choice_value() { 
  2614. $value = apply_filters( 'gform_other_choice_value', esc_html__( 'Other' , 'gravityforms' ) ); 
  2615.  
  2616. return $value; 
  2617.  
  2618. public static function get_browser_class() { 
  2619. global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone, $post; 
  2620.  
  2621. $classes = array(); 
  2622.  
  2623. //adding browser related class 
  2624. if ( $is_lynx ) { 
  2625. $classes[] = 'gf_browser_lynx'; 
  2626. } else if ( $is_gecko ) { 
  2627. $classes[] = 'gf_browser_gecko'; 
  2628. } else if ( $is_opera ) { 
  2629. $classes[] = 'gf_browser_opera'; 
  2630. } else if ( $is_NS4 ) { 
  2631. $classes[] = 'gf_browser_ns4'; 
  2632. } else if ( $is_safari ) { 
  2633. $classes[] = 'gf_browser_safari'; 
  2634. } else if ( $is_chrome ) { 
  2635. $classes[] = 'gf_browser_chrome'; 
  2636. } else if ( $is_IE ) { 
  2637. $classes[] = 'gf_browser_ie'; 
  2638. } else { 
  2639. $classes[] = 'gf_browser_unknown'; 
  2640.  
  2641.  
  2642. //adding IE version 
  2643. if ( $is_IE ) { 
  2644. if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 6' ) !== false ) { 
  2645. $classes[] = 'gf_browser_ie6'; 
  2646. } else if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 7' ) !== false ) { 
  2647. $classes[] = 'gf_browser_ie7'; 
  2648. if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) !== false ) { 
  2649. $classes[] = 'gf_browser_ie8'; 
  2650. if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 9' ) !== false ) { 
  2651. $classes[] = 'gf_browser_ie9'; 
  2652.  
  2653. if ( $is_iphone ) { 
  2654. $classes[] = 'gf_browser_iphone'; 
  2655.  
  2656. return implode( ' ', $classes ); 
  2657.  
  2658. public static function create_post( $form, &$lead ) { 
  2659. $disable_post = gf_apply_filters( array( 'gform_disable_post_creation', $form['id'] ), false, $form, $lead ); 
  2660. $post_id = 0; 
  2661. if ( ! $disable_post ) { 
  2662. //creates post if the form has any post fields 
  2663. $post_id = RGFormsModel::create_post( $form, $lead ); 
  2664.  
  2665. return $post_id; 
  2666.  
  2667. public static function evaluate_conditional_logic( $logic, $form, $lead ) { 
  2668.  
  2669. if ( ! $logic || ! is_array( rgar( $logic, 'rules' ) ) ) { 
  2670. return true; 
  2671.  
  2672. $entry_meta_keys = array_keys( GFFormsModel::get_entry_meta( $form['id'] ) ); 
  2673. $match_count = 0; 
  2674. if ( is_array( $logic['rules'] ) ) { 
  2675. foreach ( $logic['rules'] as $rule ) { 
  2676.  
  2677. if ( in_array( $rule['fieldId'], $entry_meta_keys ) ) { 
  2678. $is_value_match = GFFormsModel::is_value_match( rgar( $lead, $rule['fieldId'] ), $rule['value'], $rule['operator'], $rule, $form ); 
  2679. } else { 
  2680. $source_field = GFFormsModel::get_field( $form, $rule['fieldId'] ); 
  2681. $field_value = empty( $lead ) ? GFFormsModel::get_field_value( $source_field, array() ) : GFFormsModel::get_lead_field_value( $lead, $source_field ); 
  2682. $is_value_match = GFFormsModel::is_value_match( $field_value, $rule['value'], $rule['operator'], $source_field, $rule, $form ); 
  2683.  
  2684. if ( $is_value_match ) { 
  2685. $match_count ++; 
  2686.  
  2687. $do_action = ( $logic['logicType'] == 'all' && $match_count == sizeof( $logic['rules'] ) ) || ( $logic['logicType'] == 'any' && $match_count > 0 ); 
  2688.  
  2689. return $do_action; 
  2690.  
  2691. public static function get_card_types() { 
  2692. $cards = array( 
  2693.  
  2694. array( 
  2695. 'name' => 'American Express',  
  2696. 'slug' => 'amex',  
  2697. 'lengths' => '15',  
  2698. 'prefixes' => '34, 37',  
  2699. 'checksum' => true,  
  2700. ),  
  2701. array( 
  2702. 'name' => 'Discover',  
  2703. 'slug' => 'discover',  
  2704. 'lengths' => '16',  
  2705. 'prefixes' => '6011, 622, 64, 65',  
  2706. 'checksum' => true,  
  2707. ),  
  2708. array( 
  2709. 'name' => 'MasterCard',  
  2710. 'slug' => 'mastercard',  
  2711. 'lengths' => '16',  
  2712. 'prefixes' => '51, 52, 53, 54, 55',  
  2713. 'checksum' => true,  
  2714. ),  
  2715. array( 
  2716. 'name' => 'Visa',  
  2717. 'slug' => 'visa',  
  2718. 'lengths' => '13, 16',  
  2719. 'prefixes' => '4, 417500, 4917, 4913, 4508, 4844',  
  2720. 'checksum' => true,  
  2721. ),  
  2722. array( 
  2723. 'name' => 'JCB',  
  2724. 'slug' => 'jcb',  
  2725. 'lengths' => '16',  
  2726. 'prefixes' => '35',  
  2727. 'checksum' => true,  
  2728. ),  
  2729. array( 
  2730. 'name' => 'Maestro',  
  2731. 'slug' => 'maestro',  
  2732. 'lengths' => '12, 13, 14, 15, 16, 18, 19',  
  2733. 'prefixes' => '5018, 5020, 5038, 6304, 6759, 6761',  
  2734. 'checksum' => true,  
  2735. ),  
  2736. ); 
  2737.  
  2738. $cards = apply_filters( 'gform_creditcard_types', $cards ); 
  2739.  
  2740. return $cards; 
  2741.  
  2742. public static function get_card_type( $number ) { 
  2743.  
  2744. //removing spaces from number 
  2745. $number = str_replace( ' ', '', $number ); 
  2746.  
  2747. if ( empty( $number ) ) { 
  2748. return false; 
  2749.  
  2750. $cards = self::get_card_types(); 
  2751.  
  2752. $matched_card = false; 
  2753. foreach ( $cards as $card ) { 
  2754. if ( self::matches_card_type( $number, $card ) ) { 
  2755. $matched_card = $card; 
  2756. break; 
  2757.  
  2758. if ( $matched_card && $matched_card['checksum'] && ! self::is_valid_card_checksum( $number ) ) { 
  2759. $matched_card = false; 
  2760.  
  2761. return $matched_card ? $matched_card : false; 
  2762.  
  2763.  
  2764. private static function matches_card_type( $number, $card ) { 
  2765.  
  2766. //checking prefix 
  2767. $prefixes = explode( ', ', $card['prefixes'] ); 
  2768. $matches_prefix = false; 
  2769. foreach ( $prefixes as $prefix ) { 
  2770. if ( preg_match( "|^{$prefix}|", $number ) ) { 
  2771. $matches_prefix = true; 
  2772. break; 
  2773.  
  2774. //checking length 
  2775. $lengths = explode( ', ', $card['lengths'] ); 
  2776. $matches_length = false; 
  2777. foreach ( $lengths as $length ) { 
  2778. if ( strlen( $number ) == absint( $length ) ) { 
  2779. $matches_length = true; 
  2780. break; 
  2781.  
  2782. return $matches_prefix && $matches_length; 
  2783.  
  2784.  
  2785. private static function is_valid_card_checksum( $number ) { 
  2786. $checksum = 0; 
  2787. $num = 0; 
  2788. $multiplier = 1; 
  2789.  
  2790. // Process each character starting at the right 
  2791. for ( $i = strlen( $number ) - 1; $i >= 0; $i -- ) { 
  2792.  
  2793. //Multiply current digit by multiplier (1 or 2) 
  2794. $num = $number{$i} * $multiplier; 
  2795.  
  2796. // If the result is in greater than 9, add 1 to the checksum total 
  2797. if ( $num >= 10 ) { 
  2798. $checksum ++; 
  2799. $num -= 10; 
  2800.  
  2801. //Update checksum 
  2802. $checksum += $num; 
  2803.  
  2804. //Update multiplier 
  2805. $multiplier = $multiplier == 1 ? 2 : 1; 
  2806.  
  2807. return $checksum % 10 == 0; 
  2808.  
  2809.  
  2810. public static function is_wp_version( $min_version ) { 
  2811. return ! version_compare( get_bloginfo( 'version' ), "{$min_version}.dev1", '<' ); 
  2812.  
  2813. public static function add_categories_as_choices( $field, $value ) { 
  2814.  
  2815. $choices = $inputs = array(); 
  2816. $is_post = isset( $_POST['gform_submit'] ); 
  2817. $has_placeholder = $field->categoryInitialItemEnabled && RGFormsModel::get_input_type( $field ) == 'select'; 
  2818.  
  2819. if ( $has_placeholder ) { 
  2820. $choices[] = array( 'text' => $field->categoryInitialItem, 'value' => '', 'isSelected' => true ); 
  2821.  
  2822. $display_all = $field->displayAllCategories; 
  2823.  
  2824. $args = array( 'hide_empty' => false, 'orderby' => 'name' ); 
  2825.  
  2826. if ( ! $display_all ) { 
  2827. foreach ( $field->choices as $field_choice_to_include ) { 
  2828. $args['include'][] = $field_choice_to_include['value']; 
  2829.  
  2830. $args = gf_apply_filters( array( 'gform_post_category_args', $field->id ), $args, $field ); 
  2831. $terms = get_terms( 'category', $args ); 
  2832.  
  2833. $terms_copy = unserialize( serialize( $terms ) ); // deep copy the terms to avoid repeating GFCategoryWalker on previously cached terms. 
  2834. $walker = new GFCategoryWalker(); 
  2835. $categories = $walker->walk( $terms_copy, 0, array( 0 ) ); // 3rd parameter prevents notices triggered by $walker::display_element() function which checks $args[0] 
  2836.  
  2837. foreach ( $categories as $category ) { 
  2838. if ( $display_all ) { 
  2839. $selected = $value == $category->term_id || 
  2840. empty( $value ) && 
  2841. get_option( 'default_category' ) == $category->term_id && 
  2842. RGFormsModel::get_input_type( $field ) == 'select' && // only preselect default category on select fields 
  2843. ! $is_post && 
  2844. ! $has_placeholder 
  2845. ); 
  2846. $choices[] = array( 'text' => $category->name, 'value' => $category->term_id, 'isSelected' => $selected ); 
  2847. } else { 
  2848. foreach ( $field->choices as $field_choice ) { 
  2849. if ( $field_choice['value'] == $category->term_id ) { 
  2850. $choices[] = array( 'text' => $category->name, 'value' => $category->term_id ); 
  2851. break; 
  2852.  
  2853. if ( empty( $choices ) ) { 
  2854. $choices[] = array( 'text' => 'You must select at least one category.', 'value' => '' ); 
  2855.  
  2856. $choice_number = 1; 
  2857. foreach ( $choices as $choice ) { 
  2858.  
  2859. if ( $choice_number % 10 == 0 ) { 
  2860. //hack to skip numbers ending in 0. so that 5.1 doesn't conflict with 5.10 
  2861. $choice_number ++; 
  2862.  
  2863. $input_id = $field->id . '.' . $choice_number; 
  2864. $inputs[] = array( 'id' => $input_id, 'label' => $choice['text'], 'name' => '' ); 
  2865. $choice_number ++; 
  2866.  
  2867. $field->choices = $choices; 
  2868.  
  2869. $is_form_editor = GFCommon::is_form_editor(); 
  2870. $is_entry_detail = GFCommon::is_entry_detail(); 
  2871. $is_admin = $is_form_editor || $is_entry_detail; 
  2872.  
  2873. $form_id = $is_admin ? rgget( 'id' ) : $field->formId; 
  2874.  
  2875. /** 
  2876. * Allows you to filter (modify) the post cateogry choices when using post fields 
  2877. * @param array $field The Cateogry choices field 
  2878. * @param int $form_id The CUrrent form ID 
  2879. */ 
  2880. $field->choices = gf_apply_filters( array( 'gform_post_category_choices', $form_id, $field->id ), $field->choices, $field, $form_id ); 
  2881.  
  2882. if ( RGFormsModel::get_input_type( $field ) == 'checkbox' ) { 
  2883. $field->inputs = $inputs; 
  2884.  
  2885. return $field; 
  2886.  
  2887. public static function prepare_post_category_value( $value, $field, $mode = 'entry_detail' ) { 
  2888.  
  2889. if ( ! is_array( $value ) ) { 
  2890. $value = explode( ', ', $value ); 
  2891.  
  2892. $cat_names = array(); 
  2893. $cat_ids = array(); 
  2894. foreach ( $value as $cat_string ) { 
  2895. $ary = explode( ':', $cat_string ); 
  2896. $cat_name = count( $ary ) > 0 ? $ary[0] : ''; 
  2897. $cat_id = count( $ary ) > 1 ? $ary[1] : $ary[0]; 
  2898.  
  2899. if ( ! empty( $cat_name ) ) { 
  2900. $cat_names[] = $cat_name; 
  2901.  
  2902. if ( ! empty( $cat_id ) ) { 
  2903. $cat_ids[] = $cat_id; 
  2904.  
  2905. sort( $cat_names ); 
  2906.  
  2907. switch ( $mode ) { 
  2908. case 'entry_list': 
  2909. $value = self::implode_non_blank( ', ', $cat_names ); 
  2910. break; 
  2911. case 'entry_detail': 
  2912. $value = RGFormsModel::get_input_type( $field ) == 'checkbox' ? $cat_names : self::implode_non_blank( ', ', $cat_names ); 
  2913. break; 
  2914. case 'conditional_logic': 
  2915. $value = array_values( $cat_ids ); 
  2916. break; 
  2917.  
  2918. return $value; 
  2919.  
  2920. public static function calculate( $field, $form, $lead ) { 
  2921.  
  2922. $formula = (string) apply_filters( 'gform_calculation_formula', $field->calculationFormula, $field, $form, $lead ); 
  2923.  
  2924. // replace multiple spaces and new lines with single space 
  2925. // @props: http://stackoverflow.com/questions/3760816/remove-new-lines-from-string 
  2926. $formula = trim( preg_replace( '/\s+/', ' ', $formula ) ); 
  2927.  
  2928. preg_match_all( '/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}/mi', $formula, $matches, PREG_SET_ORDER ); 
  2929.  
  2930. if ( is_array( $matches ) ) { 
  2931. foreach ( $matches as $match ) { 
  2932.  
  2933. list( $text, $input_id ) = $match; 
  2934. $value = self::get_calculation_value( $input_id, $form, $lead ); 
  2935. $value = apply_filters( 'gform_merge_tag_value_pre_calculation', $value, $input_id, rgar( $match, 4 ), $field, $form, $lead ); 
  2936. $formula = str_replace( $text, $value, $formula ); 
  2937.  
  2938.  
  2939. $result = preg_match( '/^[0-9 -\/*\(\)]+$/', $formula ) ? eval( "return {$formula};" ) : false; 
  2940. $result = apply_filters( 'gform_calculation_result', $result, $formula, $field, $form, $lead ); 
  2941.   
  2942. return $result; 
  2943.   
  2944. public static function round_number( $number, $rounding ) { 
  2945. if ( is_numeric( $rounding ) && $rounding >= 0 ) { 
  2946. $number = round( $number, $rounding ); 
  2947.   
  2948. return $number; 
  2949.   
  2950. public static function get_calculation_value( $field_id, $form, $lead ) { 
  2951.   
  2952. $filters = array( 'price', 'value', '' ); 
  2953. $value = false; 
  2954.   
  2955. foreach ( $filters as $filter ) { 
  2956. if ( is_numeric( $value ) ) { 
  2957. //value found, exit loop 
  2958. break; 
  2959. $field = RGFormsModel::get_field( $form, $field_id ); 
  2960. $is_pricing_field = self::has_currency_value( $field ); 
  2961.   
  2962. $replaced_value = GFCommon::replace_variables( "{:{$field_id}:$filter}", $form, $lead ); 
  2963. if ( $is_pricing_field ) { 
  2964. $value = self::to_number( $replaced_value ); 
  2965. else{ 
  2966. $number_format = rgobj( $field, 'numberFormat' ); 
  2967. $value = self::clean_number( $replaced_value, $number_format ); 
  2968.   
  2969.   
  2970. if ( ! $value || ! is_numeric( $value ) ) { 
  2971. GFCommon::log_debug( "GFCommon::get_calculation_value(): No value or non-numeric value available for field #{$field_id}. Returning zero instead." ); 
  2972. $value = 0; 
  2973.   
  2974. return $value; 
  2975.   
  2976. public static function has_currency_value( $field ) { 
  2977. $has_currency = self::is_pricing_field( $field->type ) || rgobj( $field, 'numberFormat' ) == 'currency'; 
  2978. return $has_currency; 
  2979.   
  2980. public static function conditional_shortcode( $attributes, $content = null ) { 
  2981.   
  2982. extract( 
  2983. shortcode_atts( 
  2984. array( 
  2985. 'merge_tag' => '',  
  2986. 'condition' => '',  
  2987. 'value' => '',  
  2988. ), $attributes 
  2989. ); 
  2990.   
  2991. return RGFormsModel::matches_operation( $merge_tag, $value, $condition ) ? do_shortcode( $content ) : ''; 
  2992.   
  2993.   
  2994. public static function is_valid_for_calcuation( $field ) { 
  2995.   
  2996. $supported_input_types = array( 'text', 'select', 'number', 'checkbox', 'radio', 'hidden', 'singleproduct', 'price', 'hiddenproduct', 'calculation', 'singleshipping' ); 
  2997. $unsupported_field_types = array( 'category' ); 
  2998. $input_type = RGFormsModel::get_input_type( $field ); 
  2999.   
  3000. return in_array( $input_type, $supported_input_types ) && ! in_array( $input_type, $unsupported_field_types ); 
  3001.   
  3002. public static function log_error( $message ) { 
  3003. if ( class_exists( 'GFLogging' ) ) { 
  3004. GFLogging::include_logger(); 
  3005. GFLogging::log_message( 'gravityforms', $message, KLogger::ERROR ); 
  3006.   
  3007. public static function log_debug( $message ) { 
  3008. if ( class_exists( 'GFLogging' ) ) { 
  3009. GFLogging::include_logger(); 
  3010. GFLogging::log_message( 'gravityforms', $message, KLogger::DEBUG ); 
  3011.   
  3012. public static function echo_if( $condition, $text ) { 
  3013. _deprecated_function( 'GFCommon::echo_if() is deprecated', '1.9.9', 'Use checked() or selected() instead.' ); 
  3014.   
  3015. switch ( $text ) { 
  3016. case 'checked': 
  3017. $text = 'checked="checked"'; 
  3018. break; 
  3019. case 'selected': 
  3020. $text = 'selected="selected"'; 
  3021.   
  3022. echo $condition ? $text : ''; 
  3023.   
  3024. public static function gf_global( $echo = true ) { 
  3025.   
  3026. require_once( GFCommon::get_base_path() . '/currency.php' ); 
  3027.   
  3028. $gf_global = array(); 
  3029. $gf_global['gf_currency_config'] = RGCurrency::get_currency( GFCommon::get_currency() ); 
  3030. $gf_global['base_url'] = GFCommon::get_base_url(); 
  3031. $gf_global['number_formats'] = array(); 
  3032. $gf_global['spinnerUrl'] = GFCommon::get_base_url() . '/images/spinner.gif'; 
  3033.   
  3034. $gf_global_json = 'var gf_global = ' . json_encode( $gf_global ) . ';'; 
  3035.   
  3036. if ( ! $echo ) { 
  3037. return $gf_global_json; 
  3038.   
  3039. echo $gf_global_json; 
  3040.   
  3041. public static function gf_vars( $echo = true ) { 
  3042. if ( ! class_exists( 'RGCurrency' ) ) { 
  3043. require_once( 'currency.php' ); 
  3044.   
  3045. $gf_vars = array(); 
  3046. $gf_vars['active'] = esc_attr__( 'Active', 'gravityforms' ); 
  3047. $gf_vars['inactive'] = esc_attr__( 'Inactive', 'gravityforms' ); 
  3048. $gf_vars['save'] = esc_html__( 'Save', 'gravityforms' ); 
  3049. $gf_vars['update'] = esc_html__( 'Update', 'gravityforms' ); 
  3050. $gf_vars['previousLabel'] = esc_html__( 'Previous', 'gravityforms' ); 
  3051. $gf_vars['selectFormat'] = esc_html__( 'Select a format', 'gravityforms' ); 
  3052. $gf_vars['editToViewAll'] = esc_html__( '5 of %d items shown. Edit field to view all', 'gravityforms' ); 
  3053. $gf_vars['enterValue'] = esc_html__( 'Enter a value', 'gravityforms' ); 
  3054. $gf_vars['formTitle'] = esc_html__( 'Untitled Form', 'gravityforms' ); 
  3055. $gf_vars['formDescription'] = esc_html__( 'We would love to hear from you! Please fill out this form and we will get in touch with you shortly.', 'gravityforms' ); 
  3056. $gf_vars['formConfirmationMessage'] = esc_html__( 'Thanks for contacting us! We will get in touch with you shortly.', 'gravityforms' ); 
  3057. $gf_vars['buttonText'] = esc_html__( 'Submit', 'gravityforms' ); 
  3058. $gf_vars['loading'] = esc_html__( 'Loading...', 'gravityforms' ); 
  3059. $gf_vars['thisFieldIf'] = esc_html__( 'this field if', 'gravityforms' ); 
  3060. $gf_vars['thisSectionIf'] = esc_html__( 'this section if', 'gravityforms' ); 
  3061. $gf_vars['thisPage'] = esc_html__( 'this page', 'gravityforms' ); 
  3062. $gf_vars['thisFormButton'] = esc_html__( 'this form button if', 'gravityforms' ); 
  3063. $gf_vars['show'] = esc_html__( 'Show', 'gravityforms' ); 
  3064. $gf_vars['hide'] = esc_html__( 'Hide', 'gravityforms' ); 
  3065. $gf_vars['all'] = esc_html( _x( 'All', 'Conditional Logic', 'gravityforms' ) ); 
  3066. $gf_vars['any'] = esc_html( _x( 'Any', 'Conditional Logic', 'gravityforms' ) ); 
  3067. $gf_vars['ofTheFollowingMatch'] = esc_html__( 'of the following match:', 'gravityforms' ); 
  3068. $gf_vars['is'] = esc_html__( 'is', 'gravityforms' ); 
  3069. $gf_vars['isNot'] = esc_html__( 'is not', 'gravityforms' ); 
  3070. $gf_vars['greaterThan'] = esc_html__( 'greater than', 'gravityforms' ); 
  3071. $gf_vars['lessThan'] = esc_html__( 'less than', 'gravityforms' ); 
  3072. $gf_vars['contains'] = esc_html__( 'contains', 'gravityforms' ); 
  3073. $gf_vars['startsWith'] = esc_html__( 'starts with', 'gravityforms' ); 
  3074. $gf_vars['endsWith'] = esc_html__( 'ends with', 'gravityforms' ); 
  3075.   
  3076. $gf_vars['thisConfirmation'] = esc_html__( 'Use this confirmation if', 'gravityforms' ); 
  3077. $gf_vars['thisNotification'] = esc_html__( 'Send this notification if', 'gravityforms' ); 
  3078. $gf_vars['confirmationSave'] = esc_html__( 'Save', 'gravityforms' ); 
  3079. $gf_vars['confirmationSaving'] = esc_html__( 'Saving...', 'gravityforms' ); 
  3080. $gf_vars['confirmationAreYouSure'] = __( 'Are you sure you wish to cancel these changes?', 'gravityforms' ); 
  3081. $gf_vars['confirmationIssueSaving'] = __( 'There was an issue saving this confirmation.', 'gravityforms' ); 
  3082. $gf_vars['confirmationConfirmDelete'] = __( 'Are you sure you wish to delete this confirmation?', 'gravityforms' ); 
  3083. $gf_vars['confirmationIssueDeleting'] = __( 'There was an issue deleting this confirmation.', 'gravityforms' ); 
  3084. $gf_vars['confirmationConfirmDiscard'] = __( 'There are unsaved changes to the current confirmation. Would you like to discard these changes?', 'gravityforms' ); 
  3085. $gf_vars['confirmationDefaultName'] = __( 'Untitled Confirmation', 'gravityforms' ); 
  3086. $gf_vars['confirmationDefaultMessage'] = __( 'Thanks for contacting us! We will get in touch with you shortly.', 'gravityforms' ); 
  3087. $gf_vars['confirmationInvalidPageSelection'] = __( 'Please select a page.', 'gravityforms' ); 
  3088. $gf_vars['confirmationInvalidRedirect'] = __( 'Please enter a URL.', 'gravityforms' ); 
  3089. $gf_vars['confirmationInvalidName'] = __( 'Please enter a confirmation name.', 'gravityforms' ); 
  3090.   
  3091. $gf_vars['conditionalLogicDependency'] = __( "This form contains conditional logic dependent upon this field. Are you sure you want to delete this field? 'OK' to delete, 'Cancel' to abort.", 'gravityforms' ); 
  3092. $gf_vars['conditionalLogicDependencyChoice'] = __( "This form contains conditional logic dependent upon this choice. Are you sure you want to delete this choice? 'OK' to delete, 'Cancel' to abort.", 'gravityforms' ); 
  3093. $gf_vars['conditionalLogicDependencyChoiceEdit'] = __( "This form contains conditional logic dependent upon this choice. Are you sure you want to modify this choice? 'OK' to delete, 'Cancel' to abort.", 'gravityforms' ); 
  3094.   
  3095. $gf_vars['mergeTagsTooltip'] = '<h6>' . esc_html__( 'Merge Tags', 'gravityforms' ) . '</h6>' . esc_html__( 'Merge tags allow you to dynamically populate submitted field values in your form content wherever this merge tag icon is present.', 'gravityforms' ); 
  3096.   
  3097. $gf_vars['baseUrl'] = GFCommon::get_base_url(); 
  3098. $gf_vars['gf_currency_config'] = RGCurrency::get_currency( GFCommon::get_currency() ); 
  3099. $gf_vars['otherChoiceValue'] = GFCommon::get_other_choice_value(); 
  3100. $gf_vars['isFormTrash'] = false; 
  3101. $gf_vars['currentlyAddingField'] = false; 
  3102.   
  3103. $gf_vars['addFieldFilter'] = esc_html__( 'Add a condition' , 'gravityforms' ); 
  3104. $gf_vars['removeFieldFilter'] = esc_html__( 'Remove a condition' , 'gravityforms' ); 
  3105. $gf_vars['filterAndAny'] = esc_html__( 'Include results if {0} match:' , 'gravityforms' ); 
  3106.   
  3107. $gf_vars['customChoices'] = esc_html__( 'Custom Choices', 'gravityforms' ); 
  3108. $gf_vars['predefinedChoices'] = esc_html__( 'Predefined Choices', 'gravityforms' ); 
  3109.   
  3110.   
  3111. if ( is_admin() && rgget( 'id' ) ) { 
  3112. $form = RGFormsModel::get_form_meta( rgget( 'id' ) ); 
  3113. $gf_vars['mergeTags'] = GFCommon::get_merge_tags( $form['fields'], '', false ); 
  3114.   
  3115. $gf_vars_json = 'var gf_vars = ' . json_encode( $gf_vars ) . ';'; 
  3116.   
  3117. if ( ! $echo ) { 
  3118. return $gf_vars_json; 
  3119. } else { 
  3120. echo $gf_vars_json; 
  3121.   
  3122. public static function is_bp_active() { 
  3123. return defined( 'BP_VERSION' ) ? true : false; 
  3124.   
  3125. public static function add_message( $message, $is_error = false ) { 
  3126. if ( $is_error ) { 
  3127. self::$errors[] = $message; 
  3128. } else { 
  3129. self::$messages[] = $message; 
  3130.   
  3131. public static function add_error_message( $message ) { 
  3132. self::add_message( $message, true ); 
  3133.   
  3134. public static function display_admin_message( $errors = false, $messages = false ) { 
  3135.   
  3136. if ( ! $errors ) { 
  3137. $errors = self::$errors; 
  3138.   
  3139. if ( ! $messages ) { 
  3140. $messages = self::$messages; 
  3141.   
  3142. $errors = apply_filters( 'gform_admin_error_messages', $errors ); 
  3143. $messages = apply_filters( 'gform_admin_messages', $messages ); 
  3144.   
  3145. if ( ! empty( $errors ) ) { 
  3146. ?> 
  3147. <div class="error below-h2"> 
  3148. <?php if ( count( $errors ) > 1 ) { ?> 
  3149. <ul style="margin: 0.5em 0 0; padding: 2px;"> 
  3150. <li><?php echo implode( '</li><li>', $errors ); ?></li> 
  3151. </ul> 
  3152. <?php } else { ?> 
  3153. <p><?php echo $errors[0]; ?></p> 
  3154. <?php } ?> 
  3155. </div> 
  3156. <?php 
  3157. } else if ( ! empty( $messages ) ) { 
  3158. ?> 
  3159. <div id="message" class="updated below-h2"> 
  3160. <?php if ( count( $messages ) > 1 ) { ?> 
  3161. <ul style="margin: 0.5em 0 0; padding: 2px;"> 
  3162. <li><?php echo implode( '</li><li>', $messages ); ?></li> 
  3163. </ul> 
  3164. <?php } else { ?> 
  3165. <p><strong><?php echo $messages[0]; ?></strong></p> 
  3166. <?php } ?> 
  3167. </div> 
  3168. <?php 
  3169.   
  3170.   
  3171. private static function requires_gf_vars() { 
  3172. $dependent_scripts = array( 'gform_form_admin', 'gform_gravityforms', 'gform_form_editor', 'gform_field_filter' ); 
  3173. foreach ( $dependent_scripts as $script ) { 
  3174. if ( wp_script_is( $script ) ) { 
  3175. return true; 
  3176.   
  3177. return false; 
  3178.   
  3179. public static function maybe_output_gf_vars() { 
  3180. if ( self::requires_gf_vars() ) { 
  3181. echo '<script type="text/javascript">' . self::gf_vars( false ) . '</script>'; 
  3182.   
  3183. public static function maybe_add_leading_zero( $value ) { 
  3184. $first_char = GFCommon::safe_substr( $value, 0, 1, 'utf-8' ); 
  3185. if ( in_array( $first_char, array( '.', ', ' ) ) ) { 
  3186. $value = '0' . $value; 
  3187.   
  3188. return $value; 
  3189.   
  3190. // used by the gfFieldFilterUI() jQuery plugin 
  3191. public static function get_field_filter_settings( $form ) { 
  3192.   
  3193. $all_fields = $form['fields']; 
  3194.   
  3195. // set up filters 
  3196. $fields = $all_fields; 
  3197. $exclude_types = array( 'rank', 'page', 'html' ); 
  3198.   
  3199. $operators_by_input_type = array( 
  3200. 'default' => array( 'is', 'isnot', '>', '<', ),  
  3201. 'name' => array( 'is', 'isnot', '>', '<', 'contains' ),  
  3202. 'address' => array( 'is', 'isnot', '>', '<', 'contains' ),  
  3203. 'text' => array( 'is', 'isnot', '>', '<', 'contains' ),  
  3204. 'textarea' => array( 'is', 'isnot', '>', '<', 'contains' ),  
  3205. 'checkbox' => array( 'is' ),  
  3206. 'multiselect' => array( 'contains' ),  
  3207. 'number' => array( 'is', 'isnot', '>', '<' ),  
  3208. 'select' => array( 'is', 'isnot', '>', '<' ),  
  3209. 'likert' => array( 'is', 'isnot' ),  
  3210. 'list' => array( 'contains' ) 
  3211. ); 
  3212.   
  3213. for ( $i = 0; $i < count( $all_fields ); $i ++ ) { 
  3214. $input_type = GFFormsmodel::get_input_type( $all_fields[ $i ] ); 
  3215. if ( in_array( $input_type, $exclude_types ) ) { 
  3216. unset( $fields[ $i ] ); 
  3217. $fields = array_values( $fields ); 
  3218.   
  3219. $field_filters = array( 
  3220. array( 
  3221. 'key' => '0',  
  3222. 'text' => esc_html__( 'Any form field' , 'gravityforms' ),  
  3223. 'operators' => array( 'contains', 'is' ),  
  3224. 'preventMultiple' => false,  
  3225. ),  
  3226. ); 
  3227.   
  3228. foreach ( $fields as $field ) { 
  3229.   
  3230. $input_type = GFFormsModel::get_input_type( $field ); 
  3231.   
  3232. $operators = isset( $operators_by_input_type[ $input_type ] ) ? $operators_by_input_type[ $input_type ] : $operators_by_input_type['default']; 
  3233.   
  3234. if ( $field->type == 'product' && in_array( $input_type, array( 'radio', 'select' ) ) ) { 
  3235. $operators = array( 'is' ); 
  3236. } elseif ( ! isset( $field->choices ) && ! in_array( 'contains', $operators ) ) { 
  3237. $operators[] = 'contains'; 
  3238.   
  3239. $field_filter = array(); 
  3240. $key = $field->id; 
  3241. if ( $input_type == 'likert' && $field->gsurveyLikertEnableMultipleRows ) { 
  3242. // multi-row likert fields 
  3243. $field_filter['key'] = $key; 
  3244. $field_filter['group'] = true; 
  3245. $field_filter['text'] = GFFormsModel::get_label( $field ); 
  3246. $sub_filters = array(); 
  3247. $rows = $field->gsurveyLikertRows; 
  3248. foreach ( $rows as $row ) { 
  3249. $sub_filter = array(); 
  3250. $sub_filter['key'] = $key . '|' . rgar( $row, 'value' ); 
  3251. $sub_filter['text'] = rgar( $row, 'text' ); 
  3252. $sub_filter['type'] = 'field'; 
  3253. $sub_filter['preventMultiple'] = false; 
  3254. $sub_filter['operators'] = $operators; 
  3255. $sub_filter['values'] = $field->choices; 
  3256. $sub_filters[] = $sub_filter; 
  3257. $field_filter['filters'] = $sub_filters; 
  3258. } elseif ( ( $input_type == 'name' && $field->nameFormat !== '' && $field->nameFormat !== 'simple') || $input_type == 'address' ) { 
  3259. // standard two input name field 
  3260. $field_filter['key'] = $key; 
  3261. $field_filter['group'] = true; 
  3262. $field_filter['text'] = GFFormsModel::get_label( $field ); 
  3263. $sub_filters = array(); 
  3264. $inputs = $field->inputs; 
  3265. foreach ( $inputs as $input ) { 
  3266. $sub_filter = array(); 
  3267. $sub_filter['key'] = rgar( $input, 'id' ); 
  3268. $sub_filter['text'] = rgar( $input, 'label' ); 
  3269. $sub_filter['preventMultiple'] = false; 
  3270. $sub_filter['operators'] = $operators; 
  3271. $sub_filters[] = $sub_filter; 
  3272. $field_filter['filters'] = $sub_filters; 
  3273. } elseif( $input_type == 'date') { 
  3274. $field_filter['key'] = $key; 
  3275. $field_filter['preventMultiple'] = false; 
  3276. $field_filter['text'] = GFFormsModel::get_label( $field ); 
  3277.   
  3278. $field_filter['operators'] = $operators; 
  3279.   
  3280. $field_filter['placeholder'] = esc_html__('yyyy-mm-dd', 'gravityforms' ); 
  3281. $field_filter['cssClass'] = 'datepicker ymd_dash'; 
  3282. } else { 
  3283. $field_filter['key'] = $key; 
  3284. $field_filter['preventMultiple'] = false; 
  3285. $field_filter['text'] = GFFormsModel::get_label( $field ); 
  3286.   
  3287. $field_filter['operators'] = $operators; 
  3288.   
  3289. if ( isset( $field->choices ) ) { 
  3290. $field_filter['values'] = $field->choices; 
  3291. $field_filters[] = $field_filter; 
  3292.   
  3293. $form_id = $form['id']; 
  3294. $entry_meta_filters = self::get_entry_meta_filter_settings( $form_id ); 
  3295. $field_filters = array_merge( $field_filters, $entry_meta_filters ); 
  3296. $field_filters = array_values( $field_filters ); // reset the numeric keys in case some filters have been unset 
  3297. $info_filters = self::get_entry_info_filter_settings(); 
  3298. $field_filters = array_merge( $field_filters, $info_filters ); 
  3299. $field_filters = array_values( $field_filters ); 
  3300.   
  3301. return $field_filters; 
  3302.   
  3303. public static function get_entry_info_filter_settings() { 
  3304. $settings = array(); 
  3305. $info_columns = self::get_entry_info_filter_columns(); 
  3306. foreach ( $info_columns as $key => $info_column ) { 
  3307. $info_column['key'] = $key; 
  3308. $info_column['preventMultiple'] = false; 
  3309. $settings[] = $info_column; 
  3310.   
  3311. return $settings; 
  3312.   
  3313. public static function get_entry_info_filter_columns( $get_users = true ) { 
  3314. $account_choices = array(); 
  3315. if ( $get_users ) { 
  3316. $args = apply_filters( 'gform_filters_get_users', array( 'number' => 200 ) ); 
  3317. $accounts = get_users( $args ); 
  3318. $account_choices = array(); 
  3319. foreach ( $accounts as $account ) { 
  3320. $account_choices[] = array( 'text' => $account->user_login, 'value' => $account->ID ); 
  3321.   
  3322. return array( 
  3323. 'entry_id' => array( 
  3324. 'text' => esc_html__( 'Entry ID' , 'gravityforms' ),  
  3325. 'operators' => array( 'is', 'isnot', '>', '<' ) 
  3326. ),  
  3327. 'date_created' => array( 
  3328. 'text' => esc_html__( 'Entry Date' , 'gravityforms' ),  
  3329. 'operators' => array( 'is', '>', '<' ),  
  3330. 'placeholder' => __( 'yyyy-mm-dd' , 'gravityforms' ),  
  3331. 'cssClass' => 'datepicker ymd_dash',  
  3332. ),  
  3333. 'is_starred' => array( 
  3334. 'text' => esc_html__( 'Starred' , 'gravityforms' ),  
  3335. 'operators' => array( 'is', 'isnot' ),  
  3336. 'values' => array( 
  3337. array( 
  3338. 'text' => 'Yes',  
  3339. 'value' => '1',  
  3340. ),  
  3341. array( 
  3342. 'text' => 'No',  
  3343. 'value' => '0',  
  3344. ),  
  3345. ),  
  3346. 'ip' => array( 
  3347. 'text' => esc_html__( 'IP Address' , 'gravityforms' ),  
  3348. 'operators' => array( 'is', 'isnot', '>', '<', 'contains' ) 
  3349. ),  
  3350. 'source_url' => array( 
  3351. 'text' => esc_html__( 'Source URL' , 'gravityforms' ),  
  3352. 'operators' => array( 'is', 'isnot', '>', '<', 'contains' ) 
  3353. ),  
  3354. 'payment_status' => array( 
  3355. 'text' => esc_html__( 'Payment Status' , 'gravityforms' ),  
  3356. 'operators' => array( 'is', 'isnot' ),  
  3357. 'values' => array( 
  3358. array( 
  3359. 'text' => 'Paid',  
  3360. 'value' => 'Paid',  
  3361. ),  
  3362. array( 
  3363. 'text' => 'Processing',  
  3364. 'value' => 'Processing',  
  3365. ),  
  3366. array( 
  3367. 'text' => 'Failed',  
  3368. 'value' => 'Failed',  
  3369. ),  
  3370. array( 
  3371. 'text' => 'Active',  
  3372. 'value' => 'Active',  
  3373. ),  
  3374. array( 
  3375. 'text' => 'Cancelled',  
  3376. 'value' => 'Cancelled',  
  3377. ),  
  3378. ),  
  3379. 'payment_date' => array( 
  3380. 'text' => esc_html__( 'Payment Date' , 'gravityforms' ),  
  3381. 'operators' => array( 'is', 'isnot', '>', '<' ),  
  3382. 'placeholder' => __( 'yyyy-mm-dd' , 'gravityforms' ),  
  3383. 'cssClass' => 'datepicker ymd_dash',  
  3384. ),  
  3385. 'payment_amount' => array( 
  3386. 'text' => esc_html__( 'Payment Amount' , 'gravityforms' ),  
  3387. 'operators' => array( 'is', 'isnot', '>', '<', 'contains' ) 
  3388. ),  
  3389. 'transaction_id' => array( 
  3390. 'text' => esc_html__( 'Transaction ID' , 'gravityforms' ),  
  3391. 'operators' => array( 'is', 'isnot', '>', '<', 'contains' ) 
  3392. ),  
  3393. 'created_by' => array( 
  3394. 'text' => esc_html__( 'User' , 'gravityforms' ),  
  3395. 'operators' => array( 'is', 'isnot' ),  
  3396. 'values' => $account_choices,  
  3397. ); 
  3398.   
  3399. public static function get_entry_meta_filter_settings( $form_id ) { 
  3400. $filters = array(); 
  3401. $entry_meta = GFFormsModel::get_entry_meta( $form_id ); 
  3402. if ( empty( $entry_meta ) ) { 
  3403. return $filters; 
  3404.   
  3405. foreach ( $entry_meta as $key => $meta ) { 
  3406. if ( isset( $meta['filter'] ) ) { 
  3407. $filter = array(); 
  3408. $filter['key'] = $key; 
  3409. $filter['preventMultiple'] = isset( $meta['filter']['preventMultiple'] ) ? $meta['filter']['preventMultiple'] : false; 
  3410. $filter['text'] = rgar( $meta, 'label' ); 
  3411. $filter['operators'] = isset( $meta['filter']['operators'] ) ? $meta['filter']['operators'] : array( 'is', 'isnot' ); 
  3412. if ( isset( $meta['filter']['choices'] ) ) { 
  3413. $filter['values'] = $meta['filter']['choices']; 
  3414. $filters[] = $filter; 
  3415.   
  3416. return $filters; 
  3417.   
  3418.   
  3419. public static function get_field_filters_from_post( $form ) { 
  3420. $field_filters = array(); 
  3421. $filter_fields = rgpost( 'f' ); 
  3422. if ( is_array( $filter_fields ) ) { 
  3423. $filter_operators = rgpost( 'o' ); 
  3424. $filter_values = rgpost( 'v' ); 
  3425. for ( $i = 0; $i < count( $filter_fields ); $i ++ ) { 
  3426. $field_filter = array(); 
  3427. $key = $filter_fields[ $i ]; 
  3428. if ( 'entry_id' == $key ) { 
  3429. $key = 'id'; 
  3430. $operator = $filter_operators[ $i ]; 
  3431. $val = $filter_values[ $i ]; 
  3432. $strpos_row_key = strpos( $key, '|' ); 
  3433. if ( $strpos_row_key !== false ) { //multi-row likert 
  3434. $key_array = explode( '|', $key ); 
  3435. $key = $key_array[0]; 
  3436. $val = $key_array[1] . ':' . $val; 
  3437. $field_filter['key'] = $key; 
  3438.   
  3439. $field = GFFormsModel::get_field( $form, $key ); 
  3440. if ( $field ) { 
  3441. $input_type = GFFormsModel::get_input_type( $field ); 
  3442. if ( $field->type == 'product' && in_array( $input_type, array( 'radio', 'select' ) ) ) { 
  3443. $operator = 'contains'; 
  3444.   
  3445. $field_filter['operator'] = $operator; 
  3446. $field_filter['value'] = $val; 
  3447. $field_filters[] = $field_filter; 
  3448. $field_filters['mode'] = rgpost( 'mode' ); 
  3449.   
  3450. return $field_filters; 
  3451.   
  3452. public static function has_multifile_fileupload_field( $form ) { 
  3453. $fileupload_fields = GFAPI::get_fields_by_type( $form, array( 'fileupload', 'post_custom_field' ) ); 
  3454. if ( is_array( $fileupload_fields ) ) { 
  3455. foreach ( $fileupload_fields as $field ) { 
  3456. if ( $field->multipleFiles ) { 
  3457. return true; 
  3458.   
  3459. return false; 
  3460.   
  3461. public static function localize_gform_gravityforms_multifile() { 
  3462. wp_localize_script( 
  3463. 'gform_gravityforms', 'gform_gravityforms', array( 
  3464. 'strings' => array( 
  3465. 'invalid_file_extension' => esc_html__( 'This type of file is not allowed. Must be one of the following: ' , 'gravityforms' ),  
  3466. 'delete_file' => esc_html__( 'Delete this file' , 'gravityforms' ),  
  3467. 'in_progress' => esc_html__( 'in progress' , 'gravityforms' ),  
  3468. 'file_exceeds_limit' => esc_html__( 'File exceeds size limit' , 'gravityforms' ),  
  3469. 'illegal_extension' => esc_html__( 'This type of file is not allowed.' , 'gravityforms' ),  
  3470. 'max_reached' => esc_html__( 'Maximum number of files reached' , 'gravityforms' ),  
  3471. 'unknown_error' => esc_html__( 'There was a problem while saving the file on the server' , 'gravityforms' ),  
  3472. 'currently_uploading' => esc_html__( 'Please wait for the uploading to complete' , 'gravityforms' ),  
  3473. 'cancel' => esc_html__( 'Cancel' , 'gravityforms' ),  
  3474. 'cancel_upload' => esc_html__( 'Cancel this upload' , 'gravityforms' ),  
  3475. 'cancelled' => esc_html__( 'Cancelled' , 'gravityforms' ) 
  3476. ),  
  3477. 'vars' => array( 
  3478. 'images_url' => GFCommon::get_base_url() . '/images' 
  3479. ); 
  3480.   
  3481. public static function send_resume_link( $message, $subject, $email, $embed_url, $resume_token ) { 
  3482.   
  3483. $from = get_bloginfo( 'admin_email' ); 
  3484. $from_name = get_bloginfo( 'name' ); 
  3485.   
  3486. $message_format = 'html'; 
  3487.   
  3488. $resume_url = add_query_arg( array( 'gf_token' => $resume_token ), $embed_url ); 
  3489. $resume_url = esc_url( $resume_url ); 
  3490. $resume_link = "<a href='{$resume_url}'>{$resume_url}</a>"; 
  3491. $message .= $resume_link; 
  3492.   
  3493. self::send_email( $from, $email, '', $from, $subject, $message, $from_name, $message_format ); 
  3494.   
  3495. public static function safe_strlen( $string ) { 
  3496.   
  3497. if ( is_array( $string ) ) { 
  3498. return false; 
  3499.   
  3500. if ( function_exists( 'mb_strlen' ) ) { 
  3501. return mb_strlen( $string ); 
  3502. } else { 
  3503. return strlen( $string ); 
  3504.   
  3505.   
  3506. public static function safe_substr( $string, $start, $length = null ) { 
  3507.   
  3508. if ( is_array( $string ) ) { 
  3509. return false; 
  3510.   
  3511. if ( function_exists( 'mb_substr' ) ) { 
  3512. return mb_substr( $string, $start, $length ); 
  3513. } else { 
  3514. return substr( $string, $start, $length ); 
  3515.   
  3516.   
  3517. /** 
  3518. * @param string $string 
  3519. * @return string 
  3520. */ 
  3521. public static function safe_strtoupper( $string ) { 
  3522.  
  3523. if ( function_exists( 'mb_strtoupper' ) ) { 
  3524. return mb_strtoupper( $string ); 
  3525. } else { 
  3526. return strtoupper( $string ); 
  3527.  
  3528.  
  3529. /** 
  3530. * Trims a string or an array recursively. 
  3531. * @param array|string $array 
  3532. * @return array|string 
  3533. */ 
  3534. public static function trim_deep( $array ) { 
  3535. if ( ! is_array( $array ) ) { 
  3536. return trim( $array ); 
  3537.  
  3538. return array_map( array( 'GFCommon', 'trim_deep' ), $array ); 
  3539.  
  3540. /** 
  3541. * Reliably compare floats. 
  3542. * @param float $float1 
  3543. * @param float $float2 
  3544. * @param string $operator Supports: '<', '<=', '>', '>=', '==', '=', '!=' 
  3545. * @return bool 
  3546. */ 
  3547. public static function compare_floats( $float1, $float2, $operator ) { 
  3548.  
  3549. $epsilon = 0.00001; 
  3550. $is_equal = abs( floatval( $float1 ) - floatval( $float2 ) ) < $epsilon; 
  3551. $is_greater = floatval( $float1 ) > floatval( $float2 ); 
  3552. $is_less = floatval( $float1 ) < floatval( $float2 ); 
  3553.  
  3554. switch ( $operator ) { 
  3555. case '<': 
  3556. return $is_less; 
  3557. case '<=': 
  3558. return $is_less || $is_equal; 
  3559. case '>' : 
  3560. return $is_greater; 
  3561. case '>=': 
  3562. return $is_greater || $is_equal; 
  3563. case '==': 
  3564. case '=': 
  3565. return $is_equal; 
  3566. case '!=': 
  3567. return ! $is_equal; 
  3568.  
  3569.  
  3570. public static function encrypt( $text ) { 
  3571. $use_mcrypt = apply_filters('gform_use_mcrypt', function_exists( 'mcrypt_encrypt' ) ); 
  3572.  
  3573. if ( $use_mcrypt ) { 
  3574. $iv_size = mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ); 
  3575. $key = substr( md5( wp_salt( 'nonce' ) ), 0, $iv_size ); 
  3576.  
  3577. $encrypted_value = trim( base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, mcrypt_create_iv( $iv_size, MCRYPT_RAND ) ) ) ); 
  3578. else{ 
  3579. $encrypted_value = EncryptDB::encrypt( $text, wp_salt( 'nonce' ) ); 
  3580.  
  3581. //$encrypted_value = base64_encode( $wpdb->get_var( $wpdb->prepare('SELECT AES_ENCRYPT(%s, %s) AS data', $text, wp_salt( 'nonce' ) ) ) ); 
  3582.  
  3583. return $encrypted_value; 
  3584.  
  3585. public static function decrypt( $text ) { 
  3586.  
  3587. $use_mcrypt = apply_filters('gform_use_mcrypt', function_exists( 'mcrypt_decrypt' ) ); 
  3588.  
  3589. if ( $use_mcrypt ) { 
  3590. $iv_size = mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ); 
  3591. $key = substr( md5( wp_salt( 'nonce' ) ), 0, $iv_size ); 
  3592.  
  3593. $decrypted_value = trim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, $key, base64_decode( $text ), MCRYPT_MODE_ECB, mcrypt_create_iv( $iv_size, MCRYPT_RAND ) ) ); 
  3594. else{ 
  3595. $decrypted_value = EncryptDB::decrypt( $text, wp_salt( 'nonce' ) ); 
  3596.  
  3597. return $decrypted_value; 
  3598.  
  3599. public static function esc_like( $value ) { 
  3600. global $wpdb; 
  3601.  
  3602. if( is_callable( array( $wpdb, 'esc_like' ) ) ) { 
  3603. $value = $wpdb->esc_like( $value ); 
  3604. } else { 
  3605. $value = like_escape( $value ); 
  3606.  
  3607. return $value; 
  3608.  
  3609. public static function is_form_editor() { 
  3610. $is_form_editor = GFForms::get_page() == 'form_editor' || ( defined( 'DOING_AJAX' ) && DOING_AJAX && in_array( rgpost( 'action' ), array( 'rg_add_field', 'rg_refresh_field_preview', 'rg_duplicate_field', 'rg_delete_field', 'rg_change_input_type' ) ) ); 
  3611. return apply_filters( 'gform_is_form_editor', $is_form_editor ); 
  3612.  
  3613. public static function is_entry_detail() { 
  3614. $is_entry_detail = GFForms::get_page() == 'entry_detail_edit' || GFForms::get_page() == 'entry_detail' ; 
  3615. return apply_filters( 'gform_is_entry_detail', $is_entry_detail ); 
  3616.  
  3617. public static function is_entry_detail_view() { 
  3618. $is_entry_detail_view = GFForms::get_page() == 'entry_detail' ; 
  3619. return apply_filters( 'gform_is_entry_detail_view', $is_entry_detail_view ); 
  3620.  
  3621. public static function is_entry_detail_edit() { 
  3622. $is_entry_detail_edit = GFForms::get_page() == 'entry_detail_edit'; 
  3623. return apply_filters( 'gform_is_entry_detail_edit', $is_entry_detail_edit ); 
  3624.  
  3625. public static function has_merge_tag( $string ) { 
  3626. return preg_match( '/{.+}/', $string ); 
  3627.  
  3628. public static function get_upload_page_slug() { 
  3629. $slug = get_option( 'gform_upload_page_slug' ); 
  3630. if ( empty( $slug ) ) { 
  3631. $slug = substr( str_shuffle( wp_hash( microtime() ) ), 0, 15 ); 
  3632. update_option( 'gform_upload_page_slug', $slug ); 
  3633.  
  3634. return $slug; 
  3635.  
  3636. /** 
  3637. * Whitelists a value. Returns the value or the first value in the array. 
  3638. * @param $value 
  3639. * @param $whitelist 
  3640. * @return mixed 
  3641. */ 
  3642. public static function whitelist( $value, $whitelist ) { 
  3643.  
  3644. if ( ! in_array( $value, $whitelist ) ) { 
  3645. $value = $whitelist[0]; 
  3646. return $value; 
  3647.  
  3648. /** 
  3649. * Forces an integer into a range of integers. Returns the value or the minimum if it's outside the range. 
  3650. * @param $value 
  3651. * @param $min 
  3652. * @param $max 
  3653. * @return int 
  3654. */ 
  3655. public static function int_range( $value, $min, $max ) { 
  3656. $value = (int) $value; 
  3657. $min = (int) $min; 
  3658. $max = (int) $max; 
  3659.  
  3660. return filter_var( $value, FILTER_VALIDATE_INT, array( 
  3661. 'min_range' => $min,  
  3662. 'max_range' => $max 
  3663. ) ) ? $value : $min; 
  3664.  
  3665. public static function load_gf_text_domain( $domain ) { 
  3666. // Initializing translations. Translation files in the WP_LANG_DIR folder have a higher priority. 
  3667. global $l10n; 
  3668. $locale = apply_filters( 'plugin_locale', get_locale(), 'gravityforms' ); 
  3669. if ( ! isset( $l10n[$domain] ) ) { 
  3670. load_textdomain( 'gravityforms', WP_LANG_DIR . '/gravityforms/gravityforms-' . $locale . '.mo' ); 
  3671. load_plugin_textdomain( 'gravityforms', false, '/gravityforms/languages' ); 
  3672.  
  3673. public static function replace_field_variable( $text, $form, $lead, $url_encode, $esc_html, $nl2br, $format, $input_id, $match, $esc_attr = false ) { 
  3674. $field = RGFormsModel::get_field( $form, $input_id ); 
  3675.  
  3676. if ( ! $field instanceof GF_Field ) { 
  3677. $field = GF_Fields::create( $field ); 
  3678.  
  3679. $value = RGFormsModel::get_lead_field_value( $lead, $field ); 
  3680. $raw_value = $value; 
  3681.  
  3682. if ( is_array( $value ) ) { 
  3683. $value = rgar( $value, $input_id ); 
  3684.  
  3685. $value = self::format_variable_value( $value, $url_encode, $esc_html, $format, $nl2br ); 
  3686.  
  3687. // modifier will be at index 4 unless used in a conditional shortcode in which case it would be at index 5 
  3688. $i = $match[0][0] == '{' ? 4 : 5; 
  3689. $modifier = strtolower( rgar( $match, $i ) ); 
  3690.  
  3691. $value = $field->get_value_merge_tag( $value, $input_id, $lead, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ); 
  3692.  
  3693. if ( $esc_attr ) { 
  3694. $value = esc_attr( $value ); 
  3695.  
  3696. if ( $modifier == 'label' ) { 
  3697. $value = empty( $value ) ? '' : $field->label; 
  3698. } else if ( $modifier == 'qty' && $field->type == 'product' ) { 
  3699. //getting quantity associated with product field 
  3700. $products = self::get_product_fields( $form, $lead, false, false ); 
  3701. $value = 0; 
  3702. foreach ( $products['products'] as $product_id => $product ) { 
  3703. if ( $product_id == $field->id ) { 
  3704. $value = $product['quantity']; 
  3705.  
  3706. //Encoding left curly bracket so that merge tags entered in the front end are displayed as is and not parsed 
  3707. $value = self::encode_merge_tag( $value ); 
  3708.  
  3709. //filter can change merge tag value 
  3710. $value = apply_filters( 'gform_merge_tag_filter', $value, $input_id, $modifier, $field, $raw_value ); 
  3711. if ( $value === false ) { 
  3712. $value = ''; 
  3713.  
  3714. if ( $match[0][0] != '{' ) { 
  3715. // replace the merge tag in the conditional shortcode merge_tag attr 
  3716. $value = str_replace( $match[1], $value, $match[0] ); 
  3717.  
  3718. $text = str_replace( $match[0], $value, $text ); 
  3719.  
  3720. return $text;