Code Duplication    Length = 15-43 lines in 6 locations

classes/autoptimizeBase.php 6 locations

@@ 159-173 (lines=15) @@
156
    }
157
    
158
    // unhide noptimize-tags
159
    protected function restore_noptimize($noptimize_in) {
160
        if ( strpos( $noptimize_in, '%%NOPTIMIZE%%' ) !== false ) { 
161
            $noptimize_out = preg_replace_callback(
162
                '#%%NOPTIMIZE%%(.*?)%%NOPTIMIZE%%#is',
163
                create_function(
164
                    '$matches',
165
                    'return base64_decode($matches[1]);'
166
                ),
167
                $noptimize_in
168
            );
169
        } else {
170
            $noptimize_out = $noptimize_in;
171
        }
172
        return $noptimize_out;
173
    }
174
175
    protected function hide_iehacks($iehacks_in) {
176
        if ( strpos( $iehacks_in, '<!--[if' ) !== false ) { 
@@ 175-189 (lines=15) @@
172
        return $noptimize_out;
173
    }
174
175
    protected function hide_iehacks($iehacks_in) {
176
        if ( strpos( $iehacks_in, '<!--[if' ) !== false ) { 
177
            $iehacks_out = preg_replace_callback(
178
                '#<!--\[if.*?\[endif\]-->#is',
179
                create_function(
180
                    '$matches',
181
                    'return "%%IEHACK%%".base64_encode($matches[0])."%%IEHACK%%";'
182
                ),
183
                $iehacks_in
184
            );
185
        } else {
186
            $iehacks_out = $iehacks_in;
187
        }
188
        return $iehacks_out;
189
    }
190
191
    protected function restore_iehacks($iehacks_in) {
192
        if ( strpos( $iehacks_in, '%%IEHACK%%' ) !== false ) { 
@@ 191-205 (lines=15) @@
188
        return $iehacks_out;
189
    }
190
191
    protected function restore_iehacks($iehacks_in) {
192
        if ( strpos( $iehacks_in, '%%IEHACK%%' ) !== false ) { 
193
            $iehacks_out = preg_replace_callback(
194
                '#%%IEHACK%%(.*?)%%IEHACK%%#is',
195
                create_function(
196
                    '$matches',
197
                    'return base64_decode($matches[1]);'
198
                ),
199
                $iehacks_in
200
            );
201
        } else {
202
            $iehacks_out=$iehacks_in;
203
        }
204
        return $iehacks_out;
205
    }
206
207
    protected function hide_comments($comments_in) {
208
        if ( strpos( $comments_in, '<!--' ) !== false ) {
@@ 207-221 (lines=15) @@
204
        return $iehacks_out;
205
    }
206
207
    protected function hide_comments($comments_in) {
208
        if ( strpos( $comments_in, '<!--' ) !== false ) {
209
            $comments_out = preg_replace_callback(
210
                '#<!--.*?-->#is',
211
                create_function(
212
                    '$matches',
213
                    'return "%%COMMENTS%%".base64_encode($matches[0])."%%COMMENTS%%";'
214
                ),
215
                $comments_in
216
            );
217
        } else {
218
            $comments_out = $comments_in;
219
        }
220
        return $comments_out;
221
    }
222
223
    protected function restore_comments($comments_in) {
224
        if ( strpos( $comments_in, '%%COMMENTS%%' ) !== false ) {
@@ 223-237 (lines=15) @@
220
        return $comments_out;
221
    }
222
223
    protected function restore_comments($comments_in) {
224
        if ( strpos( $comments_in, '%%COMMENTS%%' ) !== false ) {
225
            $comments_out = preg_replace_callback(
226
                '#%%COMMENTS%%(.*?)%%COMMENTS%%#is',
227
                create_function(
228
                    '$matches',
229
                    'return base64_decode($matches[1]);'
230
                ),
231
                $comments_in
232
            );
233
        } else {
234
            $comments_out=$comments_in;
235
        }
236
        return $comments_out;
237
    }
238
239
    protected function url_replace_cdn( $url ) {
240
        // API filter to change base CDN URL
@@ 299-341 (lines=43) @@
296
    }
297
    
298
    // inject already minified code in optimized JS/CSS
299
    protected function inject_minified($in) {
300
        if ( strpos( $in, '%%INJECTLATER%%' ) !== false ) {
301
            $out = preg_replace_callback(
302
                '#%%INJECTLATER%%(.*?)%%INJECTLATER%%#is',
303
                create_function(
304
                    '$matches',
305
                    '$filepath=base64_decode(strtok($matches[1],"|"));
306
                    $filecontent=file_get_contents($filepath);
307
308
                    // remove BOM
309
                    $filecontent = preg_replace("#\x{EF}\x{BB}\x{BF}#","",$filecontent);
310
311
                    // remove comments and blank lines
312
                    if (substr($filepath,-3,3)===".js") {
313
                        $filecontent=preg_replace("#^\s*\/\/.*$#Um","",$filecontent);
314
                    }
315
316
                    $filecontent=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Um","",$filecontent);
317
                    $filecontent=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $filecontent);
318
319
                    // specific stuff for JS-files
320
                    if (substr($filepath,-3,3)===".js") {
321
                        if ((substr($filecontent,-1,1)!==";")&&(substr($filecontent,-1,1)!=="}")) {
322
                            $filecontent.=";";
323
                        }
324
325
                        if (get_option("autoptimize_js_trycatch")==="on") {
326
                            $filecontent="try{".$filecontent."}catch(e){}";
327
                        }
328
                    } else if ((substr($filepath,-4,4)===".css")) {
329
                        $filecontent=autoptimizeStyles::fixurls($filepath,$filecontent);
330
                    }
331
332
                    // return 
333
                    return "\n".$filecontent;'
334
                ),
335
                $in
336
            );
337
        } else {
338
            $out = $in;
339
        }
340
        return $out;
341
    }
342
    
343
    protected function minify_single($pathIn) {
344
		// determine JS or CSS and set var (also mimetype), return false if neither