PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / trunk
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel vtrunk
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 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 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / libraries / WpaeString.php
wp-all-export / libraries Last commit date
VariableProductTitle 4 weeks ago .gitkeep 10 years ago WpaeInvalidPhpException.php 9 years ago WpaeInvalidStringException.php 9 years ago WpaeMethodNotFoundException.php 9 years ago WpaePhpInterpreterErrorHandler.php 4 weeks ago WpaeString.php 8 years ago WpaeTooMuchRecursionException.php 9 years ago XmlCsvExport.php 4 weeks ago XmlExportCpt.php 4 weeks ago XmlExportCustomRecord.php 4 weeks ago XmlExportEngine.php 4 weeks ago XmlExportFiltering.php 4 weeks ago XmlExportMediaGallery.php 4 weeks ago XmlExportTaxonomy.php 4 weeks ago
WpaeString.php
153 lines
1 <?php
2
3
4 class WpaeString
5 {
6 const MIDDLE_COMMA = "*middlecomma*";
7
8 public function isBetween($haystack, $search, $start, $end)
9 {
10 if($haystack == $search) {
11 return false;
12 }
13 if (strpos($haystack, $start) === false) {
14 return false;
15 }
16
17 $haystack = str_replace($search, "#SNIPPET#", $haystack);
18 $search = "#SNIPPET#";
19
20 $searchPosition = strpos($haystack, $search);
21
22 $firstString = substr($haystack, 0, $searchPosition);
23 $lastString = substr($haystack, $searchPosition + strlen($search), strlen($haystack));
24
25 $isInFirstString = false;
26 $isInLastString = false;
27
28 // Make sure the number of strings in the part before and after is not equal
29 // to exclude cases like [a]b[c] we want only cases like a[b]c
30 $numberOfStartInFirstString = substr_count($firstString, $start);
31 $numberOfEndInFirstString = substr_count($firstString, $end);
32
33 $numberOfStartInLastString = substr_count($lastString, $start);
34 $numberOfEndInLastString = substr_count($lastString, $end);
35
36 if(strpos($firstString, $start) !== false && $numberOfStartInFirstString - $numberOfEndInFirstString) {
37 $isInFirstString = true;
38 }
39
40 if(strpos($lastString, $end) !== false && $numberOfStartInLastString - $numberOfEndInLastString) {
41 $isInLastString = true;
42 }
43
44 return $isInFirstString && $isInLastString;
45 }
46
47 /**
48 * @param $sanitizedSnippet
49 * @return mixed
50 */
51 public function quoteParams($sanitizedSnippet)
52 {
53 if(strpos($sanitizedSnippet, 'array') !== false) {
54 return $sanitizedSnippet;
55 }
56
57 if(strpos($sanitizedSnippet, WpaeXmlProcessor::SNIPPET_DELIMITER) === false && strpos($sanitizedSnippet, '"') === false && strpos($sanitizedSnippet, "'") === false ) {
58 $sanitizedSnippet = str_replace("(","(\"",$sanitizedSnippet);
59 $sanitizedSnippet = str_replace(")","\")",$sanitizedSnippet);
60
61 return $sanitizedSnippet;
62 }
63
64 $sanitizedSnippet = str_replace(WpaeXmlProcessor::SNIPPET_DELIMITER, '"', $sanitizedSnippet);
65
66 $sanitizedString = "";
67
68 $isInString = false;
69
70 for($i=0; $i< strlen($sanitizedSnippet); $i++) {
71 if($sanitizedSnippet[$i] == "\"") {
72 if($isInString) {
73 $isInString = false;
74 } else {
75 $isInString = true;
76 }
77
78 }
79
80 if($sanitizedSnippet[$i] === "," && $isInString) {
81 $sanitizedString.= self::MIDDLE_COMMA;
82 } else {
83 $sanitizedString .= $sanitizedSnippet[$i];
84 }
85 }
86
87 $sanitizedSnippet = $sanitizedString;
88
89 if(strpos($sanitizedSnippet,"(") !== false && strpos($sanitizedSnippet, ")") !== false) {
90
91 $sanitizedSnippet = str_replace("()", '("")', $sanitizedSnippet);
92 $parts = explode("(", $sanitizedSnippet);
93 if (!isset($parts[1])) {
94 //TODO: Can this happen?
95 }
96 $params = $parts[1];
97 $parameterPart = $parts[1];
98 $originalParameterPart = $parts[1];
99
100 $params = explode(")", $params);
101 $params = $params[0];
102
103 if (strpos($params, ",") !== false) {
104 $params = explode(",", $params);
105 } else {
106 $params = array($params);
107 }
108
109 foreach ($params as $param) {
110 if (!preg_match('/".*"/', $param)) {
111 $parameterPart = str_replace(','.$param, ',"' .trim($param) . '"', $parameterPart);
112 $parameterPart = str_replace('('.$param, '("' .trim($param) . '"', $parameterPart);
113 }
114 }
115
116 $sanitizedSnippet = str_replace($originalParameterPart, $parameterPart, $sanitizedSnippet);
117 }
118
119 $sanitizedSnippet = str_replace(self::MIDDLE_COMMA, ',', $sanitizedSnippet);
120
121 return $sanitizedSnippet;
122 }
123
124 /**
125 * @param $sanitizedSnippet
126 * @return string
127 */
128 private function quoteStringWithTokenizer($sanitizedSnippet)
129 {
130 $sanitizedSnippet = explode("(", $sanitizedSnippet);
131 $functionName = $sanitizedSnippet[0];
132 $sanitizedSnippet = $sanitizedSnippet[1];
133 $sanitizedSnippet = str_replace(')', '', $sanitizedSnippet);
134
135 $tokens = token_get_all('<?php ' . $sanitizedSnippet . ' ?>');
136
137 $sanitizedString = "";
138
139 foreach ($tokens as $token) {
140 if ($token[0] == 319) {
141 $sanitizedString .= '"' . $token[1] . '",';
142 }
143 if ($token[0] == 323) {
144 $sanitizedString .= $token[1] . ',';
145 }
146 }
147
148 $sanitizedString = substr($sanitizedString, 0, -1);
149 $sanitizedString = $functionName . '(' . $sanitizedSnippet . ')';
150
151 return $sanitizedString;
152 }
153 }