예제 #1
0
 private function addAutomaticLocations($sitemap, $xml)
 {
     if (!isset($sitemap['autogen'])) {
         return;
     }
     $autogen = $sitemap['autogen'];
     if (isset($autogen['pages']) && $autogen['pages']) {
         foreach ($this->pieCrust->getEnvironment()->getPages() as $page) {
             $xml->startElement('url');
             $xml->writeElement('loc', PieCrustHelper::formatUri($this->pieCrust, $page->getUri()));
             $xml->writeElement('lastmod', date('c'));
             $xml->endElement();
         }
     }
     if (isset($autogen['posts']) && $autogen['posts']) {
         $blogKeys = $this->pieCrust->getConfig()->getValueUnchecked('site/blogs');
         foreach ($blogKeys as $blogKey) {
             foreach ($this->pieCrust->getEnvironment()->getPosts($blogKey) as $page) {
                 $xml->startElement('url');
                 $xml->writeElement('loc', PieCrustHelper::formatUri($this->pieCrust, $page->getUri()));
                 $xml->writeElement('lastmod', date('c'));
                 $xml->endElement();
             }
         }
     }
 }
예제 #2
0
 /**
  * @dataProvider formatUriDataProviderWhenBaked
  */
 public function testFormatUriWhenBaked($pageUri, $expectedUri, $siteRoot = '/', $prettyUrls = true, $debug = false, $trailingSlash = false)
 {
     $fs = MockFileSystem::create();
     $fs->withConfig(array('site' => array('root' => $siteRoot, 'pretty_urls' => $prettyUrls), 'baker' => array('is_baking' => true, 'trailing_slash' => $trailingSlash)));
     $pc = new PieCrust(array('root' => $fs->getAppRoot(), 'cache' => false, 'debug' => $debug));
     $uri = PieCrustHelper::formatUri($pc, $pageUri);
     $this->assertEquals($expectedUri, $uri);
 }
예제 #3
0
 protected function addCustomValues()
 {
     $post = $this->page;
     $pieCrust = $this->page->getApp();
     $blogKey = $this->page->getConfig()->getValueUnchecked('blog');
     $postsDateFormat = PageHelper::getConfigValueUnchecked($this->page, 'date_format', $blogKey);
     // Add the easy values to the values array.
     $this->values['url'] = PieCrustHelper::formatUri($pieCrust, $post->getUri());
     $this->values['slug'] = $post->getUri();
     $this->values['timestamp'] = $post->getDate();
     //TODO: do we need to move this to the lazy-loaded values?
     $this->values['date'] = date($postsDateFormat, $post->getDate());
     // Add some lazy-loading functions for stuff
     // that would load the page's contents.
     $this->lazyValues[self::WILDCARD] = 'loadContent';
 }
예제 #4
0
 protected function addCustomValues()
 {
     $post = $this->page;
     $pieCrust = $post->getApp();
     $blogKey = $post->getConfig()->getValueUnchecked('blog');
     $postsDateFormat = PageHelper::getConfigValueUnchecked($post, 'date_format', $blogKey);
     // Add the easy values to the values array.
     $this->values['url'] = PieCrustHelper::formatUri($pieCrust, $post->getUri());
     $this->values['slug'] = $post->getUri();
     $this->values['timestamp'] = $post->getDate(true);
     $this->values['date'] = date($postsDateFormat, $post->getDate(true));
     // Make it possible to access assets.
     $assetor = new Assetor($post);
     $this->values['assets'] = $assetor;
     // Add some lazy-loading functions for stuff
     // that would load the page's contents.
     $this->lazyValues[self::WILDCARD] = 'loadContent';
 }
예제 #5
0
 /**
  * Gets the page's data for page rendering.
  *
  * It's better to call IPage::getData, which calls this function, because it
  * will also cache the results. It's useful for example when pagination
  * results needs to be re-used.
  */
 public static function getPageData(IPage $page)
 {
     $pieCrust = $page->getApp();
     $paginator = new Paginator($page);
     $assetor = new Assetor($page);
     $linker = new Linker($page);
     if ($page->getPaginationDataSource() != null) {
         $paginator->setPaginationDataSource($page->getPaginationDataSource());
     }
     $data = array('page' => $page->getConfig()->get(), 'asset' => $assetor, 'pagination' => $paginator, 'link' => $linker);
     $data['page']['url'] = PieCrustHelper::formatUri($pieCrust, $page->getUri());
     $data['page']['slug'] = $page->getUri();
     $data['page']['timestamp'] = $page->getDate();
     $dateFormat = PageHelper::getConfigValueUnchecked($page, 'date_format', $page->getConfig()->getValueUnchecked('blog'));
     $data['page']['date'] = date($dateFormat, $page->getDate());
     switch ($page->getPageType()) {
         case IPage::TYPE_TAG:
             if (is_array($page->getPageKey())) {
                 $data['tag'] = implode(' + ', $page->getPageKey());
             } else {
                 $data['tag'] = $page->getPageKey();
             }
             break;
         case IPage::TYPE_CATEGORY:
             $data['category'] = $page->getPageKey();
             break;
     }
     $extraData = $page->getExtraPageData();
     if ($extraData) {
         if (is_array($extraData)) {
             $data = Configuration::mergeArrays($data, $extraData);
         } else {
             $data['extra'] = $extraData;
         }
     }
     return $data;
 }
 public function getCategoryUrl($value, $blogKey = null)
 {
     $format = $blogKey == null ? $this->categoryUrlFormat : $pieCrust->getConfig()->getValueUnchecked($blogKey . '/category_url');
     return PieCrustHelper::formatUri($this->pieCrust, UriBuilder::buildCategoryUri($format, $value));
 }
