PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.1.5
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.1.5
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 / XmlExportTaxonomy.php
wp-all-export / libraries Last commit date
VariableProductTitle 8 years ago .gitkeep 8 years ago WpaeInvalidPhpException.php 8 years ago WpaeInvalidStringException.php 8 years ago WpaeMethodNotFoundException.php 8 years ago WpaePhpInterpreterErrorHandler.php 8 years ago WpaeString.php 8 years ago WpaeTooMuchRecursionException.php 8 years ago WpaeXmlProcessor.php 8 years ago XmlCsvExport.php 8 years ago XmlExportACF.php 8 years ago XmlExportComment.php 8 years ago XmlExportCpt.php 8 years ago XmlExportEngine.php 8 years ago XmlExportFiltering.php 8 years ago XmlExportMediaGallery.php 8 years ago XmlExportTaxonomy.php 8 years ago XmlExportUser.php 8 years ago XmlExportWooCommerce.php 8 years ago XmlExportWooCommerceCoupon.php 8 years ago XmlExportWooCommerceOrder.php 8 years ago XmlGoogleMerchants.php 8 years ago XmlSpec.php 8 years ago
XmlExportTaxonomy.php
473 lines
1 <?php
2
3 if ( ! class_exists('XmlExportTaxonomy') )
4 {
5 final class XmlExportTaxonomy
6 {
7 private $init_fields = array(
8 array(
9 'label' => 'term_id',
10 'name' => 'Term ID',
11 'type' => 'term_id'
12 ),
13 array(
14 'label' => 'term_name',
15 'name' => 'Term Name',
16 'type' => 'term_name'
17 ),
18 array(
19 'label' => 'term_slug',
20 'name' => 'Term Slug',
21 'type' => 'term_slug'
22 )
23 );
24
25 private $default_fields = array(
26 array(
27 'label' => 'term_id',
28 'name' => 'Term ID',
29 'type' => 'term_id'
30 ),
31 array(
32 'label' => 'term_name',
33 'name' => 'Term Name',
34 'type' => 'term_name'
35 ),
36 array(
37 'label' => 'term_slug',
38 'name' => 'Term Slug',
39 'type' => 'term_slug'
40 ),
41 array(
42 'label' => 'term_description',
43 'name' => 'Description',
44 'type' => 'term_description'
45 ),
46 array(
47 'label' => 'term_parent_id',
48 'name' => 'Parent ID',
49 'type' => 'term_parent_id'
50 ),
51 array(
52 'label' => 'term_parent_name',
53 'name' => 'Parent Name',
54 'type' => 'term_parent_name'
55 ),
56 array(
57 'label' => 'term_parent_slug',
58 'name' => 'Parent Slug',
59 'type' => 'term_parent_slug'
60 ),
61 array(
62 'label' => 'term_posts_count',
63 'name' => 'Count',
64 'type' => 'term_posts_count'
65 ),
66 );
67
68 private $advanced_fields = array(
69
70 );
71
72 public static $is_active = true;
73
74 public function __construct()
75 {
76
77 if ( XmlExportEngine::$exportOptions['export_type'] == 'specific' and ! in_array('taxonomies', XmlExportEngine::$post_types) or XmlExportEngine::$exportOptions['export_type'] == 'advanced'){
78 self::$is_active = false;
79 return;
80 }
81
82 add_filter("wp_all_export_available_sections", array( &$this, "filter_available_sections" ), 10, 1);
83 add_filter("wp_all_export_init_fields", array( &$this, "filter_init_fields"), 10, 1);
84 add_filter("wp_all_export_default_fields", array( &$this, "filter_default_fields"), 10, 1);
85 add_filter("wp_all_export_other_fields", array( &$this, "filter_other_fields"), 10, 1);
86 }
87
88 // [FILTERS]
89
90 /**
91 *
92 * Filter Init Fields
93 *
94 */
95 public function filter_init_fields($init_fields){
96 return $this->init_fields;
97 }
98
99 /**
100 *
101 * Filter Default Fields
102 *
103 */
104 public function filter_default_fields($default_fields){
105 return $this->default_fields;
106 }
107
108 /**
109 *
110 * Filter Other Fields
111 *
112 */
113 public function filter_other_fields($other_fields){
114 return $this->advanced_fields;
115 }
116
117 /**
118 *
119 * Filter Sections in Available Data
120 *
121 */
122 public function filter_available_sections($sections){
123
124 unset($sections['media']['additional']['attachments']);
125 unset($sections['cats']);
126 unset($sections['other']);
127
128 $sections['cf']['title'] = __("Term Meta", "wp_all_export_plugin");
129
130 return $sections;
131 }
132
133 // [\FILTERS]
134
135 public function init( & $existing_meta_keys = array() )
136 {
137 if ( ! self::$is_active ) return;
138
139 if ( ! empty(XmlExportEngine::$exportQuery)){
140 $terms = XmlExportEngine::$exportQuery->get_terms();
141 }
142
143 if ( ! empty( $terms ) ) {
144 foreach ( $terms as $term ) {
145 $term_meta = get_term_meta($term->term_id, '');
146 if ( ! empty($term_meta)){
147 foreach ($term_meta as $record_meta_key => $record_meta_value) {
148 if ( ! in_array($record_meta_key, $existing_meta_keys) ){
149 $to_add = true;
150 foreach ($this->default_fields as $default_value) {
151 if ( $record_meta_key == $default_value['name'] || $record_meta_key == $default_value['type'] ){
152 $to_add = false;
153 break;
154 }
155 }
156 if ( $to_add ){
157 foreach ($this->advanced_fields as $advanced_value) {
158 if ( $record_meta_key == $advanced_value['name'] || $record_meta_key == $advanced_value['type']){
159 $to_add = false;
160 break;
161 }
162 }
163 }
164 if ( $to_add ) $existing_meta_keys[] = $record_meta_key;
165 }
166 }
167 }
168 }
169 }
170 }
171
172 public static function prepare_data( $term, $xmlWriter = false, &$acfs, $implode_delimiter, $preview )
173 {
174 $article = array();
175
176 // associate exported comment with import
177 if ( wp_all_export_is_compatible() and XmlExportEngine::$exportOptions['is_generate_import'] and XmlExportEngine::$exportOptions['import_id'])
178 {
179 $postRecord = new PMXI_Post_Record();
180 $postRecord->clear();
181 $postRecord->getBy(array(
182 'post_id' => $term->term_id,
183 'import_id' => XmlExportEngine::$exportOptions['import_id'],
184 ));
185
186 if ($postRecord->isEmpty()){
187 $postRecord->set(array(
188 'post_id' => $term->term_id,
189 'import_id' => XmlExportEngine::$exportOptions['import_id'],
190 'unique_key' => $term->term_id
191 ))->save();
192 }
193 unset($postRecord);
194 }
195
196 $is_xml_export = false;
197
198 if ( ! empty($xmlWriter) and XmlExportEngine::$exportOptions['export_to'] == 'xml' and ! in_array(XmlExportEngine::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ){
199 $is_xml_export = true;
200 }
201
202 foreach (XmlExportEngine::$exportOptions['ids'] as $ID => $value)
203 {
204 $fieldName = apply_filters('wp_all_export_field_name', wp_all_export_parse_field_name(XmlExportEngine::$exportOptions['cc_name'][$ID]), XmlExportEngine::$exportID);
205 $fieldValue = XmlExportEngine::$exportOptions['cc_value'][$ID];
206 $fieldLabel = XmlExportEngine::$exportOptions['cc_label'][$ID];
207 $fieldSql = XmlExportEngine::$exportOptions['cc_sql'][$ID];
208 $fieldPhp = XmlExportEngine::$exportOptions['cc_php'][$ID];
209 $fieldCode = XmlExportEngine::$exportOptions['cc_code'][$ID];
210 $fieldType = XmlExportEngine::$exportOptions['cc_type'][$ID];
211 $fieldOptions = XmlExportEngine::$exportOptions['cc_options'][$ID];
212
213 if ( empty($fieldName) or empty($fieldType) or ! is_numeric($ID)) continue;
214
215 $element_name = ( ! empty($fieldName) ) ? $fieldName : 'untitled_' . $ID;
216
217 $element_name_ns = '';
218
219 if ( $is_xml_export )
220 {
221 $element_name = ( ! empty($fieldName) ) ? preg_replace('/[^a-z0-9_:-]/i', '', $fieldName) : 'untitled_' . $ID;
222
223 if (strpos($element_name, ":") !== false)
224 {
225 $element_name_parts = explode(":", $element_name);
226 $element_name_ns = (empty($element_name_parts[0])) ? '' : $element_name_parts[0];
227 $element_name = (empty($element_name_parts[1])) ? 'untitled_' . $ID : preg_replace('/[^a-z0-9_-]/i', '', $element_name_parts[1]);
228 }
229 }
230
231 $fieldSnipped = ( ! empty($fieldPhp ) and ! empty($fieldCode)) ? $fieldCode : false;
232
233 switch ($fieldType)
234 {
235 case 'term_id':
236 wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_term_id', pmxe_filter($term->term_id, $fieldSnipped), $term->term_id) );
237 break;
238 case 'term_name':
239 wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_term_name', pmxe_filter($term->name, $fieldSnipped), $term->term_id) );
240 break;
241 case 'term_slug':
242 wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_term_slug', pmxe_filter($term->slug, $fieldSnipped), $term->term_id) );
243 break;
244 case 'term_description':
245 wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_term_description', pmxe_filter($term->description, $fieldSnipped), $term->term_id) );
246 break;
247 case 'term_parent_id':
248 wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_term_parent', pmxe_filter($term->parent, $fieldSnipped), $term->term_id) );
249 break;
250 case 'term_parent_name':
251 $term_parent_name = '';
252 if ($term->parent){
253 $parent_term = get_term($term->parent, $term->taxonomy);
254 if ($parent_term){
255 $term_parent_name = $parent_term->name;
256 }
257 }
258 wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_term_parent', pmxe_filter($term_parent_name, $fieldSnipped), $term->term_id) );
259 break;
260 case 'term_parent_slug':
261 $term_parent_slug = '';
262 if ($term->parent){
263 $parent_term = get_term($term->parent, $term->taxonomy);
264 if ($parent_term){
265 $term_parent_slug = $parent_term->slug;
266 }
267 }
268 wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_term_parent', pmxe_filter($term_parent_slug, $fieldSnipped), $term->term_id) );
269 break;
270 case 'term_posts_count':
271 wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_term_count', pmxe_filter($term->count, $fieldSnipped), $term->term_id) );
272 break;
273 // Media Images
274 case 'media':
275 case 'image_id':
276 case 'image_url':
277 case 'image_filename':
278 case 'image_path':
279 case 'image_title':
280 case 'image_caption':
281 case 'image_description':
282 case 'image_alt':
283
284 $field_options = json_decode($fieldOptions, true);
285
286 XmlExportMediaGallery::getInstance($term->term_id);
287
288 $images_data = XmlExportMediaGallery::get_images($fieldType, $field_options);
289
290 $images_separator = empty($field_options['image_separator']) ? $implode_delimiter : $field_options['image_separator'];
291
292 wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_' . $fieldType, pmxe_filter( implode($images_separator, $images_data), $fieldSnipped), $term->term_id) );
293
294 break;
295 case 'cf':
296 if ( ! empty($fieldValue) ){
297 $cur_meta_values = get_term_meta($term->term_id, $fieldValue);
298 if (!empty($cur_meta_values) and is_array($cur_meta_values)){
299 $val = "";
300 foreach ($cur_meta_values as $key => $cur_meta_value) {
301 if (empty($val)){
302 $val = apply_filters('pmxe_custom_field', pmxe_filter(maybe_serialize($cur_meta_value), $fieldSnipped), $fieldValue, $term->term_id);
303 }
304 else{
305 $val = apply_filters('pmxe_custom_field', pmxe_filter($val . $implode_delimiter . maybe_serialize($cur_meta_value), $fieldSnipped), $fieldValue, $term->term_id);
306 }
307 }
308 wp_all_export_write_article( $article, $element_name, $val );
309 }
310
311 if (empty($cur_meta_values)){
312 if (empty($article[$element_name])){
313 wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_custom_field', pmxe_filter('', $fieldSnipped), $fieldValue, $term->term_id) );
314 }
315 }
316 }
317 break;
318 case 'acf':
319
320 if ( ! empty($fieldLabel) and class_exists( 'acf' ) )
321 {
322 global $acf;
323
324 $field_options = unserialize($fieldOptions);
325
326 if ( ! $is_xml_export )
327 {
328 switch ($field_options['type']) {
329 case 'textarea':
330 case 'oembed':
331 case 'wysiwyg':
332 case 'wp_wysiwyg':
333 case 'date_time_picker':
334 case 'date_picker':
335
336 $field_value = get_field($fieldLabel, $term->taxonomy . "_" . $term->term_id, false);
337
338 break;
339
340 default:
341
342 $field_value = get_field($fieldLabel, $term->taxonomy . "_" . $term->term_id);
343
344 break;
345 }
346 }
347 else
348 {
349 $field_value = get_field($fieldLabel, $term->taxonomy . "_" . $term->term_id);
350 }
351
352 XmlExportACF::export_acf_field(
353 $field_value,
354 XmlExportEngine::$exportOptions,
355 $ID,
356 $term->taxonomy . "_" . $term->term_id,
357 $article,
358 $xmlWriter,
359 $acfs,
360 $element_name,
361 $element_name_ns,
362 $fieldSnipped,
363 $field_options['group_id'],
364 $preview
365 );
366
367 }
368
369 break;
370 case 'sql':
371
372 if ( ! empty($fieldSql) )
373 {
374 global $wpdb;
375 $val = $wpdb->get_var( $wpdb->prepare( stripcslashes(str_replace("%%ID%%", "%d", $fieldSql)), $term->term_id ));
376 if ( ! empty($fieldPhp) and !empty($fieldCode) )
377 {
378 // if shortcode defined
379 if (strpos($fieldCode, '[') === 0)
380 {
381 $val = do_shortcode(str_replace("%%VALUE%%", $val, $fieldCode));
382 }
383 else
384 {
385 $val = eval('return ' . stripcslashes(str_replace("%%VALUE%%", $val, $fieldCode)) . ';');
386 }
387 }
388 wp_all_export_write_article( $article, $element_name, apply_filters('pmxe_sql_field', $val, $element_name, $term->term_id) );
389 }
390 break;
391 default:
392 # code...
393 break;
394 }
395
396 if ( $is_xml_export and isset($article[$element_name]) )
397 {
398 $element_name_in_file = XmlCsvExport::_get_valid_header_name( $element_name );
399
400 $xmlWriter = apply_filters('wp_all_export_add_before_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $term->term_id);
401
402 $xmlWriter->beginElement($element_name_ns, $element_name_in_file, null);
403 $xmlWriter->writeData($article[$element_name], $element_name_in_file);
404 $xmlWriter->closeElement();
405
406 $xmlWriter = apply_filters('wp_all_export_add_after_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $term->term_id);
407 }
408 }
409 return $article;
410 }
411
412 public static function prepare_import_template( $exportOptions, &$templateOptions, $element_name, $ID)
413 {
414
415 $options = $exportOptions;
416
417 $element_type = $options['cc_type'][$ID];
418
419 $is_xml_template = $options['export_to'] == 'xml';
420
421 $implode_delimiter = XmlExportEngine::$implode;
422
423 switch ($element_type)
424 {
425 // Export Taxonomy Terms
426 case 'term_id':
427 $templateOptions['unique_key'] = '{'. $element_name .'[1]}';
428 $templateOptions['tmp_unique_key'] = '{'. $element_name .'[1]}';
429 break;
430 case 'term_name':
431 $templateOptions['title'] = '{'. $element_name .'[1]}';
432 $templateOptions['is_update_title'] = 1;
433 break;
434 case 'term_slug':
435 $templateOptions['taxonomy_slug'] = 'xpath';
436 $templateOptions['taxonomy_slug_xpath'] = '{'. $element_name .'[1]}';
437 $templateOptions['is_update_slug'] = 1;
438 break;
439 case 'term_description':
440 $templateOptions['content'] = '{'. $element_name .'[1]}';
441 $templateOptions['is_update_content'] = 1;
442 break;
443 case 'term_parent_slug':
444 $templateOptions['taxonomy_parent'] = '{'. $element_name .'[1]}';
445 $templateOptions['is_update_parent'] = 1;
446 break;
447
448 }
449 }
450
451 /**
452 * __get function.
453 *
454 * @access public
455 * @param mixed $key
456 * @return mixed
457 */
458 public function __get( $key ) {
459 return $this->get( $key );
460 }
461
462 /**
463 * Get a session variable
464 *
465 * @param string $key
466 * @param mixed $default used if the session variable isn't set
467 * @return mixed value of session variable
468 */
469 public function get( $key, $default = null ) {
470 return isset( $this->{$key} ) ? $this->{$key} : $default;
471 }
472 }
473 }