### Eclipse Workspace Patch 1.0 #P typo3_src-trunk Index: typo3/sysext/cms/tslib/class.tslib_content.php =================================================================== --- typo3/sysext/cms/tslib/class.tslib_content.php (revision 5826) +++ typo3/sysext/cms/tslib/class.tslib_content.php (working copy) @@ -3384,6 +3384,7 @@ if ($conf['bytes']){$content=t3lib_div::formatSize($content, $conf['bytes.']['labels']);} if ($conf['substring']){$content=$this->substring($content,$conf['substring']);} if ($conf['removeBadHTML']) {$content = $this->removeBadHTML($content, $conf['removeBadHTML.']);} + if ($conf['cropHTML']){$content=$this->cropHTML($content, $conf['cropHTML']);} if ($conf['stripHtml']){$content = strip_tags($content);} if ($conf['crop']){$content=$this->crop($content, $conf['crop']);} if ($conf['rawUrlEncode']){$content = rawurlencode($content);} @@ -3835,6 +3836,131 @@ } /** + * Implements the stdWrap property "cropHTML" which is a modified "substr" function allowing to limit a string length + * to a certain number of chars (from either start or end of string) and having a pre/postfix applied if the string + * really was cropped. + * + * Compared to stdWrap.crop it respects HTML tags and entities. + * + * @param string The string to perform the operation on + * @param string The parameters splitted by "|": First parameter is the max number of chars of the string. Negative value means cropping from end of string. Second parameter is the pre/postfix string to apply if cropping occurs. Third parameter is a boolean value. If set then crop will be applied at nearest space. + * @return string The processed input value. + * @access private + * @see stdWrap() + */ + function cropHTML($content, $options) { + $options = explode('|', $options); + $chars = intval($options[0]); + $absChars = abs($chars); + $replacementForEllipsis = trim($options[1]); + $crop2space = isset($options[2]) ? trim($options[2]) : 0; + + // Split $content into an array (even items in the array are outside the tags, odd numbers are tag-blocks). + $tags= 'a|b|blockquote|body|div|em|font|form|h1|h2|h3|h4|h5|h6|i|li|map|ol|option|p|pre|sub|sup|select|span|strong|table|thead|tbody|tfoot|td|textarea|tr|u|ul|br|hr|img|input|area|link'; + // TODO We should not crop inside