aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche')
-rw-r--r--inc/poche/Database.class.php15
-rw-r--r--inc/poche/Poche.class.php204
-rw-r--r--inc/poche/Tools.class.php8
-rwxr-xr-xinc/poche/config.inc.php.new7
4 files changed, 175 insertions, 59 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index 0662581b..1d3ff0c2 100644
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -87,6 +87,17 @@ class Database {
87 return $user_config; 87 return $user_config;
88 } 88 }
89 89
90 public function userExists($username) {
91 $sql = "SELECT * FROM users WHERE username=?";
92 $query = $this->executeQuery($sql, array($username));
93 $login = $query->fetchAll();
94 if (isset($login[0])) {
95 return true;
96 } else {
97 return false;
98 }
99 }
100
90 public function login($username, $password) { 101 public function login($username, $password) {
91 $sql = "SELECT * FROM users WHERE username=? AND password=?"; 102 $sql = "SELECT * FROM users WHERE username=? AND password=?";
92 $query = $this->executeQuery($sql, array($username, $password)); 103 $query = $this->executeQuery($sql, array($username, $password));
@@ -108,8 +119,8 @@ class Database {
108 public function updatePassword($userId, $password) 119 public function updatePassword($userId, $password)
109 { 120 {
110 $sql_update = "UPDATE users SET password=? WHERE id=?"; 121 $sql_update = "UPDATE users SET password=? WHERE id=?";
111 $params_update = array($password, $id); 122 $params_update = array($password, $userId);
112 $this->updateUserConfig($userId, 'password', $password); 123 $query = $this->executeQuery($sql_update, $params_update);
113 } 124 }
114 125
115 public function updateUserConfig($userId, $key, $value) { 126 public function updateUserConfig($userId, $key, $value) {
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 1ba8e7c1..0766cd51 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);
@@ -258,7 +275,7 @@ class Poche
258 while (($theme = readdir($handle)) !== false) { 275 while (($theme = readdir($handle)) !== false) {
259 # Themes are stored in a directory, so all directory names are themes 276 # Themes are stored in a directory, so all directory names are themes
260 # @todo move theme installation data to database 277 # @todo move theme installation data to database
261 if (! is_dir(THEME . '/' . $theme) || in_array($theme, array('..', '.', '.git'))) { 278 if (! is_dir(THEME . '/' . $theme) || in_array($theme, array('..', '.'))) {
262 continue; 279 continue;
263 } 280 }
264 281
@@ -271,9 +288,33 @@ class Poche
271 $themes[] = array('name' => $theme, 'current' => $current); 288 $themes[] = array('name' => $theme, 'current' => $current);
272 } 289 }
273 290
291 sort($themes);
274 return $themes; 292 return $themes;
275 } 293 }
276 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
277 public function getDefaultConfig() 318 public function getDefaultConfig()
278 { 319 {
279 return array( 320 return array(
@@ -363,15 +404,19 @@ class Poche
363 case 'config': 404 case 'config':
364 $dev = $this->getPocheVersion('dev'); 405 $dev = $this->getPocheVersion('dev');
365 $prod = $this->getPocheVersion('prod'); 406 $prod = $this->getPocheVersion('prod');
366 $compare_dev = version_compare(POCHE_VERSION, $dev); 407 $compare_dev = version_compare(POCHE, $dev);
367 $compare_prod = version_compare(POCHE_VERSION, $prod); 408 $compare_prod = version_compare(POCHE, $prod);
368 $themes = $this->getInstalledThemes(); 409 $themes = $this->getInstalledThemes();
410 $languages = $this->getInstalledLanguages();
411 $http_auth = (isset($_SERVER['PHP_AUTH_USER']))?true:false;
369 $tpl_vars = array( 412 $tpl_vars = array(
370 'themes' => $themes, 413 'themes' => $themes,
414 'languages' => $languages,
371 'dev' => $dev, 415 'dev' => $dev,
372 'prod' => $prod, 416 'prod' => $prod,
373 'compare_dev' => $compare_dev, 417 'compare_dev' => $compare_dev,
374 'compare_prod' => $compare_prod, 418 'compare_prod' => $compare_prod,
419 'http_auth' => $http_auth,
375 ); 420 );
376 Tools::logm('config view'); 421 Tools::logm('config view');
377 break; 422 break;
@@ -492,6 +537,59 @@ class Poche
492 Tools::redirect('?view=config'); 537 Tools::redirect('?view=config');
493 } 538 }
494 539
540 public function updateLanguage()
541 {
542 # no data
543 if (empty($_POST['language'])) {
544 }
545
546 # we are not going to change it to the current language...
547 if ($_POST['language'] == $this->getLanguage()) {
548 $this->messages->add('w', _('still using the "' . $this->getLanguage() . '" language!'));
549 Tools::redirect('?view=config');
550 }
551
552 $languages = $this->getInstalledLanguages();
553 $actualLanguage = false;
554
555 foreach ($languages as $language) {
556 if ($language['name'] == $_POST['language']) {
557 $actualLanguage = true;
558 break;
559 }
560 }
561
562 if (! $actualLanguage) {
563 $this->messages->add('e', _('that language does not seem to be installed'));
564 Tools::redirect('?view=config');
565 }
566
567 $this->store->updateUserConfig($this->user->getId(), 'language', $_POST['language']);
568 $this->messages->add('s', _('you have changed your language preferences'));
569
570 $currentConfig = $_SESSION['poche_user']->config;
571 $currentConfig['language'] = $_POST['language'];
572
573 $_SESSION['poche_user']->setConfig($currentConfig);
574
575 Tools::redirect('?view=config');
576 }
577
578 /**
579 * get credentials from differents sources
580 * it redirects the user to the $referer link
581 * @return array
582 */
583 private function credentials() {
584 if(isset($_SERVER['PHP_AUTH_USER'])) {
585 return array($_SERVER['PHP_AUTH_USER'],'php_auth');
586 }
587 if(!empty($_POST['login']) && !empty($_POST['password'])) {
588 return array($_POST['login'],$_POST['password']);
589 }
590 return array(false,false);
591 }
592
495 /** 593 /**
496 * checks if login & password are correct and save the user in session. 594 * checks if login & password are correct and save the user in session.
497 * it redirects the user to the $referer link 595 * it redirects the user to the $referer link
@@ -501,11 +599,17 @@ class Poche
501 */ 599 */
502 public function login($referer) 600 public function login($referer)
503 { 601 {
504 if (!empty($_POST['login']) && !empty($_POST['password'])) { 602 list($login,$password)=$this->credentials();
505 $user = $this->store->login($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login'])); 603 if($login === false || $password === false) {
604 $this->messages->add('e', _('login failed: you have to fill all fields'));
605 Tools::logm('login failed');
606 Tools::redirect();
607 }
608 if (!empty($login) && !empty($password)) {
609 $user = $this->store->login($login, Tools::encodeString($password . $login));
506 if ($user != array()) { 610 if ($user != array()) {
507 # Save login into Session 611 # Save login into Session
508 Session::login($user['username'], $user['password'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']), array('poche_user' => new User($user))); 612 Session::login($user['username'], $user['password'], $login, Tools::encodeString($password . $login), array('poche_user' => new User($user)));
509 $this->messages->add('s', _('welcome to your poche')); 613 $this->messages->add('s', _('welcome to your poche'));
510 Tools::logm('login successful'); 614 Tools::logm('login successful');
511 Tools::redirect($referer); 615 Tools::redirect($referer);
@@ -513,10 +617,6 @@ class Poche
513 $this->messages->add('e', _('login failed: bad login or password')); 617 $this->messages->add('e', _('login failed: bad login or password'));
514 Tools::logm('login failed'); 618 Tools::logm('login failed');
515 Tools::redirect(); 619 Tools::redirect();
516 } else {
517 $this->messages->add('e', _('login failed: you have to fill all fields'));
518 Tools::logm('login failed');
519 Tools::redirect();
520 } 620 }
521 } 621 }
522 622
@@ -733,4 +833,4 @@ class Poche
733 } 833 }
734 return $version; 834 return $version;
735 } 835 }
736} \ No newline at end of file 836}
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);