'getSummary 개선' 추가 적용

This commit is contained in:
conory 2017-05-22 23:16:31 +09:00
parent 855e4ce9f1
commit eb339c8101
3 changed files with 45 additions and 53 deletions

View file

@ -416,30 +416,22 @@ class commentItem extends Object
*/ */
function getSummary($str_size = 50, $tail = '...') function getSummary($str_size = 50, $tail = '...')
{ {
$content = $this->getContent(FALSE, FALSE);
// for newline, insert a blank.
$content = preg_replace('!(<br[\s]*/{0,1}>[\s]*)+!is', ' ', $content);
// replace tags such as </p> , </div> , </li> by blanks.
$content = str_replace(array('</p>', '</div>', '</li>', '-->'), ' ', $content);
// Remove tags // Remove tags
$content = preg_replace('!<([^>]*?)>!is', '', $content); $content = strip_tags($this->getContent(false, false));
// replace < , >, " // Convert temporarily html entity for truncate
$content = str_replace(array('&lt;', '&gt;', '&quot;', '&nbsp;'), array('<', '>', '"', ' '), $content); $content = html_entity_decode($content, ENT_QUOTES);
// delete a series of blanks // Replace unicode whitespace characters (no-break space)
$content = preg_replace('/ ( +)/is', ' ', $content); $content = utf8_normalize_spaces($content);
// truncate strings // Replace all whitespaces to single space
$content = trim(cut_str($content, $str_size, $tail)); $content = trim(preg_replace('/\s+/', ' ', $content));
// restore >, <, , "\ // Truncate string
$content = str_replace(array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $content); $content = cut_str($content, $str_size, $tail);
return $content; return escape($content);
} }
function getRegdate($format = 'Y.m.d H:i:s', $conversion = true) function getRegdate($format = 'Y.m.d H:i:s', $conversion = true)

View file

@ -447,22 +447,22 @@ class content extends WidgetHandler
function _getSummary($content, $str_size = 50) function _getSummary($content, $str_size = 50)
{ {
$content = preg_replace('!(<br[\s]*/{0,1}>[\s]*)+!is', ' ', $content); // Remove tags
// Replace tags such as </p> , </div> , </li> and others to a whitespace $content = strip_tags($content);
$content = str_replace(array('</p>', '</div>', '</li>'), ' ', $content);
// Remove Tag // Convert temporarily html entity for truncate
$content = preg_replace('!<([^>]*?)>!is','', $content); $content = html_entity_decode($content, ENT_QUOTES);
// Replace tags to <, >, " and whitespace
$content = str_replace(array('&lt;','&gt;','&quot;','&nbsp;'), array('<','>','"',' '), $content); // Replace unicode whitespace characters (no-break space)
// Delete a series of whitespaces $content = utf8_normalize_spaces($content);
$content = preg_replace('/ ( +)/is', ' ', $content);
// Replace all whitespaces to single space
$content = trim(preg_replace('/\s+/', ' ', $content));
// Truncate string // Truncate string
$content = trim(cut_str($content, $str_size, $tail)); $content = cut_str($content, $str_size, '...');
// Replace back <, >, " to the original tags
$content = str_replace(array('<','>','"'),array('&lt;','&gt;','&quot;'), $content); return escape($content);
// Fixed to a newline bug for consecutive sets of English letters
$content = preg_replace('/([a-z0-9\+:\/\.\~,\|\!\@\#\$\%\^\&\*\(\)\_]){20}/is',"$0-",$content);
return $content;
} }
/** /**

View file

@ -379,22 +379,22 @@ class mcontent extends WidgetHandler
function _getSummary($content, $str_size = 50) function _getSummary($content, $str_size = 50)
{ {
$content = preg_replace('!(<br[\s]*/{0,1}>[\s]*)+!is', ' ', $content); // Remove tags
// Replace tags such as </p> , </div> , </li> and others to a whitespace $content = strip_tags($content);
$content = str_replace(array('</p>', '</div>', '</li>'), ' ', $content);
// Remove Tag // Convert temporarily html entity for truncate
$content = preg_replace('!<([^>]*?)>!is','', $content); $content = html_entity_decode($content, ENT_QUOTES);
// Replace tags to < , > , "
$content = str_replace(array('&lt;','&gt;','&quot;','&nbsp;'), array('<','>','"',' '), $content); // Replace unicode whitespace characters (no-break space)
// Delete a series of whitespaces $content = utf8_normalize_spaces($content);
$content = preg_replace('/ ( +)/is', ' ', $content);
// Replace all whitespaces to single space
$content = trim(preg_replace('/\s+/', ' ', $content));
// Truncate string // Truncate string
$content = trim(cut_str($content, $str_size, $tail)); $content = cut_str($content, $str_size, '...');
// Replace back < , > , " to theoriginal tags
$content = str_replace(array('<','>','"'),array('&lt;','&gt;','&quot;'), $content); return escape($content);
// Fixed a newline bug on a set of consecutive English letters
$content = preg_replace('/([a-z0-9\+:\/\.\~,\|\!\@\#\$\%\^\&\*\(\)\_]){20}/is',"$0-",$content);
return $content;
} }