예제 #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';
     }
 }
예제 #3
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());
     }
 }
예제 #4
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;
 }
 public function initialize(IPieCrust $pieCrust)
 {
     if ($pieCrust->isCachingEnabled()) {
         $this->cache = new Cache($pieCrust->getCacheDir() . 'bitbucket_requests/');
         $this->cacheTime = 60 * 60;
         // Cache requests for one hour.
     } else {
         $this->cache = null;
         $this->cacheTime = false;
     }
 }
예제 #6
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);
         }
     }
 }
예제 #7
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.");
 }
 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;
     }
 }
예제 #9
0
 protected function getSources(IPieCrust $pieCrust, $log)
 {
     $sources = $pieCrust->getConfig()->getValue('site/plugins_sources');
     if ($log) {
         $log->debug("Got site plugin sources: ");
         foreach ($sources as $s) {
             $log->debug(" - " . $s);
         }
     }
     return $sources;
 }
예제 #10
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;
 }
예제 #11
0
 public static function aboutImportHelpTopic(IPieCrust $pieCrust)
 {
     $importers = $pieCrust->getPluginLoader()->getImporters();
     $output = '';
     $output .= "The `import` command lets you import content from another CMS into PieCrust.\n";
     $output .= "\n";
     $output .= "Available formats:\n";
     $output .= "\n";
     foreach ($importers as $importer) {
         $output .= "`{$importer->getName()}`: " . wordwrap($importer->getDescription(), 70, "\n  ") . "\n\n";
         $firstLine = true;
         foreach (explode("\n", $importer->getHelpTopic()) as $line) {
             if ($firstLine) {
                 $output .= "  - ";
                 $firstLine = false;
             } else {
                 $output .= "    ";
             }
             $output .= wordwrap($line, 70, "\n    ") . "\n";
         }
         $output .= "\n\n";
     }
     return $output;
 }
예제 #12
0
 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');
 }
예제 #13
0
 public function __construct(IPieCrust $pieCrust)
 {
     $this->pieCrust = $pieCrust;
     $this->linkCollector = $pieCrust->getEnvironment()->getLinkCollector();
 }
예제 #14
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;
 }
예제 #15
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);
     }
 }
예제 #16
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;
 }
예제 #17
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);
 }
예제 #18
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();
 }
예제 #19
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;
 }
예제 #20
0
 public function initialize(IPieCrust $pieCrust, $logger = null)
 {
     $this->rootDirLength = strlen($pieCrust->getRootDir());
 }
예제 #21
0
 /**
  * Gets the plugins directories for a given plugin type.
  */
 public static function getPluginsDirs(IPieCrust $pieCrust, $pluginType, $defaultDir = null)
 {
     $result = array();
     // Add the default/built-in directory, if any.
     if ($defaultDir) {
         $result[] = PieCrustDefaults::APP_DIR . '/' . $defaultDir;
     }
     // Look in the app's plugins directories, and for each, look at the plugins
     // inside, looking for the correct class type.
     $locations = $pieCrust->getPluginsDirs();
     foreach ($locations as $loc) {
         $dirs = new \FilesystemIterator($loc);
         foreach ($dirs as $d) {
             if (!$d->isDir()) {
                 continue;
             }
             $pluginDir = $d->getPathname() . '/src/' . $pluginType;
             if (is_dir($pluginDir)) {
                 $result[] = $pluginDir;
             }
         }
     }
     return $result;
 }
예제 #22
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;
 }
예제 #23
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;
 }
예제 #24
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);
 }