芝麻web文件管理V1.00
编辑当前文件:/www/wwwroot/shphe-en.com/wp-content/plugins/wp-fastest-cache/inc/js-utilities.php
html = preg_replace("/\s+/", " ", ((string) $html)); $this->minify = $minify; $this->wpfc = $wpfc; $this->html = $html; $this->setJsLinksExcept(); $this->setJsLinks(); } public function check_exclude($js_url = false){ if($js_url){ foreach((array)$this->wpfc->exclude_rules as $key => $value){ if(isset($value->prefix) && $value->prefix && $value->type == "js"){ if($value->prefix == "contain"){ $preg_match_rule = preg_quote($value->content, "/"); } if(preg_match("/".$preg_match_rule."/i", $js_url)){ return true; } } } } } public function combine_js(){ if(count($this->jsLinks) > 0){ $prev_content = ""; foreach($this->jsLinks as $key => $value){ $script_tag = substr($this->html, $value["start"], ($value["end"] - $value["start"] + 1)); if(!preg_match("/"){ array_push($script_list, array("start" => $script_start_index, "end" => $i)); $script_start_index = false; } } } } if(count($script_list) > 0){ $this->jsLinks = array_reverse($script_list); } // to update jsLinksExcept foreach($this->jsLinks as $key => $value){ $script_tag = substr($this->html, $value["start"], ($value["end"] - $value["start"] + 1)); if(preg_match("/wp-spamshield\/js\/jscripts\.php/i", $script_tag)){ $this->jsLinksExcept = $this->jsLinksExcept.$script_tag; } //amazonjs/components/js/jquery-tmpl/jquery.tmpl.min.js?ver=1.0.0pre if(preg_match("/jquery-tmpl\/jquery\.tmpl\.min\.js/i", $script_tag)){ $this->jsLinksExcept = $this->jsLinksExcept.$script_tag; } } } public function setJsLinksExcept(){ $comment_tags = $this->find_tags(""); $document_write = $this->find_tags("document.write(", ")"); foreach ($comment_tags as $key => $value) { if(preg_match("/ if(preg_match("/[\?\=].*".preg_quote($httpHost, "/")."/i", $src[1])){ return false; } return $src[1]; } } } return false; } public function mergeJs($js_content, $value, $last = false){ $name = md5($js_content); $name = base_convert(crc32($name), 20, 36); $cachFilePath = $this->wpfc->getWpContentDir("/cache/wpfc-minified")."/".$name; $jsLink = $this->convert_path_to_link($cachFilePath); if(!is_dir($cachFilePath)){ $this->wpfc->createFolder($cachFilePath, $js_content, "js"); } if($jsFiles = @scandir($cachFilePath, 1)){ $newLink = ""; $script_tag = substr($this->html, $value["start"], ($value["end"] - $value["start"] + 1)); if($last){ $script_tag = $newLink."\n\n"; }else{ $script_tag = $newLink."\n".$script_tag; } $this->html = substr_replace($this->html, $script_tag, $value["start"], ($value["end"] - $value["start"] + 1)); } } public function convert_path_to_link($path){ preg_match("/\/cache\/.+/", $path, $out); $prefixLink = str_replace(array("http:", "https:"), "", WPFC_WP_CONTENT_URL); return $prefixLink.$out[0]; } public function file_get_contents_curl($url) { if($data = $this->wpfc->read_file($url)){ return $data; } if(!preg_match("/\.php$/", $url)){ $url = $url."?v=".time(); } if(preg_match("/^\/[^\/]/", $url)){ $url = home_url().$url; } $url = preg_replace("/^\/\//", "http://", $url); $response = wp_remote_get($url, array('timeout' => 10 ) ); if ( !$response || is_wp_error( $response ) ) { return false; }else{ if(wp_remote_retrieve_response_code($response) == 200){ $data = wp_remote_retrieve_body( $response ); if(preg_match("/<\/\s*html\s*>\s*$/i", $data)){ return false; }else{ return $data; } } } } public function find_tags($start_string, $end_string){ $data = $this->html; $list = array(); $start_index = false; $end_index = false; for($i = 0; $i < strlen( $data ); $i++) { if(substr($data, $i, strlen($start_string)) == $start_string){ $start_index = $i; } if($start_index && $i > $start_index){ if(substr($data, $i, strlen($end_string)) == $end_string){ $end_index = $i + strlen($end_string)-1; $text = substr($data, $start_index, ($end_index-$start_index + 1)); array_push($list, array("start" => $start_index, "end" => $end_index, "text" => $text)); $start_index = false; $end_index = false; } } } return $list; } } ?>