protected function set($sOptionKey) { $vOption = get_option($sOptionKey, array()); // Avoid casting array because it causes a zero key when the subject is null. $vOption = empty($vOption) ? array() : $vOption; // Now $vOption is an array so merge with the default option to avoid undefined index warnings. $arrOptions = AmazonAutoLinks_Utilities::uniteArrays($vOption, self::$arrStructure_Options); return $arrOptions; }
public function validation_aal_add_category_unit_set_category_unit_options($aInput, $aOldInput) { // validation + _ + page slug + tab slug $_fVerified = true; $_aErrors = array(); // Check the limitation. if ($this->oOption->isUnitLimitReached()) { $this->setFieldErrors(array('error')); // must set an field error array which does not yield empty so that it won't be redirected. $this->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_Commons::PostTypeSlug))); return $aOldInput; } if (empty($aInput['aal_add_category_unit']['category']['category_associate_id'])) { $_aErrors['category']['category_associate_id'] = __('The associate ID cannot be empty.', 'amazon-auto-links'); $_fVerified = false; } // An invalid value is found. if (!$_fVerified) { // Set the error array for the input fields. $this->setFieldErrors($_aErrors); $this->setSettingNotice(__('There was an error in your input.', 'amazon-auto-links')); return $aOldInput; } // Drop the sections. $arrNewFields = array(); foreach ($aInput['aal_add_category_unit'] as $strSection => $arrFields) { $arrNewFields = $arrNewFields + $arrFields; } $arrSanitizedFields = array(); // Remove the category_ prefix in the keys. foreach ($arrNewFields as $strKey => $vValue) { $arrSanitizedFields[preg_replace('/^category_/', '', $strKey)] = $vValue; } $arrSanitizedFields['categories'] = array(); $arrSanitizedFields['categories_exclude'] = array(); $arrSanitizedFields = $this->oOption->sanitizeUnitOpitons($arrSanitizedFields); // If nothing is checked for the feed type, enable the bestseller item. if (!array_filter($arrSanitizedFields['feed_type'])) { $arrSanitizedFields['feed_type']['bestsellers'] = true; } $arrTempUnitOptions = (array) AmazonAutoLinks_WPUtilities::getTransient('AAL_CreateUnit_' . $arrSanitizedFields['transient_id']); AmazonAutoLinks_WPUtilities::setTransient('AAL_CreateUnit_' . $arrSanitizedFields['transient_id'], AmazonAutoLinks_Utilities::uniteArrays($arrSanitizedFields, $arrTempUnitOptions), 60 * 10 * 6 * 24); // AmazonAutoLinks_Debug::logArray( $arrSanitizedFields ); return $aInput; }
/** * Escapes the given string for the KSES filter with the criteria of allowing/disallowing tags and the protocol. * * @remark Attributes are not supported at this moment. * @param array $arrAllowedTags e.g. array( 'noscript', 'style', ) * @param array $arrDisallowedTags e.g. array( 'table', 'tbody', 'thoot', 'thead', 'th', 'tr' ) * @since 2.0.0 */ public static function escapeKSESFilter($strString, $arrAllowedTags = array(), $arrDisallowedTags = array(), $arrAllowedProtocols = array()) { foreach ($arrAllowedTags as $strTag) { $arrFormatAllowedTags[$strTag] = array(); } // activate the inline style attribute. $arrAllowedHTMLTags = AmazonAutoLinks_Utilities::uniteArrays($arrFormatAllowedTags, $GLOBALS['allowedposttags']); // the first parameter takes over the second. foreach ($arrDisallowedTags as $strTag) { if (isset($arrAllowedHTMLTags[$strTag])) { unset($arrAllowedHTMLTags[$strTag]); } } if (empty($arrAllowedProtocols)) { $arrAllowedProtocols = wp_allowed_protocols(); } $strString = addslashes($strString); // the original function call was doing this - could be redundant but haven't fully tested it $strString = stripslashes($strString); // wp_filter_post_kses() $strString = wp_kses_no_null($strString); // wp_kses() $strString = wp_kses_js_entities($strString); // wp_kses() $strString = wp_kses_normalize_entities($strString); // wp_kses() $strString = wp_kses_hook($strString, $arrAllowedHTMLTags, $arrAllowedProtocols); // WP changed the order of these funcs and added args to wp_kses_hook $strString = wp_kses_split($strString, $arrAllowedHTMLTags, $arrAllowedProtocols); $strString = addslashes($strString); // wp_filter_post_kses() $strString = stripslashes($strString); // the original function call was doing this - could be redundant but haven't fully tested it return $strString; }
public function validation_aal_add_search_unit_initial_search_settings($aInput, $aOldInput) { // validation_{page slug}_{tab slug} $fVerified = true; $arrErrors = array(); $arrSearchOptions = $aInput['aal_add_search_unit']['search']; // Check the limitation. if ($this->oOption->isUnitLimitReached()) { $this->setFieldErrors(array('error')); // must set an field error array which does not yield empty so that it won't be redirected. $this->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_Commons::PostTypeSlug))); return $aOldInput; } // If the Access Key fields are present, it means the user has not set them yet in the Settings page. // In this case, just check if they are valid and if so, save them in the settings' option array. Otherwise, return an error. if (isset($arrSearchOptions['search_access_key'], $arrSearchOptions['search_access_key_secret'])) { $strPublicKey = $arrSearchOptions['search_access_key']; if (strlen($strPublicKey) != 20) { $arrErrors['search']['search_access_key'] = __('The Access Key ID must consist of 20 characters.', 'amazon-auto-links') . ': ' . $strPublicKey . ' '; $fVerified = false; } $strPrivateKey = $arrSearchOptions['search_access_key_secret']; if (strlen($strPrivateKey) != 40) { $arrErrors['search']['search_access_key_secret'] = __('The Secret Access Key must consist of 40 characters.', 'amazon-auto-links') . ': ' . $strPrivateKey . ' '; $fVerified = false; } // An invalid value is found. if (!$fVerified) { // Set the error array for the input fields. $this->setFieldErrors($arrErrors); $this->setSettingNotice(__('There was an error in your input.', 'amazon-auto-links')); return $aOldInput; } // Test authentication - browse the Books node in amazon.com. $oAmazonAPI = new AmazonAutoLinks_ProductAdvertisingAPI('com', $strPublicKey, $strPrivateKey); if (!$oAmazonAPI->test()) { $arrErrors['search']['search_access_key'] = __('Sent Value', 'amazon-auto-links') . ': ' . $strPublicKey; $arrErrors['search']['search_access_key_secret'] = __('Sent Value', 'amazon-auto-links') . ': ' . $strPrivateKey; $this->setFieldErrors($arrErrors); $this->setSettingNotice(__('Failed authentication.', 'amazon-auto-links')); $aOldInput; } // It is authenticated, so set the keys in the Settings option array. // Since the validation_ callbacks internally merge with the framework's property option array, // modify the property array, NOT the option object that plugin creates. $this->oProps->arrOptions['aal_settings']['authentication_keys']['access_key'] = $strPublicKey; $this->oProps->arrOptions['aal_settings']['authentication_keys']['access_key_secret'] = $strPrivateKey; } if (empty($arrSearchOptions['search_associate_id'])) { $arrErrors['search']['search_associate_id'] = __('The associate ID cannot be empty.', 'amazon-auto-links'); $fVerified = false; } // An invalid value is found. if (!$fVerified) { // Set the error array for the input fields. $this->setFieldErrors($arrErrors); $this->setSettingNotice(__('There was an error in your input.', 'amazon-auto-links')); return $aOldInput; } // Drop the sections. $_aNewFields = array(); foreach ($aInput['aal_add_search_unit'] as $strSection => $arrFields) { $_aNewFields = $_aNewFields + $arrFields; } // Remove the search_ prefix in the keys. $_aSanitizedFields = array(); foreach ($_aNewFields as $strKey => $vValue) { $_aSanitizedFields[preg_replace('/^search_/', '', $strKey)] = $vValue; } // Set the unit type based on the chosen one. // Redirect to the appropriate page by the search type. switch ($_aSanitizedFields['Operation']) { case 'ItemSearch': $_aSanitizedFields['unit_type'] = 'search'; $sTabSlug = 'search_products'; break; case 'ItemLookup': $_aSanitizedFields['unit_type'] = 'item_lookup'; $sTabSlug = 'item_lookup'; break; case 'SimilarityLookup': $_aSanitizedFields['unit_type'] = 'similarity_lookup'; $sTabSlug = 'similarity_lookup'; break; } // Save the transient $arrTempUnitOptions = (array) AmazonAutoLinks_WPUtilities::getTransient('AAL_CreateUnit_' . $_aSanitizedFields['transient_id']); $aSavingUnitOptions = AmazonAutoLinks_Utilities::uniteArrays($_aSanitizedFields, $arrTempUnitOptions); AmazonAutoLinks_WPUtilities::setTransient('AAL_CreateUnit_' . $_aSanitizedFields['transient_id'], $aSavingUnitOptions, 60 * 10 * 6 * 24); // Go to the next page. die(wp_redirect(add_query_arg(array('tab' => $sTabSlug, 'transient_id' => $_aSanitizedFields['transient_id']) + $_GET, $_aSanitizedFields['bounce_url']))); }