From 16f0bd49669ea3a177acf1dcf5b337cb9ca596b4 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 6 Jul 2013 12:11:29 -0400 Subject: [PATCH] Add support to override application constants --- .gitignore | 4 ++++ README.markdown | 22 ++++++++++++++++++++++ common.php | 18 ++++++------------ index.php | 6 +++--- model.php | 1 + 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 7d23e93..9b8d154 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,7 @@ Thumbs.db *~ *.lock *.out + +# App specific # +################ +config.php \ No newline at end of file diff --git a/README.markdown b/README.markdown index e9b1100..bb00576 100644 --- a/README.markdown +++ b/README.markdown @@ -118,3 +118,25 @@ You can report feeds that doesn't works properly too. Miniflux is tested with the latest versions of Mozilla Firefox, Google Chrome and Safari. I don't use Microsoft products, then I have no idea if Miniflux works correctly with Internet Explorer. + +### How to override application variables? + +There is few settings that can't be changed by the user interface. +These parameters are defined with PHP constants. + +To override them, create a `config.php` file at the root of the project and change yourself the values. + +By example, to override the default HTTP timeout value: + + # file config.php + + default value is 10 seconds +- `APP_VERSION` => default value is master +- `DB_FILENAME` => default value is `data/db.sqlite` diff --git a/common.php b/common.php index 3e9ad9e..fc85c59 100644 --- a/common.php +++ b/common.php @@ -9,26 +9,20 @@ require 'vendor/PicoDb/Table.php'; require 'schema.php'; require 'model.php'; +if (file_exists('config.php')) require 'config.php'; -const DB_VERSION = 9; -const APP_VERSION = 'master'; -const HTTP_TIMEOUT = 10; - - -function get_db_filename() -{ - return 'data/db.sqlite'; -} - +defined('APP_VERSION') or define('APP_VERSION', 'master'); +defined('HTTP_TIMEOUT') or define('HTTP_TIMEOUT', 10); +defined('DB_FILENAME') or define('DB_FILENAME', 'data/db.sqlite'); PicoTools\container('db', function() { $db = new PicoDb\Database(array( 'driver' => 'sqlite', - 'filename' => get_db_filename() + 'filename' => DB_FILENAME )); - if ($db->schema()->check(DB_VERSION)) { + if ($db->schema()->check(Model\DB_VERSION)) { return $db; } diff --git a/index.php b/index.php index 732eaee..49203a9 100644 --- a/index.php +++ b/index.php @@ -394,7 +394,7 @@ Router\get_action('optimize-db', function() { Router\get_action('download-db', function() { Response\force_download('db.sqlite.gz'); - Response\binary(gzencode(file_get_contents(get_db_filename()))); + Response\binary(gzencode(file_get_contents(DB_FILENAME))); }); @@ -439,7 +439,7 @@ Router\get_action('config', function() { Response\html(Template\layout('config', array( 'errors' => array(), 'values' => Model\get_config(), - 'db_size' => filesize(get_db_filename()), + 'db_size' => filesize(DB_FILENAME), 'languages' => Model\get_languages(), 'autoflush_options' => Model\get_autoflush_options(), 'paging_options' => Model\get_paging_options(), @@ -472,7 +472,7 @@ Router\post_action('config', function() { Response\html(Template\layout('config', array( 'errors' => $errors, 'values' => $values, - 'db_size' => filesize(get_db_filename()), + 'db_size' => filesize(DB_FILENAME), 'languages' => Model\get_languages(), 'autoflush_options' => Model\get_autoflush_options(), 'paging_options' => Model\get_paging_options(), diff --git a/model.php b/model.php index 9ed09ad..65928ad 100644 --- a/model.php +++ b/model.php @@ -22,6 +22,7 @@ use PicoFeed\Reader; use PicoFeed\Export; +const DB_VERSION = 9; const HTTP_USERAGENT = 'Miniflux - http://miniflux.net'; const LIMIT_ALL = -1;