コード例 #1
0
 public function fetchFeed($vURLs, $numItems = 0, $fCacheRenew = false)
 {
     $arrURLs = is_array($vURLs) ? $vURLs : (array) $vURLs;
     $strURLID = md5(serialize($arrURLs));
     if (!isset($this->arrFeedItems[$strURLID]) && $fCacheRenew == false) {
         $this->arrFeedItems[$strURLID] = (array) AmazonAutoLinks_WPUtilities::getTransient($this->strTransientPrefix . $strURLID);
         unset($this->arrFeedItems[$strURLID][0]);
         // casting array causes the 0 key,
     }
     // If it's out of stock, fill the array by fetching the feed.
     if (empty($this->arrFeedItems[$strURLID])) {
         // When an array of urls is passed to the Simple Pie's set_feed_url() method, the memory usage increases largely.
         // So fetch the feeds one by one per url and store the output into an array.
         foreach ($arrURLs as $strURL) {
             $oFeed = $this->getFeedObj($strURL, null, $fCacheRenew ? 0 : 3600);
             // foreach ( $oFeed->get_items( 0, $numItems * 3 ) as $item ) does not change the memory usage
             foreach ($oFeed->get_items() as $oItem) {
                 $this->arrFeedItems[$strURLID][$oItem->get_title()] = array('strContent' => $oItem->get_content(), 'strDescription' => $oItem->get_description(), 'strTitle' => $oItem->get_title(), 'strDate' => $oItem->get_title(), 'strAuthor' => $oItem->get_date('j F Y, g:i a'), 'strLink' => $oItem->get_permalink());
             }
             // For PHP below 5.3 to release the memory.
             $oFeed->__destruct();
             // Do what PHP should be doing on it's own.
             unset($oFeed);
         }
         // This life span should be little longer than the feed cache life span, which is 1700.
         AmazonAutoLinks_WPUtilities::setTransient($this->strTransientPrefix . $strURLID, $this->arrFeedItems[$strURLID], 1800);
         // 30 minutes
     }
     $arrOut = $this->arrFeedItems[$strURLID];
     if ($numItems) {
         array_splice($arrOut, ${$numItems});
     }
     return $arrOut;
 }
コード例 #2
0
 protected function getBounceURL()
 {
     // AmazonAutoLinks_WPUtilities::deleteTransient( 'AAL_BounceURL' );
     return AmazonAutoLinks_WPUtilities::getTransient(isset($_GET['bounce_url']) ? $_GET['bounce_url'] : 'AAL_BounceURL');
     // if ( ! isset( $_GET['bounce_url'] ) )
     // return;
     // $oEncode = new AmazonAutoLinks_Encrypt;
     // return $oEncode->decode( $_GET['bounce_url'] );
 }
コード例 #3
0
 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;
 }
 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;
 }
