PluginProbe ʕ •ᴥ•ʔ
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets / trunk
WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets vtrunk
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 / rapidaddon.php
wp-all-import / classes Last commit date
XmlStreamReader 3 weeks ago partner-discount-sdk 3 weeks ago api.php 3 weeks ago arraytoxml.php 3 weeks ago chunk.php 3 weeks ago config.php 2 years ago download.php 3 weeks ago error.php 3 weeks ago handler.php 3 weeks ago helper.php 3 weeks ago input.php 3 weeks ago nested.php 3 weeks ago rapidaddon.php 3 weeks ago render.php 3 weeks ago session.php 9 months ago upload.php 3 weeks ago zip.php 10 years ago
rapidaddon.php
1287 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit;
3 /**
4 * RapidAddon
5 *
6 * @package WP All Import RapidAddon
7 * @copyright Copyright (c) 2014, Soflyy
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @version 1.1.4
10 */
11
12 if (!class_exists('PMXI_RapidAddon')) {
13
14 class PMXI_RapidAddon {
15
16 public $name;
17 public $slug;
18 public $fields;
19 public $options = array();
20 public $accordions = array();
21 public $image_sections = array();
22 public $import_function;
23 public $post_saved_function;
24 public $notice_text;
25 public $logger = null;
26 public $when_to_run = false;
27 public $image_options = array(
28 'download_images' => 'yes',
29 'download_featured_delim' => ',',
30 'download_featured_image' => '',
31 'gallery_featured_image' => '',
32 'gallery_featured_delim' => ',',
33 'featured_image' => '',
34 'featured_delim' => ',',
35 'search_existing_images' => 1,
36 'is_featured' => 0,
37 'create_draft' => 'no',
38 'set_image_meta_title' => 0,
39 'image_meta_title_delim' => ',',
40 'image_meta_title' => '',
41 'set_image_meta_caption' => 0,
42 'image_meta_caption_delim' => ',',
43 'image_meta_caption' => '',
44 'set_image_meta_alt' => 0,
45 'image_meta_alt_delim' => ',',
46 'image_meta_alt' => '',
47 'set_image_meta_description' => 0,
48 'image_meta_description_delim' => ',',
49 'image_meta_description_delim_logic' => 'separate',
50 'image_meta_description' => '',
51 'auto_rename_images' => 0,
52 'auto_rename_images_suffix' => '',
53 'auto_set_extension' => 0,
54 'new_extension' => '',
55 'do_not_remove_images' => 1,
56 'search_existing_images_logic' => 'by_url'
57 );
58
59 private $active_post_types,$active_themes,$active_plugins = [];
60
61 protected $isWizard = true;
62
63 function __construct($name, $slug) {
64 $this->name = $name;
65 $this->slug = $slug;
66 if (!empty($_GET['id'])){ // phpcs:ignore WordPress.Security.NonceVerification.Recommended
67 $this->isWizard = false;
68 }
69 }
70
71 function set_import_function($name) {
72 $this->import_function = $name;
73 }
74
75 function set_post_saved_function($name) {
76 $this->post_saved_function = $name;
77 }
78
79 function is_active_addon($post_type = null) {
80
81 if ( ! class_exists( 'PMXI_Plugin' ) ) {
82 return false;
83 }
84
85 $addon_active = false;
86
87 if ($post_type !== null) {
88 if (@in_array($post_type, $this->active_post_types) or empty($this->active_post_types)) {
89 $addon_active = true;
90 }
91 }
92
93 if ($addon_active){
94
95 $current_theme = wp_get_theme();
96
97 $parent_theme = $current_theme->parent();
98
99 $theme_name = $current_theme->get('Name');
100
101 $addon_active = (@in_array($theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false;
102
103 if ( ! $addon_active and $parent_theme ){
104 $parent_theme_name = $parent_theme->get('Name');
105 $addon_active = (@in_array($parent_theme_name, $this->active_themes) or empty($this->active_themes)) ? true : false;
106
107 }
108
109 if ( $addon_active and ! empty($this->active_plugins) ){
110
111 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
112
113 foreach ($this->active_plugins as $plugin) {
114 if ( ! is_plugin_active($plugin) ) {
115 $addon_active = false;
116 break;
117 }
118 }
119 }
120
121 }
122
123 if ($this->when_to_run == "always") {
124 $addon_active = true;
125 }
126
127 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
128 return apply_filters('rapid_is_active_add_on', $addon_active, $post_type, $this->slug);
129 }
130
131 /**
132 *
133 * Add-On Initialization
134 *
135 * @param array $conditions - list of supported themes and post types
136 *
137 */
138 function run($conditions = array()) {
139
140 if (empty($conditions)) {
141 $this->when_to_run = "always";
142 }
143
144 @$this->active_post_types = ( ! empty($conditions['post_types'])) ? $conditions['post_types'] : array();
145 @$this->active_themes = ( ! empty($conditions['themes'])) ? $conditions['themes'] : array();
146 @$this->active_plugins = ( ! empty($conditions['plugins'])) ? $conditions['plugins'] : array();
147
148 add_filter('pmxi_addons', array($this, 'wpai_api_register'));
149 add_filter('wp_all_import_addon_parse', array($this, 'wpai_api_parse'));
150 add_filter('wp_all_import_addon_import', array($this, 'wpai_api_import'));
151 add_filter('wp_all_import_addon_saved_post', array($this, 'wpai_api_post_saved'));
152 add_filter('pmxi_options_options', array($this, 'wpai_api_options'));
153 add_filter('wp_all_import_image_sections', array($this, 'additional_sections'), 10, 1);
154 add_filter('pmxi_custom_types', array($this, 'filter_post_types'), 10, 2);
155 add_filter('pmxi_post_list_order', array($this,'sort_post_types'), 10, 1);
156 add_filter('wp_all_import_post_type_image', array($this, 'post_type_image'), 10, 1 );
157 add_action('pmxi_extend_options_featured', array($this, 'wpai_api_metabox'), 10, 2);
158 add_action('admin_init', array($this, 'admin_notice_ignore'));
159 }
160
161 function parse($data) {
162
163 if ( ! $this->is_active_addon($data['import']->options['custom_type'])) return false;
164
165 $parsedData = $this->helper_parse($data, $this->options_array());
166 return $parsedData;
167
168 }
169
170
171 function add_field($field_slug, $field_name, $field_type, $enum_values = null, $tooltip = "", $is_html = true, $default_text = '') {
172
173 $field = array("name" => $field_name, "type" => $field_type, "enum_values" => $enum_values, "tooltip" => $tooltip, "is_sub_field" => false, "is_main_field" => false, "slug" => $field_slug, "is_html" => $is_html, 'default_text' => $default_text);
174
175 $this->fields[$field_slug] = $field;
176
177 if ( ! empty($enum_values) ){
178 foreach ($enum_values as $key => $value) {
179 if (is_array($value))
180 {
181 if ($field['type'] == 'accordion')
182 {
183 $this->fields[$value['slug']]['is_sub_field'] = true;
184 }
185 else
186 {
187 foreach ($value as $n => $param) {
188 if (is_array($param) and ! empty($this->fields[$param['slug']])){
189 $this->fields[$param['slug']]['is_sub_field'] = true;
190 }
191 }
192 }
193 }
194 }
195 }
196
197 return $field;
198
199 }
200
201 function add_acf_field($field){
202 $this->fields[$field->post_name] = array(
203 'type' => 'acf',
204 'field_obj' => $field
205 );
206 }
207
208 private $acfGroups = array();
209
210 function use_acf_group($acf_group){
211 $this->add_text(
212 '<div class="postbox acf_postbox default acf_signle_group rad4">
213 <h3 class="hndle" style="margin-top:0;"><span>'.$acf_group['title'].'</span></h3>
214 <div class="inside">');
215 $acf_fields = get_posts(array('posts_per_page' => -1, 'post_type' => 'acf-field', 'post_parent' => $acf_group['ID'], 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC'));
216 if (!empty($acf_fields)){
217 foreach ($acf_fields as $field) {
218 $this->add_acf_field($field);
219 }
220 }
221 $this->add_text('</div></div>');
222 $this->acfGroups[] = $acf_group['ID'];
223 add_filter('wp_all_import_acf_is_show_group', array($this, 'acf_is_show_group'), 10, 2);
224 }
225
226 function acf_is_show_group($is_show, $acf_group){
227 return (in_array($acf_group['ID'], $this->acfGroups)) ? false : true;
228 }
229
230 /**
231 *
232 * Add an option to WP All Import options list
233 *
234 * @param string $slug - option name
235 * @param string $default_value - default option value
236 *
237 */
238 function add_option($slug, $default_value = ''){
239 $this->options[$slug] = $default_value;
240 }
241
242 function options_array() {
243
244 $options_list = array();
245
246 if ( ! empty( $this->fields ) ) {
247
248 foreach ($this->fields as $field_slug => $field_params) {
249 if (in_array($field_params['type'], array('title', 'plain_text', 'acf'))) continue;
250 $default_value = '';
251 if (!empty($field_params['enum_values'])){
252 foreach ($field_params['enum_values'] as $key => $value) {
253 $default_value = $key;
254 break;
255 }
256 }
257 $options_list[$field_slug] = $default_value;
258 }
259
260 }
261
262 if ( ! empty($this->options) ){
263 foreach ($this->options as $slug => $value) {
264 $options_arr[$slug] = $value;
265 }
266 }
267
268 $options_arr[$this->slug] = $options_list;
269 $options_arr['rapid_addon'] = plugin_basename( __FILE__ );
270
271 return $options_arr;
272
273 }
274
275 function wpai_api_options($all_options) {
276
277 $all_options = $all_options + $this->options_array();
278
279 return $all_options;
280
281 }
282
283
284 function wpai_api_register($addons) {
285
286 if (empty($addons[$this->slug])) {
287 $addons[$this->slug] = 1;
288 }
289
290 return $addons;
291
292 }
293
294
295 function wpai_api_parse($functions) {
296
297 $functions[$this->slug] = array($this, 'parse');
298 return $functions;
299
300 }
301
302 function wpai_api_post_saved($functions){
303 $functions[$this->slug] = array($this, 'post_saved');
304 return $functions;
305 }
306
307
308 function wpai_api_import($functions) {
309
310 $functions[$this->slug] = array($this, 'import');
311 return $functions;
312
313 }
314
315 function post_saved( $importData ){
316
317 if (is_callable($this->post_saved_function))
318 call_user_func($this->post_saved_function, $importData['pid'], $importData['import'], $importData['logger']);
319
320 }
321
322 function import($importData, $parsedData) {
323
324 if (!$this->is_active_addon($importData['post_type'])) {
325 return;
326 }
327
328 $import_options = $importData['import']['options'][$this->slug];
329
330 if ( ! empty($parsedData) ) {
331
332 $this->logger = $importData['logger'];
333
334 $post_id = $importData['pid'];
335 $index = $importData['i'];
336 $data = array();
337 if (!empty($this->fields)){
338 foreach ($this->fields as $field_slug => $field_params) {
339 if (in_array($field_params['type'], array('title', 'plain_text'))) continue;
340 switch ($field_params['type']) {
341
342 case 'image':
343
344 // import the specified image, then set the value of the field to the image ID in the media library
345
346 $image_url_or_path = $parsedData[$field_slug][$index];
347
348 if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) {
349 continue 2;
350 }
351
352 $download = $import_options['download_image'][$field_slug];
353
354 $uploaded_image = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "images", true, $importData['articleData']);
355
356 $data[$field_slug] = array(
357 "attachment_id" => $uploaded_image,
358 "image_url_or_path" => $image_url_or_path,
359 "download" => $download
360 );
361
362 break;
363
364 case 'file':
365
366 $image_url_or_path = $parsedData[$field_slug][$index];
367
368 if ( ! array_key_exists( $field_slug, $import_options['download_image'] ) ) {
369 continue 2;
370 }
371
372 $download = $import_options['download_image'][$field_slug];
373
374 $uploaded_file = PMXI_API::upload_image($post_id, $image_url_or_path, $download, $importData['logger'], true, "", "files", true, $importData['articleData']);
375
376 $data[$field_slug] = array(
377 "attachment_id" => $uploaded_file,
378 "image_url_or_path" => $image_url_or_path,
379 "download" => $download
380 );
381
382 break;
383
384 default:
385 // set the field data to the value of the field after it's been parsed
386 $data[$field_slug] = $parsedData[$field_slug][$index];
387 break;
388 }
389
390 // apply mapping rules if they exist
391 if (!empty($import_options['mapping'][$field_slug])) {
392 $mapping_rules = json_decode($import_options['mapping'][$field_slug], true);
393
394 if (!empty($mapping_rules) and is_array($mapping_rules)) {
395 foreach ($mapping_rules as $rule_number => $map_to) {
396 if (isset($map_to[trim($data[$field_slug])])){
397 $data[$field_slug] = trim($map_to[trim($data[$field_slug])]);
398 break;
399 }
400 }
401 }
402 }
403 // --------------------
404 }
405 }
406
407 call_user_func($this->import_function, $post_id, $data, $importData['import'], $importData['articleData'], $importData['logger']);
408 }
409
410 }
411
412
413 function wpai_api_metabox($post_type, $current_values) {
414
415 if (!$this->is_active_addon($post_type)) {
416 return;
417 }
418
419 // Escaping is handled in 'helper_metabox_top' method.
420 echo $this->helper_metabox_top($this->name); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Internal helper returns pre-escaped HTML.
421
422 $visible_fields = 0;
423
424 foreach ($this->fields as $field_slug => $field_params) {
425 if ($field_params['is_sub_field']) continue;
426 $visible_fields++;
427 }
428
429 $counter = 0;
430
431 foreach ($this->fields as $field_slug => $field_params) {
432
433 // do not render sub fields
434 if ($field_params['is_sub_field']) continue;
435
436 $counter++;
437
438 $this->render_field($field_params, $field_slug, $current_values, $visible_fields == $counter);
439
440 }
441
442 // Static HTML is returned by method for display.
443 echo $this->helper_metabox_bottom(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Static HTML string returned by internal helper.
444
445 if ( ! empty($this->image_sections) ){
446 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
447 $is_images_section_enabled = apply_filters('wp_all_import_is_images_section_enabled', true, $post_type);
448 foreach ($this->image_sections as $k => $section) {
449 $section_options = array();
450 foreach ($this->image_options as $slug => $value) {
451 $section_options[$section['slug'] . $slug] = $value;
452 }
453 if ( ! $is_images_section_enabled and ! $k ){
454 $section_options[$section['slug'] . 'is_featured'] = 1;
455 }
456 PMXI_API::add_additional_images_section($section['title'], $section['slug'], $current_values, '', true, false, $section['type']);
457 }
458 }
459
460 }
461
462 function render_field($field_params, $field_slug, $current_values, $in_the_bottom = false){
463
464 if (!isset($current_values[$this->slug][$field_slug])) {
465 $current_values[$this->slug][$field_slug] = isset($field_params['default_text']) ? $field_params['default_text'] : '';
466 }
467
468 if ($field_params['type'] == 'text') {
469
470 PMXI_API::add_field(
471 'simple',
472 $field_params['name'],
473 array(
474 'tooltip' => $field_params['tooltip'],
475 'field_name' => $this->slug."[".$field_slug."]",
476 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug]
477 )
478 );
479
480 } else if ($field_params['type'] == 'textarea') {
481
482 PMXI_API::add_field(
483 'textarea',
484 $field_params['name'],
485 array(
486 'tooltip' => $field_params['tooltip'],
487 'field_name' => $this->slug."[".$field_slug."]",
488 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug]
489 )
490 );
491
492 } else if ($field_params['type'] == 'wp_editor') {
493
494 PMXI_API::add_field(
495 'wp_editor',
496 $field_params['name'],
497 array(
498 'tooltip' => $field_params['tooltip'],
499 'field_name' => $this->slug."[".$field_slug."]",
500 'field_value' => ( $current_values[$this->slug][$field_slug] == '' && $this->isWizard ) ? $field_params['default_text'] : $current_values[$this->slug][$field_slug]
501 )
502 );
503
504 } else if ($field_params['type'] == 'image' or $field_params['type'] == 'file') {
505
506 if (!isset($current_values[$this->slug]['download_image'][$field_slug])) { $current_values[$this->slug]['download_image'][$field_slug] = ''; }
507
508 PMXI_API::add_field(
509 $field_params['type'],
510 $field_params['name'],
511 array(
512 'tooltip' => $field_params['tooltip'],
513 'field_name' => $this->slug."[".$field_slug."]",
514 'field_value' => $current_values[$this->slug][$field_slug],
515 'download_image' => $current_values[$this->slug]['download_image'][$field_slug],
516 'field_key' => $field_slug,
517 'addon_prefix' => $this->slug
518
519 )
520 );
521
522 } else if ($field_params['type'] == 'radio') {
523
524 if (!isset($current_values[$this->slug]['mapping'][$field_slug])) { $current_values[$this->slug]['mapping'][$field_slug] = array(); }
525 if (!isset($current_values[$this->slug]['xpaths'][$field_slug])) { $current_values[$this->slug]['xpaths'][$field_slug] = ''; }
526
527 PMXI_API::add_field(
528 'enum',
529 $field_params['name'],
530 array(
531 'tooltip' => $field_params['tooltip'],
532 'field_name' => $this->slug."[".$field_slug."]",
533 'field_value' => $current_values[$this->slug][$field_slug],
534 'enum_values' => $field_params['enum_values'],
535 'mapping' => true,
536 'field_key' => $field_slug,
537 'mapping_rules' => $current_values[$this->slug]['mapping'][$field_slug],
538 'xpath' => $current_values[$this->slug]['xpaths'][$field_slug],
539 'addon_prefix' => $this->slug,
540 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values)
541 )
542 );
543
544 } else if($field_params['type'] == 'accordion') {
545
546 PMXI_API::add_field(
547 'accordion',
548 $field_params['name'],
549 array(
550 'tooltip' => $field_params['tooltip'],
551 'field_name' => $this->slug."[".$field_slug."]",
552 'field_key' => $field_slug,
553 'addon_prefix' => $this->slug,
554 'sub_fields' => $this->get_sub_fields($field_params, $field_slug, $current_values),
555 'in_the_bottom' => $in_the_bottom
556 )
557 );
558
559 } else if($field_params['type'] == 'acf') {
560 $fieldData = (!empty($field_params['field_obj']->post_content)) ? \pmxi_maybe_unserialize($field_params['field_obj']->post_content) : array();
561 $fieldData['ID'] = $field_params['field_obj']->ID;
562 $fieldData['id'] = $field_params['field_obj']->ID;
563 $fieldData['label'] = $field_params['field_obj']->post_title;
564 $fieldData['key'] = $field_params['field_obj']->post_name;
565 if (empty($fieldData['name'])) $fieldData['name'] = $field_params['field_obj']->post_excerpt;
566 // This function is no longer used in recent versions of the ACF Import Add-On.
567 if (function_exists('pmai_render_field')) {
568 echo \wp_kses_post(pmai_render_field($fieldData, ( ! empty($current_values) ) ? $current_values : array() ));
569 }
570 } else if($field_params['type'] == 'title'){
571 ?>
572 <h4 class="wpallimport-add-on-options-title"><?php echo \esc_html($field_params['name']); ?><?php if ( ! empty($field_params['tooltip'])): ?><a href="#help" class="wpallimport-help" title="<?php echo \wp_kses_post($field_params['tooltip']); ?>" style="position:relative; top: -1px;">?</a><?php endif; ?></h4>
573 <?php
574
575 } else if($field_params['type'] == 'plain_text'){
576 if ($field_params['is_html']):
577 echo \wp_kses_post($field_params['name']);
578 else:
579 ?>
580 <p style="margin: 0 0 12px 0;"><?php echo \esc_html($field_params['name']);?></p>
581 <?php
582 endif;
583 }
584
585
586 }
587 /**
588 *
589 * Helper function for nested radio fields
590 *
591 */
592 function get_sub_fields($field_params, $field_slug, $current_values){
593 $sub_fields = array();
594 if ( ! empty($field_params['enum_values']) ){
595 foreach ($field_params['enum_values'] as $key => $value) {
596 $sub_fields[$key] = array();
597 if (is_array($value)){
598 if ($field_params['type'] == 'accordion'){
599 $sub_fields[$key][] = $this->convert_field($value, $current_values);
600 }
601 else
602 {
603 foreach ($value as $k => $sub_field) {
604 if (is_array($sub_field) and ! empty($this->fields[$sub_field['slug']]))
605 {
606 $sub_fields[$key][] = $this->convert_field($sub_field, $current_values);
607 }
608 }
609 }
610 }
611 }
612 }
613 return $sub_fields;
614 }
615
616 function convert_field($sub_field, $current_values){
617 $field = array();
618 if (!isset($current_values[$this->slug][$sub_field['slug']])) {
619 $current_values[$this->slug][$sub_field['slug']] = isset($sub_field['default_text']) ? $sub_field['default_text'] : '';
620 }
621 switch ($this->fields[$sub_field['slug']]['type']) {
622 case 'text':
623 $field = array(
624 'type' => 'simple',
625 'label' => $this->fields[$sub_field['slug']]['name'],
626 'params' => array(
627 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
628 'field_name' => $this->slug."[".$sub_field['slug']."]",
629 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']],
630 'is_main_field' => $sub_field['is_main_field']
631 )
632 );
633 break;
634 case 'textarea':
635 $field = array(
636 'type' => 'textarea',
637 'label' => $this->fields[$sub_field['slug']]['name'],
638 'params' => array(
639 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
640 'field_name' => $this->slug."[".$sub_field['slug']."]",
641 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']],
642 'is_main_field' => $sub_field['is_main_field']
643 )
644 );
645 break;
646 case 'wp_editor':
647 $field = array(
648 'type' => 'wp_editor',
649 'label' => $this->fields[$sub_field['slug']]['name'],
650 'params' => array(
651 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
652 'field_name' => $this->slug."[".$sub_field['slug']."]",
653 'field_value' => ($current_values[$this->slug][$sub_field['slug']] == '' && $this->isWizard) ? $sub_field['default_text'] : $current_values[$this->slug][$sub_field['slug']],
654 'is_main_field' => $sub_field['is_main_field']
655 )
656 );
657 break;
658 case 'image':
659 $field = array(
660 'type' => 'image',
661 'label' => $this->fields[$sub_field['slug']]['name'],
662 'params' => array(
663 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
664 'field_name' => $this->slug."[".$sub_field['slug']."]",
665 'field_value' => $current_values[$this->slug][$sub_field['slug']],
666 'download_image' => null,
667 'field_key' => $sub_field['slug'],
668 'addon_prefix' => $this->slug,
669 'is_main_field' => $sub_field['is_main_field']
670 )
671 );
672
673 if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) {
674 $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']];
675 }
676 break;
677 case 'file':
678 $field = array(
679 'type' => 'file',
680 'label' => $this->fields[$sub_field['slug']]['name'],
681 'params' => array(
682 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
683 'field_name' => $this->slug."[".$sub_field['slug']."]",
684 'field_value' => $current_values[$this->slug][$sub_field['slug']],
685 'download_image' => null,
686 'field_key' => $sub_field['slug'],
687 'addon_prefix' => $this->slug,
688 'is_main_field' => $sub_field['is_main_field']
689 )
690 );
691
692 if ( array_key_exists( 'download_image', $current_values[$this->slug] ) && array_key_exists( $sub_field['slug'], $current_values[$this->slug]['download_image'] ) ) {
693 $field['params']['download_image'] = $current_values[$this->slug]['download_image'][$sub_field['slug']];
694 }
695
696 break;
697 case 'radio':
698 $field = array(
699 'type' => 'enum',
700 'label' => $this->fields[$sub_field['slug']]['name'],
701 'params' => array(
702 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
703 'field_name' => $this->slug."[".$sub_field['slug']."]",
704 'field_value' => $current_values[$this->slug][$sub_field['slug']],
705 'enum_values' => $this->fields[$sub_field['slug']]['enum_values'],
706 'mapping' => true,
707 'field_key' => $sub_field['slug'],
708 'mapping_rules' => isset($current_values[$this->slug]['mapping'][$sub_field['slug']]) ? $current_values[$this->slug]['mapping'][$sub_field['slug']] : array(),
709 'xpath' => isset($current_values[$this->slug]['xpaths'][$sub_field['slug']]) ? $current_values[$this->slug]['xpaths'][$sub_field['slug']] : '',
710 'addon_prefix' => $this->slug,
711 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values),
712 'is_main_field' => $sub_field['is_main_field']
713 )
714 );
715 break;
716 case 'accordion':
717 $field = array(
718 'type' => 'accordion',
719 'label' => $this->fields[$sub_field['slug']]['name'],
720 'params' => array(
721 'tooltip' => $this->fields[$sub_field['slug']]['tooltip'],
722 'field_name' => $this->slug."[".$sub_field['slug']."]",
723 'field_key' => $sub_field['slug'],
724 'addon_prefix' => $this->slug,
725 'sub_fields' => $this->get_sub_fields($this->fields[$sub_field['slug']], $sub_field['slug'], $current_values),
726 'in_the_bottom' => false
727 )
728 );
729 break;
730 default:
731 # code...
732 break;
733 }
734 return $field;
735 }
736
737 /**
738 *
739 * Add accordion options
740 *
741 *
742 */
743 function add_options( $main_field = false, $title = '', $fields = array() ){
744
745 if ( ! empty($fields) )
746 {
747
748 if ($main_field){
749
750 $main_field['is_main_field'] = true;
751 $fields[] = $main_field;
752
753 }
754
755 return $this->add_field('accordion_' . $fields[0]['slug'], $title, 'accordion', $fields);
756
757 }
758
759 }
760
761 function add_title($title = '', $tooltip = ''){
762
763 if (empty($title)) return;
764
765 return $this->add_field(sanitize_key($title) . time(), $title, 'title', null, $tooltip);
766
767 }
768
769 function add_text($text = '', $is_html = false){
770
771 if (empty($text)) return;
772
773 $count = is_array($this->fields) ? count($this->fields) : 0;
774
775 return $this->add_field(sanitize_key($text) . time() . uniqid() . $count, $text, 'plain_text', null, "", $is_html);
776
777 }
778
779 function helper_metabox_top($name) {
780
781 return '
782 <style type="text/css">
783 .wpallimport-plugin .wpallimport-addon div.input {
784 margin-bottom: 15px;
785 }
786 .wpallimport-plugin .wpallimport-addon .custom-params tr td.action{
787 width: auto !important;
788 }
789 .wpallimport-plugin .wpallimport-addon .wpallimport-custom-fields-actions{
790 right:0 !important;
791 }
792 .wpallimport-plugin .wpallimport-addon table tr td.wpallimport-enum-input-wrapper{
793 width: 80%;
794 }
795 .wpallimport-plugin .wpallimport-addon table tr td.wpallimport-enum-input-wrapper input{
796 width: 100%;
797 }
798 .wpallimport-plugin .wpallimport-addon .wpallimport-custom-fields-actions{
799 float: right;
800 right: 30px;
801 position: relative;
802 border: 1px solid #ddd;
803 margin-bottom: 10px;
804 }
805
806 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options {
807 margin-bottom: 15px;
808 margin-top: -16px;
809 }
810 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-content-section{
811 padding-bottom: 8px;
812 margin:0;
813 border: none;
814 padding-top: 1px;
815 background: #f1f2f2;
816 }
817 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-collapsed-header{
818 padding-left: 13px;
819 }
820 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options .wpallimport-collapsed-header h3{
821 font-size: 14px;
822 margin: 6px 0;
823 }
824
825 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width{
826 bottom: -40px;
827 margin-bottom: 0;
828 margin-left: -25px;
829 margin-right: -25px;
830 position: relative;
831 }
832 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width .wpallimport-content-section{
833 margin:0;
834 border-top:1px solid #ddd;
835 border-bottom: none;
836 border-right: none;
837 border-left: none;
838 background: #f1f2f2;
839 }
840 .wpallimport-plugin .wpallimport-addon .wpallimport-sub-options-full-width .wpallimport-collapsed-header h3{
841 margin: 14px 0;
842 }
843
844 .wpallimport-plugin .wpallimport-addon .wpallimport-dependent-options{
845 margin-left: 1px;
846 margin-right: -1px;
847 }
848 .wpallimport-plugin .wpallimport-addon .wpallimport-dependent-options .wpallimport-content-section{
849 border: 1px solid #ddd;
850 border-top: none;
851 }
852 .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-bottom{
853 margin-left: -25px;
854 margin-right: -25px;
855 }
856 .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-not-bottom{
857 margin: 25px -1px 25px 1px;
858 }
859 .wpallimport-plugin .wpallimport-addon .wpallimport-full-with-not-bottom .wpallimport-content-section{
860 border: 1px solid #ddd;
861 }
862 .wpallimport-plugin .wpallimport-addon .wpallimport-add-on-options-title{
863 font-size: 14px;
864 margin: 45px 0 15px 0;
865 }
866 </style>
867 <div class="wpallimport-collapsed wpallimport-section wpallimport-addon '.\esc_attr($this->slug).' closed">
868 <div class="wpallimport-content-section">
869 <div class="wpallimport-collapsed-header">
870 <h3>'.\esc_html($name).'</h3>
871 </div>
872 <div class="wpallimport-collapsed-content" style="padding: 0;">
873 <div class="wpallimport-collapsed-content-inner">
874 <table class="form-table" style="max-width:none;">
875 <tr>
876 <td colspan="3">';
877 }
878
879 function helper_metabox_bottom() {
880
881 return ' </td>
882 </tr>
883 </table>
884 </div>
885 </div>
886 </div>
887 </div>';
888
889 }
890
891 /**
892 *
893 * simply add an additional section for attachments
894 *
895 */
896 function import_files( $slug, $title, $callback = NULL ){
897 $this->import_images( $slug, $title, 'files', $callback);
898 }
899
900 /**
901 *
902 * simply add an additional section
903 *
904 */
905 function import_images( $slug, $title, $type = 'images', $callback = NULL ){
906
907 if ( empty($title) or empty($slug) ) return;
908
909 if (is_array($slug)) {
910 $section_slug = 'pmxi_' . md5(serialize($slug));
911 } else {
912 $section_slug = 'pmxi_' . $slug;
913 }
914
915 $this->image_sections[] = array(
916 'title' => $title,
917 'slug' => $section_slug,
918 'type' => $type
919 );
920
921 foreach ($this->image_options as $option_slug => $value) {
922 $this->add_option($section_slug . $option_slug, $value);
923 }
924
925 if (count($this->image_sections) > 1){
926 add_filter('wp_all_import_is_show_add_new_images', array($this, 'filter_is_show_add_new_images'), 10, 2);
927 }
928
929 add_filter('wp_all_import_is_allow_import_images', array($this, 'is_allow_import_images'), 10, 2);
930
931 if ($callback && is_callable($callback)) {
932 add_action( $section_slug, $callback, 10, 4);
933 } else {
934 if (function_exists($slug)) {
935 add_action( $section_slug, $slug, 10, 4);
936 }
937 }
938 }
939 /**
940 *
941 * filter to allow import images for free edition of WP All Import
942 *
943 */
944 function is_allow_import_images($is_allow, $post_type){
945 return ($this->is_active_addon($post_type)) ? true : $is_allow;
946 }
947
948 /**
949 *
950 * filter to control additional images sections
951 *
952 */
953 function additional_sections($sections){
954 if ( ! empty($this->image_sections) ){
955 foreach ($this->image_sections as $add_section) {
956 $sections[] = $add_section;
957 }
958 }
959
960 return $sections;
961 }
962 /**
963 *
964 * remove the 'Don't touch existing images, append new images' when more than one image section is in use.
965 *
966 */
967 function filter_is_show_add_new_images($is_show, $post_type){
968 return ($this->is_active_addon($post_type)) ? false : $is_show;
969 }
970
971 /**
972 *
973 * disable the default images section
974 *
975 */
976 function disable_default_images($post_type = false){
977
978 add_filter('wp_all_import_is_images_section_enabled', array($this, 'is_enable_default_images_section'), 10, 2);
979
980 }
981 function is_enable_default_images_section($is_enabled, $post_type){
982
983 return ($this->is_active_addon($post_type)) ? false : true;
984
985 }
986
987 function helper_parse($parsingData, $options) {
988
989 extract($parsingData);
990
991 $data = array(); // parsed data
992
993 if ( ! empty($import->options[$this->slug])){
994
995 $this->logger = $parsingData['logger'];
996
997 $cxpath = $xpath_prefix . $import->xpath;
998
999 $tmp_files = array();
1000
1001 foreach ($options[$this->slug] as $option_name => $option_value) {
1002 if ( isset($import->options[$this->slug][$option_name]) and $import->options[$this->slug][$option_name] != '') {
1003 if ($import->options[$this->slug][$option_name] == "xpath") {
1004 if ($import->options[$this->slug]['xpaths'][$option_name] == ""){
1005 $count and $data[$option_name] = array_fill(0, $count, "");
1006 } else {
1007 $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug]['xpaths'][$option_name], $file)->parse();
1008 $tmp_files[] = $file;
1009 }
1010 }
1011 else {
1012 $data[$option_name] = XmlImportParser::factory($xml, $cxpath, (string) $import->options[$this->slug][$option_name], $file)->parse();
1013 $tmp_files[] = $file;
1014 }
1015
1016
1017 } else {
1018 $data[$option_name] = array_fill(0, $count, "");
1019 }
1020
1021 }
1022
1023 foreach ($tmp_files as $file) { // remove all temporary files created
1024 wp_delete_file($file);
1025 }
1026
1027 }
1028
1029 return $data;
1030 }
1031
1032
1033 function can_update_meta($meta_key, $import_options) {
1034
1035 $import_options = $import_options['options'];
1036
1037 if ($import_options['update_all_data'] == 'yes') return true;
1038
1039 if ( ! $import_options['is_update_custom_fields'] ) return false;
1040
1041 if ($import_options['update_custom_fields_logic'] == "full_update") return true;
1042 if ($import_options['update_custom_fields_logic'] == "only" and ! empty($import_options['custom_fields_list']) and is_array($import_options['custom_fields_list']) and in_array($meta_key, $import_options['custom_fields_list']) ) return true;
1043 if ($import_options['update_custom_fields_logic'] == "all_except" and ( empty($import_options['custom_fields_list']) or ! in_array($meta_key, $import_options['custom_fields_list']) )) return true;
1044
1045 return false;
1046
1047 }
1048
1049 function can_update_taxonomy($tax_name, $import_options) {
1050
1051 $import_options = $import_options['options'];
1052
1053 if ($import_options['update_all_data'] == 'yes') return true;
1054
1055 if ( ! $import_options['is_update_categories'] ) return false;
1056
1057 if ($import_options['update_categories_logic'] == "full_update") return true;
1058 if ($import_options['update_categories_logic'] == "only" and ! empty($import_options['taxonomies_list']) and is_array($import_options['taxonomies_list']) and in_array($tax_name, $import_options['taxonomies_list']) ) return true;
1059 if ($import_options['update_categories_logic'] == "all_except" and ( empty($import_options['taxonomies_list']) or ! in_array($tax_name, $import_options['taxonomies_list']) )) return true;
1060
1061 return false;
1062
1063 }
1064
1065 function can_update_image($import_options) {
1066
1067 $import_options = $import_options['options'];
1068
1069 if ($import_options['update_all_data'] == 'yes') return true;
1070
1071 if (!$import_options['is_update_images']) return false;
1072
1073 if ($import_options['is_update_images']) return true;
1074
1075 return false;
1076 }
1077
1078
1079 function admin_notice_ignore() {
1080 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1081 if (isset($_GET[$this->slug.'_ignore']) && '0' == $_GET[$this->slug.'_ignore'] ) {
1082 update_option(\sanitize_key($this->slug).'_notice_ignore', 'true');
1083 }
1084 }
1085
1086 function display_admin_notice() {
1087
1088
1089 if ($this->notice_text) {
1090 $notice_text = $this->notice_text;
1091 } else {
1092 $notice_text = $this->name.' requires WP All Import <a href="http://www.wpallimport.com/" target="_blank">Pro</a> or <a href="http://wordpress.org/plugins/wp-all-import" target="_blank">Free</a>.';
1093 }
1094
1095 if (!get_option(sanitize_key($this->slug).'_notice_ignore')) {
1096
1097 ?>
1098
1099 <div class="error notice is-dismissible wpallimport-dismissible" style="margin-top: 10px;" rel="<?php echo esc_attr(sanitize_key($this->slug)); ?>">
1100 <p><?php echo \wp_kses_post( $notice_text ); ?></p>
1101 </div>
1102
1103 <?php
1104
1105 }
1106
1107 }
1108
1109 /*
1110 *
1111 * $conditions - array('themes' => array('Realia'), 'plugins' => array('plugin-directory/plugin-file.php', 'plugin-directory2/plugin-file.php'))
1112 *
1113 */
1114 function admin_notice($notice_text = '', $conditions = array()) {
1115
1116 $is_show_notice = false;
1117
1118 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
1119
1120 if ( ! class_exists( 'PMXI_Plugin' ) ) {
1121 $is_show_notice = true;
1122 }
1123
1124 // Supported Themes
1125 if ( ! $is_show_notice and ! empty($conditions['themes']) ){
1126
1127 $themeInfo = wp_get_theme();
1128 $parentInfo = $themeInfo->parent();
1129 $currentTheme = $themeInfo->get('Name');
1130
1131 $is_show_notice = in_array($currentTheme, $conditions['themes']) ? false : true;
1132
1133 if ( $is_show_notice and $parentInfo ){
1134 $parent_theme = $parentInfo->get('Name');
1135 $is_show_notice = in_array($parent_theme, $conditions['themes']) ? false : true;
1136 }
1137
1138 }
1139
1140 // Required Plugins
1141 if ( ! $is_show_notice and ! empty($conditions['plugins']) ){
1142
1143 $requires_counter = 0;
1144 foreach ($conditions['plugins'] as $plugin) {
1145 if ( is_plugin_active($plugin) ) $requires_counter++;
1146 }
1147
1148 if ($requires_counter != count($conditions['plugins'])){
1149 $is_show_notice = true;
1150 }
1151
1152 }
1153
1154 if ( $is_show_notice ){
1155
1156 if ( $notice_text != '' ) {
1157 $this->notice_text = $notice_text;
1158 }
1159
1160 add_action('admin_notices', array($this, 'display_admin_notice'));
1161 }
1162
1163 }
1164
1165 function log( $m = false){
1166
1167 $m and $this->logger and call_user_func($this->logger, $m);
1168
1169 }
1170
1171 public function remove_post_type( $type = '' ) {
1172 if ( ! empty( $type ) ) {
1173 $this->add_option( 'post_types_to_remove', $type );
1174 }
1175 }
1176
1177 public function filter_post_types( $custom_types = array(), $custom_type = '' ) {
1178 $options = $this->options_array();
1179 $option_key = 'post_types_to_remove';
1180
1181 if ( array_key_exists( $option_key, $options ) ) {
1182 $type = $options[ $option_key ];
1183
1184 if ( ! empty( $type ) ) {
1185 if ( ! is_array( $type ) ) {
1186 if ( array_key_exists( $type, $custom_types ) ) {
1187 unset( $custom_types[ $type ] );
1188 }
1189 } else {
1190 foreach ( $type as $key => $post_type ) {
1191 if ( array_key_exists( $post_type, $custom_types ) ) {
1192 unset( $custom_types[ $post_type ] );
1193 }
1194 }
1195 }
1196 }
1197 }
1198 return $custom_types;
1199 }
1200
1201 public function sort_post_types( array $order ) {
1202 $options = $this->options_array();
1203 $option_key = 'post_type_move';
1204
1205 if ( array_key_exists( $option_key, $options ) ) {
1206 $move_rules = \pmxi_maybe_unserialize( $options[ $option_key ] );
1207
1208 foreach ( $move_rules as $rule ) {
1209 $move_this = $rule['move_this'];
1210 $move_to = $rule['move_to'];
1211 if ( $move_to > count( $order ) ) {
1212 if ( ( $rm_key = array_search( $move_this, $order ) ) !== false ) {
1213 unset( $order[ $rm_key ] );
1214 }
1215 array_push( $order, $move_this );
1216 } else {
1217 if ( ( $rm_key = array_search( $move_this, $order ) ) !== false ) {
1218 unset( $order[ $rm_key ] );
1219 }
1220 array_splice( $order, $move_to, 0, $move_this );
1221 }
1222 }
1223
1224 return $order;
1225 }
1226
1227 return $order;
1228 }
1229
1230 public function move_post_type( $move_this = null, $move_to = null ) {
1231 $move_rules = array();
1232
1233 if ( ! is_array( $move_this ) && ! is_array( $move_to ) ) {
1234 $move_rules[] = array(
1235 'move_this' => $move_this,
1236 'move_to' => $move_to
1237 );
1238 } else {
1239 foreach ( $move_this as $key => $move_post ) {
1240 $move_rules[] = array(
1241 'move_this' => $move_post,
1242 'move_to' => $move_to[ $key ]
1243 );
1244 }
1245 }
1246
1247 $this->add_option( 'post_type_move', $move_rules );
1248 }
1249
1250 public function set_post_type_image( $post_type = null, $image = null ) {
1251 $post_type_image_rules = array();
1252
1253 if ( ! is_array( $post_type ) ) {
1254
1255 $post_type_image_rules[ $post_type ] = array(
1256 'post_type' => $post_type,
1257 'image' => $image
1258 );
1259
1260 } else {
1261
1262 if ( count( $post_type ) == count( $image ) ) {
1263
1264 foreach ( $post_type as $key => $post_name ) {
1265 $post_type_image_rules[ $post_name ] = array(
1266 'post_type' => $post_name,
1267 'image' => $image[ $key ]
1268 );
1269 }
1270 }
1271 }
1272
1273 $this->add_option( 'post_type_image', $post_type_image_rules );
1274 }
1275
1276 public function post_type_image( $image ) {
1277 $options = $this->options_array();
1278 $option_key = 'post_type_image';
1279 if ( array_key_exists( $option_key, $options ) ) {
1280 $post_type_image_rules = \pmxi_maybe_unserialize( $options[ $option_key ] );
1281 return $post_type_image_rules;
1282 }
1283 return $image;
1284 }
1285 }
1286 }
1287