Example #1
0
 /**
  * Initialize the database providers.
  */
 public function initDatabase()
 {
     $dboptions = $this['config']->getDBOptions();
     $this->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $dboptions));
     // Do a dummy query, to check for a proper connection to the database.
     try {
         $this['db']->query("SELECT 1;");
     } catch (\PDOException $e) {
         $error = "Bolt could not connect to the database. Make sure the database is configured correctly in\n                    <code>app/config/config.yml</code>, that the database engine is running.";
         if ($dboptions['driver'] != 'pdo_sqlite') {
             $error .= "<br><br>Since you're using " . $dboptions['driver'] . ", you should also make sure that the\n                database <code>" . $dboptions['dbname'] . "</code> exists, and the configured user has access to it.";
         }
         $checker = new \LowlevelChecks();
         $checker->lowLevelError($error);
     }
     if ($dboptions['driver'] == 'pdo_sqlite') {
         $this['db']->query('PRAGMA synchronous = OFF');
     } elseif ($dboptions['driver'] == 'pdo_mysql') {
         /**
          * @link https://groups.google.com/forum/?fromgroups=#!topic/silex-php/AR3lpouqsgs
          */
         $this['db']->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
         // set utf8 on names and connection as all tables has this charset
         $this['db']->query("SET NAMES 'utf8';");
         $this['db']->query("SET CHARACTER SET 'utf8';");
         $this['db']->query("SET CHARACTER_SET_CONNECTION = 'utf8';");
     }
     $this->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => BOLT_CACHE_DIR));
 }
 /**
  * The constructor requires a resource manager object to perform checks against.
  * This should ideally be typehinted to Bolt\Configuration\ResourceManager
  *
  * @return void
  **/
 public function __construct($config = null)
 {
     parent::__construct($config);
     $this->addCheck('extensions');
     $this->addCheck('publicAssets');
     $this->addCheck('database', true);
     $this->addCheck('config', true);
 }
Example #3
0
<?php