コード例 #5
0
 /**
  * The global page load
  * 
  */
 public function load_AmazonAutoLinks_AdminPage()
 {
     // Check the support rate and ads visibility
     if (!(isset($_GET['tab'], $_GET['bounce_url']) && $_GET['tab'] == 'support') && !$this->oOption->arrOptions['aal_settings']['support']['agreed'] && $this->oOption->isSupportMissing()) {
         $strBounceURL = htmlspecialchars_decode(AmazonAutoLinks_WPUtilities::getCurrentAdminURL());
         $strBounceURL = str_replace('tab=support', '', $strBounceURL);
         // prevent infinite redirects            ;
         $strBounceURL = remove_query_arg('aal-option-upgrade', $strBounceURL);
         AmazonAutoLinks_WPUtilities::setTransient('AAL_BounceURL', $strBounceURL, 60 * 10);
         exit(wp_redirect(admin_url('edit.php?post_type=' . AmazonAutoLinks_Commons::PostTypeSlug . '&page=aal_settings&tab=support&bounce_url=AAL_BounceURL')));
     }
     // Check the v1 options exist and redirect to the v1 options importer.
     if (!(isset($_GET['tab'], $_GET['bounce_url']) && ($_GET['tab'] == 'import_v1_options' || $_GET['tab'] == 'support')) && !$this->oOption->arrOptions['aal_settings']['import_v1_options']['dismiss'] && false !== get_option('amazonautolinks')) {
         $strBounceURL = htmlspecialchars_decode(AmazonAutoLinks_WPUtilities::getCurrentAdminURL());
         $strBounceURL = str_replace('tab=import_v1_options', '', $strBounceURL);
         // prevent infinite redirects
         AmazonAutoLinks_WPUtilities::setTransient('AAL_BounceURL_Importer', $strBounceURL, 60 * 10);
         $this->setAdminNotice(sprintf(__('Please upgrade the options of previous versions of the plugin by clicking <a href="%1$s">here</a>.', 'amazon-auto-links') . ' ' . __('Before you do it, please <strong>back up</strong> the database.', 'amazon-auto-links') . ' ' . __('Dismiss this message by clicking <a href="%2$s">here</a>.', 'amazon-auto-links'), admin_url('edit.php?post_type=' . AmazonAutoLinks_Commons::PostTypeSlug . '&page=aal_settings&tab=import_v1_options&bounce_url=AAL_BounceURL_Importer'), admin_url('edit.php?post_type=' . AmazonAutoLinks_Commons::PostTypeSlug . '&page=aal_settings&tab=import_v1_options&action=dismiss&bounce_url=AAL_BounceURL_Importer')), 'error');
         return;
     }
     // Check v1 option importer messages
     if (isset($_GET['aal-option-upgrade'])) {
         switch ($_GET['aal-option-upgrade']) {
             case 'not-found':
                 $this->setAdminNotice(__('Could not find the options to import.', 'amazon-auto-links'), 'error');
                 break;
             case 'succeed':
                 $this->setAdminNotice(sprintf(__('Options have been imported. ( %1$s unit(s) )', 'amazon-auto-links'), $_GET['count']), 'updated');
                 break;
             case 'partial':
                 $this->setAdminNotice(sprintf(__('Options been partially imported. ( %1$s unit(s) )', 'amazon-auto-links'), $_GET['count']), 'error');
                 break;
             case 'failed':
                 $this->setAdminNotice(__('No unit was imported.', 'amazon-auto-links'), 'error');
                 break;
         }
     }
     // 3+ Add a setting notice to upgrade the options to v3
     $_sBounceURL = htmlspecialchars_decode(AmazonAutoLinks_WPUtilities::getCurrentAdminURL());
     $_sBounceURL = str_replace('tab=create_v3_options', '', $_sBounceURL);
     // prevent infinite redirects
     AmazonAutoLinks_WPUtilities::setTransient('AAL_BounceURL_Importer', $_sBounceURL, 60 * 10);
     $this->setAdminNotice('<strong>' . AmazonAutoLinks_Commons::Name . '</strong>: ' . sprintf(__('Please upgrade the options by clicking <strong><a href="%1$s">here</a></strong>.', 'amazon-auto-links') . ' ' . __('Before you do it, please <strong>back up</strong> the database.', 'amazon-auto-links'), admin_url('edit.php?post_type=' . AmazonAutoLinks_Commons::PostTypeSlug . '&page=aal_settings&tab=create_v3_options&bounce_url=AAL_BounceURL_Importer')), 'error');
 }
コード例 #6
0
 public function column_default($arrItem, $strColumnName)
 {
     // 'column_' + 'default'
     switch ($strColumnName) {
         case 'description':
             //Build row actions
             $arrActions = array('version' => sprintf(__('Version', 'amazon-auto-links') . '&nbsp;' . $arrItem['strVersion']), 'author' => sprintf('<a href="%s">' . $arrItem['strAuthor'] . '</a>', $arrItem['strAuthorURI']), 'css' => sprintf('<a href="%s">' . __('CSS', 'amazon-auto-links') . '</a>', AmazonAutoLinks_WPUtilities::getSRCFromPath($arrItem['strCSSPath'])));
             //Return the title contents
             return sprintf('%1$s <div class="active second">%2$s</div>', $arrItem['strDescription'], $this->row_actions($arrActions));
         case 'thumbnail':
             if (!file_exists($arrItem['strThumbnailPath'])) {
                 return;
             }
             $strImageURL = AmazonAutoLinks_WPUtilities::getSRCFromPath($arrItem['strThumbnailPath']);
             // $strImageURL = site_url() . "?amazon_auto_links_image=" . base64_encode( $arrItem['strThumbnailPath'] );
             return "<a class='template-thumbnail' href='#thumb'>" . "<img src='{$strImageURL}' style='max-width:80px; max-height:80px;' />" . "<span>" . "<div>" . "<img src='{$strImageURL}' /><br />" . $arrItem['strName'] . "</div>" . "</span>" . "</a>";
         default:
             return print_r($arrItem, true);
             //Show the whole array for troubleshooting purposes
     }
 }
コード例 #7
0
 protected function fetchItems($arrURLs, $numItems = 1)
 {
     $strURLID = md5(serialize(is_string($arrURLs) ? array($arrURLs) : $arrURLs));
     if (!isset($this->arrFeedItems[$strURLID])) {
         $this->arrFeedItems[$strURLID] = (array) AmazonAutoLinks_WPUtilities::getTransient($this->strTransientPrefix . $strURLID);
         $this->arrFeedItems[$strURLID] = array_filter($this->arrFeedItems[$strURLID]);
         // casting array causes the 0 key
     }
     // If it's out of stock, fill the array by fetching the feed.
     shuffle($this->arrFeedItems[$strURLID]);
     $this->arrFeedItems[$strURLID] = array_unique($this->arrFeedItems[$strURLID]);
     if (count($this->arrFeedItems[$strURLID]) < $numItems) {
         $oReplace = new AmazonAutoLinks_HTMLElementReplacer(get_bloginfo('charset'));
         // When an array of urls is passed to the Simple Pie's set_feed_url() method, the memory usage increases largely.
         // So fetch the feeds one by one per url and store the output into an array.
         foreach ($arrURLs as $strURL) {
             $oFeed = $this->getFeedObj($strURL, $numItems * 10);
             // multiplied by three to store items more than enough for next calls.
             foreach ($oFeed->get_items() as $item) {
                 // foreach ( $oFeed->get_items( 0, $numItems * 3 ) as $item ) does not change the memory usage
                 $this->arrFeedItems[$strURLID][] = $oReplace->Perform($item->get_content());
             }
             // For PHP below 5.3 to release the memory.
             $oFeed->__destruct();
             // Do what PHP should be doing on it's own.
             unset($oFeed);
         }
         unset($oReplace);
         // This life span should be little longer than the feed cache life span, which is 1700.
         AmazonAutoLinks_WPUtilities::setTransient($this->strTransientPrefix . $strURLID, $this->arrFeedItems[$strURLID], 1800);
         // 30 minutes
     }
     $this->arrFeedItems[$strURLID] = array_unique($this->arrFeedItems[$strURLID]);
     shuffle($this->arrFeedItems[$strURLID]);
     $strOut = '';
     for ($i = 1; $i <= $numItems; $i++) {
         $strOut .= array_pop($this->arrFeedItems[$strURLID]);
     }
     return $strOut;
 }
コード例 #8
0
 protected function handleCustomActions()
 {
     if (!isset($_GET['custom_action'], $_GET['nonce'], $_GET['post'])) {
         return;
     }
     $strNonce = AmazonAutoLinks_WPUtilities::getTransient('AAL_Nonce_' . $_GET['nonce']);
     if ($strNonce === false) {
         add_action('admin_notices', array($this, 'notifyNonceFailed'));
         return;
     }
     AmazonAutoLinks_WPUtilities::deleteTransient('AAL_Nonce_' . $_GET['nonce']);
     // Currently only the status toggle is supported.
     if ($_GET['custom_action'] == 'toggle_status' && $_GET['post']) {
         $arrUnitIDs = get_post_meta($_GET['post'], 'unit_ids', true);
         if (empty($arrUnitIDs)) {
             return;
         }
         // if this field is empty, the post must be the wrong post type.
         $fIsEnabled = get_post_meta($_GET['post'], 'status', true);
         update_post_meta($_GET['post'], 'status', !$fIsEnabled);
     }
 }
