/**
  * "Minify" an HTML page
  *
  * @param string $html
  *
  * @param array $options
  *
  * 'cssMinifier' : (optional) callback function to process content of STYLE
  * elements.
  * 
  * 'jsMinifier' : (optional) callback function to process content of SCRIPT
  * elements. Note: the type attribute is ignored.
  * 
  * 'xhtml' : (optional boolean) should content be treated as XHTML1.0? If
  * unset, minify will sniff for an XHTML doctype.
  * 
  * @return string
  */
 public static function minify($html, $options = array())
 {
     $min = new Brim_PageCache_Model_Minify_HTML($html, $options);
     return $min->process();
 }
 /**
  * Handles logic for caching pages.  Currently checks the root block for the
  * "CachePageFlag".  Pages are only cached if the user is not logged in and does
  * not have items in their cart.
  *
  * @param $observer
  * @return void
  */
 public function cachePage(Zend_Controller_Response_Http $response)
 {
     // Check if cache flag is set
     $rootBlock = Mage::app()->getLayout()->getBlock('root');
     if ($rootBlock && $rootBlock->getCachePageFlag()) {
         if ($this->passesConditions($rootBlock->getCachePageConditions())) {
             $cache = Mage::app()->getCache();
             $id = $this->generateFPCId();
             if ($rootBlock->getCachePageExpires() > 0) {
                 $expires = $rootBlock->getCachePageExpires();
             } else {
                 //default expires
                 $expires = Mage::getStoreConfig(Brim_PageCache_Model_Config::XML_PATH_EXPIRES);
             }
             $storageObject = Mage::getModel('brim_pagecache/storage');
             if (Mage::getStoreConfig(Brim_PageCache_Model_Config::XML_PATH_ENABLE_MINIFY_HTML)) {
                 // Minify the response body.  Helps save on cache storage space
                 // Basic grouped product page 34k in size was about 28K minified,
                 $minifyBody = Brim_PageCache_Model_Minify_HTML::minify($response->getBody());
                 $response->setBody($minifyBody);
             }
             $storageObject->setResponse($response);
             /**
              * Block update data contains partial layouts for each block.  Allows us to regenerate each one
              * with out loosing customizations.
              */
             $storageObject->setBlockUpdateData($this->getBlockUpdateData());
             // Set the expected expires time for this page
             $date = Mage::app()->getLocale()->date()->addSecond($expires);
             $storageObject->setData(self::RESPONSE_HEADER_EXPIRES_DATE, $date->get(Zend_Date::RFC_1123));
             $storageObject->setData(self::RESPONSE_HEADER_EXPIRES, $expires);
             $storageObject->setData(self::RESPONSE_HEADER_CONDITIONS, $rootBlock->getCachePageConditions());
             $storageObject->setData(self::RESPONSE_HEADER_STORE, Mage::app()->getStore()->getCode());
             $storageObject->setData(self::RESPONSE_HEADER_ORIG_TIME, microtime(true) - self::$_start_time);
             $this->debug('Saving page with cache id : ' . $id);
             if (($product = Mage::registry('product')) != null) {
                 $this->devDebug('Registering Tag: ' . self::FPC_TAG . '_PRODUCT_' . $product->getId());
                 $this->registerPageTags(self::FPC_TAG . '_PRODUCT_' . $product->getId());
             }
             if (($category = Mage::registry('current_category')) != null && $product == null) {
                 $this->devDebug('Registering Tag: ' . self::FPC_TAG . '_CATEGORY_' . $category->getId());
                 $this->registerPageTags(self::FPC_TAG . '_CATEGORY_' . $category->getId());
             }
             $cache->save(serialize($storageObject), $id, $this->getPageTags(), $expires);
         } else {
             // failed conditions
             if ($response->canSendHeaders(false)) {
                 $response->setHeader(self::RESPONSE_HEADER_FAILED, $this->_failed_conditions);
             }
         }
     } else {
         if ($response->canSendHeaders(false)) {
             // page not set to cache
             $response->setHeader(self::RESPONSE_HEADER_FAILED, 'no_cache');
         }
     }
 }