Skip to content

Commit

Permalink
# Added new by reference parameter to stripandcut helper function, to
Browse files Browse the repository at this point in the history
indicate length of text before cutting but after stripping the HTML tags
  • Loading branch information
ggppdk committed May 8, 2015
1 parent 16179b0 commit 38228f7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
4 changes: 3 additions & 1 deletion admin/views/item/view.html.php
Expand Up @@ -182,6 +182,7 @@ function display( $tpl = null )
}

// Add a preview button for LATEST version of the item
$_sh404sef = JPluginHelper::isEnabled('system', 'sh404sef');
if ( $cid )
{
// Domain URL and autologin vars
Expand All @@ -194,7 +195,8 @@ function display( $tpl = null )
if ( $isAdmin ) JFactory::$application = JApplication::getInstance('site');

// Create the URL
$item_url = JRoute::_(FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $categories[$item->catid]->slug) . $autologin );
$item_url = FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $categories[$item->catid]->slug) . $autologin;
$item_url = $_sh404sef ? $item_url : JRoute::_($item_url); // Non SEF url if SH404SEF is installed

// Check if we are in the backend again
// In backend we need to remove administrator from URL as it is added even though we've set the application to the site app
Expand Down
6 changes: 3 additions & 3 deletions site/classes/flexicontent.helper.php
Expand Up @@ -1165,7 +1165,7 @@ static function dataFilter( $v, $maxlength=0, $validation='string', $check_calla
* @return string
* @since 1.5
*/
static function striptagsandcut( $text, $chars=null )
static function striptagsandcut( $text, $chars=null, &$uncut_length=0 )
{
// Convert html entities to characters so that they will not be removed ... by strip_tags
$text = html_entity_decode ($text, ENT_NOQUOTES, 'UTF-8');
Expand Down Expand Up @@ -1194,11 +1194,11 @@ static function striptagsandcut( $text, $chars=null )
$cleantext = preg_replace('/[\p{Z}\s]{2,}/u', ' ', $cleantext); // Unicode safe whitespace replacing

// Calculate length according to UTF-8 encoding
$length = JString::strlen($cleantext);
$uncut_length = JString::strlen($cleantext);

// Cut off the text if required but reencode html entities before doing so
if ($chars) {
if ($length > $chars) {
if ($uncut_length > $chars) {
$cleantext = JString::substr( $cleantext, 0, $chars ).'...';
}
}
Expand Down
4 changes: 2 additions & 2 deletions site/templates/blog/category.xml
Expand Up @@ -43,7 +43,7 @@
<option value="">FLEXI_USE_GLOBAL</option>
<option value="0">FLEXI_NO</option>
<option value="1">FLEXI_YES_FORCE_READ_MORE</option>
<option value="2">FLEXI_YES</option>
<option value="2">FLEXI_YES_IF_NEEDED</option>
</field>
<field name="lead_cut_text" type="text" size="4" default="" label="FLEXI_CUT_INTRO" description="FLEXI_CUT_INTRO_DESC" />
<field name="leadingitems_img_sep" type="separator" hr="false" default="FLEXI_IMAGE" description="FLEXI_IMAGE_DESC" level="level2" menu="hide" />
Expand Down Expand Up @@ -115,7 +115,7 @@
<option value="">FLEXI_USE_GLOBAL</option>
<option value="0">FLEXI_NO</option>
<option value="1">FLEXI_YES_FORCE_READ_MORE</option>
<option value="2">FLEXI_YES</option>
<option value="2">FLEXI_YES_IF_NEEDED</option>
</field>
<field name="intro_cut_text" type="text" size="4" default="" label="FLEXI_CUT_INTRO" description="FLEXI_CUT_INTRO_DESC" />
<field name="introitems_img_sep" type="separator" hr="false" default="FLEXI_IMAGE" description="FLEXI_IMAGE_DESC" level="level2" menu="hide" />
Expand Down
17 changes: 11 additions & 6 deletions site/templates/blog/category_items.php
Expand Up @@ -120,6 +120,11 @@
// ONLY FIRST PAGE has leading content items
if ($this->limitstart != 0) $leadnum = 0;

$lead_cut_text = $this->params->get('lead_cut_text', 400);
$intro_cut_text = $this->params->get('intro_cut_text', 200);
$uncut_length = 0;
FlexicontentFields::getFieldDisplay($items, 'text', $values=null, $method='display'); // Render 'text' (description) field for all items

if ($leadnum) :
//added to intercept more columns (see also css changes)
$lead_cols = $this->params->get('lead_cols', 2);
Expand Down Expand Up @@ -331,9 +336,9 @@
<?php endif; ?>
<p>
<?php
FlexicontentFields::getFieldDisplay($item, 'text', $values=null, $method='display');
//FlexicontentFields::getFieldDisplay($item, 'text', $values=null, $method='display');
if ($this->params->get('lead_strip_html', 1)) :
echo flexicontent_html::striptagsandcut( $item->fields['text']->display, $this->params->get('lead_cut_text', 400) );
echo flexicontent_html::striptagsandcut( $item->fields['text']->display, $lead_cut_text, $uncut_length );
else :
echo $item->fields['text']->display;
endif;
Expand Down Expand Up @@ -397,7 +402,7 @@

<?php
$readmore_forced = $this->params->get('show_readmore', 1) == -1 || $this->params->get('lead_strip_html', 1) == 1 ;
$readmore_shown = $this->params->get('show_readmore', 1) && strlen(trim($item->fulltext)) >= 1;
$readmore_shown = $this->params->get('show_readmore', 1) && ($uncut_length > $lead_cut_text || strlen(trim($item->fulltext)) >= 1);
$readmore_shown = $readmore_shown || $readmore_forced;
$footer_shown = $readmore_shown || $item->event->afterDisplayContent;
?>
Expand Down Expand Up @@ -646,9 +651,9 @@
<?php endif; ?>
<p>
<?php
FlexicontentFields::getFieldDisplay($item, 'text', $values=null, $method='display');
//FlexicontentFields::getFieldDisplay($item, 'text', $values=null, $method='display');
if ($this->params->get('intro_strip_html', 1)) :
echo flexicontent_html::striptagsandcut( $item->fields['text']->display, $this->params->get('intro_cut_text', 200) );
echo flexicontent_html::striptagsandcut( $item->fields['text']->display, $intro_cut_text, $uncut_length );
else :
echo $item->fields['text']->display;
endif;
Expand Down Expand Up @@ -713,7 +718,7 @@

<?php
$readmore_forced = $this->params->get('show_readmore', 1) == -1 || $this->params->get('intro_strip_html', 1) == 1 ;
$readmore_shown = $this->params->get('show_readmore', 1) && strlen(trim($item->fulltext)) >= 1;
$readmore_shown = $this->params->get('show_readmore', 1) && ($uncut_length > $intro_cut_text || strlen(trim($item->fulltext)) >= 1);
$readmore_shown = $readmore_shown || $readmore_forced;
$footer_shown = $readmore_shown || $item->event->afterDisplayContent;
?>
Expand Down
17 changes: 11 additions & 6 deletions site/templates/blog/category_items_html5.php
Expand Up @@ -121,6 +121,11 @@
// ONLY FIRST PAGE has leading content items
if ($this->limitstart != 0) $leadnum = 0;

$lead_cut_text = $this->params->get('lead_cut_text', 400);
$intro_cut_text = $this->params->get('intro_cut_text', 200);
$uncut_length = 0;
FlexicontentFields::getFieldDisplay($items, 'text', $values=null, $method='display'); // Render 'text' (description) field for all items

if ($leadnum) :
//added to intercept more columns (see also css changes)
$lead_cols = $this->params->get('lead_cols', 2);
Expand Down Expand Up @@ -344,9 +349,9 @@
<?php endif; ?>
<p>
<?php
FlexicontentFields::getFieldDisplay($item, 'text', $values=null, $method='display');
//FlexicontentFields::getFieldDisplay($item, 'text', $values=null, $method='display');
if ($this->params->get('lead_strip_html', 1)) :
echo flexicontent_html::striptagsandcut( $item->fields['text']->display, $this->params->get('lead_cut_text', 400) );
echo flexicontent_html::striptagsandcut( $item->fields['text']->display, $lead_cut_text, $uncut_length );
else :
echo $item->fields['text']->display;
endif;
Expand Down Expand Up @@ -410,7 +415,7 @@

<?php
$readmore_forced = $this->params->get('show_readmore', 1) == -1 || $this->params->get('lead_strip_html', 1) == 1 ;
$readmore_shown = $this->params->get('show_readmore', 1) && strlen(trim($item->fulltext)) >= 1;
$readmore_shown = $this->params->get('show_readmore', 1) && ($uncut_length > $lead_cut_text || strlen(trim($item->fulltext)) >= 1);
$readmore_shown = $readmore_shown || $readmore_forced;
$footer_shown = $readmore_shown || $item->event->afterDisplayContent;
?>
Expand Down Expand Up @@ -687,9 +692,9 @@
<?php endif; ?>
<p>
<?php
FlexicontentFields::getFieldDisplay($item, 'text', $values=null, $method='display');
//FlexicontentFields::getFieldDisplay($item, 'text', $values=null, $method='display');
if ($this->params->get('intro_strip_html', 1)) :
echo flexicontent_html::striptagsandcut( $item->fields['text']->display, $this->params->get('intro_cut_text', 200) );
echo flexicontent_html::striptagsandcut( $item->fields['text']->display, $intro_cut_text, $uncut_length );
else :
echo $item->fields['text']->display;
endif;
Expand Down Expand Up @@ -754,7 +759,7 @@

<?php
$readmore_forced = $this->params->get('show_readmore', 1) == -1 || $this->params->get('intro_strip_html', 1) == 1 ;
$readmore_shown = $this->params->get('show_readmore', 1) && strlen(trim($item->fulltext)) >= 1;
$readmore_shown = $this->params->get('show_readmore', 1) && ($uncut_length > $intro_cut_text || strlen(trim($item->fulltext)) >= 1);
$readmore_shown = $readmore_shown || $readmore_forced;
$footer_shown = $readmore_shown || $item->event->afterDisplayContent;
?>
Expand Down
3 changes: 2 additions & 1 deletion site/templates/blog/language/en-GB/en-GB.ini
Expand Up @@ -5,4 +5,5 @@ FLEXI_TEMPLATE_HTML_MODE="HTML Version"
FLEXI_HTML_MODE="Choose HTML version"
FLEXI_HTML_MODE_DESC="Choose between xhtml or html5."
FLEXI_XHTML="xhtml"
FLEXI_HTML5="html5"
FLEXI_HTML5="html5"
FLEXI_YES_IF_NEEDED="Yes, if needed"

0 comments on commit 38228f7

Please sign in to comment.