mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 03:40:37 +02:00
Fixes Newsfeed Cache issue. Fixes text_truncate utf8 issue.
This commit is contained in:
@@ -29,10 +29,10 @@ if (!e107::isInstalled('newsfeed'))
|
||||
return;
|
||||
}
|
||||
|
||||
define('NEWSFEED_LIST_CACHE_TAG', 'nomd5_newsfeeds');
|
||||
define('NEWSFEED_NEWS_CACHE_TAG', 'nomd5_newsfeeds_news_');
|
||||
define('NEWSFEED_LIST_CACHE_TAG', 'newsfeeds'.e_LAN."_");
|
||||
define('NEWSFEED_NEWS_CACHE_TAG', 'newsfeeds_news_'.e_LAN."_");
|
||||
|
||||
define('NEWSFEED_DEBUG', FALSE);
|
||||
define('NEWSFEED_DEBUG', false);
|
||||
|
||||
|
||||
class newsfeedClass
|
||||
@@ -56,7 +56,7 @@ class newsfeedClass
|
||||
$this->lastProcessed = 0;
|
||||
$this->truncateCount = 150; // Set a pref for these two later
|
||||
$this->truncateMore = '...';
|
||||
$this->useCache = e107::getCache()->UserCacheActive; // Have our own local copy - should be faster to access
|
||||
$this->useCache = true; // e107::getCache()->UserCacheActive; // Have our own local copy - should be faster to access
|
||||
}
|
||||
|
||||
// Ensures the feed list is loaded - uses cache if available
|
||||
@@ -94,10 +94,12 @@ class newsfeedClass
|
||||
if (!empty($row['newsfeed_data']))
|
||||
{
|
||||
$this->newsList[$nfID]['newsfeed_data'] = $row['newsfeed_data']; // Pull out the actual news - might as well since we're here
|
||||
$this->newsList[$nfID]['newsfeed_timestamp'] = $row['newsfeed_timestamp'];
|
||||
|
||||
|
||||
unset($row['newsfeed_data']); // Don't keep this in memory twice!
|
||||
}
|
||||
|
||||
$this->newsList[$nfID]['newsfeed_timestamp'] = $row['newsfeed_timestamp'];
|
||||
|
||||
$this->feedList[$nfID] = $row; // Put the rest into the feed data
|
||||
}
|
||||
@@ -126,18 +128,32 @@ class newsfeedClass
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(empty($this->newsList[$feedID]['newsfeed_timestamp']) || empty($this->newsList[$feedID]['newsfeed_data']) || strpos($this->newsList[$feedID]['newsfeed_data'],'MagpieRSS')) //BC Fix to update newsfeed_data from v1 to v2 spec.
|
||||
$maxAge = ($this->feedList[$feedID]['newsfeed_updateint']/60);
|
||||
|
||||
if($maxAge < 1){ $maxAge = 1; }
|
||||
|
||||
// e107::getDebug()->log("NewsFeed #".$feedID." MaxAge: ".$maxAge);
|
||||
|
||||
$cachedData = e107::getCache()->retrieve(NEWSFEED_NEWS_CACHE_TAG.$feedID,$maxAge, true);
|
||||
|
||||
if(empty($this->newsList[$feedID]['newsfeed_timestamp']) || empty($cachedData) || strpos($this->newsList[$feedID]['newsfeed_data'],'MagpieRSS')) //BC Fix to update newsfeed_data from v1 to v2 spec.
|
||||
{
|
||||
$force = true;
|
||||
// e107::getDebug()->log("NewsFeed Force");
|
||||
}
|
||||
|
||||
if($force) // No data already in memory
|
||||
if($cachedData !== false && $force === false)
|
||||
{
|
||||
// e107::getDebug()->log("NewsFeed Cache Used");
|
||||
$this->newsList[$feedID]['newsfeed_data'] = $cachedData;
|
||||
}
|
||||
|
||||
if ($force === true) // Need to re-read from source - either no cached data yet, or cache expired
|
||||
{
|
||||
if ($force || !($this->newsList[$feedID]['newsfeed_data'] = e107::getCache()->retrieve(NEWSFEED_NEWS_CACHE_TAG.$feedID, $this->feedList[$feedID]['newsfeed_updateint']/60)))
|
||||
{ // Need to re-read from source - either no cached data yet, or cache expired
|
||||
|
||||
if (NEWSFEED_DEBUG)
|
||||
{
|
||||
e107::getDebug()->log("NewsFeed Update: Item #".$feedID." ".NEWSFEED_NEWS_CACHE_TAG);
|
||||
e107::getLog()->e_log_event(10,debug_backtrace(),"DEBUG","Newsfeed update","Refresh item: ".$feedID,FALSE,LOG_TO_ROLLING);
|
||||
}
|
||||
|
||||
@@ -208,21 +224,24 @@ class newsfeedClass
|
||||
|
||||
if ($this->useCache)
|
||||
{
|
||||
e107::getCache()->set(NEWSFEED_NEWS_CACHE_TAG.$feedID, $serializedArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
$dbData['newsfeed_data'] = $serializedArray;
|
||||
$dbData['newsfeed_timestamp'] = $now;
|
||||
// e107::getDebug()->log("Saving Cache");
|
||||
e107::getCache()->set(NEWSFEED_NEWS_CACHE_TAG.$feedID, $serializedArray, true);
|
||||
}
|
||||
|
||||
$dbData['newsfeed_data'] = $serializedArray;
|
||||
$dbData['newsfeed_timestamp'] = $now;
|
||||
|
||||
|
||||
if (count($dbData)) // Only write the feed data to DB if not using cache. Write description if changed
|
||||
{
|
||||
|
||||
$dbData['WHERE'] = "newsfeed_id=".$feedID;
|
||||
|
||||
|
||||
|
||||
if(FALSE === $sql->update('newsfeed', $dbData))
|
||||
{
|
||||
// e107::getDebug()->log("NewsFeed DB Update Failed");
|
||||
if (NEWSFEED_DEBUG) echo NFLAN_48."<br /><br />".var_dump($dbData);
|
||||
}
|
||||
}
|
||||
@@ -233,7 +252,6 @@ class newsfeedClass
|
||||
if (NEWSFEED_DEBUG) echo $xml -> error;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return e107::unserialize($this->newsList[$feedID]['newsfeed_data']);
|
||||
|
Reference in New Issue
Block a user