protected function _goToNextPage($iPostID)
 {
     $_oUtil = new AmazonAutoLinks_PluginUtility();
     // Clean up form data
     $_oUtil->deleteTransient($GLOBALS['aal_transient_id']);
     // Schedule pre-fetch
     AmazonAutoLinks_Event_Scheduler::prefetch($iPostID);
     // Go to the post definition page.
     $_oUtil->goToPostDefinitionPage($iPostID, AmazonAutoLinks_Registry::$aPostTypes['unit']);
 }
 private function _setProductData(array $aAPIResponseProductData, $sASIN, $sLocale, $iCacheDuration)
 {
     // Check if a customer review exists.
     $_bCustomerReviewExists = $this->_hasCustomerReview($aAPIResponseProductData);
     if ($_bCustomerReviewExists) {
         AmazonAutoLinks_Event_Scheduler::getCustomerReviews($this->getElement($aAPIResponseProductData, array('CustomerReviews', 'IFrameURL'), ''), $sASIN, $sLocale, $iCacheDuration);
     }
     $_aRow = $this->_formatRow($aAPIResponseProductData, $sASIN, $sLocale, $iCacheDuration, $_bCustomerReviewExists);
     $_oProductTable = new AmazonAutoLinks_DatabaseTable_product(AmazonAutoLinks_Registry::$aDatabaseTables['product']);
     $_iObjectID = $_oProductTable->setRowByASINLocale($sASIN . '_' . strtoupper($sLocale), $_aRow);
 }
 /**
  * Validates submitted form data.
  */
 public function validate($aInput, $aOriginal, $oFactory)
 {
     $_oOption = AmazonAutoLinks_Option::getInstance();
     $_oUtil = new AmazonAutoLinks_WPUtility();
     add_filter('safe_style_css', array($this, 'replyToAddAllowedInlineCSSProperties'));
     $_aAllowedHTMLTags = $_oUtil->convertStringToArray($_oOption->get('form_options', 'allowed_html_tags'), ',');
     $aInput['item_format'] = $_oUtil->escapeKSESFilter($aInput['item_format'], $_aAllowedHTMLTags);
     $aInput['image_format'] = $_oUtil->escapeKSESFilter($aInput['image_format'], $_aAllowedHTMLTags);
     $aInput['title_format'] = $_oUtil->escapeKSESFilter($aInput['title_format'], $_aAllowedHTMLTags);
     remove_filter('safe_style_css', array($this, 'replyToAddAllowedInlineCSSProperties'));
     // Schedule pre-fetch for the unit if the options have been changed.
     if ($aInput !== $aOriginal) {
         AmazonAutoLinks_Event_Scheduler::prefetch(AmazonAutoLinks_PluginUtility::getCurrentPostID());
     }
     return $aInput;
 }
 /**
  * Validates submitted form data.
  */
 public function validate($aInput, $aOriginal, $oFactory)
 {
     // Formats the options
     $_oUnitOption = new AmazonAutoLinks_UnitOption_search(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;
 }
 /**
  * 
  * @callback        action        aal_action_event_convert_template_options
  */
 public function doAction()
 {
     $_aParams = func_get_args() + array(0, array());
     $_iUnitID = $_aParams[0];
     $_aInput = $_aParams[1];
     if (!$_iUnitID) {
         return;
     }
     $_bUpdated = false;
     foreach ($_aInput as $_sMetaKey => $_mValue) {
         if (!is_string($_sMetaKey)) {
             continue;
         }
         update_post_meta($_iUnitID, $_sMetaKey, $_mValue);
         $_bUpdated = true;
     }
     if ($_bUpdated) {
         AmazonAutoLinks_Event_Scheduler::prefetch($_iUnitID);
     }
 }
 /**
  * 
  * @since       3
  */
 protected function _getValueFromRow($sColumnName, array $aRow, $mDefault = null, $aScheduleTask = array('locale' => '', 'asin' => '', 'associate_id' => ''))
 {
     $_mValue = $this->getElement($aRow, array($sColumnName), null);
     $_bIsSet = !is_null($_mValue);
     $_mValue = $_bIsSet ? maybe_unserialize($_mValue) : $mDefault;
     // Now schedule a background task to retrieve product info.
     $_bScheduleTask = !$this->isEmpty(array_filter($aScheduleTask));
     $_sModifiedTime = $this->getElement($aRow, array('modified_time'), '0000-00-00 00:00:00');
     $_iCacheDuration = (int) $this->oUnitOption->get('cache_duration');
     $_iExpirationTime = strtotime($_sModifiedTime) + $_iCacheDuration;
     $_bIsExpired = $this->isExpired($_iExpirationTime);
     if ($_bScheduleTask && $_bIsExpired) {
         AmazonAutoLinks_Event_Scheduler::getProductInfo($aScheduleTask['associate_id'], $aScheduleTask['asin'], $aScheduleTask['locale'], $_iCacheDuration);
     }
     // Now schedule a debug info to be inserted at the bottom of the product output.
     if (!$_bIsSet && $this->oOption->isDebug()) {
         $this->_setColumnItemDebugInfo($sColumnName, $aScheduleTask['asin'] . '_' . $aScheduleTask['locale'], array('column_name' => $sColumnName, 'value' => 'NULL', 'cache_duration' => $_iCacheDuration, 'expiry_time' => $_iExpirationTime, 'now' => time(), 'is_expired' => $_bIsExpired) + $aScheduleTask);
     }
     return $_mValue;
 }
 /**
  * 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;
     }
     // If specified and the customer ID is not 13 characters,
     $aInput['customer_id'] = trim($aInput['customer_id']);
     if ($aInput['customer_id'] && strlen($aInput['customer_id']) != 13) {
         $_aErrors['customer_id'] = __('The customer ID must consist of 13 characters.', 'amazon-auto-links') . ' ';
         $_bVerified = false;
     }
     if (empty($aInput['tags']) && empty($aInput['customer_id'])) {
         $_aErrors['tags'] = __('Either tags or customer ID has to be entered.', 'amazon-auto-links');
         $_sMessage = __('Either tags or customer ID has to be entered.', 'amazon-auto-links');
         $_aErrors['customer_id'] = isset($_aErrors['customer_id']) ? $_aErrors['customer_id'] . $_sMessage : $_sMessage;
         $_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;
     }
     // Sanitize the tag input
     $aInput['tags'] = trim($_oUtil->trimDelimitedElements($aInput['tags'], ','));
     $_bDoAutoInsert = $aInput['auto_insert'];
     // Format the unit options to sanitize the data.
     $_oUnitOptions = new AmazonAutoLinks_UnitOption_tag(null, $aInput);
     $aInput = $_oUnitOptions->get();
     $aInput['template_id'] = $_oTemplateOption->getDefaultTemplateIDByUnitType('tag');
     // 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;
 }
 /**
  * Called when the user submits the form of the category select page.
  * @return      array
  */
 private function _getCategorySelectFormInput(array $aPost, $aInput, $oFactory)
 {
     // If the 'Save' or 'Create' button is pressed, save the data to the post.
     // The key is set in `AmazonAutoLinks_Form_CategorySelect` when rendering the form.
     if (isset($aPost['save'])) {
         $_oUnit = new AmazonAutoLinks_UnitOption_category(isset($_GET['post']) ? $_GET['post'] : null, $aInput);
         $_iPostID = $this->_postUnitByCategory($_oUnit->get(), $aInput);
         if ($_iPostID) {
             $oFactory->setSettingNotice(__('A unit has been created.', 'amazon-auto=links'), 'updated');
         }
         $_oUtil = new AmazonAutoLinks_PluginUtility();
         // Clean temporary options.
         $_oUtil->deleteTransient($GLOBALS['aal_transient_id']);
         // Schedule pre-fetch.
         AmazonAutoLinks_Event_Scheduler::prefetch($_iPostID);
         // Will exit the script.
         $_oUtil->goToPostDefinitionPage($_iPostID, AmazonAutoLinks_Registry::$aPostTypes['unit']);
     }
     // Otherwise, update the form data.
     return $this->_getUpdatedUnitOptions($aPost, $aInput, $oFactory);
 }
 /**
  * 
  * @since       3
  * @return      string
  */
 public function formatUserRating($sASIN, $sLocale, $sAssociateID, array $aRow = array())
 {
     $_sEncodedHTML = $this->_getValueFromRow('rating_html', $aRow, null, array('asin' => $sASIN, 'locale' => $sLocale, 'associate_id' => $sAssociateID));
     // If the value is null, it means the value does not exist in the database table.
     if (null === $_sEncodedHTML) {
         AmazonAutoLinks_Event_Scheduler::getProductInfo($sAssociateID, $sASIN, $sLocale, (int) $this->oUnitOption->get('cache_duration'));
         return $this->oUnitOption->get('show_now_retrieving_message') ? '<p>' . __('Now retrieving the rating.', 'amazon-auto-links') . '</p>' : '';
     }
     if ('' === $_sEncodedHTML) {
         return '';
     }
     // Now modify the raw output.
     $_oScraper = new AmazonAutoLinks_ScraperDOM_UserRating($_sEncodedHTML, true);
     return "<div class='amazon-customer-rating-stars'>" . $_oScraper->get() . "</div>";
 }