/** * @param array The argument array/ * @param null This is only to be compatible with the parent class method. */ protected function getRSSURLsFromArguments($arrArgs, $_deprecated = null) { $arrRSSURLs = array(); $strScheme = $this->fIsSSL ? 'https' : 'http'; $arrTags = AmazonAutoLinks_Utilities::convertStringToArray($arrArgs['tags'], ","); // If the customer ID is provided, compose the URL for it first. if ($arrArgs['customer_id']) { if (!$arrArgs['tags'] || empty($arrTags)) { $arrRSSURLs[] = "{$strScheme}://www.amazon.com/rss/people/{$arrArgs['customer_id']}/products?tag={$arrArgs['associate_id']}"; return $arrRSSURLs; } foreach ($arrTags as $strTag) { $strTag = strtolower($strTag); $arrRSSURLs[] = "{$strScheme}://www.amazon.com/rss/people/{$arrArgs['customer_id']}/products/{$strTag}?tag={$arrArgs['associate_id']}&threshold={$arrArgs['threshold']}"; } return $arrRSSURLs; } // So there is a tag set by the user. foreach ($arrTags as $strTag) { $strTag = strtolower($strTag); foreach ($arrArgs['feed_type'] as $strType => $fEnable) { if (!$fEnable) { continue; } // $strType : new, popular, or recent $arrRSSURLs[] = "{$strScheme}://www.amazon.com/rss/tag/{$strTag}/{$strType}?tag={$arrArgs['associate_id']}&threshold={$arrArgs['threshold']}"; } } // AmazonAutoLinks_Debug::logArray( $arrRSSURLs ); return $arrRSSURLs; }
public function getOutput() { // Retrieve IDs $_aIDs = array(); // The id parameter - the id parameter can accept comma delimited ids. if (isset($this->aArgs['id'])) { if (is_string($this->aArgs['id']) || is_integer($this->aArgs['id'])) { $_aIDs = array_merge(AmazonAutoLinks_Utilities::convertStringToArray($this->aArgs['id'], ","), $_aIDs); } else { if (is_array($this->aArgs['id'])) { $_aIDs = $this->aArgs['id']; // The Auto-insert feature passes the id as array. } } } // The label parameter. if (isset($this->aArgs['label'])) { $this->aArgs['_labels'] = AmazonAutoLinks_Utilities::convertStringToArray($this->aArgs['label'], ","); $_aIDs = array_merge($this->_getPostIDsByLabel($this->aArgs['_labels'], isset($arrArgs['operator']) ? $arrArgs['operator'] : null), $_aIDs); } $_aOutputs = array(); $_aIDs = array_unique($_aIDs); foreach ($_aIDs as $_iID) { $_aOutputs[] = $this->_getOutputByID($_iID); } return implode('', $_aOutputs); }
/** * Sanitizes the unit options of the item_lookup unit type. * * @since 2.0.2 */ protected function sanitizeUnitOptions_ItemLookUp(array &$aUnitOptions) { // if the ISDN is spceified, the search index must be set to Books. if (isset($aUnitOptions['IdType'], $aUnitOptions['SearchIndex']) && $aUnitOptions['IdType'] == 'ISBN') { $aUnitOptions['SearchIndex'] = 'Books'; } $aUnitOptions['ItemId'] = trim(AmazonAutoLinks_Utilities::trimDelimitedElements($aUnitOptions['ItemId'], ',')); }
public function validation_AmazonAutoLinks_MetaBox_Template($arrInput, $arrOldInput) { // validation_ + extended class name // Apply allowed HTML tags for the KSES filter. add_filter('safe_style_css', array($this, 'allowInlineStyleMaxWidth')); $arrAllowedHTMLTags = AmazonAutoLinks_Utilities::convertStringToArray($GLOBALS['oAmazonAutoLinks_Option']->arrOptions['aal_settings']['form_options']['allowed_html_tags'], ','); $arrInput['item_format'] = AmazonAutoLinks_WPUtilities::escapeKSESFilter($arrInput['item_format'], $arrAllowedHTMLTags); $arrInput['image_format'] = AmazonAutoLinks_WPUtilities::escapeKSESFilter($arrInput['image_format'], $arrAllowedHTMLTags); $arrInput['title_format'] = AmazonAutoLinks_WPUtilities::escapeKSESFilter($arrInput['title_format'], $arrAllowedHTMLTags); remove_filter('safe_style_css', array($this, 'allowInlineStyleMaxWidth')); return $arrInput; }
/** * The define Auto Insert page. */ public function validation_aal_define_auto_insert($arrInput, $arrOldInput) { // Drop the sections. $arrNewFields = array(); foreach ($arrInput['aal_define_auto_insert'] as $strSection => $arrFields) { $arrNewFields = $arrNewFields + $arrFields; } // Remove the search_ prefix in the keys. $arrSanitizedFields = array(); foreach ($arrNewFields as $strKey => $vValue) { $arrSanitizedFields[preg_replace('/^autoinsert_/', '', $strKey)] = $vValue; } $fVerified = true; $arrErrors = array(); // Check necessary settings. if (!array_filter($arrSanitizedFields['built_in_areas'] + $arrSanitizedFields['static_areas']) && !$arrSanitizedFields['filter_hooks'] && !$arrSanitizedFields['action_hooks']) { $arrErrors['autoinsert_area']['autoinsert_built_in_areas'] = __('At least one area must be set.', 'amazon-auto-links'); $arrErrors['autoinsert_static_insertion']['autoinsert_static_areas'] = __('At least one area must be set.', 'amazon-auto-links'); $arrErrors['autoinsert_area']['autoinsert_filter_hooks'] = __('At least one area must be set.', 'amazon-auto-links'); $arrErrors['autoinsert_area']['autoinsert_action_hooks'] = __('At least one area must be set.', 'amazon-auto-links'); $fVerified = false; } if (!isset($arrSanitizedFields['unit_ids'])) { // if no item is selected, the select input with the multiple attribute does not send the key. $arrErrors['autoinsert_area']['autoinsert_unit_ids'] = __('A unit must be selected.', '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 $arrOldInput; } $arrSanitizedFields['filter_hooks'] = AmazonAutoLinks_Utilities::trimDelimitedElements($arrSanitizedFields['filter_hooks'], ','); $arrSanitizedFields['action_hooks'] = AmazonAutoLinks_Utilities::trimDelimitedElements($arrSanitizedFields['action_hooks'], ','); $arrSanitizedFields['enable_post_ids'] = AmazonAutoLinks_Utilities::trimDelimitedElements($arrSanitizedFields['enable_post_ids'], ','); $arrSanitizedFields['diable_post_ids'] = AmazonAutoLinks_Utilities::trimDelimitedElements($arrSanitizedFields['diable_post_ids'], ','); // AmazonAutoLinks_Debug::logArray( $arrSanitizedFields ); // Edit - Update the post. $fIsEdit = isset($_POST['mode'], $_POST['post']) && $_POST['post'] && $_POST['mode'] == 'edit'; if ($fIsEdit) { AmazonAutoLinks_Option::updatePostMeta($_POST['post'], $arrSanitizedFields); } else { // New - Create a post. $intNewPostID = AmazonAutoLinks_Option::insertPost($arrSanitizedFields, AmazonAutoLinks_Commons::PostTypeSlugAutoInsert); } // e.g. http://.../wp-admin/edit.php?post_type=aal_auto_insert die(wp_redirect($fIsEdit ? admin_url('edit.php?post_type=' . AmazonAutoLinks_Commons::PostTypeSlug . '&page=aal_define_auto_insert&mode=edit&post=' . $_POST['post']) : admin_url('edit.php?post_type=' . AmazonAutoLinks_Commons::PostTypeSlugAutoInsert))); }
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; }
/** * Returns the substring of the given subject string. * @since 2.1.2 */ public static function getSubstring($sString, $iStart, $iLength = null, $sEncoding = null) { self::$_bFunctionExists_mb_substr = isset(self::$_bFunctionExists_mb_substr) ? self::$_bFunctionExists_mb_substr : function_exists('mb_substr') && function_exists('mb_internal_encoding'); if (!self::$_bFunctionExists_mb_substr) { return substr($sString, $iStart, $iLength); } $sEncoding = isset($sEncoding) ? $sEncoding : mb_internal_encoding(); return mb_substr($sString, $iStart, $iLength, $sEncoding); }
/** * A wrapper method for the set_transient() function. * */ public function setTransient($strTransientKey, $vData, $intTime = null) { $sLockTransient = AmazonAutoLinks_Commons::TransientPrefix . '_' . md5("Lock_{$strTransientKey}"); // Check if the transient is locked if (AmazonAutoLinks_WPUtilities::getTransient($sLockTransient) !== false) { return; // it means the cache is being modified right now in a different process. } // Set a lock flag transient that indicates the transient is being renewed. AmazonAutoLinks_WPUtilities::setTransient($sLockTransient, time(), AmazonAutoLinks_Utilities::getAllowedMaxExecutionTime(30, 30)); // AmazonAutoLinks_Debug::logArray( 'set transient: ' . $strTransientKey ); // Save the cache AmazonAutoLinks_WPUtilities::setTransient($strTransientKey, array('mod' => $intTime ? $intTime : time(), 'data' => $this->oEncrypt->encode($vData))); // no expiration by itself // AmazonAutoLinks_Debug::logArray( 'the transient is saved: ' . $strTransientKey ); // AmazonAutoLinks_WPUtilities::deleteTransient( $sLockTransient ); }
/** * Performs an API request from the given request API parameters and returns the result as associative array. * * @param string $strType The return type, either 'array', 'json' */ public function request(array $arrParams, $strLocale = '', $intCacheDuration = 3600, $strType = 'array', $intTimeout = 20, $intRedirection = 5, $strHeaders = '', $strUserAgent = '') { // Arguments $arrHTTPArgs = array('timeout' => $intTimeout, 'redirection' => $intRedirection, 'sslverify' => $this->strScheme == 'https' ? false : true, 'headers' => !empty($strHeaders) ? $strHeaders : null, 'user-agent' => $strUserAgent ? $strUserAgent : $this->strUserAgent); $arrHTTPArgs = array_filter($arrHTTPArgs); // drop non value elements. // Request $vResponse = $this->requestWithCache($this->getSignedRequestURI($arrParams, $strLocale), $arrHTTPArgs, $arrParams, $intCacheDuration, $strLocale ? $strLocale : $this->strLocale); // If an error occurs, if (!is_string($vResponse)) { return $vResponse; } $_sXMLResponse = $vResponse; // It returns a string if it's not a valid XML content. $_osXML = AmazonAutoLinks_Utilities::getXMLObject($_sXMLResponse); if (is_string($_osXML)) { return array('Error' => array('Message' => $_osXML, 'Code' => 'Invalid XML')); // compose an error array. } // Return the result with the specified type. if ($strType == 'xml') { return $_sXMLResponse; } if ($strType == 'array') { return AmazonAutoLinks_Utilities::convertXMLtoArray($_osXML); } if ($strType == 'json') { return AmazonAutoLinks_Utilities::convertXMLtoJSON($_osXML); } }
public function validation_aal_add_tag_unit($arrInput, $arrOldInput) { // validation + _ + page slug + tab slug $fVerified = true; $arrErrors = array(); // Check the limitation. if ($this->oOption->isUnitLimitReached()) { $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 $arrOldInput; } // Customer ID must be 13 characters if ($arrInput['aal_add_tag_unit']['tag']['tag_customer_id'] && strlen($arrInput['aal_add_tag_unit']['tag']['tag_customer_id']) != 13) { $arrErrors['tag']['tag_customer_id'] = __('The customer ID must consist of 13 characters.', 'amazon-auto-links') . ' '; $arrInput['aal_add_tag_unit']['tag']['tag_customer_id'] = ''; $fVerified = false; } if (empty($arrInput['aal_add_tag_unit']['tag']['tag_tags']) && empty($arrInput['aal_add_tag_unit']['tag']['tag_customer_id'])) { $arrErrors['tag']['tag_tags'] = __('Either tags or customer ID has to be entered.', 'amazon-auto-links'); $strMessage = __('Either tags or customer ID has to be entered.', 'amazon-auto-links'); $arrErrors['tag']['tag_customer_id'] = isset($arrErrors['tag']['tag_customer_id']) ? $arrErrors['tag']['tag_customer_id'] . $strMessage : $strMessage; $fVerified = false; } if (empty($arrInput['aal_add_tag_unit']['tag']['tag_associate_id'])) { $arrErrors['tag']['tag_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 $arrOldInput; } // Drop the sections. $arrNewFields = array(); foreach ($arrInput['aal_add_tag_unit'] as $strSection => $arrFields) { $arrNewFields = $arrNewFields + $arrFields; } $arrSanitizedFields = array(); // Remove the tag_ prefix in the keys. foreach ($arrNewFields as $strKey => $vValue) { $arrSanitizedFields[preg_replace('/^tag_/', '', $strKey)] = $vValue; } // Sanitize the tag input $arrSanitizedFields['tags'] = trim(AmazonAutoLinks_Utilities::trimDelimitedElements($arrSanitizedFields['tags'], ',')); $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']['new'] = true; } // AmazonAutoLinks_Debug::logArray( '--Before Escaping KSES Filter--' ); // AmazonAutoLinks_Debug::logArray( $arrSanitizedFields['item_format'] ); // AmazonAutoLinks_Debug::logArray( $arrSanitizedFields['image_format'] ); // AmazonAutoLinks_Debug::logArray( $arrSanitizedFields['title_format'] ); // Apply allowed HTML tags for the KSES filter. add_filter('safe_style_css', array($this, 'allowInlineStyleMaxWidth')); $arrAllowedHTMLTags = AmazonAutoLinks_Utilities::convertStringToArray($this->oOption->arrOptions['aal_settings']['form_options']['allowed_html_tags'], ','); $arrSanitizedFields['item_format'] = AmazonAutoLinks_WPUtilities::escapeKSESFilter($arrSanitizedFields['item_format'], $arrAllowedHTMLTags); $arrSanitizedFields['image_format'] = AmazonAutoLinks_WPUtilities::escapeKSESFilter($arrSanitizedFields['image_format'], $arrAllowedHTMLTags); $arrSanitizedFields['title_format'] = AmazonAutoLinks_WPUtilities::escapeKSESFilter($arrSanitizedFields['title_format'], $arrAllowedHTMLTags); remove_filter('safe_style_css', array($this, 'allowInlineStyleMaxWidth')); // AmazonAutoLinks_Debug::logArray( '--After Escaping KSES Filter--' ); // AmazonAutoLinks_Debug::logArray( $arrAllowedHTMLTags ); // AmazonAutoLinks_Debug::logArray( $arrSanitizedFields['item_format'] ); // AmazonAutoLinks_Debug::logArray( $arrSanitizedFields['image_format'] ); // AmazonAutoLinks_Debug::logArray( $arrSanitizedFields['title_format'] ); // Create a post. $fDoAutoInsert = $arrSanitizedFields['auto_insert']; unset($arrSanitizedFields['auto_insert']); $intNewPostID = AmazonAutoLinks_Option::insertPost($arrSanitizedFields); // Create an auto insert if ($fDoAutoInsert) { $arrAutoInsertOptions = array('unit_ids' => array($intNewPostID)) + AmazonAutoLinks_Form_AutoInsert::$arrStructure_AutoInsertOptions; AmazonAutoLinks_Option::insertPost($arrAutoInsertOptions, AmazonAutoLinks_Commons::PostTypeSlugAutoInsert); } die(wp_redirect(add_query_arg(array('post_type' => AmazonAutoLinks_Commons::PostTypeSlug, 'action' => 'edit', 'post' => $intNewPostID), admin_url('post.php')))); }
/** * Generates a template array by the given template directory path. * * @remark The directory must have necessary template files including style.css and tmplate.php * @access public This is access by the pro classes. */ public function getTemplateArray($strDirPath) { // Check mandatory files. if (!$this->doFilesExist(array($strDirPath . DIRECTORY_SEPARATOR . 'style.css', $strDirPath . DIRECTORY_SEPARATOR . 'template.php'))) { return; } return array('strCSSPath' => $strDirPath . DIRECTORY_SEPARATOR . 'style.css', 'strTemplatePath' => $strDirPath . DIRECTORY_SEPARATOR . 'template.php', 'strDirPath' => $strDirPath, 'strFunctionsPath' => file_exists($strDirPath . DIRECTORY_SEPARATOR . 'functions.php') ? $strDirPath . DIRECTORY_SEPARATOR . 'functions.php' : null, 'strSettingsPath' => file_exists($strDirPath . DIRECTORY_SEPARATOR . 'settings.php') ? $strDirPath . DIRECTORY_SEPARATOR . 'settings.php' : null, 'strThumbnailPath' => $this->getScreenshotPath($strDirPath), 'strID' => md5(AmazonAutoLinks_Utilities::getRelativePath(ABSPATH, $strDirPath))) + $this->getTemplateData($strDirPath . DIRECTORY_SEPARATOR . 'style.css') + self::$arrStructure_Template; }
/** * Creates an array storing the auto-insert definition(post) ids with the keys of hooks. * * @param string $strOptionKey either 'filter_hooks' or 'action_hooks' which are defined in the AmazonAutoLinks_Form_AutoInsert class. */ protected function getHooks($arrAutoInsertOptions, $strOptionKey, $arrHooks = array()) { foreach ($arrAutoInsertOptions as $intAutoInsertID => $arrOptions) { $arrParsedHooks = AmazonAutoLinks_Utilities::convertStringToArray($arrOptions[$strOptionKey], ','); $arrParsedHooks = array_filter($arrParsedHooks); // drop non-values. foreach ($arrParsedHooks as $strHook) { $arrHooks[$strHook] = isset($arrHooks[$strHook]) && is_array($arrHooks[$strHook]) ? array_merge($arrHooks[$strHook], array($intAutoInsertID)) : array($intAutoInsertID); } } foreach ($arrHooks as &$arrIDs) { $arrIDs = array_unique(array_filter($arrIDs)); if (empty($arrIDs)) { unset($arrIDs); } } return $arrHooks; }
/** * * [aal_settings] => Array ( [product_filters] => Array ( [white_list] => Array ( [asin] => [title] => [description] => ) [black_list] => Array ( [asin] => [title] => [description] => ) ) [support] => Array ( [rate] => 10 [review] => 0 ) [query] => Array ( [cloak] => productlink [submit_general] => Save Changes ) ) */ public function validation_aal_settings_general($arrInput, $arrOldInput) { // Sanitize text inputs foreach ($arrInput['aal_settings']['product_filters']['black_list'] as &$str1) { $str1 = trim(AmazonAutoLinks_Utilities::trimDelimitedElements($str1, ',')); } foreach ($arrInput['aal_settings']['product_filters']['white_list'] as &$str2) { $str2 = trim(AmazonAutoLinks_Utilities::trimDelimitedElements($str2, ',')); } // Sanitize the query key. $arrInput['aal_settings']['query']['cloak'] = AmazonAutoLinks_Utilities::sanitizeCharsForURLQueryKey($arrInput['aal_settings']['query']['cloak']); // Sanitize the custom preview slug. $_sCustomPreviewPostTypeSlug = AmazonAutoLinks_Utilities::getTrancatedString($arrInput['aal_settings']['unit_preview']['preview_post_type_slug'], 20, ''); $_sCustomPreviewPostTypeSlug = AmazonAutoLinks_Utilities::sanitizeCharsForURLQueryKey($_sCustomPreviewPostTypeSlug); $arrInput['aal_settings']['unit_preview']['preview_post_type_slug'] = $_sCustomPreviewPostTypeSlug; return $arrInput; }
/** * Strips HTML tags and sanitizes the product title. * */ protected function sanitizeTitle($strTitle) { $strTitle = strip_tags($strTitle); // removes the heading numbering. e.g. #3: Product Name -> Product Name // Do not use "substr($strTitle, strpos($strTitle, ' '))" since some title contains double-quotes and they mess up html formats $strTitle = trim(preg_replace('/#\\d+?:\\s+?/i', '', $strTitle)); // Title character length if ($this->arrArgs['title_length'] == 0) { return ''; } if ($this->arrArgs['title_length'] > 0 && AmazonAutoLinks_Utilities::getStringLength($strTitle) > $this->arrArgs['title_length']) { $strTitle = AmazonAutoLinks_Utilities::getSubstring($strTitle, 0, $this->arrArgs['title_length']) . '...'; } // return $strTitle; return esc_attr($strTitle); }
/** * Calculates the URL from the given path. * * * * @static * @access public * @return string The source url * @since 2.0.1 * @since 2.0.3.1 Prevented "/./" to be inserted in the url. */ public static function getSRCFromPath($strFilePath) { $oWPStyles = new WP_Styles(); // It doesn't matter whether the file is a style or not. Just use the built-in WordPress class to calculate the SRC URL. $strRelativePath = AmazonAutoLinks_Utilities::getRelativePath(ABSPATH, $strFilePath); $strRelativePath = preg_replace("/^\\.[\\/\\\\]/", '', $strRelativePath, 1); // removes the heading ./ or .\ $sHref = trailingslashit($oWPStyles->base_url) . $strRelativePath; return esc_url($sHref); }
public function cell_aal_auto_insert_area($strCell, $intPostID) { $arrList = array(); $arrSelectedAreas = (array) get_post_meta($intPostID, 'built_in_areas', true) + (array) get_post_meta($intPostID, 'static_areas', true); $arrSelectedAreas = array_filter($arrSelectedAreas); $arrAreasLabel = AmazonAutoLinks_Form_AutoInsert::getPredefinedFilters() + AmazonAutoLinks_Form_AutoInsert::getPredefinedFiltersForStatic(false); foreach ($arrSelectedAreas as $strArea => $fEnable) { if (isset($arrAreasLabel[$strArea])) { $arrList[] = $arrAreasLabel[$strArea]; } } $arrFilters = AmazonAutoLinks_Utilities::convertStringToArray(get_post_meta($intPostID, 'filter_hooks', true), ','); $arrActions = AmazonAutoLinks_Utilities::convertStringToArray(get_post_meta($intPostID, 'action_hooks', true), ','); $arrList = array_merge($arrFilters, $arrActions, $arrList); return '<p>' . implode(', ', $arrList) . '</p>'; }
/** * * 'Operation' => 'ItemSearch', // ItemSearch, ItemLookup, SimilarityLookup * @since 2.0.2 * @see http://docs.aws.amazon.com/AWSECommerceService/latest/DG/ItemSearch.html */ protected function getAPIParameterArray($sOperation = 'ItemSearch', $iItemPage = null) { $_bIsIndexAllOrBlended = 'All' === $this->arrArgs['SearchIndex'] || 'Blended' === $this->arrArgs['SearchIndex']; $_aParams = array('Keywords' => AmazonAutoLinks_Utilities::trimDelimitedElements($this->arrArgs['Keywords'], ',', false), 'Title' => $_bIsIndexAllOrBlended ? null : AmazonAutoLinks_Utilities::trimDelimitedElements($this->arrArgs['Title'], ',', false), 'Operation' => $this->arrArgs['Operation'], 'SearchIndex' => $this->arrArgs['SearchIndex'], $this->arrArgs['search_by'] => $this->arrArgs['additional_attribute'] ? $this->arrArgs['additional_attribute'] : null, 'Sort' => $_bIsIndexAllOrBlended ? null : $this->arrArgs['Sort'], 'ResponseGroup' => "Large", 'BrowseNode' => !$_bIsIndexAllOrBlended && isset($this->arrArgs['BrowseNode']) && $this->arrArgs['BrowseNode'] ? $this->arrArgs['BrowseNode'] : null, 'Availability' => isset($this->arrArgs['Availability']) && $this->arrArgs['Availability'] ? 'Available' : null, 'Condition' => $_bIsIndexAllOrBlended ? null : $this->arrArgs['Condition'], 'IncludeReviewsSummary' => "True", 'MaximumPrice' => !$_bIsIndexAllOrBlended && $this->arrArgs['MaximumPrice'] ? $this->arrArgs['MaximumPrice'] : null, 'MinimumPrice' => !$_bIsIndexAllOrBlended && $this->arrArgs['MinimumPrice'] ? $this->arrArgs['MinimumPrice'] : null, 'MinPercentageOff' => $this->arrArgs['MinPercentageOff'] ? $this->arrArgs['MinPercentageOff'] : null, 'MerchantId' => 'Amazon' === $this->arrArgs['MerchantId'] ? $this->arrArgs['MerchantId'] : null, 'MarketplaceDomain' => 'Marketplace' === $this->arrArgs['SearchIndex'] ? AmazonAutoLinks_Properties::getMarketplaceDomainByLocale($this->arrArgs['country']) : null); $_aParams = $iItemPage ? $_aParams + array('ItemPage' => $iItemPage) : $_aParams; return $_aParams; }
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']))); }