예제 #1
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;
 }
예제 #2
0
 public function initialize(IPieCrust $pieCrust)
 {
     $environment = $pieCrust->getEnvironment();
     if ($environment instanceof ChefEnvironment) {
         $environment->addCommandExtension('prepare', new \PieCrust\Chef\Commands\PreparePageCommandExtension());
         $environment->addCommandExtension('prepare', new \PieCrust\Chef\Commands\PreparePostCommandExtension());
         $environment->addCommandExtension('prepare', new \PieCrust\Chef\Commands\PrepareFeedCommandExtension());
     }
 }
 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');
 }
예제 #4
0
 public function setupParser(Console_CommandLine $parser, IPieCrust $pieCrust)
 {
     $parser->description = "Helps with the creation of content in the website.";
     $environment = $pieCrust->getEnvironment();
     if ($environment instanceof ChefEnvironment) {
         $extensions = $environment->getCommandExtensions($this->getName());
         foreach ($extensions as $ext) {
             $extensionParser = $parser->addCommand($ext->getName());
             $ext->setupParser($extensionParser, $pieCrust);
         }
     }
 }
예제 #5
0
 public function __construct(IPieCrust $pieCrust, $enabled = true)
 {
     $this->pieCrust = $pieCrust;
     $this->enabled = $enabled;
     $this->pages = array();
     $this->assetUrlBaseRemap = null;
     $this->limit = 1000;
     $this->collectSize = $this->limit / 10;
     $this->loadedTimes = array();
     $log = $pieCrust->getEnvironment()->getLog();
     $log->debug("Initializing page repository with a limit of {$this->limit} loaded pages.");
 }
예제 #6
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;
 }
예제 #7
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 = $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;
 }
예제 #8
0
 /**
  * Creates a new instance of the PieCrustBaker.
  */
 public function __construct(IPieCrust $pieCrust, array $bakerParameters = array())
 {
     $this->pieCrust = $pieCrust;
     $this->pieCrust->getConfig()->setValue('baker/is_baking', false);
     $bakerParametersFromApp = $this->pieCrust->getConfig()->getValue('baker');
     if ($bakerParametersFromApp == null) {
         $bakerParametersFromApp = array();
     }
     $this->parameters = array_merge(array('smart' => true, 'clean_cache' => false, 'show_record' => false, 'config_variant' => null, 'copy_assets' => true, 'processors' => '*', 'mounts' => array(), 'skip_patterns' => array(), 'force_patterns' => array(), 'output' => false), $bakerParametersFromApp, $bakerParameters);
     $outputDir = $this->getParameterValue('output');
     if ($outputDir) {
         $this->setBakeDir($outputDir);
     }
     $this->pageBaker = null;
     $this->logger = $pieCrust->getEnvironment()->getLog();
     // New way: apply the `baker` variant.
     // Old way: apply the specified variant, or the default one. Warn about deprecation.
     $variantName = $this->parameters['config_variant'];
     if ($variantName) {
         $this->logger->warning("The `--config` parameter has been moved to a global parameter (specified before the command).");
         $this->pieCrust->getConfig()->applyVariant("baker/config_variants/{$variantName}");
         $this->logger->warning("Variant '{$variantName}' has been applied, but will need to be moved to the new `variants` section of the site configuration.");
     } else {
         if ($this->pieCrust->getConfig()->hasValue("baker/config_variants/default")) {
             $this->pieCrust->getConfig()->applyVariant("baker/config_variants/default");
             $this->logger->warning("The default baker configuration variant has been applied, but will need to be moved into the new `variants/baker` section of the site configuration.");
         } else {
             $this->pieCrust->getConfig()->applyVariant("variants/baker", false);
         }
     }
     // Load the baking assistants.
     $this->cacheAssistants();
 }
예제 #9
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;
 }
예제 #10
0
 public function __construct(IPieCrust $pieCrust)
 {
     $this->pieCrust = $pieCrust;
     $this->linkCollector = $pieCrust->getEnvironment()->getLinkCollector();
 }
예제 #11
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;
 }
예제 #12
0
 /**
  * Gets all the posts found for in a website for a particular blog.
  */
 public static function getPosts(IPieCrust $pieCrust, $blogKey)
 {
     return $pieCrust->getEnvironment()->getPosts($blogKey);
 }