PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.7.1
Import WP – CSV & XML Import Export for WordPress v2.7.1
2.15.1 2.15.0 2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 All 144 releases
jc-importer / class / Common / Addon / AddonBaseField.php

AddonBaseField.php in Import WP – CSV & XML Import Export for WordPress 2.7.1, at class/Common/Addon/AddonBaseField.php

158 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImportWP\Common\Addon;
4
5 use ImportWP\Container;
6
7 class AddonBaseField extends AddonBaseData implements AddonFieldInterface
8 {
9 /**
10 * @var callable
11 */
12 protected $_process_callback;
13
14 protected $_is_field_processable = false;
15 protected $_process_mapper;
16 protected $_process_template;
17 protected $_process_data;
18
19 public function _enable_processing()
20 {
21 $this->_is_field_processable = true;
22 }
23
24 public function _is_processing_enabled()
25 {
26 return $this->_is_field_processable;
27 }
28
29 /**
30 * @param AddonBase $addon
31 * @param integer $object_id
32 * @param string $section_id
33 * @param mixed $data
34 * @param \ImportWP\Common\Model\ImporterModel $importer_model
35 * @param \ImportWP\Common\Importer\Template\Template $template
36 * @return void
37 */
38 public function _process($addon, $object_id, $section_id, $data, $importer_model, $template, $i = false)
39 {
40 // setup
41 $this->_process_mapper = $template->get_mapper();
42 $this->_process_template = $template;
43 $this->_process_data = $data;
44
45 if ($this->_process_callback !== false && !is_null($this->_process_callback) && is_callable($this->_process_callback)) {
46 call_user_func($this->_process_callback, new AddonFieldDataApi($addon, $this, $object_id, $section_id, $data, $importer_model, $template, $i));
47 } else {
48
49 $field = $this->data();
50
51 if ($field['type'] === 'attachment') {
52 $meta_value = $this->process_attachment($object_id, $field['id'], $section_id);
53 } else {
54 $meta_value = $data[$field['id']];
55 }
56
57 if ($this->_process_callback === false) {
58 $addon->store_meta($section_id, $object_id, $field['id'], $meta_value, $i);
59 } else {
60 $addon->update_meta($object_id, $field['id'], $meta_value);
61 }
62 }
63
64 // tearmdown
65 $this->_process_mapper = null;
66 $this->_process_template = null;
67 $this->_process_data = null;
68 }
69
70 public function process_attachment($object_id, $field_id = false)
71 {
72 if ($field_id === false) {
73 $field_id = $this->get_id();
74 }
75 /**
76 * @var ImportWP\Common\Filesystem\Filesystem $filesystem
77 */
78
79 $filesystem = $this->addon()->get_service_provider('filesystem');
80
81 /**
82 * @var ImportWP\Common\Ftp\Ftp $ftp
83 */
84 $ftp = $this->addon()->get_service_provider('ftp');
85
86 /**
87 * @var ImportWP\Common\Attachment\Attachment $attachment
88 */
89 $attachment = $this->addon()->get_service_provider('attachment');
90
91 $attachment_prefix = '';
92 $attachment_data = [];
93 $attachment_keys = [
94 'location',
95 '_meta._title',
96 '_meta._alt',
97 '_meta._caption',
98 '_meta._description',
99 '_enable_image_hash',
100 '_download',
101 '_featured',
102 '_remote_url',
103 '_ftp_user',
104 '_ftp_host',
105 '_ftp_pass',
106 '_ftp_path',
107 '_local_url',
108 '_meta._enabled'
109 ];
110
111 foreach ($attachment_keys as $k) {
112 $attachment_data[$k] = $this->_process_data[$field_id . '.' . $k];
113 }
114 return $this->_process_template->process_attachment($object_id, $attachment_data, $attachment_prefix, $filesystem, $ftp, $attachment);
115 }
116
117 public function save($callback)
118 {
119 $this->_process_callback = $callback;
120 return $this;
121 }
122
123 public function options($options)
124 {
125 if (!isset($this->_data['settings'])) {
126 $this->_data['settings'] = [];
127 }
128
129 $this->_data['settings']['options'] = $options;
130 return $this;
131 }
132
133 public function default($value)
134 {
135 if (!isset($this->_data['settings'])) {
136 $this->_data['settings'] = [];
137 }
138
139 $this->_data['settings']['default'] = $value;
140 return $this;
141 }
142
143 public function tooltip($message)
144 {
145 if (!isset($this->_data['settings'])) {
146 $this->_data['settings'] = [];
147 }
148
149 $this->_data['settings']['tooltip'] = $message;
150 return $this;
151 }
152
153 public function get_id()
154 {
155 return isset($this->_data['id']) ? $this->_data['id'] : false;
156 }
157 }
158