$count = $params->get('twitterCount', '3') - 1; // Load module CSS JHtml::stylesheet('mod_tweetdisplayback/' . $template . '.css', false, true, false); $helper = new ModTweetDisplayBackHelper($params); // The files that the data is cached to $cacheTweets = JPATH_CACHE . '/tweetdisplayback_tweets.json'; $cacheUser = JPATH_CACHE . '/tweetdisplayback_user.json'; // Check if caching is enabled if ($params->get('cache') == 1) { // Fetch cache time from module parameters and convert to seconds $cacheTime = $params->get('cache_time', 15); $cacheTime = $cacheTime * 60; // Cache files expired? if (!file_exists($cacheTweets) && !file_exists($cacheUser) || time() - @filemtime($cacheTweets) > $cacheTime && time() - @filemtime($cacheUser) > $cacheTime) { // Do a request to the Twitter API for new data $twitter = $helper->compileData(); } else { // Render from the cached data $helper->isCached = true; $twitter = $helper->compileFromCache(); } } else { // Do a request to the Twitter API for new data $twitter = $helper->compileData(); } // Check to see if processing finished if (!$helper->isProcessed) { // If we have cache files still, try to render from them if (file_exists($cacheTweets) && file_exists($cacheUser)) { // Render from the cached data $helper->isCached = true;
if ($params->get('cache') == 1) { // Set the cache parameters $options = array('defaultgroup' => 'mod_tweetdisplayback'); $cache = JCache::getInstance('callback', $options); $cacheTime = $params->get('cache_time'); // J! 1.5 and 1.6 cache is set in seconds, 1.7 caches in minutes if (version_compare(JVERSION, '1.7.0', 'ge')) { $cacheTime = round($cacheTime / 60); } $cache->setLifeTime($cacheTime); $cache->setCaching(true); // Call the cache; if expired, pull new data $twitter = $cache->call(array('ModTweetDisplayBackHelper', 'compileData'), $params); } else { // Pull new data $twitter = ModTweetDisplayBackHelper::compileData($params); } // No hits remaining if (isset($twitter->hits)) { echo '<div class="TDB-tweet' . $tweetClassSfx . $tweetAvatar . '"><div class="TDB-tweet-container TDB-tweet-align-' . $tweetAlign . ' TDB-error"><div class="TDB-tweet-text">' . JText::_('MOD_TWEETDISPLAYBACK_ERROR_NOHITS') . '</div></div></div>'; return; } else { if (!$twitter || isset($twitter->error)) { echo '<div class="TDB-tweet' . $tweetClassSfx . $tweetAvatar . '"><div class="TDB-tweet-container TDB-tweet-align-' . $tweetAlign . ' TDB-error"><div class="TDB-tweet-text">' . JText::_('MOD_TWEETDISPLAYBACK_ERROR_UNABLETOLOAD') . '</div></div></div>'; return; } } } // Add the Twitter Web Intents script if something else already hasn't $document = JFactory::getDocument(); if (!in_array('<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>', $document->_custom)) {