From 4a2912880f0914b456711d695f96ce2ace18c814 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Nicolas=20L=C5=93uillet?= {{ msg|raw }} Don't forget the documentation.
{% trans "poche is still not installed. Please fill the below form to install it. Don't hesitate to read the documentation on poche website." %}
-
-
-
-
To install your poche with sqlite, copy /install/poche.sqlite in /db and delete the folder /install. you have to delete the /install folder before using poche.');
+ $this->initTpl();
+ if (!$this->checkBeforeInstall()) {
+ exit;
}
-
$this->store = new Database();
$this->init();
$this->messages = new Messages();
@@ -34,27 +33,37 @@ class Poche
}
}
- private function init()
+ /**
+ * all checks before installation.
+ * @return boolean
+ */
+ private function checkBeforeInstall()
{
- Tools::initPhp();
- Session::init();
+ $msg = '';
+ $allIsGood = TRUE;
+ if (file_exists('./install') && !DEBUG_POCHE) {
+ Tools::logm('folder /install exists');
+ $msg = 'If you want to update your poche, you just have to delete /install folder.
To install your poche with sqlite, copy /install/poche.sqlite in /db and delete the folder /install. you have to delete the /install folder before using poche.';
+ $allIsGood = FALSE;
+ }
- if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) {
- $this->user = $_SESSION['poche_user'];
+ if (STORAGE == 'sqlite' && !is_writable(STORAGE_SQLITE)) {
+ Tools::logm('you don\'t have write access on db file');
+ $msg = 'You don\'t have write access on ' . STORAGE_SQLITE . ' file.';
+ $allIsGood = FALSE;
}
- else {
- # fake user, just for install & login screens
- $this->user = new User();
- $this->user->setConfig($this->getDefaultConfig());
+
+ if (!$allIsGood) {
+ echo $this->tpl->render('error.twig', array(
+ 'msg' => $msg
+ ));
}
- # l10n
- $language = $this->user->getConfigValue('language');
- putenv('LC_ALL=' . $language);
- setlocale(LC_ALL, $language);
- bindtextdomain($language, LOCALE);
- textdomain($language);
+ return $allIsGood;
+ }
+ private function initTpl()
+ {
# template engine
$loader = new Twig_Loader_Filesystem(TPL);
if (DEBUG_POCHE) {
@@ -72,6 +81,28 @@ class Poche
# filter for reading time
$filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime');
$this->tpl->addFilter($filter);
+ }
+
+ private function init()
+ {
+ Tools::initPhp();
+ Session::init();
+
+ if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) {
+ $this->user = $_SESSION['poche_user'];
+ }
+ else {
+ # fake user, just for install & login screens
+ $this->user = new User();
+ $this->user->setConfig($this->getDefaultConfig());
+ }
+
+ # l10n
+ $language = $this->user->getConfigValue('language');
+ putenv('LC_ALL=' . $language);
+ setlocale(LC_ALL, $language);
+ bindtextdomain($language, LOCALE);
+ textdomain($language);
# Pagination
$this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p');
diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php
index ba8a9fa0..ecbf1ce6 100644
--- a/inc/poche/config.inc.php
+++ b/inc/poche/config.inc.php
@@ -34,6 +34,10 @@ define ('PAGINATION', '10');
define ('THEME', 'light');
# /!\ Be careful if you change the lines below /!\
+if (!file_exists('./vendor/autoload.php')) {
+ die('Twig does not seem installed. Have a look at the documentation.');
+}
+
require_once './inc/poche/User.class.php';
require_once './inc/poche/Tools.class.php';
require_once './inc/poche/Url.class.php';
diff --git a/tpl/error.twig b/tpl/error.twig
new file mode 100644
index 00000000..84c3bc1c
--- /dev/null
+++ b/tpl/error.twig
@@ -0,0 +1,7 @@
+{% extends "layout.twig" %}
+{% block title %}{% trans "error" %}{% endblock %}
+{% block content %}
+ error
+