public static function nav_count()
 {
     $default_config = YAML::parse(Config::getAppConfigPath() . '/default.settings.yaml');
     $admin_nav = array_merge($default_config['_admin_nav'], Config::get('_admin_nav', array()));
     return count(array_filter($admin_nav, 'strlen'));
 }
Example #2
0
File: statamic.php Project: nob/joi
 /**
  * Load the config (yaml) files in a specified order:
  *
  * 1. Loose per-site configs
  * 2. Routes
  * 3. Settings
  * 4. Theme overrides
  */
 public static function loadAllConfigs($admin = FALSE)
 {
     /*
     |--------------------------------------------------------------------------
     | YAML Mode
     |--------------------------------------------------------------------------
     |
     | We need to know the YAML mode first (loose, strict, transitional),
     | so we parse the settings file once to check before doing anything else.
     |
     */
     $preload_config = YAML::parse(Config::getConfigPath() . '/settings.yaml');
     $yaml_mode = array_get($preload_config, '_yaml_mode', 'loose');
     /*
     |--------------------------------------------------------------------------
     | Default Settings
     |--------------------------------------------------------------------------
     |
     | We keep a set of default options that the user config overrides, allowing
     | us to always have clean defaults.
     |
     */
     $default_config = YAML::parse(Config::getAppConfigPath() . '/default.settings.yaml');
     /*
     |--------------------------------------------------------------------------
     | User Site Settings
     |--------------------------------------------------------------------------
     |
     | Next we parse and override the user's settings.
     |
     */
     $user_config = YAML::parse(Config::getConfigPath() . '/settings.yaml', $yaml_mode);
     $config = array_merge($default_config, $user_config);
     /*
     |--------------------------------------------------------------------------
     | Routes and vanity URLs
     |--------------------------------------------------------------------------
     |
     | Any URL can be manipulated by routes or vanity urls. We need this info
     | early on, before content parsing begins.
     |
     */
     $routes = array();
     if (File::exists(Config::getConfigPath() . '/routes.yaml')) {
         $routes['_routes'] = YAML::parse('_config/routes.yaml', $yaml_mode);
     }
     // check for vanity URLs first, we may need to redirect
     $vanity = array();
     if (File::exists(Config::getConfigPath() . '/vanity.yaml')) {
         $vanity['_vanity_urls'] = YAML::parse(Config::getConfigPath() . '/vanity.yaml', $yaml_mode);
     }
     $config = array_merge($config, $routes, $vanity);
     /*
     |--------------------------------------------------------------------------
     | Global Variables
     |--------------------------------------------------------------------------
     |
     | We parse all the yaml files in the root (except settings and routes) of
     | the config folder and make them available as global template variables.
     |
     */
     if (Folder::exists($config_files_location = Config::getConfigPath())) {
         $finder = new Finder();
         $files = $finder->files()->in($config_files_location)->name('*.yaml')->notName('routes.yaml')->notName('vanity.yaml')->notName('settings.yaml')->depth(0);
         if (iterator_count($files) > 0) {
             foreach ($files as $file) {
                 $config = array_merge($config, YAML::parse($file->getRealPath(), $yaml_mode));
             }
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Theme Variables
     |--------------------------------------------------------------------------
     |
     | Theme variables need to specifically parsed later so they can override
     | any site/global defaults.
     |
     */
     $themes_path = array_get($config, '_themes_path', '_themes');
     $theme_name = array_get($config, '_theme', 'denali');
     if (Folder::exists($theme_files_location = URL::assemble(BASE_PATH, $themes_path, $theme_name))) {
         $finder = new Finder();
         // clear previous Finder interator results
         $theme_files = $finder->files()->in($theme_files_location)->name('*.yaml')->depth(0);
         if (iterator_count($theme_files) > 0) {
             foreach ($theme_files as $file) {
                 $config = array_merge($config, YAML::parse($file->getRealPath(), $yaml_mode));
             }
         }
     }
     /*
     |--------------------------------------------------------------------------
     | MIME Types
     |--------------------------------------------------------------------------
     */
     $config = array_merge($config, array('_mimes' => require Config::getAppConfigPath() . '/mimes.php'));
     /*
     |--------------------------------------------------------------------------
     | Localization
     |--------------------------------------------------------------------------
     |
     | We load up English by default. We're American after all. Doesn't the
     | world revolve around us? Hello? Bueller? More hamburgers please.
     |
     */
     $config['_translations'] = array();
     $config['_translations']['en'] = YAML::parse(Config::getAppConfigPath() . '/default.en.yaml');
     /*
     |--------------------------------------------------------------------------
     | Set Slim Config
     |--------------------------------------------------------------------------
     |
     | Slim needs to be initialized with a set of config options, so these
     | need to be set earlier than the set_default_tags() method.
     |
     */
     // $config['view'] = new Statamic_View();
     $config['cookies.lifetime'] = $config['_cookies.lifetime'];
     if ($admin) {
         $admin_theme = array_get($config, '_admin_theme', 'ascent');
         if (!Folder::exists(Path::tidy('/' . $config['_admin_path'] . '/' . 'themes/' . $admin_theme))) {
             $admin_theme = 'ascent';
         }
         $theme_path = Path::tidy('/' . $config['_admin_path'] . '/' . 'themes/' . $admin_theme . '/');
         $config['_admin_path'] = $config['_admin_path'];
         $config['theme_path'] = $theme_path;
         $config['templates.path'] = '.' . $theme_path;
     } else {
         $public_path = isset($config['_public_path']) ? $config['_public_path'] : '';
         $config['theme_path'] = '_themes/' . $config['_theme'] . "/";
         $config['templates.path'] = Path::tidy($public_path . '_themes/' . $config['_theme'] . "/");
     }
     return $config;
 }
Example #3
0
 /**
  * Load the config (yaml) files in a specified order:
  *
  * 1. Loose per-site configs
  * 2. Routes
  * 3. Settings
  * 4. Theme overrides
  */
 public static function loadAllConfigs($admin = false)
 {
     $hash = Debug::markStart('config', 'finding');
     /*
     |--------------------------------------------------------------------------
     | YAML Mode
     |--------------------------------------------------------------------------
     |
     | We need to know the YAML mode first (loose, strict, transitional),
     | so we parse the settings file once to check before doing anything else.
     |
     */
     $preload_config = YAML::parse(Config::getConfigPath() . '/settings.yaml');
     $yaml_mode = array_get($preload_config, '_yaml_mode', 'loose');
     /*
     |--------------------------------------------------------------------------
     | Default Settings
     |--------------------------------------------------------------------------
     |
     | We keep a set of default options that the user config overrides, allowing
     | us to always have clean defaults.
     |
     */
     $settings_to_parse = File::get(Config::getAppConfigPath() . '/default.settings.yaml');
     /*
     |--------------------------------------------------------------------------
     | User Site Settings
     |--------------------------------------------------------------------------
     |
     | Next we parse and override the user's settings.
     |
     */
     $settings_to_parse .= "\n\n" . File::get(Config::getConfigPath() . '/settings.yaml');
     /*
     |--------------------------------------------------------------------------
     | Routes and vanity URLs
     |--------------------------------------------------------------------------
     |
     | Any URL can be manipulated by routes or vanity urls. We need this info
     | early on, before content parsing begins.
     |
     */
     $settings_to_parse .= "\n\n_routes:\n  " . trim(preg_replace("/\n/", "\n  ", File::get(Config::getConfigPath() . '/routes.yaml')));
     $settings_to_parse .= "\n\n_vanity_urls:\n  " . trim(preg_replace("/\n/", "\n  ", File::get(Config::getConfigPath() . '/vanity.yaml')));
     /*
     |--------------------------------------------------------------------------
     | Global Variables
     |--------------------------------------------------------------------------
     |
     | We parse all the yaml files in the root (except settings and routes) of
     | the config folder and make them available as global template variables.
     |
     */
     if (Folder::exists($config_files_location = Config::getConfigPath())) {
         $files = glob($config_files_location . '/*.yaml');
         if ($files) {
             foreach ($files as $file) {
                 if (strpos($file, 'routes.yaml') !== false || strpos($file, 'vanity.yaml') !== false || strpos($file, 'settings.yaml')) {
                     continue;
                 }
                 $settings_to_parse .= "\n\n" . File::get($file);
             }
         }
     }
     /*
     |--------------------------------------------------------------------------
     | Parse settings up until now
     |--------------------------------------------------------------------------
     |
     | Parses the concatenated settings string we've made so far.
     |
     */
     $config = YAML::parse($settings_to_parse, $yaml_mode);
     /*
     |--------------------------------------------------------------------------
     | Theme Variables
     |--------------------------------------------------------------------------
     |
     | Theme variables need to specifically parsed later so they can override
     | any site/global defaults.
     |
     */
     $themes_path = array_get($config, '_themes_path', '_themes');
     $theme_name = array_get($config, '_theme', 'acadia');
     // reset
     $settings_to_parse = '';
     if (Folder::exists($theme_files_location = Path::assemble(BASE_PATH, $themes_path, $theme_name))) {
         $theme_files = glob(Path::tidy($theme_files_location . '/*.yaml'));
         if ($theme_files) {
             foreach ($theme_files as $file) {
                 $settings_to_parse .= "\n\n" . File::get($file);
             }
         }
     }
     Debug::markEnd($hash);
     // parse theme settings if any
     if ($settings_to_parse) {
         $config = YAML::parse($settings_to_parse, $yaml_mode) + $config;
     }
     /*
     |--------------------------------------------------------------------------
     | Load Environment Configs and Variables
     |--------------------------------------------------------------------------
     |
     | Environments settings explicitly overwrite any existing settings, and
     | therefore must be loaded late. We also set a few helper variables
     | to make working with environments even easier.
     |
     */
     _Environment::establish($config);
     /*
     |--------------------------------------------------------------------------
     | MIME Types
     |--------------------------------------------------------------------------
     */
     $config = array('_mimes' => require Config::getAppConfigPath() . '/mimes.php') + $config;
     /*
     |--------------------------------------------------------------------------
     | Localization
     |--------------------------------------------------------------------------
     |
     | We load up English by default. We're American after all. Doesn't the
     | world revolve around us? Hello? Bueller? More hamburgers please.
     |
     */
     $config['_translations'] = array();
     $config['_translations']['en'] = YAML::parse(Config::getAppConfigPath() . '/default.en.yaml');
     if ($lang = array_get($config, '_language', false)) {
         if (File::exists(Config::getTranslation($lang))) {
             $translation = YAML::parse(Config::getTranslation($lang));
             $config['_translations'][$lang] = Helper::arrayCombineRecursive($config['_translations']['en'], $translation);
         }
     }
     $finder = new Finder();
     // clear previous Finder interator results
     try {
         $translation_files = $finder->files()->in(BASE_PATH . Config::getAddonsPath() . '/*/translations')->name($lang . '.*.yaml')->depth(0)->followLinks();
         foreach ($translation_files as $file) {
             $translation = YAML::parse($file->getRealPath());
             $config['_translations'][$lang] = Helper::arrayCombineRecursive($translation, $config['_translations'][$lang]);
         }
     } catch (Exception $e) {
         // meh. not important.
     }
     /*
     |--------------------------------------------------------------------------
     | Set Slim Config
     |--------------------------------------------------------------------------
     |
     | Slim needs to be initialized with a set of config options, so these
     | need to be set earlier than the set_default_tags() method.
     |
     */
     // $config['view'] = new Statamic_View();
     $config['cookies.lifetime'] = $config['_cookies.lifetime'];
     if ($admin) {
         $admin_theme = array_get($config, '_admin_theme', 'ascent');
         if (!Folder::exists(BASE_PATH . Path::tidy('/' . $config['_admin_path'] . '/' . 'themes/' . $admin_theme))) {
             $admin_theme = 'ascent';
         }
         $theme_path = Path::tidy('/' . $config['_admin_path'] . '/' . 'themes/' . $admin_theme . '/');
         $config['theme_path'] = $theme_path;
         $config['templates.path'] = '.' . $theme_path;
     } else {
         $public_path = isset($config['_public_path']) ? $config['_public_path'] : '';
         $config['theme_path'] = $themes_path . '/' . $config['_theme'] . '/';
         $config['templates.path'] = Path::tidy($public_path . $themes_path . '/' . $config['_theme'] . '/');
     }
     if (!array_get($config, '_display_debug_panel', false)) {
         Debug::disable();
     }
     return $config;
 }
Example #4
0
 /**
  * Get Globals & Theme Variables
  *
  * Create global variables from v1 globals and theme variables
  *
  * @return array
  */
 private function createGlobals()
 {
     $globals = array('settings' => array(), 'global' => array(), 'theme' => array());
     // Get a list of variables added to _config/settings.yaml
     // Anything not also in the defaults will be considered a global added manually.
     $defaults = array_keys(YAML::parseFile(Config::getAppConfigPath() . '/default.settings.yaml'));
     $settings = array_keys(YAML::parseFile(Config::getConfigPath() . '/settings.yaml'));
     $settings_globals = array_diff($settings, $defaults);
     foreach ($settings_globals as $setting) {
         $setting = ltrim($setting, '_');
         $globals['settings'][$setting] = Config::get($setting);
     }
     // Get a list of variables in _config/global.yaml
     $site_globals = Config::getConfigPath() . '/global.yaml';
     if (File::exists($site_globals)) {
         $globals['global'] = YAML::parse($site_globals);
     }
     // Get a list of variables in the theme.yaml
     $theme_globals = Config::getCurrentThemePath() . 'theme.yaml';
     if (File::exists($theme_globals)) {
         $globals['theme'] = YAML::parse($theme_globals);
     }
     $this->migration['globals'] = $globals;
 }