コード例 #9
0
 /**
  * 
  * @remark            The scope is public because the meta box calls it.
  */
 public function getFieldOfSimilarityLookUp($strSectionID, $strPrefix)
 {
     $bIsSearchUnitType = in_array($GLOBALS['strAmazonAutoLinks_UnitType'], array('search', 'item_lookup', 'similarity_lookup '));
     $arrUnitOptions = isset($_REQUEST['transient_id']) ? AmazonAutoLinks_WPUtilities::getTransient('AAL_CreateUnit_' . $_REQUEST['transient_id']) : ($bIsSearchUnitType && isset($_GET['post']) && $_GET['post'] != 0 ? $GLOBALS['oAmazonAutoLinks_Option']->getUnitOptionsByPostID($_GET['post']) : array());
     return array(array('strFieldID' => $strPrefix . 'unit_title', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Unit Name', 'amazon-auto-links'), 'strType' => 'text', 'fIf' => isset($_REQUEST['transient_id']), 'vValue' => isset($arrUnitOptions['unit_title']) ? $arrUnitOptions['unit_title'] : null), array('strFieldID' => $strPrefix . 'ItemId', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Item ASIN', 'amazon-auto-links'), 'strType' => 'text', 'vSize' => version_compare($GLOBALS['wp_version'], '3.8', '>=') ? 40 : 60, 'strDescription' => __('Enter the ASIN(s) of the product. For more more than one items, use the <code>,</code> (comma) characters to delimit the items.', 'amazon-auto-links') . ' e.g. <code>B009ZVO3H6</code>', 'vValue' => $strSectionID ? '' : null), array('strFieldID' => $strPrefix . 'SimilarityType', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Similarity Type', 'amazon-auto-links'), 'strType' => 'radio', 'vLabel' => array('Intersection' => __('Intersection', 'amazon-auto-links') . ' - ' . __('returns the intersection of items that are similar to all of the ASINs specified', 'amazon-auto-links'), 'Random' => __('Random', 'amazon-auto-links') . ' - ' . __('returns the union of randomly picked items that are similar to all of the ASINs specified.', 'amazon-auto-links')), 'strDescription' => __('The maximum of only ten items can be retrieved.', 'amazon-auto-links'), 'vDefault' => 'Intersection'), array('strFieldID' => $strPrefix . 'count', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Number of Items', 'amazon-auto-links'), 'strType' => 'number', 'vMax' => 10, 'vMin' => 1, 'strDescription' => __('The number of product links to display. This unit type cannot display more than 10 items.'), 'vDefault' => 10), array('strFieldID' => $strPrefix . 'search_type', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Search Type', 'amazon-auto-links'), 'strType' => 'text', 'vDisable' => true, 'vReadOnly' => true, 'vValue' => isset($arrUnitOptions['Operation']) ? $this->getSearchTypeLabel($arrUnitOptions['Operation']) : __('Similar Products', 'amazon-auto-links')), array('strFieldID' => $strPrefix . 'Operation', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Operation', 'amazon-auto-links'), 'strType' => 'hidden', 'vReadOnly' => true, 'vValue' => isset($arrUnitOptions['Operation']) ? $arrUnitOptions['Operation'] : 'SimilarityLookup'), array('strFieldID' => $strPrefix . 'country', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Locale', 'amazon-auto-links'), 'strType' => 'text', 'vReadOnly' => true, 'vValue' => isset($arrUnitOptions['country']) ? $arrUnitOptions['country'] : null), array('strFieldID' => $strPrefix . 'associate_id', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Associate ID', 'amazon-auto-links'), 'strType' => 'text', 'strDescription' => 'e.g. <code>miunosoft-20</code>', 'vValue' => isset($arrUnitOptions['associate_id']) ? $arrUnitOptions['associate_id'] : null), array('strFieldID' => $strPrefix . 'image_size', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Image Size', 'amazon-auto-links'), 'strType' => 'number', 'vAfterInputTag' => ' ' . __('pixel', 'amazon-auto-links'), 'vDelimiter' => '', 'strDescription' => __('The maximum width of the product image in pixel. Set <code>0</code> for no image.', 'amazon-auto-links') . ' ' . __('Max', 'amazon-auto-links') . ': <code>500</code> ' . __('Default', 'amazon-auto-links') . ': <code>160</code>', 'vMax' => 500, 'vMin' => 0, 'vDefault' => 160), array('strFieldID' => $strPrefix . 'ref_nosim', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Direct Link Bonus', 'amazon-auto-links'), 'strType' => 'radio', 'vLabel' => array(1 => __('On', 'amazon-auto-links'), 0 => __('Off', 'amazon-auto-links')), 'strDescription' => sprintf(__('Inserts <code>ref=nosim</code> in the link url. For more information, visit <a href="%1$s">this page</a>.', 'amazon-auto-links'), 'https://affiliate-program.amazon.co.uk/gp/associates/help/t5/a21'), 'vDefault' => 0), array('strFieldID' => $strPrefix . 'title_length', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Title Length', 'amazon-auto-links'), 'strType' => 'number', 'strDescription' => __('The allowed character length for the title.', 'amazon-auto-links') . '&nbsp;' . __('Use it to prevent a broken layout caused by a very long product title. Set -1 for no limit.', 'amazon-auto-links') . '<br />' . __('Default', 'amazon-auto-links') . ": <code>-1</code>", 'vDefault' => -1), array('strFieldID' => $strPrefix . 'description_length', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Description Length', 'amazon-auto-links'), 'strType' => 'number', 'strDescription' => __('The allowed character length for the description.', 'amazon-auto-links') . '&nbsp;' . __('Set -1 for no limit.', 'amazon-auto-links') . '<br />' . __('Default', 'amazon-auto-links') . ": <code>250</code>", 'vDefault' => 250), array('strFieldID' => $strPrefix . 'link_style', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Link Style', 'amazon-auto-links'), 'strType' => 'radio', 'vLabel' => array(1 => 'http://www.amazon.<code>[domain-suffix]</code>/<code>[product-name]</code>/dp/<code>[asin]</code>/ref=<code>[...]</code>?tag=<code>[associate-id]</code>' . "&nbsp;<span class='description'>(" . __('Default', 'amazon-auto-links') . ")</span>", 2 => 'http://www.amazon.<code>[domain-suffix]</code>/exec/obidos/ASIN/<code>[asin]</code>/<code>[associate-id]</code>/ref=<code>[...]</code>', 3 => 'http://www.amazon.<code>[domain-suffix]</code>/gp/product/<code>[asin]</code>/?tag=<code>[associate-id]</code>&ref=<code>[...]</code>', 4 => 'http://www.amazon.<code>[domain-suffix]</code>/dp/ASIN/<code>[asin]</code>/ref=<code>[...]</code>?tag=<code>[associate-id]</code>', 5 => site_url() . '?' . $GLOBALS['oAmazonAutoLinks_Option']->arrOptions['aal_settings']['query']['cloak'] . '=<code>[asin]</code>&locale=<code>[...]</code>&tag=<code>[associate-id]</code>'), 'vDefault' => 1), array('strFieldID' => $strPrefix . 'credit_link', 'strSectionID' => $strSectionID ? $strSectionID : null, 'strTitle' => __('Credit Link', 'amazon-auto-links'), 'strType' => 'radio', 'vLabel' => array(1 => __('On', 'amazon-auto-links'), 0 => __('Off', 'amazon-auto-links')), 'strDescription' => sprintf(__('Inserts the credit link at the end of the unit output.', 'amazon-auto-links'), ''), 'vDefault' => 1));
 }
