1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

Fixes Newsfeed Cache issue. Fixes text_truncate utf8 issue.

This commit is contained in:
Cameron
2016-05-21 09:08:46 -07:00
parent 6952cb9272
commit 94d634462f
2 changed files with 44 additions and 20 deletions

View File

@@ -1314,25 +1314,31 @@ class e_parse extends e_parser
public function text_truncate($text, $len = 200, $more = ' ... ') public function text_truncate($text, $len = 200, $more = ' ... ')
{ {
// Always valid // Always valid
if($this->ustrlen($text) <= $len) if($this->ustrlen($text) <= $len)
{ {
return $text; return $text;
} }
$text = html_entity_decode($text,ENT_QUOTES,'utf-8');
return mb_strimwidth($text, 0, $len, $more);
$ret = $this->usubstr($text, 0, $len); // $ret = $this->usubstr($text, 0, $len);
// search for possible broken html entities // search for possible broken html entities
// - if an & is in the last 8 chars, removing it and whatever follows shouldn't hurt // - if an & is in the last 8 chars, removing it and whatever follows shouldn't hurt
// it should work for any characters encoding // it should work for any characters encoding
// FIXME - INVESTIGATE this one, switch to utf8 aware methods /*
$leftAmp = $this->ustrrpos($this->usubstr($ret, -8), '&'); $leftAmp = $this->ustrrpos($this->usubstr($ret, -8), '&');
if($leftAmp) if($leftAmp)
{ {
$ret = $this->usubstr($ret, 0, $this->ustrlen($ret) - 8 + $leftAmp); $ret = $this->usubstr($ret, 0, $this->ustrlen($ret) - 8 + $leftAmp);
} }
return $ret.$more; return $ret.$more;*/
} }

View File

@@ -29,10 +29,10 @@ if (!e107::isInstalled('newsfeed'))
return; return;
} }
define('NEWSFEED_LIST_CACHE_TAG', 'nomd5_newsfeeds'); define('NEWSFEED_LIST_CACHE_TAG', 'newsfeeds'.e_LAN."_");
define('NEWSFEED_NEWS_CACHE_TAG', 'nomd5_newsfeeds_news_'); define('NEWSFEED_NEWS_CACHE_TAG', 'newsfeeds_news_'.e_LAN."_");
define('NEWSFEED_DEBUG', FALSE); define('NEWSFEED_DEBUG', false);
class newsfeedClass class newsfeedClass
@@ -56,7 +56,7 @@ class newsfeedClass
$this->lastProcessed = 0; $this->lastProcessed = 0;
$this->truncateCount = 150; // Set a pref for these two later $this->truncateCount = 150; // Set a pref for these two later
$this->truncateMore = '...'; $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 // Ensures the feed list is loaded - uses cache if available
@@ -94,10 +94,12 @@ class newsfeedClass
if (!empty($row['newsfeed_data'])) 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_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! 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 $this->feedList[$nfID] = $row; // Put the rest into the feed data
} }
@@ -126,18 +128,32 @@ class newsfeedClass
return FALSE; 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; $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) 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); 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) if ($this->useCache)
{ {
e107::getCache()->set(NEWSFEED_NEWS_CACHE_TAG.$feedID, $serializedArray); // e107::getDebug()->log("Saving Cache");
} e107::getCache()->set(NEWSFEED_NEWS_CACHE_TAG.$feedID, $serializedArray, true);
else
{
$dbData['newsfeed_data'] = $serializedArray;
$dbData['newsfeed_timestamp'] = $now;
} }
$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 if (count($dbData)) // Only write the feed data to DB if not using cache. Write description if changed
{ {
$dbData['WHERE'] = "newsfeed_id=".$feedID; $dbData['WHERE'] = "newsfeed_id=".$feedID;
if(FALSE === $sql->update('newsfeed', $dbData)) if(FALSE === $sql->update('newsfeed', $dbData))
{ {
// e107::getDebug()->log("NewsFeed DB Update Failed");
if (NEWSFEED_DEBUG) echo NFLAN_48."<br /><br />".var_dump($dbData); if (NEWSFEED_DEBUG) echo NFLAN_48."<br /><br />".var_dump($dbData);
} }
} }
@@ -233,7 +252,6 @@ class newsfeedClass
if (NEWSFEED_DEBUG) echo $xml -> error; if (NEWSFEED_DEBUG) echo $xml -> error;
return FALSE; return FALSE;
} }
}
} }
return e107::unserialize($this->newsList[$feedID]['newsfeed_data']); return e107::unserialize($this->newsList[$feedID]['newsfeed_data']);