/** * Enqueues activated templates' CSS file. * * @callback action admin_head, wp_head * @since 3 */ public function replyToPrintStyleTag() { $_sCSSRules = $this->getButtonsCSS(); if (!$_sCSSRules) { return; } $_sCSSRules = defined('WP_DEBUG') && WP_DEBUG ? $_sCSSRules : AmazonAutoLinks_Utility::minifyCSS($_sCSSRules); echo "<style type='text/css' id='amazon-auto-links-button-css'>" . $_sCSSRules . "</style>"; }
/** * 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($sFilePath) { $_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. $_sRelativePath = AmazonAutoLinks_Utility::getRelativePath(ABSPATH, $sFilePath); $_sRelativePath = preg_replace("/^\\.[\\/\\\\]/", '', $_sRelativePath, 1); // removes the heading ./ or .\ $sHref = trailingslashit($_oWPStyles->base_url) . $_sRelativePath; return esc_url($sHref); }
/** * Validates the submitted form data. * * @since 3 */ public function validate($aInput, $aOldInput, $oAdminPage, $aSubmitInfo) { $_bVerified = true; $_aErrors = array(); // Sanitize the custom preview slug. $aInput['preview_post_type_slug'] = AmazonAutoLinks_Utility::sanitizeCharsForURLQueryKey(AmazonAutoLinks_Utility::getTrancatedString($aInput['preview_post_type_slug'], 20, '')); // An invalid value is found. Set a field error array and an admin notice and return the old values. if (!$_bVerified) { $oAdminPage->setFieldErrors($_aErrors); $oAdminPage->setSettingNotice(__('There was something wrong with your input.', 'amazon-auto-links')); return $aOldInput; } return $aInput; }
/** * Validates the submitted form data. * * @since 3 */ public function validate($aInput, $aOldInput, $oAdminPage, $aSubmitInfo) { $_bVerified = true; $_aErrors = array(); // Sanitize text inputs $aInput['allowed_html_tags'] = trim(AmazonAutoLinks_Utility::trimDelimitedElements($aInput['allowed_html_tags'], ',')); // An invalid value is found. Set a field error array and an admin notice and return the old values. if (!$_bVerified) { $oAdminPage->setFieldErrors($_aErrors); $oAdminPage->setSettingNotice(__('There was something wrong with your input.', 'amazon-auto-links')); return $aOldInput; } return $aInput; }
/** * Validates the submitted form data. * * @since 3 */ public function validate($aInput, $aOldInput, $oAdminPage, $aSubmitInfo) { $_bVerified = true; $_aErrors = array(); // Sanitize the query key. $aInput['cloak'] = AmazonAutoLinks_Utility::sanitizeCharsForURLQueryKey($aInput['cloak']); // An invalid value is found. Set a field error array and an admin notice and return the old values. if (!$_bVerified) { $oAdminPage->setFieldErrors($_aErrors); $oAdminPage->setSettingNotice(__('There was something wrong with your input.', 'amazon-auto-links')); return $aOldInput; } return $aInput; }
/** * * @since 3 */ protected function format(array $aUnitOptions) { $_oOption = AmazonAutoLinks_Option::getInstance(); $aUnitOptions = $aUnitOptions + $this->aDefault; // the item lookup search unit type does not have a count field if (isset($aUnitOptions['count'])) { $aUnitOptions['count'] = $this->fixNumber($aUnitOptions['count'], 10, 1, $_oOption->getMaximumProductLinkCount()); } $aUnitOptions['image_size'] = $this->fixNumber($aUnitOptions['image_size'], 160, 0, 500); if (isset($aUnitOptions['column'])) { $aUnitOptions['column'] = AmazonAutoLinks_Utility::fixNumber($aUnitOptions['column'], 4, 1, $_oOption->getMaxSupportedColumnNumber()); } // Drop undefined keys. foreach ($aUnitOptions as $_sKey => $_mValue) { if (array_key_exists($_sKey, $this->aDefault)) { continue; } unset($aUnitOptions[$_sKey]); } return $aUnitOptions; }
/** * Validates the submitted form data. * * @since 3 */ public function validate($aInput, $aOldInput, $oAdminPage, $aSubmitInfo) { $_bVerified = true; $_aErrors = array(); // Sanitize text inputs foreach ($aInput['black_list'] as &$_sElem) { $_sElem = AmazonAutoLinks_Utility::trimDelimitedElements($_sElem, ','); $_sElem = AmazonAutoLinks_Utility::trimDelimitedElements($_sElem, PHP_EOL, false); $_sElem = trim($_sElem); } foreach ($aInput['white_list'] as &$_sElem) { $_sElem = AmazonAutoLinks_Utility::trimDelimitedElements($_sElem, ','); $_sElem = AmazonAutoLinks_Utility::trimDelimitedElements($_sElem, PHP_EOL, false); $_sElem = trim($_sElem); } // An invalid value is found. Set a field error array and an admin notice and return the old values. if (!$_bVerified) { $oAdminPage->setFieldErrors($_aErrors); $oAdminPage->setSettingNotice(__('There was something wrong with your input.', 'amazon-auto-links')); return $aOldInput; } 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 $aAllowedTags e.g. array( 'noscript', 'style', ) * @param array $aDisallowedTags e.g. array( 'table', 'tbody', 'thoot', 'thead', 'th', 'tr' ) * @since 2.0.0 */ public static function escapeKSESFilter($sString, $aAllowedTags = array(), $aDisallowedTags = array(), $aAllowedProtocols = array()) { foreach ($aAllowedTags as $sTag) { $aFormatAllowedTags[$sTag] = array(); // activate the inline style attribute. } $aAllowedHTMLTags = AmazonAutoLinks_Utility::uniteArrays($aFormatAllowedTags, $GLOBALS['allowedposttags']); // the first parameter takes over the second. foreach ($aDisallowedTags as $sTag) { if (isset($aAllowedHTMLTags[$sTag])) { unset($aAllowedHTMLTags[$sTag]); } } if (empty($aAllowedProtocols)) { $aAllowedProtocols = wp_allowed_protocols(); } $sString = addslashes($sString); // the original function call was doing this - could be redundant but haven't fully tested it $sString = stripslashes($sString); // wp_filter_post_kses() $sString = wp_kses_no_null($sString); // wp_kses() $sString = wp_kses_js_entities($sString); // wp_kses() $sString = wp_kses_normalize_entities($sString); // wp_kses() $sString = wp_kses_hook($sString, $aAllowedHTMLTags, $aAllowedProtocols); // WP changed the order of these funcs and added args to wp_kses_hook $sString = wp_kses_split($sString, $aAllowedHTMLTags, $aAllowedProtocols); $sString = addslashes($sString); // wp_filter_post_kses() $sString = stripslashes($sString); // the original function call was doing this - could be redundant but haven't fully tested it return $sString; }
/** * Performs an API request from the given request API parameters and returns the result as associative array. * * @param string $sType The return type, either 'array', 'json' */ public function request(array $aParams, $sLocale = '', $iCacheDuration = 3600, $sType = 'array', $iTimeout = 20, $iRedirection = 5, $sHeaders = '', $sUserAgent = '') { // Arguments $aHTTPArgs = array('timeout' => $iTimeout, 'redirection' => $iRedirection, 'sslverify' => false, 'headers' => !empty($sHeaders) ? $sHeaders : null, 'user-agent' => $sUserAgent ? $sUserAgent : $this->sUserAgent); $aHTTPArgs = array_filter($aHTTPArgs); // drop non value elements. // Request $vResponse = $this->requestWithCache($this->getSignedRequestURI($aParams, $sLocale), $aHTTPArgs, $aParams, $iCacheDuration, $sLocale ? $sLocale : $this->sLocale); // If an error occurs, if (!is_string($vResponse)) { return $vResponse; } $_sXMLResponse = $vResponse; // It returns a string if it's not a valid XML content. $_boXML = AmazonAutoLinks_Utility::getXMLObject($_sXMLResponse); if (false === $_boXML) { return array('Error' => array('Message' => strip_tags($_sXMLResponse), 'Code' => 'Invalid XML')); } // Return the result with the specified type. if ('xml' === $sType) { return $_sXMLResponse; } else { if ('array' === $sType) { return AmazonAutoLinks_Utility::convertXMLtoArray($_boXML); } else { if ('json' == $sType) { return AmazonAutoLinks_Utility::convertXMLtoJSON($_boXML); } } } }