private function _importOptions($aStoredOptions, $sPageSlug, $sTabSlug) { $_oImport = new 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; }
protected function _importOptions($aStoredOptions, $sPageSlug, $sTabSlug) { $oImport = new AdminPageFramework_ImportOptions($_FILES['__import'], $_POST['__import']); $sSectionID = $oImport->getSiblingValue('section_id'); $sPressedFieldID = $oImport->getSiblingValue('field_id'); $sPressedInputID = $oImport->getSiblingValue('input_id'); $bMerge = $oImport->getSiblingValue('is_merge'); if ($oImport->getError() > 0) { $this->setSettingNotice($this->oMsg->get('import_error')); return $aStoredOptions; } $aMIMEType = $this->oUtil->addAndApplyFilters($this, array("import_mime_types_{$this->oProp->sClassName}_{$sPressedInputID}", $sSectionID ? "import_mime_types_{$this->oProp->sClassName}_{$sSectionID}_{$sPressedFieldID}" : "import_mime_types_{$this->oProp->sClassName}_{$sPressedFieldID}", $sSectionID ? "import_mime_types_{$this->oProp->sClassName}_{$sSectionID}" : null, $sTabSlug ? "import_mime_types_{$sPageSlug}_{$sTabSlug}" : null, "import_mime_types_{$sPageSlug}", "import_mime_types_{$this->oProp->sClassName}"), array('text/plain', 'application/octet-stream'), $sPressedFieldID, $sPressedInputID, $this); $_sType = $oImport->getType(); if (!in_array($oImport->getType(), $aMIMEType)) { $this->setSettingNotice(sprintf($this->oMsg->get('uploaded_file_type_not_supported'), $_sType)); return $aStoredOptions; } $vData = $oImport->getImportData(); if ($vData === false) { $this->setSettingNotice($this->oMsg->get('could_not_load_importing_data')); return $aStoredOptions; } $sFormatType = $this->oUtil->addAndApplyFilters($this, array("import_format_{$this->oProp->sClassName}_{$sPressedInputID}", $sSectionID ? "import_format_{$this->oProp->sClassName}_{$sSectionID}_{$sPressedFieldID}" : "import_format_{$this->oProp->sClassName}_{$sPressedFieldID}", $sSectionID ? "import_format_{$this->oProp->sClassName}_{$sSectionID}" : null, $sTabSlug ? "import_format_{$sPageSlug}_{$sTabSlug}" : null, "import_format_{$sPageSlug}", "import_format_{$this->oProp->sClassName}"), $oImport->getFormatType(), $sPressedFieldID, $sPressedInputID, $this); $oImport->formatImportData($vData, $sFormatType); $sImportOptionKey = $this->oUtil->addAndApplyFilters($this, array("import_option_key_{$this->oProp->sClassName}_{$sPressedInputID}", $sSectionID ? "import_option_key_{$this->oProp->sClassName}_{$sSectionID}_{$sPressedFieldID}" : "import_option_key_{$this->oProp->sClassName}_{$sPressedFieldID}", $sSectionID ? "import_option_key_{$this->oProp->sClassName}_{$sSectionID}" : null, $sTabSlug ? "import_option_key_{$sPageSlug}_{$sTabSlug}" : null, "import_option_key_{$sPageSlug}", "import_option_key_{$this->oProp->sClassName}"), $oImport->getSiblingValue('option_key'), $sPressedFieldID, $sPressedInputID, $this); $vData = $this->oUtil->addAndApplyFilters($this, array("import_{$this->oProp->sClassName}_{$sPressedInputID}", $sSectionID ? "import_{$this->oProp->sClassName}_{$sSectionID}_{$sPressedFieldID}" : "import_{$this->oProp->sClassName}_{$sPressedFieldID}", $sSectionID ? "import_{$this->oProp->sClassName}_{$sSectionID}" : null, $sTabSlug ? "import_{$sPageSlug}_{$sTabSlug}" : null, "import_{$sPageSlug}", "import_{$this->oProp->sClassName}"), $vData, $aStoredOptions, $sPressedFieldID, $sPressedInputID, $sFormatType, $sImportOptionKey, $bMerge . $this); $bEmpty = empty($vData); $this->setSettingNotice($bEmpty ? $this->oMsg->get('not_imported_data') : $this->oMsg->get('imported_data'), $bEmpty ? 'error' : 'updated', $this->oProp->sOptionKey, false); if ($sImportOptionKey != $this->oProp->sOptionKey) { update_option($sImportOptionKey, $vData); return $aStoredOptions; } return $bMerge ? $this->oUtil->unitArrays($vData, $aStoredOptions) : $vData; }
/** * Processes importing data. * * @since 2.0.0 * @since 2.1.5 Added additional filters with field id and input id. * @since 3.3.1 Moved from `AdminPageFramework_Setting_Port`. */ protected function _importOptions($aStoredOptions, $sPageSlug, $sTabSlug) { $oImport = new AdminPageFramework_ImportOptions($_FILES['__import'], $_POST['__import']); $sSectionID = $oImport->getSiblingValue('section_id'); $sPressedFieldID = $oImport->getSiblingValue('field_id'); $sPressedInputID = $oImport->getSiblingValue('input_id'); $bMerge = $oImport->getSiblingValue('is_merge'); // Check if there is an upload error. if ($oImport->getError() > 0) { $this->setSettingNotice($this->oMsg->get('import_error')); return $aStoredOptions; // do not change the framework's options. } // Apply filters to the uploaded file's MIME type. $aMIMEType = $this->oUtil->addAndApplyFilters($this, array("import_mime_types_{$this->oProp->sClassName}_{$sPressedInputID}", $sSectionID ? "import_mime_types_{$this->oProp->sClassName}_{$sSectionID}_{$sPressedFieldID}" : "import_mime_types_{$this->oProp->sClassName}_{$sPressedFieldID}", $sSectionID ? "import_mime_types_{$this->oProp->sClassName}_{$sSectionID}" : null, $sTabSlug ? "import_mime_types_{$sPageSlug}_{$sTabSlug}" : null, "import_mime_types_{$sPageSlug}", "import_mime_types_{$this->oProp->sClassName}"), array('text/plain', 'application/octet-stream'), $sPressedFieldID, $sPressedInputID, $this); // Check the uploaded file MIME type. $_sType = $oImport->getType(); if (!in_array($oImport->getType(), $aMIMEType)) { $this->setSettingNotice(sprintf($this->oMsg->get('uploaded_file_type_not_supported'), $_sType)); return $aStoredOptions; // do not change the framework's options. } // Retrieve the importing data. $vData = $oImport->getImportData(); if ($vData === false) { $this->setSettingNotice($this->oMsg->get('could_not_load_importing_data')); return $aStoredOptions; // do not change the framework's options. } // Apply filters to the data format type. $sFormatType = $this->oUtil->addAndApplyFilters($this, array("import_format_{$this->oProp->sClassName}_{$sPressedInputID}", $sSectionID ? "import_format_{$this->oProp->sClassName}_{$sSectionID}_{$sPressedFieldID}" : "import_format_{$this->oProp->sClassName}_{$sPressedFieldID}", $sSectionID ? "import_format_{$this->oProp->sClassName}_{$sSectionID}" : null, $sTabSlug ? "import_format_{$sPageSlug}_{$sTabSlug}" : null, "import_format_{$sPageSlug}", "import_format_{$this->oProp->sClassName}"), $oImport->getFormatType(), $sPressedFieldID, $sPressedInputID, $this); // Format it. $oImport->formatImportData($vData, $sFormatType); // it is passed as reference. // Apply filters to the importing option key. $sImportOptionKey = $this->oUtil->addAndApplyFilters($this, array("import_option_key_{$this->oProp->sClassName}_{$sPressedInputID}", $sSectionID ? "import_option_key_{$this->oProp->sClassName}_{$sSectionID}_{$sPressedFieldID}" : "import_option_key_{$this->oProp->sClassName}_{$sPressedFieldID}", $sSectionID ? "import_option_key_{$this->oProp->sClassName}_{$sSectionID}" : null, $sTabSlug ? "import_option_key_{$sPageSlug}_{$sTabSlug}" : null, "import_option_key_{$sPageSlug}", "import_option_key_{$this->oProp->sClassName}"), $oImport->getSiblingValue('option_key'), $sPressedFieldID, $sPressedInputID, $this); // Apply filters to the importing data. $vData = $this->oUtil->addAndApplyFilters($this, array("import_{$this->oProp->sClassName}_{$sPressedInputID}", $sSectionID ? "import_{$this->oProp->sClassName}_{$sSectionID}_{$sPressedFieldID}" : "import_{$this->oProp->sClassName}_{$sPressedFieldID}", $sSectionID ? "import_{$this->oProp->sClassName}_{$sSectionID}" : null, $sTabSlug ? "import_{$sPageSlug}_{$sTabSlug}" : null, "import_{$sPageSlug}", "import_{$this->oProp->sClassName}"), $vData, $aStoredOptions, $sPressedFieldID, $sPressedInputID, $sFormatType, $sImportOptionKey, $bMerge . $this); // Set the update notice $bEmpty = empty($vData); $this->setSettingNotice($bEmpty ? $this->oMsg->get('not_imported_data') : $this->oMsg->get('imported_data'), $bEmpty ? 'error' : 'updated', $this->oProp->sOptionKey, false); if ($sImportOptionKey != $this->oProp->sOptionKey) { update_option($sImportOptionKey, $vData); return $aStoredOptions; // do not change the framework's options. } // The option data to be saved will be returned. return $bMerge ? $this->oUtil->unitArrays($vData, $aStoredOptions) : $vData; }