コード例 #10
0
 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'])));
 }
コード例 #11
0
 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'))));
 }
コード例 #12
0
 /**
  * Enqueues activated templates' CSS file.
  * 
  */
 public function enqueueActiveTemplateStyles()
 {
     // This must be called after the option object has been established.
     foreach ($this->getActiveTemplates() as $arrTemplate) {
         if (!$this->doFilesExist(array($arrTemplate['strCSSPath'], $arrTemplate['strTemplatePath']))) {
             continue;
         }
         wp_register_style("amazon-auto-links-{$arrTemplate['strID']}", AmazonAutoLinks_WPUtilities::getSRCFromPath($arrTemplate['strCSSPath']));
         // wp_register_style( "amazon-auto-links-{$arrTemplate['strID']}", site_url() . "?amazon_auto_links_style={$arrTemplate['strID']}" );
         wp_enqueue_style("amazon-auto-links-{$arrTemplate['strID']}");
     }
 }
コード例 #13
0
 /**
  * Sets up the properties for the criteria of page types, taxonomies etc.
  * 
  * @remark            The $wp_query object has to be set priort to calling this method.
  */
 public function _replyToSetUpPageTypeProperties()
 {
     if (count($this->arrAutoInsertIDs) == 0) {
         return;
     }
     $this->intPostID = $this->getPostID();
     $this->arrDisplayedPageTypes = array('is_single' => is_single(), 'is_singular' => is_singular(), 'is_home' => is_home() || is_front_page(), 'is_archive' => is_archive(), 'is_404' => is_404(), 'is_search' => is_search());
     // The below are nothing to do with pages that don't have a post ID.
     if (!$this->intPostID) {
         return;
     }
     $this->strPostType = get_post_type($this->intPostID);
     $this->arrTermIDs = array();
     $arrTaxonomies = AmazonAutoLinks_WPUtilities::getPostTaxonomies($this->intPostID);
     foreach ($arrTaxonomies as $strTaxonomySlug => $oTaxonomy) {
         $arrTaxonomyTerms = wp_get_post_terms($this->intPostID, $strTaxonomySlug);
         foreach ($arrTaxonomyTerms as $oTerm) {
             $this->arrTermIDs[] = $oTerm->term_id;
         }
     }
     $this->arrTermIDs = array_unique($this->arrTermIDs);
 }
