PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.7.5
Import WP – CSV & XML Import Export for WordPress v2.7.5
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.5, at class/Common/Addon/AddonBaseField.php

165 lines 4.7 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_keys = [
93 '_meta._title',
94 '_meta._alt',
95 '_meta._caption',
96 '_meta._description',
97 '_enable_image_hash',
98 '_download',
99 '_featured',
100 '_remote_url',
101 '_ftp_user',
102 '_ftp_host',
103 '_ftp_pass',
104 '_ftp_path',
105 '_local_url',
106 '_meta._enabled'
107 ];
108 $attachment_data = [
109 'location' => $this->_process_data[$field_id . '.location'],
110 ];
111
112 foreach ($attachment_keys as $k) {
113 if (isset($this->_process_data[$field_id . '.settings.' . $k])) {
114 $attachment_data[$k] = $this->_process_data[$field_id . '.settings.' . $k];
115 } elseif (isset($this->_process_data[$field_id . '.' . $k])) {
116 $attachment_data[$k] = $this->_process_data[$field_id . '.' . $k];
117 } else {
118 $attachment_data[$k] = '';
119 }
120 }
121 return $this->_process_template->process_attachment($object_id, $attachment_data, $attachment_prefix, $filesystem, $ftp, $attachment);
122 }
123
124 public function save($callback)
125 {
126 $this->_process_callback = $callback;
127 return $this;
128 }
129
130 public function options($options)
131 {
132 if (!isset($this->_data['settings'])) {
133 $this->_data['settings'] = [];
134 }
135
136 $this->_data['settings']['options'] = $options;
137 return $this;
138 }
139
140 public function default($value)
141 {
142 if (!isset($this->_data['settings'])) {
143 $this->_data['settings'] = [];
144 }
145
146 $this->_data['settings']['default'] = $value;
147 return $this;
148 }
149
150 public function tooltip($message)
151 {
152 if (!isset($this->_data['settings'])) {
153 $this->_data['settings'] = [];
154 }
155
156 $this->_data['settings']['tooltip'] = $message;
157 return $this;
158 }
159
160 public function get_id()
161 {
162 return isset($this->_data['id']) ? $this->_data['id'] : false;
163 }
164 }
165