コード例 #1
0
 /**
  * Gets a configuration value either on the given page, or on its parent
  * application.
  */
 public static function getConfigValueUnchecked(IPage $page, $key, $appSection)
 {
     if ($page->getConfig()->hasValue($key)) {
         return $page->getConfig()->getValueUnchecked($key);
     }
     return $page->getApp()->getConfig()->getValueUnchecked($appSection . '/' . $key);
 }
コード例 #2
0
 public function initialize(IPage $page, $baker)
 {
     $this->path = $page->getPath();
     $this->pageType = $page->getPageType();
     $this->blogKey = $page->getBlogKey();
     $this->pageKey = $page->getPageKey();
     $this->taxonomy = array();
     $this->usedTaxonomyCombinations = array();
     $this->usedPages = false;
     $this->usedPosts = array();
     $this->outputs = array();
     if ($baker) {
         $tags = $page->getConfig()->getValue('tags');
         if ($tags) {
             $this->taxonomy['tags'] = $tags;
         }
         $category = $page->getConfig()->getValue('category');
         if ($category) {
             $this->taxonomy['category'] = $category;
         }
         $collector = $page->getApp()->getEnvironment()->getLinkCollector();
         if ($collector) {
             $tagCombinations = $collector->getAllTagCombinations();
             if ($tagCombinations) {
                 $this->usedTaxonomyCombinations['tags'] = $tagCombinations;
             }
             $collector->clearAllTagCombinations();
         }
         // TODO: remember posts used by blog.
         $this->usedPosts = $baker->wasPaginationDataAccessed();
         $this->outputs = $baker->getBakedFiles();
     }
 }
コード例 #3
0
ファイル: IsFilterClause.php プロジェクト: giftnuss/PieCrust
 public function postMatches(IPage $post)
 {
     $actualValue = $post->getConfig()->getValue($this->settingName);
     if ($this->coerceFunc != null) {
         $coerceFunc = $this->coerceFunc;
         $actualValue = $coerceFunc($actualValue);
     }
     return $actualValue != null && $actualValue == $this->settingValue;
 }
コード例 #4
0
ファイル: HasFilterClause.php プロジェクト: giftnuss/PieCrust
 public function postMatches(IPage $post)
 {
     $actualValue = $post->getConfig()->getValue($this->settingName);
     if ($actualValue == null || !is_array($actualValue)) {
         return false;
     }
     if ($this->coerceFunc != null) {
         $coerceFunc = $this->coerceFunc;
         $actualValue = array_map($coerceFunc, $actualValue);
     }
     return in_array($this->settingValue, $actualValue);
 }
コード例 #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;
 }
コード例 #6
0
 public function postMatches(IPage $post)
 {
     $actualValue = $post->getConfig()->getValue($this->settingName);
     return $actualValue != null && $actualValue == $this->settingValue;
 }
コード例 #7
0
 protected function addPageValue(IPage $page, &$dataSources)
 {
     $propertyValues = $page->getConfig()->getValue($this->propertyName);
     if ($propertyValues) {
         if (!is_array($propertyValues)) {
             $propertyValues = array($propertyValues);
         }
         foreach ($propertyValues as $v) {
             if (!isset($dataSources[$v])) {
                 $dataSources[$v] = array();
             }
             $dataSources[$v][] = $page;
         }
     }
 }
コード例 #8
0
ファイル: DataBuilder.php プロジェクト: giftnuss/PieCrust
 /**
  * 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;
 }