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

Update com_newsfeeds and mod_feed to use jfeed #306

Closed
wants to merge 7 commits into from
Closed
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
1 change: 1 addition & 0 deletions administrator/language/en-GB/en-GB.mod_feed.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
MOD_FEED="Feed Display"
MOD_FEED_ERR_CACHE="Please make cache directory writable"
MOD_FEED_ERR_NO_URL="No feed URL specified."
MOD_FEED_ERR_FEED_NOT_RETRIEVED="Feed not found"
MOD_FEED_FIELD_DESCRIPTION_DESC="Show the description text for the whole Feed"
MOD_FEED_FIELD_DESCRIPTION_LABEL="Feed Description"
MOD_FEED_FIELD_IMAGE_DESC="Show the image associated with the whole Feed"
Expand Down
168 changes: 27 additions & 141 deletions administrator/modules/mod_feed/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,157 +16,43 @@
* @subpackage mod_feed
* @since 1.5
*/
abstract class modFeedHelper
class modFeedHelper
{
/**
* @since 1.5
*/
public static function render($params)
static function getFeed($params)
{
// module params
$rssurl = $params->get('rssurl', '');
$rssitems = $params->get('rssitems', 5);
$rssdesc = $params->get('rssdesc', 1);
$rssimage = $params->get('rssimage', 1);
$rssitemdesc = $params->get('rssitemdesc', 1);
$words = $params->def('word_count', 0);
$rsstitle = $params->get('rsstitle', 1);
$rssrtl = $params->get('rssrtl', 0);
$moduleclass_sfx = $params->get('moduleclass_sfx', '');

$filter = JFilterInput::getInstance();
$rssurl = $params->get('rssurl', '');

// get RSS parsed object
$cache_time = 0;
if ($params->get('cache')) {
if ($params->get('cache'))
{
$cache_time = $params->get('cache_time', 15) * 60;
}

$rssDoc = JSimplepieFactory::getFeedParser($rssurl, $cache_time);

if ($rssDoc != false)
try
{
// channel header and link
$channel['title'] = $filter->clean($rssDoc->get_title());
$channel['link'] = $filter->clean($rssDoc->get_link());
$channel['description'] = $filter->clean($rssDoc->get_description());

// channel image if exists
$image['url'] = $rssDoc->get_image_url();
$image['title'] = $rssDoc->get_image_title();

//image handling
$iUrl = isset($image['url']) ? $image['url'] : null;
$iTitle = isset($image['title']) ? $image['title'] : null;

// items
$items = $rssDoc->get_items();

// feed elements
$items = array_slice($items, 0, $rssitems);
?>
<table cellpadding="0" cellspacing="0" class="moduletable<?php echo htmlspecialchars($params->get('moduleclass_sfx')); ?>">
<?php
// feed description
if (!is_null($channel['title']) && $rsstitle) {
?>
<tr>
<td>
<strong>
<a href="<?php echo htmlspecialchars(str_replace('&', '&amp;', $channel['link'])); ?>" target="_blank">
<?php echo htmlspecialchars($channel['title']); ?></a>
</strong>
</td>
</tr>
<?php
}

// feed description
if ($rssdesc) {
?>
<tr>
<td>
<?php echo $channel['description']; ?>
</td>
</tr>
<?php
}

// feed image
if ($rssimage && $iUrl) {
?>
<tr>
<td align="center">
<img src="<?php echo htmlspecialchars($iUrl); ?>"
alt="<?php echo htmlspecialchars(@$iTitle); ?>"/>
</td>
</tr>
<?php
}

$actualItems = count($items);
$setItems = $rssitems;

if ($setItems > $actualItems) {
$totalItems = $actualItems;
} else {
$totalItems = $setItems;
}
?>
<tr>
<td>
<ul class="newsfeed<?php echo htmlspecialchars($moduleclass_sfx); ?>" >
<?php
for ($j = 0; $j < $totalItems; $j ++)
{
$currItem = & $items[$j];
// item title
?>
<li>
<?php
if (!is_null($currItem->get_link())) {
?>
<a href="<?php echo htmlspecialchars($currItem->get_link()); ?>" target="_child">
<?php echo htmlspecialchars($currItem->get_title()); ?></a>
<?php
}

// item description
if ($rssitemdesc)
{
// item description
$text = $filter->clean(html_entity_decode($currItem->get_description(), ENT_COMPAT, 'UTF-8'));
$text = str_replace('&apos;', "'", $text);

// word limit check
if ($words) {
$texts = explode(' ', $text);
$count = count($texts);
if ($count > $words) {
$text = '';
for ($i = 0; $i < $words; $i ++)
{
$text .= ' '.$texts[$i];
}
$text .= '...';
}
}
?>
<div style="text-align: <?php echo $rssrtl ? 'right': 'left'; ?> !important">
<?php echo $text; ?>
</div>
<?php
}
?>
</li>
<?php
}
?>
</ul>
</td>
</tr>
</table>
<?php
jimport('joomla.feed.factory');
$feed = new JFeedFactory;
$rssDoc = $feed->getFeed($rssurl);
}
catch (InvalidArgumentException $e)
{
$msg = JText::_('MOD_NEWSFEEDS_ERRORS_FEED_NOT_RETRIEVED');
}
catch (RunTimeException $e)
{
$msg = JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
}
if (empty($rssDoc))
{
$msg = JText::_('MOD_FEED_ERR_FEED_NOT_RETRIEVED');
return $msg;
}
$lists = array();
if ($rssDoc)
{
return $rssDoc;
}
}
}
15 changes: 4 additions & 11 deletions administrator/modules/mod_feed/mod_feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@
$rssurl = $params->get('rssurl', '');
$rssrtl = $params->get('rssrtl', 0);

//check if cache diretory is writable as cache files will be created for the feed
$cacheDir = JPATH_CACHE;
if (!is_writable($cacheDir))
{
echo '<div>';
echo JText::_('MOD_FEED_ERR_CACHE');
echo '</div>';
return;
}

//check if feed URL has been set
if (empty ($rssurl))
{
Expand All @@ -34,4 +24,7 @@
return;
}

require JModuleHelper::getLayoutPath('mod_feed');
$feed = modFeedHelper::getFeed($params);
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));

