Example #1
0
 public function minify($url)
 {
     $this->url = $url;
     $cachFilePath = WPFC_WP_CONTENT_DIR . "/cache/wpfc-minified/" . md5($url);
     $jsLink = content_url() . "/cache/wpfc-minified/" . md5($url);
     if (is_dir($cachFilePath)) {
         return array("cachFilePath" => $cachFilePath, "jsContent" => "", "url" => $jsLink);
     } else {
         if ($js = $this->file_get_contents_curl($url)) {
             if ($this->minify) {
                 if (class_exists("WpFastestCachePowerfulHtml")) {
                     $powerful_html = new WpFastestCachePowerfulHtml();
                     $js = $powerful_html->minify_js($js);
                 } else {
                     $js = "\n// source --> " . $url . " \n" . $js;
                 }
             } else {
                 $js = "\n// source --> " . $url . " \n" . $js;
             }
             return array("cachFilePath" => $cachFilePath, "jsContent" => $js, "url" => $jsLink);
         }
     }
     return false;
 }
Example #2
0
 public function combineJs($content, $minify = false)
 {
     $minify = true;
     if (isset($this->options->wpFastestCacheCombineJs)) {
         require_once "js-utilities.php";
         $js = new JsUtilities($this, $content);
         if (count($js->getJsLinks()) > 0) {
             $prev = array("content" => "", "value" => array());
             foreach ($js->getJsLinks() as $key => $value) {
                 if ($href = $js->checkInternal($value)) {
                     if (strpos($js->getJsLinksExcept(), $href) === false) {
                         if (!preg_match("/<script[^>]+json[^>]+>.+/", $value)) {
                             $minifiedJs = $js->minify($href, $minify);
                             if ($minifiedJs) {
                                 if (!is_dir($minifiedJs["cachFilePath"])) {
                                     if (isset($this->options->wpFastestCacheCombineJsPowerFul)) {
                                         $powerful_html = new WpFastestCachePowerfulHtml();
                                         $minifiedJs["jsContent"] = $powerful_html->minify_js($minifiedJs["jsContent"]);
                                     }
                                     $prefix = time();
                                     $this->createFolder($minifiedJs["cachFilePath"], $minifiedJs["jsContent"], "js", $prefix);
                                 }
                                 if ($jsFiles = @scandir($minifiedJs["cachFilePath"], 1)) {
                                     if ($jsContent = $js->file_get_contents_curl($minifiedJs["url"] . "/" . $jsFiles[0] . "?v=" . time())) {
                                         $prev["content"] = $prev["content"] . "\n" . $jsContent;
                                         array_push($prev["value"], $value);
                                     }
                                 }
                             }
                         } else {
                             $content = $js->mergeJs($prev, $this);
                             $prev = array("content" => "", "value" => array());
                         }
                     } else {
                         $content = $js->mergeJs($prev, $this);
                         $prev = array("content" => "", "value" => array());
                     }
                 } else {
                     $content = $js->mergeJs($prev, $this);
                     $prev = array("content" => "", "value" => array());
                 }
             }
             $content = $js->mergeJs($prev, $this);
         }
     }
     $content = preg_replace("/(<!-- )+/", "<!-- ", $content);
     $content = preg_replace("/( -->)+/", " -->", $content);
     return $content;
 }