From 7ff5ee351507ce85a89f99978678c93e77a0caba Mon Sep 17 00:00:00 2001 From: Reinos Date: Sat, 8 Dec 2012 14:41:08 +0100 Subject: [PATCH 1/3] Add Exact parameter Add "exact" parameter to truncate the string to the given limit. This will bypass the normal behaviour that will not cut words. --- char_limit/pi.char_limit.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/char_limit/pi.char_limit.php b/char_limit/pi.char_limit.php index 4661a1c..cdc3c9d 100644 --- a/char_limit/pi.char_limit.php +++ b/char_limit/pi.char_limit.php @@ -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('total', '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); } // -------------------------------------------------------------------- @@ -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 ****************** From adca3a7a4ec5eae8a4e3bb1b06f789171f20df59 Mon Sep 17 00:00:00 2001 From: Reinos Date: Sat, 8 Dec 2012 14:43:17 +0100 Subject: [PATCH 2/3] Typo fetching param --- char_limit/pi.char_limit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/char_limit/pi.char_limit.php b/char_limit/pi.char_limit.php index cdc3c9d..f9cfb11 100644 --- a/char_limit/pi.char_limit.php +++ b/char_limit/pi.char_limit.php @@ -62,7 +62,7 @@ function Char_limit($str = '') $total = ( ! is_numeric($total)) ? 500 : $total; //exact truncation - $exact = $this->EE->TMPL->fetch_param('total', 'no'); + $exact = $this->EE->TMPL->fetch_param('exact', 'no'); $str = ($str == '') ? $this->EE->TMPL->tagdata : $str; From ac9b780fe433cf1cb405f00c41d2c69e2a788f91 Mon Sep 17 00:00:00 2001 From: Reinos Date: Sat, 8 Dec 2012 14:56:04 +0100 Subject: [PATCH 3/3] Add new version number --- char_limit/pi.char_limit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/char_limit/pi.char_limit.php b/char_limit/pi.char_limit.php index f9cfb11..51ccf29 100644 --- a/char_limit/pi.char_limit.php +++ b/char_limit/pi.char_limit.php @@ -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',