require JModuleHelper::getLayoutPath('mod_feed', $params->get('layout', 'default'));
114 changes: 111 additions & 3 deletions administrator/modules/mod_feed/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,114 @@
defined('_JEXEC') or die;
?>

<div style="direction: <?php echo $rssrtl ? 'rtl' :'ltr'; ?>; text-align: <?php echo $rssrtl ? 'right' :'left'; ?>">
<?php echo modFeedHelper::render($params); ?>
</div>
<?php
if (is_string($feed))
{
echo $feed;
}
else
{
$lang = JFactory::getLanguage();
$myrtl = $params->get('rssrtl');
$direction = " ";
if ($lang->isRTL() && $myrtl == 0)
{
$direction = " redirect-rtl";
}

// feed description
elseif ($lang->isRTL() && $myrtl == 1)
{
$direction = " redirect-ltr";
}

elseif ($lang->isRTL() && $myrtl == 2)
{
$direction = " redirect-rtl";
}

elseif ($myrtl == 0)
{
$direction = " redirect-ltr";
}
elseif ($myrtl == 1)
{
$direction = " redirect-ltr";
}
elseif ($myrtl == 2)
{
$direction = " redirect-rtl"; }
?>
<?php
if ($feed != false)
{
//image handling
$iUrl = isset($feed->image) ? $feed->image : null;
$iTitle = isset($feed->imagetitle) ? $feed->imagetitle : null;
?>
<div style="direction: <?php echo $rssrtl ? 'rtl' :'ltr'; ?>; text-align: <?php echo $rssrtl ? 'right' :'left'; ?> ! important" class="feed<?php echo $moduleclass_sfx; ?>">
<?php
// feed description
if (!is_null($feed->title) && $params->get('rsstitle', 1))
{
?>
<h2 class="<?php echo $direction; ?>">
<a href="<?php echo str_replace('&', '&amp', $feed->link); ?>" target="_blank">
<?php echo $feed->title; ?></a>
</h2>
<?php
}
// feed description
if ($params->get('rssdesc', 1)) {
?>
<?php echo $feed->description; ?>
<?php
}
// feed image
if ($params->get('rssimage', 1) && $iUrl) :
?>
<img src="<?php echo $iUrl; ?>" alt="<?php echo @$iTitle; ?>"/>

<?php endif; ?>

<ul class="newsfeed<?php echo $params->get('moduleclass_sfx'); ?>">
<!-- Show items -->
<?php if (!empty($feed))
{ ?>
<ul>
<?php for ($i = 0; $i < $params->get('rssitems', 5); $i++)
{ ?>
<?php
$uri = (!empty($feed[$i]->guid) || !is_null($feed[$i]->guid)) ? $feed[$i]->guid : $feed[$i]->uri;

$uri = substr($uri, 0, 4) != 'http' ? $params->get('rsslink') : $uri;
$text = !empty($feed[$i]->content) || !is_null($feed[$i]->content) ? $feed[$i]->content : $feed[$i]->description;

?>
<li>
<?php if (!empty($uri)) : ?>
<h5 class="feed-link">
<a href="<?php echo $uri; ?>" target="_blank">
<?php echo $feed[$i]->title; ?></a></h5>
<?php else : ?>
<h5 class="feed-link"><?php echo $feed[$i]->title; ?></h5>
<?php endif; ?>

<?php if ($params->get('rssitemdesc') && !empty($text)) : ?>
<div class="feed-item-description">
<?php
// Strip the images.
$text = JFilterOutput::stripImages($text);

$text = JHtml::_('string.truncate', $text, $params->get('word_count'));
echo str_replace('&apos;', "'", $text);
?>

</div>
<?php endif; ?>
</li>
<?php } ?>
</ul>
<?php }
}
}
Loading