Пример #1
0
function otf_commentexcerpt($option_key, $result, $ext)
{
    if (!$ext) {
        $len = 55;
        $type = 'a';
    } else {
        $s = explode(':', $ext);
        if (count($s) == 1) {
            $s[] = 'a';
        }
        $len = $s[0];
        $type = $s[1];
        if ($type === 'b') {
            if (count($s) > 2) {
                $more = $s[2];
            } else {
                $more = ' …';
            }
            if (count($s) > 3) {
                if ($s[3] === 'link') {
                    $url = otf_commenturl($option_key, $result, '');
                    $more = '<a href="' . $url . '">' . $more . '</a>';
                }
            }
        }
    }
    switch ($type) {
        case 'a':
            $value = oth_trim_comment_excerpt($result->comment_content, $ext);
            break;
        case 'b':
            $value = $result->comment_content;
            $value = convert_smilies($value);
            $text = str_replace(']]>', ']]&gt;', $value);
            if ($len <= count(preg_split('/[\\s]+/', strip_tags($text), -1))) {
                // remove html entities for now
                $text = str_replace("", "", $text);
                preg_match_all("/&([a-z\\d]{2,7}|#\\d{2,5});/i", $text, $ents);
                $text = preg_replace("/&([a-z\\d]{2,7}|#\\d{2,5});/i", "", $text);
                // now we start counting
                $parts = preg_split('/([\\s]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
                $in_tag = false;
                $num_words = 0;
                $text = '';
                foreach ($parts as $part) {
                    if (0 < preg_match('/<[^>]*$/s', $part)) {
                        $in_tag = true;
                    } else {
                        if (0 < preg_match('/>[^<]*$/s', $part)) {
                            $in_tag = false;
                        }
                    }
                    if (!$in_tag && '' != trim($part) && substr($part, -1, 1) != '>') {
                        $num_words++;
                    }
                    $text .= $part;
                    if ($num_words >= $len && !$in_tag) {
                        break;
                    }
                }
                // put back the missing html entities
                foreach ($ents[0] as $ent) {
                    $text = preg_replace("//", $ent, $text, 1);
                }
                $text = balanceTags($text, true);
                $value = $text . $more;
            }
            $value = apply_filters('get_comment_text', $value);
            break;
        default:
            $value = oth_trim_comment_excerpt($result->comment_content, $ext);
            break;
    }
    return $value;
}
Пример #2
0
function otf_commentexcerpt($option_key, $result, $ext)
{
    return oth_trim_comment_excerpt($result->comment_content, $ext);
}