示例#1
0
 /**
  * Gets a tag listing page.
  */
 public static function getTagPage(IPieCrust $pieCrust, $tag, $blogKey = null)
 {
     if ($blogKey == null) {
         $blogKeys = $pieCrust->getConfig()->getValueUnchecked('site/blogs');
         $blogKey = $blogKeys[0];
     }
     $pathPrefix = '';
     if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
         $pathPrefix = $blogKey . DIRECTORY_SEPARATOR;
     }
     $pageRepository = $pieCrust->getEnvironment()->getPageRepository();
     $uri = UriBuilder::buildTagUri($pieCrust->getConfig()->getValue($blogKey . '/tag_url'), $tag);
     $path = $pieCrust->getPagesDir() . $pathPrefix . PieCrustDefaults::TAG_PAGE_NAME . '.html';
     if (!is_file($path)) {
         return null;
     }
     $page = $pageRepository->getOrCreatePage($uri, $tagPagePath, IPage::TYPE_TAG, $blogKey, $tag);
     return $page;
 }
示例#2
0
 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;
 }
示例#3
0
 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;
 }
示例#4
0
 /**
  * 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);
     }
 }