; } switch ( $field["type"] ) { case 'product': $option_fields = GFCommon::get_product_fields_by_type( $form, array( "option" ), $field['id'] ); // can only have 1 quantity field $quantity_field = GFCommon::get_product_fields_by_type( $form, array( "quantity" ), $field['id'] ); $quantity_field = rgar( $quantity_field, 0 ); $product_fields[] = array( 'product' => $field, 'options' => $option_fields, 'quantity' => $quantity_field ); break; case 'shopping_cart': //todo : for next update break; } } $shipping_field = GFCommon::get_fields_by_type( $form, array( "shipping" ) ); $pricing_fields = array( "products" => $product_fields, "shipping" => $shipping_field ); $product_tag_groups = array(); foreach ( $pricing_fields['products'] as $product ) { $product_field = rgar( $product, 'product' ); $option_fields = rgar( $product, 'options' ); $quantity_field = rgar( $product, 'quantity' ); // do not include current field in subtotal if ( $product_field['id'] == $current_field['id'] ) { continue; } $product_tags = GFCommon::get_field_merge_tags( $product_field ); $quantity_tag = 1; // if a single product type, only get the "price" merge tag if ( in_array( GFFormsModel::get_input_type( $product_field ), array( 'singleproduct', 'calculation', 'hiddenproduct' ) ) ) { // single products provide quantity merge tag if ( empty( $quantity_field ) && ! rgar( $product_field, 'disableQuantity' ) ) { $quantity_tag = $product_tags[2]['tag']; } $product_tags = array( $product_tags[1] ); } // if quantity field is provided for product, get merge tag if ( ! empty( $quantity_field ) ) { $quantity_tag = GFCommon::get_field_merge_tags( $quantity_field ); $quantity_tag = $quantity_tag[0]['tag']; } if ( is_numeric( $quantity_tag ) ) { $qty_value = $quantity_tag; } else { // extract qty input ID from the merge tag preg_match_all( '/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}/mi', $quantity_tag, $matches, PREG_SET_ORDER ); $qty_input_id = rgars( $matches, '0/1' ); $qty_value = rgpost( 'input_' . str_replace( '.', '_', $qty_input_id ) ); } if ( $filter_tags && floatval( $qty_value ) <= 0 ) { continue; } $product_tags = wp_list_pluck( $product_tags, 'tag' ); $option_tags = array(); foreach ( $option_fields as $option_field ) { if ( is_array( $option_field['inputs'] ) ) { $choice_number = 1; foreach ( $option_field['inputs'] as &$input ) { //hack to skip numbers ending in 0. so that 5.1 doesn't conflict with 5.10 if ( $choice_number % 10 == 0 ) { $choice_number ++; } $input['id'] = $option_field['id'] . '.' . $choice_number ++; } } $new_options_tags = GFCommon::get_field_merge_tags( $option_field ); if ( ! is_array( $new_options_tags ) ) { continue; } if ( GFFormsModel::get_input_type( $option_field ) == 'checkbox' ) { array_shift( $new_options_tags ); } $option_tags = array_merge( $option_tags, $new_options_tags ); } $option_tags = wp_list_pluck( $option_tags, 'tag' ); $product_tag_groups[] = '( ( ' . implode( ' + ', array_merge( $product_tags, $option_tags ) ) . ' ) * ' . $quantity_tag . ' )'; } $shipping_tag = 0; //Shipping should not be included in subtotal, correct? if ( rgar( $pricing_fields, 'shipping' ) ) { $shipping_tag = GFCommon::get_field_merge_tags( rgars( $pricing_fields, 'shipping/0' ) ); $shipping_tag = $shipping_tag[0]['tag']; } $subtotal_merge_tags = '( ( ' . implode( ' + ', $product_tag_groups ) . ' ) + ' . $shipping_tag . ' )'; return $subtotal_merge_tags; } public function has_subtotal_merge_tag( $field ) { // check if form is passed if ( isset( $field['fields'] ) ) { $form = $field; foreach ( $form['fields'] as $field ) { if ( $this->has_subtotal_merge_tag( $field ) ) { return true; } } } else { if ( isset( $field['calculationFormula'] ) && strpos( $field['calculationFormula'], '{subtotal}' ) !== false ) { return true; } } return false; } /*-------------------------------------------------------------*/ /*--------End of Subtotal Merge Tags---------------------------*/ /*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/ /*--------Start of Post Content Merge Tags---------------------*/ /*-------------------------------------------------------------*/ public function merge_tags_values_post_content( $post_content ) { $entry_time = $this->entry_time; if ( ! self::$_entry ) { $entry_id = rgget( 'entry' ); if ( $entry_id ) { if ( ( ! $entry_time ) && ( ! is_numeric( $entry_id ) || intval( $entry_id ) <= 0 ) ) { if ( method_exists( 'GFCommon', 'openssl_decrypt' ) ) { $entry_id = GFCommon::openssl_decrypt( strval( $entry_id ) ); } elseif ( method_exists( 'GFCommon', 'decrypt' ) ) { $entry_id = GFCommon::decrypt( strval( $entry_id ) ); } $entry_id = intval( $entry_id ); } } else { $post = get_post(); if ( $post ) { $entry_id = get_post_meta( $post->ID, '_gform-entry-id', true ); } } if ( $entry_id ) { $entry = self::get_entry( $entry_id ); } self::$_entry = ! empty( $entry ) && $entry ? $entry : false; } $entry = self::$_entry; if ( ! $entry ) { $post_content = $this->replace_field_label_merge_tags( $post_content, '' ); } else { if ( $entry_time ) { $confirm_time = gform_get_meta( rgar( $entry, 'id' ), 'gform_page_confirm_time' ); if ( empty( $confirm_time ) ) { gform_update_meta( $entry['id'], 'gform_page_confirm_time', time() ); } elseif ( $confirm_time + $entry_time < time() ) { return $this->replace_field_label_merge_tags( $post_content, '' ); } } $form = GFFormsModel::get_form_meta( $entry['form_id'] ); $post_content = $this->replace_field_label_merge_tags( $post_content, $form ); $post_content = GFCommon::replace_variables( $post_content, $form, $entry, false, false, false ); } return $post_content; } public function replace_field_label_merge_tags( $text, $form ) { if ( ! empty( $form ) ) { preg_match_all( '/{([^:]+?)}/', $text, $matches, PREG_SET_ORDER ); if ( empty( $matches ) ) { return $text; } foreach ( $matches as $match ) { list( $search, $field_label ) = $match; foreach ( $form['fields'] as $field ) { $matches_admin_label = rgar( $field, 'adminLabel' ) == $field_label; $matches_field_label = false; if ( is_array( $field['inputs'] ) ) { foreach ( $field['inputs'] as $input ) { if ( GFFormsModel::get_label( $field, $input['id'] ) == $field_label ) { $matches_field_label = true; $input_id = $input['id']; break; } } } else { $matches_field_label = GFFormsModel::get_label( $field ) == $field_label; $input_id = $field['id']; } if ( ! $matches_admin_label && ! $matches_field_label ) { continue; } $replace = sprintf( '{%s:%s}', $field_label, (string) $input_id ); $text = str_replace( $search, $replace, $text ); break; } } } else { /* preg_match_all( '/{[^{]*?:(\d+(\.\d+)?)(:(.*?))?}/mi', $text, $matches, PREG_SET_ORDER ); if( !empty( $matches ) ) { foreach( $matches as $match ) { if ( isset($match[0])) $text = str_replace( $match[0], '' , $text ); } } unset($matches); preg_match_all( '/{([^:]+?)}/', $text, $matches, PREG_SET_ORDER ); if( !empty( $matches ) ) { foreach( $matches as $match ) { if ( isset($match[0])) $text = str_replace( $match[0], '' , $text ); } } */ } return $text; } public function confirmation_append_entry( $confirmation, $form, $entry ) { $is_ajax_redirect = is_string( $confirmation ) && strpos( $confirmation, 'gformRedirect' ); $is_redirect = is_array( $confirmation ) && isset( $confirmation['redirect'] ); if ( ! $is_ajax_redirect && ! $is_redirect ) { return $confirmation; } $entry_id = $entry['id']; if ( ! $this->entry_time ) { if ( method_exists( 'GFCommon', 'openssl_encrypt' ) ) { $entry_id = rawurlencode( GFCommon::openssl_encrypt( strval( $entry_id ) ) ); } elseif ( method_exists( 'GFCommon', 'encrypt' ) ) { $entry_id = rawurlencode( GFCommon::encrypt( strval( $entry_id ) ) ); } } if ( $is_ajax_redirect ) { preg_match_all( '/gformRedirect.+?(http.+?)(?=\'|")/', $confirmation, $matches, PREG_SET_ORDER ); list( $full_match, $url ) = $matches[0]; $redirect_url = add_query_arg( array( 'entry' => $entry_id ), $url ); $confirmation = str_replace( $url, $redirect_url, $confirmation ); } else { $redirect_url = add_query_arg( array( 'entry' => $entry_id ), $confirmation['redirect'] ); $confirmation['redirect'] = $redirect_url; } return $confirmation; } /*-------------------------------------------------------------*/ /*--------End of Post Content Merge Tags-----------------------*/ /*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/ /*--------Start of Pre Submission Merge Tags-------------------*/ /*-------------------------------------------------------------*/ public function merge_tags_pre_submission( $form ) { if ( function_exists( 'is_checkout' ) && is_checkout() ) { return $form; } $current_page = isset( GFFormDisplay::$submission[ $form['id'] ] ) && isset( GFFormDisplay::$submission[ $form['id'] ]['page_number'] ) ? GFFormDisplay::$submission[ $form['id'] ]['page_number'] : 1; //$fields = array(); if ( empty( $form['fields'] ) || ! is_array( $form['fields'] ) ) { return $form; } // get all HTML fields on the current page foreach ( $form['fields'] as &$field ) { // skip all fields on the first page if ( rgar( $field, 'pageNumber' ) <= 1 ) { continue; } $default_value = rgar( $field, 'defaultValue' ); preg_match_all( '/{.+}/', $default_value, $matches, PREG_SET_ORDER ); if ( ! empty( $matches ) ) { // if default value needs to be replaced but is not on current page, wait until on the current page to replace it if ( rgar( $field, 'pageNumber' ) != $current_page ) { $field['defaultValue'] = ''; } else { $field['defaultValue'] = $this->preview_replace_variables( $default_value, $form ); } } // only run 'content' filter for fields on the current page if ( rgar( $field, 'pageNumber' ) != $current_page ) { continue; } $html_content = rgar( $field, 'content' ); preg_match_all( '/{.+}/', $html_content, $matches, PREG_SET_ORDER ); if ( ! empty( $matches ) ) { $field['content'] = $this->preview_replace_variables( $html_content, $form ); } } return $form; } public function preview_special_merge_tags( $value, $input_id, $merge_tag, $field ) { // added to prevent overriding :noadmin filter (and other filters that remove fields) if ( ! $value ) { return $value; } $input_type = RGFormsModel::get_input_type( $field ); $is_upload_field = in_array( $input_type, array( 'post_image', 'fileupload' ) ); $is_multi_input = is_array( rgar( $field, 'inputs' ) ); $is_input = intval( $input_id ) != $input_id; if ( ! $is_upload_field && ! $is_multi_input ) { return $value; } // if is individual input of multi-input field, return just that input value if ( $is_input ) { return $value; } $form = RGFormsModel::get_form_meta( $field['formId'] ); $entry = $this->create_entry( $form ); $currency = GFCommon::get_currency(); if ( is_array( rgar( $field, 'inputs' ) ) ) { $value = RGFormsModel::get_lead_field_value( $entry, $field ); return GFCommon::get_lead_field_display( $field, $value, $currency ); } $input_name = "input_{$field['id']}"; $file_info = RGFormsModel::get_temp_filename( $form['id'], $input_name ); $source = RGFormsModel::get_upload_url( $form['id'] ) . "/tmp/" . $file_info["temp_filename"]; $value = ''; if ( $file_info ) { switch ( RGFormsModel::get_input_type( $field ) ) { case "post_image": list( , $image_title, $image_caption, $image_description ) = explode( "|:|", $entry[ $field['id'] ] ); $value = ! empty( $source ) ? $source . "|:|" . $image_title . "|:|" . $image_caption . "|:|" . $image_description : ""; break; case "fileupload" : $value = $source; break; } } switch ( $input_type ) { case 'fileupload': if ( ! empty( $value ) ) { $input_name = "input_" . str_replace( '.', '_', $field['id'] ); $file_info = RGFormsModel::get_temp_filename( $form['id'], $input_name ); $value = esc_attr( str_replace( " ", "%20", $value ) ); $value = "" . $file_info['uploaded_filename'] . ""; } break; default: $value = GFCommon::get_lead_field_display( $field, $value, $currency ); break; } return $value; } public function preview_replace_variables( $content, $form ) { $entry = $this->create_entry( $form ); // add filter that will handle getting temporary URLs for file uploads and post image fields (removed below) // beware, the RGFormsModel::create_lead() function also triggers the gform_merge_tag_filter at some point and will // result in an infinite loop if not called first above add_filter( 'gform_merge_tag_filter', array( $this, 'preview_special_merge_tags' ), 10, 4 ); $content = GFCommon::replace_variables( $content, $form, $entry, false, false, false ); // remove filter so this function is not applied after preview functionality is complete remove_filter( 'gform_merge_tag_filter', array( $this, 'preview_special_merge_tags' ) ); return $content; } public function create_entry( $form ) { if ( empty( self::$_virual_entry ) ) { self::$_virual_entry = GFFormsModel::create_lead( $form ); if ( class_exists( 'GFCache' ) ) { foreach ( $form['fields'] as &$field ) { if ( GFFormsModel::get_input_type( $field ) == 'total' ) { GFCache::delete( 'GFFormsModel::get_lead_field_value__' . $field['id'] ); } } } } return self::$_virual_entry; } /*-------------------------------------------------------------*/ /*--------End of Pre Submission Merge Tags---------------------*/ /*-------------------------------------------------------------*/ } new GFPersian_Merge_Tags; فروشگاه سیسمونی مام باب

قیمت پاپوش سفید چسبی