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

64 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 $this->search[] = '{'.$s.'}';
34 $this->replace[] = $r;
35 if (trim($r) !== '') {
36 $this->matches[$s] = true;
37 }
38 }
39 }
40
41 return str_replace($this->search, $this->replace, preg_replace_callback(
42 // /\[\s*newsletter_if\s*(\{[^\}]*\})\s*(then)?\s*("[^"]*"|'[^']*')\s*((else)?\s*("[^"]*"|'[^']*'))?\]/ims
43 //'/\\[\\s*newsletter_if\\s*(\\{[^\\}]*\\})\\s*(then)?\\s*("[^"]*"|\'[^\']*\')\\s*((else)?\\s*("[^"]*"|\'[^\']*\'))?\\]/ims',
44 // /\[\s*newsletter_if\s*(\{[^\}]*\})\s*(then|\?)?\s*("[^"]*"|'[^']*'|`[^`]*`|\[[^\]]*\])\s*((else|\:)?\s*("[^"]*"|'[^']*'|`[^`]*`|\[[^\]]*\]))?\s*\]/ims
45 '/\\[\\s*(accua_if|newsletter_if|form_if)\\s*\\{([^\\}]*)\\}\\s*(then|\\?)?\\s*("[^"]*"|\'[^\']*\'|`[^`]*`|\\[[^\\]]*\\])\\s*((else|\\:)?\\s*("[^"]*"|\'[^\']*\'|`[^`]*`|\\[[^\\]]*\\]))?\\s*\\]/is',
46 array($this, '_doReplaceMatch'),
47 $subject
48 ));
49
50 }
51
52 function _doReplaceMatch($match){
53 if (isset($match[2]) && isset($this->matches[$match[2]])){
54 @ $ret = $match[4];
55 } else {
56 @ $ret = $match[7];
57 }
58 if (is_string($ret) && strlen($ret) > 2){
59 return substr($ret,1,-1);
60 }
61 return '';
62 }
63 }
64 }