/**
  * Returns a validated version of the given site configuration.
  *
  * This is exposed as a public static function for convenience (unit tests,
  * etc.)
  */
 public static function getValidatedConfig($config)
 {
     // Validate defaults.
     if (!$config) {
         $config = array();
     }
     if (!isset($config['site'])) {
         $config['site'] = array();
     }
     $config['site'] = array_merge(array('title' => 'Untitled PieCrust Website', 'root' => null, 'theme_root' => null, 'default_format' => PieCrustDefaults::DEFAULT_FORMAT, 'default_template_engine' => PieCrustDefaults::DEFAULT_TEMPLATE_ENGINE, 'enable_gzip' => false, 'pretty_urls' => false, 'slugify' => 'transliterate|lowercase', 'timezone' => false, 'locale' => false, 'posts_fs' => PieCrustDefaults::DEFAULT_POSTS_FS, 'date_format' => PieCrustDefaults::DEFAULT_DATE_FORMAT, 'blogs' => array(PieCrustDefaults::DEFAULT_BLOG_KEY), 'plugins_sources' => array(PieCrustDefaults::DEFAULT_PLUGIN_SOURCE), 'themes_sources' => array(PieCrustDefaults::DEFAULT_THEME_SOURCE), 'auto_formats' => array(), 'cache_time' => 28800, 'display_errors' => true, 'enable_debug_info' => true), $config['site']);
     $siteConfig =& $config['site'];
     // Validate the site root URL, and remember if it was specified in the
     // source config.yml, because we won't be able to tell the difference from
     // the completely validated cache version.
     if ($siteConfig['root'] == null) {
         $siteConfig['root'] = ServerHelper::getSiteRoot($_SERVER);
         $siteConfig['is_auto_root'] = true;
     } else {
         $siteConfig['root'] = rtrim($siteConfig['root'], '/') . '/';
         $siteConfig['is_auto_root'] = false;
     }
     // Validate auto-format extensions: make sure the HTML extension is in
     // there.
     if (!is_array($siteConfig['auto_formats'])) {
         throw new PieCrustException("The 'site/auto_formats' configuration setting must be an array.");
     }
     $siteConfig['auto_formats'] = array_filter(array_merge(array('html' => '', 'md' => 'markdown', 'textile' => 'textile'), $siteConfig['auto_formats']), function ($item) {
         return $item !== false;
     });
     // Validate the plugins sources.
     if (!is_array($siteConfig['plugins_sources'])) {
         $siteConfig['plugins_sources'] = array($siteConfig['plugins_sources']);
     }
     // Validate the themes sources.
     if (!is_array($siteConfig['themes_sources'])) {
         $siteConfig['themes_sources'] = array($siteConfig['themes_sources']);
     }
     // Validate multi-blogs settings.
     if (in_array(PieCrustDefaults::DEFAULT_BLOG_KEY, $siteConfig['blogs']) and count($siteConfig['blogs']) > 1) {
         throw new PieCrustException("'" . PieCrustDefaults::DEFAULT_BLOG_KEY . "' cannot be specified as a blog key for multi-blog configurations. Please pick custom keys.");
     }
     // Add default values for the blogs configurations, or use values
     // defined at the site level for easy site-wide configuration of multiple blogs
     // and backwards compatibility.
     $defaultValues = array('post_url' => '%year%/%month%/%day%/%slug%', 'tag_url' => 'tag/%tag%', 'category_url' => '%category%', 'posts_per_page' => 5);
     foreach (array_keys($defaultValues) as $key) {
         if (isset($siteConfig[$key])) {
             $defaultValues[$key] = $siteConfig[$key];
         }
     }
     foreach ($siteConfig['blogs'] as $blogKey) {
         $prefix = '';
         if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
             $prefix = $blogKey . '/';
         }
         if (!isset($config[$blogKey])) {
             $config[$blogKey] = array();
         }
         $config[$blogKey] = array_merge(array('post_url' => $prefix . $defaultValues['post_url'], 'tag_url' => $prefix . $defaultValues['tag_url'], 'category_url' => $prefix . $defaultValues['category_url'], 'posts_per_page' => $defaultValues['posts_per_page'], 'date_format' => $siteConfig['date_format']), $config[$blogKey]);
     }
     // Validate the slugify mode and optional flags.
     $slugifySetting = preg_split("/[\\s\\|,]+/", $siteConfig['slugify']);
     $slugifyModes = array('none' => UriBuilder::SLUGIFY_MODE_NONE, 'transliterate' => UriBuilder::SLUGIFY_MODE_TRANSLITERATE, 'encode' => UriBuilder::SLUGIFY_MODE_ENCODE, 'dash' => UriBuilder::SLUGIFY_MODE_DASHES, 'iconv' => UriBuilder::SLUGIFY_MODE_ICONV);
     $slugifyFlags = array('lowercase' => UriBuilder::SLUGIFY_FLAG_LOWERCASE);
     $finalSlugify = 0;
     foreach ($slugifySetting as $i => $m) {
         if ($i == 0) {
             if (!isset($slugifyModes[$m])) {
                 throw new PieCrustException("Unsupported slugify mode: {$m}");
             }
             $finalSlugify |= $slugifyModes[$m];
         } else {
             if (!isset($slugifyFlags[$m])) {
                 throw new PieCrustException("Unsupported slugify flag: {$m}");
             }
             $finalSlugify |= $slugifyFlags[$m];
         }
     }
     // We always want to slugify the `.` (dot) character, at least for tags
     // and categories, because it would screw up how we figure out what
     // extension to use for output files.
     $finalSlugify |= UriBuilder::SLUGIFY_FLAG_DOT_TO_DASH;
     $siteConfig['slugify_flags'] = $finalSlugify;
     return $config;
 }
 /**
  * Returns a validated version of the given site configuration.
  *
  * This is exposed as a public static function for convenience (unit tests,
  * etc.)
  */
 public static function getValidatedConfig($config)
 {
     // Validate defaults.
     if (!$config) {
         $config = array();
     }
     if (!isset($config['site'])) {
         $config['site'] = array();
     }
     $config['site'] = array_merge(array('title' => 'Untitled PieCrust Website', 'root' => null, 'theme_root' => null, 'default_format' => PieCrustDefaults::DEFAULT_FORMAT, 'default_template_engine' => PieCrustDefaults::DEFAULT_TEMPLATE_ENGINE, 'enable_gzip' => false, 'pretty_urls' => false, 'posts_fs' => PieCrustDefaults::DEFAULT_POSTS_FS, 'date_format' => PieCrustDefaults::DEFAULT_DATE_FORMAT, 'blogs' => array(PieCrustDefaults::DEFAULT_BLOG_KEY), 'plugins_sources' => array(PieCrustDefaults::DEFAULT_PLUGIN_SOURCE), 'themes_sources' => array(PieCrustDefaults::DEFAULT_THEME_SOURCE), 'cache_time' => 28800, 'display_errors' => false, 'enable_debug_info' => true), $config['site']);
     // Validate the site root URL, and remember if it was specified in the
     // source config.yml, because we won't be able to tell the difference from
     // the completely validated cache version.
     if ($config['site']['root'] == null) {
         $config['site']['root'] = ServerHelper::getSiteRoot($_SERVER);
         $config['site']['is_auto_root'] = true;
     } else {
         $config['site']['root'] = rtrim($config['site']['root'], '/') . '/';
         $config['site']['is_auto_root'] = false;
     }
     // Validate the plugins sources.
     if (!is_array($config['site']['plugins_sources'])) {
         $config['site']['plugins_sources'] = array($config['site']['plugins_sources']);
     }
     if (!in_array(PieCrustDefaults::DEFAULT_PLUGIN_SOURCE, $config['site']['plugins_sources'])) {
         $config['site']['plugins_sources'][] = PieCrustDefaults::DEFAULT_PLUGIN_SOURCE;
     }
     // Validate the themes sources.
     if (!is_array($config['site']['themes_sources'])) {
         $config['site']['themes_sources'] = array($config['site']['themes_sources']);
     }
     if (!in_array(PieCrustDefaults::DEFAULT_THEME_SOURCE, $config['site']['themes_sources'])) {
         $config['site']['themes_sources'][] = PieCrustDefaults::DEFAULT_THEME_SOURCE;
     }
     // Validate multi-blogs settings.
     if (in_array(PieCrustDefaults::DEFAULT_BLOG_KEY, $config['site']['blogs']) and count($config['site']['blogs']) > 1) {
         throw new PieCrustException("'" . PieCrustDefaults::DEFAULT_BLOG_KEY . "' cannot be specified as a blog key for multi-blog configurations. Please pick custom keys.");
     }
     // Add default values for the blogs configurations, or use values
     // defined at the site level for easy site-wide configuration of multiple blogs
     // and backwards compatibility.
     $defaultValues = array('post_url' => '%year%/%month%/%day%/%slug%', 'tag_url' => 'tag/%tag%', 'category_url' => '%category%', 'posts_per_page' => 5);
     foreach (array_keys($defaultValues) as $key) {
         if (isset($config['site'][$key])) {
             $defaultValues[$key] = $config['site'][$key];
         }
     }
     foreach ($config['site']['blogs'] as $blogKey) {
         $prefix = '';
         if ($blogKey != PieCrustDefaults::DEFAULT_BLOG_KEY) {
             $prefix = $blogKey . '/';
         }
         if (!isset($config[$blogKey])) {
             $config[$blogKey] = array();
         }
         $config[$blogKey] = array_merge(array('post_url' => $prefix . $defaultValues['post_url'], 'tag_url' => $prefix . $defaultValues['tag_url'], 'category_url' => $prefix . $defaultValues['category_url'], 'posts_per_page' => $defaultValues['posts_per_page'], 'date_format' => $config['site']['date_format']), $config[$blogKey]);
     }
     return $config;
 }