示例#1
0
/**
 * Cloak all emails in text from spambots via Javascript.
 *
 * @param string The string to be cloaked.
 * @param array Additional parameters. Parameter "mode" (integer, default 1)
 * replaces addresses with "mailto:" links if nonzero.
 * @return boolean True on success.
 */
function plgEmailCloak(&$text, &$params)
{
    /*
     * Check for presence of {emailcloak=off} which is explicits disables this
     * bot for the item.
     */
    if (JString::strpos($text, '{emailcloak=off}') !== false) {
        $text = JString::str_ireplace('{emailcloak=off}', '', $text);
        return true;
    }
    // Simple performance check to determine whether bot should process further.
    if (JString::strpos($text, '@') === false) {
        return true;
    }
    $plugin =& JPluginHelper::getPlugin('content', 'emailcloak');
    // Load plugin params info
    $pluginParams = new JParameter($plugin->params);
    $mode = $pluginParams->def('mode', 1);
    // any@email.address.com
    $searchEmail = '([\\w\\.\\-]+\\@(?:[a-z0-9\\.\\-]+\\.)+(?:[a-z0-9\\-]{2,4}))';
    // any@email.address.com?subject=anyText
    $searchEmailLink = $searchEmail . '([?&][\\x20-\\x7f][^"<>]+)';
    // anyText
    $searchText = '([\\x20-\\x7f][^<>]+)';
    /*
     * Search for derivatives of link code <a href="mailto:email@amail.com"
     * >email@amail.com</a>
     */
    $pattern = plgContentEmailCloak_searchPattern($searchEmail, $searchEmail);
    while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
        $mail = $regs[1][0];
        $mailText = $regs[2][0];
        // Check to see if mail text is different from mail addy
        $replacement = JHTML::_('email.cloak', $mail, $mode, $mailText);
        // Replace the found address with the js cloaked email
        $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
    }
    /*
     * Search for derivatives of link code <a href="mailto:email@amail.com">
     * anytext</a>
     */
    $pattern = plgContentEmailCloak_searchPattern($searchEmail, $searchText);
    while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
        $mail = $regs[1][0];
        $mailText = $regs[2][0];
        $replacement = JHTML::_('email.cloak', $mail, $mode, $mailText, 0);
        // Replace the found address with the js cloaked email
        $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
    }
    /*
     * Search for derivatives of link code <a href="mailto:email@amail.com?
     * subject=Text">email@amail.com</a>
     */
    $pattern = plgContentEmailCloak_searchPattern($searchEmailLink, $searchEmail);
    while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
        $mail = $regs[1][0] . $regs[2][0];
        $mailText = $regs[3][0];
        // Needed for handling of Body parameter
        $mail = str_replace('&amp;', '&', $mail);
        // Check to see if mail text is different from mail addy
        $replacement = JHTML::_('email.cloak', $mail, $mode, $mailText);
        // Replace the found address with the js cloaked email
        $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
    }
    /*
     * Search for derivatives of link code <a href="mailto:email@amail.com?
     * subject=Text">anytext</a>
     */
    $pattern = plgContentEmailCloak_searchPattern($searchEmailLink, $searchText);
    while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
        $mail = $regs[1][0] . $regs[2][0];
        $mailText = $regs[3][0];
        // Needed for handling of Body parameter
        $mail = str_replace('&amp;', '&', $mail);
        $replacement = JHTML::_('email.cloak', $mail, $mode, $mailText, 0);
        // Replace the found address with the js cloaked email
        $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
    }
    // Search for plain text email@amail.com
    $pattern = '~' . $searchEmail . '([^a-z0-9]|$)~i';
    while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
        $mail = $regs[1][0];
        $replacement = JHTML::_('email.cloak', $mail, $mode);
        // Replace the found address with the js cloaked email
        $text = substr_replace($text, $replacement, $regs[1][1], strlen($mail));
    }
    return true;
}
示例#2
0
/**
 * Cloak all emails in text from spambots via Javascript.
 *
 * @param string The string to be cloaked.
 * @param string The mode.
 * replaces addresses with "mailto:" links if nonzero.
 * @return boolean True on success.
 */
