1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 03:40:37 +02:00

Newsfeeds: Fixes #1495. Admin-area rewrite using admin-ui. Newsfeed class is now compatible with PHP7.

This commit is contained in:
Cameron
2016-04-20 17:25:32 -07:00
parent 716678a3b7
commit f6ca9f8883
9 changed files with 376 additions and 258 deletions

View File

@@ -47,9 +47,8 @@ class newsfeedClass
var $useCache; // Set if cache is available
// Constructor
function newsfeedClass()
function __construct()
{
global $e107;
$this->validFeedList = FALSE;
$this->newsList = array();
$this->feedList = array();
@@ -57,7 +56,7 @@ class newsfeedClass
$this->lastProcessed = 0;
$this->truncateCount = 150; // Set a pref for these two later
$this->truncateMore = '...';
$this->useCache = $e107->ecache->UserCacheActive; // Have our own local copy - should be faster to access
$this->useCache = e107::getCache()->UserCacheActive; // Have our own local copy - should be faster to access
}
// Ensures the feed list is loaded - uses cache if available
@@ -71,13 +70,8 @@ class newsfeedClass
}
if($this->useCache) // Cache enabled - try to read from that first
{
$eArrayStorage = e107::getArrayStorage();
global $e107;
if (!$force && $temp = $e107->ecache->retrieve(NEWSFEED_LIST_CACHE_TAG))
if (!$force && $temp = e107::getCache()->retrieve(NEWSFEED_LIST_CACHE_TAG))
{
$this->feedList = e107::unserialize($temp);
return;
@@ -97,7 +91,7 @@ class newsfeedClass
{
$nfID = $row['newsfeed_id'];
if (isset($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_timestamp'] = $row['newsfeed_timestamp'];
@@ -110,8 +104,8 @@ class newsfeedClass
$this->validFeedList = TRUE;
}
if ($this->useCache)
{ // Cache enabled - we need to save some updated info
if ($this->useCache) // Cache enabled - we need to save some updated info
{
$temp = e107::serialize($this->feedList, FALSE);
e107::getCache()->set(NEWSFEED_LIST_CACHE_TAG,$temp);
}
@@ -121,14 +115,13 @@ class newsfeedClass
// Returns the info for a single feed - from cache or memory as appropriate. If time expired, updates the feed.
function getFeed($feedID, $force = FALSE)
{
global $e107, $admin_log;
$tp = e107::getParser();
$sql = e107::getDb();
$eArrayStorage = e107::getArrayStorage();
$this->readFeedList(); // Make sure we've got the feed data.
// $force = true;
if (!isset($this->feedList[$feedID]))
{
if (NEWSFEED_DEBUG) echo "Invalid feed number: {$feedID}<br />";
@@ -140,14 +133,14 @@ class newsfeedClass
$force = true;
}
if ($force || !isset($this->newsList[$feedID]['newsfeed_data']) || !$this->newsList[$feedID]['newsfeed_data'])
{ // No data already in memory
if ($force || !($this->newsList[$feedID]['newsfeed_data'] = $e107->ecache->retrieve(NEWSFEED_NEWS_CACHE_TAG.$feedID, $this->feedList[$feedID]['newsfeed_updateint']/60)))
if ($force || !isset($this->newsList[$feedID]['newsfeed_data']) || !$this->newsList[$feedID]['newsfeed_data']) // No data already in memory
{
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)
{
$admin_log->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);
}
require_once(e_HANDLER.'xml_class.php');
@@ -195,7 +188,7 @@ class newsfeedClass
$dbData['newsfeed_description'] = $temp['newsfeed_description'];
if ($this->useCache)
{
$e107->ecache->clear(NEWSFEED_LIST_CACHE_TAG); // Clear the newsfeed cache so its re-read next time
e107::getCache()->clear(NEWSFEED_LIST_CACHE_TAG); // Clear the newsfeed cache so its re-read next time
}
}
}
@@ -206,10 +199,10 @@ class newsfeedClass
}
else
{
$temp['newsfeed_image_link'] = "<img src='".$this->feedList[$feedID]['newsfeed_image']."' alt='' />";
$temp['newsfeed_image_link'] = !empty($newsfeed_image) ? "<img src='".$newsfeed_image."' alt='' />" : '';
}
$serializedArray = $eArrayStorage->WriteArray($temp, FALSE);
$serializedArray = e107::serialize($temp, false);
$now = time();
$this->newsList[$feedID]['newsfeed_data'] = $serializedArray;
@@ -217,17 +210,20 @@ class newsfeedClass
if ($this->useCache)
{
$e107->ecache->set(NEWSFEED_NEWS_CACHE_TAG.$feedID,$serializedArray);
e107::getCache()->set(NEWSFEED_NEWS_CACHE_TAG.$feedID, $serializedArray);
}
else
{
$dbData['newsfeed_data'] =addslashes($serializedArray);
$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(FALSE === $sql->db_UpdateArray('newsfeed', $dbData, " WHERE newsfeed_id=".$feedID))
{
$dbData['WHERE'] = "newsfeed_id=".$feedID;
if(FALSE === $sql->update('newsfeed', $dbData))
{
if (NEWSFEED_DEBUG) echo NFLAN_48."<br /><br />".var_dump($dbData);
}
@@ -254,8 +250,7 @@ class newsfeedClass
{
$tp = e107::getParser();
$sql = e107::getDb();
global $NEWSFEED_MAIN_START, $NEWSFEED_MAIN, $NEWSFEED_MAIN_END;
global $NEWSFEED_MENU_START, $NEWSFEED_MENU, $NEWSFEED_MENU_END;
@@ -272,7 +267,12 @@ class newsfeedClass
$this->readFeedList(); // Make sure we've got all the news feeds loaded
/* get template */
if (file_exists(THEME."newsfeed_menu_template.php"))
if(file_exists(THEME."templates/newsfeed/newsfeed_menu_template.php")) //v2.x
{
include(THEME."templates/newsfeed/newsfeed_menu_template.php");
}
elseif(file_exists(THEME."newsfeed_menu_template.php")) //v1.x
{
include(THEME."newsfeed_menu_template.php");
}
@@ -281,6 +281,8 @@ class newsfeedClass
include(e_PLUGIN."newsfeed/templates/newsfeed_menu_template.php");
}
$vars = array();
foreach($this->feedList as $nfID => $feed)
{
if (($filter == 0) || ($filter == $feed['newsfeed_id']))
@@ -292,10 +294,10 @@ class newsfeedClass
$numtoshow = intval($where == 'main' ? $newsfeed_showmain : $newsfeed_showmenu);
$numtoshow = ($numtoshow > 0 ? $numtoshow : 999);
$FEEDNAME = "<a href='".e_SELF."?show.{$feed['newsfeed_id']}'>".$tp->toHtml($feed['newsfeed_name'],false,'TITLE')."</a>";
$FEEDDESCRIPTION = $feed['newsfeed_description'];
$FEEDIMAGE = $rss['newsfeed_image_link'];
$FEEDLANGUAGE = $rss['channel']['language'];
$vars['FEEDNAME'] = "<a href='".e_SELF."?show.{$feed['newsfeed_id']}'>".$tp->toHtml($feed['newsfeed_name'],false,'TITLE')."</a>";
$vars['FEEDDESCRIPTION'] = $feed['newsfeed_description'];
$vars['FEEDIMAGE'] = $rss['newsfeed_image_link'];
$vars['FEEDLANGUAGE'] = $rss['channel']['language'];
if($rss['channel']['lastbuilddate'])
{
@@ -310,18 +312,18 @@ class newsfeedClass
$pubbed = NFLAN_34;
}
$FEEDLASTBUILDDATE = NFLAN_33.$pubbed;
$FEEDCOPYRIGHT = $tp -> toHTML(vartrue($rss['channel']['copyright']), FALSE);
$FEEDTITLE = "<a href='".$rss['channel']['link']."' rel='external'>".vartrue($rss['channel']['title'])."</a>";
$FEEDLINK = $rss['channel']['link'];
$vars['FEEDLASTBUILDDATE'] = NFLAN_33.$pubbed;
$vars['FEEDCOPYRIGHT'] = $tp -> toHTML(vartrue($rss['channel']['copyright']), FALSE);
$vars['FEEDTITLE'] = "<a href='".$rss['channel']['link']."' rel='external'>".vartrue($rss['channel']['title'])."</a>";
$vars['FEEDLINK'] = $rss['channel']['link'];
if($feed['newsfeed_active'] == 2 or $feed['newsfeed_active'] == 3)
{
$LINKTOMAIN = "<a href='".e_PLUGIN."newsfeed/newsfeed.php?show.".$feed['newsfeed_id']."'>".NFLAN_39."</a>";
$vars['LINKTOMAIN'] = "<a href='".e_PLUGIN."newsfeed/newsfeed.php?show.".$feed['newsfeed_id']."'>".NFLAN_39."</a>";
}
else
{
$LINKTOMAIN = "";
$vars['LINKTOMAIN'] = "";
}
$data = "";
@@ -332,42 +334,43 @@ class newsfeedClass
{
$item = $rss['items'][$i];
$FEEDITEMLINK = "<a href='".$item['link']."' rel='external'>".$tp -> toHTML($item['title'], FALSE)."</a>\n";
$FEEDITEMLINK = str_replace('&', '&amp;', $FEEDITEMLINK);
$feeditemtext = preg_replace("#\[[a-z0-9=]+\]|\[\/[a-z]+\]|\{[A-Z_]+\}#si", "", strip_tags($item['description']));
$FEEDITEMCREATOR = $tp -> toHTML(vartrue($item['author']), FALSE);
$vars['FEEDITEMLINK'] = "<a href='".$item['link']."' rel='external'>".$tp -> toHTML($item['title'], FALSE)."</a>\n";
$vars['FEEDITEMLINK'] = str_replace('&', '&amp;', $vars['FEEDITEMLINK']);
$feeditemtext = preg_replace("#\[[a-z0-9=]+\]|\[\/[a-z]+\]|\{[A-Z_]+\}#si", "", strip_tags($item['description']));
$vars['FEEDITEMCREATOR'] = $tp -> toHTML(vartrue($item['author']), FALSE);
if ($where == 'main')
{
if($NEWSFEED_COLLAPSE)
if(!empty($NEWSFEED_COLLAPSE))
{
$FEEDITEMLINK = "<a href='#' onclick='expandit(this)'>".$tp -> toHTML($item['title'], FALSE)."</a>
$vars['FEEDITEMLINK'] = "<a href='#' onclick='expandit(this)'>".$tp -> toHTML($item['title'], FALSE)."</a>
<div style='display:none' >
";
$FEEDITEMTEXT = preg_replace("/&#091;.*]/", "", $tp -> toHTML($item['description'], FALSE))."
$vars['FEEDITEMTEXT'] = preg_replace("/&#091;.*]/", "", $tp -> toHTML($item['description'], FALSE))."
<br /><br /><a href='".$item['link']."' rel='external'>".NFLAN_44."</a><br /><br />
</div>";
}
else
{
$FEEDITEMLINK = "<a href='".$item['link']."' rel='external'>".$tp -> toHTML($item['title'], FALSE)."</a>\n";
$FEEDITEMLINK = str_replace('&', '&amp;', $FEEDITEMLINK);
$feeditemtext = preg_replace("#\[[a-z0-9=]+\]|\[\/[a-z]+\]|\{[A-Z_]+\}#si", "", $item['description']);
$FEEDITEMTEXT = $tp -> toHTML($feeditemtext, FALSE)."\n";
$vars['FEEDITEMLINK'] = "<a href='".$item['link']."' rel='external'>".$tp -> toHTML($item['title'], FALSE)."</a>\n";
$vars['FEEDITEMLINK'] = str_replace('&', '&amp;', $vars['FEEDITEMLINK']);
$feeditemtext = preg_replace("#\[[a-z0-9=]+\]|\[\/[a-z]+\]|\{[A-Z_]+\}#si", "", $item['description']);
$vars['FEEDITEMTEXT'] = $tp -> toHTML($feeditemtext, FALSE)."\n";
}
$data .= preg_replace("/\{(.*?)\}/e", '$\1', $NEWSFEED_MAIN);
$data .= $tp->simpleParse( $NEWSFEED_MAIN, $vars);
}
else
{
if ($this->truncateCount)
{
$FEEDITEMTEXT = $tp->text_truncate($feeditemtext, $this->truncateCount, $this->truncateMore);
$vars['FEEDITEMTEXT'] = $tp->text_truncate($feeditemtext, $this->truncateCount, $this->truncateMore);
}
else
{
$FEEDITEMTEXT = ''; // Might just want title
$vars['FEEDITEMTEXT'] = ''; // Might just want title
}
$data .= preg_replace("/\{(.*?)\}/e", '$\1', $NEWSFEED_MENU);
$data .= $tp->simpleParse($NEWSFEED_MENU, $vars);
}
$i++;
}
@@ -376,13 +379,15 @@ class newsfeedClass
if ($where == 'main')
{
$BACKLINK = "<a href='".e_SELF."'>".NFLAN_31."</a>";
$text = preg_replace("/\{(.*?)\}/e", '$\1', $NEWSFEED_MAIN_START).$data.preg_replace("/\{(.*?)\}/e", '$\1', $NEWSFEED_MAIN_END);
$vars['BACKLINK'] = "<a href='".e_SELF."'>".NFLAN_31."</a>";
$text = $tp->simpleParse($NEWSFEED_MAIN_START, $vars).$data.$tp->simpleParse( $NEWSFEED_MAIN_END, $vars);
}
else
{
$text .= preg_replace("/\{(.*?)\}/e", '$\1', $NEWSFEED_MENU_START) . $data . preg_replace("/\{(.*?)\}/e", '$\1', $NEWSFEED_MENU_END);
$text .= $tp->simpleParse($NEWSFEED_MENU_START, $vars) . $data . $tp->simpleParse($NEWSFEED_MENU_END, $vars);
}
//TODO Move the $vars into their own shortcode class and change simpleParse to parseTemplate();
}
if($which == 'all')
@@ -391,7 +396,7 @@ class newsfeedClass
}
else
{
$ret['title'] = $feed['newsfeed_name']." ".$NEWSFEED_MAIN_CAPTION;
$ret['title'] = $feed['newsfeed_name']." ".varset($NEWSFEED_MAIN_CAPTION);
}
$ret['text'] = $text;