예제 #7
0
 public function getCategoryUrl($value, $blogKey = null)
 {
     $blogKey = $this->getSafeBlogKey($blogKey);
     return PieCrustHelper::formatUri($this->pieCrust, UriBuilder::buildCategoryUri($this->pieCrust, $blogKey, $value));
 }
예제 #8
0
 public function getSubPageUri($index)
 {
     $uri = $this->page->getUri();
     if ($index > 1) {
         if ($uri != '') {
             $uri .= '/';
         }
         $uri .= $index;
     }
     return PieCrustHelper::formatUri($this->page->getApp(), $uri);
 }
예제 #9
0
 /**
  * Gets the page's data for page rendering.
  *
  * It's better to call IPage::getData, which calls this function, because it
  * will also cache the results. It's useful for example when pagination
  * results needs to be re-used.
  */
 public static function getPageData(IPage $page)
 {
     $pieCrust = $page->getApp();
     $paginator = new Paginator($page);
     $assetor = new Assetor($page);
     $linker = new Linker($page);
     $recursiveLinker = new RecursiveLinkerIterator($linker);
     if ($page->getPaginationDataSource() != null) {
         $paginator->setPaginationDataSource($page->getPaginationDataSource());
     }
     $data = array('page' => $page->getConfig()->get(), 'assets' => $assetor, 'pagination' => $paginator, 'siblings' => $linker, 'family' => $recursiveLinker);
     $data['page']['url'] = PieCrustHelper::formatUri($pieCrust, $page->getUri());
     $data['page']['slug'] = $page->getUri();
     $data['page']['timestamp'] = $page->getDate(true);
     $dateFormat = PageHelper::getConfigValueUnchecked($page, 'date_format', $page->getConfig()->getValueUnchecked('blog'));
     $data['page']['date'] = date($dateFormat, $page->getDate(true));
     switch ($page->getPageType()) {
         case IPage::TYPE_TAG:
             if (is_array($page->getPageKey())) {
                 $data['tag'] = implode(' + ', $page->getPageKey());
             } else {
                 $data['tag'] = $page->getPageKey();
             }
             if (strpos($data['tag'], '-') >= 0) {
                 // The tag may have been slugified. Let's cheat a bit by looking at
                 // the first tag that matches in the first pagination post, and
                 // using that instead.
                 $paginationPosts = $paginator->posts();
                 if (count($paginationPosts) > 0) {
                     $firstPost = $paginationPosts[0];
                     $firstPostTags = $firstPost['tags'];
                     if (!is_array($firstPostTags)) {
                         $firstPostTags = array($firstPostTags);
                     }
                     $flags = $pieCrust->getConfig()->getValue('site/slugify_flags');
                     if (is_array($page->getPageKey())) {
                         $pageKey = $page->getPageKey();
                         foreach ($firstPostTags as $t) {
                             $st = UriBuilder::slugify($t, $flags);
                             foreach ($pageKey as &$pk) {
                                 if ($st == $pk) {
                                     $pk = $t;
                                     break;
                                 }
                             }
                         }
                         if ($page->getPageKey() == null) {
                             $page->setPageKey($pageKey);
                         }
                         $data['tag'] = implode(' + ', $pageKey);
                     } else {
                         foreach ($firstPostTags as $t) {
                             if (UriBuilder::slugify($t, $flags) == $data['tag']) {
                                 if ($page->getPageKey() == null) {
                                     $page->setPageKey($t);
                                 }
                                 $data['tag'] = $t;
                                 break;
                             }
                         }
                     }
                 }
             }
             break;
         case IPage::TYPE_CATEGORY:
             $data['category'] = $page->getPageKey();
             if (strpos($page->getPageKey(), '-') >= 0) {
                 // Same remark as for tags.
                 $paginationPosts = $paginator->posts();
                 if (count($paginationPosts) > 0) {
                     $firstPost = $paginationPosts[0];
                     if ($page->getPageKey() == null) {
                         $page->setPageKey($firstPost['category']);
                     }
                     $data['category'] = $firstPost['category'];
                 }
             }
             break;
     }
     $extraData = $page->getExtraPageData();
     if ($extraData) {
         if (is_array($extraData)) {
             $data = Configuration::mergeArrays($data, $extraData);
         } else {
             $data['extra'] = $extraData;
         }
     }
     return $data;
 }