PluginProbe
WPBot – ChatBot Conversational Forms / 1.2.0
WPBot – ChatBot Conversational Forms v1.2.0
1.5.0 1.4.8 1.4.7 trunk 0.9.2 0.9.3 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.6 1.1.7 1.1.8 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 All 36 releases
conversational-forms / classes / magic.php

magic.php in WPBot – ChatBot Conversational Forms 1.2.0, at classes/magic.php

119 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main class for magic tag parsing (or will be someday)
4 *
5 * @package Caldera_Forms Modified by QuantumCloud
6 * @author Josh Pollock <Josh@CalderaWP.com>
7 * @license GPL-2.0+
8 * @link
9 * @copyright 2017 CalderaWP LLC
10 */
11 class Qcformbuilder_Forms_Magic {
12
13 /**
14 * Qcformbuilder_Forms_Magic constructor.
15 *
16 * @since 1.5.0
17 */
18 public function __construct() {
19 add_filter( 'qcformbuilder_forms_pre_do_field_magic', array( $this, 'field_magic' ), 10, 5 );
20
21 }
22
23
24 /**
25 * Add special magic tags
26 *
27 * @uses "qcformbuilder_forms_pre_do_field_magic"
28 *
29 * @since 1.5.0
30 *
31 * @param $_value
32 * @param $value
33 * @param $matches
34 * @param $entry_id
35 * @param $form
36 *
37 * @return mixed
38 */
39 public function field_magic( $_value, $value, $matches, $entry_id, $form ){
40 if( empty( $form ) ){
41 global $form;
42 }
43
44 if( ! empty( $matches ) && ! empty( $matches[1] ) && ! empty( $matches[1][0]) ){
45
46 //Set default $form value to be an empty array (prevents option labels that use magic tags to break entry viewer)
47 if ( $form === null ){
48 $form = array();
49 }
50
51 if ( Qcformbuilder_Forms_Field_Util::has_field_type( 'credit_card_exp', $form ) ) {
52 $split = Qcformbuilder_Forms_Magic_Util::split_tags( $matches[1][0] );
53 if( is_array( $split ) && ! empty( $split[1] ) && in_array( $split[1], array( 'month', 'year' ) ) ){
54 $field = Qcformbuilder_Forms_Field_Util::get_field_by_slug( $split[0], $form );
55 $type = Qcformbuilder_Forms_Field_Util::get_type( $field, $form );
56 if ( 'credit_card_exp' == $type ) {
57 $_value = $this->expiration_magic( $value, $matches, $entry_id, $form );
58 }
59 }
60
61 }
62
63 }
64
65 return $_value;
66
67 }
68
69 /**
70 * Allows use of %field_slug:year% and %field_slug"month% magic tags for credit card expiration fields
71 *
72 * @since 1.5.0
73 *
74 * @param string $value Content to act on
75 * @param array $matches Preg matches
76 * @param int $entry_id Entry ID
77 * @param array $form Form config
78 *
79 * @return mixed
80 */
81 protected function expiration_magic( $value, $matches, $entry_id, $form ) {
82 $_value = '';
83 foreach ( $matches[ 1 ] as $match ) {
84 foreach (
85 array(
86 ':year',
87 ':month'
88 ) as $semi
89 ) {
90 if ( false !== strpos( $value, $semi ) ) {
91 $split = Qcformbuilder_Forms_Magic_Util::split_tags( $match );
92 $field = Qcformbuilder_Forms_Field_Util::get_field_by_slug( $split[ 0 ], $form );
93 if ( ! empty( $field ) ) {
94 $field_value = Qcformbuilder_Forms::get_field_data( $field[ 'ID' ], $form, $entry_id );
95 if ( is_string( $field_value ) && false !== strpos( $field_value, '/' ) ) {
96 $parts = explode( '/', $field_value );
97 switch ( $semi ) {
98 case ':year':
99 $tag = '%' . $field[ 'slug' ] . ':year' . '%';
100 $_value = str_replace( $tag, trim( $parts[ 1 ] ), $value );
101 break;
102 case ':month':
103 $tag = '%' . $field[ 'slug' ] . ':month' . '%';
104 $_value = str_replace( $tag, trim( $parts[ 0 ] ), $value );
105 break;
106 }
107 }
108 }
109 }
110 }
111 }
112
113 return $_value;
114 }
115
116
117
118
119 }