예제 #1
0
 public function initialize(IPieCrust $pieCrust)
 {
     $this->pieCrust = $pieCrust;
     $this->parser = null;
     $this->useExtra = $pieCrust->getConfig()->getValue('markdown/use_markdown_extra');
     $this->useSundown = $pieCrust->getConfig()->getValue('markdown/use_sundown');
     $this->parserConfig = $pieCrust->getConfig()->getValue('markdown/config');
 }
 public function initialize(IPieCrust $pieCrust)
 {
     $config = $pieCrust->getConfig();
     $this->markdownLibDir = 'markdown';
     if ($pieCrust->getConfig()->getValue('markdown/use_markdown_extra') === true) {
         $this->markdownLibDir = 'markdown-extra';
     }
 }
 public function __construct(IPieCrust $pieCrust)
 {
     $this->pieCrust = $pieCrust;
     $this->linkCollector = $pieCrust->getEnvironment()->getLinkCollector();
     $blogKeys = $pieCrust->getConfig()->getValueUnchecked('site/blogs');
     $this->defaultBlogKey = $blogKeys[0];
     $this->postUrlFormat = $pieCrust->getConfig()->getValueUnchecked($blogKeys[0] . '/post_url');
     $this->tagUrlFormat = $pieCrust->getConfig()->getValueUnchecked($blogKeys[0] . '/tag_url');
     $this->categoryUrlFormat = $pieCrust->getConfig()->getValueUnchecked($blogKeys[0] . '/category_url');
 }
 public function initialize(IPieCrust $pieCrust)
 {
     $this->smartypantsLibDir = 'smartypants';
     $smartypantsConfig = $pieCrust->getConfig()->getValue('smartypants');
     if ($smartypantsConfig) {
         $this->enabled = ($pieCrust->getConfig()->getValue('smartypants/enable') or $pieCrust->getConfig()->getValue('smartypants/enabled'));
         if ($pieCrust->getConfig()->getValue('smartypants/use_smartypants_typographer')) {
             $this->smartypantsLibDir = 'smartypants-typographer';
         }
     } else {
         $this->enabled = false;
     }
 }
예제 #5
0
 /**
  * Creates the appropriate implementation of `FileSystem` based
  * on the configuration of the website.
  */
 public static function create(IPieCrust $pieCrust)
 {
     $postsFs = $pieCrust->getConfig()->getValueUnchecked('site/posts_fs');
     $postsFs = array_map(function ($i) {
         return trim($i);
     }, explode(',', $postsFs));
     $fss = array();
     $fileSystems = $pieCrust->getPluginLoader()->getFileSystems();
     foreach ($fileSystems as $fs) {
         $i = array_search($fs->getName(), $postsFs);
         if ($i !== false) {
             $fss[] = $fs;
             unset($postsFs[$i]);
         }
     }
     if ($postsFs) {
         throw new PieCrustException("Unknown file-system(s): " . implode(', ', $postsFs));
     }
     $fssCount = count($fss);
     if ($fssCount == 1) {
         $pieCrust->getEnvironment()->getLog()->debug("Creating unique file-system.");
         $finalFs = $fss[0];
     } elseif ($fssCount > 1) {
         $pieCrust->getEnvironment()->getLog()->debug("Creating composite file-system.");
         $finalFs = new CompositeFileSystem($fss);
     } else {
         throw new PieCrustException("No file-systems have been created: " . implode(', ', $postsFs));
     }
     $finalFs->initialize($pieCrust);
     return $finalFs;
 }
예제 #6
0
 /**
  * Initializes this file system with the given application.
  */
 public function initialize(IPieCrust $pieCrust)
 {
     $autoFormats = $pieCrust->getConfig()->getValueUnchecked('site/auto_formats');
     $htmlExtensions = array_keys($autoFormats);
     if (count($htmlExtensions) == 0) {
         $htmlExtensions = array('html');
     }
     $this->htmlExtensions = $htmlExtensions;
     $this->pieCrust = $pieCrust;
 }