$bolt_version = "0.8";
$bolt_buildnumber = "";
$bolt_name = "Second beta";
// First, do some low level checks, like whether autoload is present, the cache
// folder is writable, if the minimum PHP version is present, etc.
require_once __DIR__ . '/classes/lib.php';
require_once __DIR__ . '/classes/lowlevelchecks.php';
$checker = new LowlevelChecks();
$checker->doChecks();
// Let's get on with the rest..
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/classes/util.php';
// Start the timer:
$starttime = getMicrotime();
$config = getConfig();
$dboptions = getDBOptions($config);
$app = new Silex\Application();
$app['debug'] = !empty($config['general']['debug']) ? $config['general']['debug'] : false;
$app['config'] = $config;
$app->register(new Silex\Provider\SessionServiceProvider(), array('session.storage.options' => array('name' => 'bolt_session', 'cookie_lifetime' => $config['general']['cookies_lifetime'])));
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => $config['twigpath'], 'twig.options' => array('debug' => true, 'cache' => __DIR__ . '/cache/', 'strict_variables' => $config['general']['strict_variables'], 'autoescape' => false)));
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $dboptions));
$app->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => __DIR__ . '/cache/'));
$app->register(new Silex\Provider\SwiftmailerServiceProvider());
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\FormServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), array('translator.messages' => array()));
// Loading stub functions for when intl / IntlDateFormatter isn't available.
Example #4
0
 /**
  * Load the configuration from the various YML files.
  */
 public function getConfig()
 {
     $config = array();
     // Read the config
     $config['general'] = array_merge($this->parseConfigYaml('config.yml'), $this->parseConfigYaml('config_local.yml'));
     $config['taxonomy'] = $this->parseConfigYaml('taxonomy.yml');
     $tempContentTypes = $this->parseConfigYaml('contenttypes.yml');
     $config['menu'] = $this->parseConfigYaml('menu.yml');
     $config['routing'] = $this->parseConfigYaml('routing.yml');
     $config['permissions'] = $this->parseConfigYaml('permissions.yml');
     $config['extensions'] = array();
     // fetch the theme config. requires special treatment due to the path
     $paths = getPaths($config);
     $themeConfigFile = $paths['themepath'] . '/config.yml';
     $config['theme'] = $this->parseConfigYaml($themeConfigFile, array(), false);
     // @todo: If no config files can be found, get them from bolt.cm/files/default/
     $this->paths = getPaths($config);
     $this->setDefaults();
     // Make sure old settings for 'contentsCss' are still picked up correctly
     if (isset($config['general']['wysiwyg']['ck']['contentsCss'])) {
         $config['general']['wysiwyg']['ck']['contentsCss'] = array(1 => $config['general']['wysiwyg']['ck']['contentsCss']);
     }
     // Make sure old settings for 'accept_file_types' are not still picked up. Before 1.5.4 we used to store them
     // as a regex-like string, and we switched to an array. If we find the old style, fall back to the defaults.
     if (isset($config['general']['accept_file_types']) && !is_array($config['general']['accept_file_types'])) {
         unset($config['general']['accept_file_types']);
     }
     // Merge the array with the defaults. Setting the required values that aren't already set.
     $config['general'] = array_merge_recursive_distinct($this->defaultConfig, $config['general']);
     // Make sure the cookie_domain for the sessions is set properly.
     if (empty($config['general']['cookies_domain'])) {
         if (isset($_SERVER['HTTP_HOST'])) {
             $hostname = $_SERVER['HTTP_HOST'];
         } elseif (isset($_SERVER['SERVER_NAME'])) {
             $hostname = $_SERVER['SERVER_NAME'];
         } else {
             $hostname = '';
         }
         // Don't set the domain for a cookie on a "TLD" - like 'localhost', or if the server_name is an IP-address
         if (strpos($hostname, '.') > 0 && preg_match("/[a-z0-9]/i", $hostname)) {
             if (preg_match("/^www[0-9]*./", $hostname)) {
                 $config['general']['cookies_domain'] = '.' . preg_replace("/^www[0-9]*./", '', $hostname);
             } else {
                 $config['general']['cookies_domain'] = '.' . $hostname;
             }
             // Make sure we don't have consecutive '.'-s in the cookies_domain..
             $config['general']['cookies_domain'] = str_replace('..', '.', $config['general']['cookies_domain']);
         } else {
             $config['general']['cookies_domain'] = '';
         }
     }
     // Make sure Bolt's mount point is OK:
     $config['general']['branding']['path'] = '/' . safeString($config['general']['branding']['path']);
     // Make sure $config['taxonomy'] is an array. (if the file is empty, YAML parses it as NULL)
     if (empty($config['taxonomy'])) {
         $config['taxonomy'] = array();
     }
     // Clean up taxonomies
     foreach ($config['taxonomy'] as $key => $value) {
         if (!isset($config['taxonomy'][$key]['name'])) {
             $config['taxonomy'][$key]['name'] = ucwords($config['taxonomy'][$key]['slug']);
         }
         if (!isset($config['taxonomy'][$key]['singular_name'])) {
             if (isset($config['taxonomy'][$key]['singular_slug'])) {
                 $config['taxonomy'][$key]['singular_name'] = ucwords($config['taxonomy'][$key]['singular_slug']);
             } else {
                 $config['taxonomy'][$key]['singular_name'] = ucwords($config['taxonomy'][$key]['slug']);
             }
         }
         if (!isset($config['taxonomy'][$key]['slug'])) {
             $config['taxonomy'][$key]['slug'] = strtolower(safeString($config['taxonomy'][$key]['name']));
         }
         if (!isset($config['taxonomy'][$key]['singular_slug'])) {
             $config['taxonomy'][$key]['singular_slug'] = strtolower(safeString($config['taxonomy'][$key]['singular_name']));
         }
         if (!isset($config['taxonomy'][$key]['has_sortorder'])) {
             $config['taxonomy'][$key]['has_sortorder'] = false;
         }
         // Make sure the options are $key => $value pairs, and not have implied integers for keys.
         if (!empty($config['taxonomy'][$key]['options']) && is_array($config['taxonomy'][$key]['options'])) {
             $options = array();
             foreach ($config['taxonomy'][$key]['options'] as $optionkey => $value) {
                 if (is_numeric($optionkey)) {
                     $optionkey = makeSlug($value);
                     // was: strtolower(safeString($value));
                 }
                 $options[$optionkey] = $value;
             }
             $config['taxonomy'][$key]['options'] = $options;
         }
         // If taxonomy is like tags, set 'tagcloud' to true by default.
         if ($config['taxonomy'][$key]['behaves_like'] == 'tags' && !isset($config['taxonomy'][$key]['tagcloud'])) {
             $config['taxonomy'][$key]['tagcloud'] = true;
         }
     }
     // Clean up contenttypes
     $config['contenttypes'] = array();
     foreach ($tempContentTypes as $key => $temp) {
         // If the slug isn't set, and the 'key' isn't numeric, use that as the slug.
         if (!isset($temp['slug']) && !is_numeric($key)) {
             $temp['slug'] = makeSlug($key);
         }
         // If neither 'name' nor 'slug' is set, we need to warn the user. Same goes for when
         // neither 'singular_name' nor 'singular_slug' is set.
         if (!isset($temp['name']) && !isset($temp['slug'])) {
             $error = sprintf("In contenttype <code>%s</code>, neither 'name' nor 'slug' is set. Please edit <code>contenttypes.yml</code>, and correct this.", $key);
             $llc = new \LowlevelChecks();
             $llc->lowlevelError($error);
         }
         if (!isset($temp['singular_name']) && !isset($temp['singular_slug'])) {
             $error = sprintf("In contenttype <code>%s</code>, neither 'singular_name' nor 'singular_slug' is set. Please edit <code>contenttypes.yml</code>, and correct this.", $key);
             $llc = new \LowlevelChecks();
             $llc->lowlevelError($error);
         }
         if (!isset($temp['slug'])) {
             $temp['slug'] = makeSlug($temp['name']);
         }
         if (!isset($temp['singular_slug'])) {
             $temp['singular_slug'] = makeSlug($temp['singular_name']);
         }
         if (!isset($temp['show_on_dashboard'])) {
             $temp['show_on_dashboard'] = true;
         }
         if (!isset($temp['sort'])) {
             $temp['sort'] = '';
         }
         if (!isset($temp['default_status'])) {
             $temp['default_status'] = 'draft';
         }
         // Make sure all fields are lowercase and 'safe'.
         $tempfields = $temp['fields'];
         $temp['fields'] = array();
         foreach ($tempfields as $key => $value) {
             // Fix name 'keys' for fields
             $key = str_replace('-', '_', strtolower(safeString($key, true)));
             $temp['fields'][$key] = $value;
             // If field is a "file" type, make sure the 'extensions' are set, and it's an array.
             if ($temp['fields'][$key]['type'] == 'file' || $temp['fields'][$key]['type'] == 'filelist') {
                 if (empty($temp['fields'][$key]['extensions'])) {
                     $temp['fields'][$key]['extensions'] = array_intersect(array('doc', 'docx', 'txt', 'md', 'pdf', 'xls', 'xlsx', 'ppt', 'pptx', 'csv'), $config['general']['accept_file_types']);
                 }
                 if (!is_array($temp['fields'][$key]['extensions'])) {
                     $temp['fields'][$key]['extensions'] = array($temp['fields'][$key]['extensions']);
                 }
             }
             // If field is an "image" type, make sure the 'extensions' are set, and it's an array.
             if ($temp['fields'][$key]['type'] == 'image' || $temp['fields'][$key]['type'] == 'imagelist') {
                 if (empty($temp['fields'][$key]['extensions'])) {
                     $temp['fields'][$key]['extensions'] = array_intersect(array('gif', 'jpg', 'jpeg', 'png'), $config['general']['accept_file_types']);
                 }
                 if (!is_array($temp['fields'][$key]['extensions'])) {
                     $temp['fields'][$key]['extensions'] = array($temp['fields'][$key]['extensions']);
                 }
             }
         }
         // Make sure the 'uses' of the slug is an array.
         if (isset($temp['fields']['slug']) && isset($temp['fields']['slug']['uses']) && !is_array($temp['fields']['slug']['uses'])) {
             $temp['fields']['slug']['uses'] = array($temp['fields']['slug']['uses']);
         }
         // Make sure taxonomy is an array.
         if (isset($temp['taxonomy']) && !is_array($temp['taxonomy'])) {
             $temp['taxonomy'] = array($temp['taxonomy']);
         }
         // when adding relations, make sure they're added by their slug. Not their 'name' or 'singular name'.
         if (!empty($temp['relations']) && is_array($temp['relations'])) {
             foreach ($temp['relations'] as $key => $relation) {
                 if ($key != makeSlug($key)) {
                     $temp['relations'][makeSlug($key)] = $temp['relations'][$key];
                     unset($temp['relations'][$key]);
                 }
             }
         }
         $config['contenttypes'][$temp['slug']] = $temp;
     }
     // Set all the distinctive arrays as part of our Config object.
     $this->data = $config;
 }
