Пример #1
0
 public function testCreateDefaultCategoryPage()
 {
     $app = MockFileSystem::create()->withConfig(array('site' => array('category_url' => 'cat/%category%')))->getApp();
     $page = Page::createFromUri($app, '/cat/foo');
     $expected = PathHelper::getUserOrThemeOrResPath($app, '_category.html');
     $this->assertEquals($expected, $page->getPath());
 }
Пример #2
0
 protected function bakeCategories()
 {
     if ($this->bakeRecord == null) {
         throw new PieCrustException("Can't bake categories without a bake-record active.");
     }
     $blogKeys = $this->pieCrust->getConfig()->getValueUnchecked('site/blogs');
     foreach ($blogKeys as $blogKey) {
         // Check that there is a category listing page to bake.
         $prefix = '';
         if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
             $prefix = $blogKey . DIRECTORY_SEPARATOR;
         }
         $categoryPageName = $prefix . PieCrustDefaults::CATEGORY_PAGE_NAME . '.html';
         $categoryPagePath = PathHelper::getUserOrThemeOrResPath($this->pieCrust, $categoryPageName);
         if ($categoryPagePath === false) {
             continue;
         }
         // Order categories so it looks nicer when we bake.
         $categoriesToBake = $this->bakeRecord->getCategoriesToBake($blogKey);
         sort($categoriesToBake);
         // Bake!
         $pageRepository = $this->pieCrust->getEnvironment()->getPageRepository();
         foreach ($categoriesToBake as $category) {
             $start = microtime(true);
             $postInfos = $this->bakeRecord->getPostsInCategory($blogKey, $category);
             if (count($postInfos) > 0) {
                 $uri = UriBuilder::buildCategoryUri($this->pieCrust->getConfig()->getValue($blogKey . '/category_url'), $category);
                 $page = $pageRepository->getOrCreatePage($uri, $categoryPagePath, IPage::TYPE_CATEGORY, $blogKey, $category);
                 $baker = new PageBaker($this->getBakeDir(), $this->getPageBakerParameters());
                 $baker->bake($page);
                 $pageCount = $baker->getPageCount();
                 $this->logger->info(self::formatTimed($start, 'category:' . $category . ($pageCount > 1 ? " [{$pageCount}]" : "")));
             }
         }
     }
 }
Пример #3
0
 private static function tryParseCategoryUri(IPieCrust $pieCrust, $blogKey, $uri, array &$pageInfo)
 {
     $blogKeyDir = '';
     if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
         $blogKeyDir = $blogKey . '/';
     }
     $relativeTagPage = $blogKeyDir . PieCrustDefaults::CATEGORY_PAGE_NAME . '.html';
     $path = PathHelper::getUserOrThemeOrResPath($pieCrust, $relativeTagPage);
     if ($path === false) {
         return false;
     }
     $categoryPattern = UriBuilder::buildCategoryUriPattern($pieCrust->getConfig()->getValueUnchecked($blogKey . '/category_url'));
     if (preg_match($categoryPattern, $uri, $matches)) {
         $pageInfo['type'] = IPage::TYPE_CATEGORY;
         $pageInfo['blogKey'] = $blogKey;
         $pageInfo['key'] = $matches['cat'];
         $pageInfo['path'] = $path;
         $pageInfo['was_path_checked'] = true;
         return true;
     }
     return false;
 }