aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
authorMaryana Rozhankivska <mariroz@mr.lviv.ua>2014-04-02 20:55:19 +0300
committerMaryana Rozhankivska <mariroz@mr.lviv.ua>2014-04-02 20:55:19 +0300
commit182faf2696b38502d4784efc3f84f2f00290343f (patch)
tree619e725c1820773dcd8bb1fe9cbd07c0c325e865 /inc/poche
parent22db488d21bc23dc28fc2d60574803525fe53b53 (diff)
downloadwallabag-182faf2696b38502d4784efc3f84f2f00290343f.tar.gz
wallabag-182faf2696b38502d4784efc3f84f2f00290343f.tar.zst
wallabag-182faf2696b38502d4784efc3f84f2f00290343f.zip
import without cron
Diffstat (limited to 'inc/poche')
-rwxr-xr-xinc/poche/Database.class.php82
-rwxr-xr-xinc/poche/Poche.class.php292
-rwxr-xr-xinc/poche/Tools.class.php8
-rwxr-xr-xinc/poche/config.inc.php.new14
4 files changed, 241 insertions, 155 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index 6f5c9ac0..9adb1644 100755
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -18,7 +18,7 @@ class Database {
18 'default' => 'ORDER BY entries.id' 18 'default' => 'ORDER BY entries.id'
19 ); 19 );
20 20
21 function __construct() 21 function __construct()
22 { 22 {
23 switch (STORAGE) { 23 switch (STORAGE) {
24 case 'sqlite': 24 case 'sqlite':
@@ -27,11 +27,11 @@ class Database {
27 break; 27 break;
28 case 'mysql': 28 case 'mysql':
29 $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; 29 $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB;
30 $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD); 30 $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD);
31 break; 31 break;
32 case 'postgres': 32 case 'postgres':
33 $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; 33 $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB;
34 $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD); 34 $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD);
35 break; 35 break;
36 } 36 }
37 37
@@ -51,7 +51,7 @@ class Database {
51 } 51 }
52 $hasAdmin = count($query->fetchAll()); 52 $hasAdmin = count($query->fetchAll());
53 53
54 if ($hasAdmin == 0) 54 if ($hasAdmin == 0)
55 return false; 55 return false;
56 56
57 return true; 57 return true;
@@ -140,7 +140,7 @@ class Database {
140 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; 140 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
141 $params = array($id_user, 'language', LANG); 141 $params = array($id_user, 'language', LANG);
142 $query = $this->executeQuery($sql, $params); 142 $query = $this->executeQuery($sql, $params);
143 143
144 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)'; 144 $sql = 'INSERT INTO users_config ( user_id, name, value ) VALUES (?, ?, ?)';
145 $params = array($id_user, 'theme', DEFAULT_THEME); 145 $params = array($id_user, 'theme', DEFAULT_THEME);
146 $query = $this->executeQuery($sql, $params); 146 $query = $this->executeQuery($sql, $params);
@@ -153,7 +153,7 @@ class Database {
153 $query = $this->executeQuery($sql, array($id)); 153 $query = $this->executeQuery($sql, array($id));
154 $result = $query->fetchAll(); 154 $result = $query->fetchAll();
155 $user_config = array(); 155 $user_config = array();
156 156
157 foreach ($result as $key => $value) { 157 foreach ($result as $key => $value) {
158 $user_config[$value['name']] = $value['value']; 158 $user_config[$value['name']] = $value['value'];
159 } 159 }
@@ -201,10 +201,10 @@ class Database {
201 $params_update = array($password, $userId); 201 $params_update = array($password, $userId);
202 $query = $this->executeQuery($sql_update, $params_update); 202 $query = $this->executeQuery($sql_update, $params_update);
203 } 203 }
204 204
205 public function updateUserConfig($userId, $key, $value) { 205 public function updateUserConfig($userId, $key, $value) {
206 $config = $this->getConfigUser($userId); 206 $config = $this->getConfigUser($userId);
207 207
208 if (! isset($config[$key])) { 208 if (! isset($config[$key])) {
209 $sql = "INSERT INTO users_config (value, user_id, name) VALUES (?, ?, ?)"; 209 $sql = "INSERT INTO users_config (value, user_id, name) VALUES (?, ?, ?)";
210 } 210 }
@@ -252,8 +252,16 @@ class Database {
252 return $entries; 252 return $entries;
253 } 253 }
254 254
255 public function retrieveUnfetchedEntriesCount($user_id) {
256 $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND user_id=?";
257 $query = $this->executeQuery($sql, array($user_id));
258 list($count) = $query->fetch();
259
260 return $count;
261 }
262
255 public function retrieveAll($user_id) { 263 public function retrieveAll($user_id) {
256 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? ORDER BY id"; 264 $sql = "SELECT * FROM entries WHERE user_id=? ORDER BY id";
257 $query = $this->executeQuery($sql, array($user_id)); 265 $query = $this->executeQuery($sql, array($user_id));
258 $entries = $query->fetchAll(); 266 $entries = $query->fetchAll();
259 267
@@ -272,7 +280,7 @@ class Database {
272 280
273 public function retrieveOneByURL($url, $user_id) { 281 public function retrieveOneByURL($url, $user_id) {
274 $entry = NULL; 282 $entry = NULL;
275 $sql = "SELECT * FROM entries WHERE content <> '' AND url=? AND user_id=?"; 283 $sql = "SELECT * FROM entries WHERE url=? AND user_id=?";
276 $params = array($url, $user_id); 284 $params = array($url, $user_id);
277 $query = $this->executeQuery($sql, $params); 285 $query = $this->executeQuery($sql, $params);
278 $entry = $query->fetchAll(); 286 $entry = $query->fetchAll();
@@ -289,22 +297,21 @@ class Database {
289 public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) { 297 public function getEntriesByView($view, $user_id, $limit = '', $tag_id = 0) {
290 switch ($view) { 298 switch ($view) {
291 case 'archive': 299 case 'archive':
292 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; 300 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
293 $params = array($user_id, 1); 301 $params = array($user_id, 1);
294 break; 302 break;
295 case 'fav' : 303 case 'fav' :
296 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_fav=? "; 304 $sql = "SELECT * FROM entries WHERE user_id=? AND is_fav=? ";
297 $params = array($user_id, 1); 305 $params = array($user_id, 1);
298 break; 306 break;
299 case 'tag' : 307 case 'tag' :
300 $sql = "SELECT entries.* FROM entries 308 $sql = "SELECT entries.* FROM entries
301 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id 309 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
302 WHERE entries.content <> '' AND 310 WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
303 entries.user_id=? AND tags_entries.tag_id = ? ";
304 $params = array($user_id, $tag_id); 311 $params = array($user_id, $tag_id);
305 break; 312 break;
306 default: 313 default:
307 $sql = "SELECT * FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; 314 $sql = "SELECT * FROM entries WHERE user_id=? AND is_read=? ";
308 $params = array($user_id, 0); 315 $params = array($user_id, 0);
309 break; 316 break;
310 } 317 }
@@ -320,22 +327,21 @@ class Database {
320 public function getEntriesByViewCount($view, $user_id, $tag_id = 0) { 327 public function getEntriesByViewCount($view, $user_id, $tag_id = 0) {
321 switch ($view) { 328 switch ($view) {
322 case 'archive': 329 case 'archive':
323 $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; 330 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
324 $params = array($user_id, 1); 331 $params = array($user_id, 1);
325 break; 332 break;
326 case 'fav' : 333 case 'fav' :
327 $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_fav=? "; 334 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_fav=? ";
328 $params = array($user_id, 1); 335 $params = array($user_id, 1);
329 break; 336 break;
330 case 'tag' : 337 case 'tag' :
331 $sql = "SELECT count(*) FROM entries 338 $sql = "SELECT count(*) FROM entries
332 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id 339 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
333 WHERE entries.content <> '' AND 340 WHERE entries.user_id=? AND tags_entries.tag_id = ? ";
334 entries.user_id=? AND tags_entries.tag_id = ? ";
335 $params = array($user_id, $tag_id); 341 $params = array($user_id, $tag_id);
336 break; 342 break;
337 default: 343 default:
338 $sql = "SELECT count(*) FROM entries WHERE content <> '' AND user_id=? AND is_read=? "; 344 $sql = "SELECT count(*) FROM entries WHERE user_id=? AND is_read=? ";
339 $params = array($user_id, 0); 345 $params = array($user_id, 0);
340 break; 346 break;
341 } 347 }
@@ -353,11 +359,24 @@ class Database {
353 return $query; 359 return $query;
354 } 360 }
355 361
356 public function add($url, $title, $content, $user_id) { 362 /**
357 $sql_action = 'INSERT INTO entries ( url, title, content, user_id ) VALUES (?, ?, ?, ?)'; 363 *
358 $params_action = array($url, $title, $content, $user_id); 364 * @param string $url
359 $query = $this->executeQuery($sql_action, $params_action); 365 * @param string $title
360 return $query; 366 * @param string $content
367 * @param integer $user_id
368 * @return integer $id of inserted record
369 */
370 public function add($url, $title, $content, $user_id, $isFavorite=0, $isRead=0) {
371 $sql_action = 'INSERT INTO entries ( url, title, content, user_id, is_fav, is_read ) VALUES (?, ?, ?, ?, ?, ?)';
372 $params_action = array($url, $title, $content, $user_id, $isFavorite, $isRead);
373 if ( !$this->executeQuery($sql_action, $params_action) ) {
374 $id = null;
375 }
376 else {
377 $id = intval($this->getLastId( (STORAGE == 'postgres') ? 'users_id_seq' : '' ));
378 }
379 return $id;
361 } 380 }
362 381
363 public function deleteById($id, $user_id) { 382 public function deleteById($id, $user_id) {
@@ -388,7 +407,7 @@ class Database {
388 public function getLastId($column = '') { 407 public function getLastId($column = '') {
389 return $this->getHandle()->lastInsertId($column); 408 return $this->getHandle()->lastInsertId($column);
390 } 409 }
391 410
392 public function search($term){ 411 public function search($term){
393 $search = '%'.$term.'%'; 412 $search = '%'.$term.'%';
394 $query = $this->getHandle()->prepare("SELECT * FROM entries WHERE content LIKE ? OR title LIKE ? OR url LIKE ?"); //searches in content, title and URL 413 $query = $this->getHandle()->prepare("SELECT * FROM entries WHERE content LIKE ? OR title LIKE ? OR url LIKE ?"); //searches in content, title and URL
@@ -401,7 +420,7 @@ class Database {
401 $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags 420 $sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags
402 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id 421 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
403 LEFT JOIN entries ON tags_entries.entry_id=entries.id 422 LEFT JOIN entries ON tags_entries.entry_id=entries.id
404 WHERE entries.content <> '' AND entries.user_id=? 423 WHERE entries.user_id=?
405 ". (($term) ? "AND lower(tags.value) LIKE ?" : '') ." 424 ". (($term) ? "AND lower(tags.value) LIKE ?" : '') ."
406 GROUP BY tags.id, tags.value 425 GROUP BY tags.id, tags.value
407 ORDER BY tags.value"; 426 ORDER BY tags.value";
@@ -416,7 +435,7 @@ class Database {
416 $sql = "SELECT DISTINCT tags.* FROM tags 435 $sql = "SELECT DISTINCT tags.* FROM tags
417 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id 436 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
418 LEFT JOIN entries ON tags_entries.entry_id=entries.id 437 LEFT JOIN entries ON tags_entries.entry_id=entries.id
419 WHERE entries.content <> '' AND tags.id=? AND entries.user_id=?"; 438 WHERE tags.id=? AND entries.user_id=?";
420 $params = array(intval($id), $user_id); 439 $params = array(intval($id), $user_id);
421 $query = $this->executeQuery($sql, $params); 440 $query = $this->executeQuery($sql, $params);
422 $tag = $query->fetchAll(); 441 $tag = $query->fetchAll();
@@ -425,11 +444,10 @@ class Database {
425 } 444 }
426 445
427 public function retrieveEntriesByTag($tag_id, $user_id) { 446 public function retrieveEntriesByTag($tag_id, $user_id) {
428 $sql = 447 $sql =
429 "SELECT entries.* FROM entries 448 "SELECT entries.* FROM entries
430 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id 449 LEFT JOIN tags_entries ON tags_entries.entry_id=entries.id
431 WHERE entries.content <> '' AND 450 WHERE tags_entries.tag_id = ? AND entries.user_id=?";
432 tags_entries.tag_id = ? AND entries.user_id=?";
433 $query = $this->executeQuery($sql, array($tag_id, $user_id)); 451 $query = $this->executeQuery($sql, array($tag_id, $user_id));
434 $entries = $query->fetchAll(); 452 $entries = $query->fetchAll();
435 453
@@ -437,7 +455,7 @@ class Database {
437 } 455 }
438 456
439 public function retrieveTagsByEntry($entry_id) { 457 public function retrieveTagsByEntry($entry_id) {
440 $sql = 458 $sql =
441 "SELECT tags.* FROM tags 459 "SELECT tags.* FROM tags
442 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id 460 LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
443 WHERE tags_entries.entry_id = ?"; 461 WHERE tags_entries.entry_id = ?";
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 7d9faed1..d1b0c945 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -18,7 +18,7 @@ class Poche
18 public $tpl; 18 public $tpl;
19 public $messages; 19 public $messages;
20 public $pagination; 20 public $pagination;
21 21
22 private $currentTheme = ''; 22 private $currentTheme = '';
23 private $currentLanguage = ''; 23 private $currentLanguage = '';
24 private $notInstalledMessage = array(); 24 private $notInstalledMessage = array();
@@ -42,11 +42,11 @@ class Poche
42 if ($this->configFileIsAvailable()) { 42 if ($this->configFileIsAvailable()) {
43 $this->init(); 43 $this->init();
44 } 44 }
45 45
46 if ($this->themeIsInstalled()) { 46 if ($this->themeIsInstalled()) {
47 $this->initTpl(); 47 $this->initTpl();
48 } 48 }
49 49
50 if ($this->systemIsInstalled()) { 50 if ($this->systemIsInstalled()) {
51 $this->store = new Database(); 51 $this->store = new Database();
52 $this->messages = new Messages(); 52 $this->messages = new Messages();
@@ -57,8 +57,8 @@ class Poche
57 $this->store->checkTags(); 57 $this->store->checkTags();
58 } 58 }
59 } 59 }
60 60
61 private function init() 61 private function init()
62 { 62 {
63 Tools::initPhp(); 63 Tools::initPhp();
64 64
@@ -74,28 +74,28 @@ class Poche
74 $language = $this->user->getConfigValue('language'); 74 $language = $this->user->getConfigValue('language');
75 putenv('LC_ALL=' . $language); 75 putenv('LC_ALL=' . $language);
76 setlocale(LC_ALL, $language); 76 setlocale(LC_ALL, $language);
77 bindtextdomain($language, LOCALE); 77 bindtextdomain($language, LOCALE);
78 textdomain($language); 78 textdomain($language);
79 79
80 # Pagination 80 # Pagination
81 $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p'); 81 $this->pagination = new Paginator($this->user->getConfigValue('pager'), 'p');
82 82
83 # Set up theme 83 # Set up theme
84 $themeDirectory = $this->user->getConfigValue('theme'); 84 $themeDirectory = $this->user->getConfigValue('theme');
85 85
86 if ($themeDirectory === false) { 86 if ($themeDirectory === false) {
87 $themeDirectory = DEFAULT_THEME; 87 $themeDirectory = DEFAULT_THEME;
88 } 88 }
89 89
90 $this->currentTheme = $themeDirectory; 90 $this->currentTheme = $themeDirectory;
91 91
92 # Set up language 92 # Set up language
93 $languageDirectory = $this->user->getConfigValue('language'); 93 $languageDirectory = $this->user->getConfigValue('language');
94 94
95 if ($languageDirectory === false) { 95 if ($languageDirectory === false) {
96 $languageDirectory = DEFAULT_THEME; 96 $languageDirectory = DEFAULT_THEME;
97 } 97 }
98 98
99 $this->currentLanguage = $languageDirectory; 99 $this->currentLanguage = $languageDirectory;
100 } 100 }
101 101
@@ -108,7 +108,7 @@ class Poche
108 108
109 return true; 109 return true;
110 } 110 }
111 111
112 public function themeIsInstalled() { 112 public function themeIsInstalled() {
113 $passTheme = TRUE; 113 $passTheme = TRUE;
114 # Twig is an absolute requirement for Poche to function. Abort immediately if the Composer installer hasn't been run yet 114 # Twig is an absolute requirement for Poche to function. Abort immediately if the Composer installer hasn't been run yet
@@ -123,27 +123,27 @@ class Poche
123 self::$canRenderTemplates = false; 123 self::$canRenderTemplates = false;
124 124
125 $passTheme = FALSE; 125 $passTheme = FALSE;
126 } 126 }
127 127
128 # Check if the selected theme and its requirements are present 128 # Check if the selected theme and its requirements are present
129 $theme = $this->getTheme(); 129 $theme = $this->getTheme();
130 130
131 if ($theme != '' && ! is_dir(THEME . '/' . $theme)) { 131 if ($theme != '' && ! is_dir(THEME . '/' . $theme)) {
132 $this->notInstalledMessage[] = 'The currently selected theme (' . $theme . ') does not seem to be properly installed (Missing directory: ' . THEME . '/' . $theme . ')'; 132 $this->notInstalledMessage[] = 'The currently selected theme (' . $theme . ') does not seem to be properly installed (Missing directory: ' . THEME . '/' . $theme . ')';
133 133
134 self::$canRenderTemplates = false; 134 self::$canRenderTemplates = false;
135 135
136 $passTheme = FALSE; 136 $passTheme = FALSE;
137 } 137 }
138 138
139 $themeInfo = $this->getThemeInfo($theme); 139 $themeInfo = $this->getThemeInfo($theme);
140 if (isset($themeInfo['requirements']) && is_array($themeInfo['requirements'])) { 140 if (isset($themeInfo['requirements']) && is_array($themeInfo['requirements'])) {
141 foreach ($themeInfo['requirements'] as $requiredTheme) { 141 foreach ($themeInfo['requirements'] as $requiredTheme) {
142 if (! is_dir(THEME . '/' . $requiredTheme)) { 142 if (! is_dir(THEME . '/' . $requiredTheme)) {
143 $this->notInstalledMessage[] = 'The required "' . $requiredTheme . '" theme is missing for the current theme (' . $theme . ')'; 143 $this->notInstalledMessage[] = 'The required "' . $requiredTheme . '" theme is missing for the current theme (' . $theme . ')';
144 144
145 self::$canRenderTemplates = false; 145 self::$canRenderTemplates = false;
146 146
147 $passTheme = FALSE; 147 $passTheme = FALSE;
148 } 148 }
149 } 149 }
@@ -153,21 +153,21 @@ class Poche
153 return FALSE; 153 return FALSE;
154 } 154 }
155 155
156 156
157 return true; 157 return true;
158 } 158 }
159 159
160 /** 160 /**
161 * all checks before installation. 161 * all checks before installation.
162 * @todo move HTML to template 162 * @todo move HTML to template
163 * @return boolean 163 * @return boolean
164 */ 164 */
165 public function systemIsInstalled() 165 public function systemIsInstalled()
166 { 166 {
167 $msg = TRUE; 167 $msg = TRUE;
168 168
169 $configSalt = defined('SALT') ? constant('SALT') : ''; 169 $configSalt = defined('SALT') ? constant('SALT') : '';
170 170
171 if (empty($configSalt)) { 171 if (empty($configSalt)) {
172 $this->notInstalledMessage[] = 'You have not yet filled in the SALT value in the config.inc.php file.'; 172 $this->notInstalledMessage[] = 'You have not yet filled in the SALT value in the config.inc.php file.';
173 $msg = FALSE; 173 $msg = FALSE;
@@ -193,7 +193,7 @@ class Poche
193 193
194 return true; 194 return true;
195 } 195 }
196 196
197 public function getNotInstalledMessage() { 197 public function getNotInstalledMessage() {
198 return $this->notInstalledMessage; 198 return $this->notInstalledMessage;
199 } 199 }
@@ -202,7 +202,7 @@ class Poche
202 { 202 {
203 $loaderChain = new Twig_Loader_Chain(); 203 $loaderChain = new Twig_Loader_Chain();
204 $theme = $this->getTheme(); 204 $theme = $this->getTheme();
205 205
206 # add the current theme as first to the loader chain so Twig will look there first for overridden template files 206 # add the current theme as first to the loader chain so Twig will look there first for overridden template files
207 try { 207 try {
208 $loaderChain->addLoader(new Twig_Loader_Filesystem(THEME . '/' . $theme)); 208 $loaderChain->addLoader(new Twig_Loader_Filesystem(THEME . '/' . $theme));
@@ -210,7 +210,7 @@ class Poche
210 # @todo isInstalled() should catch this, inject Twig later 210 # @todo isInstalled() should catch this, inject Twig later
211 die('The currently selected theme (' . $theme . ') does not seem to be properly installed (' . THEME . '/' . $theme .' is missing)'); 211 die('The currently selected theme (' . $theme . ') does not seem to be properly installed (' . THEME . '/' . $theme .' is missing)');
212 } 212 }
213 213
214 # add all required themes to the loader chain 214 # add all required themes to the loader chain
215 $themeInfo = $this->getThemeInfo($theme); 215 $themeInfo = $this->getThemeInfo($theme);
216 if (isset($themeInfo['requirements']) && is_array($themeInfo['requirements'])) { 216 if (isset($themeInfo['requirements']) && is_array($themeInfo['requirements'])) {
@@ -223,16 +223,16 @@ class Poche
223 } 223 }
224 } 224 }
225 } 225 }
226 226
227 if (DEBUG_POCHE) { 227 if (DEBUG_POCHE) {
228 $twigParams = array(); 228 $twigParams = array();
229 } else { 229 } else {
230 $twigParams = array('cache' => CACHE); 230 $twigParams = array('cache' => CACHE);
231 } 231 }
232 232
233 $this->tpl = new Twig_Environment($loaderChain, $twigParams); 233 $this->tpl = new Twig_Environment($loaderChain, $twigParams);
234 $this->tpl->addExtension(new Twig_Extensions_Extension_I18n()); 234 $this->tpl->addExtension(new Twig_Extensions_Extension_I18n());
235 235
236 # filter to display domain name of an url 236 # filter to display domain name of an url
237 $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); 237 $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain');
238 $this->tpl->addFilter($filter); 238 $this->tpl->addFilter($filter);
@@ -251,7 +251,7 @@ class Poche
251 'poche_url' => Tools::getPocheUrl() 251 'poche_url' => Tools::getPocheUrl()
252 )); 252 ));
253 if (isset($_GET['install'])) { 253 if (isset($_GET['install'])) {
254 if (($_POST['password'] == $_POST['password_repeat']) 254 if (($_POST['password'] == $_POST['password_repeat'])
255 && $_POST['password'] != "" && $_POST['login'] != "") { 255 && $_POST['password'] != "" && $_POST['login'] != "") {
256 # let's rock, install poche baby ! 256 # let's rock, install poche baby !
257 if ($this->store->install($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login']))) 257 if ($this->store->install($_POST['login'], Tools::encodeString($_POST['password'] . $_POST['login'])))
@@ -268,7 +268,7 @@ class Poche
268 } 268 }
269 exit(); 269 exit();
270 } 270 }
271 271
272 public function getTheme() { 272 public function getTheme() {
273 return $this->currentTheme; 273 return $this->currentTheme;
274 } 274 }
@@ -293,7 +293,7 @@ class Poche
293 if (is_file($themeIniFile) && is_readable($themeIniFile)) { 293 if (is_file($themeIniFile) && is_readable($themeIniFile)) {
294 $themeInfo = parse_ini_file($themeIniFile); 294 $themeInfo = parse_ini_file($themeIniFile);
295 } 295 }
296 296
297 if ($themeInfo === false) { 297 if ($themeInfo === false) {
298 $themeInfo = array(); 298 $themeInfo = array();
299 } 299 }
@@ -304,7 +304,7 @@ class Poche
304 304
305 return $themeInfo; 305 return $themeInfo;
306 } 306 }
307 307
308 public function getInstalledThemes() { 308 public function getInstalledThemes() {
309 $handle = opendir(THEME); 309 $handle = opendir(THEME);
310 $themes = array(); 310 $themes = array();
@@ -331,28 +331,28 @@ class Poche
331 public function getInstalledLanguages() { 331 public function getInstalledLanguages() {
332 $handle = opendir(LOCALE); 332 $handle = opendir(LOCALE);
333 $languages = array(); 333 $languages = array();
334 334
335 while (($language = readdir($handle)) !== false) { 335 while (($language = readdir($handle)) !== false) {
336 # Languages are stored in a directory, so all directory names are languages 336 # Languages are stored in a directory, so all directory names are languages
337 # @todo move language installation data to database 337 # @todo move language installation data to database
338 if (! is_dir(LOCALE . '/' . $language) || in_array($language, array('..', '.', 'tools'))) { 338 if (! is_dir(LOCALE . '/' . $language) || in_array($language, array('..', '.', 'tools'))) {
339 continue; 339 continue;
340 } 340 }
341 341
342 $current = false; 342 $current = false;
343 343
344 if ($language === $this->getLanguage()) { 344 if ($language === $this->getLanguage()) {
345 $current = true; 345 $current = true;
346 } 346 }
347 347
348 $languages[] = array('name' => (isset($this->language_names[$language]) ? $this->language_names[$language] : $language), 'value' => $language, 'current' => $current); 348 $languages[] = array('name' => (isset($this->language_names[$language]) ? $this->language_names[$language] : $language), 'value' => $language, 'current' => $current);
349 } 349 }
350 350
351 return $languages; 351 return $languages;
352 } 352 }
353 353
354 public function getDefaultConfig() 354 public function getDefaultConfig()
355 { 355 {
356 return array( 356 return array(
357 'pager' => PAGINATION, 357 'pager' => PAGINATION,
358 'language' => LANG, 358 'language' => LANG,
@@ -385,19 +385,15 @@ class Poche
385 $body = ''; 385 $body = '';
386 } 386 }
387 387
388 //search for possible duplicate if not in import mode 388 //search for possible duplicate
389 $duplicate = NULL; 389 $duplicate = NULL;
390 if (!$import) { 390 if (!$import) {
391 $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId()); 391 $duplicate = $this->store->retrieveOneByURL($url->getUrl(), $this->user->getId());
392 } 392 }
393 393
394 if ($this->store->add($url->getUrl(), $title, $body, $this->user->getId())) { 394 $last_id = $this->store->add($url->getUrl(), $title, $body, $this->user->getId());
395 if ( $last_id && !$import ) {
395 Tools::logm('add link ' . $url->getUrl()); 396 Tools::logm('add link ' . $url->getUrl());
396 $sequence = '';
397 if (STORAGE == 'postgres') {
398 $sequence = 'entries_id_seq';
399 }
400 $last_id = $this->store->getLastId($sequence);
401 if (DOWNLOAD_PICTURES) { 397 if (DOWNLOAD_PICTURES) {
402 $content = filtre_picture($body, $url->getUrl(), $last_id); 398 $content = filtre_picture($body, $url->getUrl(), $last_id);
403 Tools::logm('updating content article'); 399 Tools::logm('updating content article');
@@ -417,9 +413,7 @@ class Poche
417 } 413 }
418 } 414 }
419 415
420 if (!$import) { 416 $this->messages->add('s', _('the link has been added successfully'));
421 $this->messages->add('s', _('the link has been added successfully'));
422 }
423 } 417 }
424 else { 418 else {
425 if (!$import) { 419 if (!$import) {
@@ -603,7 +597,7 @@ class Poche
603 'tags' => $tags, 597 'tags' => $tags,
604 ); 598 );
605 break; 599 break;
606 600
607 case 'search': 601 case 'search':
608 if (isset($_GET['search'])){ 602 if (isset($_GET['search'])){
609 $search = $_GET['search']; 603 $search = $_GET['search'];
@@ -647,7 +641,7 @@ class Poche
647 'nb_results' => '', 641 'nb_results' => '',
648 'listmode' => (isset($_COOKIE['listmode']) ? true : false), 642 'listmode' => (isset($_COOKIE['listmode']) ? true : false),
649 ); 643 );
650 644
651 //if id is given - we retrive entries by tag: id is tag id 645 //if id is given - we retrive entries by tag: id is tag id
652 if ($id) { 646 if ($id) {
653 $tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId()); 647 $tpl_vars['tag'] = $this->store->retrieveTag($id, $this->user->getId());
@@ -672,8 +666,8 @@ class Poche
672 } 666 }
673 667
674 /** 668 /**
675 * update the password of the current user. 669 * update the password of the current user.
676 * if MODE_DEMO is TRUE, the password can't be updated. 670 * if MODE_DEMO is TRUE, the password can't be updated.
677 * @todo add the return value 671 * @todo add the return value
678 * @todo set the new password in function header like this updatePassword($newPassword) 672 * @todo set the new password in function header like this updatePassword($newPassword)
679 * @return boolean 673 * @return boolean
@@ -701,44 +695,44 @@ class Poche
701 } 695 }
702 } 696 }
703 } 697 }
704 698
705 public function updateTheme() 699 public function updateTheme()
706 { 700 {
707 # no data 701 # no data
708 if (empty($_POST['theme'])) { 702 if (empty($_POST['theme'])) {
709 } 703 }
710 704
711 # we are not going to change it to the current theme... 705 # we are not going to change it to the current theme...
712 if ($_POST['theme'] == $this->getTheme()) { 706 if ($_POST['theme'] == $this->getTheme()) {
713 $this->messages->add('w', _('still using the "' . $this->getTheme() . '" theme!')); 707 $this->messages->add('w', _('still using the "' . $this->getTheme() . '" theme!'));
714 Tools::redirect('?view=config'); 708 Tools::redirect('?view=config');
715 } 709 }
716 710
717 $themes = $this->getInstalledThemes(); 711 $themes = $this->getInstalledThemes();
718 $actualTheme = false; 712 $actualTheme = false;
719 713
720 foreach (array_keys($themes) as $theme) { 714 foreach (array_keys($themes) as $theme) {
721 if ($theme == $_POST['theme']) { 715 if ($theme == $_POST['theme']) {
722 $actualTheme = true; 716 $actualTheme = true;
723 break; 717 break;
724 } 718 }
725 } 719 }
726 720
727 if (! $actualTheme) { 721 if (! $actualTheme) {
728 $this->messages->add('e', _('that theme does not seem to be installed')); 722 $this->messages->add('e', _('that theme does not seem to be installed'));
729 Tools::redirect('?view=config'); 723 Tools::redirect('?view=config');
730 } 724 }
731 725
732 $this->store->updateUserConfig($this->user->getId(), 'theme', $_POST['theme']); 726 $this->store->updateUserConfig($this->user->getId(), 'theme', $_POST['theme']);
733 $this->messages->add('s', _('you have changed your theme preferences')); 727 $this->messages->add('s', _('you have changed your theme preferences'));
734 728
735 $currentConfig = $_SESSION['poche_user']->config; 729 $currentConfig = $_SESSION['poche_user']->config;
736 $currentConfig['theme'] = $_POST['theme']; 730 $currentConfig['theme'] = $_POST['theme'];
737 731
738 $_SESSION['poche_user']->setConfig($currentConfig); 732 $_SESSION['poche_user']->setConfig($currentConfig);
739 733
740 $this->emptyCache(); 734 $this->emptyCache();
741 735
742 Tools::redirect('?view=config'); 736 Tools::redirect('?view=config');
743 } 737 }
744 738
@@ -747,40 +741,40 @@ class Poche
747 # no data 741 # no data
748 if (empty($_POST['language'])) { 742 if (empty($_POST['language'])) {
749 } 743 }
750 744
751 # we are not going to change it to the current language... 745 # we are not going to change it to the current language...
752 if ($_POST['language'] == $this->getLanguage()) { 746 if ($_POST['language'] == $this->getLanguage()) {
753 $this->messages->add('w', _('still using the "' . $this->getLanguage() . '" language!')); 747 $this->messages->add('w', _('still using the "' . $this->getLanguage() . '" language!'));
754 Tools::redirect('?view=config'); 748 Tools::redirect('?view=config');
755 } 749 }
756 750
757 $languages = $this->getInstalledLanguages(); 751 $languages = $this->getInstalledLanguages();
758 $actualLanguage = false; 752 $actualLanguage = false;
759 753
760 foreach ($languages as $language) { 754 foreach ($languages as $language) {
761 if ($language['value'] == $_POST['language']) { 755 if ($language['value'] == $_POST['language']) {
762 $actualLanguage = true; 756 $actualLanguage = true;
763 break; 757 break;
764 } 758 }
765 } 759 }
766 760
767 if (! $actualLanguage) { 761 if (! $actualLanguage) {
768 $this->messages->add('e', _('that language does not seem to be installed')); 762 $this->messages->add('e', _('that language does not seem to be installed'));
769 Tools::redirect('?view=config'); 763 Tools::redirect('?view=config');
770 } 764 }
771 765
772 $this->store->updateUserConfig($this->user->getId(), 'language', $_POST['language']); 766 $this->store->updateUserConfig($this->user->getId(), 'language', $_POST['language']);
773 $this->messages->add('s', _('you have changed your language preferences')); 767 $this->messages->add('s', _('you have changed your language preferences'));
774 768
775 $currentConfig = $_SESSION['poche_user']->config; 769 $currentConfig = $_SESSION['poche_user']->config;
776 $currentConfig['language'] = $_POST['language']; 770 $currentConfig['language'] = $_POST['language'];
777 771
778 $_SESSION['poche_user']->setConfig($currentConfig); 772 $_SESSION['poche_user']->setConfig($currentConfig);
779 773
780 $this->emptyCache(); 774 $this->emptyCache();
781 775
782 Tools::redirect('?view=config'); 776 Tools::redirect('?view=config');
783 } 777 }
784 /** 778 /**
785 * get credentials from differents sources 779 * get credentials from differents sources
786 * it redirects the user to the $referer link 780 * it redirects the user to the $referer link
@@ -835,7 +829,7 @@ class Poche
835 /** 829 /**
836 * log out the poche user. It cleans the session. 830 * log out the poche user. It cleans the session.
837 * @todo add the return value 831 * @todo add the return value
838 * @return boolean 832 * @return boolean
839 */ 833 */
840 public function logout() 834 public function logout()
841 { 835 {
@@ -891,7 +885,7 @@ class Poche
891 * import from Pocket. poche needs a ./ril_export.html file 885 * import from Pocket. poche needs a ./ril_export.html file
892 * @todo add the return value 886 * @todo add the return value
893 * @param string $targetFile the file used for importing 887 * @param string $targetFile the file used for importing
894 * @return boolean 888 * @return boolean
895 */ 889 */
896 private function importFromPocket($targetFile) 890 private function importFromPocket($targetFile)
897 { 891 {
@@ -922,7 +916,7 @@ class Poche
922 $this->action('add_tag',$url,$last_id,true,false,$tags); 916 $this->action('add_tag',$url,$last_id,true,false,$tags);
923 } 917 }
924 } 918 }
925 919
926 # the second <ul> is for read links 920 # the second <ul> is for read links
927 $read = 1; 921 $read = 1;
928 } 922 }
@@ -937,7 +931,7 @@ class Poche
937 * import from Readability. poche needs a ./readability file 931 * import from Readability. poche needs a ./readability file
938 * @todo add the return value 932 * @todo add the return value
939 * @param string $targetFile the file used for importing 933 * @param string $targetFile the file used for importing
940 * @return boolean 934 * @return boolean
941 */ 935 */
942 private function importFromReadability($targetFile) 936 private function importFromReadability($targetFile)
943 { 937 {
@@ -994,7 +988,7 @@ class Poche
994 /** 988 /**
995 * import from Poche exported file 989 * import from Poche exported file
996 * @param string $targetFile the file used for importing 990 * @param string $targetFile the file used for importing
997 * @return boolean 991 * @return boolean
998 */ 992 */
999 private function importFromPoche($targetFile) 993 private function importFromPoche($targetFile)
1000 { 994 {
@@ -1014,12 +1008,12 @@ class Poche
1014 $url = new Url(base64_encode($value['url'])); 1008 $url = new Url(base64_encode($value['url']));
1015 $favorite = ($value['is_fav'] == -1); 1009 $favorite = ($value['is_fav'] == -1);
1016 $archive = ($value['is_read'] == -1); 1010 $archive = ($value['is_read'] == -1);
1017 1011
1018 # we can add the url 1012 # we can add the url
1019 if (!is_null($url) && $url->isCorrect()) { 1013 if (!is_null($url) && $url->isCorrect()) {
1020 1014
1021 $this->action('add', $url, 0, TRUE); 1015 $this->action('add', $url, 0, TRUE);
1022 1016
1023 $count++; 1017 $count++;
1024 if ($favorite) { 1018 if ($favorite) {
1025 $last_id = $this->store->getLastId($sequence); 1019 $last_id = $this->store->getLastId($sequence);
@@ -1030,7 +1024,7 @@ class Poche
1030 $this->action('toggle_archive', $url, $last_id, TRUE); 1024 $this->action('toggle_archive', $url, $last_id, TRUE);
1031 } 1025 }
1032 } 1026 }
1033 1027
1034 } 1028 }
1035 1029
1036 unlink($targetFile); 1030 unlink($targetFile);
@@ -1041,37 +1035,115 @@ class Poche
1041 1035
1042 /** 1036 /**
1043 * import datas into your poche 1037 * import datas into your poche
1044 * @param string $from name of the service to import : pocket, instapaper or readability 1038 * @return boolean
1045 * @todo add the return value
1046 * @return boolean
1047 */ 1039 */
1048 public function import($from) 1040 public function import() {
1049 { 1041
1050 $providers = array( 1042 if ( isset($_FILES['file']) ) {
1051 'pocket' => 'importFromPocket', 1043 // assume, that file is in json format
1052 'readability' => 'importFromReadability', 1044 $str_data = file_get_contents($_FILES['file']['tmp_name']);
1053 'instapaper' => 'importFromInstapaper', 1045 $data = json_decode($str_data, true);
1054 'poche' => 'importFromPoche', 1046
1055 ); 1047 if ( $data === null ) {
1056 1048 //not json - assume html
1057 if (! isset($providers[$from])) { 1049 $html = new simple_html_dom();
1058 $this->messages->add('e', _('Unknown import provider.')); 1050 $html->load_file($_FILES['file']['tmp_name']);
1059 Tools::redirect(); 1051 $data = array();
1052 $read = 0;
1053 foreach (array('ol','ul') as $list) {
1054 foreach ($html->find($list) as $ul) {
1055 foreach ($ul->find('li') as $li) {
1056 $tmpEntry = array();
1057 $a = $li->find('a');
1058 $tmpEntry['url'] = $a[0]->href;
1059 $tmpEntry['tags'] = $a[0]->tags;
1060 $tmpEntry['is_read'] = $read;
1061 if ($tmpEntry['url']) {
1062 $data[] = $tmpEntry;
1063 }
1064 }
1065 # the second <ol/ul> is for read links
1066 $read = ((sizeof($data) && $read)?0:1);
1067 }
1068 }
1060 } 1069 }
1061 1070
1062 $targetFile = CACHE . '/' . constant(strtoupper($from) . '_FILE'); 1071 $i = 0; //counter for articles inserted
1063 1072 foreach ($data as $record) {
1064 if (! file_exists($targetFile)) { 1073 //echo '<pre>';
1065 $this->messages->add('e', _('Could not find required "' . $targetFile . '" import file.')); 1074 //var_dump($record);
1066 Tools::redirect(); 1075 // foreach ($record as $key=>$val) {
1076 // echo "\n=================\n$i: $key: $val\n";
1077 // }
1078 // exit;
1079
1080 $url = trim($record['url']);
1081 if ( $url ) {
1082 $title = (isset($record['title']) ? $record['title'] : _('Untitled - Import - ').'</a> <a href="./?import">'._('click to finish import').'</a><a>');
1083 $body = (isset($record['content']) ? $record['content'] : '');
1084 $isRead = (isset($record['is_read']) ? intval($record['is_read']) : 0);
1085 $isFavorite = (isset($record['is_fav']) ? intval($record['is_fav']) : 0);
1086 //insert new record
1087 $id = $this->store->add($url, $title, $body, $this->user->getId(), $isFavorite, $isRead);
1088 if ( $id ) {
1089 //increment no of records inserted
1090 $i++;
1091 if ( isset($record['tags']) && trim($record['tags']) ) {
1092 //@TODO: set tags
1093
1094 }
1095 }
1096 }
1097 }
1098
1099 if ( $i > 0 ) {
1100 $this->messages->add('s', _('Articles inserted: ').$i._('. Please note, that some may be marked as "read".'));
1101 }
1102 }
1103 //file parsing finished here
1104
1105 //now download article contents if any
1106
1107 //check if we need to download any content
1108 $recordsDownloadRequired = $this->store->retrieveUnfetchedEntriesCount($this->user->getId());
1109 if ( $recordsDownloadRequired == 0 ) {
1110 //nothing to download
1111 $this->messages->add('s', _('Import finished.'));
1112 Tools::redirect();
1113 }
1114 else {
1115 //if just inserted - don't download anything, download will start in next reload
1116 if ( !isset($_FILES['file']) ) {
1117 //download next batch
1118 $items = $this->store->retrieveUnfetchedEntries($this->user->getId(), IMPORT_LIMIT);
1119
1120 $config = HTMLPurifier_Config::createDefault();
1121 $config->set('Cache.SerializerPath', CACHE);
1122 $purifier = new HTMLPurifier($config);
1123
1124 foreach ($items as $item) {
1125 $url = new Url(base64_encode($item['url']));
1126 $content = Tools::getPageContent($url);
1127
1128 $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'));
1129 $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined'));
1130
1131 //clean content to prevent xss attack
1132 $title = $purifier->purify($title);
1133 $body = $purifier->purify($body);
1134
1135 $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId());
1136 }
1137
1067 } 1138 }
1068 1139 }
1069 $this->$providers[$from]($targetFile); 1140
1141 return array('includeImport'=>true, 'import'=>array('recordsDownloadRequired'=>$recordsDownloadRequired, 'recordsUnderDownload'=> IMPORT_LIMIT, 'delay'=> IMPORT_DELAY * 1000) );
1070 } 1142 }
1071 1143
1072 public function uploadFile() { 1144 public function uploadFile() {
1073 if(isset($_FILES['file'])) 1145 if (isset($_FILES['file']))
1074 { 1146 {
1075 $dir = CACHE . '/'; 1147 $dir = CACHE . '/';
1076 $file = basename($_FILES['file']['name']); 1148 $file = basename($_FILES['file']['name']);
1077 if(move_uploaded_file($_FILES['file']['tmp_name'], $dir . $file)) { 1149 if(move_uploaded_file($_FILES['file']['tmp_name'], $dir . $file)) {
@@ -1081,7 +1153,7 @@ class Poche
1081 $this->messages->add('e', _('Error while importing file. Do you have access to upload it?')); 1153 $this->messages->add('e', _('Error while importing file. Do you have access to upload it?'));
1082 } 1154 }
1083 } 1155 }
1084 1156
1085 Tools::redirect('?view=config'); 1157 Tools::redirect('?view=config');
1086 } 1158 }
1087 1159
@@ -1093,7 +1165,7 @@ class Poche
1093 { 1165 {
1094 $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; 1166 $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json";
1095 header('Content-Disposition: attachment; filename='.$filename); 1167 header('Content-Disposition: attachment; filename='.$filename);
1096 1168
1097 $entries = $this->store->retrieveAll($this->user->getId()); 1169 $entries = $this->store->retrieveAll($this->user->getId());
1098 echo $this->tpl->render('export.twig', array( 1170 echo $this->tpl->render('export.twig', array(
1099 'export' => Tools::renderJson($entries), 1171 'export' => Tools::renderJson($entries),
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index ad451fc6..a130e94b 100755
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -7,7 +7,7 @@
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 */
10 10
11class Tools 11class Tools
12{ 12{
13 public static function initPhp() 13 public static function initPhp()
@@ -42,7 +42,7 @@ class Tools
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 45 || (isset($_SERVER["SERVER_PORT"]) //Custom HTTPS port detection
46 && $_SERVER["SERVER_PORT"] == SSL_PORT) 46 && $_SERVER["SERVER_PORT"] == SSL_PORT)
47 || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) 47 || (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])
48 && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'); 48 && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https');
@@ -148,7 +148,7 @@ class Tools
148 ); 148 );
149 149
150 # only download page lesser than 4MB 150 # only download page lesser than 4MB
151 $data = @file_get_contents($url, false, $context, -1, 4000000); 151 $data = @file_get_contents($url, false, $context, -1, 4000000);
152 152
153 if (isset($http_response_header) and isset($http_response_header[0])) { 153 if (isset($http_response_header) and isset($http_response_header[0])) {
154 $httpcodeOK = isset($http_response_header) and isset($http_response_header[0]) and ((strpos($http_response_header[0], '200 OK') !== FALSE) or (strpos($http_response_header[0], '301 Moved Permanently') !== FALSE)); 154 $httpcodeOK = isset($http_response_header) and isset($http_response_header[0]) and ((strpos($http_response_header[0], '200 OK') !== FALSE) or (strpos($http_response_header[0], '301 Moved Permanently') !== FALSE));
@@ -200,7 +200,7 @@ class Tools
200 } 200 }
201 } 201 }
202 202
203 public static function encodeString($string) 203 public static function encodeString($string)
204 { 204 {
205 return sha1($string . SALT); 205 return sha1($string . SALT);
206 } 206 }
diff --git a/inc/poche/config.inc.php.new b/inc/poche/config.inc.php.new
index 8d52497b..83b3c4c0 100755
--- a/inc/poche/config.inc.php.new
+++ b/inc/poche/config.inc.php.new
@@ -52,12 +52,8 @@ define ('CACHE', ROOT . '/cache');
52 52
53define ('PAGINATION', '10'); 53define ('PAGINATION', '10');
54 54
55define ('POCKET_FILE', '/ril_export.html'); 55//limit for download of articles during import
56define ('READABILITY_FILE', '/readability'); 56define ('IMPORT_LIMIT', 5);
57define ('INSTAPAPER_FILE', '/instapaper-export.html'); 57//delay between downloads (in sec)
58define ('POCHE_FILE', '/poche-export'); 58define ('IMPORT_DELAY', 5);
59 59
60define ('IMPORT_POCKET_FILE', ROOT . POCKET_FILE);
61define ('IMPORT_READABILITY_FILE', ROOT . READABILITY_FILE);
62define ('IMPORT_INSTAPAPER_FILE', ROOT . INSTAPAPER_FILE);
63define ('IMPORT_POCHE_FILE', ROOT . POCHE_FILE); \ No newline at end of file