Example #5
0
        define('BOLT_COMPOSER_INSTALLED', false);
        define('BOLT_PROJECT_ROOT_DIR', dirname(__DIR__));
        define('BOLT_WEB_DIR', BOLT_PROJECT_ROOT_DIR);
        // Set the config folder location. If we haven't set the constant in index.php, use one of the
        // default values.
        if (!defined('BOLT_CONFIG_DIR')) {
            if (is_dir(__DIR__ . '/config')) {
                // Default value, /app/config/..
                define('BOLT_CONFIG_DIR', __DIR__ . '/config');
            } else {
                // otherwise use /config, outside of the webroot folder.
                define('BOLT_CONFIG_DIR', dirname(dirname(__DIR__)) . '/config');
            }
        }
    }
}
// First, do some low level checks, like whether autoload is present, the cache
// folder is writable, if the minimum PHP version is present, etc.
require_once __DIR__ . '/classes/lib.php';
require_once __DIR__ . '/classes/lowlevelchecks.php';
$checker = new LowlevelChecks();
$checker->doChecks();
// Let's get on with the rest..
require_once BOLT_PROJECT_ROOT_DIR . '/vendor/autoload.php';
require_once __DIR__ . '/classes/util.php';
// Create the 'Bolt application'.
$app = new Bolt\Application();
// Finally, check if the app/database folder is writable, if it needs to be.
$checker->doDatabaseCheck($app['config']);
// Initialize the 'Bolt application': Set up all routes, providers, database, templating, etc..
$app->initialize();