PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / 3.9.4
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets v3.9.4
3.9.5 3.9.6 4.0.0 4.0.1 4.1.0 trunk 2.12 2.13 2.14 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9 3.7.0 3.7.1 3.7.2 3.7.3 3.7.3-beta-1.0 3.7.4 3.7.4-beta-1.0 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4
wp-all-import / classes / render.php
wp-all-import / classes Last commit date
XmlStreamReader 2 years ago partner-discount-sdk 1 year ago api.php 4 years ago arraytoxml.php 8 years ago chunk.php 1 year ago config.php 2 years ago download.php 13 years ago error.php 2 years ago handler.php 9 months ago helper.php 8 years ago input.php 7 years ago nested.php 4 years ago rapidaddon.php 9 months ago render.php 4 years ago session.php 9 months ago upload.php 9 months ago zip.php 10 years ago
render.php
315 lines
1 <?php
2 if ( ! class_exists('PMXI_Render')){
3
4 class PMXI_Render{
5
6 public function __construct(){
7
8 }
9
10 public static function xml_find_repeating(DOMElement $el, $path = '/')
11 {
12 $path .= $el->nodeName;
13 if ( ! $el->parentNode instanceof DOMDocument) {
14 $path .= '[1]';
15 }
16 $children = array();
17 foreach ($el->childNodes as $child) {
18 if ($child instanceof DOMElement) {
19 if ( ! empty($children[$child->nodeName])) {
20 return $path . '/' . $child->nodeName;
21 } else {
22 $children[$child->nodeName] = true;
23 }
24 }
25 }
26 // reaching this point means we didn't find anything among current element children, so recursively ask children to find something in them
27 foreach ($el->childNodes as $child) {
28 if ($child instanceof DOMElement) {
29 $result = slef::xml_find_repeating($child, $path . '/');
30 if ($result) {
31 return $result;
32 }
33 }
34 }
35 // reaching this point means we didn't find anything, so return element itself if the function was called for it
36 if ('/' . $el->nodeName == $path) {
37 return $path;
38 }
39
40 return NULL;
41 }
42
43 public static function render_csv_element(DOMElement $el, $shorten = false, $path = '/', $ind = 1, $lvl = 0)
44 {
45 $path .= $el->nodeName;
46 if ( ! $el->parentNode instanceof DOMDocument and $ind > 0) {
47 $path .= "[$ind]";
48 }
49
50 echo '<div class="xml-element csv_element lvl-' . esc_attr($lvl) . ' lvl-mod4-' . ($lvl % 4) . '" title="' . esc_attr($path) . '">';
51 if ($el->hasChildNodes()) {
52 $is_render_collapsed = $ind > 1;
53 if ($lvl) echo '<div class="csv-tag opening"><span class="csv-tag-name">' . esc_html($el->nodeName) . '</span>'; echo '</div>';
54 if (1 == $el->childNodes->length and $el->childNodes->item(0) instanceof DOMText) {
55 $child = $el->childNodes->item(0);
56 if (!empty($child->wholeText)){
57 self::render_csv_text(trim($child->wholeText), $shorten, $is_render_collapsed);
58 }
59 elseif (is_callable(array($child, 'nodeValue'), true) && isset($child->nodeValue)){
60 self::render_csv_text(trim($child->nodeValue), $shorten, $is_render_collapsed);
61 }
62 } else {
63 echo '<div class="csv-content' . ($is_render_collapsed ? ' collapsed' : '') . '">';
64 $indexes = array();
65 foreach ($el->childNodes as $child) {
66 if ($child instanceof DOMElement) {
67 empty($indexes[$child->nodeName]) and $indexes[$child->nodeName] = 0; $indexes[$child->nodeName]++;
68 self::render_csv_element($child, $shorten, $path . '/', $indexes[$child->nodeName], $lvl + 1);
69 } elseif ($child instanceof DOMText) {
70 self::render_csv_text(trim($child->wholeText), $shorten);
71 } elseif ($child instanceof DOMComment) {
72 if (preg_match('%\[pmxi_more:(\d+)\]%', $child->nodeValue, $mtch)) {
73 $no = intval($mtch[1]);
74 echo '<div class="xml-more">[ &dArr; ' . sprintf(__('<strong>%s</strong> %s more', 'wp_all_import_plugin'), $no, _n('element', 'elements', $no, 'wp_all_import_plugin')) . ' &dArr; ]</div>';
75 }
76 }
77 }
78 echo '</div>';
79 }
80 //echo '<div class="xml-tag closing"><span class="xml-tag-name">' . $el->nodeName . '</span></div>';
81 } else {
82 echo '<div class="xml-tag opening empty"><span class="xml-tag-name">' . wp_kses_post($el->nodeName) . '</span>'; self::render_xml_attributes($el); echo '</div>';
83 }
84 echo '</div>';
85 }
86
87 protected static function render_csv_text($text, $shorten = false, $is_render_collapsed = false)
88 {
89 if (empty($text) and 0 !== (int)$text) {
90 return; // do not display empty text nodes
91 }
92 if (preg_match('%\[more:(\d+)\]%', $text, $mtch)) {
93 $no = intval($mtch[1]);
94 echo '<div class="xml-more">[ &dArr; ' . sprintf(__('<strong>%s</strong> %s more', 'wp_all_import_plugin'), $no, _n('element', 'elements', $no, 'wp_all_import_plugin')) . ' &dArr; ]</div>';
95 return;
96 }
97 $more = '';
98 if ($shorten and preg_match('%^(.*?\s+){20}(?=\S)%', $text, $mtch)) {
99 $text = $mtch[0];
100 $more = '<span class="xml-more">[' . __('more', 'wp_all_import_plugin') . ']</span>';
101 }
102 $is_short = strlen($text) <= 40;
103 $newtext = htmlspecialchars($text);
104 //$newtext = preg_replace('%(?<!\s)\b(?!\s|\W[\w\s])|\w{20}%', '$0&#8203;', $newtext); // put explicit breaks for xml content to wrap
105 echo '<div class="xml-content textonly' . ($is_short ? ' short' : '') . ($is_render_collapsed ? ' collapsed' : '') . ' '. (is_numeric($text) ? 'is_numeric' : '') .'">' . wp_kses_post($newtext . $more) . '</div>';
106 }
107 public static $option_paths = array();
108 public static function render_xml_elements_for_filtring(DOMElement $el, $originPath ='', $lvl = 0){
109 $path = $originPath;
110 if ("" != $path){
111 if ($lvl > 1) $path .= "->" . $el->nodeName; else $path = $el->nodeName;
112 if (empty(self::$option_paths[$path]))
113 self::$option_paths[$path] = 1;
114 else
115 self::$option_paths[$path]++;
116 echo '<option value="'. esc_attr($path) .'['. esc_attr(self::$option_paths[$path]) .']">' . esc_html($path) . '['. esc_html(self::$option_paths[$path]) .']</option>';
117 }
118 else $path = $el->nodeName;
119
120 foreach ($el->attributes as $attr) {
121 if (empty($originPath)){
122 echo '<option value="@' . esc_attr($attr->nodeName).'">@' . esc_html($attr->nodeName) . '</option>';
123 }
124 else{
125 echo '<option value="'. esc_attr($path) .'['. esc_attr(self::$option_paths[$path]) .']'. '/@' . esc_attr($attr->nodeName).'">'. esc_html($path) .'['. esc_html(self::$option_paths[$path]) .']'. '@' . esc_html($attr->nodeName) . '</option>';
126 }
127 }
128 if ($el->hasChildNodes()) {
129 foreach ($el->childNodes as $child) {
130 if ($child instanceof DOMElement)
131 self::render_xml_elements_for_filtring($child, $path, $lvl + 1);
132 }
133 }
134 }
135
136 public static function render_xml_element(DOMElement $el, $shorten = false, $path = '/', $ind = 1, $lvl = 0)
137 {
138 $render_whole_tree = apply_filters('wp_all_import_is_render_whole_xml_tree', true);
139
140 $path .= $el->nodeName;
141 $alternativePath = $path;
142 if ( ! $el->parentNode instanceof DOMDocument and $ind > 0) {
143 $path .= "[$ind]";
144 }
145
146 echo '<div class="xml-element lvl-' . esc_attr($lvl) . ' lvl-mod4-' . esc_attr($lvl % 4) . '" title="' . esc_attr($path) . '">';
147 //if ($el->hasAttributes()){
148 echo '<div class="xml-element-xpaths">'; self::render_element_xpaths($el, $alternativePath, $ind, $lvl); echo '</div>';
149 //}
150 if ($el->hasChildNodes()) {
151 $is_render_collapsed = $ind > 1;
152 if ($el->childNodes->length > 1 or ! $el->childNodes->item(0) instanceof DOMText or strlen(trim($el->childNodes->item(0)->wholeText)) > 40) {
153 echo '<div class="xml-expander">' . ($is_render_collapsed ? '+' : '-') . '</div>';
154 }
155 echo '<div class="xml-tag opening">&lt;<span class="xml-tag-name">' . esc_html($el->nodeName) . '</span>'; self::render_xml_attributes($el, $path . '/'); echo '&gt;</div>';
156 if (1 == $el->childNodes->length and $el->childNodes->item(0) instanceof DOMText) {
157 $item = $el->childNodes->item(0);
158 if (!empty($item->wholeText)){
159 self::render_xml_text(trim($item->wholeText), $shorten, $is_render_collapsed);
160 }
161 else{
162 self::render_xml_text(trim($item->nodeValue), $shorten, $is_render_collapsed);
163 }
164 } else {
165 echo '<div class="xml-content' . ($is_render_collapsed ? ' collapsed' : '') . '">';
166 $indexes = array();
167 foreach ($el->childNodes as $eli => $child) {
168 if ($child instanceof DOMElement) {
169 empty($indexes[$child->nodeName]) and $indexes[$child->nodeName] = 0; $indexes[$child->nodeName]++;
170 if ( $render_whole_tree || $indexes[$child->nodeName] === 1){
171 self::render_xml_element($child, $shorten, $path . '/', $indexes[$child->nodeName], $lvl + 1);
172 }
173 } elseif ($child instanceof DOMCdataSection) {
174 self::render_xml_text(trim($child->wholeText), $shorten, false, true);
175 } elseif ($child instanceof DOMText) {
176 if ( $el->childNodes->item($eli - 1) and ($el->childNodes->item($eli - 1) instanceof DOMCdataSection) ){
177
178 }
179 elseif( $el->childNodes->item($eli + 1) and ($el->childNodes->item($eli + 1) instanceof DOMCdataSection) ){
180
181 }
182 else{
183 self::render_xml_text(trim($child->wholeText), $shorten);
184 }
185 } elseif ($child instanceof DOMComment) {
186 if (preg_match('%\[pmxi_more:(\d+)\]%', $child->nodeValue, $mtch)) {
187 $no = intval($mtch[1]);
188 echo '<div class="xml-more">[ &dArr; ' . sprintf(__('<strong>%s</strong> %s more', 'wp_all_import_plugin'), $no, _n('element', 'elements', $no, 'wp_all_import_plugin')) . ' &dArr; ]</div>';
189 }
190 }
191 }
192 echo '</div>';
193 }
194 echo '<div class="xml-tag closing">&lt;/<span class="xml-tag-name">' . esc_html($el->nodeName) . '</span>&gt;</div>';
195 } else {
196 echo '<div class="xml-tag opening empty">&lt;<span class="xml-tag-name">' . esc_html($el->nodeName) . '</span>'; self::render_xml_attributes($el); echo '/&gt;</div>';
197 }
198 echo '</div>';
199 }
200
201 protected static function render_xml_text($text, $shorten = false, $is_render_collapsed = false, $is_cdata = false)
202 {
203 if (empty($text) and 0 !== (int)$text) {
204 return; // do not display empty text nodes
205 }
206 if (preg_match('%\[more:(\d+)\]%', $text, $mtch)) {
207 $no = intval($mtch[1]);
208 echo '<div class="xml-more">[ &dArr; ' . sprintf(__('<strong>%s</strong> %s more', 'wp_all_import_plugin'), $no, _n('element', 'elements', $no, 'wp_all_import_plugin')) . ' &dArr; ]</div>';
209 return;
210 }
211 $more = '';
212 if ($shorten and preg_match('%^(.*?\s+){20}(?=\S)%', $text, $mtch)) {
213 $text = $mtch[0];
214 $more = '<span class="xml-more">[' . __('more', 'wp_all_import_plugin') . ']</span>';
215 }
216 $is_short = strlen($text) <= 40;
217 $text = htmlspecialchars($text);
218 if ($is_cdata){
219 $text = "<span class='wpallimport-cdata'>" . htmlspecialchars("<![CDATA[") . "</span> " . $text . " <span class='wpallimport-cdata'>" . htmlspecialchars("]]>") . "</span>";
220 }
221 //$text = preg_replace('%(?<!\s)\b(?!\s|\W[\w\s])|\w{20}%', '$0&#8203;', $text); // put explicit breaks for xml content to wrap
222 echo '<div class="xml-content textonly' . ($is_short ? ' short' : '') . ($is_render_collapsed ? ' collapsed' : '') . '">' . esc_html($text . $more) . '</div>';
223 }
224
225 public static function get_xml_path(DOMElement $el, DOMXPath $xpath)
226 {
227 for($p = '', $doc = $el; $doc and ! $doc instanceof DOMDocument; $doc = $doc->parentNode) {
228 if (($ind = $xpath->query('preceding-sibling::' . $doc->nodeName, $doc)->length)) {
229 $p = '[' . ++$ind . ']' . $p;
230 } elseif ( ! $doc->parentNode instanceof DOMDocument) {
231 $p = '[' . ($ind = 1) . ']' . $p;
232 }
233 $p = '/' . $doc->nodeName . $p;
234 }
235 return $p;
236 }
237
238 protected static function render_xml_attributes(DOMElement $el, $path = '/')
239 {
240 foreach ($el->attributes as $attr) {
241 echo ' <span class="xml-attr" title="' . esc_attr($path) . '@' . esc_attr($attr->nodeName) . '"><span class="xml-attr-name">' . esc_html($attr->nodeName) . '</span>=<span class="xml-attr-value">"' . esc_attr($attr->value) . '"</span></span>';
242 }
243 }
244
245 protected static function render_element_xpaths(DOMElement $el, $path = '/', $ind = 1, $lvl = 0){
246 ?>
247 <ul id="menu-<?php echo str_replace('/', '-', esc_attr($path)); ?>" class="ui-helper-hidden">
248 <?php foreach ($el->attributes as $attr) : if ( empty($attr->value) ) continue; ?>
249 <li data-command="action1" title="<?php echo esc_attr($path . '[@'. $attr->nodeName .' = "' . $attr->value . '"]'); ?>">
250 <a href="#"><?php echo wp_kses_post($path . '[@'. $attr->nodeName .' = "' . $attr->value) . '"]'; ?></a>
251 </li>
252 <li data-command="action2" title="<?php echo esc_attr($path . '[@'. $attr->nodeName .'[contains(.,"' . $attr->value . '")]]'); ?>">
253 <a href="#"><?php echo wp_kses_post($path . '[@'. $attr->nodeName .'[contains(.,"' . $attr->value) . '")]]'; ?></a>
254 </li>
255 <?php endforeach; ?>
256 <?php
257 $altNode = null;
258 $altNodeText = null;
259 $parentNode = $el->parentNode;
260 $grandNode = $parentNode->parentNode;
261
262 if ( ! $grandNode instanceof DOMDocument and $grandNode instanceof DOMElement ){
263
264 $equalsElements = 0;
265 foreach ($grandNode->childNodes as $child) {
266 if ($child instanceof DOMElement) {
267 if ($child->nodeName == $parentNode->nodeName){
268 $equalsElements++;
269 if ($equalsElements > 1)
270 break;
271 }
272 }
273 }
274
275 if ($equalsElements > 1){
276 if ($parentNode->hasChildNodes()) {
277 foreach ($parentNode->childNodes as $i => $child) {
278 if ($child instanceof DOMElement) {
279 if ($child->nodeName != $el->nodeName){
280 $altNode = $child;
281 if ($child->hasChildNodes()){
282 foreach ($child->childNodes as $i => $txtChild) {
283 if ($txtChild instanceof DOMText) {
284 $altNodeText = $txtChild;
285 break;
286 }
287 }
288 }
289 break;
290 }
291 }
292 }
293 }
294
295 if ( ! empty($altNode) and !empty($altNodeText) ){
296
297 $pathArgs = explode('/', $path);
298 array_pop($pathArgs);
299 array_pop($pathArgs);
300 $vpath = esc_attr(implode('/', $pathArgs) . '/' . $parentNode->nodeName . '[contains('. $altNode->nodeName .',"' . esc_attr($altNodeText->wholeText) . '")]/' . $el->nodeName);
301 ?>
302 <li data-command="action3" title="<?php echo esc_attr($vpath); ?>">
303 <a href="#"><?php echo esc_html($vpath); ?></a>
304 </li>
305 <?php
306
307 }
308 }
309 }
310 ?>
311 </ul>
312 <?php
313 }
314 }
315 }