Skip to content

Commit

Permalink
Merge pull request #3 from reinos/master
Browse files Browse the repository at this point in the history
Added "exact" parameter
  • Loading branch information
kevincupp committed Dec 13, 2012
2 parents 1ca857e + ac9b780 commit f5ca879
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions char_limit/pi.char_limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

$plugin_info = array(
'pi_name' => 'Character Limiter',
'pi_version' => '1.1',
'pi_version' => '1.2',
'pi_author' => 'Rick Ellis',
'pi_author_url' => 'http://expressionengine.com/',
'pi_description' => 'Permits you to limit the number of characters in some text',
Expand Down Expand Up @@ -60,10 +60,13 @@ function Char_limit($str = '')

$total = ( ! $this->EE->TMPL->fetch_param('total')) ? 500 : $this->EE->TMPL->fetch_param('total');
$total = ( ! is_numeric($total)) ? 500 : $total;

//exact truncation
$exact = $this->EE->TMPL->fetch_param('exact', 'no');

$str = ($str == '') ? $this->EE->TMPL->tagdata : $str;

$this->return_data = $this->EE->functions->char_limiter($str, $total);
$this->return_data = in_array($exact, array('yes', 'y')) ? substr($str, 0, $total) : $this->EE->functions->char_limiter($str, $total);
}

// --------------------------------------------------------------------
Expand All @@ -82,15 +85,20 @@ function usage()
?>
Wrap anything you want to be processed between the tag pairs.

{exp:char_limit total="100"}
{exp:char_limit total="100" exact="no"}

text you want processed

{/exp:char_limit}

The "total" parameter lets you specify the number of characters.
The "exact" parameter will truncate the string exact to the "limit"

Note: When exact="no" this tag will always leave entire words intact so you may get a few additional characters than what you specify.

Note: This tag will always leave entire words intact so you may get a few additional characters than what you specify.
Version 1.2
******************
- Add "exact" parameter

Version 1.1
******************
Expand Down

0 comments on commit f5ca879

Please sign in to comment.