예제 #7
0
 protected function setPortableSiteRoot(IPieCrust $app, $currentPath)
 {
     $portableUrls = $app->getConfig()->getValue('baker/portable_urls');
     if (!$portableUrls) {
         return null;
     }
     $siteRoot = '';
     $curDir = dirname($currentPath);
     while (strlen($curDir) > strlen($this->bakeDir)) {
         $siteRoot .= '../';
         $curDir = dirname($curDir);
     }
     if ($siteRoot == '') {
         $siteRoot = './';
     }
     $savedSiteRoot = $app->getConfig()->getValueUnchecked('site/root');
     $app->getConfig()->setValue('site/root', $siteRoot);
     // We need to unload all loaded pages because their rendered
     // contents will probably be invalid now that the site root changed.
     $repo = $app->getEnvironment()->getPageRepository();
     foreach ($repo->getPages() as $p) {
         $p->unload();
     }
     return $savedSiteRoot;
 }
예제 #8
0
 /**
  * Builds the URL of a category listing.
  */
 public static function buildCategoryUri(IPieCrust $pieCrust, $blogKey, $category, $slugify = true)
 {
     $categoryUrlFormat = $pieCrust->getConfig()->getValue($blogKey . '/category_url');
     if ($slugify) {
         $flags = $pieCrust->getConfig()->getValue('site/slugify_flags');
         $category = UriBuilder::slugify($category, $flags);
     }
     return str_replace('%category%', $category, $categoryUrlFormat);
 }
예제 #9
0
 protected function getSources(IPieCrust $pieCrust, $log)
 {
     $sources = $pieCrust->getConfig()->getValue('site/themes_sources');
     if ($log) {
         $log->debug("Got site theme sources: ");
         foreach ($sources as $s) {
             $log->debug(" - " . $s);
         }
     }
     return $sources;
 }
예제 #10
0
 private static function tryParseCategoryUri(IPieCrust $pieCrust, $blogKey, $uri, array &$pageInfo)
 {
     $blogKeyDir = '';
     if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
         $blogKeyDir = $blogKey . '/';
     }
     $categoryPageName = array();
     $themeCategoryPageName = array();
     $autoFormats = $pieCrust->getConfig()->getValueUnchecked('site/auto_formats');
     foreach ($autoFormats as $ext => $format) {
         $categoryPageName[] = $blogKeyDir . PieCrustDefaults::CATEGORY_PAGE_NAME . '.' . $ext;
         $themeCategoryPageName[] = PieCrustDefaults::CATEGORY_PAGE_NAME . '.' . $ext;
     }
     $path = PathHelper::getUserOrThemePath($pieCrust, $categoryPageName, $themeCategoryPageName);
     if ($path === false) {
         return false;
     }
     $flags = $pieCrust->getConfig()->getValueUnchecked('site/slugify_flags');
     $categoryPattern = UriBuilder::buildCategoryUriPattern($pieCrust->getConfig()->getValueUnchecked($blogKey . '/category_url'));
     if (preg_match($categoryPattern, $uri, $matches)) {
         $cat = rawurldecode($matches['cat']);
         $cat = UriBuilder::slugify($cat, $flags);
         $pageInfo['type'] = IPage::TYPE_CATEGORY;
         $pageInfo['blogKey'] = $blogKey;
         $pageInfo['key'] = $cat;
         $pageInfo['path'] = $path;
         $pageInfo['was_path_checked'] = true;
         return true;
     }
     return false;
 }
예제 #11
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;
 }
예제 #12
0
 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 = FileSystem::create($pieCrust, $blogKey);
         $pathInfo = $fs->getPostPathInfo($matches);
         $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;
 }
예제 #13
0
 /**
  * Gets a formatted page URI.
  */
 public static function formatUri(IPieCrust $pieCrust, $uri)
 {
     if (strlen($uri) > 0 and ($uri[0] == '/' or preg_match(',[a-zA-Z]+://,', $uri))) {
         // Don't do anything if the URI is already absolute.
         return $uri;
     }
     // Get the URI format for the current app. There's a couple weird ones
     // that should be used only if the URI to format doesn't have an extension
     // specified.
     $uriFormat = $pieCrust->getEnvironment()->getUriFormat();
     $tokens = array('%root%', '%slug%', '%slash_if_no_ext%', '%html_if_no_ext%');
     $replacements = array($pieCrust->getConfig()->getValueUnchecked('site/root'), $uri, '/', '.html');
     // Adjust the replacement bits if the given URI has an extension.
     $hasExtensionOrIsRoot = ($uri == '' or pathinfo($uri, PATHINFO_EXTENSION) != null);
     if ($hasExtensionOrIsRoot) {
         $replacements[2] = '';
         $replacements[3] = '';
     }
     $formattedUri = str_replace($tokens, $replacements, $uriFormat);
     return $formattedUri;
 }
예제 #14
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);
     }
 }