aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche')
-rw-r--r--inc/poche/Database.class.php4
-rw-r--r--inc/poche/Poche.class.php166
-rw-r--r--inc/poche/Tools.class.php8
-rwxr-xr-xinc/poche/config.inc.php.new7
4 files changed, 135 insertions, 50 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index 0662581b..5c40b026 100644
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -108,8 +108,8 @@ class Database {
108 public function updatePassword($userId, $password) 108 public function updatePassword($userId, $password)
109 { 109 {
110 $sql_update = "UPDATE users SET password=? WHERE id=?"; 110 $sql_update = "UPDATE users SET password=? WHERE id=?";
111 $params_update = array($password, $id); 111 $params_update = array($password, $userId);
112 $this->updateUserConfig($userId, 'password', $password); 112 $query = $this->executeQuery($sql_update, $params_update);
113 } 113 }
114 114
115 public function updateUserConfig($userId, $key, $value) { 115 public function updateUserConfig($userId, $key, $value) {
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 6325adcf..806da54b 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -20,7 +20,8 @@ class Poche
20 public $pagination; 20 public $pagination;
21 21
22 private $currentTheme = ''; 22 private $currentTheme = '';
23 private $notInstalledMessage = ''; 23 private $currentLanguage = '';
24 private $notInstalledMessage = array();
24 25
25 # @todo make this dynamic (actually install themes and save them in the database including author information et cetera) 26 # @todo make this dynamic (actually install themes and save them in the database including author information et cetera)
26 private $installedThemes = array( 27 private $installedThemes = array(
@@ -33,28 +34,21 @@ class Poche
33 34
34 public function __construct() 35 public function __construct()
35 { 36 {
36 if (! $this->configFileIsAvailable()) { 37 if ($this->configFileIsAvailable()) {
37 return; 38 $this->init();
38 } 39 }
39 40
40 $this->init(); 41 if ($this->themeIsInstalled()) {
41 42 $this->initTpl();
42 if (! $this->themeIsInstalled()) {
43 return;
44 } 43 }
45 44
46 $this->initTpl(); 45 if ($this->systemIsInstalled()) {
47 46 $this->store = new Database();
48 if (! $this->systemIsInstalled()) { 47 $this->messages = new Messages();
49 return; 48 # installation
50 } 49 if (! $this->store->isInstalled()) {
51 50 $this->install();
52 $this->store = new Database(); 51 }
53 $this->messages = new Messages();
54
55 # installation
56 if (! $this->store->isInstalled()) {
57 $this->install();
58 } 52 }
59 } 53 }
60 54
@@ -90,11 +84,20 @@ class Poche
90 } 84 }
91 85
92 $this->currentTheme = $themeDirectory; 86 $this->currentTheme = $themeDirectory;
87
88 # Set up language
89 $languageDirectory = $this->user->getConfigValue('language');
90
91 if ($languageDirectory === false) {
92 $languageDirectory = DEFAULT_THEME;
93 }
94
95 $this->currentLanguage = $languageDirectory;
93 } 96 }
94 97
95 public function configFileIsAvailable() { 98 public function configFileIsAvailable() {
96 if (! self::$configFileAvailable) { 99 if (! self::$configFileAvailable) {
97 $this->notInstalledMessage = 'You have to rename <strong>inc/poche/config.inc.php.new</strong> to <strong>inc/poche/config.inc.php</strong>.'; 100 $this->notInstalledMessage[] = 'You have to rename inc/poche/config.inc.php.new to inc/poche/config.inc.php.';
98 101
99 return false; 102 return false;
100 } 103 }
@@ -103,39 +106,44 @@ class Poche
103 } 106 }
104 107
105 public function themeIsInstalled() { 108 public function themeIsInstalled() {
109 $passTheme = TRUE;
106 # Twig is an absolute requirement for Poche to function. Abort immediately if the Composer installer hasn't been run yet 110 # Twig is an absolute requirement for Poche to function. Abort immediately if the Composer installer hasn't been run yet
107 if (! self::$canRenderTemplates) { 111 if (! self::$canRenderTemplates) {
108 $this->notInstalledMessage = 'Twig does not seem to be installed. Please initialize the Composer installation to automatically fetch dependencies. Have a look at <a href="http://doc.inthepoche.com/doku.php?id=users:begin:install">the documentation.</a>'; 112 $this->notInstalledMessage[] = 'Twig does not seem to be installed. Please initialize the Composer installation to automatically fetch dependencies. Have a look at <a href="http://doc.inthepoche.com/doku.php?id=users:begin:install">the documentation.</a>';
109 113 $passTheme = FALSE;
110 return false;
111 } 114 }
112 115
113 if (! is_writable(CACHE)) { 116 if (! is_writable(CACHE)) {
114 $this->notInstalledMessage = '<h1>error</h1><p>You don\'t have write access on cache directory.</p>'; 117 $this->notInstalledMessage[] = 'You don\'t have write access on cache directory.';
115 118
116 self::$canRenderTemplates = false; 119 self::$canRenderTemplates = false;
117 120
118 return false; 121 $passTheme = FALSE;
119 } 122 }
120 123
121 # Check if the selected theme and its requirements are present 124 # Check if the selected theme and its requirements are present
122 if (! is_dir(THEME . '/' . $this->getTheme())) { 125 if ($this->getTheme() != '' && ! is_dir(THEME . '/' . $this->getTheme())) {
123 $this->notInstalledMessage = 'The currently selected theme (' . $this->getTheme() . ') does not seem to be properly installed (Missing directory: ' . THEME . '/' . $this->getTheme() . ')'; 126 $this->notInstalledMessage[] = 'The currently selected theme (' . $this->getTheme() . ') does not seem to be properly installed (Missing directory: ' . THEME . '/' . $this->getTheme() . ')';
124 127
125 self::$canRenderTemplates = false; 128 self::$canRenderTemplates = false;
126 129
127 return false; 130 $passTheme = FALSE;
128 } 131 }
129 132
130 foreach ($this->installedThemes[$this->getTheme()]['requires'] as $requiredTheme) { 133 foreach ($this->installedThemes[$this->getTheme()]['requires'] as $requiredTheme) {
131 if (! is_dir(THEME . '/' . $requiredTheme)) { 134 if (! is_dir(THEME . '/' . $requiredTheme)) {
132 $this->notInstalledMessage = 'The required "' . $requiredTheme . '" theme is missing for the current theme (' . $this->getTheme() . ')'; 135 $this->notInstalledMessage[] = 'The required "' . $requiredTheme . '" theme is missing for the current theme (' . $this->getTheme() . ')';
133 136
134 self::$canRenderTemplates = false; 137 self::$canRenderTemplates = false;
135 138
136 return false; 139 $passTheme = FALSE;
137 } 140 }
138 } 141 }
142
143 if (!$passTheme) {
144 return FALSE;
145 }
146
139 147
140 return true; 148 return true;
141 } 149 }
@@ -147,25 +155,30 @@ class Poche
147 */ 155 */
148 public function systemIsInstalled() 156 public function systemIsInstalled()
149 { 157 {
150 $msg = ''; 158 $msg = TRUE;
151 159
152 $configSalt = defined('SALT') ? constant('SALT') : ''; 160 $configSalt = defined('SALT') ? constant('SALT') : '';
153 161
154 if (empty($configSalt)) { 162 if (empty($configSalt)) {
155 $msg = '<h1>error</h1><p>You have not yet filled in the SALT value in the config.inc.php file.</p>'; 163 $this->notInstalledMessage[] = 'You have not yet filled in the SALT value in the config.inc.php file.';
156 } else if (STORAGE == 'sqlite' && ! file_exists(STORAGE_SQLITE)) { 164 $msg = FALSE;
165 }
166 if (STORAGE == 'sqlite' && ! file_exists(STORAGE_SQLITE)) {
157 Tools::logm('sqlite file doesn\'t exist'); 167 Tools::logm('sqlite file doesn\'t exist');
158 $msg = '<h1>error</h1><p>sqlite file doesn\'t exist, you can find it in install folder. Copy it in /db folder.</p>'; 168 $this->notInstalledMessage[] = 'sqlite file doesn\'t exist, you can find it in install folder. Copy it in /db folder.';
159 } else if (is_dir(ROOT . '/install') && ! DEBUG_POCHE) { 169 $msg = FALSE;
160 $msg = '<h1>install folder</h1><p>you have to delete the /install folder before using poche.</p>'; 170 }
161 } else if (STORAGE == 'sqlite' && ! is_writable(STORAGE_SQLITE)) { 171 if (is_dir(ROOT . '/install') && ! DEBUG_POCHE) {
172 $this->notInstalledMessage[] = 'you have to delete the /install folder before using poche.';
173 $msg = FALSE;
174 }
175 if (STORAGE == 'sqlite' && ! is_writable(STORAGE_SQLITE)) {
162 Tools::logm('you don\'t have write access on sqlite file'); 176 Tools::logm('you don\'t have write access on sqlite file');
163 $msg = '<h1>error</h1><p>You don\'t have write access on sqlite file.</p>'; 177 $this->notInstalledMessage[] = 'You don\'t have write access on sqlite file.';
178 $msg = FALSE;
164 } 179 }
165 180
166 if (! empty($msg)) { 181 if (! $msg) {
167 $this->notInstalledMessage = $msg;
168
169 return false; 182 return false;
170 } 183 }
171 184
@@ -250,6 +263,10 @@ class Poche
250 public function getTheme() { 263 public function getTheme() {
251 return $this->currentTheme; 264 return $this->currentTheme;
252 } 265 }
266
267 public function getLanguage() {
268 return $this->currentLanguage;
269 }
253 270
254 public function getInstalledThemes() { 271 public function getInstalledThemes() {
255 $handle = opendir(THEME); 272 $handle = opendir(THEME);
@@ -275,6 +292,29 @@ class Poche
275 return $themes; 292 return $themes;
276 } 293 }
277 294
295 public function getInstalledLanguages() {
296 $handle = opendir(LOCALE);
297 $languages = array();
298
299 while (($language = readdir($handle)) !== false) {
300 # Languages are stored in a directory, so all directory names are languages
301 # @todo move language installation data to database
302 if (! is_dir(LOCALE . '/' . $language) || in_array($language, array('..', '.'))) {
303 continue;
304 }
305
306 $current = false;
307
308 if ($language === $this->getLanguage()) {
309 $current = true;
310 }
311
312 $languages[] = array('name' => $language, 'current' => $current);
313 }
314
315 return $languages;
316 }
317
278 public function getDefaultConfig() 318 public function getDefaultConfig()
279 { 319 {
280 return array( 320 return array(
@@ -364,11 +404,13 @@ class Poche
364 case 'config': 404 case 'config':
365 $dev = $this->getPocheVersion('dev'); 405 $dev = $this->getPocheVersion('dev');
366 $prod = $this->getPocheVersion('prod'); 406 $prod = $this->getPocheVersion('prod');
367 $compare_dev = version_compare(POCHE_VERSION, $dev); 407 $compare_dev = version_compare(POCHE, $dev);
368 $compare_prod = version_compare(POCHE_VERSION, $prod); 408 $compare_prod = version_compare(POCHE, $prod);
369 $themes = $this->getInstalledThemes(); 409 $themes = $this->getInstalledThemes();
410 $languages = $this->getInstalledLanguages();
370 $tpl_vars = array( 411 $tpl_vars = array(
371 'themes' => $themes, 412 'themes' => $themes,
413 'languages' => $languages,
372 'dev' => $dev, 414 'dev' => $dev,
373 'prod' => $prod, 415 'prod' => $prod,
374 'compare_dev' => $compare_dev, 416 'compare_dev' => $compare_dev,
@@ -493,6 +535,44 @@ class Poche
493 Tools::redirect('?view=config'); 535 Tools::redirect('?view=config');
494 } 536 }
495 537
538 public function updateLanguage()
539 {
540 # no data
541 if (empty($_POST['language'])) {
542 }
543
544 # we are not going to change it to the current language...
545 if ($_POST['language'] == $this->getLanguage()) {
546 $this->messages->add('w', _('still using the "' . $this->getLanguage() . '" language!'));
547 Tools::redirect('?view=config');
548 }
549
550 $languages = $this->getInstalledLanguages();
551 $actualLanguage = false;
552
553 foreach ($languages as $language) {
554 if ($language['name'] == $_POST['language']) {
555 $actualLanguage = true;
556 break;
557 }
558 }
559
560 if (! $actualLanguage) {
561 $this->messages->add('e', _('that language does not seem to be installed'));
562 Tools::redirect('?view=config');
563 }
564
565 $this->store->updateUserConfig($this->user->getId(), 'language', $_POST['language']);
566 $this->messages->add('s', _('you have changed your language preferences'));
567
568 $currentConfig = $_SESSION['poche_user']->config;
569 $currentConfig['language'] = $_POST['language'];
570
571 $_SESSION['poche_user']->setConfig($currentConfig);
572
573 Tools::redirect('?view=config');
574 }
575
496 /** 576 /**
497 * checks if login & password are correct and save the user in session. 577 * checks if login & password are correct and save the user in session.
498 * it redirects the user to the $referer link 578 * it redirects the user to the $referer link
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index 8eb988f4..1d092823 100644
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -41,10 +41,14 @@ class Tools
41 $https = (!empty($_SERVER['HTTPS']) 41 $https = (!empty($_SERVER['HTTPS'])
42 && (strtolower($_SERVER['HTTPS']) == 'on')) 42 && (strtolower($_SERVER['HTTPS']) == 'on'))
43 || (isset($_SERVER["SERVER_PORT"]) 43 || (isset($_SERVER["SERVER_PORT"])
44 && $_SERVER["SERVER_PORT"] == '443'); // HTTPS detection. 44 && $_SERVER["SERVER_PORT"] == '443') // HTTPS detection.
45 || (isset($_SERVER["SERVER_PORT"]) //Custom HTTPS port detection
46 && $_SERVER["SERVER_PORT"] == SSL_PORT);
47
45 $serverport = (!isset($_SERVER["SERVER_PORT"]) 48 $serverport = (!isset($_SERVER["SERVER_PORT"])
46 || $_SERVER["SERVER_PORT"] == '80' 49 || $_SERVER["SERVER_PORT"] == '80'
47 || ($https && $_SERVER["SERVER_PORT"] == '443') 50 || ($https && $_SERVER["SERVER_PORT"] == '443')
51 || ($https && $_SERVER["SERVER_PORT"]==SSL_PORT) //Custom HTTPS port detection
48 ? '' : ':' . $_SERVER["SERVER_PORT"]); 52 ? '' : ':' . $_SERVER["SERVER_PORT"]);
49 53
50 $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]); 54 $scriptname = str_replace('/index.php', '/', $_SERVER["SCRIPT_NAME"]);
@@ -243,4 +247,4 @@ class Tools
243 $lang = explode('.', $userlanguage); 247 $lang = explode('.', $userlanguage);
244 return str_replace('_', '-', $lang[0]); 248 return str_replace('_', '-', $lang[0]);
245 } 249 }
246} \ No newline at end of file 250}
diff --git a/inc/poche/config.inc.php.new b/inc/poche/config.inc.php.new
index 255b97e6..c60d4f80 100755
--- a/inc/poche/config.inc.php.new
+++ b/inc/poche/config.inc.php.new
@@ -25,6 +25,9 @@ define ('STORAGE_PASSWORD', 'poche');
25# Do not trespass unless you know what you are doing 25# Do not trespass unless you know what you are doing
26################################################################################# 26#################################################################################
27 27
28// Change this if not using the standart port for SSL - i.e you server is behind sslh
29define ('SSL_PORT', 443);
30
28define ('MODE_DEMO', FALSE); 31define ('MODE_DEMO', FALSE);
29define ('DEBUG_POCHE', FALSE); 32define ('DEBUG_POCHE', FALSE);
30define ('DOWNLOAD_PICTURES', FALSE); 33define ('DOWNLOAD_PICTURES', FALSE);
@@ -49,12 +52,10 @@ define ('CACHE', ROOT . '/cache');
49 52
50define ('PAGINATION', '10'); 53define ('PAGINATION', '10');
51 54
52define ('POCHE_VERSION', '1.0.0');
53
54define ('POCKET_FILE', '/ril_export.html'); 55define ('POCKET_FILE', '/ril_export.html');
55define ('READABILITY_FILE', '/readability'); 56define ('READABILITY_FILE', '/readability');
56define ('INSTAPAPER_FILE', '/instapaper-export.html'); 57define ('INSTAPAPER_FILE', '/instapaper-export.html');
57 58
58define ('IMPORT_POCKET_FILE', ROOT . POCKET_FILE); 59define ('IMPORT_POCKET_FILE', ROOT . POCKET_FILE);
59define ('IMPORT_READABILITY_FILE', ROOT . READABILITY_FILE); 60define ('IMPORT_READABILITY_FILE', ROOT . READABILITY_FILE);
60define ('IMPORT_INSTAPAPER_FILE', ROOT . INSTAPAPER_FILE); \ No newline at end of file 61define ('IMPORT_INSTAPAPER_FILE', ROOT . INSTAPAPER_FILE);