Skip to content

Commit

Permalink
Solve word count bug in mod_feed + some code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels van der Veer (n9iels) committed Nov 1, 2015
1 parent e0fc0c2 commit 877e7c4
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 140 deletions.
4 changes: 2 additions & 2 deletions language/en-GB/en-GB.mod_feed.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ MOD_FEED_FIELD_RSSURL_DESC="Enter the URL of the RSS/RDF/ATOM feed."
MOD_FEED_FIELD_RSSURL_LABEL="Feed URL"
MOD_FEED_FIELD_RTL_DESC="Display feed in RTL direction."
MOD_FEED_FIELD_RTL_LABEL="RTL Feed"
MOD_FEED_FIELD_WORDCOUNT_DESC="Allows you to limit the amount of visible Item description text. 0 will show all the text."
MOD_FEED_FIELD_WORDCOUNT_LABEL="Word Count"
MOD_FEED_FIELD_WORDCOUNT_DESC="Allows you to limit the amount of characters visible in the item description text. 0 will show all the text."
MOD_FEED_FIELD_WORDCOUNT_LABEL="Character Count"
MOD_FEED_XML_DESCRIPTION="This module allows the displaying of a syndicated feed."
15 changes: 1 addition & 14 deletions modules/mod_feed/mod_feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@
// Include the syndicate functions only once
require_once __DIR__ . '/helper.php';

$rssurl = $params->get('rssurl', '');
$rssrtl = $params->get('rssrtl', 0);

// Check if feed URL has been set
if (empty ($rssurl))
{
echo '<div>';
echo JText::_('MOD_FEED_ERR_NO_URL');
echo '</div>';

return;
}

$feed = ModFeedHelper::getFeed($params);
$feed = ModFeedHelper::getFeed($params);
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));

require JModuleHelper::getLayoutPath('mod_feed', $params->get('layout', 'default'));
82 changes: 44 additions & 38 deletions modules/mod_feed/mod_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,113 +30,119 @@
required="true"
validate="url"
label="MOD_FEED_FIELD_RSSURL_LABEL"
description="MOD_FEED_FIELD_RSSURL_DESC" />
description="MOD_FEED_FIELD_RSSURL_DESC"
/>

<field
name="rssrtl"
type="radio"
class="btn-group btn-group-yesno"
default="0"
label="MOD_FEED_FIELD_RTL_LABEL"
description="MOD_FEED_FIELD_RTL_DESC">
<option
value="1">JYES</option>
<option
value="0">JNO</option>
description="MOD_FEED_FIELD_RTL_DESC"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>

<field
name="rsstitle"
type="radio"
class="btn-group btn-group-yesno"
default="1"
label="MOD_FEED_FIELD_RSSTITLE_LABEL"
description="MOD_FEED_FIELD_RSSTITLE_DESC">
<option
value="1">JYES</option>
<option
value="0">JNO</option>
description="MOD_FEED_FIELD_RSSTITLE_DESC"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>

<field
name="rssdesc"
type="radio"
class="btn-group btn-group-yesno"
default="1"
label="MOD_FEED_FIELD_DESCRIPTION_LABEL"
description="MOD_FEED_FIELD_DESCRIPTION_DESC">
<option
value="1">JYES</option>
<option
value="0">JNO</option>
description="MOD_FEED_FIELD_DESCRIPTION_DESC"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>

<field
name="rssimage"
type="radio"
class="btn-group btn-group-yesno"
default="1"
label="MOD_FEED_FIELD_IMAGE_LABEL"
description="MOD_FEED_FIELD_IMAGE_DESC">
<option
value="1">JYES</option>
<option
value="0">JNO</option>
description="MOD_FEED_FIELD_IMAGE_DESC"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>

<field
name="rssitems"
type="text"
default="3"
label="MOD_FEED_FIELD_ITEMS_LABEL"
description="MOD_FEED_FIELD_ITEMS_DESC" />
description="MOD_FEED_FIELD_ITEMS_DESC"
/>

<field
name="rssitemdesc"
type="radio"
class="btn-group btn-group-yesno"
default="1"
label="MOD_FEED_FIELD_ITEMDESCRIPTION_LABEL"
description="MOD_FEED_FIELD_ITEMDESCRIPTION_DESC">
<option
value="1">JYES</option>
<option
value="0">JNO</option>
description="MOD_FEED_FIELD_ITEMDESCRIPTION_DESC"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>

<field
name="word_count"
type="text"
size="6"
default="0"
label="MOD_FEED_FIELD_WORDCOUNT_LABEL"
description="MOD_FEED_FIELD_WORDCOUNT_DESC" />
description="MOD_FEED_FIELD_WORDCOUNT_DESC"
/>
</fieldset>
<fieldset
name="advanced">
<fieldset name="advanced">
<field
name="layout"
type="modulelayout"
label="JFIELD_ALT_LAYOUT_LABEL"
description="JFIELD_ALT_MODULE_LAYOUT_DESC" />
description="JFIELD_ALT_MODULE_LAYOUT_DESC"
/>

