/**
  * Output buffer callback
  *
  * @param string  $buffer
  * @return mixed
  */
 function ob_callback($buffer)
 {
     if ($buffer != '' && Util_Content::is_html($buffer)) {
         $domain_url_regexp = Util_Environment::home_domain_root_url_regexp();
         $buffer = preg_replace_callback('~(href|src|action|extsrc|asyncsrc|w3tc_load_js\\()=?([\'"])((' . $domain_url_regexp . ')?(/[^\'"]*\\.([a-z-_]+)(\\?[^\'"]*)?))[\'"]~Ui', array($this, 'link_replace_callback'), $buffer);
     }
     return $buffer;
 }
 private function fill_regexps()
 {
     $regexps = array();
     $site_path = Util_Environment::site_url_uri();
     $domain_url_regexp = Util_Environment::home_domain_root_url_regexp();
     $site_domain_url_regexp = false;
     if ($domain_url_regexp != Util_Environment::get_url_regexp(Util_Environment::url_to_host(site_url()))) {
         $site_domain_url_regexp = Util_Environment::get_url_regexp(Util_Environment::url_to_host(site_url()));
     }
     if ($this->_config->get_boolean('cdn.uploads.enable')) {
         $upload_info = Util_Http::upload_info();
         if ($upload_info) {
             $baseurl = $upload_info['baseurl'];
             if (defined('DOMAIN_MAPPING') && DOMAIN_MAPPING) {
                 $parsed = @parse_url($upload_info['baseurl']);
                 $baseurl = home_url() . $parsed['path'];
             }
             $regexps = $this->make_uploads_regexes($domain_url_regexp, $baseurl, $upload_info, $regexps);
             if ($site_domain_url_regexp) {
                 $regexps = $this->make_uploads_regexes($site_domain_url_regexp, $baseurl, $upload_info, $regexps);
             }
         }
     }
     if ($this->_config->get_boolean('cdn.includes.enable')) {
         $mask = $this->_config->get_string('cdn.includes.files');
         if ($mask != '') {
             $regexps[] = '~(["\'(=])\\s*((' . $domain_url_regexp . ')?(' . Util_Environment::preg_quote($site_path . WPINC) . '/(' . Cdn_Util::get_regexp_by_mask($mask) . ')([^"\'() >]*)))~i';
             if ($site_domain_url_regexp) {
                 $regexps[] = '~(["\'(=])\\s*((' . $site_domain_url_regexp . ')?(' . Util_Environment::preg_quote($site_path . WPINC) . '/(' . Cdn_Util::get_regexp_by_mask($mask) . ')([^"\'() >]*)))~i';
             }
         }
     }
     if ($this->_config->get_boolean('cdn.theme.enable')) {
         $theme_dir = preg_replace('~' . $domain_url_regexp . '~i', '', get_theme_root_uri());
         $mask = $this->_config->get_string('cdn.theme.files');
         if ($mask != '') {
             $regexps[] = '~(["\'(=])\\s*((' . $domain_url_regexp . ')?(' . Util_Environment::preg_quote($theme_dir) . '/(' . Cdn_Util::get_regexp_by_mask($mask) . ')([^"\'() >]*)))~i';
             if ($site_domain_url_regexp) {
                 $theme_dir2 = preg_replace('~' . $site_domain_url_regexp . '~i', '', get_theme_root_uri());
                 $regexps[] = '~(["\'(=])\\s*((' . $site_domain_url_regexp . ')?(' . Util_Environment::preg_quote($theme_dir) . '/(' . Cdn_Util::get_regexp_by_mask($mask) . ')([^"\'() >]*)))~i';
                 $regexps[] = '~(["\'(=])\\s*((' . $site_domain_url_regexp . ')?(' . Util_Environment::preg_quote($theme_dir2) . '/(' . Cdn_Util::get_regexp_by_mask($mask) . ')([^"\'() >]*)))~i';
             }
         }
     }
     if ($this->_config->get_boolean('cdn.custom.enable')) {
         $masks = $this->_config->get_array('cdn.custom.files');
         $masks = array_map(array('\\W3TC\\Cdn_Util', 'replace_folder_placeholders'), $masks);
         $masks = array_map(array('\\W3TC\\Util_Environment', 'parse_path'), $masks);
         if (count($masks)) {
             $mask_regexps = array();
             foreach ($masks as $mask) {
                 if ($mask != '') {
                     $mask = Util_Environment::normalize_file($mask);
                     $mask_regexps[] = Cdn_Util::get_regexp_by_mask($mask);
                 }
             }
             $regexps[] = '~(["\'(=])\\s*((' . $domain_url_regexp . ')?(' . Util_Environment::preg_quote($site_path) . '(' . implode('|', $mask_regexps) . ')([^"\'() >]*)))~i';
             if ($site_domain_url_regexp) {
                 $regexps[] = '~(["\'(=])\\s*((' . $site_domain_url_regexp . ')?(' . Util_Environment::preg_quote($site_path) . '(' . implode('|', $mask_regexps) . ')([^"\'() >]*)))~i';
             }
         }
     }
     $this->_regexps = $regexps;
 }
 /**
  * Normalizes file name for minify
  *
  * Relative to document root!
  *
  * @param string  $file
  * @return string
  */
 public static function normalize_file_minify($file)
 {
     if (Util_Environment::is_url($file)) {
         if (strstr($file, '?') === false) {
             $domain_url_regexp = '~' . Util_Environment::home_domain_root_url_regexp() . '~i';
             $file = preg_replace($domain_url_regexp, '', $file);
         }
     }
     if (!Util_Environment::is_url($file)) {
         $file = Util_Environment::normalize_path($file);
         $file = str_replace(Util_Environment::document_root(), '', $file);
         $file = ltrim($file, '/');
     }
     return $file;
 }