WHAT! My hacks in public!
Well, in the interests of someone doing it better...
In/functions/functions_general.php:
in function zen_trunc_string (around line 1036),
I edited it to call a new function in
/extra_functions/my_new_functions.php just before returning the truncated string:
Code:
function zen_trunc_string($str = "", $len = 150, $more = 'true') {
//echo '$str = '.$str.' $len = '.$len.' $more = '.$more.'<br />';//check
if ($str == "") return $str;
if (is_array($str)) return $str;
$str = trim($str);//strips whitespace from either end
// if it's less than the size given, then return it
if (strlen($str) <= $len) return $str;
// else get that size of text
$str = substr($str, 0, $len);//strips string to required length
// backtrack to the end of a word
if ($str != "") {
// check to see if there are any spaces left
if (!substr_count($str , " ")) {
if ($more == 'true') $str .= "...";
$str = check_for_p($str);//check for unclosed paragraph tags
return $str;
}
// backtrack
while(strlen($str) && ($str[strlen($str)-1] != " ")) {
$str = substr($str, 0, -1);
}
$str = substr($str, 0, -1);
if ($more == 'true') $str .= "...";
if ($more != 'true' and $more != 'false') $str .= $more;
$str = check_for_p($str);//steve check for unclosed paragraph tags
}
return $str;
}
and the new function:
PHP Code:
function check_for_p ($str) {
$needle = '<p';
$opened_p = substr_count($str,$needle);
$needle = '</p>';
$closed_p = substr_count($str,$needle);
if ($opened_p != $closed_p) {$str = $str.'</p>';}
return $str;
}