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