/** * Returns a path relative to a site's root directory. */ public static function getRelativePath(IPieCrust $pieCrust, $path, $stripExtension = false) { $basePath = null; $themeDir = $pieCrust->getThemeDir(); if ($themeDir and strncmp($path, $themeDir, strlen($themeDir)) == 0) { // Theme path. $basePath = $themeDir; } else { // Normal website path. $basePath = $pieCrust->getRootDir(); } if (!$basePath) { throw new PieCrustException("Can't get a relative path for '{$path}': it doesn't seem to be either a website, theme or resource path."); } $relativePath = PathHelper::getRelativePath($basePath, $path); if ($stripExtension) { $relativePath = preg_replace('/\\.[a-zA-Z0-9]+$/', '', $relativePath); } return $relativePath; }
public static function getUserOrThemePath(IPieCrust $pieCrust, $relativePath, $themePath = false) { if (!is_array($relativePath)) { $relativePath = array($relativePath); } $pagesDir = $pieCrust->getPagesDir(); if ($pagesDir !== false) { foreach ($relativePath as $rp) { $path = $pagesDir . $rp; if (is_file($path)) { return $path; } } } if (!$themePath) { $themePath = $relativePath; } elseif (!is_array($themePath)) { $themePath = array($themePath); } $themeDir = $pieCrust->getThemeDir(); if ($themeDir !== false) { foreach ($themePath as $rp) { $path = $themeDir . '_content/pages/' . $rp; if (is_file($path)) { return $path; } } } return false; }
public static function getUserOrThemeOrResPath(IPieCrust $pieCrust, $relativePath) { $pagesDir = $pieCrust->getPagesDir(); if ($pagesDir !== false) { $path = $pagesDir . $relativePath; if (is_file($path)) { return $path; } } $themeDir = $pieCrust->getThemeDir(); if ($themeDir !== false) { $path = $themeDir . '_content/pages/' . $relativePath; if (is_file($path)) { return $path; } } $resDir = dirname(dirname(PieCrustDefaults::APP_DIR)) . '/res/'; $path = $resDir . 'pages/' . $relativePath; if (is_file($path)) { return $path; } 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); } }