コード例 #14
0
 /**
  * The v2 Option Converter page(tab) to v3
  * 
  * @since           3
  * @callback        action      load_{page slug}_{tab slug}
  */
 public function load_aal_settings_create_v3_options()
 {
     if (!isset($_GET['bounce_url'])) {
         return;
     }
     $_sBounceURL = AmazonAutoLinks_WPUtilities::getTransient($_GET['bounce_url']);
     // Created v3 options from the v2 options.
     new AmazonAutoLinks_ImportV2Options(get_option(AmazonAutoLinks_Commons::AdminOptionKey, array()));
     // v3 will be loaded in the next page.
     delete_option(AmazonAutoLinks_Commons::AdminOptionKey);
     exit(wp_redirect($_sBounceURL . "&aal-option-upgrade=true"));
 }
コード例 #15
0
 /**
  * A wrapper method for the get_transient() function.
  * 
  * This method does retrieves the transient with the given transient key. In addition, it checks if it is an array; otherwise, it makes it an array.
  * 
  * @access            public
  * @since            2.0.0
  * @remark            The scope is public as the event method uses it.
  */
 public function getTransient($strTransientKey)
 {
     $vData = AmazonAutoLinks_WPUtilities::getTransient($strTransientKey);
     // if it's false, no transient is stored. Otherwise, some values are in there.
     if ($vData === false) {
         return false;
     }
     // If it's array, okay.
     if (is_array($vData)) {
         return $vData;
     }
     // Maybe it's encoded
     if (is_string($vData) && is_serialized($vData)) {
         return unserialize($vData);
     }
     // Maybe it's an object. In that case, convert it to an associative array.
     if (is_object($vData)) {
         return get_object_vars($vData);
     }
     // It's an unknown type. So cast array and return it.
     return (array) $vData;
 }
コード例 #16
0
 /**
  * A callback method triggered when the plugin is uninstalled.
  * @remark            currently not used yet.
  */
 public static function _replyToDoWhenPluginUninstalled()
 {
     AmazonAutoLinks_WPUtilities::cleanTransients();
 }
コード例 #17
0
 /**
  * Deletes the cache of the provided URL.
  */
 public function deleteCache($strURL)
 {
     AmazonAutoLinks_WPUtilities::deleteTransient($this->strHTMLCachePrefix . md5($strURL));
 }
コード例 #18
0
 public function getRemainedAllowedUnits($intNumberOfUnits = null)
 {
     if (!isset($intNumberOfUnits)) {
         $oNumberOfUnits = AmazonAutoLinks_WPUtilities::countPosts(AmazonAutoLinks_Commons::PostTypeSlug);
         $intNumberOfUnits = $oNumberOfUnits->publish + $oNumberOfUnits->private + $oNumberOfUnits->trash;
     }
     return 3 - $intNumberOfUnits;
 }
コード例 #19
0
 /**
  * A callback for the accessSiteAtShutDown() method.
  * 
  * @since            1.0.0
  */
 public static function _replyToAccessSite()
 {
     // Retrieve the plugin scheduled tasks array.
     $_sTransientName = md5(get_class());
     $_aTasks = AmazonAutoLinks_WPUtilities::getTransient($_sTransientName);
     $_aTasks = $_aTasks ? $_aTasks : array();
     $_nNow = microtime(true);
     // Check the excessive background call protection interval
     if (!self::$_fIgnoreLock) {
         $_nCalled = isset($_aTasks['called']) ? $_aTasks['called'] : 0;
         if ($_nCalled + self::$_iLockBackgroundCallInterval > $_nNow) {
             return;
             // if it's called within 10 seconds from the last time of calling this method, do nothing to avoid excessive calls.
         }
     }
     // Renew the called time.
     $_aFlagKeys = array('called' => $_nNow);
     AmazonAutoLinks_WPUtilities::setTransient($_sTransientName, $_aFlagKeys + $_aTasks, self::getAllowedMaxExecutionTime());
     // set a locked key so it prevents duplicated function calls due to too many calls caused by simultaneous accesses.
     // Compose a GET query array
     $_aGet = self::$_aGet;
     if (defined('WP_DEBUG')) {
         $_aGet['debug'] = WP_DEBUG;
     }
     unset($_aGet[0]);
     // Load the site in the background.
     wp_remote_get(site_url('?' . http_build_query($_aGet)), array('timeout' => 0.01, 'sslverify' => false, 'cookies' => $_aFlagKeys + array($_sTransientName => true)));
 }