PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.2.10
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.2.10
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 / XmlExportComment.php
wp-all-export / libraries Last commit date
VariableProductTitle 4 years ago .gitkeep 4 years ago WpaeInvalidPhpException.php 4 years ago WpaeInvalidStringException.php 4 years ago WpaeMethodNotFoundException.php 4 years ago WpaePhpInterpreterErrorHandler.php 4 years ago WpaeString.php 4 years ago WpaeTooMuchRecursionException.php 4 years ago WpaeXmlProcessor.php 4 years ago XmlCsvExport.php 4 years ago XmlExportACF.php 4 years ago XmlExportComment.php 4 years ago XmlExportCpt.php 4 years ago XmlExportEngine.php 4 years ago XmlExportFiltering.php 4 years ago XmlExportMediaGallery.php 4 years ago XmlExportTaxonomy.php 4 years ago XmlExportUser.php 4 years ago XmlExportWooCommerce.php 4 years ago XmlExportWooCommerceCoupon.php 4 years ago XmlExportWooCommerceOrder.php 4 years ago XmlGoogleMerchants.php 4 years ago XmlSpec.php 4 years ago
XmlExportComment.php
399 lines
1 <?php
2
3 if (!class_exists('XmlExportComment')) {
4 final class XmlExportComment
5 {
6 private $init_fields = array(
7 array(
8 'label' => 'comment_ID',
9 'name' => 'ID',
10 'type' => 'comment_ID'
11 ),
12 array(
13 'label' => 'comment_author_email',
14 'name' => 'Author Email',
15 'type' => 'comment_author_email'
16 ),
17 array(
18 'label' => 'comment_content',
19 'name' => 'Content',
20 'type' => 'comment_content'
21 )
22 );
23
24 private $default_fields = array(
25 array(
26 'label' => 'comment_ID',
27 'name' => 'ID',
28 'type' => 'comment_ID'
29 ),
30 array(
31 'label' => 'comment_post_ID',
32 'name' => 'Post ID',
33 'type' => 'comment_post_ID'
34 ),
35 array(
36 'label' => 'comment_author',
37 'name' => 'Author',
38 'type' => 'comment_author'
39 ),
40 array(
41 'label' => 'comment_author_email',
42 'name' => 'Author Email',
43 'type' => 'comment_author_email'
44 ),
45 array(
46 'label' => 'comment_author_url',
47 'name' => 'Author URL',
48 'type' => 'comment_author_url'
49 ),
50 array(
51 'label' => 'comment_author_IP',
52 'name' => 'Author IP',
53 'type' => 'comment_author_IP'
54 ),
55 array(
56 'label' => 'comment_date',
57 'name' => 'Date',
58 'type' => 'comment_date'
59 ),
60 array(
61 'label' => 'comment_content',
62 'name' => 'Content',
63 'type' => 'comment_content'
64 ),
65 array(
66 'label' => 'comment_karma',
67 'name' => 'Karma',
68 'type' => 'comment_karma'
69 ),
70 array(
71 'label' => 'comment_approved',
72 'name' => 'Approved',
73 'type' => 'comment_approved'
74 ),
75 array(
76 'label' => 'comment_agent',
77 'name' => 'Agent',
78 'type' => 'comment_agent'
79 ),
80 array(
81 'label' => 'comment_type',
82 'name' => 'Type',
83 'type' => 'comment_type'
84 ),
85 array(
86 'label' => 'comment_parent',
87 'name' => 'Comment Parent',
88 'type' => 'comment_parent'
89 ),
90 array(
91 'label' => 'user_id',
92 'name' => 'User ID',
93 'type' => 'user_id'
94 )
95
96 );
97
98 private $advanced_fields = array();
99
100 public static $is_active = true;
101
102 public function __construct()
103 {
104
105 if ((XmlExportEngine::$exportOptions['export_type'] == 'specific' and !in_array('comments', XmlExportEngine::$post_types))
106 or (XmlExportEngine::$exportOptions['export_type'] == 'advanced' and XmlExportEngine::$exportOptions['wp_query_selector'] != 'wp_comment_query')
107 ) {
108 self::$is_active = false;
109 return;
110 }
111
112 add_filter("wp_all_export_available_sections", array(&$this, "filter_available_sections"), 10, 1);
113 add_filter("wp_all_export_init_fields", array(&$this, "filter_init_fields"), 10, 1);
114 add_filter("wp_all_export_default_fields", array(&$this, "filter_default_fields"), 10, 1);
115 add_filter("wp_all_export_other_fields", array(&$this, "filter_other_fields"), 10, 1);
116 }
117
118 // [FILTERS]
119
120 /**
121 *
122 * Filter Init Fields
123 *
124 */
125 public function filter_init_fields($init_fields)
126 {
127 return $this->init_fields;
128 }
129
130 /**
131 *
132 * Filter Default Fields
133 *
134 */
135 public function filter_default_fields($default_fields)
136 {
137 return $this->default_fields;
138 }
139
140 /**
141 *
142 * Filter Other Fields
143 *
144 */
145 public function filter_other_fields($other_fields)
146 {
147 return $this->advanced_fields;
148 }
149
150 /**
151 *
152 * Filter Sections in Available Data
153 *
154 */
155 public function filter_available_sections($sections)
156 {
157
158 unset($sections['cats']);
159 unset($sections['media']);
160 unset($sections['other']);
161
162 $sections['cf']['title'] = __("Comment meta", "wp_all_export_plugin");
163
164 return $sections;
165 }
166
167 // [\FILTERS]
168
169 public function init(& $existing_meta_keys = array())
170 {
171 if (!self::$is_active) return;
172
173 global $wp_version;
174
175 if (!empty(XmlExportEngine::$exportQuery)) {
176 if (version_compare($wp_version, '4.2.0', '>=')) {
177 $comments = XmlExportEngine::$exportQuery->get_comments();
178 } else {
179 $comments = XmlExportEngine::$exportQuery;
180 }
181 }
182
183 if (!empty($comments)) {
184 foreach ($comments as $comment) {
185 $comment_meta = get_comment_meta($comment->comment_ID, '');
186 if (!empty($comment_meta)) {
187 foreach ($comment_meta as $record_meta_key => $record_meta_value) {
188 if (!in_array($record_meta_key, $existing_meta_keys)) {
189 $to_add = true;
190 foreach ($this->default_fields as $default_value) {
191 if ($record_meta_key == $default_value['name'] || $record_meta_key == $default_value['type']) {
192 $to_add = false;
193 break;
194 }
195 }
196 if ($to_add) {
197 foreach ($this->advanced_fields as $advanced_value) {
198 if ($record_meta_key == $advanced_value['name'] || $record_meta_key == $advanced_value['type']) {
199 $to_add = false;
200 break;
201 }
202 }
203 }
204 if ($to_add) $existing_meta_keys[] = $record_meta_key;
205 }
206 }
207 }
208 }
209 }
210 }
211
212 public static function prepare_data($comment, $exportOptions, $xmlWriter = false, $implode_delimiter, $preview)
213 {
214 $article = array();
215
216 // associate exported comment with import
217 if (wp_all_export_is_compatible() && isset($exportOptions['is_generate_import']) && $exportOptions['is_generate_import'] && $exportOptions['import_id']) {
218 $postRecord = new PMXI_Post_Record();
219 $postRecord->clear();
220 $postRecord->getBy(array(
221 'post_id' => $comment->comment_ID,
222 'import_id' => $exportOptions['import_id'],
223 ));
224
225 if ($postRecord->isEmpty()) {
226 $postRecord->set(array(
227 'post_id' => $comment->comment_ID,
228 'import_id' => $exportOptions['import_id'],
229 'unique_key' => $comment->comment_ID
230 ))->save();
231 }
232 unset($postRecord);
233 }
234
235 $is_xml_export = false;
236
237 if (!empty($xmlWriter) and $exportOptions['export_to'] == 'xml' and !in_array($exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants'))) {
238 $is_xml_export = true;
239 }
240
241 foreach ($exportOptions['ids'] as $ID => $value) {
242 $fieldName = apply_filters('wp_all_export_field_name', wp_all_export_parse_field_name($exportOptions['cc_name'][$ID]), $ID);
243 $fieldValue = $exportOptions['cc_value'][$ID];
244 $fieldLabel = $exportOptions['cc_label'][$ID];
245 $fieldSql = $exportOptions['cc_sql'][$ID];
246 $fieldPhp = $exportOptions['cc_php'][$ID];
247 $fieldCode = $exportOptions['cc_code'][$ID];
248 $fieldType = $exportOptions['cc_type'][$ID];
249 $fieldOptions = $exportOptions['cc_options'][$ID];
250 $fieldSettings = empty($exportOptions['cc_settings'][$ID]) ? $fieldOptions : $exportOptions['cc_settings'][$ID];
251
252 if (empty($fieldName) or empty($fieldType) or !is_numeric($ID)) continue;
253
254 $element_name = (!empty($fieldName)) ? $fieldName : 'untitled_' . $ID;
255
256 $element_name_ns = '';
257
258 if ($is_xml_export) {
259 $element_name = (!empty($fieldName)) ? preg_replace('/[^a-z0-9_:-]/i', '', $fieldName) : 'untitled_' . $ID;
260
261 if (strpos($element_name, ":") !== false) {
262 $element_name_parts = explode(":", $element_name);
263 $element_name_ns = (empty($element_name_parts[0])) ? '' : $element_name_parts[0];
264 $element_name = (empty($element_name_parts[1])) ? 'untitled_' . $ID : preg_replace('/[^a-z0-9_-]/i', '', $element_name_parts[1]);
265 }
266 }
267
268 $fieldSnipped = (!empty($fieldPhp) and !empty($fieldCode)) ? $fieldCode : false;
269
270
271 switch ($fieldType) {
272 case 'comment_ID':
273 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_id', pmxe_filter($comment->comment_ID, $fieldSnipped), $comment->comment_ID));
274 break;
275 case 'comment_post_ID':
276 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_post_id', pmxe_filter($comment->comment_post_ID, $fieldSnipped), $comment->comment_ID));
277 break;
278 case 'comment_author':
279 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_author', pmxe_filter($comment->comment_author, $fieldSnipped), $comment->comment_ID));
280 break;
281 case 'comment_author_email':
282 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_author_email', pmxe_filter($comment->comment_author_email, $fieldSnipped), $comment->comment_ID));
283 break;
284 case 'comment_author_url':
285 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_author_url', pmxe_filter($comment->comment_author_url, $fieldSnipped), $comment->comment_ID));
286 break;
287 case 'comment_author_IP':
288 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_author_ip', pmxe_filter($comment->comment_author_IP, $fieldSnipped), $comment->comment_ID));
289 break;
290 case 'comment_karma':
291 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_karma', pmxe_filter($comment->comment_karma, $fieldSnipped), $comment->comment_ID));
292 break;
293 case 'comment_content':
294 $val = apply_filters('pmxe_comment_content', pmxe_filter($comment->comment_content, $fieldSnipped), $comment->comment_ID);
295 wp_all_export_write_article($article, $element_name, ($preview) ? trim(preg_replace('~[\r\n]+~', ' ', htmlspecialchars($val))) : $val);
296 break;
297 case 'comment_date':
298
299 $post_date = prepare_date_field_value($fieldSettings, strtotime($comment->comment_date), "Y-m-d H:i:s");
300
301 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_date', pmxe_filter($post_date, $fieldSnipped), $comment->comment_ID));
302 break;
303 case 'comment_approved':
304 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_approved', pmxe_filter($comment->comment_approved, $fieldSnipped), $comment->comment_ID));
305 break;
306 case 'comment_agent':
307 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_agent', pmxe_filter($comment->comment_agent, $fieldSnipped), $comment->comment_ID));
308 break;
309 case 'comment_type':
310 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_type', pmxe_filter($comment->comment_type, $fieldSnipped), $comment->comment_ID));
311 break;
312 case 'comment_parent':
313 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_comment_parent', pmxe_filter($comment->comment_parent, $fieldSnipped), $comment->comment_ID));
314 break;
315 case 'user_id':
316 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_user_id', pmxe_filter($comment->user_id, $fieldSnipped), $comment->comment_ID));
317 break;
318 case 'cf':
319 if (!empty($fieldValue)) {
320 $cur_meta_values = get_comment_meta($comment->comment_ID, $fieldValue);
321 if (!empty($cur_meta_values) and is_array($cur_meta_values)) {
322 $val = "";
323 foreach ($cur_meta_values as $key => $cur_meta_value) {
324 if (empty($val)) {
325 $val = apply_filters('pmxe_custom_field', pmxe_filter(maybe_serialize($cur_meta_value), $fieldSnipped), $fieldValue, $comment->comment_ID);
326 } else {
327 $val = apply_filters('pmxe_custom_field', pmxe_filter($val . $implode_delimiter . maybe_serialize($cur_meta_value), $fieldSnipped), $fieldValue, $comment->comment_ID);
328 }
329 }
330 wp_all_export_write_article($article, $element_name, $val);
331 }
332
333 if (empty($cur_meta_values)) {
334 if (empty($article[$element_name])) {
335 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_custom_field', pmxe_filter('', $fieldSnipped), $fieldValue, $comment->comment_ID));
336 }
337 }
338 }
339 break;
340 case 'sql':
341 if (!empty($fieldSql)) {
342 global $wpdb;
343 $val = $wpdb->get_var($wpdb->prepare(stripcslashes(str_replace("%%ID%%", "%d", $fieldSql)), $comment->comment_ID));
344 if (!empty($fieldPhp) and !empty($fieldCode)) {
345 // if shortcode defined
346 if (strpos($fieldCode, '[') === 0) {
347 $val = do_shortcode(str_replace("%%VALUE%%", $val, $fieldCode));
348 } else {
349 $val = eval('return ' . stripcslashes(str_replace("%%VALUE%%", $val, $fieldCode)) . ';');
350 }
351 }
352 wp_all_export_write_article($article, $element_name, apply_filters('pmxe_sql_field', $val, $element_name, $comment->comment_ID));
353 }
354 break;
355 default:
356 break;
357
358 }
359
360 if ($is_xml_export and isset($article[$element_name])) {
361 $element_name_in_file = XmlCsvExport::_get_valid_header_name($element_name);
362
363 $xmlWriter = apply_filters('wp_all_export_add_before_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $comment->comment_ID);
364
365 $xmlWriter->beginElement($element_name_ns, $element_name_in_file, null);
366 $xmlWriter->writeData($article[$element_name], $element_name_in_file);
367 $xmlWriter->closeElement();
368
369 $xmlWriter = apply_filters('wp_all_export_add_after_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $comment->comment_ID);
370 }
371 }
372 return $article;
373 }
374
375 /**
376 * __get function.
377 *
378 * @access public
379 * @param mixed $key
380 * @return mixed
381 */
382 public function __get($key)
383 {
384 return $this->get($key);
385 }
386
387 /**
388 * Get a session variable
389 *
390 * @param string $key
391 * @param mixed $default used if the session variable isn't set
392 * @return mixed value of session variable
393 */
394 public function get($key, $default = null)
395 {
396 return isset($this->{$key}) ? $this->{$key} : $default;
397 }
398 }
399 }