Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mantis 18456 - bootstrap theme not using the updated community rss feed code #116

Merged
merged 2 commits into from
Dec 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions public_html/lists/admin/communityfeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Build the news <ul> element from the rss feed items.
*
* @param ONYX_RSS $rss onyx-rss instance
* @param int $max the maximum number of feed items to return
*
* @return string the generated html or an empty string
*/
function buildNews($rss, $max)
{
if ($rss->numItems() == 0) {
return '';
}

$news = '';
$count = 0;
// reset index so that feed items can be processed more than once
$rss->rss['output_index'] = -1;

while ($item = $rss->getNextItem()) {
$count++;

if ($count > $max) {
break;
}
$date = $item['pubdate'];
$date = str_replace('00:00:00 +0000', '', $date);
$date = str_replace('00:00:00 +0100', '', $date);
$date = str_replace('+0000', '', $date);
if (preg_match('/\d+:\d+:\d+/', $date, $regs)) {
$date = str_replace($regs[0], '', $date);
}

## remove the '<p>&nbsp;</p>' in the descriptions
$desc = $item['description'];
$desc = str_replace('<p>&nbsp;</p>', '', $desc);
$desc = '';

$news .= '<li>
<div class="publisheddate">'.$date.'</div> <a href="'.$item['link'].'?utm_source=phplist-'.VERSION.'&utm_medium=newspanel&utm_content='.urlencode($item['title']).'&utm_campaign=newspanel" target="_blank">'.$item['title'].'</a>
'.$desc.'
</li>';
}

return "<ul>$news</ul>";
}

/**
* Generate the short and long community news lists from an rss feed then cache
* in the session.
*/
$newsSize = 'long';

if (empty($_SESSION['adminloggedin'])
|| (isset($_GET['page']) && !in_array($_GET['page'], array('home', 'about', 'dashboard', 'community','login')))) {
$newsSize = 'short';
}

if (isset($_SESSION['communitynews'][$newsSize])) {
echo $_SESSION['communitynews'][$newsSize];

return;
}

include 'onyxrss/onyx-rss.php';
$onyxRss = new ONYX_RSS();

if (!DEVVERSION) {
$onyxRss->setDebugMode(false);
}
$onyxRss->setCachePath($GLOBALS['tmpdir']);
$onyxRss->setExpiryTime(1440);
$parseresult = $onyxRss->parse('https://www.phplist.org/newslist/feed/', 'phplistnews');

if ($parseresult) {
$_SESSION['communitynews']['short'] = buildNews($onyxRss, 3);
$_SESSION['communitynews']['long'] = buildNews($onyxRss, 10);
} else {
$_SESSION['communitynews']['short'] = '';
$_SESSION['communitynews']['long'] = '';
}

echo $_SESSION['communitynews'][$newsSize];
Loading