/** * Creates a new instance of PageLoader. */ public function __construct(IPage $page) { $this->page = $page; $this->cache = null; if ($page->getApp()->isCachingEnabled()) { $this->cache = new Cache($page->getApp()->getCacheDir() . 'pages_r'); } $this->pageData = null; }
/** * Returns a validated version of the given site configuration. * * This is exposed as a public static function for convenience (unit tests, * etc.) */ public static function getValidatedConfig(IPage $page, $config) { if (!$config) { $config = array(); } // Add the default page config values. $pieCrustConfig = $page->getApp()->getConfig(); $blogKeys = $pieCrustConfig->getValueUnchecked('site/blogs'); $layoutName = PieCrustDefaults::DEFAULT_PAGE_TEMPLATE_NAME; if (PageHelper::isPost($page)) { $layoutName = PieCrustDefaults::DEFAULT_POST_TEMPLATE_NAME; if ($page->getBlogKey()) { // If this is a post in a multi-blog environment, make it use // the `<blogname>/post.html` layout first by default, and // then fallback on `post.html` if that doesn't exist. $layoutName = $page->getBlogKey() . '/' . PieCrustDefaults::DEFAULT_POST_TEMPLATE_NAME . ',' . $layoutName; } } $validatedConfig = array_merge(array('layout' => $layoutName, 'format' => $pieCrustConfig->getValueUnchecked('site/default_format'), 'template_engine' => $pieCrustConfig->getValueUnchecked('site/default_template_engine'), 'content_type' => 'html', 'title' => 'Untitled Page', 'blog' => $page->getBlogKey() != null ? $page->getBlogKey() : $blogKeys[0], 'segments' => array()), $config); // Detect common problems. if (isset($validatedConfig['category'])) { if (is_array($validatedConfig['category'])) { throw new PieCrustException("Page '{$page->getUri()}': `category` is an array -- it must be a string. For multiple values, use `tags` instead."); } } if (isset($validatedConfig['tags'])) { if (!is_array($validatedConfig['tags'])) { $validatedConfig['tags'] = array($validatedConfig['tags']); } } if (isset($validatedConfig['single_page'])) { throw new PieCrustException("Page '{$page->getUri()}': `single_page` has been deprecated. Use `blog.posts` with some limits if you want a single page showing the most recent posts."); } return $validatedConfig; }
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(); } }
public function __construct(IPage $page, $blogKey, $timeValue, $timestamp, array $dataSource) { $this->timeValue = $timeValue; $this->timestamp = $timestamp; $this->posts = new PageIterator($page->getApp(), $blogKey, $dataSource); $this->posts->setCurrentPage($page); }
/** * 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); }
public function __construct(IPage $page, $blogKey, $propertyValue, array $dataSource) { $this->propertyValue = $propertyValue; $this->posts = new PageIterator($page->getApp(), $blogKey, $dataSource); $this->posts->setCurrentPage($page); $this->postCount = count($dataSource); // Backwards compatibility (should use posts.count) }
/** * Returns a validated version of the given site configuration. * * This is exposed as a public static function for convenience (unit tests, * etc.) */ public static function getValidatedConfig(IPage $page, $config) { if (!$config) { $config = array(); } // Add the default page config values. $pieCrustConfig = $page->getApp()->getConfig(); $blogKeys = $pieCrustConfig->getValueUnchecked('site/blogs'); $validatedConfig = array_merge(array('layout' => PageHelper::isPost($page) ? PieCrustDefaults::DEFAULT_POST_TEMPLATE_NAME : PieCrustDefaults::DEFAULT_PAGE_TEMPLATE_NAME, 'format' => $pieCrustConfig->getValueUnchecked('site/default_format'), 'template_engine' => $pieCrustConfig->getValueUnchecked('site/default_template_engine'), 'content_type' => 'html', 'title' => 'Untitled Page', 'blog' => $page->getBlogKey() != null ? $page->getBlogKey() : $blogKeys[0], 'segments' => array()), $config); return $validatedConfig; }
public function addPageClauses(IPage $page, array $userFilterInfo = null) { // If the current page is a tag/category page, add filtering // for that. $pageClause = null; $pieCrust = $page->getApp(); $flags = $pieCrust->getConfig()->getValue('site/slugify_flags'); switch ($page->getPageType()) { case IPage::TYPE_TAG: $pageKey = $page->getPageKey(); if (is_array($pageKey)) { $pageClause = new AndBooleanClause(); foreach ($pageKey as $k) { $pageClause->addClause(new HasFilterClause('tags', $k, function ($t) use($flags) { return UriBuilder::slugify($t, $flags); })); } } else { $pageClause = new HasFilterClause('tags', $pageKey, function ($t) use($flags) { return UriBuilder::slugify($t, $flags); }); } break; case IPage::TYPE_CATEGORY: $pageClause = new IsFilterClause('category', $page->getPageKey(), function ($c) use($flags) { return UriBuilder::slugify($c, $flags); }); break; } if ($pageClause != null) { // Combine the default page filters with some user filters, // if any. if ($userFilterInfo != null) { $combinedClause = new AndBooleanClause(); $combinedClause->addClause($pageClause); $this->addClausesRecursive($userFilterInfo, $combinedClause); $this->addClause($combinedClause); } else { $this->addClause($pageClause); } } }
/** * 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; }
protected static function buildUrlBase(IPage $page, $assetUrlBaseRemap) { $siteRoot = $page->getApp()->getConfig()->getValueUnchecked('site/root'); $relativePath = str_replace('\\', '/', PieCrustHelper::getRelativePath($page->getApp(), $page->getPath(), true)); $uri = $page->getUri(); $prettyUrls = PageHelper::getConfigValue($page, 'pretty_urls', 'site'); if (!$prettyUrls) { // Remove the extension from the URI (if any), because without 'pretty URLs', // we want to copy assets to a directory named after the page's filename // (without the extension). See `PageBaker` for more information. $uriInfo = pathinfo($uri); $uri = $uriInfo['dirname']; if ($uri == '.') { $uri = ''; } else { $uri .= '/'; } $uri .= $uriInfo['filename']; } $replacements = array('%site_root%' => $siteRoot, '%path%' => $relativePath, '%uri%' => $uri); return str_replace(array_keys($replacements), array_values($replacements), $assetUrlBaseRemap); }
public static function mergeProviderData(IPage $page, array &$data) { foreach ($page->getApp()->getPluginLoader()->getDataProviders() as $provider) { $providerData = $provider->getPageData($page); if ($providerData !== null) { $endPoint = $provider->getName(); if (isset($data[$endPoint])) { throw new PieCrustException("Can't load data provider: the page configuration already has a value at'{$endPoint}'."); } $data[$endPoint] = $providerData; } } }