PluginProbe
Import WP – CSV & XML Import Export for WordPress / trunk
Import WP – CSV & XML Import Export for WordPress vtrunk
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 trunk 0.1.6 All 142 releases
jc-importer / class / Common / Addon / AddonBaseField.php

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

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