Exemplo n.º 1
0
 /**
  * @dataProvider buildTagUriDataProvider
  */
 public function testBuildTagUri($tag, $expectedUri)
 {
     $pc = new MockPieCrust();
     $pc->getConfig()->setValue('blog/tag_url', '/%tag%');
     $uri = UriBuilder::buildTagUri($pc, 'blog', $tag);
     $this->assertEquals($expectedUri, $uri);
 }
 public function getTagUrl($value, $blogKey = null)
 {
     if ($this->linkCollector) {
         $this->linkCollector->registerTagCombination($blogKey == null ? $this->defaultBlogKey : $blogKey, $value);
     }
     $format = $blogKey == null ? $this->tagUrlFormat : $pieCrust->getConfig()->getValueUnchecked($blogKey . '/tag_url');
     return PieCrustHelper::formatUri($this->pieCrust, UriBuilder::buildTagUri($format, $value));
 }
Exemplo n.º 3
0
 public function getTagUrl($value, $blogKey = null)
 {
     $blogKey = $this->getSafeBlogKey($blogKey);
     if ($this->linkCollector) {
         $this->linkCollector->registerTagCombination($blogKey, $value);
     }
     return PieCrustHelper::formatUri($this->pieCrust, UriBuilder::buildTagUri($this->pieCrust, $blogKey, $value));
 }
Exemplo n.º 4
0
 protected function bakeTags()
 {
     if ($this->bakeRecord == null) {
         throw new PieCrustException("Can't bake tags without a bake-record active.");
     }
     $blogKeys = $this->pieCrust->getConfig()->getValueUnchecked('site/blogs');
     foreach ($blogKeys as $blogKey) {
         // Check that there is a tag listing page to bake.
         $prefix = '';
         if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
             $prefix = $blogKey . DIRECTORY_SEPARATOR;
         }
         $tagPageName = $prefix . PieCrustDefaults::TAG_PAGE_NAME . '.html';
         $tagPagePath = PathHelper::getUserOrThemeOrResPath($this->pieCrust, $tagPageName);
         if ($tagPagePath === false) {
             continue;
         }
         // Get single and multi tags to bake.
         $tagsToBake = $this->bakeRecord->getTagsToBake($blogKey);
         $combinations = $this->parameters['tag_combinations'];
         if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
             if (array_key_exists($blogKey, $combinations)) {
                 $combinations = $combinations[$blogKey];
             } else {
                 $combinations = array();
             }
         }
         $lastKnownCombinations = $this->bakeRecord->getLast('knownTagCombinations');
         if (array_key_exists($blogKey, $lastKnownCombinations)) {
             $combinations = array_merge($combinations, $lastKnownCombinations[$blogKey]);
             $combinations = array_unique($combinations);
         }
         if (count($combinations) > 0) {
             // Filter combinations that contain tags that got invalidated.
             $combinationsToBake = array();
             foreach ($combinations as $comb) {
                 $explodedComb = explode('/', $comb);
                 if (count(array_intersect($explodedComb, $tagsToBake)) > 0) {
                     $combinationsToBake[] = $explodedComb;
                 }
             }
             $tagsToBake = array_merge($combinationsToBake, $tagsToBake);
         }
         // Order tags so it looks nice when we bake.
         usort($tagsToBake, function ($t1, $t2) {
             if (is_array($t1)) {
                 $t1 = implode('+', $t1);
             }
             if (is_array($t2)) {
                 $t2 = implode('+', $t2);
             }
             return strcmp($t1, $t2);
         });
         // Bake!
         $pageRepository = $this->pieCrust->getEnvironment()->getPageRepository();
         foreach ($tagsToBake as $tag) {
             $start = microtime(true);
             $formattedTag = $tag;
             if (is_array($tag)) {
                 $formattedTag = implode('+', $tag);
             }
             $postInfos = $this->bakeRecord->getPostsTagged($blogKey, $tag);
             if (count($postInfos) > 0) {
                 $uri = UriBuilder::buildTagUri($this->pieCrust->getConfig()->getValue($blogKey . '/tag_url'), $tag);
                 $page = $pageRepository->getOrCreatePage($uri, $tagPagePath, IPage::TYPE_TAG, $blogKey, $tag);
                 $baker = new PageBaker($this->getBakeDir(), $this->getPageBakerParameters());
                 $baker->bake($page);
                 $pageCount = $baker->getPageCount();
                 $this->logger->info(self::formatTimed($start, 'tag:' . $formattedTag . ($pageCount > 1 ? " [{$pageCount}]" : "")));
             }
         }
     }
 }
Exemplo n.º 5
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}]" : "")));
             }
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Gets a tag listing page.
  */
 public static function getTagPage(IPieCrust $pieCrust, $tag, $blogKey = null)
 {
     if ($blogKey == null) {
         $blogKeys = $pieCrust->getConfig()->getValueUnchecked('site/blogs');
         $blogKey = $blogKeys[0];
     }
     $pathPrefix = '';
     if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
         $pathPrefix = $blogKey . DIRECTORY_SEPARATOR;
     }
     $pageRepository = $pieCrust->getEnvironment()->getPageRepository();
     $uri = UriBuilder::buildTagUri($pieCrust->getConfig()->getValue($blogKey . '/tag_url'), $tag);
     $path = $pieCrust->getPagesDir() . $pathPrefix . PieCrustDefaults::TAG_PAGE_NAME . '.html';
     if (!is_file($path)) {
         return null;
     }
     $page = $pageRepository->getOrCreatePage($uri, $tagPagePath, IPage::TYPE_TAG, $blogKey, $tag);
     return $page;
 }
Exemplo n.º 7
0
 /**
  * @dataProvider buildTagUriDataProvider
  */
 public function testBuildTagUri($tag, $expectedUri)
 {
     $uri = UriBuilder::buildTagUri('/%tag%', $tag);
     $this->assertEquals($expectedUri, $uri);
 }