private static function getKey()
 {
     if (self::$key) {
         return self::$key;
     }
     return self::$key = substr(Cookie::getSecretKey(), 0, 32);
 }
Ejemplo n.º 2
0
<?php

/*
|--------------------------------------------------------------------------
| Load Site Configuration
|--------------------------------------------------------------------------
|
| Before anything we need to load all the user-specified configurations,
| global variables, custom routes, and theme settings. Many methods
| depend on these settings.
|
*/
$config = Statamic::loadAllConfigs();
$config['_cookies.secret_key'] = Cookie::getSecretKey();
$config['log_enabled'] = TRUE;
$config['log.level'] = Log::convert_log_level($config['_log_level']);
$config['whoops.editor'] = 'sublime';
$config['log.writer'] = new Statamic_Logwriter(array('path' => $config['_log_file_path'], 'file_prefix' => $config['_log_file_prefix']));
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Many users are upgrading to PHP 5.3 for the first time. I know.
| We've gone ahead set the default timezone that will be used by the PHP
| date and date-time functions. This prevents some potentially
| frustrating errors for novice developers.
|
*/
date_default_timezone_set(Helper::pick($config['_timezone'], @date_default_timezone_get(), "UTC"));
/*
Ejemplo n.º 3
0
 /**
  * Creates a hash for this user
  * 
  * @param Member  $member  Member object
  * @return string
  */
 protected static function createHash($member)
 {
     return $member->get('username') . ':' . md5($member->get('password_hash') . Cookie::getSecretKey());
 }
Ejemplo n.º 4
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);
                }
            }
        }

        Debug::markEnd($hash);

        /*
        |--------------------------------------------------------------------------
        | 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.
        |
        */

        $hash = Debug::markStart('config', 'finding');
        
        $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['_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');
;
        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'];
        $config['_cookies.secret_key']  = Cookie::getSecretKey();

        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;
    }
/*
|--------------------------------------------------------------------------
| Slim Initialization
|--------------------------------------------------------------------------
|
| Time to get an instance of Slim fired up. We're passing the $config
| array, which contains a bit more data than necessary, but helps keep
| everything simple.
|
*/
$config['whoops.editor'] = 'sublime';
$admin_app = new \Slim\Slim(array_merge($config, array('view' => new Statamic_View())));
// Initialize Whoops middleware
$admin_app->add(new \Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware());
$admin_app->config = $config;
$admin_app->config['_cookies.secret_key'] = Cookie::getSecretKey();
/*
|--------------------------------------------------------------------------
| Cookies for the Monster
|--------------------------------------------------------------------------
|
| Get the Slim Cookie middleware running the specified lifetime.
|
*/
session_cache_limiter(false);
session_start();
/*
|--------------------------------------------------------------------------
| Check for Disabled Control Panel
|--------------------------------------------------------------------------
|