/** * Sets up hooks. */ public function setUp() { if ($this->_isInThePage()) { $this->sCustomNonce = uniqid(); AmazonAutoLinks_WPUtility::setTransient('AAL_Nonce_' . $this->sCustomNonce, $this->sCustomNonce, 60 * 10); // unit listing table columns add_filter('columns_' . AmazonAutoLinks_Registry::$aPostTypes['auto_insert'], array($this, 'replyToModifyColumnHeader')); } parent::setUp(); }
/** * * @remark Will redirect the user to the next page and exits the script. */ private function _goToNextPage($aInput) { // Format the submitted data. $aInput['transient_id'] = isset($_GET['transient_id']) ? $_GET['transient_id'] : uniqid(); $aInput['bounce_url'] = add_query_arg(array('transient_id' => $aInput['transient_id'], 'aal_action' => 'select_category', 'page' => $this->sPageSlug, 'tab' => $this->sTabSlug) + $_GET, admin_url($GLOBALS['pagenow'])); return $aInput; // Save the data in a temporary area of the databse. $_bSucceed = AmazonAutoLinks_WPUtility::setTransient(AmazonAutoLinks_Registry::TRANSIENT_PREFIX . '_CreateUnit_' . $aInput['transient_id'], $aInput, 60 * 10 * 6 * 24); // Go to the next page. exit(wp_safe_redirect(add_query_arg(array('transient_id' => $aInput['transient_id'], 'aal_action' => 'select_category', 'tab' => 'second') + $_GET, admin_url($GLOBALS['pagenow'])))); }
/** * A wrapper method for the set_transient() function. * * @since unknown * @since 3 Changed the name from `setTransient()`. */ public function setCache($sTransientKey, $vData, $iDuration = 0, $sRequestURI = '') { $sLockTransient = AmazonAutoLinks_Registry::TRANSIENT_PREFIX . '_' . md5("Lock_{$sTransientKey}"); // Check if the transient is locked if (AmazonAutoLinks_WPUtility::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_WPUtility::setTransient($sLockTransient, time(), AmazonAutoLinks_WPUtility::getAllowedMaxExecutionTime(30, 30)); // Save the cache if ($this->bUseCacheTable) { $_oCacheTable = new AmazonAutoLinks_DatabaseTable_request_cache(AmazonAutoLinks_Registry::$aDatabaseTables['request_cache']); $_aData = $_oCacheTable->setCache($sTransientKey, array('mod' => time(), 'data' => $vData), (int) $iDuration, array('request_uri' => $sRequestURI, 'type' => 'api')); } else { AmazonAutoLinks_WPUtility::setTransient($sTransientKey, array('mod' => time(), 'data' => $this->oEncrypt->encode($vData)), 9999999); } }
/** * 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_WPUtility::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); // set a locked key so it prevents duplicated function calls due to too many calls caused by simultaneous accesses. AmazonAutoLinks_WPUtility::setTransient($_sTransientName, $_aFlagKeys + $_aTasks, self::getAllowedMaxExecutionTime()); // 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.1, 'sslverify' => false, 'cookies' => $_aFlagKeys + array($_sTransientName => true))); }
public function save($data) { if (is_a($data, 'SimplePie')) { $data = $data->data; } $GLOBALS['aSimplePieCacheModTimestamps'][$this->sPluginKey][$this->sFileID] = time(); // make it 100 times longer so that it barely gets expires by itself AmazonAutoLinks_WPUtility::setTransient($this->sTransientName, $data, $this->iLifetime * $this->iExpand); return true; }