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 3.9-beta 3.9.1 3.9.2 3.9.3 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1-beta 4.1.1 4.1.2 4.2 4.2-beta 4.2.1 4.2.2 4.3 4.3.1 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6 4.6.1 4.7 4.8 4.8.1 4.9 4.9.1 4.9.2 5.0 5.0.1
contact-form-7 / includes / pipe.php
contact-form-7 / includes Last commit date
block-editor 1 year ago config-validator 11 months ago css 11 months ago js 1 year ago swv 11 months ago capabilities.php 7 years ago contact-form-functions.php 11 months ago contact-form-template.php 11 months ago contact-form.php 11 months ago controller.php 11 months ago file.php 11 months ago filesystem.php 11 months ago form-tag.php 11 months ago form-tags-manager.php 11 months ago formatting.php 11 months ago functions.php 11 months ago html-formatter.php 11 months ago integration.php 11 months ago l10n.php 11 months ago mail-tag.php 11 months ago mail.php 11 months ago pipe.php 11 months ago pocket-holder.php 3 years ago rest-api.php 11 months ago shortcodes.php 11 months ago special-mail-tags.php 1 year ago submission.php 11 months ago upgrade.php 11 months ago validation-functions.php 11 months ago validation.php 11 months ago
pipe.php
150 lines
1 <?php
2 /**
3 * Pipe-related classes.
4 *
5 * @link https://contactform7.com/selectable-recipient-with-pipes/
6 */
7
8
9 /**
10 * Class representing a pair of pipe.
11 */
12 class WPCF7_Pipe {
13
14 public $before = '';
15 public $after = '';
16
17 public function __construct( $text ) {
18 $text = (string) $text;
19
20 $pipe_pos = strpos( $text, '|' );
21
22 if ( false === $pipe_pos ) {
23 $this->before = $this->after = wpcf7_strip_whitespaces( $text );
24 } else {
25 $this->before = wpcf7_strip_whitespaces( substr( $text, 0, $pipe_pos ) );
26 $this->after = wpcf7_strip_whitespaces( substr( $text, $pipe_pos + 1 ) );
27 }
28 }
29 }
30
31
32 /**
33 * Class representing a list of pipes.
34 */
35 class WPCF7_Pipes {
36
37 private $pipes = array();
38
39 public function __construct( $texts = null ) {
40 foreach ( (array) $texts as $text ) {
41 $this->add_pipe( $text );
42 }
43 }
44
45 private function add_pipe( $text ) {
46 $pipe = new WPCF7_Pipe( $text );
47 $this->pipes[] = $pipe;
48 }
49
50 public function merge( self $another ) {
51 $this->pipes = array_merge( $this->pipes, $another->pipes );
52 }
53
54 public function do_pipe( $input ) {
55 $input_canonical = wpcf7_canonicalize( $input, array(
56 'strto' => 'as-is',
57 ) );
58
59 foreach ( $this->pipes as $pipe ) {
60 $before_canonical = wpcf7_canonicalize( $pipe->before, array(
61 'strto' => 'as-is',
62 ) );
63
64 if ( $input_canonical === $before_canonical ) {
65 return $pipe->after;
66 }
67 }
68
69 return $input;
70 }
71
72 public function collect_befores() {
73 $befores = array();
74
75 foreach ( $this->pipes as $pipe ) {
76 $befores[] = $pipe->before;
77 }
78
79 return $befores;
80 }
81
82 public function collect_afters() {
83 $afters = array();
84
85 foreach ( $this->pipes as $pipe ) {
86 $afters[] = $pipe->after;
87 }
88
89 return $afters;
90 }
91
92 public function zero() {
93 return empty( $this->pipes );
94 }
95
96 public function random_pipe() {
97 if ( $this->zero() ) {
98 return null;
99 }
100
101 return $this->pipes[array_rand( $this->pipes )];
102 }
103
104 public function to_array() {
105 return array_map(
106 static function ( WPCF7_Pipe $pipe ) {
107 return array(
108 $pipe->before,
109 $pipe->after,
110 );
111 },
112 $this->pipes
113 );
114 }
115 }
116
117
118 /**
119 * Trait for classes that hold cross-tag WPCF7_Pipes object.
120 */
121 trait WPCF7_PipesHolder {
122
123 protected $pipes;
124
125 public function get_pipes( $field_name ) {
126 if ( isset( $this->pipes[$field_name] ) ) {
127 return $this->pipes[$field_name];
128 }
129
130 $result = new WPCF7_Pipes();
131
132 $tags = $this->scan_form_tags( array(
133 'name' => $field_name,
134 ) );
135
136 foreach ( $tags as $tag ) {
137 if ( $tag->pipes instanceof WPCF7_Pipes ) {
138 $result->merge( $tag->pipes );
139 }
140 }
141
142 return $this->pipes[$field_name] = $result;
143 }
144
145 public function scan_form_tags() {
146 return array();
147 }
148
149 }
150