function plgEmailCloakString(&$text, $mode = 1)
{
    // Simple performance check to determine whether bot should process further.
    if (JString::strpos($text, '@') === false) {
        return true;
    }
    // any@email.address.com
    $searchEmail = '([\\w\\.\\-]+\\@(?:[a-z0-9\\.\\-]+\\.)+(?:[a-z0-9\\-]{2,4}))';
    // any@email.address.com?subject=anyText
    $searchEmailLink = $searchEmail . '([?&][\\x20-\\x7f][^"<>]+)';
    // anyText
    $searchText = '((?:[\\x20-\\x7f]|[\\xA1-\\xFF]|[\\xC2-\\xDF][\\x80-\\xBF]|[\\xE0-\\xEF][\\x80-\\xBF]{2}|[\\xF0-\\xF4][\\x80-\\xBF]{3})[^<>]+)';
    //$searchText = '(+)';
    //Any Image link
    $searchImage = "(<img[^>]+>)";
    /*
     * Search for derivatives of link code <a href="mailto:email@amail.com"
     * >email@amail.com</a>
     */
    $pattern = plgContentEmailCloak_searchPattern($searchEmail, $searchEmail);
    while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
        $mail = $regs[2][0];
        $mailText = $regs[3][0];
        // Check to see if mail text is different from mail addy
        $replacement = JHTML::_('email.cloak', $mail, $mode, $mailText);
        // Replace the found address with the js cloaked email
        $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
    }
    /*
     * Search for derivatives of link code <a href="mailto:email@amail.com">
     * anytext</a>
     */
    $pattern = plgContentEmailCloak_searchPattern($searchEmail, $searchText);
    while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
        $prefix = $regs[1][0];
        $mail = $regs[2][0];
        $suffix = $regs[3][0];
        $attribs = $regs[4][0];
        $mailText = $regs[5][0];
        $replacement = JHTML::_('email.cloak', $mail, $mode, $mailText, 0, $prefix, $suffix, $attribs);
        // Replace the found address with the js cloaked email
        $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
    }
    /*
     * Search for derivatives of link code <a href="mailto:email@amail.com">
     * <img anything></a>
     */
    $pattern = plgContentEmailCloak_searchPattern($searchEmail, $searchImage);
    while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
        $prefix = $regs[1][0];
        $mail = $regs[2][0];
        $suffix = $regs[3][0];
        $attribs = $regs[4][0];
        $mailText = $regs[5][0];
        $replacement = JHTML::_('email.cloak', $mail, $mode, $mailText, 0, $prefix, $suffix, $attribs);
        // Replace the found address with the js cloaked email
        $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
    }
    /*
     * Search for derivatives of link code <a href="mailto:email@amail.com?
     * subject=Text">email@amail.com</a>
     */
    $pattern = plgContentEmailCloak_searchPattern($searchEmailLink, $searchEmail);
    while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
        $mail = $regs[2][0] . $regs[3][0];
        $mailText = $regs[6][0];
        // Needed for handling of Body parameter
        $mail = str_replace('&amp;', '&', $mail);
        // Check to see if mail text is different from mail addy
        $replacement = JHTML::_('email.cloak', $mail, $mode, $mailText);
        // Replace the found address with the js cloaked email
        $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
    }
    /*
     * Search for derivatives of link code <a href="mailto:email@amail.com?
     * subject=Text">anytext</a>
     */
    $pattern = plgContentEmailCloak_searchPattern($searchEmailLink, $searchText);
    while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
        $mail = $regs[2][0] . $regs[3][0];
        $mailText = $regs[6][0];
        // Needed for handling of Body parameter
        $mail = str_replace('&amp;', '&', $mail);
        $replacement = JHTML::_('email.cloak', $mail, $mode, $mailText, 0);
        // Replace the found address with the js cloaked email
        $text = substr_replace($text, $replacement, $regs[0][1], strlen($regs[0][0]));
    }
    // Search for plain text email@amail.com
    $pattern = '~' . $searchEmail . '([^a-z0-9]|$)~i';
    while (preg_match($pattern, $text, $regs, PREG_OFFSET_CAPTURE)) {
        $mail = $regs[1][0];
        $replacement = JHTML::_('email.cloak', $mail, $mode);
        // Replace the found address with the js cloaked email
        $text = substr_replace($text, $replacement, $regs[1][1], strlen($mail));
    }
    return true;
}
示例#3
0
/**
* Plugin that Cloaks all emails in content from spambots via javascript
*/
function plgContentEmailCloak(&$row, &$params, $page = 0)
{
    // simple performance check to determine whether bot should process further
    if (JString::strpos($row->text, '@') === false) {
        return true;
    }
    $plugin =& JPluginHelper::getPlugin('content', 'emailcloak');
    // check for presence of {emailcloak=off} which is explicits disables this bot for the item
    if (!JString::strpos($row->text, '{emailcloak=off}') === false) {
        $row->text = JString::str_ireplace('{emailcloak=off}', '', $row->text);
        return true;
    }
    // load plugin params info
    $pluginParams = new JParameter($plugin->params);
    $mode = $pluginParams->def('mode', 1);
    // any@email.address.com
    $search_email = "([[:alnum:]_\\.\\-]+)(\\@[[:alnum:]\\.\\-]+\\.+)([[:alnum:]\\.\\-]+)";
    // any@email.address.com?subject=anyText
    $search_email_msg = "([[:alnum:]_\\.\\-]+)(\\@[[:alnum:]\\.\\-]+\\.+)([[:alnum:]\\.\\-]+)([[:alnum:][:space:][:punct:]][^\"<>]+)";
    // anyText
    $search_text = "([[:alnum:][:space:][:punct:]][^<>]+)";
    // search for derivativs of link code <a href="mailto:email@amail.com">email@amail.com</a>
    $pattern = plgContentEmailCloak_searchPattern($search_email, $search_email);
    while (eregi($pattern, $row->text, $regs)) {
        $mail = $regs[2] . $regs[3] . $regs[4];
        $mail_text = $regs[5] . $regs[6] . $regs[7];
        // check to see if mail text is different from mail addy
        if ($mail_text) {
            $replacement = JHTML::_('email.cloak', $mail, $mode, $mail_text);
        } else {
            $replacement = JHTML::_('email.cloak', $mail, $mode);
        }
        // replace the found address with the js cloacked email
        $row->text = str_replace($regs[0], $replacement, $row->text);
    }
    // search for derivativs of link code <a href="mailto:email@amail.com">anytext</a>
    $pattern = plgContentEmailCloak_searchPattern($search_email, $search_text);
    while (eregi($pattern, $row->text, $regs)) {
        $mail = $regs[2] . $regs[3] . $regs[4];
        $mail_text = $regs[5];
        $replacement = JHTML::_('email.cloak', $mail, $mode, $mail_text, 0);
        // replace the found address with the js cloacked email
        $row->text = str_replace($regs[0], $replacement, $row->text);
    }
    // search for derivativs of link code <a href="mailto:email@amail.com?subject=Text">email@amail.com</a>
    $pattern = plgContentEmailCloak_searchPattern($search_email_msg, $search_email);
    while (eregi($pattern, $row->text, $regs)) {
        $mail = $regs[2] . $regs[3] . $regs[4] . $regs[5];
        $mail_text = $regs[6] . $regs[7] . $regs[8];
        //needed for handling of Body parameter
        $mail = str_replace('&amp;', '&', $mail);
        // check to see if mail text is different from mail addy
        if ($mail_text) {
            $replacement = JHTML::_('email.cloak', $mail, $mode, $mail_text);
        } else {
            $replacement = JHTML::_('email.cloak', $mail, $mode);
        }
        // replace the found address with the js cloacked email
        $row->text = str_replace($regs[0], $replacement, $row->text);
    }
    // search for derivativs of link code <a href="mailto:email@amail.com?subject=Text">anytext</a>
    $pattern = plgContentEmailCloak_searchPattern($search_email_msg, $search_text);
    while (eregi($pattern, $row->text, $regs)) {
        $mail = $regs[2] . $regs[3] . $regs[4] . $regs[5];
        $mail_text = $regs[6];
        //needed for handling of Body parameter
        $mail = str_replace('&amp;', '&', $mail);
        $replacement = JHTML::_('email.cloak', $mail);
        // replace the found address with the js cloacked email
        $row->text = str_replace($regs[0], $replacement, $row->text);
    }
    // search for plain text email@amail.com
    while (eregi($search_email, $row->text, $regs)) {
        $mail = $regs[0];
        $replacement = JHTML::_('email.cloak', $mail, $mode);
        // replace the found address with the js cloacked email
        $row->text = str_replace($regs[0], $replacement, $row->text);
    }
}