public function __construct() { // Objects $this->oBase64 = new FetchTweets_Base64(); // For transient (cache) renewal events add_action('fetch_tweets_action_transient_renewal', array($this, '_replyToRenewTransients')); // For transient (cache) formatting events - adds oEmbed elements. add_action('fetch_tweets_action_transient_add_oembed_elements', array($this, '_replyToAddOEmbedElements')); // For SimplePie cache renewal events add_action('fetch_tweets_action_simplepie_renew_cache', array($this, '_replyToRenewSimplePieCaches')); // This must be called after the above action hooks are added. if ('intense' == $GLOBALS['oFetchTweets_Option']->aOptions['cache_settings']['caching_mode']) { new FetchTweets_Cron(apply_filters('fetch_tweets_filter_plugin_cron_actions', array('fetch_tweets_action_transient_renewal', 'fetch_tweets_action_transient_add_oembed_elements', 'fetch_tweets_action_simplepie_renew_cache'))); } else { if (FetchTweets_Cron::isBackground()) { exit; } } // Redirects if (isset($_GET['fetch_tweets_link']) && $_GET['fetch_tweets_link']) { $_oRedirect = new FetchTweets_Redirects(); $_oRedirect->go($_GET['fetch_tweets_link']); // will exit there. } // Draw the cached image. if (isset($_GET['fetch_tweets_image']) && $_GET['fetch_tweets_image'] && is_user_logged_in()) { $_oImageLoader = new FetchTweets_ImageHandler('FTWS'); $_oImageLoader->draw($_GET['fetch_tweets_image']); exit; } // For the activation hook add_action('fetch_tweets_action_setup_transients', array($this, '_replyToSetUpTransients')); }
/** * A wrapper method for the set_transient() function. * * @since 1.2.0 * @since 1.3.0 Made it public as the event method uses it. */ public function setTransient($sRequestURI, $vData, $iTime = null, $bIgnoreLock = false) { $_sTransientKey = FetchTweets_Commons::TransientPrefix . "_" . md5(trim($sRequestURI)); $_sLockTransient = FetchTweets_Commons::TransientPrefix . '_' . md5("Lock_" . $_sTransientKey); // Give some time to the server to store transients in case of simultaneous accesses. if (FetchTweets_Cron::isBackground()) { sleep(1); } // Check if the transient is locked. if (!$bIgnoreLock && false !== FetchTweets_WPUtilities::getTransient($_sLockTransient)) { return; // it means the cache is being modified. } // Set a lock flag transient that indicates the transient is being renewed. if (!$bIgnoreLock) { FetchTweets_WPUtilities::setTransient($_sLockTransient, 'locked', 10); } // Store the cache $_bIsSet = FetchTweets_WPUtilities::setTransient($_sTransientKey, array('mod' => $iTime ? $iTime : time(), 'data' => $this->oBase64->encode($vData))); if (!$_bIsSet) { return; } // Schedule the action to run in the background with WP Cron. If already scheduled, skip. // This adds the embedding elements which takes some time to process. $_aArgs = array($sRequestURI); if ($iTime || wp_next_scheduled('fetch_tweets_action_transient_add_oembed_elements', $_aArgs)) { return; } wp_schedule_single_event(time(), 'fetch_tweets_action_transient_add_oembed_elements', $_aArgs); if ('intense' == $this->oOption->aOptions['cache_settings']['caching_mode']) { FetchTweets_Cron::see(array(), true); } else { // $this->arrExpiredTransientsRequestURIs wp_remote_get(site_url("/wp-cron.php"), array('timeout' => 0.01, 'sslverify' => false)); } // Delete the lock transient // FetchTweets_WPUtilities::deleteTransient( $_sLockTransient ); }