Moved gzip and aggressive_optimize_html calls to output.php
authorDan
Sun, 15 Mar 2009 11:09:02 -0400
changeset 867 fc4e242995d4
parent 866 0a691138a1e5
child 868 75dcd8cf6232
Moved gzip and aggressive_optimize_html calls to output.php
includes/output.php
index.php
--- a/includes/output.php	Sun Mar 15 11:08:07 2009 -0400
+++ b/includes/output.php	Sun Mar 15 11:09:02 2009 -0400
@@ -163,6 +163,24 @@
     echo $template->getFooter();
     echo $this->after_footer;
     
+    global $aggressive_optimize_html;
+    if ( $aggressive_optimize_html )
+    {
+      $content = ob_get_contents();
+      ob_end_clean();
+      
+      ob_start();
+      echo aggressive_optimize_html($content);
+    }
+    else
+    {
+      $content = ob_get_contents();
+      ob_end_clean();
+      
+      ob_start();
+      echo preg_replace('~</?enano:no-opt>~', '', $content);
+    }
+    
   }
   
   public function set_title($title)
@@ -175,6 +193,51 @@
 }
 
 /**
+ * Same as HTML, except uses simple-header and simple-footer.
+ */
+
+class Output_HTML_Simple extends Output_HTML
+{
+  public function footer()
+  {
+    global $template;
+    if ( !$this->headers_sent )
+      return;
+    
+    $this->headers_sent = false;
+    $content = ob_get_contents();
+    ob_end_clean();
+    
+    ob_start();
+    echo $this->before_header;
+    echo $template->getHeader(true);
+    echo $this->after_header;
+    echo $content;
+    echo $this->before_footer;
+    echo $template->getFooter(true);
+    echo $this->after_footer;
+    
+    global $aggressive_optimize_html;
+    if ( $aggressive_optimize_html )
+    {
+      $content = ob_get_contents();
+      ob_end_clean();
+      
+      ob_start();
+      echo aggressive_optimize_html($content);
+    }
+    else
+    {
+      $content = ob_get_contents();
+      ob_end_clean();
+      
+      ob_start();
+      echo preg_replace('~</?enano:no-opt>~', '', $content);
+    }
+  }
+}
+
+/**
  * Outputter that bypasses $template->header() and $template->footer(), but still shows HTML added via {before,after}_{header,footer}.
  */
 
--- a/index.php	Sun Mar 15 11:08:07 2009 -0400
+++ b/index.php	Sun Mar 15 11:09:02 2009 -0400
@@ -575,40 +575,24 @@
       break;
   }
   
-  //
-  // Optimize HTML by replacing newlines with spaces (excludes <pre>, <script>, and <style> blocks)
-  //
-  if ($aggressive_optimize_html)
+  // Generate an ETag
+  /*
+  // format: first 10 digits of SHA1 of page name, user id in hex, user and auth levels, page timestamp in hex
+  $etag = substr(sha1($paths->namespace . ':' . $paths->page_id), 0, 10) . '-' .
+          "u{$session->user_id}l{$session->user_level}a{$session->auth_level}-" .
+          dechex($page_timestamp);
+          
+  if ( isset($_SERVER['HTTP_IF_NONE_MATCH']) )
   {
-    // Load up the HTML
-    $html = ob_get_contents();
-    @ob_end_clean();
-    
-    $html = aggressive_optimize_html($html);
-    
-    // Re-enable output buffering to allow the Gzip function (below) to work
-    ob_start();
-    
-    // Generate an ETag
-    // format: first 10 digits of SHA1 of page name, user id in hex, user and auth levels, page timestamp in hex
-    $etag = substr(sha1($paths->namespace . ':' . $paths->page_id), 0, 10) . '-' .
-            "u{$session->user_id}l{$session->user_level}a{$session->auth_level}-" .
-            dechex($page_timestamp);
+    if ( "\"$etag\"" == $_SERVER['HTTP_IF_NONE_MATCH'] )
+    {
+      header('HTTP/1.1 304 Not Modified');
+      exit();
+    }
+  }
             
-    if ( isset($_SERVER['HTTP_IF_NONE_MATCH']) )
-    {
-      if ( "\"$etag\"" == $_SERVER['HTTP_IF_NONE_MATCH'] )
-      {
-        header('HTTP/1.1 304 Not Modified');
-        exit();
-      }
-    }
-            
-    // header("ETag: \"$etag\"");
-    
-    // Done, send it to the user
-    echo( $html );
-  }
+  header("ETag: \"$etag\"");
+  */
   
   $db->close();  
   gzip_output();