css
12 years ago
js
12 years ago
capabilities.php
13 years ago
classes.php
12 years ago
controller.php
12 years ago
deprecated.php
14 years ago
formatting.php
12 years ago
functions.php
12 years ago
pipe.php
12 years ago
shortcodes.php
12 years ago
pipe.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | class WPCF7_Pipe { |
| 4 | |
| 5 | var $before = ''; |
| 6 | var $after = ''; |
| 7 | |
| 8 | function WPCF7_Pipe( $text ) { |
| 9 | $pipe_pos = strpos( $text, '|' ); |
| 10 | if ( false === $pipe_pos ) { |
| 11 | $this->before = $this->after = trim( $text ); |
| 12 | } else { |
| 13 | $this->before = trim( substr( $text, 0, $pipe_pos ) ); |
| 14 | $this->after = trim( substr( $text, $pipe_pos + 1 ) ); |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | class WPCF7_Pipes { |
| 20 | |
| 21 | var $pipes = array(); |
| 22 | |
| 23 | function WPCF7_Pipes( $texts ) { |
| 24 | if ( ! is_array( $texts ) ) |
| 25 | return; |
| 26 | |
| 27 | foreach ( $texts as $text ) { |
| 28 | $this->add_pipe( $text ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | function add_pipe( $text ) { |
| 33 | $pipe = new WPCF7_Pipe( $text ); |
| 34 | $this->pipes[] = $pipe; |
| 35 | } |
| 36 | |
| 37 | function do_pipe( $before ) { |
| 38 | foreach ( $this->pipes as $pipe ) { |
| 39 | if ( $pipe->before == $before ) |
| 40 | return $pipe->after; |
| 41 | } |
| 42 | return $before; |
| 43 | } |
| 44 | |
| 45 | function collect_befores() { |
| 46 | $befores = array(); |
| 47 | |
| 48 | foreach ( $this->pipes as $pipe ) { |
| 49 | $befores[] = $pipe->before; |
| 50 | } |
| 51 | |
| 52 | return $befores; |
| 53 | } |
| 54 | |
| 55 | function zero() { |
| 56 | return empty( $this->pipes ); |
| 57 | } |
| 58 | |
| 59 | function random_pipe() { |
| 60 | if ( $this->zero() ) |
| 61 | return null; |
| 62 | |
| 63 | return $this->pipes[array_rand( $this->pipes )]; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | ?> |