PluginProbe
Contact Forms by Cimatti / trunk
Contact Forms by Cimatti vtrunk
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / AccuaConditionalReplacer.php

AccuaConditionalReplacer.php in Contact Forms by Cimatti trunk, at AccuaConditionalReplacer.php

68 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3
4 if (!class_exists('AccuaConditionalReplacer')) {
5 class AccuaConditionalReplacer {
6 protected $map = array();
7 protected $search = null;
8 protected $replace = null;
9 protected $matches = null;
10
11 function __construct(array $map = array()){
12 $this->map = $map;
13 }
14
15 function appendPattern(array $map = array()){
16 $this->map = $map + $this->map;
17 $this->search = null;
18 $this->replace = null;
19 $this->matches = null;
20 }
21
22 function setPattern(array $map = array()){
23 $this->map = $map;
24 $this->search = null;
25 $this->replace = null;
26 $this->matches = null;
27 }
28
29 function doReplace($subject) {
30 if ($this->matches === null){
31 $this->search = array();
32 $this->replace = array();
33 $this->matches = array();
34 foreach ($this->map as $s => $r) {
35 $s = (string) $s;
36 $r = (string) $r;
37 $this->search[] = '{'.$s.'}';
38 $this->replace[] = $r;
39 if (trim($r) !== '') {
40 $this->matches[$s] = true;
41 }
42 }
43 }
44
45 return str_replace($this->search, $this->replace, preg_replace_callback(
46 // /\[\s*newsletter_if\s*(\{[^\}]*\})\s*(then)?\s*("[^"]*"|'[^']*')\s*((else)?\s*("[^"]*"|'[^']*'))?\]/ims
47 //'/\\[\\s*newsletter_if\\s*(\\{[^\\}]*\\})\\s*(then)?\\s*("[^"]*"|\'[^\']*\')\\s*((else)?\\s*("[^"]*"|\'[^\']*\'))?\\]/ims',
48 // /\[\s*newsletter_if\s*(\{[^\}]*\})\s*(then|\?)?\s*("[^"]*"|'[^']*'|`[^`]*`|\[[^\]]*\])\s*((else|\:)?\s*("[^"]*"|'[^']*'|`[^`]*`|\[[^\]]*\]))?\s*\]/ims
49 '/\\[\\s*(accua_if|newsletter_if|form_if)\\s*\\{([^\\}]*)\\}\\s*(then|\\?)?\\s*("[^"]*"|\'[^\']*\'|`[^`]*`|\\[[^\\]]*\\])\\s*((else|\\:)?\\s*("[^"]*"|\'[^\']*\'|`[^`]*`|\\[[^\\]]*\\]))?\\s*\\]/is',
50 array($this, '_doReplaceMatch'),
51 $subject
52 ));
53
54 }
55
56 function _doReplaceMatch($match){
57 if (isset($match[2]) && isset($this->matches[$match[2]])){
58 @ $ret = $match[4];
59 } else {
60 @ $ret = $match[7];
61 }
62 if (is_string($ret) && strlen($ret) > 2){
63 return substr($ret,1,-1);
64 }
65 return '';
66 }
67 }
68 }