private static function tryParsePostUri(IPieCrust $pieCrust, $blogKey, $uri, array &$pageInfo) { $postsDir = $pieCrust->getPostsDir(); if ($postsDir === false) { return false; } $matches = array(); $postsPattern = UriBuilder::buildPostUriPattern($pieCrust->getConfig()->getValueUnchecked($blogKey . '/post_url')); if (preg_match($postsPattern, $uri, $matches)) { $fs = $pieCrust->getEnvironment()->getFileSystem(); $pathInfo = $fs->getPostPathInfo($blogKey, $matches, FileSystem::PATHINFO_PARSING); $date = mktime(0, 0, 0, intval($pathInfo['month']), intval($pathInfo['day']), intval($pathInfo['year'])); $pageInfo['type'] = IPage::TYPE_POST; $pageInfo['blogKey'] = $blogKey; $pageInfo['date'] = $date; $pageInfo['path'] = $pathInfo['path']; return true; } return false; }
/** * Creates the appropriate implementation of `FileSystem` based * on the configuration of the website. */ public static function create(IPieCrust $pieCrust, $postsSubDir = null, $themeFs = false) { $postsFs = $pieCrust->getConfig()->getValueUnchecked('site/posts_fs'); if ($themeFs) { $themeDir = $pieCrust->getThemeDir(); if (!$themeDir) { throw new PieCrustException("Can't create a theme file-system because there's no theme in the current website."); } $pagesDir = $themeDir . PieCrustDefaults::CONTENT_PAGES_DIR; $postsDir = $themeDir . PieCrustDefaults::CONTENT_POSTS_DIR; } else { $pagesDir = $pieCrust->getPagesDir(); $postsDir = $pieCrust->getPostsDir(); if ($postsSubDir == PieCrustDefaults::DEFAULT_BLOG_KEY) { $postsSubDir = null; } if ($postsSubDir != null) { $postsDir .= trim($postsSubDir, '\\/') . '/'; } } switch ($postsFs) { case 'hierarchy': return new HierarchicalFileSystem($pagesDir, $postsDir); case 'shallow': return new ShallowFileSystem($pagesDir, $postsDir); case 'flat': return new FlatFileSystem($pagesDir, $postsDir); default: throw new PieCrustException("Unknown posts_fs: " . $postsFs); } }