/**
  * Processes script tag
  *
  * @param unknown $script_tag
  * @return void
  */
 private function process_script_tag($script_tag, $script_tag_number)
 {
     if ($this->debug) {
         Minify_Core::log('processing tag ' . substr($script_tag, 0, 150));
     }
     $tag_pos = strpos($this->buffer, $script_tag);
     if ($tag_pos === false) {
         // script is external but not found, skip processing it
         error_log('script not found:' . $script_tag);
         Minify_Core::log('script not found:' . $script_tag);
         return;
     }
     $match = null;
     if (!preg_match('~<script\\s+[^<>]*src=["\']?([^"\'> ]+)["\'> ]~is', $script_tag, $match)) {
         $match = null;
     }
     if (is_null($match)) {
         $data = array('script_tag_original' => $script_tag, 'script_tag_new' => $script_tag, 'script_tag_number' => $script_tag_number, 'script_tag_pos' => $tag_pos, 'should_replace' => false, 'buffer' => $this->buffer);
         $data = apply_filters('w3tc_minify_js_do_local_script_minification', $data);
         $this->buffer = $data['buffer'];
         if ($data['should_replace']) {
             $this->buffer = substr_replace($this->buffer, $data['script_tag_new'], $tag_pos, strlen($script_tag));
         }
         // it's not external script, have to flush what we have before it
         if ($this->debug) {
             Minify_Core::log('its not src=, flushing');
         }
         $this->flush_collected($script_tag);
         if (preg_match('~</head>~is', $script_tag, $match)) {
             $this->group_type = 'body';
         }
         return;
     }
     $script_src = $match[1];
     $script_src = Util_Environment::url_relative_to_full($script_src);
     $file = Util_Environment::url_to_docroot_filename($script_src);
     $step1 = $this->minify_helpers->is_file_for_minification($file);
     $step2 = !in_array($file, $this->ignore_js_files);
     $do_tag_minification = $step1 && $step2;
     $do_tag_minification = apply_filters('w3tc_minify_js_do_tag_minification', $do_tag_minification, $script_tag, $file);
     if (!$do_tag_minification) {
         if ($this->debug) {
             Minify_Core::log('file ' . $file . ' didnt pass minification check:' . ' file_for_min: ' . ($step1 ? 'true' : 'false') . ' ignore_js_files: ' . ($step2 ? 'true' : 'false'));
         }
         $data = array('script_tag_original' => $script_tag, 'script_tag_new' => $script_tag, 'script_tag_number' => $script_tag_number, 'script_tag_pos' => $tag_pos, 'script_src' => $script_src, 'should_replace' => false, 'buffer' => $this->buffer);
         $data = apply_filters('w3tc_minify_js_do_excluded_tag_script_minification', $data);
         $this->buffer = $data['buffer'];
         if ($data['should_replace']) {
             $this->buffer = substr_replace($this->buffer, $data['script_tag_new'], $tag_pos, strlen($script_tag));
         }
         $this->flush_collected($script_tag);
         return;
     }
     $this->debug_minified_urls[] = $file;
     $this->buffer = substr_replace($this->buffer, '', $tag_pos, strlen($script_tag));
     // for head group - put minified file at the place of first script
     // for body - put at the place of last script, to make as more DOM
     // objects available as possible
     if (count($this->files_to_minify) <= 0 || $this->group_type == 'body') {
         $this->embed_pos = $tag_pos;
     }
     $this->files_to_minify[] = $file;
 }
 public function debug_error($error)
 {
     Minify_Core::debug_error($error);
 }
 /**
  * Checks rewrite
  *
  * @throws Util_Environment_Exceptions
  */
 private function verify_rewrite_working()
 {
     $url = Minify_Core::minified_url(rand() . 'w3tc_rewrite_test.css');
     $result = $this->test_rewrite($url);
     if ($result != 'ok') {
         $home_url = get_home_url();
         $tech_message = (Util_Environment::is_nginx() ? 'nginx configuration file' : '.htaccess file') . ' contains rules to rewrite url ' . $url . '. If handled by ' . 'plugin, it returns "OK" message.<br/>';
         $tech_message .= 'The plugin made a request to ' . $url . ' but received: <br />' . $result . '<br />';
         $tech_message .= 'instead of "OK" response. <br />';
         $error = '<strong>W3 Total Cache error:</strong>It appears Minify ' . '<acronym title="Uniform Resource Locator">URL</acronym> ' . 'rewriting is not working. ';
         if (Util_Environment::is_nginx()) {
             $error .= 'Please verify that all configuration files are ' . 'included in the configuration file ' . '(and that you have reloaded / restarted nginx).';
         } else {
             $error .= 'Please verify that the server configuration ' . 'allows .htaccess';
         }
         $error .= '<br />Unfortunately minification will ' . 'not function without custom rewrite rules. ' . 'Please ask your server administrator for assistance. ' . 'Also refer to <a href="' . admin_url('admin.php?page=w3tc_install') . '">the install page</a>  for the rules for your server.';
         throw new Util_Environment_Exception($error, $tech_message);
     }
 }
Ejemplo n.º 4
0
 /**
  * Sends error response
  *
  * @param string  $error
  * @param boolean $handle
  * @param integer $status
  * @return void
  */
 public static function debug_error($error)
 {
     $c = Dispatcher::config();
     $debug = $c->get_boolean('minify.debug');
     if ($debug) {
         Minify_Core::log($error);
         echo "\r\n/* " . htmlspecialchars($error) . " */\r\n";
     }
 }