/** * Bakes the website. */ public function bake() { $overallStart = microtime(true); // Pre-bake notification. $this->callAssistants('onBakeStart', array($this)); // Display debug information. $this->logger->debug(" Bake Output: " . $this->getBakeDir()); $this->logger->debug(" Root URL: " . $this->pieCrust->getConfig()->getValue('site/root')); // Setup the PieCrust environment. if ($this->parameters['copy_assets']) { $this->pieCrust->getEnvironment()->getPageRepository()->setAssetUrlBaseRemap('%site_root%%uri%'); } $this->pieCrust->getConfig()->setValue('baker/is_baking', true); // Create the bake record. $bakeRecordPath = false; $this->bakeRecord = new TransitionalBakeRecord($this->pieCrust); if ($this->pieCrust->isCachingEnabled()) { $start = microtime(true); $bakeRecordPath = $this->pieCrust->getCacheDir() . self::BAKE_RECORD_PATH . md5($this->getBakeDir()) . DIRECTORY_SEPARATOR . 'record.json'; $this->bakeRecord->loadPrevious($bakeRecordPath); $this->logger->debug(self::formatTimed($start, "loaded bake record")); } // Create the execution context. $executionContext = $this->pieCrust->getEnvironment()->getExecutionContext(true); // Get the cache validity information. $cacheInfo = new PieCrustCacheInfo($this->pieCrust); $cacheValidity = $cacheInfo->getValidity(false); $executionContext->isCacheValid = $cacheValidity['is_valid']; // Figure out if we need to clean the cache. $this->parameters['__smart_content'] = $this->parameters['smart']; if ($this->pieCrust->isCachingEnabled()) { if ($this->cleanCacheIfNeeded($cacheValidity)) { $executionContext->wasCacheCleaned = true; $this->parameters['__smart_content'] = false; } else { // If we didn't clean the cache, at least clean the level 0 bake cache, // where bake-only plugins can cache things. $this->cleanLevel0Cache(); } } $this->ensureLevel0Cache(); // Bake! $this->bakePosts(); $this->bakePages(); $this->bakeTaxonomies(); $dirBaker = new DirectoryBaker($this->pieCrust, $this->getBakeDir(), array('smart' => $this->parameters['smart'], 'mounts' => $this->parameters['mounts'], 'processors' => $this->parameters['processors'], 'skip_patterns' => $this->parameters['skip_patterns'], 'force_patterns' => $this->parameters['force_patterns']), $this->logger); $dirBaker->bake(); $this->bakeRecord->getCurrent()->addAssetEntries($dirBaker->getBakedFiles()); $this->handleDeletions(); // Post-bake notification. $this->callAssistants('onBakeEnd', array($this)); // Save the bake record and clean up. if ($bakeRecordPath) { $start = microtime(true); $this->bakeRecord->collapse(); $this->bakeRecord->saveCurrent($bakeRecordPath); $this->logger->debug(self::formatTimed($start, "saved bake record")); } $this->bakeRecord = null; $this->pieCrust->getConfig()->setValue('baker/is_baking', false); $this->logger->info('-------------------------'); $this->logger->notice(self::formatTimed($overallStart, 'done baking')); }
/** * Bakes the website. */ public function bake() { $overallStart = microtime(true); // Display the banner. $bannerLevel = PEAR_LOG_DEBUG; if ($this->parameters['info_only']) { $bannerLevel = PEAR_LOG_NOTICE; } $this->logger->log("PieCrust Baker v." . PieCrustDefaults::VERSION, $bannerLevel); $this->logger->log(" website : " . $this->pieCrust->getRootDir(), $bannerLevel); $this->logger->log(" output : " . $this->getBakeDir(), $bannerLevel); $this->logger->log(" url : " . $this->pieCrust->getConfig()->getValueUnchecked('site/root'), $bannerLevel); if ($this->parameters['info_only']) { return; } // Setup the PieCrust environment. if ($this->parameters['copy_assets']) { $this->pieCrust->getEnvironment()->getPageRepository()->setAssetUrlBaseRemap('%site_root%%uri%'); } $this->pieCrust->getConfig()->setValue('baker/is_baking', true); // Create the bake record. $blogKeys = $this->pieCrust->getConfig()->getValueUnchecked('site/blogs'); $bakeInfoPath = false; if ($this->pieCrust->isCachingEnabled()) { $bakeInfoPath = $this->pieCrust->getCacheDir() . self::BAKE_INFO_FILE; } $this->bakeRecord = new BakeRecord($blogKeys, $bakeInfoPath); // Get the cache validity information. $cacheInfo = new PieCrustCacheInfo($this->pieCrust); $cacheValidity = $cacheInfo->getValidity(false); // Figure out if we need to clean the cache. if ($this->pieCrust->isCachingEnabled()) { $this->cleanCacheIfNeeded($cacheValidity); } // Bake! $this->bakePosts(); $this->bakePages(); $this->bakeRecord->collectTagCombinations($this->pieCrust->getEnvironment()->getLinkCollector()); $this->bakeTags(); $this->bakeCategories(); $dirBaker = new DirectoryBaker($this->pieCrust, $this->getBakeDir(), array('smart' => $this->parameters['smart'], 'mounts' => $this->parameters['mounts'], 'processors' => $this->parameters['processors'], 'skip_patterns' => $this->parameters['skip_patterns'], 'force_patterns' => $this->parameters['force_patterns']), $this->logger); $dirBaker->bake(); // Save the bake record and clean up. if ($bakeInfoPath) { $this->bakeRecord->saveBakeInfo($bakeInfoPath); } $this->bakeRecord = null; $this->pieCrust->getConfig()->setValue('baker/is_baking', false); $this->logger->info('-------------------------'); $this->logger->notice(self::formatTimed($overallStart, 'done baking')); }
/** * Runs PieCrust on the given URI with the given extra page rendering data, * but without any error handling. */ public function runUnsafe($uri = null, array $server = null, $extraPageData = null, array &$headers = null) { // Create an execution context. $executionContext = $this->pieCrust->getEnvironment()->getExecutionContext(true); // Check the cache validity, and clean it automatically. if ($this->pieCrust->isCachingEnabled()) { $cacheInfo = new PieCrustCacheInfo($this->pieCrust); $cacheValidity = $cacheInfo->getValidity(true); $executionContext->isCacheValid = $cacheValidity['is_valid']; $executionContext->wasCacheCleaned = $cacheValidity['was_cleaned']; } // Get the resource URI and corresponding physical path. if ($server == null) { $server = $_SERVER; } if ($uri == null) { $uri = ServerHelper::getRequestUri($server, $this->pieCrust->getConfig()->getValueUnchecked('site/pretty_urls')); } // Do the heavy lifting. $page = Page::createFromUri($this->pieCrust, $uri); $executionContext->pushPage($page); if ($extraPageData != null) { $page->setExtraPageData($extraPageData); } $pageRenderer = new PageRenderer($page); $output = $pageRenderer->get(); // Set or return the HTML headers. HttpHeaderHelper::setOrAddHeaders(PageRenderer::getHeaders($page->getConfig()->getValue('content_type'), $server), $headers); // Handle caching. if (!$this->pieCrust->isDebuggingEnabled()) { $hash = md5($output); HttpHeaderHelper::setOrAddHeader('Etag', '"' . $hash . '"', $headers); $clientHash = null; if (isset($server['HTTP_IF_NONE_MATCH'])) { $clientHash = $server['HTTP_IF_NONE_MATCH']; } if ($clientHash != null) { $clientHash = trim($clientHash, '"'); if ($hash == $clientHash) { HttpHeaderHelper::setOrAddHeader(0, 304, $headers); HttpHeaderHelper::setOrAddHeader('Content-Length', '0', $headers); return; } } } if ($this->pieCrust->isDebuggingEnabled()) { HttpHeaderHelper::setOrAddHeader('Cache-Control', 'no-cache, must-revalidate', $headers); } else { $cacheTime = PageHelper::getConfigValue($page, 'cache_time', 'site'); if ($cacheTime) { HttpHeaderHelper::setOrAddHeader('Cache-Control', 'public, max-age=' . $cacheTime, $headers); } } // Output with or without GZip compression. $gzipEnabled = ($this->pieCrust->getConfig()->getValueUnchecked('site/enable_gzip') === true and array_key_exists('HTTP_ACCEPT_ENCODING', $server) and strpos($server['HTTP_ACCEPT_ENCODING'], 'gzip') !== false); if ($gzipEnabled) { $zippedOutput = gzencode($output); if ($zippedOutput === false) { HttpHeaderHelper::setOrAddHeader('Content-Length', strlen($output), $headers); echo $output; } else { HttpHeaderHelper::setOrAddHeader('Content-Encoding', 'gzip', $headers); HttpHeaderHelper::setOrAddHeader('Content-Length', strlen($zippedOutput), $headers); echo $zippedOutput; } } else { HttpHeaderHelper::setOrAddHeader('Content-Length', strlen($output), $headers); echo $output; } }