<field
name="moduleclass_sfx"
type="textarea" rows="3"
label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL"
description="COM_MODULES_FIELD_MODULECLASS_SFX_DESC" />
description="COM_MODULES_FIELD_MODULECLASS_SFX_DESC"
/>

<field
name="cache"
type="list"
default="1"
label="COM_MODULES_FIELD_CACHING_LABEL"
description="COM_MODULES_FIELD_CACHING_DESC">
<option
value="1">JGLOBAL_USE_GLOBAL</option>
<option
value="0">COM_MODULES_FIELD_VALUE_NOCACHING</option>
description="COM_MODULES_FIELD_CACHING_DESC"
>
<option value="1">JGLOBAL_USE_GLOBAL</option>
<option value="0">COM_MODULES_FIELD_VALUE_NOCACHING</option>
</field>

<field
name="cache_time"
type="text"
default="900"
label="COM_MODULES_FIELD_CACHE_TIME_LABEL"
description="COM_MODULES_FIELD_CACHE_TIME_DESC" />
description="COM_MODULES_FIELD_CACHE_TIME_DESC"
/>
</fieldset>
</fields>
</config>
Expand Down
150 changes: 64 additions & 86 deletions modules/mod_feed/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,111 +17,89 @@
}
else
{
$lang = JFactory::getLanguage();
$myrtl = $params->get('rssrtl');
$direction = " ";
$lang = JFactory::getLanguage();
$myrtl = $params->get('rssrtl');
$direction = "";

// Set feed to RTL if parameter is set
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)
else
{
$direction = " redirect-rtl";
}
?>

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 htmlspecialchars($rssurl); ?>" target="_blank">
<?php echo $feed->title; ?></a>
</h2>
<?php
}
// Feed description
if ($params->get('rssdesc', 1))
{
?>
<div style="direction: <?php echo $rssrtl ? 'rtl' :'ltr'; ?>; text-align: <?php echo $rssrtl ? 'right' :'left'; ?> ! important"
class="feed<?php echo $moduleclass_sfx; ?>">
<?php if (!is_null($feed->title) && $params->get('rsstitle', 1)) : ?>
<h2 class="<?php echo $direction; ?>">
<a href="<?php echo htmlspecialchars($rssurl); ?>" target="_blank">
<?php echo $feed->title; ?>
</a>
</h2>
<?php endif; ?>

<?php 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; ?>

<!-- Feed image -->
<?php
$iUrl = isset($feed->image) ? $feed->image : null;

<!-- Show items -->
<?php if (!empty($feed))
{ ?>
<ul class="newsfeed<?php echo $params->get('moduleclass_sfx'); ?>">
<?php for ($i = 0; $i < $params->get('rssitems', 5); $i++)
if ($params->get('rssimage', 1) && $iUrl)
{
if (!$feed->offsetExists($i))
{
break;
}
?>
<?php
$uri = (!empty($feed[$i]->uri) || !is_null($feed[$i]->uri)) ? $feed[$i]->uri : $feed[$i]->guid;
$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;
$iTitle = isset($feed->imagetitle) ? $feed->imagetitle : null;
?>
<li>
<?php if (!empty($uri)) : ?>
<span class="feed-link">
<a href="<?php echo htmlspecialchars($uri); ?>" target="_blank">
<?php echo $feed[$i]->title; ?></a></span>
<?php else : ?>
<span class="feed-link"><?php echo $feed[$i]->title; ?></span>
<?php endif; ?>
<img src="<?php echo $iUrl; ?>" alt="<?php echo @$iTitle; ?>"/>
<?php } ?>

<?php if ($params->get('rssitemdesc') && !empty($text)) : ?>
<div class="feed-item-description">
<?php
// Strip the images.
$text = JFilterOutput::stripImages($text);
<!-- Show items -->
<?php if (!empty($feed)) : ?>
<ul class="newsfeed<?php echo $params->get('moduleclass_sfx'); ?>">
<?php for ($i = 0; $i < $params->get('rssitems', 5); $i++) :
if (!$feed->offsetExists($i)) :
break;
endif;

$text = JHtml::_('string.truncate', $text, $params->get('word_count'));
echo str_replace('&apos;', "'", $text);
?>
</div>
<?php endif; ?>
</li>
<?php } ?>
</ul>
<?php } ?>
$uri = (!empty($feed[$i]->uri) || !is_null($feed[$i]->uri)) ? $feed[$i]->uri : $feed[$i]->guid;
$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)) : ?>
<span class="feed-link">
<a href="<?php echo htmlspecialchars($uri); ?>" target="_blank">
<?php echo $feed[$i]->title; ?>
</a>
</span>
<?php else : ?>
<span class="feed-link">
<?php echo $feed[$i]->title; ?>
</span>
<?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', strip_tags($text), $params->get('word_count'));

echo str_replace('&apos;', "'", $text);
?>
</div>
<?php endif; ?>
</li>
<?php endfor; ?>
</ul>
<?php endif; ?>
</div>
<?php }
}
<?php } ?>

0 comments on commit 877e7c4

Please sign in to comment.