public function getcontent()
 {
     // restore IE hacks
     $this->content = $this->restore_iehacks($this->content);
     // restore comments
     $this->content = $this->restore_comments($this->content);
     // restore noscript
     if (strpos($this->content, '%%NOSCRIPT%%') !== false) {
         $this->content = preg_replace_callback('#%%NOSCRIPT%%(.*?)%%NOSCRIPT%%#is', create_function('$matches', 'return stripslashes(base64_decode($matches[1]));'), $this->content);
     }
     // restore noptimize
     $this->content = $this->restore_noptimize($this->content);
     //Restore the full content
     if (!empty($this->restofcontent)) {
         $this->content .= $this->restofcontent;
         $this->restofcontent = '';
     }
     // Inject the new stylesheets
     $replaceTag = array("<title", "before");
     $replaceTag = apply_filters('autoptimize_filter_css_replacetag', $replaceTag);
     if ($this->inline == true) {
         foreach ($this->csscode as $media => $code) {
             $this->inject_in_html('<style type="text/css" media="' . $media . '">' . $code . '</style>', $replaceTag);
         }
     } else {
         if ($this->defer == true) {
             $deferredCssBlock = "<script>function lCss(url,media) {var d=document;var l=d.createElement('link');l.rel='stylesheet';l.type='text/css';l.href=url;l.media=media; d.getElementsByTagName('head')[0].appendChild(l);}function deferredCSS() {";
             $noScriptCssBlock = "<noscript>";
             $defer_inline_code = $this->defer_inline;
             $defer_inline_code = apply_filters('autoptimize_filter_css_defer_inline', $defer_inline_code);
             if (!empty($defer_inline_code)) {
                 $iCssHash = md5($defer_inline_code);
                 $iCssCache = new autoptimizeCache($iCssHash, 'css');
                 if ($iCssCache->check()) {
                     // we have the optimized inline CSS in cache
                     $defer_inline_code = $iCssCache->retrieve();
                 } else {
                     if (class_exists('Minify_CSS_Compressor')) {
                         $tmp_code = trim(Minify_CSS_Compressor::process($this->defer_inline));
                     } else {
                         if (class_exists('CSSmin')) {
                             $cssmin = new CSSmin();
                             $tmp_code = trim($cssmin->run($defer_inline_code));
                         }
                     }
                     if (!empty($tmp_code)) {
                         $defer_inline_code = $tmp_code;
                         $iCssCache->cache($defer_inline_code, "text/css");
                         unset($tmp_code);
                     }
                 }
                 $code_out = '<style type="text/css" media="all">' . $defer_inline_code . '</style>';
                 $this->inject_in_html($code_out, $replaceTag);
             }
         }
         foreach ($this->url as $media => $url) {
             $url = $this->url_replace_cdn($url);
             //Add the stylesheet either deferred (import at bottom) or normal links in head
             if ($this->defer == true) {
                 $deferredCssBlock .= "lCss('" . $url . "','" . $media . "');";
                 $noScriptCssBlock .= '<link type="text/css" media="' . $media . '" href="' . $url . '" rel="stylesheet" />';
             } else {
                 $this->inject_in_html('<link type="text/css" media="' . $media . '" href="' . $url . '" rel="stylesheet" />', $replaceTag);
             }
         }
         if ($this->defer == true) {
             $deferredCssBlock .= "}if(window.addEventListener){window.addEventListener('DOMContentLoaded',deferredCSS,false);}else{window.onload = deferredCSS;}</script>";
             $noScriptCssBlock .= "</noscript>";
             $this->inject_in_html($noScriptCssBlock, array('<title>', 'before'));
             $this->inject_in_html($deferredCssBlock, array('</body>', 'before'));
         }
     }
     //Return the modified stylesheet
     return $this->content;
 }
 public function cache()
 {
     $cache = new autoptimizeCache($this->md5hash, 'js');
     if (!$cache->check()) {
         //Cache our code
         $cache->cache($this->jscode, 'text/javascript');
     }
     $this->url = AUTOPTIMIZE_CACHE_URL . $cache->getname();
     $this->url = $this->url_replace_cdn($this->url);
 }
 public function cache()
 {
     if ($this->datauris) {
         //MHTML Preparation
         $this->mhtml = "/*\r\nContent-Type: multipart/related; boundary=\"_\"\r\n\r\n" . $this->mhtml . "*/\r\n";
         $md5 = md5($this->mhtml);
         $cache = new autoptimizeCache($md5, 'txt');
         if (!$cache->check()) {
             //Cache our images for IE
             $cache->cache($this->mhtml, 'text/plain');
         }
         $mhtml = AUTOPTIMIZE_CACHE_URL . $cache->getname();
     }
     //CSS cache
     foreach ($this->csscode as $media => $code) {
         // fgo, moved from below to prevent empty md5 resulting in filenames without hash autoptimize_.php
         $md5 = $this->hashmap[md5($code)];
         if ($this->datauris) {
             //Images for ie! Get the right url
             $code = str_replace('%%MHTML%%', $mhtml, $code);
         }
         // $md5 = $this->hashmap[md5($code)];
         $cache = new autoptimizeCache($md5, 'css');
         if (!$cache->check()) {
             //Cache our code
             $cache->cache($code, 'text/css');
         }
         $this->url[$media] = AUTOPTIMIZE_CACHE_URL . $cache->getname();
     }
 }