示例#1
0
function textFilter($text, $size, $wrap, $urls, $bbcodes, $eofs, $admin, $shorten = 0)
{
    if (get_magic_quotes_gpc() == 0) {
        $text = addslashes($text);
    }
    if (($admin == 1 or isset($GLOBALS['isMod']) and $GLOBALS['isMod'] == 1) and isset($GLOBALS['adminHTML']) and $GLOBALS['adminHTML']) {
        $text = trim($text);
    } else {
        $text = htmlspecialchars(trim($text), ENT_QUOTES);
    }
    $text = str_replace(array('\\'', '\\"', chr(92) . chr(92) . chr(92) . chr(92), chr(92) . chr(92), '&#', '$'), array(''', '"', '\\', '\', '&#', '$'), $text);
    $text = convert_entities($text);
    if (isset($GLOBALS['l_meta']) and substr_count(strtolower($GLOBALS['l_meta']), 'utf-8') == 0) {
        $text = str_replace(array('“', '”', '‘', '’', '…'), array('"', '"', ''', ''', '...'), $text);
    }
    if (substr_count($text, '&#9') > 0) {
        $text = preg_replace("@&#9[0-9]{2,};@", '', $text);
    }
    if (!$bbcodes) {
        $text = enCodeBB($text, $admin);
        $text = str_replace('><img src=', '> <img src=', $text);
    }
    if ($urls and !$bbcodes) {
        $text = urlMaker($text);
    }
    $text = wrapText($wrap, $text);
    $sce = FALSE;
    if (isset($GLOBALS['simpleCodes'])) {
        foreach ($GLOBALS['simpleCodes'] as $e) {
            if (substr_count($text, $e) > 0) {
                $sce = TRUE;
                break;
            }
        }
    }
    if (trim(strip_tags($text)) == '' and !$sce) {
        return '';
    }
    if ($size and strlen($text) > $size) {
        $text = special_substr($text, $size);
        if ($shorten > 0 and strlen($text) > $shorten) {
            $text = substr($text, 0, $shorten);
        }
        if (substr_count($text, '&') > 0) {
            /* Avoid special symbols extract */
            $tmpArr = explode('&', $text);
            $last = sizeof($tmpArr) - 1;
            if ($last > 0) {
                if (substr_count($tmpArr[$last], ';') == 0) {
                    array_pop($tmpArr);
                }
                $text = implode('&', $tmpArr);
            }
        }
    }
    if ($eofs and !isset($GLOBALS['disableLineBreaks'])) {
        while (substr_count($text, "\r\n\r\n\r\n\r\n") > 4) {
            $text = str_replace("\r\n\r\n\r\n\r\n", "\r\n", $text);
        }
        while (substr_count($text, "\n\n\n\n") > 4) {
            $text = str_replace("\n\n\n\n", "\n", $text);
        }
        $text = str_replace(array("\r\n", "\n"), '<br />', $text);
    }
    while (substr($text, -1) == chr(92)) {
        $text = substr($text, 0, strlen($text) - 1);
    }
    return $text;
}
示例#2
0
function textFilter($text, $size, $wrap, $urls, $bbcodes, $eofs, $admin)
{
    $text = trim(chop(htmlspecialchars($text, ENT_QUOTES)));
    $text = str_replace('\\&#039;', '&#039;', $text);
    $text = str_replace('\\&quot;', '&quot;', $text);
    $text = str_replace(chr(92) . chr(92) . chr(92) . chr(92), '&#92;&#92;', $text);
    $text = str_replace(chr(92) . chr(92), '&#92;', $text);
    $text = str_replace('&amp;#', '&#', $text);
    $text = str_replace('$', '&#036;', $text);
    if ($urls and !$bbcodes) {
        $text = urlMaker($text, $wrap);
    }
    if (!$bbcodes) {
        $text = enCodeBB($text, $admin);
        $text = str_replace('><img src=', '> <img src=', $text);
    }
    //echo $text;
    $text = wrapText($wrap, $text);
    //echo "<br><br>\n\n".$text;
    //exit;
    if ($size) {
        if (strlen($text) > $size) {
            $text = substr($text, 0, $size);
            //Avoid special symbols extract
            $tmpArr = explode('&', $text);
            $last = sizeof($tmpArr) - 1;
            if ($last > 0) {
                if (substr_count($tmpArr[$last], ';') == 0) {
                    array_pop($tmpArr);
                }
                $text = implode('&', $tmpArr);
            }
        }
    }
    if ($eofs) {
        while (substr_count($text, "\r\n\r\n\r\n\r\n") > 4) {
            $text = str_replace("\r\n\r\n\r\n\r\n", "\r\n", $text);
        }
        while (substr_count($text, "\n\n\n\n") > 4) {
            $text = str_replace("\n\n\n\n", "\n", $text);
        }
        $text = str_replace("\n", '<br>', $text);
        $text = str_replace("\r", '', $text);
    }
    while (substr($text, -1) == chr(92)) {
        $text = substr($text, 0, strlen($text) - 1);
    }
    return $text;
}