PluginProbe
Contact Forms by Cimatti / 1.4.1
Contact Forms by Cimatti v1.4.1
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 1.4.1, at AccuaConditionalReplacer.php

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