Commit 87c002d5 by Qiang Xue

Fixes #6207: Added support for truncating HTML strings using…

Fixes #6207: Added support for truncating HTML strings using `StringHelper::truncate()` and `StringHelper::truncateWords()`
parent b2797b03
......@@ -58,6 +58,7 @@ Yii Framework 2 Change Log
- Enh #5954: `yii message` command now shows user friendly error if it's not able to parse source file (samdark)
- Enh #5983: Added `Inflector::sentence()` (pana1990, qiangxue)
- Enh #6113: Improved debugger configuration and request UI (schmunk42)
- Enh #6207: Added support for truncating HTML strings using `StringHelper::truncate()` and `StringHelper::truncateWords()` (Alex-Code)
- Enh: `Console::confirm()` now uses `Console::stdout()` instead of `echo` to be consistent with all other functions (cebe)
- Enh: `yii\rbac\DbManager` migration now uses database component specified in component settings instead of always using default `db` (samdark)
- Enh: Added `yii\base\Controller::renderContent()` (qiangxue)
......
......@@ -98,7 +98,7 @@ class BaseStringHelper
* @param integer $length How many characters from original string to include into truncated string.
* @param string $suffix String to append to the end of truncated string.
* @param string $encoding The charset to use, defaults to charset currently used by application.
* @param boolean $asHtml If the string contains HTML set this to true to preserve it.
* @param boolean $asHtml Whether to treat the string being truncated as HTML and preserve proper HTML tags
* @return string the truncated string.
*/
public static function truncate($string, $length, $suffix = '...', $encoding = null, $asHtml = false)
......@@ -120,7 +120,7 @@ class BaseStringHelper
* @param string $string The string to truncate.
* @param integer $count How many words from original string to include into truncated string.
* @param string $suffix String to append to the end of truncated string.
* @param boolean $asHtml If the string contains HTML set this to true to preserve it.
* @param boolean $asHtml Whether to treat the string being truncated as HTML and preserve proper HTML tags
* @return string the truncated string.
*/
public static function truncateWords($string, $count, $suffix = '...', $asHtml = false)
......@@ -143,10 +143,10 @@ class BaseStringHelper
* @param string $string The string to truncate
* @param integer $count
* @param string $suffix String to append to the end of the truncated string.
* @param string $encoding
* @param string|boolean $encoding
* @return string
*/
private static function truncateHtml($string, $count, $suffix, $encoding = false)
protected static function truncateHtml($string, $count, $suffix, $encoding = false)
{
$config = \HTMLPurifier_Config::create(null);
$lexer = \HTMLPurifier_Lexer::create($config);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment