private function _importOptions($aStoredOptions, $sPageSlug, $sTabSlug) { $_oImport = new AmazonAutoLinks_AdminPageFramework_ImportOptions($_FILES['__import'], $_POST['__import']); $_aArguments = array('class_name' => $this->oFactory->oProp->sClassName, 'page_slug' => $sPageSlug, 'tab_slug' => $sTabSlug, 'section_id' => $_oImport->getSiblingValue('section_id'), 'pressed_field_id' => $_oImport->getSiblingValue('field_id'), 'pressed_input_id' => $_oImport->getSiblingValue('input_id'), 'should_merge' => $_oImport->getSiblingValue('is_merge')); if ($_oImport->getError() > 0) { $this->oFactory->setSettingNotice($this->oFactory->oMsg->get('import_error')); return $aStoredOptions; } $_aMIMEType = $this->_getImportMIMEType($_aArguments); $_sType = $_oImport->getType(); if (!in_array($_sType, $_aMIMEType)) { $this->oFactory->setSettingNotice(sprintf($this->oFactory->oMsg->get('uploaded_file_type_not_supported'), $_sType)); return $aStoredOptions; } $_mData = $_oImport->getImportData(); if (false === $_mData) { $this->oFactory->setSettingNotice($this->oFactory->oMsg->get('could_not_load_importing_data')); return $aStoredOptions; } $_sFormatType = $this->_getImportFormatType($_aArguments, $_oImport->getFormatType()); $_oImport->formatImportData($_mData, $_sFormatType); $_sImportOptionKey = $this->_getImportOptionKey($_aArguments, $_oImport->getSiblingValue('option_key')); $_mData = $this->_getFilteredImportData($_aArguments, $_mData, $aStoredOptions, $_sFormatType, $_sImportOptionKey); $this->_setImportAdminNotice(empty($_mData)); if ($_sImportOptionKey != $this->oFactory->oProp->sOptionKey) { update_option($_sImportOptionKey, $_mData); return $aStoredOptions; } return $_aArguments['should_merge'] ? $this->uniteArrays($_mData, $aStoredOptions) : $_mData; }
/** * Processes the imported data. * * @since 2.0.0 * @since 2.1.5 Added additional filters with field id and input id. */ private function importOptions($arrStoredOptions, $strPageSlug, $strTabSlug) { $oImport = new AmazonAutoLinks_AdminPageFramework_ImportOptions($_FILES['__import'], $_POST['__import']); $strPressedFieldID = $oImport->getSiblingValue('field_id'); $strPressedInputID = $oImport->getSiblingValue('input_id'); $fMerge = $oImport->getSiblingValue('do_merge'); // Check if there is an upload error. if ($oImport->getError() > 0) { $this->setSettingNotice($this->oMsg->___('import_error')); return $arrStoredOptions; // do not change the framework's options. } // Apply filters to the uploaded file's MIME type. $arrMIMEType = $this->oUtil->addAndApplyFilters($this, array("import_mime_types_{$strPageSlug}_{$strTabSlug}", "import_mime_types_{$strPageSlug}", "import_mime_types_{$this->oProps->strClassName}_{$strPressedInputID}", "import_mime_types_{$this->oProps->strClassName}_{$strPressedFieldID}", "import_mime_types_{$this->oProps->strClassName}"), array('text/plain', 'application/octet-stream'), $strPressedFieldID, $strPressedInputID); // Check the uploaded file MIME type. if (!in_array($oImport->getType(), $arrMIMEType)) { $this->setSettingNotice($this->oMsg->___('uploaded_file_type_not_supported')); return $arrStoredOptions; // do not change the framework's options. } // Retrieve the importing data. $vData = $oImport->getImportData(); if ($vData === false) { $this->setSettingNotice($this->oMsg->___('could_not_load_importing_data')); return $arrStoredOptions; // do not change the framework's options. } // Apply filters to the data format type. $strFormatType = $this->oUtil->addAndApplyFilters($this, array("import_format_{$strPageSlug}_{$strTabSlug}", "import_format_{$strPageSlug}", "import_format_{$this->oProps->strClassName}_{$strPressedInputID}", "import_format_{$this->oProps->strClassName}_{$strPressedFieldID}", "import_format_{$this->oProps->strClassName}"), $oImport->getFormatType(), $strPressedFieldID, $strPressedInputID); // import_format_{$strPageSlug}_{$strTabSlug}, import_format_{$strPageSlug}, import_format_{$strClassName}_{pressed input id}, import_format_{$strClassName}_{pressed field id}, import_format_{$strClassName} // Format it. $oImport->formatImportData($vData, $strFormatType); // it is passed as reference. // If a custom option key is set, // Apply filters to the importing option key. $strImportOptionKey = $this->oUtil->addAndApplyFilters($this, array("import_option_key_{$strPageSlug}_{$strTabSlug}", "import_option_key_{$strPageSlug}", "import_option_key_{$this->oProps->strClassName}_{$strPressedInputID}", "import_option_key_{$this->oProps->strClassName}_{$strPressedFieldID}", "import_option_key_{$this->oProps->strClassName}"), $oImport->getSiblingValue('import_option_key'), $strPressedFieldID, $strPressedInputID); // import_option_key_{$strPageSlug}_{$strTabSlug}, import_option_key_{$strPageSlug}, import_option_key_{$strClassName}_{pressed input id}, import_option_key_{$strClassName}_{pressed field id}, import_option_key_{$strClassName} // Apply filters to the importing data. $vData = $this->oUtil->addAndApplyFilters($this, array("import_{$strPageSlug}_{$strTabSlug}", "import_{$strPageSlug}", "import_{$this->oProps->strClassName}_{$strPressedInputID}", "import_{$this->oProps->strClassName}_{$strPressedFieldID}", "import_{$this->oProps->strClassName}"), $vData, $arrStoredOptions, $strPressedFieldID, $strPressedInputID, $strFormatType, $strImportOptionKey, $fMerge); // Set the update notice $fEmpty = empty($vData); $this->setSettingNotice($fEmpty ? $this->oMsg->___('not_imported_data') : $this->oMsg->___('imported_data'), $fEmpty ? 'error' : 'updated', $this->oProps->strOptionKey, false); if ($strImportOptionKey != $this->oProps->strOptionKey) { update_option($strImportOptionKey, $vData); return $arrStoredOptions; // do not change the framework's options. } // The option data to be saved will be returned. return $fMerge ? $this->oUtil->unitArrays($vData, $arrStoredOptions) : $vData; }