_id, $modifier, $field, $raw_value ); if ( $value === false ) { $value = ''; } // Clear merge tag modifiers from the field object. $field->set_modifiers( array() ); if ( $match[0][0] != '{' ) { // Replace the merge tag in the conditional shortcode merge_tag attr. $value = str_replace( $match[1], $value, $match[0] ); } $text = str_replace( $match[0], $value, $text ); return $text; } public static function encode_shortcodes( $string ) { $find = array( '[', ']' ); $replace = array( '[', ']' ); $string = str_replace( $find, $replace, $string ); return $string; } /** * Sanitizes html content. Checks the unfiltered_html capability. * * @since 2.0.0 * @access public * * @param $html * @param $allowed_html * @param $allowed_protocols * * @return string */ public static function maybe_wp_kses( $html, $allowed_html = 'post', $allowed_protocols = array() ) { if ( ! current_user_can( 'unfiltered_html' ) ) { $html = wp_kses( $html, $allowed_html, $allowed_protocols ); } return $html; } /** * Sanitizes a confirmation message. * * @since 2.0.0 * * @param $confirmation_message * * @return string */ public static function maybe_sanitize_confirmation_message( $confirmation_message ) { // Default during deprecation period = false $sanitize_confirmation_nessage = false; /** * Allows sanitization to be turned on or off for the confirmation message. Only turn off if you're sure you know what you're doing. * * @since 2.0.0 * * @param bool $sanitize_confirmation_nessage Whether to sanitize the confirmation message. default: true */ $sanitize_confirmation_nessage = apply_filters( 'gform_sanitize_confirmation_message', $sanitize_confirmation_nessage ); if ( $sanitize_confirmation_nessage ) { $confirmation_message = wp_kses_post( $confirmation_message ); } return $confirmation_message; } /** * Generates a hash for a Gravity Forms download. * * May return false if the algorithm is not available. * * @param int $form_id The Form ID. * @param int $field_id The ID of the field used to upload the file. * @param string $file The file url relative to the form's upload folder. E.g. 2016/04/my-file.pdf * * @return string|bool */ public static function generate_download_hash( $form_id, $field_id, $file ) { $key = absint( $form_id ) . ':' . absint( $field_id ) . ':' . urlencode( $file ); $algo = 'sha256'; /** * Allows the hash algorithm to be changed when generating the file download hash. * * @param string $algo The algorithm. E.g. "md5", "sha256", "haval160,4", etc */ $algo = apply_filters( 'gform_download_hash_algorithm', $algo ); $hash = hash_hmac( $algo, $key, 'gform_download' . wp_salt() ); /** * Allows the hash to be modified. * * @param string $hash The hash. * @param int $form_id The Form ID * @param string $file The File path relative to the upload root for the form. */ $hash = apply_filters( 'gform_download_hash', $hash, $form_id, $file ); return $hash; } public static function get_visibility_options() { $options = array( array( 'label' => __( 'Visible', 'gravityforms' ), 'value' => 'visible', 'description' => __( 'Default option. The field is visible when viewing the form.', 'gravityforms' ) ), array( 'label' => __( 'Hidden', 'gravityforms' ), 'value' => 'hidden', 'description' => __( 'The field is hidden when viewing the form. Useful when you require the functionality of this field but do not want the user to be able to see this field.', 'gravityforms' ) ), array( 'label' => __( 'Administrative', 'gravityforms' ), 'value' => 'administrative', 'description' => __( 'The field is only visible when administering submitted entries. The field is not visible or functional when viewing the form.', 'gravityforms' ) ), ); /** * Allows default visibility options to be modified or removed and custom visibility options to be added. * * @since 2.1 * * @param array $options { * An array of visibility options. * * @type string $label The label of the visibility option; displayed in the field's Visibility setting. * @type string $value The value of the visibility option; will be saved to the form meta. * @type string $description The description of the visibility option; used in the Visibility setting tooltip. * } */ return (array) apply_filters( 'gform_visibility_options', $options ); } public static function get_visibility_tooltip() { $options = self::get_visibility_options(); $markup = array(); foreach ( $options as $option ) { $markup[] = sprintf( '%s
%s', $option['label'], $option['description'] ); } $markup = sprintf( '', implode( '
  • ', $markup ) ); return sprintf( '
    %s
    %s

    %s', __( 'Visibility', 'gravityforms' ), __( 'Select the visibility for this field.', 'gravityforms' ), $markup ); } /** * @param $message * * @return mixed|string */ private static function format_text_message( $message ) { // Replacing tags with asterisk. $text_message = preg_replace( '| tags with new line character. $text_message = preg_replace( '||', "\n
    ", $text_message ); // Removing all HTML tags. $text_message = wp_strip_all_tags( $text_message ); // Removing   characters $text_message = str_replace( ' ', ' ', $text_message ); // Removing multiple white spaces $text_message = preg_replace( '|[ \t]+|', ' ', $text_message ); // Removing multiple line feeds $text_message = preg_replace( "|[\r\n]+\s*|", "\n", $text_message ); return $text_message; } /** * Maybe wrap the notification message in html tags. * * @since 2.2.0 * * @param string $message The notification message. Merge tags have already been processed. * @param string $subject The notification subject line. Merge tags have already been processed. * * @return string */ private static function format_html_message( $message, $subject ) { if ( ! preg_match( '/update_current_site( '' ); } else { //License Key has changed, update site record appropriately. //Get new license key information $version_info = GFCommon::get_version_info( false ); //Has site been already registered? $is_site_registered = gapi()->is_site_registered(); $is_valid_new = $version_info['is_valid_key'] && ! $is_site_registered; $is_valid_registered = $version_info['is_valid_key'] && $is_site_registered; if ( $is_valid_new ) { //Site is new (not registered) and license key is valid //Register new site $result = gapi()->register_current_site( $new_key, $is_md5 ); } elseif ( $is_valid_registered ) { //Site is already registered and new license key is valid //Update site with new license key $result = gapi()->update_current_site( $new_key ); } else { //Invalid key, do not change site registration. $result = new WP_Error( 'invalid_license', 'Invalid license. Site cannot be registered' ); GFCommon::log_error( 'Invalid license. Site cannot be registered' ); } } if ( is_wp_error( $result ) ) { GFCommon::log_error( 'Failed to update site registration with Gravity Manager. ' . print_r( $result, true ) ); } return $result; } } class GFCategoryWalker extends Walker { /** * @see Walker::$tree_type * @since 2.1.0 * @var string */ var $tree_type = 'category'; /** * @see Walker::$db_fields * @since 2.1.0 * @todo Decouple this * @var array */ var $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' ); /** * @see Walker::start_el() * @since 2.1.0 * * @param string $output Passed by reference. Used to append additional content. * @param object $object Category data object. * @param int $depth Depth of category. Used for padding. Defaults to 0. * @param array $args Uses 'selected' and 'show_count' keys, if they exist. Defaults to empty array. * @param int $current_object_id The current object ID. Defaults to 0. */ function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { //$pad = str_repeat(' ', $depth * 3); $pad = str_repeat( '─', $depth ); if ( ! empty( $pad ) ) { $pad .= ' '; } $object->name = "{$pad}{$object->name}"; if ( empty( $output ) ) { $output = array(); } $output[] = $object; } } /** * * Notes: * 1. The WordPress Transients API does not support boolean * values so boolean values should be converted to integers * or arrays before setting the values as persistent. * * 2. The transients API only deletes the transient from the database * when the transient is accessed after it has expired. WordPress doesn't * do any garbage collection of transients. * */ class GFCache { private static $_transient_prefix = 'GFCache_'; private static $_cache = array(); public static function get( $key, &$found = null, $is_persistent = true ) { global $blog_id; if ( is_multisite() ) { $key = $blog_id . ':' . $key; } if ( isset( self::$_cache[ $key ] ) ) { $found = true; $data = rgar( self::$_cache[ $key ], 'data' ); return $data; } //If set to not persistent, do not check transient for performance reasons if ( ! $is_persistent ) { $found = false; return false; } $data = self::get_transient( $key ); if ( false === ( $data ) ) { $found = false; return false; } else { self::$_cache[ $key ] = array( 'data' => $data, 'is_persistent' => true ); $found = true; return $data; } } public static function set( $key, $data, $is_persistent = false, $expiration_seconds = 0 ) { global $blog_id; $success = true; if ( is_multisite() ) { $key = $blog_id . ':' . $key; } if ( $is_persistent ) { $success = self::set_transient( $key, $data, $expiration_seconds ); } self::$_cache[ $key ] = array( 'data' => $data, 'is_persistent' => $is_persistent ); return $success; } public static function delete( $key ) { global $blog_id; $success = true; if ( is_multisite() ) { $key = $blog_id . ':' . $key; } if ( isset( self::$_cache[ $key ] ) ) { if ( self::$_cache[ $key ]['is_persistent'] ) { $success = self::delete_transient( $key ); } unset( self::$_cache[ $key ] ); } else { $success = self::delete_transient( $key ); } return $success; } public static function flush( $flush_persistent = false ) { global $wpdb; self::$_cache = array(); if ( false === $flush_persistent ) { return true; } if ( is_multisite() ) { $sql = " DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE '\_site\_transient\_timeout\_GFCache\_%' OR meta_key LIKE '_site_transient_GFCache_%' "; } else { $sql = " DELETE FROM $wpdb->options WHERE option_name LIKE '\_transient\_timeout\_GFCache\_%' OR option_name LIKE '\_transient\_GFCache\_%' "; } $rows_deleted = $wpdb->query( $sql ); $success = $rows_deleted !== false ? true : false; return $success; } private static function delete_transient( $key ) { if ( ! function_exists( 'wp_hash' ) ) { return false; } $key = self::$_transient_prefix . wp_hash( $key ); if ( is_multisite() ) { $success = delete_site_transient( $key ); } else { $success = delete_transient( $key ); } return $success; } private static function set_transient( $key, $data, $expiration ) { if ( ! function_exists( 'wp_hash' ) ) { return false; } $key = self::$_transient_prefix . wp_hash( $key ); if ( is_multisite() ) { $success = set_site_transient( $key, $data, $expiration ); } else { $success = set_transient( $key, $data, $expiration ); } return $success; } private static function get_transient( $key ) { if ( ! function_exists( 'wp_hash' ) ) { return false; } $key = self::$_transient_prefix . wp_hash( $key ); if ( is_multisite() ) { $data = get_site_transient( $key ); } else { $data = get_transient( $key ); } return $data; } } class EncryptDB extends wpdb { private static $_instance = null; public static function get_instance() { if ( self::$_instance == null ) { self::$_instance = new EncryptDB( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ); } return self::$_instance; } public static function encrypt( $text, $key ) { $db = self::get_instance(); $encrypted = base64_encode( $db->get_var( $db->prepare( 'SELECT AES_ENCRYPT(%s, %s) AS data', $text, $key ) ) ); return $encrypted; } public static function decrypt( $text, $key ) { $db = self::get_instance(); $decrypted = $db->get_var( $db->prepare( 'SELECT AES_DECRYPT(%s, %s) AS data', base64_decode( $text ), wp_salt( 'nonce' ) ) ); return $decrypted; } public function get_var( $query = null, $x = 0, $y = 0 ) { $this->check_current_query = false; return parent::get_var( $query ); } } /** * Late static binding for dynamic function calls. * * Provides compatibility with PHP 7.2 (create_function deprecated) and 5.2. * So whenever the need for `create_function` arises, use this instead. */ class GF_Late_Static_Binding { private $args = array(); public function __construct( $args ) { $this->args = wp_parse_args( $args, array( 'form_id' => 0, ) ); } /** * Binding for GFFormDisplay::footer_init_scripts */ public function GFFormDisplay_footer_init_scripts() { return GFFormDisplay::footer_init_scripts( $this->args['form_id'] ); } }