aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche')
-rw-r--r--inc/poche/Database.class.php16
-rw-r--r--inc/poche/Poche.class.php335
-rw-r--r--inc/poche/PocheReadability.php46
-rw-r--r--inc/poche/Tools.class.php41
-rw-r--r--inc/poche/Url.class.php2
-rwxr-xr-xinc/poche/config.inc.php59
-rwxr-xr-xinc/poche/config.inc.php.new56
-rw-r--r--inc/poche/define.inc.php7
-rw-r--r--inc/poche/global.inc.php64
9 files changed, 459 insertions, 167 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index 84916b83..4d664992 100644
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -60,11 +60,15 @@ class Database {
60 $id_user = intval($this->getLastId($sequence)); 60 $id_user = intval($this->getLastId($sequence));
61 61
62 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; 62 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
63 $params = array($id_user, 'pager', '10'); 63 $params = array($id_user, 'pager', PAGINATION);
64 $query = $this->executeQuery($sql, $params); 64 $query = $this->executeQuery($sql, $params);
65 65
66 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; 66 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
67 $params = array($id_user, 'language', 'en_EN.UTF8'); 67 $params = array($id_user, 'language', LANG);
68 $query = $this->executeQuery($sql, $params);
69
70 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
71 $params = array($id_user, 'theme', DEFAULT_THEME);
68 $query = $this->executeQuery($sql, $params); 72 $query = $this->executeQuery($sql, $params);
69 73
70 return TRUE; 74 return TRUE;
@@ -101,10 +105,16 @@ class Database {
101 return $user; 105 return $user;
102 } 106 }
103 107
104 public function updatePassword($id, $password) 108 public function updatePassword($userId, $password)
105 { 109 {
106 $sql_update = "UPDATE users SET password=? WHERE id=?"; 110 $sql_update = "UPDATE users SET password=? WHERE id=?";
107 $params_update = array($password, $id); 111 $params_update = array($password, $id);
112 $this->updateUserConfig($userId, 'password', $password);
113 }
114
115 public function updateUserConfig($userId, $key, $value) {
116 $sql_update = "UPDATE users_config SET `value`=? WHERE `user_id`=? AND `name`=?";
117 $params_update = array($value, $userId, $key);
108 $query = $this->executeQuery($sql_update, $params_update); 118 $query = $this->executeQuery($sql_update, $params_update);
109 } 119 }
110 120
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 646193f7..18860ddc 100644
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -10,77 +10,200 @@
10 10
11class Poche 11class Poche
12{ 12{
13 public static $canRenderTemplates = true;
14 public static $configFileAvailable = true;
15
13 public $user; 16 public $user;
14 public $store; 17 public $store;
15 public $tpl; 18 public $tpl;
16 public $messages; 19 public $messages;
17 public $pagination; 20 public $pagination;
18 21
19 function __construct() 22 private $currentTheme = '';
23 private $notInstalledMessage = '';
24
25 # @todo make this dynamic (actually install themes and save them in the database including author information et cetera)
26 private $installedThemes = array(
27 'default' => array('requires' => array()),
28 'dark' => array('requires' => array('default')),
29 'dmagenta' => array('requires' => array('default')),
30 'solarized' => array('requires' => array('default')),
31 'solarized-dark' => array('requires' => array('default'))
32 );
33
34 public function __construct()
20 { 35 {
36 if (! $this->configFileIsAvailable()) {
37 return;
38 }
39
40 $this->init();
41
42 if (! $this->themeIsInstalled()) {
43 return;
44 }
45
21 $this->initTpl(); 46 $this->initTpl();
22 if (!$this->checkBeforeInstall()) { 47
23 exit; 48 if (! $this->systemIsInstalled()) {
49 return;
24 } 50 }
51
25 $this->store = new Database(); 52 $this->store = new Database();
26 $this->init();
27 $this->messages = new Messages(); 53 $this->messages = new Messages();
28 54
29 # installation 55 # installation
30 if(!$this->store->isInstalled()) 56 if (! $this->store->isInstalled()) {
31 {
32 $this->install(); 57 $this->install();
33 } 58 }
34 } 59 }
60
61 private function init()
62 {
63 Tools::initPhp();
64 Session::$sessionName = 'poche';
65 Session::init();
35 66
67 if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) {
68 $this->user = $_SESSION['poche_user'];
69 } else {
70 # fake user, just for install & login screens
71 $this->user = new User();
72 $this->user->setConfig($this->getDefaultConfig());
73 }
74
75 # l10n
76 $language = $this->user->getConfigValue('language');
77 putenv('LC_ALL=' . $language);
78 setlocale(LC_ALL, $language);
79 bindtextdomain($language, LOCALE);
80 textdomain($language);
81
82 # Pagination
83 $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p');
84
85 # Set up theme
86 $themeDirectory = $this->user->getConfigValue('theme');
87
88 if ($themeDirectory === false) {
89 $themeDirectory = DEFAULT_THEME;
90 }
91
92 $this->currentTheme = $themeDirectory;
93 }
94
95 public function configFileIsAvailable() {
96 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>.';
98
99 return false;
100 }
101
102 return true;
103 }
104
105 public function themeIsInstalled() {
106 # Twig is an absolute requirement for Poche to function. Abort immediately if the Composer installer hasn't been run yet
107 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://inthepoche.com/?pages/Documentation">the documentation.</a>';
109
110 return false;
111 }
112
113 # Check if the selected theme and its requirements are present
114 if (! is_dir(THEME . '/' . $this->getTheme())) {
115 $this->notInstalledMessage = 'The currently selected theme (' . $this->getTheme() . ') does not seem to be properly installed (Missing directory: ' . THEME . '/' . $this->getTheme() . ')';
116
117 self::$canRenderTemplates = false;
118
119 return false;
120 }
121
122 foreach ($this->installedThemes[$this->getTheme()]['requires'] as $requiredTheme) {
123 if (! is_dir(THEME . '/' . $requiredTheme)) {
124 $this->notInstalledMessage = 'The required "' . $requiredTheme . '" theme is missing for the current theme (' . $this->getTheme() . ')';
125
126 self::$canRenderTemplates = false;
127
128 return false;
129 }
130 }
131
132 return true;
133 }
134
36 /** 135 /**
37 * all checks before installation. 136 * all checks before installation.
137 * @todo move HTML to template
38 * @return boolean 138 * @return boolean
39 */ 139 */
40 private function checkBeforeInstall() 140 public function systemIsInstalled()
41 { 141 {
42 $msg = ''; 142 $msg = '';
43 $allIsGood = TRUE; 143
44 144 $configSalt = defined('SALT') ? constant('SALT') : '';
45 if (!is_writable(CACHE)) { 145
146 if (empty($configSalt)) {
147 $msg = '<h1>error</h1><p>You have not yet filled in the SALT value in the config.inc.php file.</p>';
148 } else if (! is_writable(CACHE)) {
46 Tools::logm('you don\'t have write access on cache directory'); 149 Tools::logm('you don\'t have write access on cache directory');
47 die('You don\'t have write access on cache directory.'); 150 $msg = '<h1>error</h1><p>You don\'t have write access on cache directory.</p>';
48 } 151 } else if (STORAGE == 'sqlite' && ! file_exists(STORAGE_SQLITE)) {
49 else if (file_exists('./install/update.php') && !DEBUG_POCHE) { 152 Tools::logm('sqlite file doesn\'t exist');
153 $msg = '<h1>error</h1><p>sqlite file doesn\'t exist, you can find it in install folder. Copy it in /db folder.</p>';
154 } else if (file_exists(ROOT . '/install/update.php') && ! DEBUG_POCHE) {
50 $msg = '<h1>setup</h1><p><strong>It\'s your first time here?</strong> Please copy /install/poche.sqlite in db folder. Then, delete install folder.<br /><strong>If you have already installed poche</strong>, an update is needed <a href="install/update.php">by clicking here</a>.</p>'; 155 $msg = '<h1>setup</h1><p><strong>It\'s your first time here?</strong> Please copy /install/poche.sqlite in db folder. Then, delete install folder.<br /><strong>If you have already installed poche</strong>, an update is needed <a href="install/update.php">by clicking here</a>.</p>';
51 $allIsGood = FALSE; 156 } else if (is_dir(ROOT . '/install') && ! DEBUG_POCHE) {
52 }
53 else if (file_exists('./install') && !DEBUG_POCHE) {
54 $msg = '<h1>setup</h1><p><strong>If you want to update your poche</strong>, you just have to delete /install folder. <br /><strong>To install your poche with sqlite</strong>, copy /install/poche.sqlite in /db and delete the folder /install. you have to delete the /install folder before using poche.</p>'; 157 $msg = '<h1>setup</h1><p><strong>If you want to update your poche</strong>, you just have to delete /install folder. <br /><strong>To install your poche with sqlite</strong>, copy /install/poche.sqlite in /db and delete the folder /install. you have to delete the /install folder before using poche.</p>';
55 $allIsGood = FALSE; 158 } else if (STORAGE == 'sqlite' && ! is_writable(STORAGE_SQLITE)) {
56 }
57 else if (STORAGE == 'sqlite' && !is_writable(STORAGE_SQLITE)) {
58 Tools::logm('you don\'t have write access on sqlite file'); 159 Tools::logm('you don\'t have write access on sqlite file');
59 $msg = '<h1>error</h1><p>You don\'t have write access on sqlite file.</p>'; 160 $msg = '<h1>error</h1><p>You don\'t have write access on sqlite file.</p>';
60 $allIsGood = FALSE;
61 } 161 }
62 162
63 if (!$allIsGood) { 163 if (! empty($msg)) {
64 echo $this->tpl->render('error.twig', array( 164 $this->notInstalledMessage = $msg;
65 'msg' => $msg 165
66 )); 166 return false;
67 } 167 }
68 168
69 return $allIsGood; 169 return true;
170 }
171
172 public function getNotInstalledMessage() {
173 return $this->notInstalledMessage;
70 } 174 }
71 175
72 private function initTpl() 176 private function initTpl()
73 { 177 {
74 # template engine 178 $loaderChain = new Twig_Loader_Chain();
75 $loader = new Twig_Loader_Filesystem(TPL); 179
180 # add the current theme as first to the loader chain so Twig will look there first for overridden template files
181 try {
182 $loaderChain->addLoader(new Twig_Loader_Filesystem(THEME . '/' . $this->getTheme()));
183 } catch (Twig_Error_Loader $e) {
184 # @todo isInstalled() should catch this, inject Twig later
185 die('The currently selected theme (' . $this->getTheme() . ') does not seem to be properly installed (' . THEME . '/' . $this->getTheme() .' is missing)');
186 }
187
188 # add all required themes to the loader chain
189 foreach ($this->installedThemes[$this->getTheme()]['requires'] as $requiredTheme) {
190 try {
191 $loaderChain->addLoader(new Twig_Loader_Filesystem(THEME . '/' . DEFAULT_THEME));
192 } catch (Twig_Error_Loader $e) {
193 # @todo isInstalled() should catch this, inject Twig later
194 die('The required "' . $requiredTheme . '" theme is missing for the current theme (' . $this->getTheme() . ')');
195 }
196 }
197
76 if (DEBUG_POCHE) { 198 if (DEBUG_POCHE) {
77 $twig_params = array(); 199 $twig_params = array();
78 } 200 } else {
79 else {
80 $twig_params = array('cache' => CACHE); 201 $twig_params = array('cache' => CACHE);
81 } 202 }
82 $this->tpl = new Twig_Environment($loader, $twig_params); 203
204 $this->tpl = new Twig_Environment($loaderChain, $twig_params);
83 $this->tpl->addExtension(new Twig_Extensions_Extension_I18n()); 205 $this->tpl->addExtension(new Twig_Extensions_Extension_I18n());
206
84 # filter to display domain name of an url 207 # filter to display domain name of an url
85 $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); 208 $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain');
86 $this->tpl->addFilter($filter); 209 $this->tpl->addFilter($filter);
@@ -88,38 +211,19 @@ class Poche
88 # filter for reading time 211 # filter for reading time
89 $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime'); 212 $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime');
90 $this->tpl->addFilter($filter); 213 $this->tpl->addFilter($filter);
91 } 214
92 215 # filter for simple filenames in config view
93 private function init() 216 $filter = new Twig_SimpleFilter('getPrettyFilename', function($string) { return str_replace(ROOT, '', $string); });
94 { 217 $this->tpl->addFilter($filter);
95 Tools::initPhp();
96 Session::init();
97
98 if (isset($_SESSION['poche_user']) && $_SESSION['poche_user'] != array()) {
99 $this->user = $_SESSION['poche_user'];
100 }
101 else {
102 # fake user, just for install & login screens
103 $this->user = new User();
104 $this->user->setConfig($this->getDefaultConfig());
105 }
106
107 # l10n
108 $language = $this->user->getConfigValue('language');
109 putenv('LC_ALL=' . $language);
110 setlocale(LC_ALL, $language);
111 bindtextdomain($language, LOCALE);
112 textdomain($language);
113
114 # Pagination
115 $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p');
116 } 218 }
117 219
118 private function install() 220 private function install()
119 { 221 {
120 Tools::logm('poche still not installed'); 222 Tools::logm('poche still not installed');
121 echo $this->tpl->render('install.twig', array( 223 echo $this->tpl->render('install.twig', array(
122 'token' => Session::getToken() 224 'token' => Session::getToken(),
225 'theme' => $this->getTheme(),
226 'poche_url' => Tools::getPocheUrl()
123 )); 227 ));
124 if (isset($_GET['install'])) { 228 if (isset($_GET['install'])) {
125 if (($_POST['password'] == $_POST['password_repeat']) 229 if (($_POST['password'] == $_POST['password_repeat'])
@@ -139,13 +243,41 @@ class Poche
139 } 243 }
140 exit(); 244 exit();
141 } 245 }
246
247 public function getTheme() {
248 return $this->currentTheme;
249 }
250
251 public function getInstalledThemes() {
252 $handle = opendir(THEME);
253 $themes = array();
254
255 while (($theme = readdir($handle)) !== false) {
256 # Themes are stored in a directory, so all directory names are themes
257 # @todo move theme installation data to database
258 if (! is_dir(THEME . '/' . $theme) || in_array($theme, array('..', '.'))) {
259 continue;
260 }
261
262 $current = false;
263
264 if ($theme === $this->getTheme()) {
265 $current = true;
266 }
267
268 $themes[] = array('name' => $theme, 'current' => $current);
269 }
270
271 return $themes;
272 }
142 273
143 public function getDefaultConfig() 274 public function getDefaultConfig()
144 { 275 {
145 return array( 276 return array(
146 'pager' => PAGINATION, 277 'pager' => PAGINATION,
147 'language' => LANG, 278 'language' => LANG,
148 ); 279 'theme' => DEFAULT_THEME
280 );
149 } 281 }
150 282
151 /** 283 /**
@@ -166,7 +298,7 @@ class Poche
166 } 298 }
167 $last_id = $this->store->getLastId($sequence); 299 $last_id = $this->store->getLastId($sequence);
168 if (DOWNLOAD_PICTURES) { 300 if (DOWNLOAD_PICTURES) {
169 $content = filtre_picture($parametres_url['body'], $url->getUrl(), $last_id); 301 $content = filtre_picture($content['body'], $url->getUrl(), $last_id);
170 Tools::logm('updating content article'); 302 Tools::logm('updating content article');
171 $this->store->updateContent($last_id, $content, $this->user->getId()); 303 $this->store->updateContent($last_id, $content, $this->user->getId());
172 } 304 }
@@ -182,7 +314,7 @@ class Poche
182 } 314 }
183 315
184 if (!$import) { 316 if (!$import) {
185 Tools::redirect(); 317 Tools::redirect('?view=home');
186 } 318 }
187 break; 319 break;
188 case 'delete': 320 case 'delete':
@@ -230,7 +362,9 @@ class Poche
230 $prod = $this->getPocheVersion('prod'); 362 $prod = $this->getPocheVersion('prod');
231 $compare_dev = version_compare(POCHE_VERSION, $dev); 363 $compare_dev = version_compare(POCHE_VERSION, $dev);
232 $compare_prod = version_compare(POCHE_VERSION, $prod); 364 $compare_prod = version_compare(POCHE_VERSION, $prod);
365 $themes = $this->getInstalledThemes();
233 $tpl_vars = array( 366 $tpl_vars = array(
367 'themes' => $themes,
234 'dev' => $dev, 368 'dev' => $dev,
235 'prod' => $prod, 369 'prod' => $prod,
236 'compare_dev' => $compare_dev, 370 'compare_dev' => $compare_dev,
@@ -247,25 +381,37 @@ class Poche
247 $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8'); 381 $tidy = tidy_parse_string($content, array('indent'=>true, 'show-body-only' => true), 'UTF8');
248 $tidy->cleanRepair(); 382 $tidy->cleanRepair();
249 $content = $tidy->value; 383 $content = $tidy->value;
250 } 384
251 $tpl_vars = array( 385 # flattr checking
386 $flattr = new FlattrItem();
387 $flattr->checkItem($entry['url']);
388
389 $tpl_vars = array(
252 'entry' => $entry, 390 'entry' => $entry,
253 'content' => $content, 391 'content' => $content,
254 ); 392 'flattr' => $flattr
393 );
394 }
255 } 395 }
256 else { 396 else {
257 Tools::logm('error in view call : entry is null'); 397 Tools::logm('error in view call : entry is null');
258 } 398 }
259 break; 399 break;
260 default: # home view 400 default: # home, favorites and archive views
261 $entries = $this->store->getEntriesByView($view, $this->user->getId()); 401 $entries = $this->store->getEntriesByView($view, $this->user->getId());
262 $this->pagination->set_total(count($entries));
263 $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&');
264 $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit());
265 $tpl_vars = array( 402 $tpl_vars = array(
266 'entries' => $datas, 403 'entries' => '',
267 'page_links' => $page_links, 404 'page_links' => '',
405 'nb_results' => '',
268 ); 406 );
407 if (count($entries) > 0) {
408 $this->pagination->set_total(count($entries));
409 $page_links = $this->pagination->page_links('?view=' . $view . '&sort=' . $_SESSION['sort'] . '&');
410 $datas = $this->store->getEntriesByView($view, $this->user->getId(), $this->pagination->get_limit());
411 $tpl_vars['entries'] = $datas;
412 $tpl_vars['page_links'] = $page_links;
413 $tpl_vars['nb_results'] = count($entries);
414 }
269 Tools::logm('display ' . $view . ' view'); 415 Tools::logm('display ' . $view . ' view');
270 break; 416 break;
271 } 417 }
@@ -303,6 +449,44 @@ class Poche
303 } 449 }
304 } 450 }
305 } 451 }
452
453 public function updateTheme()
454 {
455 # no data
456 if (empty($_POST['theme'])) {
457 }
458
459 # we are not going to change it to the current theme...
460 if ($_POST['theme'] == $this->getTheme()) {
461 $this->messages->add('w', _('still using the "' . $this->getTheme() . '" theme!'));
462 Tools::redirect('?view=config');
463 }
464
465 $themes = $this->getInstalledThemes();
466 $actualTheme = false;
467
468 foreach ($themes as $theme) {
469 if ($theme['name'] == $_POST['theme']) {
470 $actualTheme = true;
471 break;
472 }
473 }
474
475 if (! $actualTheme) {
476 $this->messages->add('e', _('that theme does not seem to be installed'));
477 Tools::redirect('?view=config');
478 }
479
480 $this->store->updateUserConfig($this->user->getId(), 'theme', $_POST['theme']);
481 $this->messages->add('s', _('you have changed your theme preferences'));
482
483 $currentConfig = $_SESSION['poche_user']->config;
484 $currentConfig['theme'] = $_POST['theme'];
485
486 $_SESSION['poche_user']->setConfig($currentConfig);
487
488 Tools::redirect('?view=config');
489 }
306 490
307 /** 491 /**
308 * checks if login & password are correct and save the user in session. 492 * checks if login & password are correct and save the user in session.
@@ -318,16 +502,7 @@ class Poche
318 if ($user != array()) { 502 if ($user != array()) {
319 # Save login into Session 503 # Save login into Session
320 Session::login($user['username'], $user['password'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']), array('poche_user' => new User($user))); 504 Session::login($user['username'], $user['password'], $_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']), array('poche_user' => new User($user)));
321
322 $this->messages->add('s', _('welcome to your poche')); 505 $this->messages->add('s', _('welcome to your poche'));
323 if (!empty($_POST['longlastingsession'])) {
324 $_SESSION['longlastingsession'] = 31536000;
325 $_SESSION['expires_on'] = time() + $_SESSION['longlastingsession'];
326 session_set_cookie_params($_SESSION['longlastingsession']);
327 } else {
328 session_set_cookie_params(0);
329 }
330 session_regenerate_id(true);
331 Tools::logm('login successful'); 506 Tools::logm('login successful');
332 Tools::redirect($referer); 507 Tools::redirect($referer);
333 } 508 }
diff --git a/inc/poche/PocheReadability.php b/inc/poche/PocheReadability.php
new file mode 100644
index 00000000..48ae90d0
--- /dev/null
+++ b/inc/poche/PocheReadability.php
@@ -0,0 +1,46 @@
1<?php
2
3class PocheReadability extends Readability
4{
5 /**
6 * Get the article title as an H1.
7 *
8 * @return DOMElement
9 */
10 protected function getArticleTitle() {
11 $curTitle = '';
12 $origTitle = '';
13
14 try {
15 $curTitle = $origTitle = $this->getInnerText($this->dom->getElementsByTagName('title')->item(0));
16 } catch(Exception $e) {}
17
18 if (preg_match('/ [\|\-] /', $curTitle))
19 {
20 $curTitle = preg_replace('/(.*)[\|\-] .*/i', '$1', $origTitle);
21
22 if (count(explode(' ', $curTitle)) < 3) {
23 $curTitle = preg_replace('/[^\|\-]*[\|\-](.*)/i', '$1', $origTitle);
24 }
25 }
26 else if(strlen($curTitle) > 150 || strlen($curTitle) < 15)
27 {
28 $hOnes = $this->dom->getElementsByTagName('h1');
29 if($hOnes->length == 1)
30 {
31 $curTitle = $this->getInnerText($hOnes->item(0));
32 }
33 }
34
35 $curTitle = trim($curTitle);
36
37 if (count(explode(' ', $curTitle)) <= 4) {
38 $curTitle = $origTitle;
39 }
40
41 $articleTitle = $this->dom->createElement('h1');
42 $articleTitle->innerHTML = $curTitle;
43
44 return $articleTitle;
45 }
46} \ No newline at end of file
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index 3a792d43..8eb988f4 100644
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -84,9 +84,9 @@ class Tools
84 84
85 public static function getTplFile($view) 85 public static function getTplFile($view)
86 { 86 {
87 $tpl_file = 'home.twig'; 87 $default_tpl = 'home.twig';
88 switch ($view) 88
89 { 89 switch ($view) {
90 case 'install': 90 case 'install':
91 $tpl_file = 'install.twig'; 91 $tpl_file = 'install.twig';
92 break; 92 break;
@@ -102,9 +102,20 @@ class Tools
102 case 'view': 102 case 'view':
103 $tpl_file = 'view.twig'; 103 $tpl_file = 'view.twig';
104 break; 104 break;
105
106 case 'login':
107 $tpl_file = 'login.twig';
108 break;
109
110 case 'error':
111 $tpl_file = 'error.twig';
112 break;
113
105 default: 114 default:
106 break; 115 $tpl_file = $default_tpl;
116 break;
107 } 117 }
118
108 return $tpl_file; 119 return $tpl_file;
109 } 120 }
110 121
@@ -228,24 +239,8 @@ class Tools
228 return $minutes; 239 return $minutes;
229 } 240 }
230 241
231 242 public static function getDocLanguage($userlanguage) {
232 public static function createMyConfig() 243 $lang = explode('.', $userlanguage);
233 { 244 return str_replace('_', '-', $lang[0]);
234 $myconfig_file = './inc/poche/myconfig.inc.php';
235
236 if (!is_writable('./inc/poche/')) {
237 self::logm('you don\'t have write access to create ./inc/poche/myconfig.inc.php');
238 die('You don\'t have write access to create ./inc/poche/myconfig.inc.php.');
239 }
240
241 if (!file_exists($myconfig_file))
242 {
243 $fp = fopen($myconfig_file, 'w');
244 fwrite($fp, '<?php'."\r\n");
245 fwrite($fp, "define ('POCHE_VERSION', '1.0-beta4');" . "\r\n");
246 fwrite($fp, "define ('SALT', '" . md5(time() . $_SERVER['SCRIPT_FILENAME'] . rand()) . "');" . "\r\n");
247 fwrite($fp, "define ('LANG', 'en_EN.utf8');" . "\r\n");
248 fclose($fp);
249 }
250 } 245 }
251} \ No newline at end of file 246} \ No newline at end of file
diff --git a/inc/poche/Url.class.php b/inc/poche/Url.class.php
index 5a893014..600a2166 100644
--- a/inc/poche/Url.class.php
+++ b/inc/poche/Url.class.php
@@ -354,7 +354,7 @@ class Url
354 } 354 }
355 if (isset($splink)) { 355 if (isset($splink)) {
356 // Build DOM tree from HTML 356 // Build DOM tree from HTML
357 $readability = new Readability($html, $url); 357 $readability = new PocheReadability($html, $url);
358 $xpath = new DOMXPath($readability->dom); 358 $xpath = new DOMXPath($readability->dom);
359 // Loop through single_page_link xpath expressions 359 // Loop through single_page_link xpath expressions
360 $single_page_url = null; 360 $single_page_url = null;
diff --git a/inc/poche/config.inc.php b/inc/poche/config.inc.php
deleted file mode 100755
index a1917295..00000000
--- a/inc/poche/config.inc.php
+++ /dev/null
@@ -1,59 +0,0 @@
1<?php
2/**
3 * poche, a read it later open source system
4 *
5 * @category poche
6 * @author Nicolas Lœuillet <nicolas@loeuillet.org>
7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file
9 */
10
11require_once __DIR__ . '/../../inc/poche/define.inc.php';
12
13# /!\ Be careful if you change the lines below /!\
14if (!file_exists(__DIR__ . '/../../vendor/autoload.php')) {
15 die('Twig does not seem installed. Have a look at <a href="http://inthepoche.com/?pages/Documentation">the documentation.</a>');
16}
17
18// if (file_exists(__DIR__ . '/../../inc/poche/myconfig.inc.php')) {
19 // require_once __DIR__ . '/../../inc/poche/myconfig.inc.php';
20// }
21require_once __DIR__ . '/../../inc/poche/User.class.php';
22require_once __DIR__ . '/../../inc/poche/Url.class.php';
23require_once __DIR__ . '/../../inc/3rdparty/class.messages.php';
24require_once __DIR__ . '/../../inc/poche/Poche.class.php';
25require_once __DIR__ . '/../../inc/3rdparty/Readability.php';
26require_once __DIR__ . '/../../inc/3rdparty/Encoding.php';
27require_once __DIR__ . '/../../inc/poche/Database.class.php';
28require_once __DIR__ . '/../../vendor/autoload.php';
29require_once __DIR__ . '/../../inc/3rdparty/simple_html_dom.php';
30require_once __DIR__ . '/../../inc/3rdparty/paginator.php';
31require_once __DIR__ . '/../../inc/3rdparty/Session.class.php';
32
33require_once __DIR__ . '/../../inc/3rdparty/simplepie/SimplePieAutoloader.php';
34require_once __DIR__ . '/../../inc/3rdparty/simplepie/SimplePie/Core.php';
35require_once __DIR__ . '/../../inc/3rdparty/content-extractor/ContentExtractor.php';
36require_once __DIR__ . '/../../inc/3rdparty/content-extractor/SiteConfig.php';
37require_once __DIR__ . '/../../inc/3rdparty/humble-http-agent/HumbleHttpAgent.php';
38require_once __DIR__ . '/../../inc/3rdparty/humble-http-agent/SimplePie_HumbleHttpAgent.php';
39require_once __DIR__ . '/../../inc/3rdparty/humble-http-agent/CookieJar.php';
40require_once __DIR__ . '/../../inc/3rdparty/feedwriter/FeedItem.php';
41require_once __DIR__ . '/../../inc/3rdparty/feedwriter/FeedWriter.php';
42require_once __DIR__ . '/../../inc/3rdparty/feedwriter/DummySingleItemFeed.php';
43
44if (DOWNLOAD_PICTURES) {
45 require_once __DIR__ . '/../../inc/poche/pochePictures.php';
46}
47
48if (!ini_get('date.timezone') || !@date_default_timezone_set(ini_get('date.timezone'))) {
49 date_default_timezone_set('UTC');
50}
51
52$poche = new Poche();
53#XSRF protection with token
54// if (!empty($_POST)) {
55// if (!Session::isToken($_POST['token'])) {
56// die(_('Wrong token'));
57// }
58// unset($_SESSION['tokens']);
59// } \ No newline at end of file
diff --git a/inc/poche/config.inc.php.new b/inc/poche/config.inc.php.new
new file mode 100755
index 00000000..48cc5783
--- /dev/null
+++ b/inc/poche/config.inc.php.new
@@ -0,0 +1,56 @@
1<?php
2/**
3 * poche, a read it later open source system
4 *
5 * @category poche
6 * @author Nicolas Lœuillet <support@inthepoche.com>
7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file
9 */
10
11define ('SALT', ''); # put a strong string here
12define ('LANG', 'en_EN.utf8');
13
14define ('STORAGE', 'sqlite'); # postgres, mysql or sqlite
15
16define ('STORAGE_SQLITE', ROOT . '/db/poche.sqlite'); # if you are using sqlite, where the database file is located
17
18# only for postgres & mysql
19define ('STORAGE_SERVER', 'localhost');
20define ('STORAGE_DB', 'poche');
21define ('STORAGE_USER', 'poche');
22define ('STORAGE_PASSWORD', 'poche');
23
24#################################################################################
25# Do not trespass unless you know what you are doing
26#################################################################################
27
28define ('MODE_DEMO', FALSE);
29define ('DEBUG_POCHE', true);
30define ('DOWNLOAD_PICTURES', FALSE);
31define ('CONVERT_LINKS_FOOTNOTES', FALSE);
32define ('REVERT_FORCED_PARAGRAPH_ELEMENTS', FALSE);
33define ('SHARE_TWITTER', TRUE);
34define ('SHARE_MAIL', TRUE);
35define ('SHARE_SHAARLI', FALSE);
36define ('SHAARLI_URL', 'http://myshaarliurl.com');
37define ('FLATTR', TRUE);
38define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url=');
39define ('NOT_FLATTRABLE', '0');
40define ('FLATTRABLE', '1');
41define ('FLATTRED', '2');
42define ('ABS_PATH', 'assets/');
43
44define ('DEFAULT_THEME', 'default');
45
46define ('THEME', ROOT . '/themes');
47define ('LOCALE', ROOT . '/locale');
48define ('CACHE', ROOT . '/cache');
49
50define ('PAGINATION', '10');
51
52define ('POCHE_VERSION', '1.0-beta5');
53
54define ('IMPORT_POCKET_FILE', ROOT . '/ril_export.html');
55define ('IMPORT_READABILITY_FILE', ROOT . '/readability');
56define ('IMPORT_INSTAPAPER_FILE', ROOT . '/instapaper-export.html'); \ No newline at end of file
diff --git a/inc/poche/define.inc.php b/inc/poche/define.inc.php
index 3f667430..40f77b5c 100644
--- a/inc/poche/define.inc.php
+++ b/inc/poche/define.inc.php
@@ -3,7 +3,7 @@
3 * poche, a read it later open source system 3 * poche, a read it later open source system
4 * 4 *
5 * @category poche 5 * @category poche
6 * @author Nicolas Lœuillet <nicolas@loeuillet.org> 6 * @author Nicolas Lœuillet <support@inthepoche.com>
7 * @copyright 2013 7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file 8 * @license http://www.wtfpl.net/ see COPYING file
9 */ 9 */
@@ -22,6 +22,11 @@ define ('SHARE_TWITTER', TRUE);
22define ('SHARE_MAIL', TRUE); 22define ('SHARE_MAIL', TRUE);
23define ('SHARE_SHAARLI', FALSE); 23define ('SHARE_SHAARLI', FALSE);
24define ('SHAARLI_URL', 'http://myshaarliurl.com'); 24define ('SHAARLI_URL', 'http://myshaarliurl.com');
25define ('FLATTR', TRUE);
26define ('FLATTR_API', 'https://api.flattr.com/rest/v2/things/lookup/?url=');
27define ('NOT_FLATTRABLE', '0');
28define ('FLATTRABLE', '1');
29define ('FLATTRED', '2');
25define ('ABS_PATH', 'assets/'); 30define ('ABS_PATH', 'assets/');
26define ('TPL', __DIR__ . '/../../tpl'); 31define ('TPL', __DIR__ . '/../../tpl');
27define ('LOCALE', __DIR__ . '/../../locale'); 32define ('LOCALE', __DIR__ . '/../../locale');
diff --git a/inc/poche/global.inc.php b/inc/poche/global.inc.php
new file mode 100644
index 00000000..65a026a7
--- /dev/null
+++ b/inc/poche/global.inc.php
@@ -0,0 +1,64 @@
1<?php
2/**
3 * poche, a read it later open source system
4 *
5 * @category poche
6 * @author Nicolas Lœuillet <support@inthepoche.com>
7 * @copyright 2013
8 * @license http://www.wtfpl.net/ see COPYING file
9 */
10
11# the poche system root directory (/inc)
12define('INCLUDES', dirname(__FILE__) . '/..');
13
14# the poche root directory
15define('ROOT', INCLUDES . '/..');
16
17require_once INCLUDES . '/poche/Tools.class.php';
18require_once INCLUDES . '/poche/User.class.php';
19require_once INCLUDES . '/poche/Url.class.php';
20require_once INCLUDES . '/3rdparty/class.messages.php';
21require_once INCLUDES . '/poche/Poche.class.php';
22
23require_once INCLUDES . '/3rdparty/Readability.php';
24require_once INCLUDES . '/poche/PocheReadability.php';
25
26require_once INCLUDES . '/3rdparty/Encoding.php';
27require_once INCLUDES . '/poche/Database.class.php';
28require_once INCLUDES . '/3rdparty/simple_html_dom.php';
29require_once INCLUDES . '/3rdparty/paginator.php';
30require_once INCLUDES . '/3rdparty/Session.class.php';
31
32require_once INCLUDES . '/3rdparty/simplepie/SimplePieAutoloader.php';
33require_once INCLUDES . '/3rdparty/simplepie/SimplePie/Core.php';
34require_once INCLUDES . '/3rdparty/content-extractor/ContentExtractor.php';
35require_once INCLUDES . '/3rdparty/content-extractor/SiteConfig.php';
36require_once INCLUDES . '/3rdparty/humble-http-agent/HumbleHttpAgent.php';
37require_once INCLUDES . '/3rdparty/humble-http-agent/SimplePie_HumbleHttpAgent.php';
38require_once INCLUDES . '/3rdparty/humble-http-agent/CookieJar.php';
39require_once INCLUDES . '/3rdparty/feedwriter/FeedItem.php';
40require_once INCLUDES . '/3rdparty/feedwriter/FeedWriter.php';
41require_once INCLUDES . '/3rdparty/feedwriter/DummySingleItemFeed.php';
42require_once INCLUDES . '/3rdparty/FlattrItem.class.php';
43
44# Composer its autoloader for automatically loading Twig
45if (! file_exists(ROOT . '/vendor/autoload.php')) {
46 Poche::$canRenderTemplates = false;
47} else {
48 require_once ROOT . '/vendor/autoload.php';
49}
50
51# system configuration; database credentials et cetera
52if (! file_exists(INCLUDES . '/poche/config.inc.php')) {
53 Poche::$configFileAvailable = false;
54} else {
55 require_once INCLUDES . '/poche/config.inc.php';
56}
57
58if (Poche::$configFileAvailable && DOWNLOAD_PICTURES) {
59 require_once INCLUDES . '/poche/pochePictures.php';
60}
61
62if (!ini_get('date.timezone') || !@date_default_timezone_set(ini_get('date.timezone'))) {
63 date_default_timezone_set('UTC');
64} \ No newline at end of file