/** * Validates submitted form data. */ public function validate($aInput, $aOriginal, $oFactory) { // Formats the options $_oUnitOption = new AmazonAutoLinks_UnitOption_url(null, $aInput); $_aFormatted = $_oUnitOption->get(); // Drop unsent keys. foreach ($_aFormatted as $_sKey => $_mValue) { if (!array_key_exists($_sKey, $aInput)) { unset($_aFormatted[$_sKey]); } } // Schedule pre-fetch for the unit if the options have been changed. if ($aInput !== $aOriginal) { AmazonAutoLinks_Event_Scheduler::prefetch(AmazonAutoLinks_PluginUtility::getCurrentPostID()); } return $_aFormatted + $aInput; }
/** * Validates submitted form data. */ public function validate($aInput, $aOriginal, $oFactory) { $_aErrors = array(); $_bVerified = true; // Formats the options $_oUnitOption = new AmazonAutoLinks_UnitOption_url(null, $aInput); $_aFormatted = $_oUnitOption->get(); // Check if a url iset. $aInput['urls'] = $this->oUtil->getAsArray($aInput['urls']); if (empty($aInput['urls'])) { $_aErrors['urls'] = __('Please set a url.', 'amazon-auto-links'); $_bVerified = false; } // An invalid value is found. if (!$_bVerified) { // Set the error array for the input fields. $oFactory->setFieldErrors($_aErrors); $oFactory->setSettingNotice(__('There was an error in your input.', 'amazon-auto-links')); return $aInput; } // Sanitize foreach ($aInput['urls'] as $_iIndex => $_sURL) { $aInput['urls'][$_iIndex] = trim($_sURL); } // Drop unsent keys. foreach ($_aFormatted as $_sKey => $_mValue) { if (!array_key_exists($_sKey, $aInput)) { unset($_aFormatted[$_sKey]); } } // Schedule pre-fetch for the unit if the options have been changed. if ($aInput !== $aOriginal) { AmazonAutoLinks_Event_Scheduler::prefetch(AmazonAutoLinks_PluginUtility::getCurrentPostID()); } return $_aFormatted + $aInput; }
/** * * @callback filter validation + _ + page slug */ public function validate($aInput, $aOldInput, $oFactory, $aSubmitInfo) { $_bVerified = true; $_aErrors = array(); $_oOption = AmazonAutoLinks_Option::getInstance(); $_oTemplateOption = AmazonAutoLinks_TemplateOption::getInstance(); $_oUtil = new AmazonAutoLinks_PluginUtility(); // Check the limitation. if ($_oOption->isUnitLimitReached()) { $oFactory->setSettingNotice(sprintf(__('Please upgrade to <A href="%1$s">Pro</a> to add more units! Make sure to empty the <a href="%2$s">trash box</a> to delete the units completely!', 'amazon-auto-links'), 'http://en.michaeluno.jp/amazon-auto-links-pro/', admin_url('edit.php?post_status=trash&post_type=' . AmazonAutoLinks_Registry::$aPostTypes['unit']))); return $aOldInput; } // Check if a url iset. $aInput['urls'] = $_oUtil->getAsArray($aInput['urls']); if (empty($aInput['urls'])) { $_aErrors['urls'] = __('Please set a url.', 'amazon-auto-links'); $_bVerified = false; } if (empty($aInput['associate_id'])) { $_aErrors['associate_id'] = __('The associate ID cannot be empty.', 'amazon-auto-links'); $_bVerified = false; } // An invalid value is found. if (!$_bVerified) { // Set the error array for the input fields. $oFactory->setFieldErrors($_aErrors); $oFactory->setSettingNotice(__('There was an error in your input.', 'amazon-auto-links')); return $aInput; } $_bDoAutoInsert = $aInput['auto_insert']; // Format the unit options to sanitize the data. $_oUnitOptions = new AmazonAutoLinks_UnitOption_url(null, $aInput); $aInput = $_oUnitOptions->get(); $aInput['template_id'] = $_oTemplateOption->getDefaultTemplateIDByUnitType('url'); // Create a unit post $_iNewPostID = $_oUtil->insertPost($aInput, AmazonAutoLinks_Registry::$aPostTypes['unit']); // Create an auto insert if ($_bDoAutoInsert) { $_oUtil->createAutoInsert($_iNewPostID); } // Clean the temporary form options data. $_oUtil->deleteTransient($GLOBALS['aal_transient_id']); // Schedule pre-fetching the unit feed in the background // so that by the time the user opens the unit page, the cache will be ready. AmazonAutoLinks_Event_Scheduler::prefetch($_iNewPostID); // Store the inputs for the next time. update_option(AmazonAutoLinks_Registry::$aOptionKeys['last_input'], $aInput, false); // Go to the post editing page and exit. This way the framework won't create a new form transient row. $_oUtil->goToPostDefinitionPage($_iNewPostID, AmazonAutoLinks_Registry::$aPostTypes['unit']); // This won't be reached. return $aInput; }