PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / 3.3.2
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets v3.3.2
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
PHPExcel 10 years ago PHPExcel.php 10 years ago api.php 10 years ago arraytoxml.php 10 years ago chunk.php 10 years ago config.php 10 years ago download.php 10 years ago handler.php 10 years ago helper.php 10 years ago input.php 10 years ago render.php 10 years ago session.php 10 years ago upload.php 10 years ago
render.php
290 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-' . $lvl . ' lvl-mod4-' . ($lvl % 4) . '" title="' . $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">' . $el->nodeName . '</span>'; echo '</div>';
54 if (1 == $el->childNodes->length and $el->childNodes->item(0) instanceof DOMText) {
55 self::render_csv_text(trim($el->childNodes->item(0)->wholeText), $shorten, $is_render_collapsed);
56 } else {
57 echo '<div class="csv-content' . ($is_render_collapsed ? ' collapsed' : '') . '">';
58 $indexes = array();
59 foreach ($el->childNodes as $child) {
60 if ($child instanceof DOMElement) {
61 empty($indexes[$child->nodeName]) and $indexes[$child->nodeName] = 0; $indexes[$child->nodeName]++;
62 self::render_csv_element($child, $shorten, $path . '/', $indexes[$child->nodeName], $lvl + 1);
63 } elseif ($child instanceof DOMText) {
64 self::render_csv_text(trim($child->wholeText), $shorten);
65 } elseif ($child instanceof DOMComment) {
66 if (preg_match('%\[pmxi_more:(\d+)\]%', $child->nodeValue, $mtch)) {
67 $no = intval($mtch[1]);
68 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>';
69 }
70 }
71 }
72 echo '</div>';
73 }
74 //echo '<div class="xml-tag closing"><span class="xml-tag-name">' . $el->nodeName . '</span></div>';
75 } else {
76 echo '<div class="xml-tag opening empty"><span class="xml-tag-name">' . $el->nodeName . '</span>'; self::render_xml_attributes($el); echo '</div>';
77 }
78 echo '</div>';
79 }
80
81 protected static function render_csv_text($text, $shorten = false, $is_render_collapsed = false)
82 {
83 if (empty($text) and 0 !== (int)$text) {
84 return; // do not display empty text nodes
85 }
86 if (preg_match('%\[more:(\d+)\]%', $text, $mtch)) {
87 $no = intval($mtch[1]);
88 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>';
89 return;
90 }
91 $more = '';
92 if ($shorten and preg_match('%^(.*?\s+){20}(?=\S)%', $text, $mtch)) {
93 $text = $mtch[0];
94 $more = '<span class="xml-more">[' . __('more', 'wp_all_import_plugin') . ']</span>';
95 }
96 $is_short = strlen($text) <= 40;
97 $newtext = htmlspecialchars($text);
98 //$newtext = preg_replace('%(?<!\s)\b(?!\s|\W[\w\s])|\w{20}%', '$0&#8203;', $newtext); // put explicit breaks for xml content to wrap
99 echo '<div class="xml-content textonly' . ($is_short ? ' short' : '') . ($is_render_collapsed ? ' collapsed' : '') . ' '. (is_numeric($text) ? 'is_numeric' : '') .'">' . $newtext . $more . '</div>';
100 }
101
102 public static function render_xml_elements_for_filtring(DOMElement $el, $path ='', $lvl = 0){
103
104 if ("" != $path){
105 if ($lvl > 1) $path .= "->" . $el->nodeName; else $path = $el->nodeName;
106 echo '<option value="'.$path.'['. $lvl .']">' .$path . '['. $lvl .']</option>';
107 }
108 else $path = $el->nodeName;
109
110 foreach ($el->attributes as $attr) {
111 echo '<option value="'.$path . '@' . $attr->nodeName.'">'. $path . '@' . $attr->nodeName . '</option>';
112 }
113 if ($el->hasChildNodes()) {
114 foreach ($el->childNodes as $child) {
115 if ($child instanceof DOMElement)
116 self::render_xml_elements_for_filtring($child, $path, $lvl + 1);
117 }
118 }
119 }
120
121 public static function render_xml_element(DOMElement $el, $shorten = false, $path = '/', $ind = 1, $lvl = 0)
122 {
123 $path .= $el->nodeName;
124 $alternativePath = $path;
125 if ( ! $el->parentNode instanceof DOMDocument and $ind > 0) {
126 $path .= "[$ind]";
127 }
128
129 echo '<div class="xml-element lvl-' . $lvl . ' lvl-mod4-' . ($lvl % 4) . '" title="' . $path . '">';
130 //if ($el->hasAttributes()){
131 echo '<div class="xml-element-xpaths">'; self::render_element_xpaths($el, $alternativePath, $ind, $lvl); echo '</div>';
132 //}
133 if ($el->hasChildNodes()) {
134 $is_render_collapsed = $ind > 1;
135 if ($el->childNodes->length > 1 or ! $el->childNodes->item(0) instanceof DOMText or strlen(trim($el->childNodes->item(0)->wholeText)) > 40) {
136 echo '<div class="xml-expander">' . ($is_render_collapsed ? '+' : '-') . '</div>';
137 }
138 echo '<div class="xml-tag opening">&lt;<span class="xml-tag-name">' . $el->nodeName . '</span>'; self::render_xml_attributes($el, $path . '/'); echo '&gt;</div>';
139 if (1 == $el->childNodes->length and $el->childNodes->item(0) instanceof DOMText) {
140 self::render_xml_text(trim($el->childNodes->item(0)->wholeText), $shorten, $is_render_collapsed);
141 } else {
142 echo '<div class="xml-content' . ($is_render_collapsed ? ' collapsed' : '') . '">';
143 $indexes = array();
144 foreach ($el->childNodes as $eli => $child) {
145 if ($child instanceof DOMElement) {
146 empty($indexes[$child->nodeName]) and $indexes[$child->nodeName] = 0; $indexes[$child->nodeName]++;
147 self::render_xml_element($child, $shorten, $path . '/', $indexes[$child->nodeName], $lvl + 1);
148 } elseif ($child instanceof DOMCdataSection) {
149 self::render_xml_text(trim($child->wholeText), $shorten, false, true);
150 } elseif ($child instanceof DOMText) {
151 if ( $el->childNodes->item($eli - 1) and ($el->childNodes->item($eli - 1) instanceof DOMCdataSection) ){
152
153 }
154 elseif( $el->childNodes->item($eli + 1) and ($el->childNodes->item($eli + 1) instanceof DOMCdataSection) ){
155
156 }
157 else{
158 self::render_xml_text(trim($child->wholeText), $shorten);
159 }
160 } elseif ($child instanceof DOMComment) {
161 if (preg_match('%\[pmxi_more:(\d+)\]%', $child->nodeValue, $mtch)) {
162 $no = intval($mtch[1]);
163 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>';
164 }
165 }
166 }
167 echo '</div>';
168 }
169 echo '<div class="xml-tag closing">&lt;/<span class="xml-tag-name">' . $el->nodeName . '</span>&gt;</div>';
170 } else {
171 echo '<div class="xml-tag opening empty">&lt;<span class="xml-tag-name">' . $el->nodeName . '</span>'; self::render_xml_attributes($el); echo '/&gt;</div>';
172 }
173 echo '</div>';
174 }
175
176 protected static function render_xml_text($text, $shorten = false, $is_render_collapsed = false, $is_cdata = false)
177 {
178 if (empty($text) and 0 !== (int)$text) {
179 return; // do not display empty text nodes
180 }
181 if (preg_match('%\[more:(\d+)\]%', $text, $mtch)) {
182 $no = intval($mtch[1]);
183 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>';
184 return;
185 }
186 $more = '';
187 if ($shorten and preg_match('%^(.*?\s+){20}(?=\S)%', $text, $mtch)) {
188 $text = $mtch[0];
189 $more = '<span class="xml-more">[' . __('more', 'wp_all_import_plugin') . ']</span>';
190 }
191 $is_short = strlen($text) <= 40;
192 $text = htmlspecialchars($text);
193 if ($is_cdata){
194 $text = "<span class='wpallimport-cdata'>" . htmlspecialchars("<![CDATA[") . "</span> " . $text . " <span class='wpallimport-cdata'>" . htmlspecialchars("]]>") . "</span>";
195 }
196 //$text = preg_replace('%(?<!\s)\b(?!\s|\W[\w\s])|\w{20}%', '$0&#8203;', $text); // put explicit breaks for xml content to wrap
197 echo '<div class="xml-content textonly' . ($is_short ? ' short' : '') . ($is_render_collapsed ? ' collapsed' : '') . '">' . $text . $more . '</div>';
198 }
199
200 public static function get_xml_path(DOMElement $el, DOMXPath $xpath)
201 {
202 for($p = '', $doc = $el; $doc and ! $doc instanceof DOMDocument; $doc = $doc->parentNode) {
203 if (($ind = $xpath->query('preceding-sibling::' . $doc->nodeName, $doc)->length)) {
204 $p = '[' . ++$ind . ']' . $p;
205 } elseif ( ! $doc->parentNode instanceof DOMDocument) {
206 $p = '[' . ($ind = 1) . ']' . $p;
207 }
208 $p = '/' . $doc->nodeName . $p;
209 }
210 return $p;
211 }
212
213 protected static function render_xml_attributes(DOMElement $el, $path = '/')
214 {
215 foreach ($el->attributes as $attr) {
216 echo ' <span class="xml-attr" title="' . $path . '@' . $attr->nodeName . '"><span class="xml-attr-name">' . $attr->nodeName . '</span>=<span class="xml-attr-value">"' . esc_attr($attr->value) . '"</span></span>';
217 }
218 }
219
220 protected static function render_element_xpaths(DOMElement $el, $path = '/', $ind = 1, $lvl = 0){
221 ?>
222 <ul id="menu-<?php echo sanitize_title(esc_attr($path)); ?>" class="ui-helper-hidden">
223 <?php foreach ($el->attributes as $attr) : if ( empty($attr->value) ) continue; ?>
224 <li data-command="action1" title="<?php echo esc_attr($path . '[@'. $attr->nodeName .' = "' . esc_attr($attr->value) . '"]'); ?>">
225 <a href="#"><?php echo $path . '[@'. $attr->nodeName .' = "' . esc_attr($attr->value) . '"]'; ?></a>
226 </li>
227 <li data-command="action2" title="<?php echo esc_attr($path . '[@'. $attr->nodeName .'[contains(.,"' . esc_attr($attr->value) . '")]]'); ?>">
228 <a href="#"><?php echo $path . '[@'. $attr->nodeName .'[contains(.,"' . esc_attr($attr->value) . '")]]'; ?></a>
229 </li>
230 <?php endforeach; ?>
231 <?php
232 $altNode = null;
233 $altNodeText = null;
234 $parentNode = $el->parentNode;
235 $grandNode = $parentNode->parentNode;
236
237 if ( ! $grandNode instanceof DOMDocument and $grandNode instanceof DOMElement ){
238
239 $equalsElements = 0;
240 foreach ($grandNode->childNodes as $child) {
241 if ($child instanceof DOMElement) {
242 if ($child->nodeName == $parentNode->nodeName){
243 $equalsElements++;
244 if ($equalsElements > 1)
245 break;
246 }
247 }
248 }
249
250 if ($equalsElements > 1){
251 if ($parentNode->hasChildNodes()) {
252 foreach ($parentNode->childNodes as $i => $child) {
253 if ($child instanceof DOMElement) {
254 if ($child->nodeName != $el->nodeName){
255 $altNode = $child;
256 if ($child->hasChildNodes()){
257 foreach ($child->childNodes as $i => $txtChild) {
258 if ($txtChild instanceof DOMText) {
259 $altNodeText = $txtChild;
260 break;
261 }
262 }
263 }
264 break;
265 }
266 }
267 }
268 }
269
270 if ( ! empty($altNode) and !empty($altNodeText) ){
271
272 $pathArgs = explode('/', $path);
273 array_pop($pathArgs);
274 array_pop($pathArgs);
275 $vpath = esc_attr(implode('/', $pathArgs) . '/' . $parentNode->nodeName . '[contains('. $altNode->nodeName .',"' . esc_attr($altNodeText->wholeText) . '")]/' . $el->nodeName);
276 ?>
277 <li data-command="action3" title="<?php echo $vpath; ?>">
278 <a href="#"><?php echo $vpath; ?></a>
279 </li>
280 <?php
281
282 }
283 }
284 }
285 ?>
286 </ul>
287 <?php
288 }
289 }
290 }