예제 #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::getUserOrThemePath($app, '_category.html');
     $this->assertEquals($expected, $page->getPath());
 }
예제 #2
0
 private static function tryParseCategoryUri(IPieCrust $pieCrust, $blogKey, $uri, array &$pageInfo)
 {
     $blogKeyDir = '';
     if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
         $blogKeyDir = $blogKey . '/';
     }
     $categoryPageName = array();
     $themeCategoryPageName = array();
     $autoFormats = $pieCrust->getConfig()->getValueUnchecked('site/auto_formats');
     foreach ($autoFormats as $ext => $format) {
         $categoryPageName[] = $blogKeyDir . PieCrustDefaults::CATEGORY_PAGE_NAME . '.' . $ext;
         $themeCategoryPageName[] = PieCrustDefaults::CATEGORY_PAGE_NAME . '.' . $ext;
     }
     $path = PathHelper::getUserOrThemePath($pieCrust, $categoryPageName, $themeCategoryPageName);
     if ($path === false) {
         return false;
     }
     $flags = $pieCrust->getConfig()->getValueUnchecked('site/slugify_flags');
     $categoryPattern = UriBuilder::buildCategoryUriPattern($pieCrust->getConfig()->getValueUnchecked($blogKey . '/category_url'));
     if (preg_match($categoryPattern, $uri, $matches)) {
         $cat = rawurldecode($matches['cat']);
         $cat = UriBuilder::slugify($cat, $flags);
         $pageInfo['type'] = IPage::TYPE_CATEGORY;
         $pageInfo['blogKey'] = $blogKey;
         $pageInfo['key'] = $cat;
         $pageInfo['path'] = $path;
         $pageInfo['was_path_checked'] = true;
         return true;
     }
     return false;
 }
예제 #3
0
 protected function bakeTaxonomies()
 {
     // Get some global stuff we'll need.
     $slugifyFlags = $this->pieCrust->getConfig()->getValue('site/slugify_flags');
     $pageRepository = $this->pieCrust->getEnvironment()->getPageRepository();
     // Get the taxonomies.
     $taxonomies = array('tags' => array('multiple' => true, 'singular' => 'tag', 'page' => PieCrustDefaults::TAG_PAGE_NAME . '.html'), 'category' => array('multiple' => false, 'page' => PieCrustDefaults::CATEGORY_PAGE_NAME . '.html'));
     // Get which terms we need to bake.
     $allDirtyTaxonomies = $this->bakeRecord->getDirtyTaxonomies($taxonomies);
     $allUsedCombinations = $this->bakeRecord->getUsedTaxonomyCombinations($taxonomies);
     // Get the taxonomy listing pages, if they exist.
     $taxonomyPages = array();
     $blogKeys = $this->pieCrust->getConfig()->getValue('site/blogs');
     foreach ($taxonomies as $name => $taxonomyMetadata) {
         $taxonomyPages[$name] = array();
         foreach ($blogKeys as $blogKey) {
             $prefix = '';
             if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
                 $prefix = $blogKey . DIRECTORY_SEPARATOR;
             }
             $termPageName = $prefix . $taxonomyMetadata['page'];
             $themeTermPageName = $taxonomyMetadata['page'];
             $termPagePath = PathHelper::getUserOrThemePath($this->pieCrust, $termPageName, $themeTermPageName);
             $taxonomyPages[$name][$blogKey] = $termPagePath;
         }
     }
     foreach ($allDirtyTaxonomies as $name => $dirtyTerms) {
         $taxonomyMetadata = $taxonomies[$name];
         foreach ($dirtyTerms as $blogKey => $dirtyTermsForBlog) {
             // Check that we have a term listing page to bake.
             $termPagePath = $taxonomyPages[$name][$blogKey];
             if (!$termPagePath) {
                 continue;
             }
             // We have the terms that need to be rebaked.
             $termsToBake = $dirtyTermsForBlog;
             // Look at the combinations of terms we need to consider.
             if ($taxonomyMetadata['multiple']) {
                 // User-specified combinations.
                 $forcedCombinations = array();
                 $forcedCombinationParameters = array($name . '_combinations');
                 if (isset($taxonomyMetadata['singular'])) {
                     $forcedCombinationParameters[] = $taxonomyMetadata['singular'] . '_combinations';
                 }
                 foreach ($forcedCombinationParameters as $param) {
                     if (isset($this->parameters[$param])) {
                         $forcedCombinations = $this->parameters[$param];
                         if (array_key_exists($blogKey, $forcedCombinations)) {
                             $forcedCombinations = $forcedCombinations[$blogKey];
                         } elseif (count($blogKeys > 1)) {
                             $forcedCombinations = array();
                         }
                         break;
                     }
                 }
                 // Collected combinations in use.
                 $usedCombinations = array();
                 if (isset($allUsedCombinations[$name]) && isset($allUsedCombinations[$name][$blogKey])) {
                     $usedCombinations = $allUsedCombinations[$name][$blogKey];
                 }
                 // Get all the combinations together (forced and used) and keep
                 // those that include a term that we have to rebake.
                 $combinations = array_merge($forcedCombinations, $usedCombinations);
                 if ($combinations) {
                     $combinationsToBake = array();
                     foreach ($combinations as $comb) {
                         if (count(array_intersect($comb, $termsToBake)) > 0) {
                             $combinationsToBake[] = $comb;
                         }
                     }
                     $termsToBake = array_merge($termsToBake, $combinationsToBake);
                 }
             }
             // Order terms so it looks nice when we bake.
             usort($termsToBake, function ($t1, $t2) {
                 if (is_array($t1)) {
                     $t1 = implode('+', $t1);
                 }
                 if (is_array($t2)) {
                     $t2 = implode('+', $t2);
                 }
                 return strcmp($t1, $t2);
             });
             // Bake!
             foreach ($termsToBake as $term) {
                 $start = microtime(true);
                 if ($taxonomyMetadata['multiple'] && is_array($term)) {
                     $slugifiedTerm = array_map(function ($t) use($slugifyFlags) {
                         return UriBuilder::slugify($t, $slugifyFlags);
                     }, $term);
                     $formattedTerm = implode('+', array_map('rawurldecode', $term));
                 } else {
                     $slugifiedTerm = UriBuilder::slugify($term, $slugifyFlags);
                     $formattedTerm = rawurldecode($term);
                 }
                 if ($name == 'tags') {
                     $uri = UriBuilder::buildTagUri($this->pieCrust, $blogKey, $slugifiedTerm, false);
                     $pageType = IPage::TYPE_TAG;
                 } else {
                     if ($name == 'category') {
                         $uri = UriBuilder::buildCategoryUri($this->pieCrust, $blogKey, $slugifiedTerm, false);
                         $pageType = IPage::TYPE_CATEGORY;
                     }
                 }
                 $page = $pageRepository->getOrCreatePage($uri, $termPagePath, $pageType, $blogKey);
                 $page->setPageKey($slugifiedTerm);
                 $this->callAssistants('onPageBakeStart', array($page));
                 $baker = $this->getPageBaker();
                 $baker->bake($page);
                 $this->callAssistants('onPageBakeEnd', array($page, new BakeResult(true)));
                 $pageCount = $baker->getPageCount();
                 $this->logger->info(self::formatTimed($start, "{$name}:{$formattedTerm}" . ($pageCount > 1 ? " [{$pageCount}]" : "")));
             }
         }
     }
 }