protected function _importOptions($aStoredOptions, $sPageSlug, $sTabSlug) { $_oImport = new FetchTweets_AdminPageFramework_ImportOptions($_FILES['__import'], $_POST['__import']); $_aArguments = array('class_name' => $this->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->setSettingNotice($this->oMsg->get('import_error')); return $aStoredOptions; } $_aMIMEType = $this->_getImportMIMEType($_aArguments); $_sType = $_oImport->getType(); if (!in_array($_sType, $_aMIMEType)) { $this->setSettingNotice(sprintf($this->oMsg->get('uploaded_file_type_not_supported'), $_sType)); return $aStoredOptions; } $_mData = $_oImport->getImportData(); if (false === $_mData) { $this->setSettingNotice($this->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->oProp->sOptionKey) { update_option($_sImportOptionKey, $_mData); return $aStoredOptions; } return $_aArguments['should_merge'] ? $this->oUtil->uniteArrays($_mData, $aStoredOptions) : $_mData; }
private function importOptions($arrInput, $strPageSlug, $strTabSlug) { $oImport = new FetchTweets_AdminPageFramework_ImportOptions($_FILES['__import'], $_POST['__import']); // Check if there is an upload error. if ($oImport->getError() > 0) { add_settings_error($this->oProps->strOptionKey, $strPageSlug, $this->oMsg->___('import_error'), 'error'); return $arrInput; // do not change the framework's options. } // Check the uploaded file type. if (!in_array($oImport->getType(), array('text/plain', 'application/octet-stream'))) { // .json file is dealt as binary file. add_settings_error($this->oProps->strOptionKey, $strPageSlug, $this->oMsg->___('uploaded_file_type_not_supported'), 'error'); return $arrInput; // do not change the framework's options. } // Retrieve the importing data. $vData = $oImport->getImportData(); if ($vData === false) { add_settings_error($this->oProps->strOptionKey, $strPageSlug, $this->oMsg->___('could_not_load_importing_data'), 'error'); return $arrInput; // do not change the framework's options. } // Apply filters to the data format type. $strFormatType = $this->oUtil->addAndApplyFilters($this, $this->oUtil->getFilterArrayByPrefix('import_format_', $this->oProps->strClassName, $strPageSlug, $strTabSlug), $oImport->getFormatType(), $oImport->getFieldID()); // import_format_{$strPageSlug}_{$strTabSlug}, import_format_{$strPageSlug}, import_format_{$strClassName} // Format it. $oImport->formatImportData($vData, $strFormatType); // it is passed as reference. // Apply filters to the importing data. $vData = $this->oUtil->addAndApplyFilters($this, $this->oUtil->getFilterArrayByPrefix('import_', $this->oProps->strClassName, $strPageSlug, $strTabSlug), $vData, $oImport->getFieldID()); // Set the admin notice. add_settings_error($this->oProps->strOptionKey, $strPageSlug, $this->oMsg->___('imported_data'), 'updated'); // If a custom option key is set, // Apply filters to the importing option key. $strImportOptionKey = $this->oUtil->addAndApplyFilters($this, $this->oUtil->getFilterArrayByPrefix('import_option_key_', $this->oProps->strClassName, $strPageSlug, $strTabSlug), $oImport->getImportOptionKey(), $oImport->getFieldID()); // import_option_key_{$strPageSlug}_{$strTabSlug}, import_option_key_{$strPageSlug}, import_option_key_{$strClassName} if ($strImportOptionKey != $this->oProps->strOptionKey) { update_option($strImportOptionKey, $vData); return $arrInput; // do not change the framework's options. } return $vData; }