PluginProbe
Autoptimize / 1.7.1
Autoptimize v1.7.1
2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 All 107 releases
autoptimize / classes / autoptimizeBase.php

autoptimizeBase.php in Autoptimize 1.7.1, at classes/autoptimizeBase.php

93 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
4 abstract class autoptimizeBase
5 {
6 protected $content = '';
7
8 public function __construct($content)
9 {
10 $this->content = $content;
11 //Best place to catch errors
12 }
13
14 //Reads the page and collects tags
15 abstract public function read($justhead);
16
17 //Joins and optimizes collected things
18 abstract public function minify();
19
20 //Caches the things
21 abstract public function cache();
22
23 //Returns the content
24 abstract public function getcontent();
25
26 //Converts an URL to a full path
27 protected function getpath($url)
28 {
29
30 if ((strpos($url,'//')===false) && (strpos($url,parse_url(AUTOPTIMIZE_WP_SITE_URL,PHP_URL_HOST))===false)) {
31 $url = AUTOPTIMIZE_WP_SITE_URL.$url;
32 }
33 $path = str_replace(AUTOPTIMIZE_WP_ROOT_URL,'',$url);
34 if(preg_match('#^((https?|ftp):)?//#i',$path))
35 {
36 /** External script/css (adsense, etc) */
37 return false;
38 }
39 $path = str_replace('//','/',WP_ROOT_DIR.$path);
40 return $path;
41 }
42 // logger
43 protected function ao_logger($logmsg) {
44 $logfile=WP_CONTENT_DIR.'/ao_log.txt';
45 $logmsg.="\n";
46 file_put_contents($logfile,$logmsg,FILE_APPEND);
47 }
48 // hide everything between noptimize-comment tags
49 protected function hide_noptimize($noptimize_in) {
50 if ( preg_match( '/<!--\s?noptimize\s?-->/', $noptimize_in ) ) {
51 $noptimize_out = preg_replace_callback(
52 '#<!--\s?noptimize\s?-->.*?<!--\s?/\s?noptimize\s?-->#is',
53 create_function(
54 '$matches',
55 'return "%%NOPTIMIZE%%".base64_encode($matches[0])."%%NOPTIMIZE%%";'
56 ),
57 $noptimize_in
58 );
59 } else {
60 $noptimize_out = $noptimize_in;
61 }
62 return $noptimize_out;
63 }
64
65 // unhide noptimize-tags
66 protected function restore_noptimize($noptimize_in) {
67 if ( preg_match( '/%%NOPTIMIZE%%/', $noptimize_in ) ) {
68 $noptimize_out = preg_replace_callback(
69 '#%%NOPTIMIZE%%(.*?)%%NOPTIMIZE%%#is',
70 create_function(
71 '$matches',
72 'return stripslashes(base64_decode($matches[1]));'
73 ),
74 $noptimize_in
75 );
76 } else {
77 $noptimize_out = $noptimize_in;
78 }
79 return $noptimize_out;
80 }
81
82 protected function url_replace_cdn($url) {
83
84 if (!empty($this->cdn_url)) {
85 // this check is too expensive, is done on admin-screen
86 // if (preg_match("/^(https?)?:\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*\/?$/",$this->cdn_url)) {
87 $url=str_replace(AUTOPTIMIZE_WP_SITE_URL,rtrim($this->cdn_url,'/'),$url);
88 // }
89 }
90 return $url;
91 }
92 }
93