VariableProductTitle
9 years ago
.gitkeep
11 years ago
WpaeInvalidPhpException.php
9 years ago
WpaeInvalidStringException.php
9 years ago
WpaeMethodNotFoundException.php
9 years ago
WpaePhpInterpreterErrorHandler.php
2 years ago
WpaeString.php
9 years ago
WpaeTooMuchRecursionException.php
9 years ago
WpaeXmlProcessor.php
2 years ago
XmlCsvExport.php
2 years ago
XmlExportComment.php
4 years ago
XmlExportCpt.php
2 years ago
XmlExportCustomRecord.php
3 years ago
XmlExportEngine.php
2 years ago
XmlExportFiltering.php
4 years ago
XmlExportMediaGallery.php
3 years ago
XmlExportTaxonomy.php
4 years ago
XmlGoogleMerchants.php
9 years ago
XmlSpec.php
9 years ago
XmlExportCustomRecord.php
345 lines
| 1 | <?php |
| 2 | |
| 3 | if (!class_exists('XmlExportCustomRecord')) { |
| 4 | final class XmlExportCustomRecord { |
| 5 | |
| 6 | private $default_fields = []; |
| 7 | |
| 8 | private $author_fields = []; |
| 9 | |
| 10 | private $other_fields = []; |
| 11 | |
| 12 | private $parent_fields = []; |
| 13 | |
| 14 | private $advanced_fields = []; |
| 15 | |
| 16 | public static $is_active = true; |
| 17 | |
| 18 | public function __construct() { |
| 19 | if (XmlExportEngine::$exportOptions['export_type'] == 'specific' and strpos(XmlExportEngine::$exportOptions['cpt'][0], 'custom_') !== 0) { |
| 20 | self::$is_active = false; |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | do_action('pmxe_custom_record_export', XmlExportEngine::$exportOptions); |
| 25 | } |
| 26 | |
| 27 | |
| 28 | // [\FILTERS] |
| 29 | |
| 30 | public function init(& $existing_meta_keys = array()) { |
| 31 | if (!self::$is_active) return; |
| 32 | |
| 33 | if(PMXE_Plugin::$session->get('exportQuery') && !XmlExportEngine::$exportQuery) { |
| 34 | XmlExportEngine::$exportQuery = PMXE_Plugin::$session->get('exportQuery'); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | public static function prepare_data($record, $exportOptions, $xmlWriter, $implode_delimiter, $preview) { |
| 39 | $article = array(); |
| 40 | |
| 41 | if (wp_all_export_is_compatible() && isset($exportOptions['is_generate_import']) && $exportOptions['is_generate_import'] && $exportOptions['import_id']) { |
| 42 | $postRecord = new PMXI_Post_Record(); |
| 43 | $postRecord->clear(); |
| 44 | $postRecord->getBy(array( |
| 45 | 'post_id' => $record->id, |
| 46 | 'import_id' => $exportOptions['import_id'], |
| 47 | )); |
| 48 | |
| 49 | if ($postRecord->isEmpty()) { |
| 50 | $postRecord->set(array( |
| 51 | 'post_id' => $record->id, |
| 52 | 'import_id' => $exportOptions['import_id'], |
| 53 | 'unique_key' => $record->id |
| 54 | ))->save(); |
| 55 | } |
| 56 | unset($postRecord); |
| 57 | } |
| 58 | |
| 59 | $is_xml_export = false; |
| 60 | |
| 61 | if ( |
| 62 | !empty($xmlWriter) && |
| 63 | isset($exportOptions['export_to']) && |
| 64 | $exportOptions['export_to'] == 'xml' && |
| 65 | !in_array($exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants'))) |
| 66 | { |
| 67 | $is_xml_export = true; |
| 68 | } |
| 69 | |
| 70 | foreach ($exportOptions['ids'] as $ID => $value) { |
| 71 | $fieldName = apply_filters('wp_all_export_field_name', wp_all_export_parse_field_name($exportOptions['cc_name'][$ID]), $ID); |
| 72 | $fieldValue = $exportOptions['cc_value'][$ID]; |
| 73 | $fieldLabel = $exportOptions['cc_label'][$ID]; |
| 74 | $fieldSql = $exportOptions['cc_sql'][$ID]; |
| 75 | $fieldPhp = $exportOptions['cc_php'][$ID]; |
| 76 | $fieldCode = $exportOptions['cc_code'][$ID]; |
| 77 | $fieldType = $exportOptions['cc_type'][$ID]; |
| 78 | $fieldOptions = isset($exportOptions['cc_options']) ? $exportOptions['cc_options'][$ID] : []; |
| 79 | $fieldSettings = empty($exportOptions['cc_settings'][$ID]) ? $fieldOptions : $exportOptions['cc_settings'][$ID]; |
| 80 | |
| 81 | if (empty($fieldName) or empty($fieldType) or !is_numeric($ID)) continue; |
| 82 | |
| 83 | $element_name = (!empty($fieldName)) ? $fieldName : 'untitled_' . $ID; |
| 84 | |
| 85 | $element_name_ns = ''; |
| 86 | |
| 87 | if ($is_xml_export) { |
| 88 | //$element_name = (!empty($fieldName)) ? preg_replace('/[^a-z0-9_:-]/i', '', $fieldName) : 'untitled_' . $ID; |
| 89 | |
| 90 | if (strpos($element_name, ":") !== false) { |
| 91 | $element_name_parts = explode(":", $element_name); |
| 92 | $element_name_ns = (empty($element_name_parts[0])) ? '' : $element_name_parts[0]; |
| 93 | $element_name = (empty($element_name_parts[1])) ? 'untitled_' . $ID : preg_replace('/[^a-z0-9_-]/i', '', $element_name_parts[1]); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | $fieldSnipped = (!empty($fieldPhp) and !empty($fieldCode)) ? $fieldCode : false; |
| 98 | |
| 99 | if (isset($exportOptions['cc_combine_multiple_fields'][$ID]) && $exportOptions['cc_combine_multiple_fields'][$ID]) { |
| 100 | |
| 101 | $combineMultipleFieldsValue = $exportOptions['cc_combine_multiple_fields_value'][$ID]; |
| 102 | |
| 103 | $combineMultipleFieldsValue = stripslashes($combineMultipleFieldsValue); |
| 104 | $snippetParser = new \Wpae\App\Service\SnippetParser(); |
| 105 | $snippets = $snippetParser->parseSnippets($combineMultipleFieldsValue); |
| 106 | $engine = new XmlExportEngine(XmlExportEngine::$exportOptions); |
| 107 | $engine->init_available_data(); |
| 108 | $engine->init_additional_data(); |
| 109 | $snippets = $engine->get_fields_options($snippets); |
| 110 | |
| 111 | $articleData = self::prepare_data($record, $snippets, $xmlWriter, $implode_delimiter, $preview); |
| 112 | |
| 113 | $functions = $snippetParser->parseFunctions($combineMultipleFieldsValue); |
| 114 | $combineMultipleFieldsValue = \Wpae\App\Service\CombineFields::prepareMultipleFieldsValue($functions, $combineMultipleFieldsValue, $articleData); |
| 115 | |
| 116 | if ($preview) { |
| 117 | $combineMultipleFieldsValue = trim(preg_replace('~[\r\n]+~', ' ', htmlspecialchars($combineMultipleFieldsValue))); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | wp_all_export_write_article($article, $element_name, pmxe_filter($combineMultipleFieldsValue, $fieldSnipped)); |
| 122 | |
| 123 | } else { |
| 124 | |
| 125 | |
| 126 | $addon = GF_Export_Add_On::get_instance(); |
| 127 | $addon->add_on->handle_element($article, $element_name, $fieldValue, $record, $fieldSnipped, $preview); |
| 128 | |
| 129 | } |
| 130 | |
| 131 | if ($is_xml_export and isset($article[$element_name])) { |
| 132 | |
| 133 | $element_name_in_file = XmlCsvExport::_get_valid_header_name($element_name); |
| 134 | |
| 135 | $element_name_in_file = str_replace(' ', '', $element_name_in_file); |
| 136 | $element_name_in_file = str_replace('-', '_', $element_name_in_file); |
| 137 | $element_name_in_file = str_replace('/', '_', $element_name_in_file); |
| 138 | |
| 139 | $xmlWriter = apply_filters('wp_all_export_add_before_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $record->id); |
| 140 | |
| 141 | $xmlWriter->beginElement($element_name_ns, $element_name_in_file, null); |
| 142 | $xmlWriter->writeData($article[$element_name], $element_name_in_file); |
| 143 | $xmlWriter->closeElement(); |
| 144 | |
| 145 | $xmlWriter = apply_filters('wp_all_export_add_after_element', $xmlWriter, $element_name_in_file, XmlExportEngine::$exportID, $record->id); |
| 146 | |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | return $article; |
| 151 | } |
| 152 | |
| 153 | public static function prepare_import_template( $exportOptions, &$templateOptions, $element_name, $ID) { |
| 154 | |
| 155 | $rapid_addon = \GF_Export_Add_On::get_instance()->add_on; |
| 156 | |
| 157 | $element_slug = $exportOptions['cc_label'][$ID]; |
| 158 | |
| 159 | $element_location = $rapid_addon->get_element_location($element_slug); |
| 160 | |
| 161 | $element_data = $rapid_addon->get_data_element_by_slug($element_slug); |
| 162 | |
| 163 | if($element_location === 'meta') { |
| 164 | |
| 165 | if(isset($element_data['consent']) && $element_data['consent']) { |
| 166 | |
| 167 | $element_name_in_file = $element_data['element_meta_key']; |
| 168 | $element_name_in_file = explode(".", $element_name_in_file); |
| 169 | $element_name_in_file = $element_name_in_file[0]; |
| 170 | |
| 171 | if($exportOptions['export_to'] === 'csv') { |
| 172 | $templateOptions['pmgi']['fields'][$element_name_in_file] = '{consentconsent[1]}'; |
| 173 | $templateOptions['pmgi']['is_multiple_field_value'][$element_name_in_file] = 'no'; |
| 174 | } |
| 175 | else { |
| 176 | $templateOptions['pmgi']['fields'][$element_name_in_file] = '{Consent_Consent[1]}'; |
| 177 | $templateOptions['pmgi']['is_multiple_field_value'][$element_name_in_file] = 'no'; |
| 178 | } |
| 179 | } else { |
| 180 | if ($exportOptions['export_to'] === 'csv') { |
| 181 | |
| 182 | $element_value = '{' . $element_name . '[1]}'; |
| 183 | |
| 184 | if (isset($templateOptions['pmgi']['fields']) && is_array($templateOptions['pmgi']['fields']) && in_array($element_value, $templateOptions['pmgi']['fields'])) { |
| 185 | $field_order = 2; |
| 186 | |
| 187 | while (in_array('{' . $element_name . '_' . $field_order . '[1]}', $templateOptions['pmgi']['fields'])) { |
| 188 | $field_order++; |
| 189 | } |
| 190 | |
| 191 | $templateOptions['pmgi']['fields'][$element_data['element_meta_key']] = '{' . $element_name . '_' . $field_order . '[1]}'; |
| 192 | } else { |
| 193 | $templateOptions['pmgi']['fields'][$element_data['element_meta_key']] = $element_value; |
| 194 | } |
| 195 | |
| 196 | $templateOptions['pmgi']['is_multiple_field_value'][$element_data['element_meta_key']] = 'no'; |
| 197 | |
| 198 | } else { |
| 199 | |
| 200 | |
| 201 | $element_name = str_replace(' ', '', $element_data['element_label']); |
| 202 | |
| 203 | $element_name = str_replace(['-', '/'], '-', $element_name); |
| 204 | |
| 205 | $i = 1; |
| 206 | |
| 207 | if(isset($templateOptions['pmgi']['fields']) && is_array($templateOptions['pmgi']['fields'])) { |
| 208 | while (in_array('{' . $element_name . '[' . $i . ']}', $templateOptions['pmgi']['fields'])) { |
| 209 | $i++; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | $templateOptions['pmgi']['fields'][$element_data['element_meta_key']] = '{' . str_replace('-', '_', $element_name) . '[' . $i . ']}'; |
| 214 | $templateOptions['pmgi']['is_multiple_field_value'][$element_data['element_meta_key']] = 'no'; |
| 215 | |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | |
| 220 | } else if ($element_location === 'related_table') { |
| 221 | |
| 222 | switch ($element_slug) { |
| 223 | |
| 224 | case 'user_name': |
| 225 | $templateOptions['pmgi']['notes'][0]['username'] = '{' . $element_name . '[1]}'; |
| 226 | break; |
| 227 | |
| 228 | case 'value': |
| 229 | $templateOptions['pmgi']['notes'][0]['note_text'] = '{' . $element_name . '[1]}'; |
| 230 | break; |
| 231 | |
| 232 | case 'note_type': |
| 233 | $templateOptions['pmgi']['notes'][0]['note_type'] = '{' . $element_name . '[1]}'; |
| 234 | break; |
| 235 | |
| 236 | case 'sub_type': |
| 237 | $templateOptions['pmgi']['notes'][0]['note_sub_type'] = '{' . $element_name . '[1]}'; |
| 238 | break; |
| 239 | |
| 240 | } |
| 241 | |
| 242 | if(strpos($element_slug, 'date_created') === 0) { |
| 243 | $templateOptions['pmgi']['notes'][0]['date'] = '{' . $element_name . '[1]}'; |
| 244 | |
| 245 | } |
| 246 | |
| 247 | } else if ($element_location === 'main_table') { |
| 248 | |
| 249 | if($exportOptions['export_to'] === 'csv') { |
| 250 | |
| 251 | $other_entry_data = [ |
| 252 | 'datecreated', |
| 253 | 'dateupdated', |
| 254 | 'starred', |
| 255 | 'read', |
| 256 | 'ip', |
| 257 | 'sourceurl', |
| 258 | 'useragent', |
| 259 | 'createdbyuserid', |
| 260 | 'status' |
| 261 | ]; |
| 262 | } else { |
| 263 | $other_entry_data = [ |
| 264 | 'DateCreated', |
| 265 | 'DateUpdated', |
| 266 | 'Starred', |
| 267 | 'Read', |
| 268 | 'IP', |
| 269 | 'SourceURL', |
| 270 | 'UserAgent', |
| 271 | 'CreatedByUserID', |
| 272 | 'Status' |
| 273 | ]; |
| 274 | } |
| 275 | |
| 276 | if(in_array($element_name, $other_entry_data)) { |
| 277 | |
| 278 | if($element_name === 'sourceurl' || $element_name === 'SourceURL') { |
| 279 | $wpai_element_name = 'source_url'; |
| 280 | } else if ($element_name === 'useragent' || $element_name === 'UserAgent') { |
| 281 | $wpai_element_name = 'user_agent'; |
| 282 | } else if ($element_name === 'createdbyuserid' || $element_name === 'CreatedByUserID') { |
| 283 | $wpai_element_name = 'created_by'; |
| 284 | } |
| 285 | else if ($element_name === 'datecreated' || $element_name === 'DateCreated') { |
| 286 | $wpai_element_name = 'date_created'; |
| 287 | } |
| 288 | else if ($element_name === 'dateupdated' || $element_name === 'DateUpdated') { |
| 289 | $wpai_element_name = 'date_updated'; |
| 290 | } |
| 291 | |
| 292 | else { |
| 293 | $wpai_element_name = str_replace('_', '', strtolower($element_name)); |
| 294 | } |
| 295 | |
| 296 | if(in_array($element_name, ['starred', 'read', 'status']) || in_array($element_name, ['Starred', 'Read', 'Status'])) { |
| 297 | $templateOptions['pmgi'][strtolower($wpai_element_name)] = 'xpath'; |
| 298 | $templateOptions['pmgi'][strtolower($element_name). "_xpath"] = '{' . $element_name . '[1]}'; |
| 299 | } else { |
| 300 | $templateOptions['pmgi'][strtolower($wpai_element_name)] = '{' . $element_name . '[1]}'; |
| 301 | $templateOptions['is_update_' . $exportOptions['cc_type'][$ID]] = 1; |
| 302 | } |
| 303 | |
| 304 | } |
| 305 | |
| 306 | if ($element_name === 'id'){ |
| 307 | |
| 308 | if ($element_name == 'ID' && !$ID && $exportOptions['export_to'] == 'csv' && $exportOptions['export_to_sheet'] != 'csv') { |
| 309 | $element_name = 'id'; |
| 310 | } |
| 311 | |
| 312 | $templateOptions['unique_key'] = '{' . $element_name . '[1]}'; |
| 313 | $templateOptions['tmp_unique_key'] = '{' . $element_name . '[1]}'; |
| 314 | $templateOptions['single_product_id'] = '{' . $element_name . '[1]}'; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * __get function. |
| 323 | * |
| 324 | * @access public |
| 325 | * @param mixed $key |
| 326 | * @return mixed |
| 327 | */ |
| 328 | public function __get($key) { |
| 329 | return $this->get($key); |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Get a session variable |
| 334 | * |
| 335 | * @param string $key |
| 336 | * @param mixed $default used if the session variable isn't set |
| 337 | * @return mixed value of session variable |
| 338 | */ |
| 339 | public function get($key, $default = null) { |
| 340 | return isset($this->{$key}) ? $this->{$key} : $default; |
| 341 | } |
| 342 | |
| 343 | } |
| 344 | } |
| 345 |