Project

General

Profile

« Previous | Next » 

Revision 5

Added by Manuela about 7 years ago

output_filter::filterEmail:: mdcr.js is loaded only when at least one email address is encrypted on the current page

View differences:

branches/main/admin/interface/version.php
48 48

  
49 49
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
50 50
if(!defined('VERSION')) { define('VERSION', '2.10.1-dev'); }
51
if(!defined('REVISION')) { define('REVISION', '4'); }
51
if(!defined('REVISION')) { define('REVISION', '5'); }
52 52
if(!defined('SP')) { define('SP', ''); }
53 53

  
branches/main/modules/output_filter/filters/filterEmail.php
15 15
            ) {
16 16
                return $content;
17 17
            }
18
        // test if js-decryption is installed
19
            if( preg_match('/<head.*<.*src=\".*\/mdcr.js.*>.*<\/head/siU', $content) ) {
18
            $bNeedMdcr = false;
19
        // test if js-decryption is available
20
            $script = str_replace('\\', '/',str_replace(WB_PATH,'', dirname(__DIR__)).'/js/mdcr.js');
21
            if(is_readable(WB_PATH.$script)) {
22
                $scriptLink = "\t".'<script src="'.WB_URL.$script.'" type="text/javascript"></script>'."\n";
20 23
                $aFilterSettings['OutputFilterMode'] |= pow(2, 2); // n | 2^2
21
            }else {
22
            // try to insert js-decrypt into <head> if available
23
                $script = str_replace('\\', '/',str_replace(WB_PATH,'', dirname(__DIR__)).'/js/mdcr.js');
24
                if(is_readable(WB_PATH.$script)) {
25
                    $scriptLink = "\t".'<script src="'.WB_URL.$script.'" type="text/javascript"></script>'."\n";
26
                    $regex = '/(.*)(<\s*?\/\s*?head\s*>.*)/isU';
27
                    $replace = '$1'.$scriptLink.'$2';
28
                    $content = preg_replace ($regex, $replace, $content);
29
                    $aFilterSettings['OutputFilterMode'] |= pow(2, 2); // n | 2^2
30
                }
31 24
            }
32 25
/* *** obfuscate mailto addresses by js:mdcr *** */
33 26
            // work out the defined output filter mode: possible output filter modes: [0], 1, 2, 3, 6, 7
......
54 47
            $content = preg_replace_callback(
55 48
                $pattern,
56 49
    /* ************************************************************************** */
57
                function ($match) use ($aFilterSettings) {
50
                function ($match) use ($aFilterSettings, $bNeedMdcr) {
58 51
                    // check if required arguments are defined
59 52
                    $search = array('@', '.');
60 53
                    $replace = array($aFilterSettings['at_replacement'] ,$aFilterSettings['dot_replacement']);
......
111 104
                                $encrypted_email .= chr($shift + 97);
112 105
                            // build the encrypted Javascript mailto link
113 106
                                $mailto_link  = "<a {$class_attr}{$id_attr}href=\"javascript:mdcr('$encrypted_email','$email_subject')\">" .$match[5] ."</a>";
107
                                $bNeedMdcr = true;
114 108
                                return $mailto_link;
115 109
                            } else {
116 110
                            /** DO NOT USE JAVASCRIPT ENCRYPTION FOR MAILTO LINKS **/
......
132 126
                $content
133 127
            );
134 128
        }
129
        if ($bNeedMdcr) {
130
        // test if js-decryption is installed
131
            if (!preg_match('/<head.*<.*src=\".*\/mdcr.js.*>.*<\/head/siU', $content) ) {
132
            // try to insert js-decrypt into <head> if available
133
                $script = str_replace('\\', '/',str_replace(WB_PATH,'', dirname(__DIR__)).'/js/mdcr.js');
134
                if(is_readable(WB_PATH.$script)) {
135
                    $scriptLink = "\t".'<script src="'.WB_URL.$script.'" type="text/javascript"></script>'."\n";
136
                    $regex = '/(.*)(<\s*?\/\s*?head\s*>.*)/isU';
137
                    $replace = '$1'.$scriptLink.'$2';
138
                    $content = preg_replace ($regex, $replace, $content);
139
                }
140
            }
141
        }
135 142
        return $content;
136 143
    }

Also available in: Unified diff